/* =========================================================================
   U-DIP — shared stylesheet
   ========================================================================= */
:root {
  --signal: #E0A33E;   /* U-DIP: fills the overlap, nothing else */
  --bg:        #f6f7f8;
  --surface:   #ffffff;
  --surface-2: #f0f2f4;
  --line:      #d9dde2;
  --line-soft: #e8ebee;
  --ink:       #12171c;
  --ink-2:     #495663;
  --ink-3:     #7c8996;
  --accent:    #0f5f66;
  --accent-2:  #0b464b;
  --accent-bg: #e6f1f1;
  --ok:        #1d6b3f;
  --ok-bg:     #e6f2ea;
  --warn:      #8a5a11;
  --warn-bg:   #fbf1e0;
  --bad:       #97231f;
  --bad-bg:    #fbe9e8;
  --radius:    8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:#0e1216; --surface:#151b21; --surface-2:#1b232a; --line:#2a343d; --line-soft:#222b33;
    --ink:#e7ecf1; --ink-2:#a9b6c2; --ink-3:#78848f;
    --accent:#4ec9c9; --accent-2:#7fdcd9; --accent-bg:#12292b;
    --ok:#63c48c; --ok-bg:#14291d; --warn:#d8a24a; --warn-bg:#2a2113; --bad:#e2736c; --bad-bg:#2b1614;
    color-scheme: dark;
  }
}
/* Dark is the product's default, to match discognia.com. The explicit choice
   wins in both directions so the toggle always works. */
:root[data-theme="dark"] {
  --bg:#0e1216; --surface:#151b21; --surface-2:#1b232a; --line:#2a343d; --line-soft:#222b33;
  --ink:#e7ecf1; --ink-2:#a9b6c2; --ink-3:#78848f;
  --accent:#4ec9c9; --accent-2:#7fdcd9; --accent-bg:#12292b;
  --ok:#63c48c; --ok-bg:#14291d; --warn:#d8a24a; --warn-bg:#2a2113; --bad:#e2736c; --bad-bg:#2b1614;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg); color: var(--ink);
  font-family: var(--sans); font-size: 14px; line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1,h2,h3,h4 { margin: 0 0 .5em; line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.25rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
code, .mono { font-family: var(--mono); font-size: .86em; }
.muted { color: var(--ink-3); }
.small { font-size: .82rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }

/* ------------------------------------------------------------- structure */
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 20px; }
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 16px; padding: 10px 20px;
}
.brand { display: flex; align-items: baseline; gap: 9px; font-weight: 700; letter-spacing: -.02em; }
/* The product mark: the wordmark's three bars, on their own. They carry their
   own colours in both themes, so nothing here has to change with the theme. */
.brand .mark {
  width: 26px; height: 26px; flex: none; align-self: baseline;
  position: relative; top: 2px;
}
/* The full lock-up. Two files, one per theme, chosen here rather than in
   script: the theme can change without a reload, and a rule beats having to
   remember to re-point an <img> from three different places. */
.brand .lockup { display: block; flex: none; position: relative; top: 3px; line-height: 0; }
.brand .lockup .lk { height: 24px; width: auto; display: none; }
:root[data-theme="light"] .brand .lockup .lk-light { display: block; }
:root[data-theme="dark"]  .brand .lockup .lk-dark  { display: block; }
/* Neither rule matches before applyTheme() has stamped the attribute, and a
   header with no logo in it for one frame is worse than the wrong one. */
:root:not([data-theme]) .brand .lockup .lk-light { display: block; }
.brand small { font-weight: 500; color: var(--ink-3); letter-spacing: 0; }
.spacer { flex: 1; }

.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; margin-bottom: 16px;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
/* a card that lives inside something else already has a border around it */
.card.plain { border: 0; padding: 0; margin-bottom: 0; background: none; }

/* ------------------------------------------------- folded-away settings
   For the parts of a step that arrive correct and are almost never edited.
   Closed by default, and it must look like a control rather than a heading. */
.fold { border: 1px solid var(--line); border-radius: var(--radius);
        background: var(--surface); margin-bottom: 16px; }
.fold > summary { cursor: pointer; padding: 12px 18px; font-size: 13px;
                  color: var(--ink-2); list-style: none; }
.fold > summary::-webkit-details-marker { display: none; }
.fold > summary::before { content: "\25B8"; display: inline-block; width: 14px;
                          color: var(--ink-3); transition: transform .15s ease; }
.fold[open] > summary::before { transform: rotate(90deg); }
.fold > summary:hover { color: var(--ink); }
.fold > div { padding: 0 18px 18px; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(auto-fit, minmax(300px,1fr)); }
.g3 { grid-template-columns: repeat(auto-fit, minmax(220px,1fr)); }
.g4 { grid-template-columns: repeat(auto-fit, minmax(165px,1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ---------------------------------------------------------------- inputs */
label { display: block; font-size: .8rem; font-weight: 600; color: var(--ink-2); margin-bottom: 4px; }
input, select, textarea, button {
  font-family: inherit; font-size: 14px;
}
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
textarea { min-height: 110px; font-family: var(--mono); font-size: 12.5px; }
.field { margin-bottom: 12px; }

button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 15px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); cursor: pointer; font-weight: 550;
}
button:hover, .btn:hover { background: var(--surface-2); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover, .btn.primary:hover { background: var(--accent-2); border-color: var(--accent-2); }
button.ghost { border-color: transparent; background: transparent; }
button.danger { color: var(--bad); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.sm, .btn.sm { padding: 5px 10px; font-size: 12.5px; }

/* ---------------------------------------------------------------- tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line-soft); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); font-weight: 650; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; font-family: var(--mono); font-size: 12.5px; }
.scroll-x { overflow-x: auto; }

/* ----------------------------------------------------------------- chips */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 100px; font-size: 11.5px; font-weight: 650;
  border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-2);
  letter-spacing: .01em; white-space: nowrap;
}
.chip.ok   { background: var(--ok-bg);   color: var(--ok);   border-color: transparent; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.chip.bad  { background: var(--bad-bg);  color: var(--bad);  border-color: transparent; }
.chip.acc  { background: var(--accent-bg); color: var(--accent); border-color: transparent; }

/* ------------------------------------------------------------ stat tiles */
.stat { background: var(--surface-2); border-radius: var(--radius); padding: 12px 14px; border: 1px solid var(--line-soft); }
.stat .k { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 650; }
.stat .v { font-size: 1.5rem; font-weight: 680; font-family: var(--mono); letter-spacing: -.02em; margin-top: 2px; }
.stat .s { font-size: .78rem; color: var(--ink-3); }

.meter { height: 6px; border-radius: 3px; background: var(--line-soft); overflow: hidden; margin-top: 6px; }
.meter > i { display: block; height: 100%; background: var(--accent); }

/* ------------------------------------------------------------------ tabs */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button {
  border: none; background: transparent; border-bottom: 2px solid transparent;
  border-radius: 0; padding: 9px 13px; color: var(--ink-3); font-weight: 600;
}
.tabs button.on { color: var(--ink); border-bottom-color: var(--accent); }
.tabs button:hover { background: transparent; color: var(--ink); }

/* ----------------------------------------------------------------- misc */
.gatewrap { display: grid; grid-template-columns: repeat(auto-fill, minmax(58px,1fr)); gap: 5px; }
.gate {
  font-family: var(--mono); font-size: 11px; text-align: center; padding: 5px 2px;
  border-radius: 5px; background: var(--ok-bg); color: var(--ok); font-weight: 700; cursor: default;
}
.gate.fail { background: var(--bad-bg); color: var(--bad); }
.notice { padding: 11px 14px; border-radius: var(--radius); font-size: 13px; margin-bottom: 14px; border: 1px solid transparent; }
.notice.ok   { background: var(--ok-bg);   color: var(--ok);   border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.notice.warn { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.notice.bad  { background: var(--bad-bg);  color: var(--bad);  border-color: color-mix(in srgb, var(--bad) 25%, transparent); }
.notice.info { background: var(--accent-bg); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 25%, transparent); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 3px 14px; font-size: 13px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; font-family: var(--mono); font-size: 12.5px; word-break: break-all; }

.hidden { display: none !important; }
.loading { display: inline-block; width: 13px; height: 13px; border: 2px solid var(--line);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.sticky-actions { position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--line);
  padding: 12px 20px; display: flex; gap: 10px; align-items: center; }

@media (max-width: 640px) {
  .wrap { padding: 0 12px; }
  .card { padding: 14px; }
  .topbar { padding: 10px 12px; gap: 10px; }
  .brand small { display: none; }
}


/* =========================================================================
   Console components
   ========================================================================= */

/* ---- toasts ---- */
#toast { position: fixed; right: 16px; bottom: 16px; z-index: 99; display: grid; gap: 8px;
         max-width: min(420px, calc(100vw - 32px)); }
.toastmsg { position: relative; margin: 0; box-shadow: 0 8px 30px rgba(0,0,0,.28); padding-right: 34px; }
.toastx { position: absolute; top: 6px; right: 8px; font-size: 16px; line-height: 1; }
.linky { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline;
         cursor: pointer; font: inherit; opacity: .8; }
.linky:hover { opacity: 1; }
.errdetail { margin: 8px 0 0; padding: 8px 10px; background: rgba(0,0,0,.18); border-radius: 6px;
             font-family: var(--mono); font-size: 11.5px; white-space: pre-wrap; word-break: break-word;
             max-height: 160px; overflow: auto; }

/* ---- busy ---- */
.spin { display: inline-block; width: 12px; height: 12px; vertical-align: -1px;
        border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
        animation: sp .7s linear infinite; opacity: .8; }
@keyframes sp { to { transform: rotate(360deg); } }
button.is-busy { opacity: .85; cursor: progress; }
.skeleton { background: linear-gradient(90deg, var(--surface-2) 25%, var(--line-soft) 37%, var(--surface-2) 63%);
            background-size: 400% 100%; animation: sk 1.3s ease infinite; border-radius: 6px; height: 12px; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---- modal ---- */
.backdrop { position: fixed; inset: 0; background: rgba(4,8,12,.55); backdrop-filter: blur(2px);
            display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 120; }
.modal { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
         padding: 20px; width: min(440px, 100%); box-shadow: 0 24px 60px rgba(0,0,0,.4); }

/* ---- empty states ---- */
.empty { text-align: center; padding: 34px 20px; max-width: 560px; margin: 0 auto; }
.empty-mark { font-family: var(--mono); font-size: 22px; color: var(--accent);
              width: 46px; height: 46px; line-height: 44px; margin: 0 auto 14px;
              border: 1px solid var(--accent); border-radius: 50%; }
.empty h3 { margin-bottom: 8px; font-size: 1.05rem; }
.empty p { color: var(--ink-2); margin: 0 auto; max-width: 46em; }
.empty .examples { margin-top: 16px; text-align: left; display: inline-block; }
.empty .examples ul { margin: 6px 0 0; padding-left: 18px; color: var(--ink-2); font-size: 13px; }
.empty .examples li { margin: 2px 0; }

/* ---- stepper ---- */
.stepper { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0 10px; margin-bottom: 4px;
           scrollbar-width: none; align-items: stretch; }
.stepper::-webkit-scrollbar { display: none; }
.step { flex: 1 1 0; min-width: 118px; text-align: left; background: var(--surface-2);
        border: 1px solid var(--line-soft); border-radius: var(--radius); padding: 9px 11px;
        cursor: pointer; position: relative;
        display: flex; flex-direction: column; align-items: flex-start; gap: 0;
        justify-content: flex-start; height: auto; }
.step:hover { border-color: var(--line); }
.step.on { border-color: var(--accent); background: var(--accent-bg); }
.step.locked { cursor: not-allowed; opacity: .72; }
.step .n { font-size: .68rem; font-family: var(--mono); color: var(--ink-3); }
.step .l { display: block; font-weight: 650; font-size: .88rem; margin-top: 1px; }
.step .s { display: block; font-size: .74rem; margin-top: 2px; }
.step .s.done { color: var(--ok); } .step .s.warn { color: var(--warn); }
.step .s.lock { color: var(--ink-3); } .step .s.ready { color: var(--accent); }
.step .s.todo { color: var(--ink-3); }
.lockwhy { font-size: .82rem; color: var(--ink-2); background: var(--surface-2);
           border-left: 2px solid var(--warn); padding: 8px 12px; border-radius: 0 6px 6px 0;
           margin: 0 0 16px; }

/* ---- intervals: uncertainty drawn as uncertainty ---- */
.iv { position: relative; height: 16px; }
.iv .track { position: absolute; left: 0; right: 0; top: 7px; height: 2px; background: var(--line); }
.iv .band { position: absolute; top: 3px; height: 10px; border-radius: 5px;
            background: color-mix(in srgb, var(--accent) 28%, transparent);
            border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); }
.iv .pt { position: absolute; top: 0; width: 2px; height: 16px; background: var(--accent); border-radius: 1px; }
.iv .lab { display: none; }
.ivscale { display: flex; justify-content: space-between; font-family: var(--mono);
           font-size: 10px; color: var(--ink-3); margin-top: 1px; }

/* ---- rank rows ---- */
.rankrow { display: grid; grid-template-columns: 42px 1.4fr 1.6fr auto; gap: 14px; align-items: center;
           padding: 14px 0; border-top: 1px solid var(--line-soft); }
.rankrow:first-of-type { border-top: 0; }
.rankno { font-family: var(--mono); font-size: 1.4rem; font-weight: 700; color: var(--accent);
          text-align: center; }
.bars { display: grid; gap: 4px; }
.barline { display: grid; grid-template-columns: 78px 1fr 46px; gap: 8px; align-items: center;
           font-size: .74rem; color: var(--ink-3); }
.barline .bar { height: 5px; border-radius: 3px; background: var(--line-soft); overflow: hidden; }
.barline .bar > i { display: block; height: 100%; background: var(--accent); }
.barline .bar > i.warnfill { background: var(--warn); }
.barline .v { font-family: var(--mono); text-align: right; color: var(--ink-2); }

/* ---- movement track (console) ---- */
.move { position: relative; height: 30px; }
.move .axis { position: absolute; left: 0; right: 0; top: 15px; height: 1px; background: var(--line); }
.move i { position: absolute; top: 9px; width: 9px; height: 9px; border-radius: 50%; transform: translateX(-4px); }
.move i.p { background: var(--ink-3); }
.move i.e { background: var(--warn); }
.move i.b { background: var(--accent); width: 11px; height: 11px; top: 8px; }
.move .arrow { position: absolute; top: 14px; height: 2px; background: var(--accent); opacity: .5; }
.movekey { display: flex; gap: 12px; font-size: .72rem; color: var(--ink-3); }
.movekey span::before { content: "●"; margin-right: 4px; }
.movekey .kp::before { color: var(--ink-3); }
.movekey .ke::before { color: var(--warn); }
.movekey .kb::before { color: var(--accent); }

/* ---- cold start ---- */
.cold { border: 1px solid var(--accent); border-radius: var(--radius); padding: 18px 20px;
        background: var(--accent-bg); margin-bottom: 16px; }
.cold h3 { color: var(--accent); margin-bottom: 6px; }
.cold p { color: var(--ink-2); }
.progwrap { margin-top: 14px; }
.prog { height: 8px; border-radius: 4px; background: color-mix(in srgb, var(--accent) 18%, transparent);
        overflow: hidden; }
.prog > i { display: block; height: 100%; background: var(--accent); }
.progtxt { display: flex; justify-content: space-between; font-size: .78rem; margin-top: 5px;
           color: var(--ink-2); }

/* ---- questionnaire ---- */
.qprog { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 10px 0 8px;
         border-bottom: 1px solid var(--line-soft); margin-bottom: 8px; }
.qbar { height: 4px; border-radius: 2px; background: var(--line-soft); overflow: hidden; margin-top: 6px; }
.qbar > i { display: block; height: 100%; background: var(--accent); transition: width .25s ease; }
.opt { display: block; width: 100%; text-align: left; padding: 13px 14px; margin: 6px 0;
       border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface);
       cursor: pointer; font-size: 15px; min-height: 46px; }
.opt:hover { border-color: var(--accent); }
.opt.sel { border-color: var(--accent); background: var(--accent-bg); color: var(--accent); font-weight: 600; }

/* ---- print ---- */
@media print {
  .noprint, .topbar, .sidebar, .stepper, #toast, .tabs { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border-color: #ccc; break-inside: avoid; page-break-inside: avoid; }
  .layout { display: block; padding: 0; }
  a[href]::after { content: ""; }
}

/* ---- small screens ---- */
@media (max-width: 620px) {
  .wrap { padding: 0 12px; }
  .rankrow { grid-template-columns: 32px 1fr; row-gap: 8px; }
  .rankrow > *:nth-child(3), .rankrow > *:nth-child(4) { grid-column: 1 / -1; }
  .step { min-width: 104px; }
  .card { padding: 14px; }
  h1 { font-size: 1.35rem; }
  table { font-size: 12.5px; }
}


/* ---- narrow-screen containment ------------------------------------------
   In a column flex layout min-width:0 does not stop a wide child from pushing
   the page sideways, so the panes are pinned to the viewport explicitly. */
.topbar { flex-wrap: wrap; row-gap: 6px; }
.layout { min-width: 0; }
.main, .sidebar { min-width: 0; max-width: 100%; }
.row > .small.muted { min-width: 0; }
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar, .main { width: 100%; flex: 0 0 auto; }
}
@media (max-width: 620px) {
  .rankrow .bars { min-width: 0; }
  .barline { grid-template-columns: 68px 1fr 40px; }
  .kv { grid-template-columns: 1fr; }
  .kv dd { margin-bottom: 6px; }
  .modal { width: 100%; }
}

.beliefline { display: flex; align-items: baseline; gap: 9px; margin-top: 10px; flex-wrap: wrap; }
.bignum { font-family: var(--mono); font-size: 1.35rem; font-weight: 700; color: var(--ink); letter-spacing: -.02em; }
