:root {
    --bg: #07090c;
    --panel: #11151b;
    --panel-2: #171c23;
    --line: #26303b;
    --text: #f4f7fb;
    --muted: #9da9b7;
    --accent: #36d399;
    --accent-2: #42a5f5;
    --warning: #ffc857;
    --danger: #ff6b6b;
    --shadow: 0 18px 60px rgba(0,0,0,.28);
    --radius: 18px;
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
    margin: 0;
    background:
        radial-gradient(circle at top right, rgba(66,165,245,.08), transparent 28rem),
        radial-gradient(circle at top left, rgba(54,211,153,.06), transparent 30rem),
        var(--bg);
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    min-height: 100vh;
}

a { color: #71c7ff; text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell {
    width: min(1380px, calc(100% - 32px));
    margin: 0 auto;
    padding: 24px 0 36px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 22px;
    padding: 10px 2px;
}

.eyebrow {
    color: var(--accent);
    font-size: .72rem;
    letter-spacing: .18em;
    font-weight: 800;
}

h1 {
    margin: 4px 0 0;
    font-size: clamp(1.3rem, 2.1vw, 2rem);
    letter-spacing: -.03em;
}

h2 { margin: 3px 0 0; font-size: 1.12rem; }
p { line-height: 1.55; }

.nav {
    display: flex;
    gap: 8px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(17,21,27,.84);
}

.nav a {
    color: var(--muted);
    padding: 10px 14px;
    border-radius: 10px;
    font-weight: 700;
    font-size: .9rem;
    text-decoration: none;
}

.nav a.active, .nav a:hover {
    color: var(--text);
    background: var(--panel-2);
}

.hero-card, .panel, .record-card, .empty-state {
    background: linear-gradient(180deg, rgba(23,28,35,.98), rgba(15,19,24,.98));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.hero-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    padding: 22px 24px;
    margin-bottom: 18px;
}

.hero-card strong { font-size: 1.03rem; }
.hero-card p { margin: 5px 0 0; color: var(--muted); max-width: 850px; }
.status-dot {
    width: 9px; height: 9px; display: inline-block; border-radius: 999px;
    background: var(--accent); margin-right: 8px; box-shadow: 0 0 18px rgba(54,211,153,.75);
}

.formula-chip {
    flex: 0 0 auto;
    color: #d8fff1;
    border: 1px solid rgba(54,211,153,.28);
    background: rgba(54,211,153,.08);
    padding: 10px 13px;
    border-radius: 12px;
    font: 700 .86rem/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.panel { padding: 22px; }
.span-2 { grid-column: span 2; }

.panel-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
}

.section-number {
    color: var(--accent);
    font-size: .68rem;
    font-weight: 900;
    letter-spacing: .12em;
}

.grid-4, .grid-2, .summary-grid {
    display: grid;
    gap: 14px;
}
.grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
.grid-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }

label { display: block; }
label > span {
    display: block;
    margin-bottom: 7px;
    color: #c8d1db;
    font-size: .83rem;
    font-weight: 700;
}

input, select, textarea {
    width: 100%;
    border: 1px solid #303b47;
    background: #0b0f14;
    color: var(--text);
    border-radius: 11px;
    padding: 11px 12px;
    outline: none;
    font: inherit;
    transition: border-color .15s ease, box-shadow .15s ease;
}

textarea { resize: vertical; }
input:focus, select:focus, textarea:focus {
    border-color: rgba(66,165,245,.85);
    box-shadow: 0 0 0 3px rgba(66,165,245,.12);
}

.input-unit {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    border: 1px solid #303b47;
    border-radius: 11px;
    overflow: hidden;
    background: #0b0f14;
}
.input-unit input { border: 0; border-radius: 0; box-shadow: none; }
.input-unit b {
    color: var(--muted);
    padding: 0 11px;
    font-size: .74rem;
    border-left: 1px solid #27313b;
}
.input-unit.compact { max-width: 190px; }

.bands-table-wrap { overflow-x: auto; }
.bands-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.bands-table-main { min-width: 940px; }
.bands-table th, .bands-table td {
    padding: 13px 12px;
    border-bottom: 1px solid #242d36;
    text-align: left;
    vertical-align: middle;
}
.bands-table th {
    color: #8f9cab;
    font-size: .73rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    font-weight: 800;
}
.bands-table td small { display: block; color: var(--muted); margin-top: 4px; }
.bands-table tr:last-child td { border-bottom: 0; }

.speed-result {
    display: inline-flex;
    min-width: 145px;
    justify-content: center;
    border-radius: 10px;
    padding: 9px 11px;
    color: #dffcf0;
    background: rgba(54,211,153,.08);
    border: 1px solid rgba(54,211,153,.22);
    font-weight: 800;
}
.speed-result.pending {
    color: #ffe4a3;
    background: rgba(255,200,87,.07);
    border-color: rgba(255,200,87,.22);
}

.current-speed {
    display: inline-flex;
    min-width: 145px;
    justify-content: center;
    border-radius: 10px;
    padding: 9px 11px;
    color: #e5f4ff;
    background: rgba(66,165,245,.09);
    border: 1px solid rgba(66,165,245,.26);
    font-weight: 800;
}
.current-speed.empty {
    color: #95a2af;
    background: rgba(149,162,175,.06);
    border-color: rgba(149,162,175,.18);
}
.band-status-group {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 7px;
}
.current-source {
    display: inline-flex;
    align-items: center;
    border: 1px solid rgba(66,165,245,.24);
    background: rgba(66,165,245,.07);
    color: #b9dcf5;
    border-radius: 999px;
    padding: 6px 10px;
    font-size: .74rem;
    font-weight: 800;
    white-space: nowrap;
}
.current-source.no-data {
    border-color: rgba(149,162,175,.18);
    background: rgba(149,162,175,.05);
    color: #95a2af;
}
.warning-text { color: var(--warning) !important; }
.legend, .muted { color: var(--muted); font-size: .82rem; }
.muted { margin: 12px 0 0; }

.actions-panel {
    display: flex;
    align-items: end;
    gap: 18px;
}
.grow { flex: 1; }

.primary-btn, .secondary-btn, .export-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border-radius: 11px;
    padding: 0 18px;
    font-weight: 900;
    cursor: pointer;
    text-decoration: none;
    border: 0;
    white-space: nowrap;
    font: inherit;
}
.primary-btn {
    color: #07110d;
    background: linear-gradient(135deg, #56e8ad, #31c98e);
    box-shadow: 0 10px 28px rgba(49,201,142,.18);
}
.primary-btn:hover { filter: brightness(1.06); text-decoration: none; }
.primary-btn.small { min-height: 42px; }
.secondary-btn {
    color: var(--text);
    border: 1px solid #303b47;
    background: #10151b;
}
.secondary-btn:hover { text-decoration: none; background: #171d25; }
.export-btn {
    color: #071019;
    background: linear-gradient(135deg, #75c9ff, #42a5f5);
    box-shadow: 0 10px 28px rgba(66,165,245,.16);
}
.export-btn:hover { filter: brightness(1.06); }
.muted-inline { color: var(--muted); }


.alert {
    border-radius: 13px;
    padding: 13px 15px;
    margin-bottom: 18px;
    border: 1px solid;
    font-weight: 700;
}
.alert.success { color: #d8ffef; background: rgba(54,211,153,.09); border-color: rgba(54,211,153,.3); }
.alert.error { color: #ffd8d8; background: rgba(255,107,107,.08); border-color: rgba(255,107,107,.3); }

.search-panel { margin-bottom: 18px; }
.search-form {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) minmax(150px, .7fr) auto auto auto;
    gap: 12px;
    align-items: end;
}

.results-head {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    color: var(--muted);
    margin: 18px 2px 10px;
    font-size: .88rem;
}
.results-head strong { color: var(--text); }

.record-card { padding: 22px; margin-bottom: 18px; }
.record-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 16px;
}
.record-date { color: var(--accent); font-weight: 900; font-size: .8rem; }
.record-badges { display: flex; gap: 8px; flex-wrap: wrap; }
.record-badges span {
    border: 1px solid #2c3742;
    background: #0d1217;
    color: #dce4ec;
    border-radius: 999px;
    padding: 7px 10px;
    font-size: .78rem;
    font-weight: 800;
}
.summary-grid { grid-template-columns: repeat(6, minmax(0,1fr)); margin-bottom: 18px; }
.summary-grid > div {
    padding: 12px;
    background: #0c1116;
    border: 1px solid #222c35;
    border-radius: 12px;
}
.summary-grid small { display: block; color: var(--muted); margin-bottom: 5px; }
.summary-grid strong { font-size: .92rem; }
.record-table .bands-table { min-width: 620px; }
.notes {
    margin-top: 16px;
    padding: 13px 14px;
    border: 1px solid #28323d;
    background: #0d1217;
    border-radius: 12px;
}
.notes small { color: var(--muted); }
.notes p { margin: 5px 0 0; }
.record-footer { color: #72808e; font-size: .74rem; margin-top: 13px; text-align: right; }

.empty-state { padding: 36px; text-align: center; }
.empty-state p { color: var(--muted); margin-bottom: 0; }

.calibration-table input { min-width: 150px; }
.calibration-note {
    margin-top: 16px;
    border: 1px solid rgba(255,200,87,.22);
    background: rgba(255,200,87,.06);
    color: #e9d59f;
    border-radius: 12px;
    padding: 13px 14px;
    line-height: 1.5;
}
.right-actions { display: flex; justify-content: flex-end; margin-top: 16px; }

.footer {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    color: #697684;
    font-size: .75rem;
    padding: 20px 4px 0;
}

@media (max-width: 980px) {
    .topbar { align-items: flex-start; flex-direction: column; }
    .nav {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    .form-grid { grid-template-columns: 1fr; }
    .span-2 { grid-column: auto; }
    .grid-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .summary-grid { grid-template-columns: repeat(3, minmax(0,1fr)); }
    .search-form { grid-template-columns: 1fr 1fr; }
    .hero-card { align-items: flex-start; flex-direction: column; }
    .actions-panel { flex-direction: column; align-items: stretch; }
    .time-reference-box { grid-template-columns: 1fr; }
    .band-status-group { align-items: flex-start; }
    .current-source { white-space: normal; }
}


@media (max-width: 640px) {
    .app-shell { width: min(100% - 16px, 1380px); padding-top: 10px; }
    .panel, .record-card, .hero-card, .empty-state { padding: 15px; border-radius: 15px; }
    .grid-4, .grid-2, .summary-grid, .search-form { grid-template-columns: 1fr; }
    .actions-panel, .record-header, .results-head, .footer { flex-direction: column; align-items: stretch; }
    .primary-btn, .secondary-btn, .export-btn { width: 100%; }
    .nav {
        display: grid;
        grid-template-columns: 1fr;
        width: 100%;
        gap: 8px;
        padding: 8px;
        overflow: visible;
    }
    .nav a {
        text-align: center;
        min-width: 0;
    }
    .bands-table-wrap {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding-bottom: 6px;
        scrollbar-width: thin;
    }
    .bands-table-main { min-width: 900px; }
    .speed-result, .current-speed { min-width: 132px; }
    input, select, textarea {
        font-size: 16px;
    }
    .results-head span,
    .record-footer {
        text-align: left;
    }
}


.no-margin { margin: 0; }

.time-reference-box {
    margin-top: 16px;
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(250px, .85fr);
    gap: 16px;
    align-items: stretch;
}

.time-reference-copy,
.time-reference-image {
    border: 1px solid #27313b;
    background: linear-gradient(180deg, rgba(12,17,22,.96), rgba(9,13,18,.96));
    border-radius: 14px;
}

.time-reference-copy {
    padding: 15px 16px;
}

.mini-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: #d8fff1;
    background: rgba(54,211,153,.08);
    border: 1px solid rgba(54,211,153,.22);
    border-radius: 999px;
    padding: 5px 10px;
    font-size: .72rem;
    font-weight: 900;
    letter-spacing: .04em;
    margin-bottom: 9px;
}

.time-reference-copy strong {
    display: block;
    margin-bottom: 7px;
    font-size: .98rem;
}

.time-reference-copy p {
    margin: 0 0 10px;
    color: var(--muted);
}

.time-reference-image {
    display: flex;
    flex-direction: column;
    padding: 10px;
    text-decoration: none;
    gap: 9px;
    transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease;
}

.time-reference-image:hover {
    text-decoration: none;
    border-color: rgba(66,165,245,.45);
    box-shadow: 0 10px 24px rgba(0,0,0,.22);
    transform: translateY(-1px);
}

.time-reference-image img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 10px;
    border: 1px solid #2c3742;
    object-fit: cover;
    background: #05070a;
}

.time-reference-image span {
    color: #b8c5d2;
    font-size: .8rem;
    font-weight: 700;
    text-align: center;
}
