/* Shared tokens, base elements and detail-panel styling used by index.html,
   run.html and new-task.html. Metro-map SVG styling stays out of this file —
   it belongs only to index.html. */

/* Any element whose class sets its own `display` (flex, inline-flex, grid, …)
   overrides the browser's built-in `[hidden] { display: none }` rule, since
   author CSS always wins over the user-agent stylesheet regardless of
   specificity — the `hidden` attribute would otherwise be silently ignored
   on things like `.btn-link`. Keep this ahead of every rule that sets
   `display` on a toggle-able element. */
[hidden] { display: none !important; }

:root {
  --paper:   #FBFCFD;
  --paper-2: #F1F4F8;
  --card:    #FFFFFF;
  --ink:     #161B22;
  --ink-2:   #4A5565;
  --ink-3:   #8A95A5;
  --rule:    #DEE4EC;
  --rail:    #C6D0DC;
  --shadow:  0 1px 2px rgba(22,27,34,.07), 0 10px 30px rgba(22,27,34,.07);
  --ok:   #0E7C66;
  --warn: #B06A00;
  --bad:  #C0392B;
  --line-filter: none;

  --f-sign: "Archivo", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --f-ui:   "Hanken Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-data: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:   #0E1217;
    --paper-2: #151B23;
    --card:    #171E27;
    --ink:     #E9EEF5;
    --ink-2:   #A9B4C2;
    --ink-3:   #6E7A89;
    --rule:    #242D38;
    --rail:    #303B49;
    --shadow:  0 1px 2px rgba(0,0,0,.5), 0 12px 34px rgba(0,0,0,.45);
    --ok:   #34B399;
    --warn: #E0A33C;
    --bad:  #EB6A5C;
    --line-filter: saturate(1.1) brightness(1.22);
  }
}
:root[data-theme="dark"] {
  --paper:   #0E1217;
  --paper-2: #151B23;
  --card:    #171E27;
  --ink:     #E9EEF5;
  --ink-2:   #A9B4C2;
  --ink-3:   #6E7A89;
  --rule:    #242D38;
  --rail:    #303B49;
  --shadow:  0 1px 2px rgba(0,0,0,.5), 0 12px 34px rgba(0,0,0,.45);
  --ok:   #34B399;
  --warn: #E0A33C;
  --bad:  #EB6A5C;
  --line-filter: saturate(1.1) brightness(1.22);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.5 var(--f-ui);
  -webkit-font-smoothing: antialiased;
}
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 4px; }
.grow { flex: 1 1 auto; }

button {
  font: 500 13.5px/1 var(--f-ui);
  padding: .58rem .9rem; border-radius: 8px;
  border: 1px solid var(--rule); background: var(--card); color: var(--ink);
  cursor: pointer; transition: border-color .15s, background .15s, transform .08s;
}
button:hover:not(:disabled) { border-color: var(--ink-3); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
button.primary:hover:not(:disabled) { background: color-mix(in srgb, var(--ink) 85%, var(--paper)); }
button.icon, a.icon {
  width: 30px; height: 30px; padding: 0; border-radius: 7px;
  font-size: 13px; color: var(--ink-3); line-height: 1;
}
a.icon:hover { color: var(--ink); }
/* Same treatment for the <a class="btn-link"> nav links that go icon-only. */
.btn-link.icon {
  width: 30px; height: 30px; padding: 0; border-radius: 7px;
  font-size: 15px; justify-content: center;
}

/* A plain <a> made to look and sit like a button, for nav links in headers. */
.btn-link {
  font: 500 13.5px/1 var(--f-ui);
  padding: .58rem .9rem; border-radius: 8px;
  border: 1px solid var(--rule); background: var(--card); color: var(--ink);
  cursor: pointer; text-decoration: none; display: inline-flex; align-items: center;
  transition: border-color .15s, background .15s, transform .08s;
}
.btn-link:hover { border-color: var(--ink-3); }
/* Brand logo & link */
.brand-logo {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
  border-radius: 6px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .2);
}
.brand-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
  color: inherit;
  line-height: 1;
}

.chips { display: flex; gap: .45rem; align-items: center; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: .4rem;
  font: 500 11.5px/1 var(--f-ui); letter-spacing: .03em; text-transform: uppercase;
  padding: .38rem .6rem; border-radius: 999px;
  border: 1px solid var(--rule); color: var(--ink-2); background: var(--paper-2);
  white-space: nowrap;
}
.chip b { font-family: var(--f-data); font-weight: 500; text-transform: none; letter-spacing: 0; }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-3); }
.chip.live .dot { background: var(--ok); animation: breathe 2s ease-in-out infinite; }
.chip.live { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, var(--rule)); }
@keyframes breathe { 0%,100% { opacity: .35 } 50% { opacity: 1 } }

/* ── Detail panel content (shared by the slide-over sheet and the full page) ── */
.scrim {
  position: fixed; inset: 0; background: rgba(12, 16, 22, .08);
  backdrop-filter: blur(1px);
  opacity: 0; pointer-events: none; transition: opacity .28s; z-index: 30;
}
.scrim.open { opacity: 1; pointer-events: auto; }

.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(540px, 96vw);
  background: var(--card); border-left: 1px solid var(--rule);
  box-shadow: -14px 0 44px rgba(0,0,0,.18);
  display: flex; flex-direction: column;
  transform: translateX(101%); transition: transform .28s cubic-bezier(.4,0,.2,1);
  z-index: 40;
}
.sheet.open { transform: none; }
@media (prefers-reduced-motion: reduce) {
  .sheet, .scrim { transition: none; }
}

.sheet-head { padding: 1.1rem 1.35rem 1.2rem; border-bottom: 1px solid var(--rule); }
.sheet-top { display: flex; align-items: center; gap: .6rem; margin-bottom: .75rem; }
.sheet-head .eyebrow { font: 500 11.5px/1 var(--f-data); color: var(--ink-3); }
.sheet-head h2 { font: 600 1.1rem/1.32 var(--f-sign); margin: 0 0 .6rem; text-wrap: balance; }
.sheet-head .where { display: flex; align-items: center; gap: .5rem; font-size: 12.5px; color: var(--ink-2); }
.sheet-head .where .bullet { width: 10px; height: 10px; border-radius: 50%; flex: none; }

/* ticket-type chip: the colour comes from the backend catalogue, set by JS */
.ttype {
  font: 600 10.5px/1 var(--f-ui); letter-spacing: .07em; text-transform: uppercase;
  padding: .35rem .55rem; border-radius: 5px; color: #fff; white-space: nowrap;
}
.ttype-swatch {
  display: inline-block; width: 9px; height: 9px; border-radius: 50%; flex: none;
}

.sheet-actions {
  display: flex; align-items: center; justify-content: space-between; gap: .6rem; flex-wrap: wrap;
  padding: .85rem 1.35rem; border-bottom: 1px solid var(--rule);
  background: var(--paper-2);
}
.sheet-actions:empty { display: none; }

.actions-left,
.actions-right {
  display: flex; align-items: center; gap: .5rem; flex-wrap: wrap;
}
.actions-right { margin-left: auto; }

#s-cancel:hover:not(:disabled) {
  border-color: var(--bad);
  color: var(--bad);
  background: color-mix(in srgb, var(--bad) 6%, var(--card));
}
#s-approve.primary {
  background: var(--ok);
  border-color: var(--ok);
  color: #FFFFFF;
}
#s-approve.primary:hover:not(:disabled) {
  background: color-mix(in srgb, var(--ok) 85%, #000);
  border-color: color-mix(in srgb, var(--ok) 85%, #000);
}
#s-simulate-loop {
  color: #D97706;
  border-color: color-mix(in srgb, #D97706 35%, var(--rule));
}
#s-simulate-loop:hover:not(:disabled) {
  background: color-mix(in srgb, #D97706 10%, var(--card));
  border-color: #D97706;
}

.sheet-body { padding: 1.25rem 1.35rem 2.5rem; overflow-y: auto; flex: 1; }
.sheet-body h3 {
  font: 600 10.5px/1 var(--f-ui); letter-spacing: .11em; text-transform: uppercase;
  color: var(--ink-3); margin: 1.6rem 0 .7rem;
}
.sheet-body h3:first-child { margin-top: 0; }

/* Who asked */
.who { display: flex; align-items: center; gap: .7rem; }
.who .avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center;
  font: 600 13px/1 var(--f-sign); color: #fff; letter-spacing: .02em;
}
.who .name { font-weight: 600; font-size: 14px; }
.who .handle { font: 400 12px/1.3 var(--f-data); color: var(--ink-3); }

/* Ticket summary */
.summary {
  font-size: 13.5px; line-height: 1.62; color: var(--ink-2);
  max-width: 62ch;
}
.summary p { margin: 0 0 .7rem; }
.summary p:last-child { margin-bottom: 0; }
.summary strong { color: var(--ink); font-weight: 600; }
.summary ol, .summary ul { margin: 0 0 .7rem; padding-left: 1.25rem; }
.summary li { margin-bottom: .2rem; }
.summary code {
  font: 400 12px/1 var(--f-data);
  background: var(--paper-2); border: 1px solid var(--rule);
  padding: .1rem .3rem; border-radius: 4px; color: var(--ink);
}
.summary .empty { color: var(--ink-3); font-style: italic; }

/* Labels */
.tags { display: flex; gap: .35rem; flex-wrap: wrap; }
.tag {
  font: 500 11.5px/1 var(--f-ui); padding: .32rem .55rem; border-radius: 999px;
  border: 1px solid var(--rule); background: var(--paper-2); color: var(--ink-2);
}

/* Tracking: key/value pairs */
.facts { display: grid; grid-template-columns: auto 1fr; gap: .5rem 1rem; margin: 0; }
.facts dt {
  font: 500 10.5px/1.4 var(--f-ui); letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-3); padding-top: .12rem;
}
.facts dd { margin: 0; font: 500 12.5px/1.4 var(--f-data); font-variant-numeric: tabular-nums; }
.facts dd.plain { font-family: var(--f-ui); }

/* Stage detail: per-stage breakdown of what the agent actually checked/did,
   one plain-language line per action (see agents/tools.ts's `action` field) */
.stage-breakdown { display: flex; flex-direction: column; gap: .4rem; margin-bottom: .9rem; }
.stage-detail { border: 1px solid var(--rule); border-radius: 9px; overflow: hidden; flex-shrink: 0; min-height: 34px; }
.stage-detail[disabled] { opacity: .55; }
.stage-detail summary {
  display: flex; align-items: center; gap: .5rem; padding: .5rem .8rem;
  cursor: pointer; font-size: 12.5px; font-weight: 600; color: var(--ink);
  list-style: none;
}
.stage-detail[disabled] summary { cursor: default; }
.stage-detail summary::-webkit-details-marker { display: none; }
.stage-detail-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.stage-detail-agent { font-weight: 400; color: var(--ink-3); }
.stage-detail-count {
  margin-left: auto; font: 500 10.5px/1 var(--f-data); color: var(--ink-3);
  background: var(--paper-2); border-radius: 999px; padding: .18rem .45rem;
}
.stage-detail-list { list-style: none; margin: 0; padding: 0 .8rem .65rem 2.05rem; }
.stage-detail-list li {
  position: relative; padding: .2rem 0; font-size: 12.5px; color: var(--ink-2);
}
.stage-detail-list li::before { content: "–"; position: absolute; left: -1.1rem; color: var(--ink-3); }
.stage-detail-list li.is-error { color: var(--bad); font-weight: 500; }
.stage-detail-list li.is-warning { color: var(--warn); font-weight: 500; }

/* SPEC-08: per-acceptance-criterion checklist inside the Tests stage's
   breakdown — the sidebar is the surface for this, not the map, because the
   full-viewport .scrim behind the open sheet swallows every click on the map
   underneath, so the Station Magnifier's colored pips can only ever be
   *seen*, never clicked. */
.test-case-list { list-style: none; margin: .1rem 0 .3rem; padding: 0 .8rem 0 2.05rem; display: flex; flex-direction: column; gap: .3rem; }
.test-case-item { position: relative; padding: .3rem .55rem; border-radius: 6px; background: var(--paper-2); border: 1px solid var(--rule); }
.test-case-item .tc-head { display: flex; align-items: center; gap: .4rem; font-size: 12.5px; font-weight: 600; color: var(--ink); }
.test-case-item .tc-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.test-case-item.passed .tc-dot { background: var(--ok); }
.test-case-item.failed .tc-dot { background: var(--bad); }
.test-case-item .tc-spec { margin-top: .15rem; font-size: 11.5px; color: var(--ink-3); font-style: italic; }
.test-case-item .tc-assert { margin-top: .2rem; font: 500 11.5px/1.4 var(--f-data); color: var(--bad); white-space: pre-wrap; word-break: break-word; }

/* Journey */
.tl { list-style: none; margin: 0; padding: 0; }
.tl li { display: grid; grid-template-columns: 54px 1fr; gap: .7rem; padding: .28rem 0; font-size: 12.5px; }
.tl .ts { font: 400 11px/1.5 var(--f-data); color: var(--ink-3); }
.tl .txt { color: var(--ink-2); }
.tl li.is-stage { padding-top: .5rem; }
.tl li.is-stage .txt { color: var(--ink); font-weight: 600; }
.tl li.is-error .txt { color: var(--bad); font-weight: 500; }
.tl li.is-warning .txt { color: var(--warn); font-weight: 500; }

/* Deliverables */
.art { border: 1px solid var(--rule); border-radius: 9px; margin-bottom: .5rem; overflow: hidden; }
.art summary { padding: .55rem .8rem; cursor: pointer; font-size: 12.5px; font-weight: 500; }
.art summary .kind { font: 400 11px/1 var(--f-data); color: var(--ink-3); }
.art pre {
  margin: 0; padding: .8rem; border-top: 1px solid var(--rule);
  background: var(--paper-2); overflow-x: auto; font: 400 11.5px/1.55 var(--f-data);
}
.muted { color: var(--ink-3); font-size: 12.5px; }

/* Metrics row (tokens / elapsed): a low-priority footnote, not something a
   PM needs up front, so it sits at the bottom of the sheet in plain text. */
.detail-footer-metrics {
  display: flex; gap: 1.4rem; margin-top: 1.6rem; padding-top: .85rem;
  border-top: 1px solid var(--rule);
}
.footer-metric { display: flex; align-items: baseline; gap: .35rem; }
.footer-metric .m-label {
  font: 600 10px/1 var(--f-ui); text-transform: uppercase; letter-spacing: .08em; color: var(--ink-3);
}
.footer-metric .m-val {
  font: 500 12px/1.2 var(--f-data); color: var(--ink-2); font-variant-numeric: tabular-nums;
}

/* Compact/expand ("Show more") cards: Ticket summary, Stage detail and
   Journey can all run long; collapse them to ~4 lines and let a click
   reveal the rest, since the full detail is also always in the log. */
.section-collapsible { position: relative; overflow: hidden; max-height: 6.6em; }
.summary.section-collapsible { max-height: 14em; }
.tl.section-collapsible { max-height: 18em; }
.stage-breakdown.section-collapsible { max-height: 24em; }
.section-collapsible.expanded { max-height: none; }
.section-collapsible.clamped::after {
  content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2.4em;
  background: linear-gradient(to bottom, transparent, var(--card));
  pointer-events: none;
}
.section-toggle {
  display: inline-flex; align-items: center; gap: .3rem; margin-top: .5rem;
  font: 600 11.5px/1 var(--f-ui); color: var(--ink-3);
  background: none; border: none; padding: 0; cursor: pointer;
}
.section-toggle:hover { color: var(--ink); text-decoration: underline; }

/* Live agent console */
.console-box {
  margin-bottom: 1.4rem; border-radius: 9px; border: 1px solid var(--rule);
  background: #0E1217; color: #DDE3EA; overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.console-header {
  display: flex; align-items: center; gap: .5rem;
  padding: .45rem .8rem; background: #151B23; border-bottom: 1px solid #242D38;
  font: 600 10.5px/1 var(--f-ui); letter-spacing: .07em; color: #8A95A5;
}
.console-dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--ok);
  animation: breathe 1.8s ease-in-out infinite;
}
.console-badge {
  font: 500 9.5px/1 var(--f-data); padding: .2rem .4rem; border-radius: 4px;
  background: rgba(14, 124, 102, .25); color: #34B399;
}
.console-stream {
  padding: .75rem; max-height: 200px; overflow-y: auto;
  font: 400 11.5px/1.55 var(--f-data); display: flex; flex-direction: column; gap: .3rem;
}
.console-stream::-webkit-scrollbar { width: 6px; }
.console-stream::-webkit-scrollbar-thumb { background: #303B49; border-radius: 3px; }
.console-row { display: flex; gap: .55rem; align-items: baseline; word-break: break-word; }
.console-ts { color: #6E7A89; flex: none; font-size: 10.5px; }
.console-tag {
  font-size: 9.5px; padding: .05rem .3rem; border-radius: 3px; text-transform: uppercase; font-weight: 500; flex: none;
}
.console-tag.tool { background: #1B2C42; color: #58A6FF; }
.console-tag.note { background: #2F2415; color: #E3B341; }
.console-tag.error { background: #3D1C1B; color: #F85149; }
.console-tag.stage { background: #1F2E2A; color: #3FB950; }
.console-tag.warn { background: #3D2F13; color: #E3B341; }
.console-msg { flex: 1; color: #E6EDF3; }
.console-msg.is-error { color: #F85149; }
.console-msg.is-warning { color: #E3B341; }

/* ── Language switcher (rendered by public/i18n.js) ──
   Small select dropdown that fits next to header buttons / brand.
   The host element is just a marker (e.g. <div id="lang-switcher">); the
   module drops in <label class="lang-switcher"> + <span>/<select>. */
.lang-switcher {
  display: inline-flex; align-items: center; gap: .45rem;
  font: 500 11.5px/1 var(--f-ui);
  color: var(--ink-2);
  cursor: pointer;
}
.lang-switcher-label {
  letter-spacing: .04em; text-transform: uppercase;
  font-size: 10.5px; color: var(--ink-3);
}
.lang-switcher-select {
  font: 500 12.5px/1 var(--f-ui);
  padding: .38rem 1.65rem .38rem .6rem;
  border: 1px solid var(--rule);
  border-radius: 7px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position:
    calc(100% - .85rem) 55%,
    calc(100% - .55rem) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: border-color .15s;
}
.lang-switcher-select:hover { border-color: var(--ink-3); }
.lang-switcher-select:focus-visible { outline-offset: 0; }
@media (max-width: 640px) {
  .lang-switcher-label { display: none; }
}

/* ── Project switcher (rendered by public/header.js) ──
   Sits where the lang switcher sits in index.html / run.html. The host is just
   a marker <div id="header-projects"></div>; the module replaces it with
   <label class="project-switcher"> + <span>/<select>. The dropdown is
   scoped to the current user's accessible projects. */
.project-switcher {
  display: inline-flex; align-items: center; gap: .45rem;
  font: 500 11.5px/1 var(--f-ui);
  color: var(--ink-2);
  cursor: pointer;
}
.project-switcher-label {
  letter-spacing: .04em; text-transform: uppercase;
  font-size: 10.5px; color: var(--ink-3);
}
.project-switcher-select {
  font: 500 12.5px/1 var(--f-ui);
  padding: .38rem 1.65rem .38rem .6rem;
  border: 1px solid var(--rule);
  border-radius: 7px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-3) 50%),
    linear-gradient(135deg, var(--ink-3) 50%, transparent 50%);
  background-position:
    calc(100% - .85rem) 55%,
    calc(100% - .55rem) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: border-color .15s;
  max-width: 220px;
}
.project-switcher-select:hover { border-color: var(--ink-3); }
.project-switcher-select:focus-visible { outline-offset: 0; }
.project-switcher-empty {
  font: 500 11.5px/1 var(--f-ui);
  color: var(--ink-3);
}
@media (max-width: 720px) {
  .project-switcher-label { display: none; }
}
