:root {
    color-scheme: light;
    --bg: #f4f7fb;
    --bg-soft: #e8eef7;
    --card: rgba(255, 255, 255, .92);
    --card-solid: #ffffff;
    --card-soft: #f7f9fc;
    --text: #111827;
    --muted: #64748b;
    --line: #dbe4f0;
    --input: #ffffff;
    --primary: #2563eb;
    --primary-2: #1d4ed8;
    --danger: #ef4444;
    --success: #16a34a;
    --warning: #f59e0b;
    --shadow: 0 18px 45px rgba(15, 23, 42, .10);
    --shadow-soft: 0 10px 25px rgba(15, 23, 42, .08);
    --radius: 18px;
    --radius-sm: 12px;
}

:root.dark {
    color-scheme: dark;
    --bg: #070d18;
    --bg-soft: #0c1525;
    --card: rgba(15, 23, 42, .88);
    --card-solid: #0f172a;
    --card-soft: #111c30;
    --text: #eaf0f8;
    --muted: #94a3b8;
    --line: #223047;
    --input: #0b1220;
    --primary: #3b82f6;
    --primary-2: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #fbbf24;
    --shadow: 0 24px 70px rgba(0, 0, 0, .42);
    --shadow-soft: 0 12px 35px rgba(0, 0, 0, .30);
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body {
    margin: 0;
    width: 100%;
    min-height: 100%;
    overflow-x: clip;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, .15), transparent 28rem),
        radial-gradient(circle at bottom right, rgba(34, 197, 94, .08), transparent 24rem),
        var(--bg);
    color: var(--text);
}

a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, .button {
    border: 0;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    min-height: 40px;
    padding: 9px 13px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font-weight: 750;
    text-decoration: none;
    cursor: pointer;
    box-shadow: 0 8px 18px rgba(37, 99, 235, .20);
    transition: transform .12s ease, filter .12s ease, background .12s ease;
}
button:hover, .button:hover { filter: brightness(1.05); transform: translateY(-1px); }
button.secondary, .button.secondary { background: #334155; box-shadow: none; }
button.success, .button.success { background: var(--success); box-shadow: none; }
button.danger, .button.danger { background: var(--danger); box-shadow: none; }
button.warning, .button.warning { background: var(--warning); color: #111827; box-shadow: none; }
button.ghost, .button.ghost { background: var(--card-soft); color: var(--text); border: 1px solid var(--line); box-shadow: none; }
.small-button { min-height: 32px; padding: 6px 10px; border-radius: 10px; font-size: 13px; }
.icon-button, .round-remove {
    width: 38px;
    min-width: 38px;
    height: 38px;
    min-height: 38px;
    padding: 0;
    border-radius: 999px;
    box-shadow: none;
}
.icon-button { background: var(--card-soft); color: var(--text); border: 1px solid var(--line); font-size: 24px; }
.round-remove { background: rgba(239, 68, 68, .13); color: #fca5a5; border: 1px solid rgba(239, 68, 68, .28); font-size: 24px; line-height: 1; }
:root:not(.dark) .round-remove { color: #991b1b; }

.header {
    position: sticky;
    top: 0;
    z-index: 40;
    background: rgba(7, 13, 24, .88);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid rgba(148, 163, 184, .18);
    color: #fff;
    padding: 12px 18px;
}
.header-inner {
    max-width: 1280px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}
.logo { font-weight: 900; letter-spacing: -.02em; white-space: nowrap; }
.nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.nav a, .theme-toggle {
    min-height: 34px;
    padding: 7px 11px;
    border-radius: 999px;
    color: #dbeafe;
    text-decoration: none;
    font-size: 14px;
    background: transparent;
    border: 1px solid transparent;
    box-shadow: none;
}
.nav a.active, .nav a:hover, .theme-toggle:hover { background: rgba(255,255,255,.10); border-color: rgba(255,255,255,.10); }

.container {
    width: min(1280px, 100%);
    margin: 22px auto 56px;
    padding: 0 16px;
}
.grid { display: grid; gap: 16px; min-width: 0; }
.grid.two { grid-template-columns: minmax(0, 1.25fr) minmax(300px, .75fr); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card, .mini-card, .run-card {
    background: var(--card);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-soft);
    border-radius: var(--radius);
}
.card { padding: 18px; }
.card h1, .card h2, .card h3 { margin-top: 0; letter-spacing: -.02em; }
.card h1 { font-size: clamp(24px, 3vw, 34px); margin-bottom: 14px; }
.card h2 { font-size: 20px; margin-bottom: 12px; }
.muted { color: var(--muted); }
.field-hint { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.35; font-weight: 550; }
.big-number { font-size: clamp(28px, 4vw, 42px); line-height: 1; font-weight: 900; }
.mini-card { padding: 14px; background: var(--card-soft); }
.mini-card span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 13px; }
.mini-card strong { font-size: 23px; }
.section-head, .settings-card-head, .run-head, .modal-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
}
.section-head { margin-bottom: 16px; }
.section-head h1, .settings-card-head h2, .modal-head h2 { margin-bottom: 2px; }
.compact-head { align-items: center; }

form { margin: 0; }
label { display: block; margin-bottom: 11px; font-size: 14px; font-weight: 720; }
input, select, textarea {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    margin-top: 6px;
    border: 1px solid var(--line);
    border-radius: 13px;
    padding: 10px 12px;
    background: var(--input);
    color: var(--text);
    outline: none;
    transition: border-color .12s ease, box-shadow .12s ease, background .12s ease;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(59, 130, 246, .14); }
textarea { min-height: 82px; resize: vertical; }
input[type="date"], input[type="time"], input[type="datetime-local"], input[type="month"] { min-inline-size: 0; -webkit-appearance: none; appearance: none; }
.checkbox-line { display: flex; align-items: center; gap: 9px; }
.checkbox-line input { width: auto; margin: 0; }
.form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-row.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.hidden-field { display: none !important; }
.button-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.badge {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    max-width: 100%;
    gap: 5px;
    border-radius: 999px;
    padding: 5px 10px;
    font-size: 12px;
    font-weight: 800;
    background: #e2e8f0;
    color: #334155;
    white-space: nowrap;
}
.badge.green { background: #dcfce7; color: #166534; }
.badge.blue { background: #dbeafe; color: #1e40af; }
.badge.yellow { background: #fef3c7; color: #92400e; }
.badge.red { background: #fee2e2; color: #991b1b; }
:root.dark .badge { background: rgba(148, 163, 184, .14); color: #cbd5e1; }
:root.dark .badge.green { background: rgba(34, 197, 94, .15); color: #86efac; }
:root.dark .badge.blue { background: rgba(59, 130, 246, .18); color: #93c5fd; }
:root.dark .badge.yellow { background: rgba(251, 191, 36, .14); color: #fde68a; }
:root.dark .badge.red { background: rgba(239, 68, 68, .16); color: #fecaca; }

.alert {
    margin: 0 0 16px;
    padding: 12px 14px;
    border: 1px solid rgba(59, 130, 246, .25);
    border-radius: 14px;
    background: rgba(59, 130, 246, .12);
    color: var(--text);
}
.alert.success { border-color: rgba(34, 197, 94, .28); background: rgba(34, 197, 94, .13); }
.alert.danger { border-color: rgba(239, 68, 68, .30); background: rgba(239, 68, 68, .13); }

.table-wrap { max-width: 100%; overflow-x: auto; border-radius: 14px; }
table { width: 100%; min-width: 780px; border-collapse: collapse; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .035em; }
tr:last-child td { border-bottom: 0; }
.group-row td { background: var(--card-soft); color: var(--muted); font-weight: 850; }
.row-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: nowrap;
    min-width: 0;
}
td.row-actions { min-width: 174px; }
.row-actions form { margin: 0; display: inline-flex; }
.row-actions .small-button { white-space: nowrap; }

.run-card { padding: 14px; margin-bottom: 12px; background: var(--card-soft); border-style: solid; }
.run-title { font-size: 17px; font-weight: 900; }
.route-hint, .weight-preview {
    display: none;
    margin: 4px 0 12px;
    border-radius: 13px;
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 700;
    border: 1px solid rgba(59, 130, 246, .25);
    background: rgba(59, 130, 246, .12);
    color: var(--text);
}
.route-hint.green { border-color: rgba(34, 197, 94, .28); background: rgba(34, 197, 94, .12); }
.route-hint.red { border-color: rgba(239, 68, 68, .28); background: rgba(239, 68, 68, .12); }
.route-hint.unknown { border-color: rgba(251, 191, 36, .28); background: rgba(251, 191, 36, .12); }
.place-field { position: relative; }
.place-dropdown {
    display: none;
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    top: calc(100% + 6px);
    max-height: 280px;
    overflow: auto;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--card-solid);
    box-shadow: var(--shadow);
}
.place-dropdown.open { display: block; }
.place-option {
    width: 100%;
    display: block;
    min-height: 0;
    margin: 0;
    padding: 9px 10px;
    border-radius: 10px;
    background: transparent;
    color: var(--text);
    border: 0;
    text-align: left;
    box-shadow: none;
}
.place-option:hover { background: var(--card-soft); transform: none; }
.place-main { display: block; font-weight: 850; }
.place-meta { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }
.sessions-wrap { display: grid; gap: 10px; }
.session-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)) auto; gap: 10px; align-items: end; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--card-soft); }

.category-chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.category-chip { padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; background: var(--card-soft); text-decoration: none; color: var(--muted); font-weight: 760; }
.category-chip.active { color: #fff; background: var(--primary); border-color: var(--primary); }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.settings-card-small { grid-column: 1 / -1; }
.settings-kicker { color: var(--muted); font-size: 13px; }
.compact-table-wrap { border: 1px solid var(--line); overflow: hidden; }
.settings-table { min-width: 0; table-layout: fixed; }
.settings-table th, .settings-table td { overflow-wrap: anywhere; }
.settings-table td:last-child, .settings-table th:last-child { width: 188px; }

.route-list { display: grid; gap: 12px; }
.route-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: start;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: var(--card-soft);
}
.route-path { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 17px; font-weight: 900; }
.route-subtitle { margin-top: 4px; }
.route-badges { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 10px; }
.route-note { margin: 10px 0 0; color: var(--muted); }
.route-actions { align-self: stretch; align-items: flex-start; }
.empty-state { padding: 18px; border: 1px dashed var(--line); border-radius: 14px; color: var(--muted); background: var(--card-soft); }

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: none;
    place-items: center;
    padding: 18px;
    background: rgba(2, 6, 23, .66);
    backdrop-filter: blur(10px);
}
.modal-backdrop.open { display: grid; }
.modal-card {
    width: min(700px, 100%);
    max-height: calc(100dvh - 36px);
    overflow: auto;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 22px;
    background: var(--card-solid);
    box-shadow: 0 28px 90px rgba(0,0,0,.45);
}
.modal-head { position: sticky; top: -18px; z-index: 2; padding: 0 0 12px; background: var(--card-solid); }
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: min(430px, 100%); padding: 22px; border: 1px solid var(--line); border-radius: 22px; background: var(--card-solid); box-shadow: var(--shadow); }
.assistant-progress { height: 12px; border-radius: 999px; overflow: hidden; background: var(--card-soft); border: 1px solid var(--line); }
.assistant-progress span { display: block; height: 100%; width: var(--progress); border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--success)); }
.current-plant-box { padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: var(--card-soft); margin-bottom: 14px; }
.current-plant-box strong { display: block; margin: 4px 0 8px; font-size: 24px; }
.quick-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.quick-list a { text-decoration: none; }
.route-form-footer { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

* { scrollbar-width: thin; scrollbar-color: rgba(148, 163, 184, .45) transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: rgba(148, 163, 184, .42); border-radius: 999px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: rgba(148, 163, 184, .62); background-clip: content-box; }

@media (max-width: 980px) {
    .grid.two, .grid.three, .form-row, .form-row.three, .form-row.four, .settings-grid { grid-template-columns: minmax(0, 1fr); }
    .section-head, .settings-card-head { align-items: stretch; flex-direction: column; }
    .section-head .button-row, .settings-card-head .small-button { width: 100%; }
    .session-row { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 720px) {
    body { overflow-x: hidden; }
    .header { padding: 10px; }
    .header-inner { align-items: flex-start; flex-direction: column; gap: 10px; }
    .logo { white-space: normal; font-size: 15px; }
    .nav { width: 100%; flex-wrap: nowrap; overflow-x: auto; padding-bottom: 2px; }
    .nav a, .theme-toggle { flex: 0 0 auto; white-space: nowrap; font-size: 13px; background: rgba(255,255,255,.07); }
    .container { margin-top: 12px; padding: 0 10px; overflow: hidden; }
    .card { padding: 13px; border-radius: 16px; }
    .run-card { padding: 12px; }
    .button-row { align-items: stretch; }
    .button-row > button, .button-row > .button, .button-row > form, .button-row > form > button { width: 100%; }
    input, select, textarea { font-size: 16px; }
    .table-wrap { margin-inline: -2px; }
    table { min-width: 720px; }
    th, td { padding: 10px 8px; }
    td.row-actions, .row-actions { min-width: 0; justify-content: flex-start; }
    .row-actions { flex-wrap: wrap; }
    .row-actions .small-button { flex: 0 0 auto; }
    .route-item { grid-template-columns: minmax(0, 1fr); }
    .route-actions { justify-content: flex-start; }
    .modal-backdrop { align-items: end; padding: 8px; }
    .modal-card { max-height: calc(100dvh - 16px); border-radius: 18px; padding: 14px; }
    .modal-head { top: -14px; }
}

@media (max-width: 560px) {
    .settings-table { min-width: 0; width: 100%; }
    .settings-table thead { display: none; }
    .settings-table, .settings-table tbody, .settings-table tr, .settings-table td { display: block; width: 100%; }
    .settings-table tr { padding: 10px; border-bottom: 1px solid var(--line); }
    .settings-table tr:last-child { border-bottom: 0; }
    .settings-table td { display: grid; grid-template-columns: minmax(95px, 34%) minmax(0, 1fr); gap: 8px; align-items: center; border: 0; padding: 6px 0; }
    .settings-table td::before { content: attr(data-label); color: var(--muted); font-size: 12px; font-weight: 850; }
    .settings-table td[colspan] { display: block; }
    .settings-table td[colspan]::before { display: none; }
    .settings-table td:last-child, .settings-table th:last-child { width: auto; }
    .settings-table .row-actions { justify-content: stretch; }
    .settings-table .row-actions .small-button, .settings-table .row-actions form, .settings-table .row-actions form button { width: 100%; }
}

@supports not (overflow: clip) {
    body { overflow-x: hidden; }
}
