:root {
    --bg: #020617;
    --surface: #111827;
    --surface-soft: #1f2937;
    --text: #f8fafc;
    --muted: #94a3b8;
    --border: #334155;
    --success: #16a34a;
    --error: #dc2626;
    --info: #0ea5e9;
    --accent: #818cf8;
}

[data-theme="light"] {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --text: #0f172a;
    --muted: #64748b;
    --border: #dbe3ee;
    --success: #16a34a;
    --error: #dc2626;
    --info: #0284c7;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background:
        radial-gradient(900px 420px at 50% 0%, rgba(99, 102, 241, 0.28), transparent 60%),
        radial-gradient(700px 300px at 20% 30%, rgba(14, 165, 233, 0.14), transparent 60%),
        var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, Segoe UI, sans-serif;
}
.app { display: flex; min-height: 100vh; }
.app.app--guest {
    display: block;
}
.sidebar {
    width: 260px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 100vh;
}
.sidebar-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.profile-block {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: rgba(148, 163, 184, 0.06);
}
.profile-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    flex: 0 0 40px;
    border-radius: 999px;
    border: 1px solid var(--border);
    display: grid;
    place-items: center;
    font-weight: 700;
}
.profile-meta {
    min-width: 0;
}
.profile-label {
    margin: 0;
    color: var(--muted);
    font-size: 12px;
}
.profile-name {
    margin: 4px 0 0;
    font-size: 14px;
    line-height: 1.2;
    word-break: break-word;
}
.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.nav-item {
    width: 100%;
    text-align: left;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    padding: 10px 12px;
    cursor: pointer;
}
.nav-item.is-active {
    background: color-mix(in srgb, var(--accent) 22%, transparent);
    border-color: color-mix(in srgb, var(--accent) 62%, transparent);
}
.sidebar-actions {
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-top: 4px;
}
.main { flex: 1; padding: 16px; }
.topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
}
.topbar-spacer {
    flex: 1;
    min-width: 0;
}
.card {
    position: relative;
    margin-top: 16px;
    max-width: 620px;
    background: var(--surface-soft);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
}
.waybill-query-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    background: rgba(148, 163, 184, 0.04);
}
.waybill-query-card h3 {
    margin: 0 0 10px;
    font-size: 16px;
}
.waybill-search-form {
    display: flex;
    gap: 10px;
    align-items: center;
}
.waybill-input {
    flex: 1;
    min-width: 0;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    padding: 10px 12px;
    font-size: 15px;
    -webkit-tap-highlight-color: transparent;
}
.waybill-input:focus,
.waybill-input:focus-visible {
    outline: none;
    box-shadow: none;
    border-color: var(--border);
}
[data-theme="light"] .waybill-input:focus,
[data-theme="light"] .waybill-input:focus-visible {
    background: #ffffff;
}
.waybill-input:-webkit-autofill,
.waybill-input:-webkit-autofill:hover,
.waybill-input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text);
    box-shadow: 0 0 0 1000px var(--surface) inset;
    transition: background-color 9999s ease-out;
}
[data-theme="light"] .waybill-input:-webkit-autofill,
[data-theme="light"] .waybill-input:-webkit-autofill:hover,
[data-theme="light"] .waybill-input:-webkit-autofill:focus {
    box-shadow: 0 0 0 1000px #ffffff inset;
}
@media (min-width: 900px) {
    .waybill-search-form .waybill-input {
        flex: 0 0 auto;
        width: 20ch;
        max-width: 20ch;
        min-width: 0;
    }
}
.waybill-legend strong {
    font-weight: 700;
    color: var(--text);
}
.waybill-search-btn {
    border-color: color-mix(in srgb, var(--accent) 70%, var(--border));
}
.waybill-legend {
    margin: 10px 0 0;
    color: var(--muted);
    font-size: 13px;
}
.waybill-result {
    margin-top: 14px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    background: rgba(17, 24, 39, 0.4);
}
[data-theme="light"] .waybill-result {
    background: rgba(255, 255, 255, 0.9);
}
.waybill-result-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
}
.waybill-result-header h3 {
    margin: 0;
    font-size: 18px;
    min-width: 0;
    flex: 1 1 auto;
    line-height: 1.25;
}
.waybill-result-header h3 .waybill-title-nb {
    font-weight: 700;
    color: var(--text);
}
.arrival-pill {
    border-radius: 999px;
    font-size: 12px;
    padding: 4px 10px;
    border: 1px solid var(--border);
    white-space: nowrap;
    flex: 0 0 auto;
    align-self: center;
}
.arrival-pill.ok {
    border-color: rgba(22, 163, 74, 0.6);
    color: #86efac;
}
.arrival-pill.warn {
    border-color: rgba(234, 179, 8, 0.6);
    color: #fde68a;
}
.waybill-meta {
    margin: 0 0 6px;
    color: var(--muted);
}
.waybill-grid {
    margin-top: 12px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
}
.waybill-grid div {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.waybill-grid-label {
    font-weight: 700;
    color: var(--text);
    font-size: 13px;
}
.waybill-grid-value {
    font-size: 16px;
    font-variant-numeric: tabular-nums;
    color: var(--text);
}
.waybill-warning {
    margin: 10px 0 0;
    color: #facc15;
    font-size: 13px;
}
.waybill-loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(2, 6, 23, 0.74);
    backdrop-filter: blur(2px);
}
.waybill-loading-overlay p {
    margin: 0;
    font-size: 14px;
    color: #f1f5f9;
}
.app.app--guest .main {
    min-height: 100vh;
    display: block;
    padding: 20px;
}
.app.app--guest .card {
    width: min(100%, 430px);
    margin: 0 auto;
    background: rgba(17, 24, 39, 0.72);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(148, 163, 184, 0.28);
    box-shadow: 0 20px 60px rgba(2, 6, 23, 0.55);
}
[data-theme="light"] .app.app--guest .card {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(148, 163, 184, 0.34);
    box-shadow: 0 14px 36px rgba(15, 23, 42, 0.12);
}
.app.app--guest #loginSection {
    text-align: center;
}
.auth-method-box {
    margin-top: 10px;
    padding: 14px;
    border: 1px solid rgba(255, 255, 255, 0.55);
    border-radius: 12px;
}
[data-theme="light"] .auth-method-box {
    border-color: rgba(15, 23, 42, 0.2);
}
.auth-method-title {
    margin: 0 0 12px 0;
    color: var(--muted);
    font-size: 14px;
}
.auth-vpn-hint {
    margin: -6px 0 14px;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 12px;
    line-height: 1.35;
    color: var(--muted);
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid rgba(148, 163, 184, 0.22);
}
[data-theme="light"] .auth-vpn-hint {
    background: rgba(15, 23, 42, 0.04);
    border-color: rgba(15, 23, 42, 0.1);
}
.app.app--guest #telegramAuthButton {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 52px;
}
.btn {
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface-soft);
    color: var(--text);
    padding: 10px 12px;
    cursor: pointer;
}
.btn-ghost { background: transparent; }
.btn-danger { background: transparent; color: #ff8b8b; border-color: rgba(220, 38, 38, 0.5); }
/* В светлой теме общий --border слишком светлый: ободок «Меню» как у текста */
[data-theme="light"] .topbar .btn.btn-ghost {
    border-color: color-mix(in srgb, var(--text) 88%, var(--border));
}
.hidden { display: none !important; }

.notification-root {
    position: fixed;
    right: 12px;
    bottom: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
}
.notification {
    min-width: 200px;
    max-width: 320px;
    padding: 10px 12px;
    border-radius: 10px;
    color: #fff;
}
.notification.success { background: var(--success); }
.notification.error { background: var(--error); }
.notification.info { background: var(--info); }
.widget-loader {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 150px;
    color: var(--muted);
}
.spinner {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 3px solid rgba(148, 163, 184, 0.25);
    border-top-color: var(--accent);
    animation: spin 0.8s linear infinite;
}
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}
.startup-loader {
    display: none;
}
.theme-fab {
    width: 42px;
    height: 42px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-soft);
    color: var(--text);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    flex: 0 0 auto;
}
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(2, 6, 23, 0.62);
    z-index: 250;
}

@media (min-width: 901px) {
    .topbar {
        position: fixed;
        top: max(14px, env(safe-area-inset-top, 0px));
        right: max(14px, env(safe-area-inset-right, 0px));
        left: auto;
        width: auto;
        max-width: none;
        margin: 0;
        padding: 0;
        z-index: 200;
        background: transparent;
        pointer-events: none;
    }
    .topbar .theme-fab {
        pointer-events: auto;
    }
    .topbar-spacer {
        display: none;
    }
}

.app.app--guest .topbar {
    position: sticky;
    top: 0;
    right: auto;
    left: auto;
    width: 100%;
    max-width: none;
    margin: 0 0 12px;
    padding: max(8px, env(safe-area-inset-top, 0px)) 0 6px;
    z-index: 120;
    background: transparent;
    border: 0;
    pointer-events: auto;
    justify-content: flex-end;
}
.app.app--guest .topbar .theme-fab {
    pointer-events: auto;
}
.app.app--guest .topbar-spacer {
    display: none;
}

@media (max-width: 900px) {
    .theme-fab {
        width: 42px;
        height: 42px;
        min-width: 42px;
        min-height: 42px;
        font-size: 26px;
        box-sizing: border-box;
    }
    /* Как driver app: прозрачная полоса в потоке, без «плашки» — кнопки по краям, контент не перекрывается */
    .app:not(.app--guest) .topbar {
        position: static;
        z-index: auto;
        margin: 0 0 10px;
        padding: max(6px, env(safe-area-inset-top, 0px)) 0 6px;
        background: transparent;
        border: none;
        box-shadow: none;
        justify-content: space-between;
    }
    .app:not(.app--guest) .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100dvh;
        min-height: 100dvh;
        max-height: 100dvh;
        z-index: 260;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: 0 12px 40px rgba(2, 6, 23, 0.45);
        overflow-y: auto;
        padding-bottom: calc(16px + env(safe-area-inset-bottom));
    }
    .app:not(.app--guest) .sidebar.open {
        transform: translateX(0);
    }
    .app:not(.app--guest) .main {
        padding: 14px;
    }
    .app:not(.app--guest) .card {
        margin-top: 0;
    }
    .waybill-search-form {
        flex-direction: column;
        align-items: stretch;
    }
    .waybill-grid {
        grid-template-columns: 1fr;
    }
}
