:root {
    --bg: #f6f7f9;
    --card: #ffffff;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e5e7eb;
    --primary: #00a85a;
    --primary-2: #00a85a;
    --primary-hover: #008b45;
    --shadow: 0 6px 24px rgba(15, 23, 42, 0.08);
    --radius: 8px;
}

html[data-theme="dark"] {
    --bg: #0b1220;
    --card: #0f172a;
    --text: #e5e7eb;
    --muted: #94a3b8;
    --border: rgba(148, 163, 184, 0.18);
    --primary: #00a85a;
    --primary-2: #00a85a;
    --primary-hover: #008b45;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    margin: 0;
    font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "Liberation Sans", sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app {
    height: 100vh;
    overflow: hidden;
    display: grid;
    grid-template-columns: 260px 1fr;
}

.sidebar {
    background: var(--card);
    border-right: 1px solid var(--border);
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 18px;
    height: 100vh;
    overflow: hidden;
}

.sidebar .nav {
    flex: 1;
    overflow: auto;
}

.sidebar-bottom {
    margin-top: auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.sidebar-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.70);
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background 150ms ease, transform 120ms ease, color 150ms ease, border-color 150ms ease;
}

html[data-theme="dark"] .icon-btn {
    background: rgba(15, 23, 42, 0.7);
}

.icon-btn:hover {
    background: rgba(15, 23, 42, 0.04);
    color: var(--text);
    transform: translateY(-1px);
}

.brand-title {
    font-size: 18px;
    font-weight: 700;
}

.brand-sub {
    margin-top: 6px;
    font-size: 12px;
    color: var(--muted);
}

.nav {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.nav-item {
    text-decoration: none;
    color: var(--text);
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #fff;
    transition: background 150ms ease, transform 120ms ease, border-color 150ms ease;
}

.nav-item:hover {
    background: rgba(15, 23, 42, 0.04);
    transform: translateY(-1px);
}

.nav-item.active {
    border-color: rgba(34, 197, 94, 0.35);
    background: rgba(34, 197, 94, 0.10);
}

.sidebar-footer {
    margin-top: 10px;
    color: var(--muted);
    font-size: 12px;
}

.content {
    padding: 22px;
    height: 100vh;
    overflow: auto;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 16px;
}

.h1 {
    font-size: 22px;
    font-weight: 800;
}

.h2 {
    margin-top: 6px;
    font-size: 13px;
    color: var(--muted);
}

.grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.detect-card {
    overflow: visible;
}

.detect-card .card-body {
    overflow: visible;
}

.card-title {
    padding: 14px 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
}

.card-title-row {
    padding: 14px 16px;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
}

.card-title-text {
    white-space: nowrap;
}

.dataset-status {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    flex-wrap: wrap;
    justify-content: flex-end;
}

.dataset-status .status-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.card-body {
    padding: 16px;
}

.form {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.file {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

html[data-theme="dark"] .file {
    background: rgba(15, 23, 42, 0.7);
    border-color: var(--border);
    color: var(--text);
}

.file::file-selector-button {
    margin-right: 12px;
    border: 1px solid var(--border);
    background: #ffffff;
    color: var(--text);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: background 150ms ease, transform 120ms ease;
}

.file::file-selector-button:hover {
    background: rgba(15, 23, 42, 0.04);
    transform: translateY(-1px);
}

html[data-theme="dark"] .file::file-selector-button {
    background: rgba(15, 23, 42, 0.7);
    border-color: var(--border);
    color: var(--text);
}

.btn {
    border: none;
    background: var(--primary);
    color: #fff;
    padding: 10px 14px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: background 150ms ease, transform 120ms ease, box-shadow 150ms ease;
}

.btn:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(1px);
}

.btn-white {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    padding: 10px 14px;
    border-radius: 8px;
    font-weight: 700;
    cursor: pointer;
    transition: background 150ms ease, transform 120ms ease, border-color 150ms ease;
}

html[data-theme="dark"] .btn-white {
    background: rgba(15, 23, 42, 0.7);
}

.btn-white:hover {
    background: rgba(15, 23, 42, 0.04);
    transform: translateY(-1px);
}

.btn-danger {
    background: #dc2626;
}

.btn-danger:hover {
    background: #b91c1c;
}

.fixed-box {
    max-height: 140px;
    overflow: auto;
    white-space: pre-wrap;
}

#trainPanel #trainStatus {
    height: 140px;
}

#trainPanel #trainLog {
    height: 220px;
}

#terminalLog {
    height: 360px;
}

.fixed-box.fixed-box-lg {
    max-height: 220px;
}

.fixed-box.fixed-box-xl {
    max-height: 360px;
}

.fade-top {
    position: relative;
}

.fade-top::before {
    content: "";
    position: sticky;
    top: 0;
    display: block;
    height: 18px;
    margin-bottom: -18px;
    pointer-events: none;
    background: linear-gradient(to bottom, var(--card), rgba(255,255,255,0));
}

html[data-theme="dark"] .fade-top::before {
    background: linear-gradient(to bottom, var(--card), rgba(15, 23, 42, 0));
}

.result-img {
    width: 100%;
    display: block;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.table th, .table td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}

.empty {
    color: var(--muted);
    font-size: 13px;
}

.error {
    margin-top: 10px;
    color: #b91c1c;
    font-size: 13px;
}

.note {
    font-size: 13px;
    color: var(--muted);
    line-height: 1.6;
}

code {
    background: rgba(15, 23, 42, 0.06);
    padding: 2px 6px;
    border-radius: 6px;
}

.lang {
    display: flex;
    gap: 8px;
}

.lang a {
    text-decoration: none;
    color: var(--muted);
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card);
    font-size: 12px;
    transition: background 150ms ease, transform 120ms ease;
}

.lang a:hover {
    background: rgba(15, 23, 42, 0.04);
    transform: translateY(-1px);
}

.file-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.settings-section {
    margin-top: 18px;
}

.settings-section:first-child {
    margin-top: 0;
}

.file-input {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
    pointer-events: none;
}

.file-btn {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: background 150ms ease, transform 120ms ease;
    text-decoration: none;
}

.file-btn:hover {
    background: rgba(15, 23, 42, 0.04);
    transform: translateY(-1px);
    text-decoration: none;
}

html[data-theme="dark"] .file-btn {
    background: rgba(15, 23, 42, 0.7);
    border-color: var(--border);
    color: var(--text);
}

input[type="range"] {
    accent-color: var(--primary);
}

.detect-range {
    width: 220px;
}

.detect-number {
    width: 120px;
    max-width: 120px;
}

.help-tip {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 800;
    cursor: help;
    background: var(--card);
    position: relative;
    z-index: 2;
}

.help-tip:hover {
    color: var(--text);
    border-color: rgba(34, 197, 94, 0.35);
}

.help-tip:hover::after {
    content: attr(data-tip);
    position: absolute;
    left: 0;
    transform: none;
    top: 24px;
    min-width: 220px;
    max-width: 320px;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 10px;
    border-radius: 10px;
    box-shadow: var(--shadow);
    z-index: 99999;
    font-weight: 500;
    line-height: 1.5;
    pointer-events: none;
}

.detect-tune {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 14px;
    align-items: center;
}

.tune-item {
    display: grid;
    grid-template-columns: 96px 1fr 120px;
    gap: 10px;
    align-items: center;
    position: relative;
    z-index: 1;
}

.tune-item:hover {
    z-index: 100000;
}

.tune-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    justify-content: flex-start;
}

.tune-item--checks {
    grid-column: 1 / -1;
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}

.tune-check {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.detect-range {
    width: 100%;
}

.thumbs {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.thumb {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    border: 1px solid var(--border);
    object-fit: cover;
    background: var(--card);
}

.file-btn:visited {
    text-decoration: none;
}

#backToTop {
    position: fixed;
    right: 22px;
    bottom: 22px;
    width: 46px;
    height: 46px;
    border-radius: 999px;
    border: none;
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow);
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 50;
    transition: transform 120ms ease, background 150ms ease, opacity 150ms ease;
    opacity: 0.95;
}

#backToTop:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    opacity: 1;
}

.file-name {
    color: var(--muted);
    font-size: 13px;
    max-width: 320px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 980px) {
    .app {
        grid-template-columns: 1fr;
        height: auto;
    }

    .sidebar {
        border-right: none;
        border-bottom: 1px solid var(--border);
        height: auto;
        overflow: visible;
    }

    .grid {
        grid-template-columns: 1fr;
    }

    html, body {
        overflow: auto;
    }

    .content {
        height: auto;
        overflow: visible;
    }
}
