:root {
    --bg: #f4f5f2;
    --surface: #ffffff;
    --ink: #1c2420;
    --muted: #5e6963;
    --line: #e2e6e1;
    --line-strong: #d3d9d4;
    --green-950: #10241c;
    --green-900: #16352a;
    --green-800: #1e4636;
    --green-700: #1f6b4a;
    --green-100: #e7f2ec;
    --amber-700: #8d5a16;
    --amber-100: #f8f1e3;
    --red-700: #8d3d32;
    --red-100: #f8ece9;
    --shadow: 0 1px 2px rgba(16, 28, 22, 0.04);
    --sidebar: 248px;
    --font: "IBM Plex Sans", "Segoe UI", sans-serif;
    --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    font-size: 15px;
    line-height: 1.5;
}

a { color: var(--green-800); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }

img { max-width: 100%; }

.shell {
    min-height: 100vh;
    display: grid;
    grid-template-columns: var(--sidebar) minmax(0, 1fr);
}

.sidebar {
    background: var(--green-950);
    color: #e7eee9;
    padding: 22px 16px 18px;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.brand {
    display: flex;
    gap: 12px;
    align-items: center;
    color: #f4f7f4;
    text-decoration: none;
    padding: 0 8px;
}

.brand:hover { text-decoration: none; }

.brand strong {
    display: block;
    font-size: 0.98rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.brand small {
    display: block;
    color: #b7c7be;
    font-size: 0.78rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.sidebar-kicker {
    margin: 22px 8px 8px;
    color: #8ea399;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.side-nav { display: flex; flex-direction: column; gap: 2px; }

.side-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #d5e2da;
    text-decoration: none;
    padding: 9px 10px;
    border-radius: 6px;
    font-size: 0.94rem;
}

.side-nav a svg { width: 16px; height: 16px; stroke-width: 1.75; }

.side-nav a:hover { background: rgba(255, 255, 255, 0.05); text-decoration: none; }

.side-nav a.is-active {
    background: var(--green-800);
    color: #ffffff;
}

.sidebar-user {
    margin-top: auto;
    padding: 14px 8px 0;
    display: grid;
    gap: 2px;
}

.sidebar-user strong {
    color: #f4f7f4;
    font-size: 0.9rem;
    font-weight: 600;
}

.sidebar-user small,
.sidebar-user a {
    color: #b7c7be;
    font-size: 0.78rem;
}

.sidebar-user a:hover { color: #ffffff; }

.sidebar-user form { margin-top: 8px; }

.sidebar-signout {
    width: 100%;
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: #e7eee9;
    border-radius: 6px;
    padding: 6px 10px;
    cursor: pointer;
}

.sidebar-signout:hover { background: rgba(255, 255, 255, 0.06); }

.sidebar-foot {
    margin-top: 14px;
    padding: 0 8px;
    color: #9aafa4;
    font-size: 0.78rem;
}

.sidebar-foot p { margin: 0; }

.workspace { min-width: 0; }

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    padding: 18px 28px 14px;
    background: rgba(244, 245, 242, 0.92);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 5;
}

.topbar-title { display: flex; align-items: flex-start; gap: 10px; }

.eyebrow {
    margin: 0 0 2px;
    color: var(--muted);
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

h1 {
    margin: 0;
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: -0.015em;
    line-height: 1.25;
}

.topbar-tools {
    display: flex;
    align-items: center;
    gap: 12px;
}

.nav-toggle {
    display: none;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    border-radius: 6px;
    width: 36px;
    height: 36px;
    padding: 0;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    border-radius: 999px;
    padding: 6px 10px;
    color: var(--green-900);
    font-size: 0.78rem;
    white-space: nowrap;
}

.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--green-700);
}

.content { padding: 22px 28px 40px; }

.notice {
    border: 1px solid #e4d3a8;
    background: #fbf7ee;
    color: #5c4a28;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
    font-size: 0.92rem;
}

.notice strong { font-weight: 600; }

.notice-ok {
    border-color: #c9ddd2;
    background: #f3f8f5;
    color: #1e4636;
}

.notice-bad {
    border-color: #efd4cf;
    background: var(--red-100);
    color: var(--red-700);
}

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

.stat, .panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.stat {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px 14px 12px;
}

.stat-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    display: grid;
    place-items: center;
    background: var(--green-100);
    color: var(--green-800);
    flex: none;
}

.stat-icon svg { width: 16px; height: 16px; }

.stat-icon.tone-abnormal { background: var(--red-100); color: var(--red-700); }
.stat-icon.tone-pending { background: var(--amber-100); color: var(--amber-700); }

.stat-label {
    margin: 0;
    color: var(--muted);
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.stat-value {
    margin: 2px 0 0;
    font-size: 1.45rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.stat-note {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.75rem;
}

.section-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin: 22px 0 10px;
}

.section-head h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.section-head p, .quiet {
    margin: 0;
    color: var(--muted);
    font-size: 0.84rem;
}

.chart-grid {
    display: grid;
    grid-template-columns: minmax(260px, 0.8fr) minmax(0, 1.2fr);
    gap: 12px;
}

.panel { padding: 14px 16px 16px; }

.panel h3 {
    margin: 0 0 4px;
    font-size: 0.95rem;
    font-weight: 600;
}

.chart-box { position: relative; height: 260px; margin-top: 8px; }
.chart-box.tall { height: 320px; }

.table-wrap { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

.data-table th {
    text-align: left;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
}

.data-table td {
    padding: 9px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

.data-table tbody tr:hover td { background: #f7f8f6; }
.data-table tbody tr:last-child td { border-bottom: 0; }

.data-table a { font-weight: 500; }

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    border: 1px solid transparent;
    white-space: nowrap;
}

.badge-normal { color: var(--green-800); background: var(--green-100); border-color: #cfe3d7; }
.badge-abnormal { color: var(--red-700); background: var(--red-100); border-color: #efd4cf; }
.badge-synced { color: var(--green-800); background: #f3f7f4; border-color: var(--line-strong); }
.badge-pending { color: var(--amber-700); background: var(--amber-100); border-color: #ead7b4; }
.badge-off { color: var(--muted); background: #f4f5f3; border-color: var(--line); }

.thumb {
    width: 56px;
    height: 42px;
    border: 1px solid var(--line);
    background: #f3f5f2;
    display: grid;
    place-items: center;
    overflow: hidden;
}

.thumb img { width: 100%; height: 100%; object-fit: contain; }

.mono { font-family: var(--mono); font-size: 0.78rem; }

.filters {
    display: grid;
    grid-template-columns: 1.4fr repeat(4, minmax(0, 1fr)) auto;
    gap: 10px;
    align-items: end;
    margin-bottom: 12px;
}

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.field span, .field label {
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
}

input[type="text"], input[type="search"], input[type="date"], input[type="email"], input[type="password"], select, textarea {
    width: 100%;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    border-radius: 6px;
    padding: 8px 10px;
    outline: none;
}

textarea { min-height: 76px; resize: vertical; }

input:focus, select:focus, textarea:focus { border-color: var(--green-700); }

.btn, .btn-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 6px;
    padding: 8px 12px;
    border: 1px solid var(--green-800);
    background: var(--green-800);
    color: #f7fbf8;
    text-decoration: none;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 500;
}

.btn:hover, .btn-link:hover { background: var(--green-900); text-decoration: none; }

.btn-ghost {
    background: var(--surface);
    color: var(--ink);
    border-color: var(--line-strong);
}

.btn-ghost:hover { background: #f7f8f6; }

.btn-row { display: flex; gap: 8px; align-items: center; }

.pager {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding-top: 12px;
}

.pager-meta { margin: 0; color: var(--muted); font-size: 0.82rem; }

.pager-links { display: flex; flex-wrap: wrap; gap: 4px; }

.pager-link {
    min-width: 32px;
    text-align: center;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--ink);
    border-radius: 6px;
    padding: 4px 8px;
    font-size: 0.82rem;
    text-decoration: none;
}

a.pager-link:hover { border-color: var(--green-700); text-decoration: none; }

.pager-link.is-current { background: var(--green-900); color: white; border-color: var(--green-900); }
.pager-link.is-disabled { color: #9aa39d; }

.detail-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(300px, 0.85fr);
    gap: 14px;
    align-items: start;
}

.photo-stage {
    background: #eef1ee;
    border: 1px solid var(--line);
    min-height: 280px;
    display: grid;
    place-items: center;
    padding: 16px;
}

.photo-stage img {
    max-width: 100%;
    max-height: 640px;
    object-fit: contain;
}

.photo-caption {
    margin: 12px 0 0;
    font-size: 0.95rem;
}

.photo-caption strong { font-weight: 600; }

.facts { margin: 0; display: grid; gap: 10px; }

.facts div { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 8px; }

.facts dt { margin: 0; color: var(--muted); font-size: 0.78rem; padding-top: 2px; }
.facts dd { margin: 0; overflow-wrap: anywhere; }

.hash-row { display: flex; gap: 8px; align-items: flex-start; }
.hash-row code { font-family: var(--mono); font-size: 0.75rem; line-height: 1.45; }

.map-frame {
    height: 280px;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    margin-top: 8px;
    background: #e7ece8;
}

.map-frame.distribution-map { height: 440px; }

.map-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    color: var(--muted);
    font-size: 0.82rem;
}

.map-legend span { display: inline-flex; align-items: center; gap: 6px; }

.map-swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.map-swatch.normal { background: #1f6b4a; }
.map-swatch.abnormal { background: #a34b32; }

.map-note { margin: 8px 0 0; }

.form-grid { display: grid; grid-template-columns: 1.2fr 0.8fr; gap: 10px; }
.form-grid .wide { grid-column: 1 / -1; }

.error {
    color: var(--red-700);
    font-size: 0.78rem;
    margin: 0;
}

.split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.7fr); gap: 14px; align-items: start; }

.empty {
    padding: 28px 8px;
    text-align: center;
    color: var(--muted);
}

.back-link { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 12px; font-size: 0.88rem; }

.search-inline { min-width: 220px; }

.settings-list { margin: 0; padding-left: 18px; color: var(--ink); }
.settings-list li { margin: 4px 0; }

.roadmap { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.roadmap td { padding: 8px 0; border-bottom: 1px solid var(--line); vertical-align: top; }
.roadmap td:first-child { width: 88px; color: var(--muted); }

body.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px 16px;
    background:
        radial-gradient(640px 280px at 50% -40px, rgba(255, 255, 255, 0.08), transparent 70%),
        #10241c;
}

.auth-card {
    width: min(420px, 100%);
    justify-self: center;
    background: var(--surface);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.28);
    padding: 28px 28px 22px;
}

.auth-panel { max-width: 460px; }

.auth-brand {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 22px;
    color: inherit;
}

.auth-brand img {
    border-radius: 8px;
}

.auth-brand strong { display: block; font-size: 1rem; font-weight: 600; }
.auth-brand small {
    display: block;
    color: var(--muted);
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.auth-card h1 { margin-bottom: 6px; }

.auth-card .quiet { margin: 0; }

.auth-card input[type="email"],
.auth-card input[type="password"],
.auth-card input[type="text"] {
    padding: 10px 12px;
    background: #fbfcfb;
}

.auth-form {
    display: grid;
    gap: 14px;
    margin-top: 18px;
}

.auth-form .btn,
.auth-card > form .btn {
    width: 100%;
    padding: 10px 12px;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.88rem;
    color: var(--ink);
}

.check input { width: auto; margin: 0; }

.auth-note {
    margin-top: 18px;
    padding: 12px 14px;
    border-radius: 10px;
    background: #f6f7f5;
    border: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.84rem;
}

.auth-note p { margin: 0 0 8px; }

.auth-note-title {
    color: var(--ink);
    font-weight: 600;
    font-size: 0.82rem;
}

.auth-accounts { display: grid; gap: 8px; }

.auth-accounts div {
    display: grid;
    gap: 1px;
}

.auth-accounts span {
    color: var(--ink);
    font-size: 0.78rem;
    font-weight: 600;
}

.auth-accounts code {
    font-family: var(--mono);
    font-size: 0.75rem;
    color: var(--green-900);
}

.auth-card .notice { margin-top: 14px; }
.auth-card .notice ul { margin: 0; }

:focus-visible {
    outline: 2px solid var(--green-700);
    outline-offset: 2px;
}

@media (max-width: 1100px) {
    .stats, .chart-grid, .filters, .detail-grid, .split, .form-grid { grid-template-columns: 1fr 1fr; }
    .filters { grid-template-columns: 1fr 1fr; }
    .form-grid .wide { grid-column: auto; }
}

@media (max-width: 860px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar {
        position: fixed;
        z-index: 20;
        transform: translateX(-105%);
        width: min(280px, 86vw);
        transition: transform 160ms ease;
    }
    body.nav-open .sidebar { transform: none; }
    .nav-toggle { display: inline-flex; }
    .content, .topbar { padding-left: 16px; padding-right: 16px; }
    .stats, .chart-grid, .detail-grid, .split, .filters, .form-grid { grid-template-columns: 1fr; }
    .topbar { align-items: flex-start; flex-direction: column; }
    .facts div { grid-template-columns: 1fr; gap: 2px; }
    .pager { flex-direction: column; align-items: flex-start; }
}
