/* ============================================================================
   Detect (behalf.ai) — Carbon & Linen design system
   Canonical spec: Shared/design-system/CARBON_LINEN.md
   Source: behalf.ai-Visual-Identity-Carbon-Linen.html, section data-look="carbon"
   ========================================================================== */

:root {
  /* Canonical Carbon & Linen tokens */
  --c-paper: #E6E7E8;
  --c-panel: #F5F6F7;
  --c-ink: #292929;
  --c-soft: #B5B7BA;
  --c-silver: #D1D4D6;
  --c-rule: #C7C9CC;
  --c-on-silver: #292929;
  --c-on-carbon: #E6E7E8;
  --c-line: #555E66;
  --c-signal: #3D484F;

  /* Semantic roles (use these in components, not raw values) */
  --bg: var(--c-paper);
  --surface: var(--c-panel);
  --text: var(--c-ink);
  --text-muted: #4A4F54;        /* accessible on paper/panel (>= 7:1) */
  --text-faint: #62666B;        /* metadata only (>= 4.5:1 on paper and panel) */
  --border: var(--c-rule);
  --focus: var(--c-signal);
  --accent: var(--c-ink);       /* carbon is the brand action color */
  --accent-contrast: var(--c-on-carbon);
  --accent-soft: var(--c-silver);

  /* Semantic extensions (restrained, always paired with text/icon) */
  --good: #2E6B4F;   --good-soft: #E3EDE8;   --good-line: #9DB8A9;
  --warn: #8A5A00;   --warn-soft: #F2E9DA;   --warn-line: #C9B48C;
  --bad: #A1261F;    --bad-soft: #F3E3E2;    --bad-line: #D3A5A1;
  --info: #33536B;   --info-soft: #E4EBF0;   --info-line: #A8BDC9;

  /* Geometry + scale */
  --radius: 2px;
  --sp-1: 4px; --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 48px;

  /* Typography */
  --font-display: "Space Grotesk", Arial, sans-serif;
  --font-body: "Inter", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;

  /* Legacy aliases (inline styles / shared markup still reference these) */
  --faint: var(--text-faint);
  --muted: var(--text-muted);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: var(--c-silver); color: var(--c-on-silver); }

/* ---- Focus (light + dark surfaces; never a brand-blue ring) ---- */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 1px;
}
.inverse :focus-visible, .on-carbon :focus-visible { outline-color: var(--c-silver); }

/* ============================================================================
   Layout + header
   ========================================================================== */

header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-5);
  padding: 14px 4vw;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-family: var(--font-display);
  font-weight: 500; font-size: 17px; letter-spacing: -0.01em; white-space: nowrap;
  color: var(--text);
}
.brand .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.brand .sub { color: var(--text-muted); font-weight: 400; }

nav.mainnav { display: flex; gap: var(--sp-1); overflow-x: auto; align-items: stretch; }
.maintab {
  appearance: none; border: none; background: transparent;
  font-family: var(--font-body);
  color: var(--text-muted); font-size: 13.5px; font-weight: 500;
  padding: 10px 14px; cursor: pointer; border-radius: var(--radius);
  white-space: nowrap; position: relative;
  transition: color .15s ease, background .15s ease;
}
.maintab:hover { color: var(--text); background: var(--surface); }
.maintab.active {
  color: var(--text);
  box-shadow: inset 0 -2px 0 0 var(--accent); /* 2px carbon underline = current location */
  background: transparent;
}
.maintab.active:hover { background: transparent; }
/* The permanent agent-entry header button reads as a deliberate secondary action. */
.maintab#agentEntryHeaderBtn {
  border: 1px solid var(--border);
  background: var(--surface);
}
.maintab#agentEntryHeaderBtn:hover { border-color: var(--text); background: var(--surface); }
.maintab#agentEntryHeaderBtn.active { box-shadow: inset 0 -2px 0 0 var(--accent); }

.wrap { max-width: 860px; margin: 0 auto; padding: 40px 20px 90px; }

/* ============================================================================
   Typography
   ========================================================================== */

.kicker {
  font-family: var(--font-body);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .14em;
  color: var(--text-muted); font-weight: 500; margin: 0 0 14px;
}
h1, h2, h3 { font-family: var(--font-display); font-weight: 400; color: var(--text); }
h1 { font-size: clamp(24px, 3vw, 32px); line-height: 1.1; letter-spacing: -0.025em; margin: 0 0 8px; }
h2 { font-size: 17px; font-weight: 500; letter-spacing: -0.01em; margin: 0 0 14px; }
.lead { color: var(--text-muted); font-size: 15px; margin: 0 0 28px; }

/* ============================================================================
   Cards + panels (square, panel surface, deliberate boundaries)
   ========================================================================== */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: var(--sp-6);
  margin-bottom: var(--sp-5);
}
.card.emphasis { border-top: 2px solid var(--accent); }  /* emphasized consent-style panel */
.card.inverse {
  background: var(--c-ink);
  color: var(--c-on-carbon);
  border-color: var(--c-ink);
}
.card.inverse h1, .card.inverse h2, .card.inverse h3 { color: var(--c-on-carbon); }
.card.inverse .kicker { color: var(--c-silver); }
.card.inverse .lead, .card.inverse .note { color: var(--c-silver); }

.row { display: flex; gap: var(--sp-3); flex-wrap: wrap; align-items: center; }
label.tgl {
  display: flex; gap: 8px; align-items: center;
  font-size: 13px; color: var(--text-muted); font-weight: 500;
}

/* ============================================================================
   Forms
   ========================================================================== */

input, select, textarea {
  font-family: var(--font-body);
  background: #FFFFFF;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 12px; font-size: 14.5px;
}
input:hover, select:hover, textarea:hover { border-color: var(--c-soft); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--text); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--focus); outline-offset: 2px;
}
textarea { flex: 1 1 100%; min-height: 80px; resize: vertical; }
::placeholder { color: var(--text-faint); }
label:has(input), label:has(select), label:has(textarea) { display: block; margin-bottom: var(--sp-3); }
label { font-size: 13px; font-weight: 500; color: var(--text-muted); }
label > input, label > select, label > textarea { display: block; width: 100%; margin-top: 6px; }
label > textarea { font-family: var(--font-body); }

/* Checkboxes + radio: unmistakable checked state */
input[type=checkbox], input[type=radio] {
  width: 16px; height: 16px; accent-color: var(--accent); padding: 0;
}

/* ============================================================================
   Buttons
   ========================================================================== */

button {
  appearance: none;
  font-family: var(--font-body);
  background: var(--accent);              /* primary: carbon */
  color: var(--accent-contrast);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 18px; font-size: 13.5px; font-weight: 500; cursor: pointer;
  min-height: 40px;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
button:hover { background: #3B3B3B; border-color: #3B3B3B; }
button:active { background: var(--c-signal); border-color: var(--c-signal); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost {                         /* secondary: neutral surface + carbon label */
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
button.ghost:hover { background: #EDEEF0; border-color: var(--text); }
button.ghost:active { background: var(--c-silver); border-color: var(--text); }
button.link {                          /* tertiary: text action */
  background: transparent; color: var(--text); border-color: transparent;
  text-decoration: underline; text-underline-offset: 3px; min-height: 32px; padding: 6px 8px;
}
button.link:hover { background: var(--surface); border-color: transparent; }
.on-carbon button.ghost, .inverse button.ghost {
  background: transparent; color: var(--c-on-carbon); border-color: var(--c-silver);
}
.on-carbon button.ghost:hover, .inverse button.ghost:hover {
  background: rgba(230, 231, 232, .08); border-color: var(--c-on-carbon);
}
/* Full-width actions only in compact decision panels */
.decision-row button { width: 100%; min-height: 44px; }

/* ============================================================================
   Chat
   ========================================================================== */

#chat {
  min-height: 300px; max-height: 460px; overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: var(--sp-4); margin-bottom: 14px;
}
.chat-row { margin: 10px 0; font-size: 14.5px; line-height: 1.5; }
.chat-row.agent {
  background: var(--c-silver); color: var(--c-on-silver);
  border-radius: var(--radius); padding: 10px 14px; margin-right: 16%;
}
.chat-row.user {
  background: #FFFFFF; border: 1px solid var(--border); color: var(--text);
  border-radius: var(--radius); padding: 10px 14px; margin-left: 16%;
}
.chat-row.sys { text-align: center; color: var(--text-faint); font-size: 12.5px; margin: 14px 0; }

/* Offer tiles (selectable) */
.offers { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }
.offer-tile {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 16px;
  font-size: 13.5px; font-weight: 500; font-family: var(--font-body);
  cursor: pointer; text-align: left;
  transition: border-color .15s ease, background .15s ease;
}
.offer-tile:hover { border-color: var(--text); background: #EDEEF0; }

/* ============================================================================
   Rules, entries, countdown, results
   ========================================================================== */

.rules {
  margin-top: 14px; padding: 10px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); font-size: 13.5px; color: var(--text);
}
.entries { margin-top: 8px; font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.countdown { margin: 12px 0; text-align: center; font-weight: 500; color: var(--warn); font-size: 14px; }
.result-banner { text-align: center; font-weight: 500; font-size: 18px; margin: 14px 0; }
.result-banner.win { color: var(--good); }
.result-banner.tie { color: var(--warn); }
.result-banner.loss { color: var(--bad); }
.result-banner.caught { color: var(--bad); }

/* Badges: square, semantic color always paired with border */
.badge {
  display: inline-block; font-size: 12px; padding: 3px 8px;
  border-radius: var(--radius); font-weight: 500;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
}
.badge.ai    { background: var(--bad-soft);  color: var(--bad);  border-color: var(--bad-line); }
.badge.human { background: var(--good-soft); color: var(--good); border-color: var(--good-line); }
.badge.fork  { background: var(--warn-soft); color: var(--warn); border-color: var(--warn-line); }

pre {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; overflow-x: auto; font-size: 12.5px; font-family: var(--font-mono); margin: 0;
}

.note { font-size: 13px; color: var(--text-muted); margin-top: 16px; }
.note a { color: var(--text); text-decoration: underline; text-underline-offset: 3px; }
.note a:hover { color: var(--c-signal); }
.hidden { display: none !important; }

/* Instructions block */
.instructions {
  white-space: pre-wrap; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px;
  font-size: 15px; line-height: 1.6; color: var(--text);
}

/* ============================================================================
   Tables (admin logs, results, method review)
   ========================================================================== */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border);
  color: var(--text-muted); font-weight: 500; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: .06em; white-space: nowrap;
  border-top: 2px solid var(--border); /* deliberate table top rule */
}
tbody td { padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
tbody tr:hover { background: #ECEDEF; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
@media (max-width: 760px) {
  table { font-size: 12.5px; }
  thead th, tbody td { padding: 8px 10px; }
}

/* ============================================================================
   Params + methods + stats
   ========================================================================== */

.params-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
.params-grid label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 13px; color: var(--text-muted); font-weight: 500;
}
.params-grid input { width: 100%; }

.method-row { padding: 8px 0; border-bottom: 1px solid var(--border); }
.method-row label {
  display: flex; align-items: flex-start; gap: 8px;
  font-size: 13.5px; color: var(--text); font-weight: 400;
}
.method-row input[type=checkbox] { margin-top: 2px; }

.stat-row {
  display: flex; align-items: baseline; justify-content: space-between; gap: 16px;
  padding: 12px 0; border-bottom: 1px solid var(--border); font-size: 14px;
}
.stat-row:last-child { border-bottom: none; }
.stat-label { color: var(--text-muted); font-weight: 500; }
.stat-value { color: var(--text); font-variant-numeric: tabular-nums; font-weight: 500; text-align: right; }

/* ============================================================================
   Bars + charts (carbon emphasized, soft supporting, neutral tracks)
   ========================================================================== */

.bar-row { margin: 10px 0; }
.bar-label {
  font-size: 13px; color: var(--text-muted); font-weight: 500; margin-bottom: 4px;
  display: flex; justify-content: space-between; gap: 12px;
}
.bar-label .pct { color: var(--text); font-variant-numeric: tabular-nums; }
.bar-track { background: var(--c-silver); border-radius: var(--radius); height: 14px; overflow: hidden; }
.bar-fill { background: var(--accent); height: 100%; border-radius: var(--radius); transition: width .3s ease; }
.bar-fill.soft { background: var(--c-soft); }  /* supporting series */
.bar-fill.good { background: var(--good); }
.bar-fill.warn { background: var(--warn); }
.bar-fill.bad  { background: var(--bad); }
.chart-title {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); font-weight: 500; margin: 14px 0 6px;
}

/* Participant progress strip */
.progress-strip {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 14px;
}
.progress-row {
  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  font-size: 13.5px; margin-bottom: 8px;
}
.progress-row b { color: var(--text); font-weight: 500; }
.progress-strip .bar-track { height: 10px; }

/* ============================================================================
   Login + landing (only places the network motif is used)
   ========================================================================== */

#loginView, #tab-landing { position: relative; overflow: hidden; }
#loginView { padding: var(--sp-8); }
#loginView h1, #tab-landing h1 { font-size: clamp(24px, 4vw, 34px); letter-spacing: -0.03em; }

/* One reusable network motif (see Shared/design-system/CARBON_LINEN.md §6).
   Noninteractive, hidden from AT, fades toward the text area. */
.network-motif {
  position: absolute; top: 0; right: 0; bottom: 0; width: 46%;
  pointer-events: none; overflow: hidden;
  -webkit-mask-image: linear-gradient(to left, rgba(0,0,0,.95) 25%, transparent 95%);
  mask-image: linear-gradient(to left, rgba(0,0,0,.95) 25%, transparent 95%);
}
.network-motif svg { position: absolute; right: -20px; top: 50%; transform: translateY(-50%); height: 110%; }
.network-motif .wire { stroke: var(--c-line); stroke-width: .7; fill: none; opacity: .5; }
.network-motif .node { fill: var(--c-signal); }
.network-motif .sig {
  stroke: var(--c-signal); stroke-width: 2; fill: none;
  stroke-linecap: round; stroke-dasharray: .05 .95;
  animation: motif-signal 12s linear infinite;
}
.network-motif .sig.slow { animation-duration: 17s; animation-delay: -6s; }
@keyframes motif-signal {
  from { stroke-dashoffset: 0; }
  to   { stroke-dashoffset: -1; }
}
@media (prefers-reduced-motion: reduce) {
  .network-motif .sig { animation: none; }
}
@media (max-width: 540px) {
  .network-motif { width: 100%; opacity: .45; }
}
@media print {
  .network-motif { display: none; }
}

/* ============================================================================
   Voice tab
   ========================================================================== */

#voiceChat {
  min-height: 180px; max-height: 320px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); padding: var(--sp-4); margin-bottom: 12px;
}
#recordBtn, #stopBtn { min-height: 40px; }

/* ============================================================================
   Responsive
   ========================================================================== */

@media (max-width: 760px) {
  .chat-row.agent { margin-right: 4%; }
  .chat-row.user { margin-left: 4%; }
  .header-inner { flex-wrap: wrap; }
  .wrap { padding: 24px 16px 70px; }
}

@media (max-width: 540px) {
  .card { padding: var(--sp-5); }
  #loginView { padding: var(--sp-5); }
  .row { gap: var(--sp-2); }
}

/* ============================================================================
   Reduced motion (global)
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
