/* ==============================================================================
   MedCodeSec Auditor Arena — Executive Clinical Compliance Theme
   Modern Web Guidance compliant: scroll-driven tab fades, focusgroup tabs,
   responsive @container stacked tables, and Invoker Commands copy feedback.
   ============================================================================== */

@property --fade-start {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

@property --fade-end {
  syntax: "<length>";
  inherits: false;
  initial-value: 0px;
}

:root {
  --bg-canvas: #f5f6f8;
  --bg-surface: #ffffff;
  --bg-subtle: #eef1f5;
  --bg-header: #0b1324;

  --border: #d8dee8;
  --border-strong: #b6c2d4;

  --ink-heading: #0b1324;
  --ink-primary: #1a2436;
  --ink-secondary: #435066;
  --ink-muted: #5d6b82;

  --navy: #142952;
  --accent: #0f62fe;
  --accent-tint: rgba(15, 98, 254, 0.07);

  --emerald: #065f46;
  --emerald-bg: #ecfdf5;
  --emerald-border: #86efac;

  --amber: #92400e;
  --amber-bg: #fffbeb;
  --amber-border: #fcd34d;

  --crimson: #9f1239;
  --crimson-bg: #fff1f2;
  --crimson-border: #fda4af;

  --radius-sm: 5px;
  --radius-md: 8px;
  --radius-lg: 11px;
  --radius-full: 9999px;

  --shadow-xs: 0 1px 2px rgba(11, 19, 36, 0.05);
  --shadow-sm: 0 2px 6px rgba(11, 19, 36, 0.06);

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  color-scheme: light;
}

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

html, body {
  background: var(--bg-canvas);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.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;
}

.skip-link {
  position: absolute;
  inset-inline-start: -9999px;
  background: var(--navy);
  color: #ffffff;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  z-index: 100;
}
.skip-link:focus {
  inset-inline-start: 16px;
  inset-block-start: 12px;
}

.app-shell {
  max-width: 1220px;
  margin: 0 auto;
  padding: 14px 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Top Bar */
.topbar {
  background: var(--bg-header);
  color: #f8fafc;
  border: 1px solid #1e2c48;
  border-radius: var(--radius-lg);
  padding: 12px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  box-shadow: var(--shadow-sm);
}

.brand { display: flex; align-items: center; gap: 11px; }

.brand-seal {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #0f62fe 0%, #065f46 100%);
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #ffffff;
  font-size: 1.2rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.brand-name { display: block; font-weight: 700; font-size: 1.04rem; letter-spacing: -0.01em; }
.brand-sub { display: block; font-size: 0.78rem; color: #b7c4d8; }

.tier-delta-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius-full);
  padding: 5px 12px;
  font-size: 0.8rem;
}
.delta-standalone strong { color: #fcd34d; font-family: var(--font-mono); }
.delta-compound strong { color: #6ee7b7; font-family: var(--font-mono); }
.delta-arrow { color: #94a3b8; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.8rem;
  color: #d1fae5;
  background: rgba(6, 95, 70, 0.35);
  border: 1px solid rgba(110, 231, 183, 0.4);
  border-radius: var(--radius-full);
  padding: 4px 11px;
}
.status-pill.fallback {
  color: #fde68a;
  background: rgba(146, 64, 14, 0.38);
  border-color: rgba(252, 211, 77, 0.45);
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #34d399;
}
.status-pill.fallback .status-dot {
  background: #fbbf24;
}

/* Single-Row Scrollable Tablist with Scroll-Driven Edge Fades */
.tabs-bar-wrap {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 8px;
  box-shadow: var(--shadow-xs);
  margin-block-end: 12px;
}

.tablist.scroller {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  scrollbar-width: none;
  scroll-snap-type: inline proximity;
  --fade-size: 2.5rem;
  --fade-dir: right;
  --fade-start-pos: 0;
  --fade-end-pos: 100%;
  scroll-padding-inline: var(--fade-size);
  mask:
    linear-gradient(black, black) no-clip subtract,
    linear-gradient(to var(--fade-dir), black, transparent) var(--fade-start-pos) 0 / var(--fade-start) 100% no-repeat no-clip,
    linear-gradient(to var(--fade-dir), transparent, black) var(--fade-end-pos) 0 / var(--fade-end) 100% no-repeat no-clip;
  animation: reveal-fade-start linear both, hide-fade-end linear both;
  animation-timeline: scroll(self inline);
  animation-range: 0 var(--fade-size), calc(100% - var(--fade-size)) 100%;
  transition: --fade-start .2s, --fade-end .2s;
}
.tablist.scroller::-webkit-scrollbar { display: none; }
.tablist.scroller.more-start { --fade-start: var(--fade-size); }
.tablist.scroller.more-end { --fade-end: var(--fade-size); }

@keyframes reveal-fade-start { to { --fade-start: var(--fade-size); } }
@keyframes hide-fade-end { from { --fade-end: var(--fade-size); } }

[role="tab"] {
  position: relative;
  flex: none;
  scroll-snap-align: start;
  background: transparent;
  color: var(--ink-secondary);
  border: 0;
  padding: 12px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
[role="tab"]:hover { color: var(--ink-heading); }
[role="tab"]:focus-visible { outline: 2px solid var(--accent); outline-offset: -3px; }
[role="tab"][aria-selected="true"] { color: var(--accent); }
[role="tab"][aria-selected="true"]::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  border-block-end: 3px solid var(--accent);
}

/* Panels stack without placing padding/borders directly on [hidden="until-found"] */
.panels-stack {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}
.tab-pane {
  grid-area: 1 / 1;
}
.tab-pane[hidden] {
  pointer-events: none;
  visibility: hidden;
  z-index: 0;
}
.tab-pane:not([hidden]) {
  position: relative;
  z-index: 1;
}
.panel-inner.panel-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.presets-header, .pane-bar, .micro-bench-header {
  display: flex;
  justify-content: space-between;
  align-items: safe center;
  gap: 12px;
  flex-wrap: wrap;
}
.presets-label-group {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}
.section-kicker {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--navy);
}
.section-hint, .pane-desc { color: var(--ink-secondary); font-size: 0.82rem; }
.pane-title { font-size: 1.08rem; color: var(--ink-heading); margin-bottom: 2px; }

.prompt-chips, .holiday-presets-bar, .micro-filter-row, .micro-case-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.prompt-chip, .mini-chip {
  background: var(--bg-canvas);
  color: var(--ink-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-block-size: 30px;
}
.prompt-chip-landmark {
  background: var(--bg-surface);
  border-color: var(--border-strong);
}
.prompt-chip:hover, .mini-chip:hover { border-color: var(--accent); background: var(--accent-tint); color: var(--navy); }
.prompt-chip:focus-visible, .mini-chip:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.mini-chip.active { background: var(--navy); color: #ffffff; border-color: var(--navy); }
.chip-tag {
  background: var(--navy);
  color: #ffffff;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 3px;
}
.chip-tag-muted { background: var(--crimson); }

/* Arena Two-Column Comparison (PatentSec Side-by-Side Parity) */
.arena-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
@media (max-width: 820px) {
  .arena-grid { grid-template-columns: 1fr; }
}

.arena-col {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-canvas);
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
  block-size: 430px;
  overflow: clip;
}
.arena-col-standalone {
  border-block-start: 3px solid #d97706;
}
.arena-col-compound {
  border-color: var(--emerald-border);
  border-block-start: 3px solid var(--emerald);
  background: #f8fdfb;
}

.arena-col-header {
  display: flex;
  justify-content: space-between;
  align-items: safe center;
  gap: 8px;
  padding: 10px 13px;
  border-block-end: 1px solid var(--border);
  background: var(--bg-surface);
  flex: none;
}
.arena-col-compound .arena-col-header {
  background: #f3fbf7;
  border-block-end-color: var(--emerald-border);
}
.arena-model-title { display: flex; align-items: center; gap: 9px; min-inline-size: 0; }
.model-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.model-dot-amber { background: #d97706; }
.model-dot-emerald { background: #059669; }
.model-name { font-weight: 700; font-size: 0.86rem; color: var(--ink-heading); line-height: 1.2; }
.model-sub-inline { font-size: 0.72rem; color: var(--ink-muted); }

.badge-amber, .badge-emerald, .badge-crimson {
  display: inline-block;
  flex: none;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.badge-amber { background: var(--amber-bg); color: var(--amber); border: 1px solid var(--amber-border); }
.badge-emerald { background: var(--emerald-bg); color: var(--emerald); border: 1px solid var(--emerald-border); }
.badge-crimson { background: var(--crimson-bg); color: var(--crimson); border: 1px solid var(--crimson-border); }

.arena-stream {
  flex: 1 1 auto;
  min-block-size: 0;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-y: auto;
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}
.msg-bubble {
  padding: 10px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-surface);
  font-size: 0.84rem;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg-user { background: var(--navy); color: #ffffff; border-color: var(--navy); align-self: flex-end; max-inline-size: 90%; }
.msg-head-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-block-end: 6px;
}
.msg-head {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-secondary);
}
.msg-latency {
  font-family: var(--font-mono);
  font-size: 0.69rem;
  color: var(--ink-muted);
  white-space: nowrap;
}
.msg-body {
  display: flex;
  flex-direction: column;
  gap: 5px;
  white-space: normal;
}
.md-heading {
  font-weight: 700;
  font-size: 0.86rem;
  color: var(--ink-heading);
  margin-block-start: 4px;
}
.md-para {
  margin: 0;
  line-height: 1.5;
}
.md-list {
  margin: 2px 0 4px 18px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.md-code {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  background: var(--bg-subtle);
  padding: 1px 4px;
  border-radius: 3px;
  color: var(--navy);
}
.phi-notice-badge {
  margin-block-start: 6px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  background: rgba(16, 185, 129, 0.16);
  border: 1px solid rgba(110, 231, 183, 0.45);
  color: #d1fae5;
  font-family: var(--font-mono);
  font-size: 0.7rem;
}
.verified-receipt-card {
  margin-block-start: 10px;
  padding: 9px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--emerald-border);
  background: var(--emerald-bg);
}
.verified-receipt-title {
  font-family: var(--font-mono);
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--emerald);
  margin-block-end: 6px;
}
.verified-receipt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 6px 10px;
}
.verified-kv {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-inline-size: 0;
}
.verified-k {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}
.verified-v {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--ink-heading);
  word-break: break-all;
}
.msg-meta { margin-block-start: 6px; font-family: var(--font-mono); font-size: 0.72rem; color: var(--ink-muted); }

/* Forms & Controls */
.chat-composer { display: flex; gap: 10px; align-items: flex-end; }
.composer-textarea { flex: 1 1 auto; min-inline-size: 0; resize: vertical; min-block-size: 38px; }

.four-col-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.three-col-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; margin: 8px 0; }
.inline-split { display: flex; gap: 6px; }
.inline-split input { flex: 1; }

.field-group { display: flex; flex-direction: column; gap: 4px; }
label { font-size: 0.8rem; font-weight: 600; color: var(--ink-secondary); }
input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.86rem;
  color: var(--ink-primary);
  background: var(--bg-surface);
}
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.primary-btn {
  background: var(--navy);
  color: #ffffff;
  border: 1px solid var(--navy);
  border-radius: var(--radius-sm);
  padding: 8px 15px;
  min-block-size: 34px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}
.primary-btn:hover { background: #1c3973; }
.primary-btn:focus-visible, .secondary-btn:focus-visible, .ghost-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.secondary-btn, .ghost-btn {
  background: var(--bg-surface);
  color: var(--ink-primary);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  min-inline-size: 32px;
  min-block-size: 32px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.secondary-btn:hover, .ghost-btn:hover { background: var(--bg-subtle); border-color: var(--navy); color: var(--navy); }

.action-bar, .result-toolbar, .export-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.latency-pill { font-family: var(--font-mono); font-size: 0.78rem; color: var(--ink-muted); }

/* Copy button & confirmation live region (Modern Web Guidance) */
.copy {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.copy-button {
  min-inline-size: 24px;
  min-block-size: 24px;
}
.copy-tip {
  opacity: 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--emerald);
  transition: opacity 0.15s ease;
  pointer-events: none;
}
.copy-button[data-copied] + .copy-tip { opacity: 1; color: var(--emerald); }
.copy-button[data-failed] + .copy-tip { opacity: 1; color: var(--crimson); }

@media (prefers-reduced-motion: reduce) {
  .copy-tip, .tablist.scroller { transition: none; }
}

/* Verdict Banners */
.verdict-banner {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  font-weight: 700;
  border: 1px solid var(--border);
}
.verdict-pass { background: var(--emerald-bg); color: var(--emerald); border-color: var(--emerald-border); }
.verdict-warn { background: var(--amber-bg); color: var(--amber); border-color: var(--amber-border); }
.verdict-block { background: var(--crimson-bg); color: var(--crimson); border-color: var(--crimson-border); }

/* Responsive Tables with Sticky Headers & @container Stacked Mobile Cards */
.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(460px, 75vh);
  container-type: inline-size;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
}
.clinical-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.84rem;
}
.clinical-table thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: var(--bg-subtle);
}
.clinical-table th, .clinical-table td {
  padding: 9px 11px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.clinical-table tbody th {
  position: sticky;
  inset-inline-start: 0;
  background: var(--bg-surface);
  z-index: 1;
  font-weight: 600;
}
.clinical-table .highlight-row td, .clinical-table .highlight-row th { background: #f8fafc; }

@container (width < 600px) {
  .clinical-table, .clinical-table thead, .clinical-table tbody, .clinical-table tr, .clinical-table th, .clinical-table td {
    display: block;
  }
  .clinical-table thead { display: none; }
  .clinical-table tr {
    margin-block-end: 0.75rem;
    border-bottom: 2px solid var(--border-strong);
  }
  .clinical-table tbody th {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
    background: var(--bg-subtle);
  }
  .scrub-table {
    --label-2: "Role / System";
    --label-3: "Billable / POA";
    --label-4: "Status";
    --label-5: "Hierarchy / Rule Finding";
  }
  .bench-table {
    --label-2: "12B Alone";
    --label-3: "MedCodeSec + ICX";
    --label-4: "Deterministic Guarantee";
  }
  .clinical-table td:nth-child(2)::before { content: var(--label-2) ": "; font-weight: 700; }
  .clinical-table td:nth-child(3)::before { content: var(--label-3) ": "; font-weight: 700; }
  .clinical-table td:nth-child(4)::before { content: var(--label-4) ": "; font-weight: 700; }
  .clinical-table td:nth-child(5)::before { content: var(--label-5) ": "; font-weight: 700; }
}

/* Subcards, KPIs, Case Inspector */
.calc-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (max-width: 860px) { .calc-grid { grid-template-columns: 1fr; } }

.subcard {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  background: #fafbfd;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.subcard-title { font-size: 0.95rem; color: var(--ink-heading); }
.calc-output, .result-meta, .micro-diff-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.83rem;
  white-space: pre-wrap;
}

.kpi-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 820px) { .kpi-strip { grid-template-columns: repeat(2, 1fr); } }
.kpi-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  background: #fafbfd;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.kpi-card-highlight { border-color: var(--emerald-border); background: var(--emerald-bg); }
.kpi-label { font-size: 0.76rem; color: var(--ink-secondary); font-weight: 600; }
.kpi-value { font-size: 1.32rem; font-weight: 800; font-family: var(--font-mono); color: var(--ink-heading); }
.kpi-sub { font-size: 0.74rem; color: var(--ink-muted); }

.micro-bench-section {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.micro-bench-title { font-size: 0.98rem; color: var(--ink-heading); }

.footer-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  font-size: 0.8rem;
  color: var(--ink-muted);
  padding: 4px 4px 12px;
}
.footer-links { display: flex; gap: 14px; flex-wrap: wrap; }
.footer-links a { color: var(--navy); font-weight: 600; text-decoration: none; }
.footer-links a:hover { text-decoration: underline; }
