/* ============================================================
   Face Intel · Intelligence Console — styles
   Light + dark theme via CSS custom properties.
   No external dependencies.
   ============================================================ */

/* ---------- Reset & base ---------- */
*,
*::before,
*::after { box-sizing: border-box; }

/* Honor the HTML `hidden` attribute globally.
   Without this, any CSS rule setting `display: flex/grid/block` etc.
   on a `[hidden]` element will override the attribute and the element
   will be visible. This is a common cross-browser pitfall. */
[hidden] { display: none !important; }

html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, "Noto Sans", sans-serif,
               "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button { font: inherit; color: inherit; cursor: pointer; }
input { font: inherit; }
img { max-width: 100%; display: block; }
code, pre, kbd, samp { font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Theme tokens ---------- */
:root,
[data-theme="light"] {
  --bg: #f8fafc;
  --bg-gradient: radial-gradient(1200px 600px at 80% -10%, rgba(8, 145, 178, .08), transparent 60%);
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --surface-3: #e2e8f0;
  --surface-hover: #f8fafc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;

  --primary: #0e7490;
  --primary-strong: #155e75;
  --primary-contrast: #ffffff;
  --primary-soft: rgba(14, 116, 144, 0.1);
  --primary-border: rgba(14, 116, 144, 0.25);

  --success: #16a34a;
  --success-soft: rgba(22, 163, 74, 0.12);
  --success-border: rgba(22, 163, 74, 0.3);
  --warning: #b45309;
  --warning-soft: rgba(217, 119, 6, 0.12);
  --warning-border: rgba(217, 119, 6, 0.3);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, 0.1);
  --danger-border: rgba(220, 38, 38, 0.3);
  --info: #2563eb;
  --info-soft: rgba(37, 99, 235, 0.1);
  --info-border: rgba(37, 99, 235, 0.3);

  --neutral: #475569;
  --neutral-soft: rgba(71, 85, 105, 0.1);

  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 1px rgba(15, 23, 42, 0.04);
  --shadow-md: 0 4px 12px rgba(15, 23, 42, 0.08), 0 2px 4px rgba(15, 23, 42, 0.04);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.14), 0 4px 8px rgba(15, 23, 42, 0.06);

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-xl: 18px;

  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-text-muted: #64748b;
  --sidebar-active-bg: rgba(8, 145, 178, 0.18);
  --sidebar-active-text: #5eead4;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.05);

  --focus-ring: 0 0 0 3px rgba(14, 116, 144, 0.35);
}

[data-theme="dark"] {
  --bg: #0f172a;
  --bg-gradient: radial-gradient(1200px 600px at 80% -10%, rgba(8, 145, 178, 0.18), transparent 60%);
  --surface: #1e293b;
  --surface-2: #0f172a;
  --surface-3: #334155;
  --surface-hover: #283548;
  --border: #334155;
  --border-strong: #475569;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --text-faint: #64748b;

  --primary: #22d3ee;
  --primary-strong: #06b6d4;
  --primary-contrast: #0b1220;
  --primary-soft: rgba(34, 211, 238, 0.14);
  --primary-border: rgba(34, 211, 238, 0.35);

  --success: #4ade80;
  --success-soft: rgba(74, 222, 128, 0.14);
  --success-border: rgba(74, 222, 128, 0.35);
  --warning: #fbbf24;
  --warning-soft: rgba(251, 191, 36, 0.14);
  --warning-border: rgba(251, 191, 36, 0.35);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, 0.14);
  --danger-border: rgba(248, 113, 113, 0.35);
  --info: #60a5fa;
  --info-soft: rgba(96, 165, 250, 0.14);
  --info-border: rgba(96, 165, 250, 0.35);

  --neutral: #94a3b8;
  --neutral-soft: rgba(148, 163, 184, 0.14);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.55);

  --sidebar-bg: #020617;
  --sidebar-text: #cbd5e1;
  --sidebar-text-muted: #64748b;
  --sidebar-active-bg: rgba(34, 211, 238, 0.18);
  --sidebar-active-text: #67e8f9;
  --sidebar-hover-bg: rgba(255, 255, 255, 0.06);

  --focus-ring: 0 0 0 3px rgba(34, 211, 238, 0.35);
}

/* ---------- App shell ---------- */
.app-shell {
  display: grid;
  grid-template-columns: 256px 1fr;
  min-height: 100vh;
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--primary);
  color: var(--primary-contrast);
  padding: 10px 16px;
  border-radius: 0 0 var(--radius) 0;
  z-index: 1000;
}
.skip-link:focus { left: 0; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  gap: 24px;
  border-right: 1px solid rgba(255, 255, 255, 0.04);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.brand-mark {
  color: #22d3ee;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; font-size: 16px; color: #f1f5f9; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--sidebar-text-muted); text-transform: uppercase; letter-spacing: 0.08em; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: none;
  background: transparent;
  color: var(--sidebar-text);
  text-align: left;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  width: 100%;
}
.nav-item:hover { background: var(--sidebar-hover-bg); color: #f1f5f9; }
.nav-item:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.nav-item.is-active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
}
.nav-icon { flex-shrink: 0; opacity: 0.9; }
.nav-label { flex: 1; }

.sidebar-footer { border-top: 1px solid rgba(255, 255, 255, 0.06); padding-top: 14px; }
.sidebar-footer .ghost-btn {
  width: 100%;
  color: var(--sidebar-text);
  justify-content: flex-start;
}
.sidebar-footer .ghost-btn:hover { background: var(--sidebar-hover-bg); color: #f1f5f9; }

.icon-sun, .icon-moon { flex-shrink: 0; }
[data-theme="light"] .icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }

/* ---------- Main ---------- */
.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 28px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar-title {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  flex: 1;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.connection-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.connection-pill .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-faint);
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.18);
}
.connection-pill.ok .dot { background: var(--success); box-shadow: 0 0 0 3px var(--success-soft); }
.connection-pill.ok { color: var(--success); }
.connection-pill.warn .dot { background: var(--warning); box-shadow: 0 0 0 3px var(--warning-soft); }
.connection-pill.warn { color: var(--warning); }
.connection-pill.err .dot { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.connection-pill.err { color: var(--danger); }

.content {
  padding: 24px 28px 48px;
  flex: 1;
  max-width: 1500px;
  width: 100%;
}

/* ---------- Views ---------- */
.view { display: none; animation: fade-in 0.18s ease-out; }
.view.is-active { display: block; }
@keyframes fade-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.stack { display: flex; flex-direction: column; gap: 20px; }
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

/* ---------- Panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.panel-title { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.panel-body { padding: 20px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  background: var(--primary);
  color: var(--primary-contrast);
  transition: background 0.15s, border-color 0.15s, transform 0.05s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--primary-strong); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.sm { padding: 6px 12px; font-size: 12px; }

.btn.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}
.btn.secondary:hover { background: var(--surface-hover); border-color: var(--primary); color: var(--primary); }

.btn.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--danger-border);
}
.btn.danger:hover { background: var(--danger-soft); }

.ghost-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.ghost-btn:hover { background: var(--surface-2); color: var(--text); }
.ghost-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.ghost-btn.sm { padding: 5px 10px; font-size: 12px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  transition: background 0.15s, color 0.15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.menu-toggle { display: none; }

/* ---------- Inputs ---------- */
.text-input {
  width: 100%;
  padding: 10px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.text-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.text-input::placeholder { color: var(--text-faint); }

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input-row {
  display: flex;
  gap: 8px;
}
.input-row .text-input { flex: 1; }

/* ---------- Dropzone ---------- */
.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 36px 20px;
  text-align: center;
  color: var(--text-muted);
  background: var(--surface-2);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
  cursor: pointer;
}
.dropzone:hover, .dropzone:focus-visible {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  outline: none;
}
.dropzone.is-dragover {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  transform: scale(1.01);
}
.dropzone-title { margin: 12px 0 4px; font-size: 15px; font-weight: 600; color: var(--text); }
.dropzone-sub { margin: 0; font-size: 13px; color: var(--text-muted); }
.dropzone .link { color: var(--primary); font-weight: 600; text-decoration: underline; }
.dropzone svg { color: var(--text-faint); }

/* ---------- Preview ---------- */
.preview-area {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 16px;
  align-items: start;
}
.preview-frame {
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--surface-2);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.preview-frame img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background:
    linear(45deg, #0001 25%, transparent 25%, transparent 75%, #0001 75%) 0 0/16px 16px,
    linear(45deg, #0001 25%, transparent 25%, transparent 75%, #0001 75%) 8px 8px/16px 16px;
}
.preview-meta { display: flex; flex-direction: column; gap: 6px; }
.meta-row {
  display: flex;
  font-size: 13px;
  gap: 10px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border);
}
.meta-key {
  flex-shrink: 0;
  width: 90px;
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.05em;
  font-weight: 600;
  padding-top: 2px;
}
.meta-val { font-family: "SFMono-Regular", Menlo, Consolas, monospace; word-break: break-all; }

.url-input-group { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--border); }

/* ---------- Action grid ---------- */
.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.action-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface-2);
  text-align: left;
  transition: border-color 0.15s, background 0.15s, transform 0.05s, box-shadow 0.15s;
  width: 100%;
}
.action-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: var(--shadow-sm);
}
.action-btn:active:not(:disabled) { transform: translateY(1px); }
.action-btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }
.action-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.action-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--primary);
  flex-shrink: 0;
}
.action-btn:hover:not(:disabled) .action-icon { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }
.action-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.action-title { font-weight: 600; font-size: 13px; }
.action-desc { font-size: 11.5px; color: var(--text-muted); }
.action-btn.primary-action { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }
.action-btn.primary-action .action-icon { background: rgba(255, 255, 255, 0.18); color: var(--primary-contrast); border-color: transparent; }
.action-btn.primary-action .action-desc { color: rgba(255, 255, 255, 0.8); }
.action-btn.primary-action:hover:not(:disabled) { background: var(--primary-strong); box-shadow: var(--shadow-md); }

.last-run {
  margin-top: 18px;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
}
.last-run-row { display: flex; flex-direction: column; gap: 2px; }
.last-run-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); font-weight: 600; }
.last-run-value { font-size: 13px; font-weight: 600; }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table thead { background: var(--surface-2); }
.data-table th {
  text-align: left;
  padding: 11px 14px;
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th.num, .data-table td.num { text-align: right; }
.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background 0.12s; }
.data-table tbody tr:hover { background: var(--surface-hover); }
.data-table tbody tr.is-clickable { cursor: pointer; }
.data-table tbody tr.is-selected { background: var(--primary-soft); }
.data-table td.mono { font-family: "SFMono-Regular", Menlo, Consolas, monospace; font-size: 12px; }
.data-table td.truncate { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.data-table .col-actions { width: 1%; white-space: nowrap; }
.data-table .row-actions { display: flex; gap: 6px; }

.empty-row {
  text-align: center;
  color: var(--text-muted);
  padding: 28px;
  font-size: 13px;
  margin: 0;
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge.success { background: var(--success-soft); color: var(--success); border-color: var(--success-border); }
.badge.warning { background: var(--warning-soft); color: var(--warning); border-color: var(--warning-border); }
.badge.danger { background: var(--danger-soft); color: var(--danger); border-color: var(--danger-border); }
.badge.info { background: var(--info-soft); color: var(--info); border-color: var(--info-border); }
.badge.neutral { background: var(--neutral-soft); color: var(--neutral); border-color: var(--border-strong); }
.badge.muted { background: var(--surface-2); color: var(--text-muted); border-color: var(--border); }

/* ---------- Empty state ---------- */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state svg { color: var(--text-faint); margin-bottom: 16px; }
.empty-state h3 { margin: 0 0 6px; color: var(--text); font-weight: 600; font-size: 16px; }
.empty-state p { margin: 0 auto; max-width: 420px; font-size: 13px; }

/* ---------- Callouts ---------- */
.callout {
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 14px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.callout.warn { background: var(--warning-soft); color: var(--warning); border: 1px solid var(--warning-border); }
.callout.error { background: var(--danger-soft); color: var(--danger); border: 1px solid var(--danger-border); }
.callout.info { background: var(--info-soft); color: var(--info); border: 1px solid var(--info-border); }
.callout-title { font-weight: 700; margin-bottom: 2px; }

/* ---------- Stat grid (cache) ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
}
.stat-cell {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}
.stat-value { font-size: 18px; font-weight: 700; color: var(--text); letter-spacing: -0.02em; }

.hit-ratio-bar {
  margin-top: 14px;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-3);
  overflow: hidden;
}
.hit-ratio-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--success), var(--primary));
  border-radius: 999px;
  transition: width 0.4s ease;
}

/* ---------- Counter list ---------- */
.counter-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 320px;
  overflow-y: auto;
}
.counter-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12.5px;
}
.counter-key { font-family: "SFMono-Regular", Menlo, Consolas, monospace; color: var(--text-muted); }
.counter-val { font-weight: 700; color: var(--text); }

/* ---------- Health banner ---------- */
.health-banner {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.health-banner.healthy { background: var(--success-soft); border-color: var(--success-border); }
.health-banner.degraded { background: var(--warning-soft); border-color: var(--warning-border); }
.health-banner.unhealthy { background: var(--danger-soft); border-color: var(--danger-border); }
.health-banner-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  flex-shrink: 0;
}
.health-banner-text { flex: 1; }
.health-banner-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }
.health-banner-sub { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.health-banner-meta { display: flex; gap: 18px; flex-wrap: wrap; font-size: 12px; }
.health-banner-meta span { display: inline-flex; flex-direction: column; align-items: flex-end; }
.health-banner-meta b { font-size: 14px; color: var(--text); }

/* ---------- Report viewer ---------- */
.report-section { margin-bottom: 22px; }
.report-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin: 0 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.report-section-title .count {
  background: var(--surface-3);
  color: var(--text);
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.report-meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}
.report-meta-cell {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.report-meta-cell .k {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}
.report-meta-cell .v { font-size: 13px; word-break: break-all; margin-top: 2px; font-family: "SFMono-Regular", Menlo, Consolas, monospace; }

.limitations-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.limitations-list li {
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 4px 0 4px 18px;
  position: relative;
  list-style: none;
}
.limitations-list li::before {
  content: "!";
  position: absolute;
  left: 0;
  top: 4px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--warning-soft);
  color: var(--warning);
  font-size: 10px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Confidence card */
.confidence-card {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 22px;
  border-radius: var(--radius-lg);
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex-wrap: wrap;
}
.confidence-display { display: flex; align-items: center; gap: 16px; flex-shrink: 0; }
.confidence-ring {
  position: relative;
  width: 96px;
  height: 96px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.confidence-ring svg { transform: rotate(-90deg); }
.confidence-ring .ring-bg { fill: none; stroke: var(--surface-3); stroke-width: 8; }
.confidence-ring .ring-fg { fill: none; stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset 0.5s ease; }
.confidence-pct {
  position: absolute;
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.02em;
}
.confidence-info { flex: 1; min-width: 220px; }
.confidence-tier { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.confidence-tier.high { color: var(--success); }
.confidence-tier.mid { color: var(--warning); }
.confidence-tier.low { color: var(--danger); }
.confidence-explanation { font-size: 13px; color: var(--text-muted); line-height: 1.5; }
.confidence-explanation code { background: var(--surface-3); padding: 1px 6px; border-radius: 4px; font-size: 12px; }
.confidence-components {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  width: 100%;
}
.conf-comp {
  display: grid;
  grid-template-columns: 140px 1fr 50px;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}
.conf-comp-name { color: var(--text-muted); font-weight: 500; }
.conf-comp-bar { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.conf-comp-fill { height: 100%; border-radius: 999px; background: var(--primary); transition: width 0.4s ease; }
.conf-comp-val { text-align: right; font-family: "SFMono-Regular", monospace; font-weight: 600; }

/* Conflicts banner */
.conflicts-banner {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
  margin-bottom: 20px;
}
.conflicts-banner .head {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  color: var(--warning);
}
.conflict-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
}
.conflict-item .conflict-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}
.conflict-item .conflict-desc { color: var(--text-muted); font-size: 12.5px; }
.conflict-item .conflict-providers { display: flex; gap: 4px; flex-wrap: wrap; }

/* Card grid */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}
.info-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.info-card .card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  gap: 10px;
}
.info-card .card-title { font-weight: 600; font-size: 13px; }
.info-card .kv { display: flex; justify-content: space-between; font-size: 12.5px; gap: 10px; padding: 2px 0; }
.info-card .kv .k { color: var(--text-muted); }
.info-card .kv .v { font-weight: 600; font-family: "SFMono-Regular", monospace; }

/* Color swatches */
.swatches { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.swatch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10.5px;
  font-family: "SFMono-Regular", monospace;
  color: var(--text-muted);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px 2px 2px;
}
.swatch-chip {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  flex-shrink: 0;
}

/* Detection list */
.det-list { display: flex; flex-direction: column; gap: 10px; }
.det-row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.det-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}
.det-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.det-box { font-family: "SFMono-Regular", monospace; font-size: 12px; color: var(--text-muted); }
.det-providers { display: flex; gap: 4px; flex-wrap: wrap; }
.det-confidence { text-align: right; flex-shrink: 0; }
.det-conf-val { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.det-conf-label { font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Reverse matches */
.match-list { display: flex; flex-direction: column; gap: 10px; }
.match-card {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 14px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.match-thumb {
  width: 90px;
  height: 90px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.match-thumb-placeholder {
  width: 90px;
  height: 90px;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
}
.match-info { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.match-engine {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 4px;
  width: fit-content;
}
.match-engine.engine-yandex { background: rgba(255, 204, 0, 0.15); color: #ffcc00; }
.match-engine.engine-yandex_face { background: rgba(16, 185, 129, 0.15); color: #10b981; }
.match-engine.engine-bing { background: rgba(0, 120, 215, 0.15); color: #0078d7; }
.match-engine.engine-tineye { background: rgba(99, 102, 241, 0.15); color: #6366f1; }
.match-engine.engine-scraper { background: rgba(148, 163, 184, 0.15); color: #94a3b8; }
.match-title { font-weight: 600; font-size: 13px; word-break: break-word; }
.match-source { font-size: 11.5px; color: var(--text-muted); font-family: "SFMono-Regular", monospace; word-break: break-all; }
.match-snippet { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

/* Scraped grid */
.scrape-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
}
.scrape-cell {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
}
.scrape-cell img { width: 100%; height: 100%; object-fit: cover; }
.scrape-cell .scrape-overlay {
  position: absolute;
  inset: auto 0 0 0;
  background: linear-gradient(0deg, rgba(0,0,0,0.7), transparent);
  color: #fff;
  padding: 6px 8px;
  font-size: 10px;
  font-family: "SFMono-Regular", monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  opacity: 0;
  transition: opacity 0.15s;
}
.scrape-cell:hover .scrape-overlay { opacity: 1; }

/* ---------- Collapsible ---------- */
details.disclosure {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 10px;
}
details.disclosure > summary {
  list-style: none;
  cursor: pointer;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 600;
  font-size: 13px;
  user-select: none;
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::after {
  content: "";
  width: 8px;
  height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: rotate(-45deg);
  transition: transform 0.18s;
  flex-shrink: 0;
}
details.disclosure[open] > summary::after { transform: rotate(45deg); }
details.disclosure > summary:hover { background: var(--surface-hover); }
details.disclosure > .disclosure-body { padding: 0 14px 14px; }

/* ---------- JSON tree ---------- */
.json-tree {
  font-family: "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 12.5px;
  line-height: 1.6;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  overflow-x: auto;
}
.json-node { display: block; }
.json-row { display: flex; align-items: flex-start; gap: 4px; }
.json-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 18px;
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 10px;
  transition: transform 0.15s;
}
.json-toggle:hover { color: var(--primary); }
.json-toggle.collapsed { transform: rotate(-90deg); }
.json-toggle.leaf { visibility: hidden; }
.json-key { color: var(--primary); font-weight: 600; }
.json-key::after { content: ": "; color: var(--text-muted); font-weight: normal; }
.json-string { color: var(--success); }
.json-number { color: var(--info); }
.json-bool { color: var(--warning); }
.json-null { color: var(--text-faint); font-style: italic; }
.json-bracket { color: var(--text-muted); }
.json-children { padding-left: 18px; border-left: 1px dashed var(--border); margin-left: 8px; }
.json-children.collapsed { display: none; }
.json-preview { color: var(--text-faint); font-style: italic; margin-left: 4px; }

/* ---------- Loading overlay ---------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.loading-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px 36px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.spinner {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 3px solid var(--surface-3);
  border-top-color: var(--primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { font-size: 13px; color: var(--text-muted); font-weight: 500; }

/* ---------- Toasts ---------- */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1100;
  max-width: calc(100vw - 40px);
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--info);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow-lg);
  min-width: 280px;
  max-width: 420px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  animation: toast-in 0.22s cubic-bezier(0.2, 0.9, 0.3, 1.2);
  font-size: 13px;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warning); }
.toast.info { border-left-color: var(--info); }
.toast.leaving { animation: toast-out 0.18s ease forwards; }
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateX(20px); } }
.toast-icon {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  margin-top: 1px;
}
.toast.success .toast-icon { background: var(--success); }
.toast.error .toast-icon { background: var(--danger); }
.toast.warn .toast-icon { background: var(--warning); }
.toast.info .toast-icon { background: var(--info); }
.toast-body { flex: 1; min-width: 0; }
.toast-title { font-weight: 700; margin-bottom: 2px; }
.toast-msg { color: var(--text-muted); word-break: break-word; }
.toast-close {
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 18px;
  line-height: 1;
  padding: 0 4px;
  cursor: pointer;
}
.toast-close:hover { color: var(--text); }

/* ---------- Utility ---------- */
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.link { color: var(--primary); cursor: pointer; text-decoration: underline; }
.mono { font-family: "SFMono-Regular", Menlo, Consolas, monospace; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 860px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 256px;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.is-open { transform: none; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 18px 16px 40px; }
  .topbar { padding: 12px 16px; }
  .preview-area { grid-template-columns: 1fr; }
  .preview-frame { max-width: 220px; margin: 0 auto; }
  .action-grid { grid-template-columns: 1fr; }
  .confidence-card { gap: 14px; }
  .conf-comp { grid-template-columns: 110px 1fr 40px; }
  .det-row { grid-template-columns: auto 1fr; }
  .det-confidence { grid-column: 2; text-align: left; }
  .match-card { grid-template-columns: 70px 1fr; }
  .match-thumb, .match-thumb-placeholder { width: 70px; height: 70px; }
}

@media (max-width: 540px) {
  .topbar-title { font-size: 16px; }
  .panel-header { padding: 14px 16px; }
  .panel-body { padding: 16px; }
  .toast-container { right: 12px; bottom: 12px; }
  .toast { min-width: 240px; }
}

/* ---------- Backdrop for mobile sidebar ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 150;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.backdrop.is-open { opacity: 1; pointer-events: auto; }

/* ---------- Print ---------- */
@media print {
  .sidebar, .topbar, .loading-overlay, .toast-container { display: none; }
  .app-shell { grid-template-columns: 1fr; }
  .content { padding: 0; }
}
