/* ─── Reset ─── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ─── Design tokens ─── */
:root {
    --black:    #080808;
    --black2:   #0f0f0f;
    --black3:   #141414;
    --black4:   #1a1a1a;
    --black5:   #222222;

    --line:     rgba(255,255,255,0.07);
    --line2:    rgba(255,255,255,0.12);

    --white:    #f5f5f5;
    --dim:      #888;
    --dimmer:   #555;
    --dimmest:  #333;

    --blue:     #3b82f6;
    --blue-l:   rgba(59,130,246,0.18);
    --green:    #22c55e;
    --green-l:  rgba(34,197,94,0.14);
    --amber:    #f59e0b;
    --amber-l:  rgba(245,158,11,0.14);
    --red:      #ef4444;
    --red-l:    rgba(239,68,68,0.14);

    --sidebar: 210px;
    --font: 'Inter', system-ui, -apple-system, sans-serif;
    --mono: 'SF Mono', 'Fira Code', 'Fira Mono', 'Roboto Mono', monospace;
}

html { font-size: 13px; }

body {
    font-family: var(--font);
    background: var(--black2);
    color: var(--white);
    line-height: 1.5;
    height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ─── Layout ─── */
.layout { display: flex; height: 100vh; width: 100vw; }
.main   { margin-left: var(--sidebar); flex: 1; display: flex; flex-direction: column; min-width: 0; }

/* ═══════════════════════════════════
   SIDEBAR
═══════════════════════════════════ */
.sidebar {
    width: var(--sidebar);
    background: var(--black);
    border-right: 1px solid var(--line);
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    z-index: 100;
    display: flex;
    flex-direction: column;
    padding: 0;
}

/* Logo */
.brand {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 16px 16px 14px;
    border-bottom: 1px solid var(--line);
}
.brand-logo {
    width: 26px; height: 26px;
    border-radius: 6px;
    background: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.68rem;
    font-weight: 800;
    color: #fff;
    letter-spacing: -0.03em;
    flex-shrink: 0;
}
.brand-name { font-size: 0.82rem; font-weight: 700; color: var(--white); letter-spacing: -0.01em; }
.brand-sub  { font-size: 0.63rem; color: var(--dimmer); text-transform: uppercase; letter-spacing: 0.07em; margin-top: 1px; }

/* Nav */
.sidenav { flex: 1; padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 6px;
    background: transparent;
    border: none;
    border-left: 2px solid transparent;
    color: var(--dim);
    cursor: pointer;
    text-align: left;
    width: 100%;
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    position: relative;
}
.nav-item:hover { background: var(--black3); color: var(--white); }
.nav-item.active {
    background: rgba(59,130,246,0.08);
    color: var(--white);
    border-left-color: var(--blue);
}
.nav-ico  { width: 14px; text-align: center; font-size: 0.85rem; flex-shrink: 0; opacity: 0.7; }
.nav-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.nav-label{ font-size: 0.78rem; font-weight: 600; line-height: 1.3; }
.nav-sub  { font-size: 0.63rem; color: var(--dimmer); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.nav-item.active .nav-sub { color: #666; }

.live-dot {
    width: 5px; height: 5px;
    border-radius: 50%;
    background: var(--amber);
    opacity: 0;
    flex-shrink: 0;
    transition: opacity 0.2s;
}
.live-dot.active { opacity: 1; animation: blink 1.4s ease infinite; }
@keyframes blink { 0%,100%{ opacity:1; } 50%{ opacity:0.3; } }

.sidebar-foot {
    border-top: 1px solid var(--line);
    padding: 10px 18px;
    display: flex;
    justify-content: space-between;
    font-size: 0.67rem;
    color: var(--dimmest);
}
.foot-val { color: var(--dimmer); }

/* ═══════════════════════════════════
   TOPBAR
═══════════════════════════════════ */
.topbar {
    background: var(--black);
    border-bottom: 1px solid var(--line);
    padding: 0 20px;
    height: 52px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    gap: 12px;
}

.metrics { display: flex; gap: 6px; }

.metric {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 5px 10px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--black3);
    transition: border-color 0.15s;
}
.metric:hover { border-color: var(--line2); }
.metric-dot { width: 6px; height: 6px; border-radius: 50%; flex-shrink: 0; }
.metric-dot.blue   { background: var(--blue); }
.metric-dot.green  { background: var(--green); }
.metric-dot.red    { background: var(--red); }
.metric-dot.grey   { background: var(--dimmer); }
.metric-val { font-size: 0.8rem; font-weight: 700; color: var(--white); font-variant-numeric: tabular-nums; }
.metric-key { font-size: 0.65rem; color: var(--dim); text-transform: uppercase; letter-spacing: 0.04em; }

.topbar-right { display: flex; align-items: center; gap: 10px; }
.status-pill {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    color: var(--dim);
    padding: 4px 10px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: var(--black3);
}
.status-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--green); flex-shrink: 0; }
.status-dot.scanning { background: var(--amber); animation: blink 1s infinite; }

.btn-refresh {
    padding: 5px 12px;
    background: var(--black3);
    border: 1px solid var(--line2);
    border-radius: 6px;
    color: var(--dim);
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    font-family: var(--font);
    transition: all 0.15s;
    letter-spacing: 0.01em;
}
.btn-refresh:hover { background: var(--black5); color: var(--white); border-color: var(--line2); }
.btn-refresh:active { transform: scale(0.97); }

/* ─── Scan Progress Bar ─── */
.scan-bar {
    height: 2px;
    background: var(--black3);
    position: relative;
    overflow: hidden;
    display: none;
}
.scan-bar.visible { display: block; }
.scan-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #8b5cf6, #ec4899, #f59e0b);
    background-size: 200% 100%;
    animation: gradient-slide 2s linear infinite;
    transition: width 0.6s ease;
    border-radius: 0 2px 2px 0;
}
@keyframes gradient-slide { 0%{ background-position: 0% 0%; } 100%{ background-position: -200% 0%; } }

/* ─── Scan notice ─── */
.scan-notice {
    padding: 7px 20px;
    background: rgba(245,158,11,0.06);
    border-bottom: 1px solid rgba(245,158,11,0.1);
    font-size: 0.73rem;
    color: #b38500;
    display: none;
    align-items: center;
    gap: 8px;
}
.scan-notice.visible { display: flex; }
.scan-notice-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--amber); animation: blink 1s infinite; flex-shrink: 0; }

/* ═══════════════════════════════════
   CONTENT
═══════════════════════════════════ */
.content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.tab { display: none; height: 100%; flex-direction: column; overflow: hidden; }
.tab.active { display: flex; }

/* ─── Tab toolbar ─── */
.tab-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
    border-bottom: 1px solid var(--line);
    gap: 12px;
    flex-wrap: wrap;
    background: var(--black2);
    flex-shrink: 0;
}
.tab-title { font-size: 0.9rem; font-weight: 700; color: var(--white); letter-spacing: -0.02em; }
.tab-desc  { font-size: 0.7rem; color: var(--dim); margin-top: 2px; }
.filters   { display: flex; gap: 6px; flex-wrap: wrap; }

.f-input, .f-select {
    padding: 5px 10px;
    background: var(--black3);
    border: 1px solid var(--line);
    border-radius: 5px;
    color: var(--white);
    font-size: 0.75rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.15s;
}
.f-input:focus, .f-select:focus { border-color: rgba(59,130,246,0.4); }
.f-input::placeholder { color: var(--dimmest); }
.f-input  { width: 190px; }
.f-select { cursor: pointer; }
.f-select option { background: #111; }

/* ═══════════════════════════════════
   SCHEMA TABLE
═══════════════════════════════════ */
.tbl-wrap { flex: 1; overflow: auto; }

.data-tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.78rem;
}

.data-tbl thead th {
    padding: 9px 16px;
    text-align: left;
    font-size: 0.62rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.07em;
    color: var(--dimmer);
    border-bottom: 1px solid var(--line);
    white-space: nowrap;
    background: var(--black);
    position: sticky;
    top: 0;
    z-index: 30;
}
.data-tbl thead th.r { text-align: right; }

.data-tbl tbody tr {
    border-bottom: 1px solid var(--line);
    transition: background 0.1s;
}
.data-tbl tbody tr:last-child { border-bottom: none; }
.data-tbl tbody tr:nth-child(even) { background: rgba(255,255,255,0.012); }
.data-tbl tbody tr:hover td { background: rgba(59,130,246,0.05); }
.data-tbl tbody tr.row-err { border-left: 2px solid var(--red); }
.data-tbl tbody tr.row-err:hover td { background: rgba(239,68,68,0.04); }
.data-tbl tbody tr.row-pending { opacity: 0.45; }

.data-tbl td {
    padding: 8px 16px;
    color: var(--dim);
    white-space: nowrap;
}
.data-tbl td.r { text-align: right; font-variant-numeric: tabular-nums; }
.data-tbl td.c-db     { font-weight: 600; color: var(--white); max-width: 200px; overflow: hidden; text-overflow: ellipsis; }
.data-tbl td.c-tbl    { font-family: var(--mono); font-size: 0.72rem; color: #667; }
.data-tbl td.c-rows   { color: var(--white); }
.data-tbl td.c-cols   { color: var(--dim); }
.data-tbl td.c-cols.warn { color: var(--amber); font-weight: 600; }
.data-tbl td.c-time   { color: var(--dimmest); font-size: 0.72rem; }
.data-tbl td.c-err-msg { color: var(--red); font-size: 0.72rem; }

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    border-radius: 4px;
    font-size: 0.65rem;
    font-weight: 600;
    letter-spacing: 0.03em;
    border: 1px solid transparent;
}
.b-ok      { background: var(--green-l); color: var(--green); border-color: rgba(34,197,94,0.15); }
.b-err     { background: var(--red-l);   color: var(--red);   border-color: rgba(239,68,68,0.15); }
.b-warn    { background: var(--amber-l); color: var(--amber); border-color: rgba(245,158,11,0.15); }
.b-pending { background: rgba(255,255,255,0.04); color: var(--dimmer); }

/* ═══════════════════════════════════
   IMAGE GRID
═══════════════════════════════════ */
.card-grid {
    padding: 16px 20px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    align-content: start;
    gap: 12px;
    flex: 1;
    overflow-y: auto;
}

.img-card {
    background: var(--black);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    transition: border-color 0.15s;
}
.img-card:hover { border-color: var(--line2); }
.img-card.pending { opacity: 0.55; }

.card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}
.card-db   { font-size: 0.82rem; font-weight: 700; color: var(--white); margin-bottom: 2px; }
.card-meta { font-size: 0.67rem; color: var(--dimmest); }

/* Totals row */
.card-totals {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 5px;
    margin-bottom: 10px;
}
.tot-cell {
    background: var(--black3);
    border-radius: 5px;
    padding: 6px 5px;
    text-align: center;
}
.tot-v { font-size: 0.85rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.tot-v.blue   { color: #60a5fa; }
.tot-v.green  { color: var(--green); }
.tot-v.amber  { color: var(--amber); }
.tot-v.red    { color: var(--red); }
.tot-k { font-size: 0.6rem; color: var(--dimmest); text-transform: uppercase; letter-spacing: 0.04em; margin-top: 2px; }

/* Bar */
.card-bar {
    height: 3px;
    background: var(--black5);
    border-radius: 3px;
    overflow: hidden;
    display: flex;
    margin-bottom: 12px;
}
.bar-seg { height: 100%; transition: width 0.6s ease; }
.bar-seg.green  { background: var(--green); }
.bar-seg.amber  { background: var(--amber); }
.bar-seg.red    { background: var(--red); }
.bar-shimmer {
    flex: 1;
    background: linear-gradient(90deg, var(--black3) 0%, var(--black5) 50%, var(--black3) 100%);
    background-size: 200% 100%;
    animation: shimmer 1.8s linear infinite;
}
@keyframes shimmer { 0%{ background-position: 200% 0; } 100%{ background-position: -200% 0; } }

/* Breakdown mini-table */
.bk-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.72rem;
    table-layout: fixed;
    border-top: 1px solid var(--line);
}
.bk-table thead th {
    padding: 5px 4px;
    font-size: 0.59rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--dimmest);
    border-bottom: 1px solid var(--line);
    text-align: right;
}
.bk-table thead th:first-child { text-align: left; width: 44%; }
.bk-table thead th:nth-child(n+2):nth-child(-n+5) { width: 11%; }
.bk-table thead th:last-child { width: 9%; }

.bk-table tbody tr { border-bottom: 1px solid rgba(255,255,255,0.04); }
.bk-table tbody tr:last-child { border-bottom: none; }
.bk-table tbody tr:hover td { background: rgba(255,255,255,0.025); }
.bk-table td {
    padding: 5px 4px;
    color: var(--dim);
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.bk-table td:first-child { text-align: left; }
.td-name { font-family: var(--mono); font-size: 0.68rem; color: var(--dim) !important; display: block; overflow: hidden; text-overflow: ellipsis; }
.td-name.absent { color: var(--dimmest) !important; font-style: italic; }
.td-ok   { color: var(--green); font-variant-numeric: tabular-nums; }
.td-warn { color: var(--amber); font-variant-numeric: tabular-nums; }
.td-err  { color: var(--red);   font-variant-numeric: tabular-nums; }
.td-num  { font-variant-numeric: tabular-nums; }
.td-pct  { font-weight: 600; font-size: 0.7rem; }
.td-nil  { color: var(--dimmest); font-size: 0.68rem; font-style: italic; text-align: left !important; padding-left: 5px !important; }

/* ─── States ─── */
.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 56px 20px;
    color: var(--dimmer);
    font-size: 0.8rem;
}
.spinner {
    width: 18px; height: 18px;
    border: 1.5px solid var(--line2);
    border-top-color: var(--blue);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to{ transform: rotate(360deg); } }

/* ─── Toasts ─── */
.toast-wrap { position: fixed; bottom: 16px; right: 16px; z-index: 999; display: flex; flex-direction: column; gap: 5px; }
.toast {
    background: var(--black4);
    border: 1px solid var(--line2);
    border-left: 2px solid var(--blue);
    border-radius: 6px;
    padding: 8px 13px;
    font-size: 0.75rem;
    color: var(--white);
    box-shadow: 0 4px 20px rgba(0,0,0,0.5);
    animation: slide-up 0.2s ease;
}
@keyframes slide-up { from{ opacity:0; transform:translateY(6px); } to{ opacity:1; transform:translateY(0); } }

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .sidebar { width: 48px; padding: 10px 6px; }
    .brand-name, .brand-sub, .nav-info, .live-dot, .sidebar-foot { display: none; }
    .nav-ico { margin: auto; font-size: 1rem; }
    .brand-logo { margin: auto; }
    .brand { padding: 12px 6px 10px; }
    .main { margin-left: 48px; }
    .card-grid { grid-template-columns: 1fr; padding: 12px; }
    .metrics { gap: 4px; }
    .metric-key { display: none; }
    .tab-bar { top: 52px; }
}
