/* Module 03 — Context Window.
   Only what styles.css does not already provide: the stacked budget bar, the
   item rows colour-coded by kind, and the "outside the window" area.
   Colours are declared as tokens here and used via var() everywhere below. */

:root {
  --cw-system: var(--accent);
  --cw-user: #0f766e;
  --cw-assistant: #b45309;
  --cw-doc: #7c3aed;
  --cw-summary: #64748b;
  --cw-reserve: #94a3b8;
  --cw-free: #e3e9f2;

  --cw-system-soft: var(--accent-soft);
  --cw-user-soft: #e6f4f1;
  --cw-assistant-soft: var(--warn-soft);
  --cw-doc-soft: #f1ebfe;
  --cw-summary-soft: var(--surface-alt);
}

/* Shared chips are 40 px; this module's are primary controls, so lift them to
   the 44 px tap target without touching the shared sheet. */
.chips .chip { min-height: 44px; }

/* ------------------------------------------------------------- budget bar */

.cw-bar {
  display: flex;
  width: 100%;
  height: 46px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--cw-free);
  margin-bottom: 10px;
}
.cw-seg {
  flex: 0 0 auto;
  min-width: 3px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: .74rem;
  font-weight: 700;
  color: #fff;
  border-right: 1px solid rgba(255, 255, 255, .55);
  transition: width .25s ease;
}
.cw-seg:last-child { border-right: 0; }
.cw-seg-system    { background: var(--cw-system); }
.cw-seg-user      { background: var(--cw-user); }
.cw-seg-assistant { background: var(--cw-assistant); }
.cw-seg-doc       { background: var(--cw-doc); }
.cw-seg-summary   { background: var(--cw-summary); }
.cw-seg-reserve {
  background: repeating-linear-gradient(
    135deg, var(--cw-reserve), var(--cw-reserve) 6px,
    var(--surface) 6px, var(--surface) 12px);
  color: var(--ink);
}
.cw-seg-free { background: var(--cw-free); color: var(--ink-faint); }

@media (prefers-reduced-motion: reduce) { .cw-seg { transition: none; } }

.cw-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  font-size: .82rem;
  color: var(--ink-soft);
  margin-bottom: 4px;
}
.cw-legend span { display: inline-flex; align-items: center; gap: 6px; }
.cw-swatch {
  width: 13px; height: 13px; flex: none;
  border-radius: 3px;
  border: 1px solid rgba(15, 23, 42, .18);
}

/* ------------------------------------------------------------- the readout */

.cw-readout {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(136px, 1fr));
  gap: 10px;
  margin: 14px 0;
}
.cw-stat {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface-alt);
  padding: 10px 12px;
}
.cw-stat .k {
  display: block;
  font-size: .78rem;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--ink-faint);
}
.cw-stat .v {
  font-family: var(--mono);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.cw-stat .v.warn { color: var(--danger); }

/* ---------------------------------------------------------------- controls */

.cw-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin: 4px 0 18px;
}
.cw-actions button.btn { width: 100%; min-height: 48px; }

/* ------------------------------------------------------------- item rows */

.cw-list { display: grid; gap: 8px; }
.cw-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--cw-summary);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 10px 12px;
}
.cw-row-system    { border-left-color: var(--cw-system);    background: var(--cw-system-soft); }
.cw-row-user      { border-left-color: var(--cw-user);      background: var(--cw-user-soft); }
.cw-row-assistant { border-left-color: var(--cw-assistant); background: var(--cw-assistant-soft); }
.cw-row-doc       { border-left-color: var(--cw-doc);       background: var(--cw-doc-soft); }
.cw-row-summary   { border-left-color: var(--cw-summary);   background: var(--cw-summary-soft); }

.cw-row-main { flex: 1 1 auto; min-width: 0; }
.cw-row-kind {
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.cw-row-text { font-size: .93rem; line-height: 1.45; margin: 2px 0 0; }
.cw-row-cost {
  flex: none;
  font-family: var(--mono);
  font-size: .82rem;
  font-weight: 700;
  color: var(--ink-soft);
  white-space: nowrap;
  padding-top: 2px;
}

/* --------------------------------------------------- outside the window */

.cw-outside-card { border-color: var(--danger); }
.cw-outside-card > .section-title h2 { color: var(--danger); }

.cw-gone .cw-row {
  background: var(--surface-alt);
  border-left-color: var(--line-strong);
  opacity: .72;
}
.cw-gone .cw-row-text { text-decoration: line-through; color: var(--ink-faint); }
.cw-gone .cw-row-kind { color: var(--ink-faint); }

.cw-flash { animation: cw-flash 1.1s ease-out 1; }
@keyframes cw-flash {
  0%   { box-shadow: 0 0 0 0 var(--danger); background: var(--danger-soft); }
  100% { box-shadow: 0 0 0 10px rgba(185, 28, 28, 0); background: transparent; }
}
@media (prefers-reduced-motion: reduce) { .cw-flash { animation: none; } }

.cw-empty { color: var(--ink-faint); font-style: italic; margin: 0; }
.cw-fineprint { font-size: .84rem; color: var(--ink-faint); margin: 8px 0 0; }

/* ------------------------------------------------------ strategy compare */

.cw-cols { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 900px) { .cw-cols { grid-template-columns: repeat(3, 1fr); align-items: start; } }

.cw-col {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.cw-col.is-active { border-color: var(--accent); box-shadow: var(--shadow-sm); }
.cw-col-head {
  padding: 11px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-alt);
}
.cw-col.is-active .cw-col-head { background: var(--accent-soft); }
.cw-col-head h3 { margin: 0; font-size: 1rem; }
.cw-col-head .sub { font-size: .82rem; color: var(--ink-soft); }
.cw-col-body { padding: 12px; display: grid; gap: 8px; }
.cw-mini {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: .88rem;
  border-left: 4px solid var(--cw-summary);
  background: var(--surface-alt);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  padding: 6px 9px;
}
.cw-mini.kind-system    { border-left-color: var(--cw-system); }
.cw-mini.kind-user      { border-left-color: var(--cw-user); }
.cw-mini.kind-assistant { border-left-color: var(--cw-assistant); }
.cw-mini.kind-doc       { border-left-color: var(--cw-doc); }
.cw-mini.gone { opacity: .6; text-decoration: line-through; }
.cw-mini .n { font-family: var(--mono); font-size: .8rem; flex: none; color: var(--ink-soft); }
.cw-mini .l { min-width: 0; overflow-wrap: anywhere; }

/* ------------------------------------------------------- long-chat cost */

.cw-turns { display: grid; gap: 7px; margin: 4px 0 14px; }
.cw-turn { display: grid; grid-template-columns: 64px 1fr auto; gap: 10px; align-items: center; }
.cw-turn .t { font-size: .84rem; font-weight: 700; color: var(--ink-soft); }
.cw-turn .track { height: 16px; border-radius: 999px; background: var(--cw-free); overflow: hidden; }
.cw-turn .fill { height: 100%; background: var(--accent); border-radius: 999px; }
.cw-turn .n { font-family: var(--mono); font-size: .82rem; font-variant-numeric: tabular-nums; }

@media (max-width: 460px) {
  .cw-turn { grid-template-columns: 52px 1fr auto; gap: 7px; }
  .cw-turn .t, .cw-turn .n { font-size: .78rem; }
}
