/* GrailScan dashboard. Dark, the same look as the former /grailscan page on content.loopstudio.tech. */
:root {
  color-scheme: dark;
  --page: #0a0a0a;
  --panel: #141414;
  --panel-2: #111111;
  --panel-3: #161616;
  --row-hover: #151515;
  --border: #262626;
  --border-2: #2a2a2a;
  --divider: #222222;
  --ink: #ffffff;
  --ink-2: #e5e5e5;
  --ink-3: #a3a3a3;
  --muted: #737373;
  --faint: #666666;
  --fainter: #525252;
  --accent: #00b894;
  --cyan: #22d3ee;
  --blue: #3b82f6;
  --amber: #f59e0b;
  --green: #22c55e;
  --red: #ef4444;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  min-height: 100vh;
  background: var(--page);
  color: var(--ink-2);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
button, input { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--ink); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
p { margin: 0; }

.loading-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; font-size: 14px; color: var(--muted); }

.wrap { max-width: 1280px; margin: 0 auto; padding: 32px 24px; }
@media (max-width: 640px) { .wrap { padding: 24px 16px; } }

/* Header */
.top { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 32px; }
.brand { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.brand img { width: 32px; height: 32px; border-radius: 7px; display: block; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 600; letter-spacing: 0.18em; text-transform: uppercase; }
h1 { font-size: 24px; line-height: 32px; font-weight: 700; color: var(--ink); margin: 0; }
h2 { font-size: 18px; line-height: 28px; font-weight: 700; color: var(--ink); margin: 4px 0 0; }
.sync { display: flex; align-items: center; gap: 8px; margin-top: 8px; color: var(--faint); font-size: 12px; }
@media (max-width: 639px) { .sync .synced { display: none; } }
.pulse { width: 6px; height: 6px; border-radius: 50%; background: var(--green); animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; flex: none; }
@keyframes pulse { 50% { opacity: 0.5; } }
.actions { display: flex; align-items: center; gap: 8px; }
.btn {
  height: 36px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--border-2); background: var(--panel);
  color: var(--muted); font-size: 12px; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
}
.btn:hover { color: var(--ink); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.icon { width: 36px; padding: 0; }
.btn svg { width: 15px; height: 15px; }
.spin svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner { margin-bottom: 20px; padding: 12px 16px; border: 1px solid rgba(239, 68, 68, 0.33); background: rgba(239, 68, 68, 0.06); border-radius: var(--radius); color: var(--red); font-size: 14px; }

/* Stat cards */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 1024px) { .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-height: 126px; display: flex; flex-direction: column; justify-content: space-between; min-width: 0; }
.stat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stat-label { font-size: 11px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.stat-head svg { width: 18px; height: 18px; flex: none; }
.stat-value { font-size: 30px; line-height: 36px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.stat-detail { font-size: 12px; color: var(--fainter); margin-top: 4px; }

/* Sections */
section.block { margin-top: 40px; }
.section-head { margin-bottom: 16px; }
.section-head.split { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.kicker { font-size: 11px; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; }
.k-green { color: var(--accent); }
.k-blue { color: var(--blue); }
.k-cyan { color: var(--cyan); }
.note { font-size: 12px; color: var(--fainter); }

.usage { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; }
@media (min-width: 1024px) { .usage { grid-template-columns: minmax(0, 1fr) 300px; } }
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; min-width: 0; }
.panel.clip { overflow: hidden; }
.panel-title { font-size: 10px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); margin-bottom: 12px; }

/* Daily calls chart: scrolls sideways on phones, starting at the newest day. */
.chart-scroll { overflow-x: auto; padding-bottom: 8px; direction: rtl; }
@media (min-width: 640px) { .chart-scroll { direction: ltr; } }
.chart { position: relative; min-width: 900px; direction: ltr; }
.chart svg { display: block; width: 100%; cursor: crosshair; }
.tooltip {
  position: absolute; top: 0; z-index: 10; pointer-events: none; background: #1a1a1a; border: 1px solid #333; border-radius: 8px;
  padding: 8px 12px; box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5); white-space: nowrap;
}
.tooltip .t-calls { color: var(--ink); font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tooltip .t-date { color: var(--muted); font-size: 10px; }
.tooltip .t-cost { color: var(--accent); font-size: 10px; margin-top: 4px; }

/* Calls by operation */
.ops > div + div { border-top: 1px solid #252525; }
.op { padding: 12px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.op-name { min-width: 0; }
.op-name p:first-child { font-size: 12px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.op-name p:last-child { font-size: 10px; color: var(--fainter); margin-top: 2px; }
.op-num { text-align: right; flex: none; }
.op-num p:first-child { font-size: 14px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.op-num p:last-child { font-size: 10px; color: var(--amber); }
.empty-small { font-size: 12px; color: var(--fainter); padding: 32px 0; text-align: center; }

/* Tables */
.table-box { border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel-2); overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; }
.w-820 { min-width: 820px; }
.w-760 { min-width: 760px; }
.w-680 { min-width: 680px; }
thead { background: var(--panel-3); border-bottom: 1px solid var(--border); }
th { padding: 12px 16px; font-size: 10px; font-weight: 600; letter-spacing: 0.12em; text-transform: uppercase; color: var(--faint); white-space: nowrap; }
th.w-10 { width: 40px; padding: 0; }
.main-table > tbody > tr + tr { border-top: 1px solid var(--divider); }
.main-table > tbody > tr > td { padding: 12px 16px; vertical-align: middle; }
.main-table > tbody > tr.hoverable { transition: background-color 0.15s; }
.main-table > tbody > tr.hoverable:hover { background: var(--row-hover); }
.c-title { font-size: 14px; font-weight: 600; color: var(--ink); }
.c-sub { font-size: 12px; color: var(--faint); margin-top: 2px; }
.c-err { font-size: 10px; color: var(--red); margin-top: 4px; }
.t-xs { font-size: 12px; }
.t-ink3 { color: var(--ink-3); }
.t-muted { color: var(--muted); }
.t-mono { font-family: var(--mono); }
.t-price { font-size: 14px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.capitalize { text-transform: capitalize; }
.time-rel { font-size: 12px; color: var(--ink-3); display: flex; align-items: center; gap: 4px; }
.time-rel svg { width: 11px; height: 11px; flex: none; }
.time-abs { font-size: 10px; color: var(--fainter); margin-top: 2px; }
.empty-row td { padding: 56px 16px !important; text-align: center; font-size: 14px; color: var(--fainter); }
.error-row td { padding: 48px 16px !important; text-align: center; }
.error-text { font-size: 14px; color: var(--red); }
.link-btn { margin-top: 12px; background: none; border: 0; padding: 0; cursor: pointer; font-size: 12px; font-weight: 600; color: var(--accent); }
.link-btn:hover { color: var(--ink); }

/* Status pills */
.status {
  display: inline-flex; align-items: center; gap: 6px; font-size: 10px; font-weight: 600; letter-spacing: 0.025em; text-transform: uppercase;
  padding: 4px 8px; border-radius: 999px; border: 1px solid; white-space: nowrap;
}
.status.completed { color: var(--green); background: rgba(34, 197, 94, 0.07); border-color: rgba(34, 197, 94, 0.2); }
.status.processing { color: var(--cyan); background: rgba(34, 211, 238, 0.07); border-color: rgba(34, 211, 238, 0.2); }
.status.failed { color: var(--red); background: rgba(239, 68, 68, 0.07); border-color: rgba(239, 68, 68, 0.2); }
.status .d { width: 6px; height: 6px; border-radius: 50%; background: var(--cyan); animation: pulse 2s cubic-bezier(0.4, 0, 0.6, 1) infinite; }

/* Card database */
.search { position: relative; width: 100%; }
@media (min-width: 640px) { .search { width: 288px; } }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 15px; height: 15px; color: var(--fainter); }
.search input {
  width: 100%; height: 36px; background: var(--panel); border: 1px solid var(--border-2); border-radius: 8px; padding: 0 12px 0 36px;
  font-size: 14px; color: var(--ink); outline: none;
}
.search input::placeholder { color: var(--fainter); }
.search input:focus { border-color: var(--accent); }
.card-btn { text-align: left; background: none; border: 0; padding: 0; cursor: pointer; }
.card-btn .c-title { transition: color 0.15s; }
.card-btn:hover .c-title { color: var(--accent); }
td.toggle-cell { padding: 0 12px 0 0 !important; color: var(--fainter); }
.toggle { width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; background: none; border: 0; padding: 0; cursor: pointer; color: inherit; }
.toggle:hover { color: var(--ink); }
.toggle svg { width: 16px; height: 16px; }
tr.history-row { background: #0d0d0d; }
.main-table > tbody > tr.history-row > td { padding: 16px; }
.card-meta { display: flex; flex-wrap: wrap; gap: 4px 20px; font-size: 11px; color: var(--faint); margin-bottom: 12px; }
.card-meta strong { color: var(--ink-3); font-weight: 500; }
.history-note { font-size: 12px; color: var(--fainter); padding: 12px 0; }
.history-note.plain { padding: 0; }
.history-error { padding: 12px 0; }
.history-error p { font-size: 12px; color: var(--red); }
.history-error .link-btn { margin-top: 8px; }
.history th { padding: 8px 0; font-size: 9px; letter-spacing: 0.05em; color: var(--fainter); text-align: left; }
.history thead { background: none; border-bottom: 1px solid var(--divider); }
.history tbody tr + tr { border-top: 1px solid #1d1d1d; }
.history td { padding: 10px 0; font-size: 12px; color: var(--ink-3); }
.history td.price { font-weight: 700; color: var(--ink); }
.sources { display: flex; flex-wrap: wrap; gap: 8px; }
.sources a { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); }
.sources a:hover { color: var(--ink); }
.sources svg { width: 11px; height: 11px; }
.sources .none { color: var(--fainter); }
.list-error { font-size: 12px; color: var(--red); margin-top: 12px; }
.more { display: flex; justify-content: center; margin-top: 16px; }
.more .btn { color: var(--ink-3); }
.more .btn:hover { border-color: #3a3a3a; }

footer { padding: 32px 0; margin-top: 32px; border-top: 1px solid #1f1f1f; font-size: 10px; color: #444; display: flex; justify-content: space-between; gap: 12px; }

/* Login: 4-digit PIN, like the AskMed dashboard */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { display: flex; flex-direction: column; align-items: center; }
.login-card .app-icon { width: 64px; height: 64px; border-radius: 16px; margin-bottom: 12px; display: block; }
.login-card h1 { font-size: 18px; line-height: 1.45; font-weight: 600; margin: 0 0 24px; }
.pin { display: flex; gap: 12px; margin-bottom: 12px; }
.pin input {
  width: 48px; height: 56px; border-radius: 8px; border: 2px solid #333; background: var(--panel); color: var(--ink);
  text-align: center; font-size: 20px; font-weight: 700; outline: none; transition: border-color 0.15s; padding: 0;
}
.pin input:focus { border-color: #555; }
.pin input.filled { border-color: #22c55e; }
.login-hint { margin: 0; color: #444; font-size: 12px; min-height: 20px; text-align: center; }
.login-hint.error { color: #ef4444; font-size: 14px; }
