/* ============================================================
   HistaLab — Design system (dark bio-lab neon)
   ============================================================ */
:root {
  --bg-0: #0B1220;
  --bg-1: #111827;
  --card: #111a2b;
  --card-2: #0f172a;
  --border: rgba(163, 230, 53, 0.25);
  --border-soft: rgba(163, 230, 53, 0.12);
  --neon: #22C55E;
  --lime: #A3E635;
  --amber: #F59E0B;
  --red: #EF4444;
  --text: #E2E8F0;
  --muted: #94A3B8;
}

html { scroll-behavior: smooth; }
body {
  background: radial-gradient(1200px 600px at 10% -10%, rgba(34, 197, 94, 0.10), transparent 60%),
              radial-gradient(900px 500px at 100% 0%, rgba(163, 230, 53, 0.07), transparent 60%),
              linear-gradient(180deg, var(--bg-0) 0%, var(--bg-1) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: "Space Grotesk", Inter, system-ui, sans-serif;
}

.font-mono, .num, table td.num, .tabular {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

/* Accessibility */
.skip-link {
  position: absolute; left: -999px; top: 0; z-index: 100;
  background: var(--lime); color: #052e16; padding: .5rem 1rem; border-radius: 0 0 .5rem 0;
  font-weight: 600;
}
.skip-link:focus { left: 0; }
:focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; border-radius: 4px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* Cards */
.card {
  background: linear-gradient(180deg, rgba(17, 26, 43, 0.95), rgba(15, 23, 42, 0.95));
  border: 1px solid var(--border);
  border-radius: 1rem;
  box-shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(255,255,255,0.02) inset;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
}
.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 40px -14px rgba(0, 0, 0, 0.7), 0 0 24px -6px rgba(163, 230, 53, 0.25);
  border-color: rgba(163, 230, 53, 0.45);
}
.card-title { font-weight: 600; font-size: 0.95rem; color: #F1F5F9; display: flex; align-items: center; gap: .5rem; }
.card-title i { color: var(--lime); }

.glow { text-shadow: 0 0 18px rgba(163, 230, 53, 0.55); }
.neon-ring { box-shadow: 0 0 0 1px rgba(163,230,53,.35), 0 0 22px -4px rgba(163,230,53,.45); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .5rem .9rem; border-radius: .75rem; font-weight: 600; font-size: .85rem;
  border: 1px solid transparent; transition: all .2s ease; cursor: pointer; white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, #22C55E, #A3E635); color: #052e16; box-shadow: 0 6px 20px -8px rgba(163,230,53,.7); }
.btn-primary:hover:not(:disabled) { filter: brightness(1.08); transform: translateY(-1px); }
.btn-ghost { background: rgba(163,230,53,.06); color: #d9f99d; border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: rgba(163,230,53,.14); border-color: rgba(163,230,53,.5); }
.btn-danger { background: rgba(239,68,68,.12); color: #fca5a5; border-color: rgba(239,68,68,.35); }
.btn-danger:hover { background: rgba(239,68,68,.22); }
.btn-sm { padding: .3rem .6rem; font-size: .75rem; border-radius: .5rem; }
.btn-icon { padding: .45rem; width: 2.25rem; height: 2.25rem; }

/* Inputs */
.input, .select, textarea.input {
  width: 100%; background: #0b1324; color: var(--text);
  border: 1px solid rgba(148,163,184,.25); border-radius: .65rem;
  padding: .5rem .7rem; font-size: .9rem; transition: border-color .2s, box-shadow .2s;
}
.input:focus, .select:focus { border-color: var(--lime); box-shadow: 0 0 0 3px rgba(163,230,53,.15); outline: none; }
.input.num { text-align: right; }
.input.input-error { border-color: var(--red); }
.label { display: flex; align-items: center; gap: .35rem; font-size: .75rem; color: var(--muted); margin-bottom: .3rem; font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a3e635' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right .7rem center; padding-right: 2rem; }
input[type="range"] { accent-color: var(--lime); width: 100%; }
input[type="checkbox"] { accent-color: var(--lime); }

/* Tooltip ("i") */
.tip { position: relative; display: inline-flex; align-items: center; justify-content: center; width: 1rem; height: 1rem; border-radius: 9999px; border: 1px solid rgba(163,230,53,.5); color: var(--lime); font-size: .6rem; font-style: normal; cursor: help; text-transform: none; }
.tip::after {
  content: attr(data-tip); position: absolute; bottom: 130%; left: 50%; transform: translateX(-50%) translateY(4px);
  width: max-content; max-width: 240px; white-space: normal; text-transform: none; letter-spacing: 0;
  background: #020617; color: #e2e8f0; padding: .5rem .65rem; border-radius: .5rem; font-size: .72rem; line-height: 1.3;
  border: 1px solid var(--border); box-shadow: 0 10px 30px -10px #000; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60; font-weight: 400;
}
.tip:hover::after, .tip:focus::after { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: .35rem; padding: .2rem .6rem; border-radius: 9999px; font-size: .7rem; font-weight: 600; letter-spacing: .02em; border: 1px solid transparent; }
.badge-green { background: rgba(34,197,94,.15); color: #86efac; border-color: rgba(34,197,94,.4); }
.badge-amber { background: rgba(245,158,11,.15); color: #fcd34d; border-color: rgba(245,158,11,.4); }
.badge-red { background: rgba(239,68,68,.15); color: #fca5a5; border-color: rgba(239,68,68,.4); }
.badge-slate { background: rgba(148,163,184,.12); color: #cbd5e1; border-color: rgba(148,163,184,.3); }
.badge-demo { background: rgba(245,158,11,.08); color: #fbbf24; border: 1px dashed rgba(245,158,11,.5); font-weight: 500; text-transform: uppercase; letter-spacing: .06em; font-size: .62rem; }

/* Tabs */
.tab-nav { position: sticky; top: 3.6rem; z-index: 30; background: rgba(11,18,32,.85); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border-soft); }
.tab-list { display: flex; gap: .25rem; overflow-x: auto; padding: .4rem .75rem; scrollbar-width: none; }
.tab-list::-webkit-scrollbar { display: none; }
.tab-btn {
  display: inline-flex; align-items: center; gap: .45rem; white-space: nowrap;
  padding: .5rem .85rem; border-radius: .7rem; font-size: .82rem; font-weight: 500; color: var(--muted);
  border: 1px solid transparent; transition: all .2s ease;
}
.tab-btn:hover { color: #e2e8f0; background: rgba(163,230,53,.06); }
.tab-btn[aria-selected="true"] { color: #0B1220; background: linear-gradient(135deg, #22C55E, #A3E635); box-shadow: 0 6px 18px -8px rgba(163,230,53,.8); font-weight: 600; }
.tab-btn .tab-num { font-family: "JetBrains Mono", monospace; font-size: .65rem; opacity: .7; }

/* Tables */
.table-wrap { overflow-x: auto; border-radius: .75rem; border: 1px solid var(--border-soft); }
table.data { width: 100%; border-collapse: collapse; font-size: .82rem; }
table.data th { text-align: left; font-weight: 600; color: #cbd5e1; background: rgba(15,23,42,.9); padding: .55rem .7rem; border-bottom: 1px solid var(--border); white-space: nowrap; position: sticky; top: 0; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--lime); }
table.data td { padding: .5rem .7rem; border-bottom: 1px solid rgba(148,163,184,.08); color: #e2e8f0; }
table.data tbody tr { transition: background .15s; }
table.data tbody tr:hover { background: rgba(163,230,53,.05); }
table.data td.num, table.data th.num { text-align: right; }
table.data input.input { padding: .3rem .5rem; font-size: .82rem; }

/* KPI */
.kpi-value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; font-family: "JetBrains Mono", monospace; }
.kpi-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }

/* Result card */
.result-card { position: relative; overflow: hidden; }
.result-card::before { content: ""; position: absolute; inset: -40%; background: radial-gradient(circle at 30% 30%, var(--result-glow, rgba(163,230,53,.25)), transparent 45%); pointer-events: none; }
.result-value { font-size: clamp(2.4rem, 8vw, 4rem); font-weight: 700; font-family: "JetBrains Mono", monospace; line-height: 1; }

/* Verdict colors */
.v-ok { --c: #22C55E; }
.v-warn { --c: #F59E0B; }
.v-fail { --c: #EF4444; }
.v-na { --c: #64748B; }
.verdict-banner { border-left: 4px solid var(--c); background: color-mix(in srgb, var(--c) 12%, transparent); border-radius: .75rem; padding: .9rem 1rem; }
.verdict-banner .verdict-title { color: var(--c); font-weight: 700; letter-spacing: .04em; }

/* Gauge */
.gauge { position: relative; height: 22px; border-radius: 9999px; overflow: visible;
  background: linear-gradient(90deg, #22C55E 0%, #22C55E 10%, #84cc16 10%, #F59E0B 20%, #F97316 40%, #EF4444 40%, #7f1d1d 100%); }
.gauge-marker { position: absolute; top: -8px; width: 4px; height: 38px; background: #fff; border-radius: 2px; box-shadow: 0 0 12px rgba(255,255,255,.9); transform: translateX(-50%); transition: left .6s cubic-bezier(.2,.8,.2,1); }
.gauge-marker::after { content: ""; position: absolute; top: -8px; left: 50%; transform: translateX(-50%); border: 6px solid transparent; border-top-color: #fff; }
.gauge-tick { position: absolute; top: 26px; transform: translateX(-50%); font-size: .65rem; color: var(--muted); font-family: "JetBrains Mono", monospace; white-space: nowrap; }
.gauge-tick::before { content: ""; position: absolute; top: -6px; left: 50%; width: 1px; height: 5px; background: rgba(148,163,184,.5); }

/* Calculation trace (lab notebook) */
.trace { background: #050a16; border: 1px solid var(--border-soft); border-radius: .9rem; padding: 1rem 1.1rem; font-family: "JetBrains Mono", monospace; font-size: .8rem; line-height: 1.55;
  background-image: repeating-linear-gradient(transparent, transparent 1.55em, rgba(163,230,53,.04) 1.55em, rgba(163,230,53,.04) calc(1.55em + 1px)); }
.trace .t-step { display: grid; grid-template-columns: 1.6rem 1fr; gap: .5rem; padding: .35rem 0; border-bottom: 1px dashed rgba(148,163,184,.12); }
.trace .t-step:last-child { border-bottom: 0; }
.trace .t-n { color: var(--lime); font-weight: 600; }
.trace .t-title { color: #cbd5e1; font-family: "Space Grotesk", sans-serif; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.trace .t-eq { color: #e2e8f0; }
.trace .t-sub { color: #86efac; }
.trace .t-res { color: #fff; font-weight: 600; }
.trace .t-res b { color: var(--lime); }
.trace .t-note { color: var(--muted); font-style: italic; font-family: "Space Grotesk", sans-serif; font-size: .74rem; }

/* Stepper */
.stepper { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
.step { position: relative; border: 1px solid var(--border-soft); border-radius: .9rem; padding: .8rem .8rem .8rem; background: rgba(15,23,42,.6); cursor: pointer; transition: all .2s; text-align: left; width: 100%; }
.step:hover, .step[aria-expanded="true"] { border-color: var(--lime); box-shadow: 0 0 20px -8px rgba(163,230,53,.6); }
.step .step-n { width: 1.7rem; height: 1.7rem; border-radius: 9999px; display: grid; place-items: center; font-family: "JetBrains Mono", monospace; font-size: .75rem; font-weight: 700; color: #052e16; background: linear-gradient(135deg, #22C55E, #A3E635); }
.step-detail { border: 1px solid var(--border); border-radius: .9rem; padding: 1rem; background: rgba(2,6,23,.6); animation: fadeIn .25s ease; }

/* Heatmap */
.heat-grid { display: grid; gap: 3px; }
.heat-cell { aspect-ratio: 1.6; border-radius: 4px; display: grid; place-items: center; font-size: .62rem; font-family: "JetBrains Mono", monospace; color: #fff; transition: transform .15s; }
.heat-cell:hover { transform: scale(1.08); outline: 1px solid #fff; z-index: 2; }

/* Levey-Jennings violations */
.viol { border-left: 3px solid var(--red); background: rgba(239,68,68,.08); border-radius: .5rem; padding: .5rem .7rem; }

/* Toasts */
.toast { pointer-events: auto; background: #020617; border: 1px solid var(--border); color: #e2e8f0; padding: .6rem 1rem; border-radius: .75rem; font-size: .85rem; box-shadow: 0 10px 30px -10px #000; animation: slideUp .25s ease; display: flex; gap: .5rem; align-items: center; }
.toast.ok { border-color: rgba(34,197,94,.5); } .toast.err { border-color: rgba(239,68,68,.5); }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(2,6,23,.75); backdrop-filter: blur(6px); z-index: 80; display: grid; place-items: center; padding: 1rem; animation: fadeIn .2s ease; }
.modal { width: 100%; max-width: 720px; max-height: 90vh; overflow-y: auto; animation: slideUp .25s ease; }

/* Animations */
@keyframes fadeIn { from { opacity: 0 } to { opacity: 1 } }
@keyframes slideUp { from { opacity: 0; transform: translateY(10px) } to { opacity: 1; transform: translateY(0) } }
.fade-in { animation: fadeIn .3s ease; }
.pulse-dot { width: .5rem; height: .5rem; border-radius: 9999px; background: var(--lime); box-shadow: 0 0 0 0 rgba(163,230,53,.7); animation: pulse 1.8s infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(163,230,53,.7) } 70% { box-shadow: 0 0 0 10px rgba(163,230,53,0) } 100% { box-shadow: 0 0 0 0 rgba(163,230,53,0) } }

/* Pagination */
.page-btn { min-width: 2rem; height: 2rem; border-radius: .5rem; border: 1px solid var(--border-soft); color: var(--muted); font-size: .8rem; font-family: "JetBrains Mono", monospace; }
.page-btn[aria-current="page"] { background: rgba(163,230,53,.15); color: var(--lime); border-color: var(--lime); }

/* Chips */
.chip { display: inline-flex; align-items: center; gap: .3rem; padding: .25rem .6rem; border-radius: 9999px; border: 1px solid rgba(148,163,184,.3); font-size: .74rem; color: #cbd5e1; cursor: pointer; transition: all .15s; user-select: none; }
.chip[aria-pressed="true"] { background: rgba(163,230,53,.15); border-color: var(--lime); color: #ecfccb; }

/* Kinetics sparkline of time-to-threshold */
.readout { font-family: "JetBrains Mono", monospace; font-size: 1.6rem; font-weight: 700; }

/* Print styles for the report */
@media print {
  body { background: #fff !important; color: #000 !important; }
  #app { display: none !important; }
  #print-report { display: block !important; color: #000; }
  .no-print { display: none !important; }
}
#print-report { display: none; }
@media screen { #print-report.preview { display: block; } }

.print-report { font-family: Inter, system-ui, sans-serif; color: #111; background: #fff; padding: 24px; max-width: 900px; margin: 0 auto; }
.print-report h1 { font-size: 20px; margin: 0 0 4px; }
.print-report h2 { font-size: 14px; margin: 18px 0 6px; border-bottom: 2px solid #22C55E; padding-bottom: 3px; text-transform: uppercase; letter-spacing: .05em; }
.print-report table { width: 100%; border-collapse: collapse; font-size: 12px; }
.print-report td, .print-report th { border: 1px solid #ddd; padding: 4px 6px; text-align: left; }
.print-report .mono { font-family: "JetBrains Mono", monospace; }
.print-report .verdict { padding: 8px 12px; border-left: 5px solid; font-weight: 700; margin: 6px 0; }

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(163,230,53,.25); border-radius: 8px; }
::-webkit-scrollbar-track { background: transparent; }

/* Small screens */
@media (max-width: 640px) {
  .kpi-value { font-size: 1.35rem; }
  .tab-nav { top: 3.4rem; }
}

/* ---- Responsive hardening: grid/flex children must be allowed to shrink ---- */
.grid > *, .card, .card > * { min-width: 0; }
.card { overflow: hidden; }
.card-title { flex-wrap: wrap; }
canvas { max-width: 100%; }
table.data th { text-transform: none; letter-spacing: 0; }
@media (max-width: 640px) {
  .card .flex.justify-between { flex-wrap: wrap; }
  .result-value { font-size: clamp(2rem, 12vw, 3rem); }
  .kpi-value { font-size: 1.25rem; }
  .readout { font-size: 1.3rem; }
  .trace { font-size: .72rem; padding: .75rem; }
  .trace .t-eq, .trace .t-sub, .trace .t-res { word-break: break-word; overflow-wrap: anywhere; }
  .gauge-tick { font-size: .55rem; }
  .btn-sm { padding: .3rem .5rem; }
}
