:root {
    color-scheme: light;
    --paper: #f4f1e8;
    --ink: #1f2a20;
    --accent: #2f6f4f;
    --line: #d6cfbd;
    --panel: rgba(255, 255, 255, 0.56);
    --danger: #8b2d2d;
    --muted: #5f675d;
    --topbar-h: 60px;
    --sidebar-workspace-h: calc(100vh - var(--topbar-h) - 30px);
    --route-panel-size: 58%;
    --regions-panel-size: 260px;
    --history-panel-size: 220px;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    color: var(--ink);
    background:
        radial-gradient(circle at top left, rgba(47, 111, 79, 0.14), transparent 28%),
        linear-gradient(135deg, #f6f2e7 0%, #ebe4d4 100%);
}
.topbar {
    min-height: var(--topbar-h);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(12px);
}
.topbar-info { display: none; }

.topbar-kicker {
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-size: 0.68rem;
    color: var(--accent);
    white-space: nowrap;
}
.topbar strong { font-size: 1.05rem; }
#topbar-meta { display: none; }

.topbar-actions {
    display: flex;
    align-items: end;
    gap: 8px;
    min-width: 0;
    justify-content: flex-start;
}
.topbar-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}
.topbar-field span {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}
.route-picker-field { flex: 0 0 auto; width: 280px; }
select,
input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 8px 10px;
    font: inherit;
    background: rgba(255, 255, 255, 0.92);
}
.topbar-stats {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 0 auto;
    padding: 0;
    flex-shrink: 0;
}
.topbar-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    min-width: max-content;
    flex-shrink: 0;
}
.topbar-stats div {
    display: flex;
    gap: 5px;
    align-items: baseline;
    white-space: nowrap;
}
.topbar-stats dt {
    margin: 0;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
}
.topbar-stats dd {
    margin: 0;
    font-size: 0.82rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.layout {
    min-height: calc(100vh - var(--topbar-h));
    display: grid;
    grid-template-columns: 380px 1fr;
}
.sidebar {
    padding: 14px 12px;
    border-right: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.42);
    backdrop-filter: blur(12px);
}
.sidebar-workspace {
    height: var(--sidebar-workspace-h);
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.panel {
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
    overflow: hidden;
}
.panel-fill {
    min-height: 120px;
}
.current-panel {
    flex: 0 1 var(--route-panel-size);
    display: flex;
    flex-direction: column;
    min-height: 220px;
}
.sidebar-workspace:not(.is-regions-open) .current-panel {
    flex-grow: 1;
}
.history-dock {
    display: flex;
    flex: 0 0 auto;
    flex-direction: column;
    min-height: 0;
}
.history-panel {
    flex: 0 0 var(--history-panel-size);
    display: flex;
    flex-direction: column;
    min-height: 54px;
}
.regions-panel {
    flex: 1 1 var(--regions-panel-size);
    display: flex;
    flex-direction: column;
    min-height: 180px;
    position: relative;
}
.regions-panel:not([open]) {
    flex: 0 0 auto;
    min-height: 54px;
}
.history-panel:not([open]) {
    flex-basis: auto;
}
.panel-header,
.panel-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 10px;
    font-size: 0.92rem;
    font-weight: 700;
}
.panel-summary {
    cursor: pointer;
    list-style: none;
}
.panel-summary::-webkit-details-marker { display: none; }
.panel-summary::before {
    content: "+";
    display: inline-block;
    width: 14px;
    margin-right: 6px;
    color: var(--accent);
}
.history-panel[open] .panel-summary::before { content: "-"; }
.regions-panel[open] .panel-summary::before { content: "-"; }
.panel-body {
    border-top: 1px solid rgba(214, 207, 189, 0.7);
    padding: 0 10px 10px;
}
.panel-body-fill {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
}
.regions-panel .panel-body {
    position: absolute;
    top: 37px;
    right: 0;
    bottom: 0;
    left: 0;
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}
.sidebar-resizer {
    height: 10px;
    margin: 6px 0;
    border-radius: 999px;
    background: rgba(47, 111, 79, 0.16);
    cursor: row-resize;
    flex: 0 0 auto;
}
.sidebar-resizer.is-hidden {
    display: none;
    pointer-events: none;
}
button {
    appearance: none;
    border: 0;
    border-radius: 999px;
    padding: 7px 10px;
    font: inherit;
    font-size: 0.82rem;
    line-height: 1.1;
    background: var(--accent);
    color: white;
    cursor: pointer;
    white-space: nowrap;
}
button:disabled { opacity: 0.55; cursor: not-allowed; }
.button-secondary {
    background: rgba(31, 42, 32, 0.12);
    color: var(--ink);
}
.inline-actions {
    display: flex;
    gap: 0;
    flex-wrap: wrap;
}
.metric-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    margin-top: 10px;
}
.metric-card {
    padding: 8px 10px;
    border: 1px solid rgba(214, 207, 189, 0.8);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.7);
}
.metric-card-preview {
    background: rgba(47, 111, 79, 0.08);
}
.metric-label {
    display: block;
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}
.metric-card strong {
    display: block;
    margin-top: 3px;
    font-size: 0.95rem;
}
#distance-delta.is-better { color: #2f6f4f; }
#distance-delta.is-worse { color: #8b2d2d; }
.status {
    min-height: 1em;
    margin: 8px 0 0;
    color: #415246;
    font-size: 0.84rem;
}
.status.error { color: var(--danger); }
#route-detail-summary { display: none; }
.route-bar-list {
    flex: 1 1 0;
    min-height: 0;
    max-height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 0;
}
.route-drop-gap {
    display: block;
    width: 100%;
    min-height: 36px;
    height: 36px;
    margin: 4px 0;
    border-radius: 12px;
    background: rgba(69, 138, 81, 0.08);
    pointer-events: none;
    transition: background-color 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
}
.route-drop-gap.is-insert-target {
    background: rgba(120, 148, 176, 0.38);
    box-shadow: 0 0 0 2px rgba(120, 148, 176, 0.24);
}
.route-virtual-spacer {
    flex: 0 0 auto;
    width: 100%;
    pointer-events: none;
}
.route-bar {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 6px;
    align-items: center;
    height: 36px;
    padding: 4px 6px;
    border: 1px solid rgba(214, 207, 189, 0.9);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.82);
    cursor: default;
    transition: outline-color 120ms ease, background-color 120ms ease;
}
.route-bar.dragging {
    opacity: 0.45;
}
.route-bar.is-merge-target {
    outline: 3px solid #458a51;
    outline-offset: 1px;
    background: rgba(69, 138, 81, 0.18);
    box-shadow: 0 0 0 3px rgba(69, 138, 81, 0.16);
}
.route-bar.is-locked {
    border-color: rgba(140, 108, 51, 0.7);
}
.route-bar.is-selected {
    outline: 2px solid #476d91;
    outline-offset: 1px;
    background: rgba(71, 109, 145, 0.18);
    box-shadow: 0 0 0 2px rgba(71, 109, 145, 0.14);
}
.route-bar.is-area-selected {
    outline: 2px solid rgba(47, 111, 79, 0.48);
    outline-offset: 1px;
    background: rgba(47, 111, 79, 0.14);
}

.route-bar.is-blocked {
    background: rgba(71, 109, 145, 0.08);
}
.route-bar-main {
    min-width: 0;
}
.route-bar-title {
    display: block;
    font-size: 0.86rem;
    font-weight: 700;
    color: #1f2a20;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.route-bar-indicators {
    display: flex;
    gap: 3px;
    flex-wrap: nowrap;
    justify-content: flex-end;
    align-self: center;
}
.lock-badge {
    min-width: 24px;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: rgba(140, 108, 51, 0.18);
    color: #8c6c33;
    font-size: 0.86rem;
    line-height: 1;
}
.block-badge {
    min-width: 24px;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    background: rgba(71, 109, 145, 0.18);
    color: #476d91;
    font-size: 0.8rem;
    line-height: 1;
}

.menu-button {
    background: rgba(31, 42, 32, 0.12);
    color: var(--ink);
}
.stop-menu {
    position: absolute;
    top: calc(100% + 4px);
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 104px;
    padding: 6px;
    border: 1px solid rgba(214, 207, 189, 0.9);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.98);
    box-shadow: 0 12px 24px rgba(31, 42, 32, 0.12);
    z-index: 20;
}
button.stop-menu-item {
    width: 100%;
    min-width: 0;
    height: auto;
    padding: 6px 8px;
    justify-content: flex-start;
    border-radius: 8px;
    background: rgba(31, 42, 32, 0.08);
    color: var(--ink);
}

.version-list {
    list-style: none;
    margin: 10px 0 0;
    padding: 0;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
}
.version-list li {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    align-items: center;
    min-height: 30px;
    padding: 4px 0;
    border-bottom: 1px solid rgba(214, 207, 189, 0.7);
}
.version-list li:last-child { border-bottom: 0; }
.version-list li.is-current { color: var(--accent); }
.version-list strong {
    font-size: 0.85rem;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.regions-list {
    margin-top: 8px;
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    max-height: none;
    overflow-y: auto;
    overscroll-behavior: contain;
}
.regions-list .region-bar {
    height: 32px;
    min-height: 32px;
    margin: 0;
    border-radius: 8px;
    cursor: pointer;
}
.regions-list .region-bar + .region-bar {
    margin-top: 3px;
}
.region-item-main {
    min-width: 0;
    overflow: hidden;
}
.optimization-stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin-top: 8px;
}
.optimization-stat {
    border: 1px solid rgba(214, 207, 189, 0.8);
    border-radius: 8px;
    padding: 5px 6px;
    background: rgba(255, 255, 255, 0.72);
}
.optimization-stat span {
    display: block;
    color: var(--muted);
    font-size: 0.68rem;
}
.optimization-stat strong {
    display: block;
    margin-top: 2px;
    font-size: 0.88rem;
}
.optimization-workers {
    margin-top: 6px;
    color: var(--muted);
    font-size: 0.76rem;
}
.main-panel {
    min-width: 0;
    position: relative;
}
.main-view {
    display: none;
    min-height: var(--sidebar-workspace-h);
}
.main-view.is-active {
    display: block;
}
.map-panel { padding: 14px; position: relative; }
#map {
    width: 100%;
    height: var(--sidebar-workspace-h);
    border: 1px solid rgba(31, 42, 32, 0.12);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 18px 40px rgba(64, 53, 32, 0.12);
}
.optimization-main-panel {
    padding: 14px;
}
.optimization-main-inner {
    height: var(--sidebar-workspace-h);
    min-height: 0;
    overflow: auto;
    padding: 16px;
    border: 1px solid rgba(31, 42, 32, 0.12);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.62);
    box-shadow: 0 18px 40px rgba(64, 53, 32, 0.12);
}
.optimization-main-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 14px;
    padding-bottom: 12px;
    border-bottom: 1px solid rgba(214, 207, 189, 0.8);
}
.optimization-main-header h1 {
    margin: 0 0 4px;
    font-size: 1.28rem;
}
.optimization-main-header .status {
    margin: 0;
}
.optimization-stats-main {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 8px;
    margin-top: 14px;
}
.optimization-stats-main .optimization-stat {
    padding: 10px;
}
.optimization-dashboard-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid rgba(214, 207, 189, 0.75);
}
.optimization-dashboard-section h2 {
    margin: 0 0 8px;
    font-size: 1rem;
}
.optimization-detail-list {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 0.82rem;
}
.optimization-detail-row {
    display: grid;
    grid-template-columns: minmax(100px, 160px) 1fr;
    gap: 10px;
    align-items: baseline;
    padding: 7px 8px;
    border: 1px solid rgba(214, 207, 189, 0.72);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.56);
}
.optimization-detail-row strong {
    color: var(--ink);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.optimization-detail-row span {
    min-width: 0;
    overflow-wrap: anywhere;
}
.route-creation-status {
    position: absolute;
    left: 28px;
    bottom: 28px;
    max-width: min(380px, calc(100vw - 56px));
    padding: 10px 12px;
    border: 1px solid rgba(214, 207, 189, 0.9);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.92);
    box-shadow: 0 16px 32px rgba(31, 42, 32, 0.16);
    color: var(--ink);
    font-size: 0.86rem;
    line-height: 1.35;
    z-index: 500;
    backdrop-filter: blur(10px);
}
.route-creation-status.is-hidden {
    display: none;
}
.route-creation-status.is-pending {
    border-color: rgba(71, 109, 145, 0.48);
    background: rgba(225, 235, 244, 0.94);
}
.route-creation-status.is-success {
    border-color: rgba(47, 111, 79, 0.48);
    background: rgba(232, 241, 235, 0.94);
}
.route-creation-status.is-error {
    border-color: rgba(139, 45, 45, 0.4);
    background: rgba(248, 234, 234, 0.95);
}
.route-dialog {
    border: 1px solid rgba(31, 42, 32, 0.12);
    border-radius: 16px;
    padding: 0;
    background: rgba(246, 242, 231, 0.98);
    color: var(--ink);
    width: min(460px, calc(100vw - 32px));
}
.route-dialog::backdrop {
    background: rgba(31, 42, 32, 0.28);
}
.auth-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(31, 42, 32, 0.28);
    backdrop-filter: blur(8px);
    z-index: 1200;
}
.auth-overlay.is-hidden {
    display: none;
}
.auth-card {
    width: min(420px, calc(100vw - 32px));
    padding: 18px;
    border: 1px solid rgba(31, 42, 32, 0.12);
    border-radius: 16px;
    background: rgba(246, 242, 231, 0.98);
    box-shadow: 0 16px 32px rgba(31, 42, 32, 0.18);
}
.auth-card h2 {
    margin: 0 0 10px;
    font-size: 1.15rem;
}
.route-dialog-form {
    padding: 16px;
}
.route-dialog-form h2 {
    margin: 0 0 8px;
    font-size: 1.1rem;
}
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 12px;
}
.field span {
    font-size: 0.82rem;
    color: var(--muted);
}
.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0;
    margin-top: 14px;
}
@media (max-width: 1100px) {
    .topbar {
    min-height: var(--topbar-h);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.78);
    backdrop-filter: blur(12px);
}
    .topbar-stats {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 0 0 auto;
    padding: 0;
    flex-shrink: 0;
}
}
@media (max-width: 900px) {
    #topbar-meta { display: none; }

    .layout { grid-template-columns: 1fr; min-height: auto; }
    .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
    .metric-grid { grid-template-columns: 1fr; }
    .sidebar-workspace,
    #map,
    .optimization-main-inner { height: 70vh; }
    .route-creation-status {
        left: 22px;
        right: 22px;
        bottom: 22px;
        max-width: none;
    }
}
.panel-tools { justify-content: flex-end; }
.route-tools { gap: 6px; margin-left: auto; }
.route-tool-group {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    flex-wrap: nowrap;
    padding: 3px;
    border: 1px solid rgba(214, 207, 189, 0.85);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.55);
    white-space: nowrap;
}
.topbar-tool-group { flex: 0 0 auto; }
.tool-button { min-width: 30px; width: 30px; height: 30px; padding: 0; display: inline-flex; align-items: center; justify-content: center; border-radius: 8px; font-size: 1rem; line-height: 1; }

.tool-icon { width: 14px; height: 14px; display: block; color: currentColor; }
.tool-button.is-active { background: rgba(71, 109, 145, 0.95); }
.stop-number-label {
    background: transparent;
    border: 0;
}
.stop-number-label span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 24px;
    height: 18px;
    padding: 0 5px;
    border: 1px solid rgba(31, 95, 168, 0.9);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.92);
    color: #123d72;
    box-shadow: 0 1px 5px rgba(31, 42, 32, 0.22);
    font-family: Georgia, "Times New Roman", serif;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1;
}
.popup-action-button {
    margin-top: 8px;
    padding: 5px 9px;
    border-radius: 8px;
    font-size: 0.76rem;
    background: rgba(47, 111, 79, 0.92);
}

