/* VY Retention — styled to the VY Design System (v1.0), same base as vy-sales:
   white base, aqua primary + violet secondary, Archivo display,
   Inter body, JetBrains Mono for labels & numerals.

   Light is the default and does NOT follow the OS setting — the design system's
   base is white. Dark is opt-in via the topbar toggle (data-theme="dark"). */
:root {
  color-scheme: light;
  --ink: #0B0F14;
  --ink-2: #161B22;
  --paper: #ffffff;
  --paper-2: #F2F4F7;
  --mute: #667085;
  --rule: #E4E7EC;
  --aqua: #27C4D1;
  --aqua-deep: #0E8A95;
  --violet: #7C5BFF;
  --violet-deep: #5B3CD6;
  --good: #12B76A;
  --warn: #B7791F;
  --bad: #D92D20;

  --bg: var(--paper-2);
  --surface: var(--paper);
  --accent: var(--aqua);
  --focus: color-mix(in srgb, var(--aqua) 45%, transparent);

  --font-display: "Archivo", Helvetica, Arial, sans-serif;
  --font-body: "Inter", Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;

  --r-sm: 8px;
  --r-md: 16px;
  --r-pill: 999px;
  --shadow: 0 1px 2px rgba(11, 15, 20, .04), 0 8px 24px rgba(11, 15, 20, .06);
  --ease: cubic-bezier(.2, .8, .2, 1);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0B0F14; --surface: #161B22; --ink: #F2F4F7; --ink-2: #E4E7EC;
  --mute: #98A2B3; --rule: #262D38;
  --good: #35C08A; --warn: #D9A441; --bad: #E5726C;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* .field's display:flex must not defeat the hidden attribute */
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
}

.mono-label {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .16em; color: var(--mute);
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 24px; background: var(--surface); border-bottom: 1px solid var(--rule);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 14px; }
.vy-mark {
  width: 42px; height: 42px; border-radius: var(--r-sm);
  display: grid; place-items: center;
  background: #161B22; flex: none;
}
.vy-mark img { width: 30px; height: 30px; display: block; }
.brand-title {
  font-family: var(--font-display); font-weight: 900; font-size: 19px;
  letter-spacing: -0.015em; line-height: 1;
}
.brand-sub { color: var(--mute); font-size: 12.5px; margin-top: 3px; }
.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.picker { display: flex; align-items: center; gap: 10px; }
.picker input, .picker select {
  padding: 8px 12px; border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); font: 14px var(--font-body);
}

/* Theme toggle — sun in light, moon in dark */
.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;
}
.theme-toggle {
  appearance: none; cursor: pointer; flex: none;
  width: 38px; height: 38px; border-radius: var(--r-sm);
  border: 1px solid var(--rule); background: var(--surface);
  display: grid; place-items: center;
  transition: border-color 120ms var(--ease), background 120ms var(--ease);
}
.theme-toggle:hover { border-color: var(--aqua); }
.theme-toggle:focus-visible { outline: none; border-color: var(--aqua); box-shadow: 0 0 0 3px var(--focus); }
.theme-icon {
  width: 16px; height: 16px; display: block; color: var(--mute);
  background: currentColor;
  -webkit-mask: var(--icon-sun) center / contain no-repeat;
          mask: var(--icon-sun) center / contain no-repeat;
}
:root[data-theme="dark"] .theme-icon {
  -webkit-mask-image: var(--icon-moon);
          mask-image: var(--icon-moon);
}
:root {
  --icon-sun: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round'><circle cx='12' cy='12' r='4'/><path d='M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4'/></svg>");
  --icon-moon: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M21 12.8A9 9 0 1 1 11.2 3a7 7 0 0 0 9.8 9.8z'/></svg>");
}

/* Tabs */
.tabs { display: flex; gap: 2px; padding: 10px 24px 0; background: var(--surface); border-bottom: 1px solid var(--rule); }
.tab {
  appearance: none; border: none; background: none; cursor: pointer;
  padding: 10px 16px 12px; font: 600 14.5px var(--font-body); color: var(--mute);
  border-bottom: 2px solid transparent;
  transition: color 240ms var(--ease), border-color 240ms var(--ease);
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--aqua); }

main { max-width: 1360px; margin: 0 auto; padding: 24px 20px; }
.view { display: none; }
.view.is-active { display: block; animation: view-in 240ms var(--ease); }
@keyframes view-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--surface); border-radius: var(--r-md);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 18px;
}
.card-head {
  font-family: var(--font-mono); font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .16em; color: var(--mute);
  margin-bottom: 14px;
}

/* List toolbar — search + filters + sort, above the table */
.list-toolbar {
  display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px;
}
.list-toolbar input[type="search"] {
  flex: 1 1 220px; min-width: 180px;
}
.list-toolbar input, .list-toolbar select {
  padding: 9px 12px; border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); font: 13.5px var(--font-body);
  transition: border-color 120ms var(--ease), box-shadow 120ms var(--ease);
}
.list-toolbar input:focus, .list-toolbar select:focus {
  outline: none; border-color: var(--aqua); box-shadow: 0 0 0 3px var(--focus);
}

/* Pager — count left, prev/next right */
.pager {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding-top: 14px;
}
.pager-btns { display: flex; gap: 8px; }
.pager button:disabled { opacity: .4; cursor: default; }
.pager button:disabled:hover { border-color: var(--rule); background: var(--surface); }

/* Tables — mono headers, right-aligned numerics, hairline rules */
.table-scroll { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { padding: 9px 10px; text-align: right; white-space: nowrap; }
table.grid th:first-child, table.grid td:first-child,
table.grid th.l, table.grid td.l { text-align: left; }
table.grid thead th {
  font-family: var(--font-mono); font-weight: 600; color: var(--mute);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .14em;
  border-bottom: 1px solid var(--rule);
}
table.grid tbody td {
  border-bottom: 1px solid var(--rule);
  font-family: var(--font-mono); font-weight: 500; font-size: 12.5px;
}
table.grid tbody td.l { font-family: var(--font-body); font-size: 13px; font-weight: 500; }
table.grid tbody tr:hover td { background: color-mix(in srgb, var(--aqua) 5%, transparent); }
table.grid tr.total-row td {
  font-weight: 700; border-top: 1px solid var(--ink); border-bottom: none;
}
table.grid tr.total-row td.l { font-weight: 700; }

/* The "why call" line is the one column that should wrap, not truncate.
   max-width on a td is unreliable in auto table layout, so the constraint
   lives on an inner div. */
th.why-col { min-width: 300px; }
td.why-col { color: var(--mute); font-size: 12.5px; }
.why-text { width: 320px; white-space: normal; line-height: 1.35; }

.mname { font-weight: 600; }
.mid { font-family: var(--font-mono); font-size: 10.5px; color: var(--mute); }
.tel { color: var(--aqua-deep); text-decoration: none; font-family: var(--font-mono); }
:root[data-theme="dark"] .tel { color: var(--aqua); }
.tel:hover { text-decoration: underline; }
.attempts { font-family: var(--font-mono); font-size: 10.5px; color: var(--mute); }

/* Priority-tier chip: 1 = urgent save, 2 = protect, 3 = standard */
.tier-chip {
  display: inline-grid; place-items: center;
  width: 22px; height: 22px; border-radius: 50%;
  font-family: var(--font-mono); font-weight: 600; font-size: 11.5px;
  background: color-mix(in srgb, var(--mute) 14%, transparent); color: var(--mute);
}
.tier-chip.t1 { background: color-mix(in srgb, var(--bad) 14%, transparent);  color: var(--bad); }
.tier-chip.t2 { background: color-mix(in srgb, var(--violet) 14%, transparent); color: var(--violet-deep); }
:root[data-theme="dark"] .tier-chip.t2 { color: var(--violet); }
.tier-chip.t3 { background: color-mix(in srgb, var(--aqua) 14%, transparent); color: var(--aqua-deep); }
:root[data-theme="dark"] .tier-chip.t3 { color: var(--aqua); }

/* Status pill — glyphless tint + text, never color alone */
.pill {
  display: inline-block; font-family: var(--font-mono); font-weight: 600; font-size: 11.5px;
  padding: 2px 8px; border-radius: var(--r-pill);
  background: color-mix(in srgb, var(--mute) 12%, transparent); color: var(--mute);
}
.pill.good { background: color-mix(in srgb, var(--good) 14%, transparent); color: var(--good); }
.pill.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.pill.bad  { background: color-mix(in srgb, var(--bad) 12%, transparent);  color: var(--bad); }

.btn-log {
  appearance: none; cursor: pointer;
  font: 600 12.5px var(--font-body);
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--rule); border-radius: var(--r-pill);
  padding: 5px 14px;
  transition: border-color 120ms var(--ease), background 120ms var(--ease);
}
.btn-log:hover { border-color: var(--aqua); background: color-mix(in srgb, var(--aqua) 8%, transparent); }

/* Log dialog */
dialog#log-dialog {
  border: none; border-radius: var(--r-md); box-shadow: var(--shadow);
  background: var(--surface); color: var(--ink);
  padding: 22px; width: min(560px, calc(100vw - 32px));
}
dialog#log-dialog::backdrop { background: rgba(11, 15, 20, .45); }
.log-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.log-member { font-family: var(--font-display); font-weight: 800; font-size: 18px; letter-spacing: -0.01em; }
.log-sub { color: var(--mute); font-size: 12.5px; margin-top: 3px; }
.icon-btn {
  appearance: none; border: 1px solid var(--rule); background: var(--surface);
  color: var(--mute); cursor: pointer; border-radius: var(--r-sm);
  width: 30px; height: 30px; font-size: 13px;
}
.icon-btn:hover { border-color: var(--aqua); color: var(--ink); }
.log-why {
  margin: 12px 0 16px; padding: 10px 12px; border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--aqua) 8%, transparent);
  font-size: 13px; line-height: 1.4;
}
.log-why:empty { display: none; }

/* Form */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.field label { font-size: 12.5px; color: var(--mute); font-weight: 600; }
.field-hint-inline { font-weight: 400; font-size: 11px; }
.field input, .field select, .field textarea {
  padding: 10px 12px; border: 1px solid var(--rule); border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink); font: inherit; width: 100%;
  transition: border-color 120ms var(--ease), box-shadow 120ms var(--ease);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--aqua); box-shadow: 0 0 0 3px var(--focus);
}
.branch-out {
  padding: 10px 12px; border: 1px dashed var(--rule); border-radius: var(--r-sm);
  color: var(--mute); background: color-mix(in srgb, var(--bg) 60%, transparent);
  font-family: var(--font-mono);
}
.form-actions { display: flex; align-items: center; gap: 16px; margin-top: 18px; }
.btn-primary {
  appearance: none; border: none; cursor: pointer;
  font: 700 15px var(--font-body);
  background: var(--aqua); color: #0B0F14;
  padding: 12px 28px; border-radius: var(--r-pill);
  transition: transform 120ms var(--ease), background 120ms var(--ease);
}
.btn-primary:hover { background: color-mix(in srgb, var(--aqua) 88%, #ffffff); }
.btn-primary:active { transform: scale(.98); }
.status { font-size: 13.5px; font-weight: 600; }
.status.ok { color: var(--good); }
.status.err { color: var(--bad); }

/* Earlier-calls history inside the dialog */
.log-history { margin-top: 18px; }
.log-history:empty { display: none; }
.hist-row {
  display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline;
  padding: 7px 0; border-top: 1px solid var(--rule); font-size: 12.5px;
}
.hist-n { font-family: var(--font-mono); color: var(--mute); }
.hist-what { font-weight: 600; }
.hist-when { color: var(--mute); font-size: 11.5px; }
.hist-notes { flex-basis: 100%; color: var(--mute); }

/* Progress KPI cards */
.kpi-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border-radius: var(--r-md);
  box-shadow: var(--shadow); padding: 18px 20px 16px;
}
.kpi-cash {
  font-family: var(--font-mono); font-weight: 600; font-size: 30px;
  letter-spacing: -0.02em; line-height: 1;
}
.kpi-target { color: var(--mute); font-size: 12.5px; margin-top: 6px; }

.asof-row { display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: baseline; margin-bottom: 16px; }
.asof { color: var(--ink); }
.basis-note { color: var(--mute); font-size: 12.5px; }
.err-note { color: var(--bad); font-size: 13.5px; font-weight: 600; padding: 8px 0; }

.foot {
  max-width: 1360px; margin: 8px auto 36px; padding: 0 20px;
  color: var(--mute); font-size: 12px;
}

@media (max-width: 900px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 720px) {
  .form-grid { grid-template-columns: 1fr; }
  main { padding: 16px 14px; }
  .kpi-cash { font-size: 24px; }
}
@media (max-width: 460px) { .kpi-grid { grid-template-columns: 1fr 1fr; } }

/* ── VY IT Ops additions ─────────────────────────────────────────────────
   Extends the shared VY design system rather than restating it: the tokens,
   .card, .grid, .pill, .field and .kpi bases all come from above. */

/* Section headings inside a view */
.sec-head {
  font-family: var(--font-display); font-weight: 800; font-size: 15px;
  letter-spacing: -0.01em; margin: 26px 0 12px; display: flex;
  align-items: baseline; gap: 10px;
}
.sec-head:first-child { margin-top: 4px; }
.sec-sub { font: 400 12.5px var(--font-body); color: var(--mute); }

/* Stat tiles. The left rule carries the tone so the number itself stays ink —
   a wall of coloured digits reads as decoration, a coloured edge reads as state. */
.kpi { border-left: 3px solid var(--rule); }
.kpi-good { border-left-color: var(--good); }
.kpi-warn { border-left-color: var(--warn); }
.kpi-bad  { border-left-color: var(--bad); }
.kpi-info { border-left-color: var(--aqua); }
.kpi-mute { border-left-color: var(--rule); }
.kpi-label { margin-bottom: 8px; }
.kpi-value {
  font-family: var(--font-mono); font-weight: 600; font-size: 26px;
  letter-spacing: -0.02em; line-height: 1;
}
.kpi-note { color: var(--mute); font-size: 12px; margin-top: 6px; line-height: 1.35; }

.pill.info { background: color-mix(in srgb, var(--aqua) 16%, transparent); color: var(--aqua-deep); }
.pill.mute { background: color-mix(in srgb, var(--mute) 12%, transparent); color: var(--mute); }

/* Alert strip — only rendered when something is actually wrong. */
.alert-strip { margin-bottom: 18px; display: flex; flex-direction: column; gap: 8px; }
.alert {
  background: color-mix(in srgb, var(--bad) 8%, var(--surface));
  border-left: 3px solid var(--bad); border-radius: var(--r-sm);
  padding: 11px 14px; font-size: 13.5px; line-height: 1.45;
}
.alert-ok .alert {
  background: color-mix(in srgb, var(--good) 8%, var(--surface));
  border-left-color: var(--good); color: var(--mute);
}

/* Sub-tabs inside the Registers view */
.subtabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.subtab {
  appearance: none; cursor: pointer; font: 600 12.5px var(--font-body);
  background: var(--surface); color: var(--mute);
  border: 1px solid var(--rule); border-radius: var(--r-pill); padding: 6px 16px;
  transition: color 140ms var(--ease), border-color 140ms var(--ease);
}
.subtab:hover { color: var(--ink); }
.subtab.is-active { color: var(--ink); border-color: var(--aqua); box-shadow: inset 0 -2px 0 var(--aqua); }

/* Table cell texture */
.cell-sub { color: var(--mute); font-size: 11.5px; line-height: 1.4; }
.cell-bad { color: var(--bad); font-weight: 600; }
.cell-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.grid tr.row-bad td { background: color-mix(in srgb, var(--bad) 5%, transparent); }
.empty { color: var(--mute); font-size: 13px; padding: 22px 8px; text-align: center; }

/* Dialog: a full-width field for long text */
.field-wide { grid-column: 1 / -1; }
.hist-head { margin: 14px 0 6px; }

.whoami-name { font-size: 13.5px; font-weight: 600; }

@media (max-width: 1100px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 620px)  { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }

/* Keep the widest registers scrollable without letting a single prose column
   push the action button out of reach. */
.grid td { vertical-align: top; }
.grid td .cell-sub { max-width: 46ch; }

/* ── Dashboard: six state cards + one attention list ─────────────────────
   Replaces a 27-tile grid. The card shows one number per area; the coloured
   dot carries the state so the numerals stay ink and the row stays readable. */
.board {
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 14px; margin-bottom: 32px;
}
.board-card {
  appearance: none; cursor: pointer; text-align: left; font: inherit; color: inherit;
  display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--r-md);
  padding: 16px 18px 15px;
  transition: border-color 140ms var(--ease), transform 140ms var(--ease), box-shadow 140ms var(--ease);
}
.board-card:hover { border-color: var(--aqua); transform: translateY(-2px); box-shadow: var(--shadow); }
.board-card:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.board-top { display: flex; align-items: center; gap: 8px; }
.board-label { letter-spacing: .12em; }
.board-value {
  font-family: var(--font-mono); font-weight: 600; font-size: 30px;
  letter-spacing: -0.03em; line-height: 1;
}
.board-note { color: var(--mute); font-size: 12px; line-height: 1.35; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--mute); }
.dot-good { background: var(--good); }
.dot-warn { background: var(--warn); }
.dot-bad  { background: var(--bad); }
.dot-info { background: var(--aqua); }
.dot-mute { background: var(--rule); }

.attn-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.attn-head h2 {
  font-family: var(--font-display); font-weight: 800; font-size: 17px;
  letter-spacing: -0.015em; margin: 0;
}
.attn-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.attn {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--surface); padding: 13px 18px; font-size: 13.5px; line-height: 1.45;
  border-left: 3px solid var(--rule);
}
.attn:first-child { border-radius: var(--r-md) var(--r-md) 0 0; }
.attn:last-child  { border-radius: 0 0 var(--r-md) var(--r-md); }
.attn:only-child  { border-radius: var(--r-md); }
.attn-bad  { border-left-color: var(--bad); }
.attn-warn { border-left-color: var(--warn); }
.attn-info { border-left-color: var(--aqua); }
.attn-text { flex: 1; }
.attn-go {
  appearance: none; cursor: pointer; flex: none;
  font: 600 12px var(--font-body); color: var(--mute);
  background: none; border: none; padding: 4px 2px;
  transition: color 140ms var(--ease);
}
.attn-go:hover { color: var(--aqua-deep); }
.attn-empty {
  background: color-mix(in srgb, var(--good) 7%, var(--surface));
  border-left: 3px solid var(--good); border-radius: var(--r-md);
  padding: 16px 18px; color: var(--mute); font-size: 13.5px; margin: 0; line-height: 1.5;
}

@media (max-width: 1100px) { .board { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 620px)  { .board { grid-template-columns: repeat(2, 1fr); }
  .attn { flex-direction: column; align-items: flex-start; gap: 8px; } }
