/* Mythos ERP — design system component layer.
 *
 * Built entirely on assets/tokens.css, which is a VERBATIM copy of the Hub's
 * token file. That is deliberate: the ERP and the Hub cannot drift if they
 * read the same values. If a token is missing here, add it to the shared file
 * rather than inventing a local one.
 *
 * Rules this file keeps, and the legacy stylesheets did not:
 *   - no literal colour values (the legacy CSS has 63 distinct hex values and
 *     399 rgba() calls across 3,244 lines)
 *   - no !important (the legacy CSS has 188)
 *   - no inline styles and no inline event handlers — the platform CSP is
 *     script-src 'self', which forbids both
 *   - one 35° gesture per view (A-012): the topbar rule, nowhere else
 */

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

body {
  background: var(--mythos-ground);
  color: var(--mythos-text-primary);
  font-family: var(--mythos-font-text);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

:focus-visible { outline: 2px solid var(--mythos-focus-ring); outline-offset: 2px; }

.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;
}
.skip-link {
  position: absolute; left: -9999px; top: 0; z-index: 100;
  background: var(--mythos-accent); color: var(--mythos-text-on-accent);
  padding: 12px 20px; font-weight: var(--mythos-weight-semibold);
}
.skip-link:focus { left: 0; }

/* ── Layout shell ──────────────────────────────────────────────────────── */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "rail topbar" "rail main";
  min-height: 100vh;
}

.topbar {
  grid-area: topbar;
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--mythos-space-5);
  min-height: 64px; padding: 0 var(--mythos-space-6);
  background: var(--mythos-ground-deep);
  border-bottom: 1px solid var(--mythos-border-hairline);
  position: relative; overflow: hidden;
}
/* The view's single 35° gesture. */
.topbar::after {
  content: ""; position: absolute; right: -40px; top: 0; bottom: 0; width: 18%;
  background: linear-gradient(125deg, transparent 0 55%, var(--mythos-accent-dim) 55% 55.4%, transparent 55.4%);
  pointer-events: none;
}
.topbar h1 {
  font-family: var(--mythos-font-display);
  font-weight: var(--mythos-weight-semibold);
  font-size: 19px; letter-spacing: -0.01em;
}
.topbar-tools { display: flex; align-items: center; gap: var(--mythos-space-3); }

.rail {
  grid-area: rail;
  background: var(--mythos-ground-deep);
  border-right: 1px solid var(--mythos-border-hairline);
  padding: var(--mythos-space-5) var(--mythos-space-4);
  display: flex; flex-direction: column; gap: var(--mythos-space-2);
}
.rail-brand {
  display: flex; align-items: baseline; gap: var(--mythos-space-3);
  padding: 0 var(--mythos-space-3) var(--mythos-space-5);
}
.rail-brand .wordmark {
  font-family: var(--mythos-font-display);
  font-weight: var(--mythos-weight-semibold);
  font-size: 17px; letter-spacing: 0.02em;
  color: var(--mythos-text-primary); text-decoration: none;
}
.rail-brand .unit {
  font-size: 11px; letter-spacing: 0.10em; text-transform: uppercase;
  color: var(--mythos-accent); font-weight: var(--mythos-weight-medium);
}
.rail a {
  display: flex; align-items: center; gap: var(--mythos-space-3);
  min-height: 44px; padding: 0 var(--mythos-space-4);
  border-radius: var(--mythos-radius-control);
  color: var(--mythos-text-secondary); text-decoration: none;
  font-size: 14px; font-weight: var(--mythos-weight-medium);
  transition: background var(--mythos-motion-micro) var(--mythos-ease-move);
}
.rail a:hover { background: var(--mythos-surface); color: var(--mythos-text-primary); }
.rail a[aria-current="page"] {
  background: var(--mythos-surface-card);
  color: var(--mythos-text-primary);
  box-shadow: inset 2px 0 0 var(--mythos-accent);
}
.rail a .glyph { width: 18px; text-align: center; opacity: 0.85; }
.rail-foot { margin-top: auto; padding: var(--mythos-space-4) var(--mythos-space-3) 0; }

main { grid-area: main; padding: var(--mythos-space-7) var(--mythos-space-6); }
.view { display: none; }
.view[data-active="true"] { display: block; }

.view-head { margin-bottom: var(--mythos-space-6); }
.view-kicker {
  font-size: 11px; letter-spacing: 0.10em; text-transform: uppercase;
  color: var(--mythos-accent); margin-bottom: var(--mythos-space-2);
}
.view-head h2 {
  font-family: var(--mythos-font-display);
  font-weight: var(--mythos-weight-semibold);
  font-size: clamp(22px, 2.6vw, 28px); letter-spacing: -0.015em;
}
.view-head p { color: var(--mythos-text-secondary); margin-top: var(--mythos-space-2); max-width: 68ch; }

/* ── Cards ─────────────────────────────────────────────────────────────── */
.grid { display: grid; gap: var(--mythos-space-5); }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }

.card {
  background: var(--mythos-surface);
  border: 1px solid var(--mythos-border-hairline);
  border-radius: var(--mythos-radius-card);
  padding: var(--mythos-space-6);
  display: flex; flex-direction: column; gap: var(--mythos-space-3);
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--mythos-space-4); }
.card h3 { font-size: 16px; font-weight: var(--mythos-weight-semibold); }
.card p { color: var(--mythos-text-secondary); font-size: 14px; }

/* Stat tile — the value is the hero, the label is quiet. */
.stat .stat-label {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--mythos-text-secondary);
}
.stat .stat-value {
  font-family: var(--mythos-font-display);
  font-weight: var(--mythos-weight-semibold);
  font-size: 30px; line-height: 1.1; letter-spacing: -0.02em;
}
.stat .stat-sub { font-family: var(--mythos-font-mono); font-size: 12px; color: var(--mythos-text-secondary); }

/* ── Badges / pills ────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: var(--mythos-space-2);
  padding: 3px 10px; border-radius: var(--mythos-radius-pill);
  font-size: 11px; font-weight: var(--mythos-weight-medium);
  letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap;
  background: var(--mythos-surface-card); color: var(--mythos-text-secondary);
  border: 1px solid var(--mythos-border-hairline);
}
.badge.ok      { color: var(--mythos-success); background: var(--mythos-success-dim); border-color: transparent; }
.badge.warn    { color: var(--mythos-warning); background: var(--mythos-warning-dim); border-color: transparent; }
.badge.danger  { color: var(--mythos-danger);  background: var(--mythos-danger-dim);  border-color: transparent; }
.badge.info    { color: var(--mythos-info);    background: var(--mythos-info-dim);    border-color: transparent; }
.badge.mock    { color: var(--mythos-text-secondary); }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--mythos-space-2);
  min-height: var(--mythos-size-control-comfortable);
  padding: 0 var(--mythos-space-5);
  border: 1px solid transparent; border-radius: var(--mythos-radius-control);
  font-family: var(--mythos-font-text); font-size: 14px;
  font-weight: var(--mythos-weight-medium);
  cursor: pointer; text-decoration: none;
  transition: background var(--mythos-motion-micro) var(--mythos-ease-move);
}
.btn-primary   { background: var(--mythos-accent); color: var(--mythos-text-on-accent); }
.btn-primary:hover  { background: var(--mythos-accent-hover); }
.btn-secondary { background: var(--mythos-surface-card); color: var(--mythos-text-primary); border-color: var(--mythos-border-control); }
.btn-secondary:hover { border-color: var(--mythos-border-strong); }
.btn-ghost     { background: transparent; color: var(--mythos-text-secondary); }
.btn-ghost:hover { color: var(--mythos-text-primary); background: var(--mythos-surface); }
.btn-danger    { background: var(--mythos-danger-dim); color: var(--mythos-danger); }
.btn:disabled, .btn[aria-disabled="true"] { cursor: not-allowed; opacity: 0.55; }
.btn-sm { min-height: var(--mythos-size-control-compact); padding: 0 var(--mythos-space-4); font-size: 13px; }

/* ── Forms ─────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: var(--mythos-space-2); margin-bottom: var(--mythos-space-5); }
.field label { font-size: 13px; font-weight: var(--mythos-weight-medium); color: var(--mythos-text-secondary); }
.field .hint { font-size: 12px; color: var(--mythos-text-secondary); }
.field .error { font-size: 12px; color: var(--mythos-danger); }

.input, .select, .textarea {
  width: 100%; min-height: var(--mythos-size-control-comfortable);
  padding: 0 var(--mythos-space-4);
  background: var(--mythos-ground-deep);
  border: 1px solid var(--mythos-border-control);
  border-radius: var(--mythos-radius-control);
  color: var(--mythos-text-primary);
  font-family: var(--mythos-font-text); font-size: 14px;
}
.textarea { min-height: 110px; padding: var(--mythos-space-3) var(--mythos-space-4); resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--mythos-accent); }
.input::placeholder, .textarea::placeholder { color: var(--mythos-text-disabled); }
.input:disabled, .select:disabled, .textarea:disabled { cursor: not-allowed; opacity: 0.6; }
.input[aria-invalid="true"] { border-color: var(--mythos-danger); }
.field-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--mythos-space-5); }

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-wrap {
  border: 1px solid var(--mythos-border-hairline);
  border-radius: var(--mythos-radius-card);
  overflow-x: auto;
  background: var(--mythos-surface);
}
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td {
  padding: var(--mythos-space-4) var(--mythos-space-5);
  text-align: left; border-bottom: 1px solid var(--mythos-border-hairline);
}
table.data th {
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--mythos-text-secondary); font-weight: var(--mythos-weight-medium);
  background: var(--mythos-ground-deep); position: sticky; top: 0;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--mythos-surface-card); }
table.data td.num { font-family: var(--mythos-font-mono); text-align: right; }

/* ── Empty state — never fake data, say there is none ──────────────────── */
.empty {
  border: 1px dashed var(--mythos-border-strong);
  border-radius: var(--mythos-radius-card);
  padding: var(--mythos-space-8) var(--mythos-space-6);
  text-align: center; color: var(--mythos-text-secondary);
}
.empty strong { display: block; color: var(--mythos-text-primary); margin-bottom: var(--mythos-space-2); }

.notice {
  border: 1px solid var(--mythos-border-hairline);
  border-left: 3px solid var(--mythos-info);
  border-radius: var(--mythos-radius-control);
  background: var(--mythos-surface);
  padding: var(--mythos-space-4) var(--mythos-space-5);
  font-size: 14px; color: var(--mythos-text-secondary);
  margin-bottom: var(--mythos-space-6);
}
.notice strong { color: var(--mythos-text-primary); }

/* ── Responsive ────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  .app { grid-template-columns: 72px 1fr; }
  .rail a span:not(.glyph) { display: none; }
  .rail-brand .unit, .rail-brand .wordmark { display: none; }
  .rail a { justify-content: center; padding: 0; }
}
@media (max-width: 700px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "topbar" "main" "rail"; }
  .rail {
    flex-direction: row; overflow-x: auto; border-right: 0;
    border-top: 1px solid var(--mythos-border-hairline);
    position: sticky; bottom: 0; padding: var(--mythos-space-3);
  }
  .rail-brand, .rail-foot { display: none; }
  .rail a { min-width: 56px; }
  main { padding: var(--mythos-space-5) var(--mythos-space-4); }
  .topbar { padding: 0 var(--mythos-space-4); }
}
@media (prefers-reduced-motion: reduce) {
  .btn, .rail a, .card { transition: none; }
}
.print-only { display: none; }
@media print {
  .rail, .topbar-tools, .btn { display: none; }
  .app { grid-template-columns: 1fr; grid-template-areas: "topbar" "main"; }
  body { background: none; color: black; }
  .print-only { display: block; }
}

/* ── Phase 6: live application components ──────────────────────────────── */
/* Same rules as above: tokens only, no literal colour, no !important, no
   inline style. Every state below (loading, empty, error, modal, toast, tabs,
   pagination, chart) is a component so views cannot improvise one. */

[hidden] { display: none; }

/* Login */
.login {
  min-height: 100vh; display: grid; place-items: center;
  padding: var(--mythos-space-6); background: var(--mythos-ground);
}
/* .login's own display:grid has the same specificity as [hidden]'s
   display:none and comes later in the cascade, so it always won — the
   hidden attribute was set correctly by app.js on every successful login
   (verified: element.hidden === true) but had no visual effect, leaving
   the login card visibly on screen over the now-rendered dashboard. This
   selector's specificity (0,2,0) beats both, independent of source order. */
.login[hidden] { display: none; }
.login-card { width: min(420px, 100%); gap: var(--mythos-space-4); }
.login-card h1 {
  font-family: var(--mythos-font-display); font-weight: var(--mythos-weight-semibold);
  font-size: 24px; letter-spacing: -0.015em;
}
.login-sub { color: var(--mythos-text-secondary); font-size: 14px; }
.login-card .field { margin-bottom: 0; }
.login-card .error { color: var(--mythos-danger); font-size: 13px; }

/* Top bar extras */
.select-sm { min-height: var(--mythos-size-control-compact); font-size: 13px; width: auto; max-width: 220px; }
.topbar-user { font-size: 13px; color: var(--mythos-text-secondary); }

/* Toolbar under the view header: search, filters, primary action. */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: end; gap: var(--mythos-space-4);
  margin-bottom: var(--mythos-space-5);
}
.toolbar .field { margin-bottom: 0; min-width: 200px; flex: 1 1 200px; }
.toolbar .actions { display: flex; gap: var(--mythos-space-3); margin-left: auto; }
.toolbar-count { font-family: var(--mythos-font-mono); font-size: 12px; color: var(--mythos-text-secondary); }

/* Tabs — one panel visible, role=tablist for assistive tech. */
.tabs { display: flex; gap: var(--mythos-space-2); border-bottom: 1px solid var(--mythos-border-hairline); margin-bottom: var(--mythos-space-6); overflow-x: auto; }
.tabs [role="tab"] {
  appearance: none; background: transparent; border: 0; cursor: pointer;
  padding: var(--mythos-space-3) var(--mythos-space-4); min-height: var(--mythos-size-touch-min);
  color: var(--mythos-text-secondary); font: inherit; font-size: 14px; font-weight: var(--mythos-weight-medium);
  border-bottom: 2px solid transparent; white-space: nowrap;
}
.tabs [role="tab"]:hover { color: var(--mythos-text-primary); }
.tabs [role="tab"][aria-selected="true"] { color: var(--mythos-text-primary); border-bottom-color: var(--mythos-accent); }

/* Pagination */
.pagination {
  display: flex; align-items: center; justify-content: space-between; gap: var(--mythos-space-4);
  padding: var(--mythos-space-4) 0; font-size: 13px; color: var(--mythos-text-secondary);
}
.pagination .pages { display: flex; gap: var(--mythos-space-2); }

/* Loading — skeleton rows, never a spinner over fake numbers. */
@keyframes erp-shimmer { from { opacity: 0.45; } to { opacity: 0.9; } }
.skeleton {
  background: var(--mythos-surface-card); border-radius: var(--mythos-radius-control);
  animation: erp-shimmer var(--mythos-motion-base) var(--mythos-ease-move) infinite alternate;
}
.skeleton.h-row { height: 40px; margin-bottom: var(--mythos-space-3); }
.skeleton.h-stat { height: 36px; width: 60%; }
.stat .stat-value.is-loading { color: var(--mythos-text-disabled); }

/* Error box — the failure is stated, with a retry. */
.errorbox {
  border: 1px solid var(--mythos-danger); border-left-width: 3px;
  border-radius: var(--mythos-radius-control); background: var(--mythos-danger-dim);
  padding: var(--mythos-space-4) var(--mythos-space-5); color: var(--mythos-text-primary);
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--mythos-space-4);
}
.errorbox strong { color: var(--mythos-danger); }
.errorbox code { font-family: var(--mythos-font-mono); font-size: 12px; color: var(--mythos-text-secondary); }

/* Toasts */
.toasts {
  position: fixed; right: var(--mythos-space-5); bottom: var(--mythos-space-5); z-index: 60;
  display: flex; flex-direction: column; gap: var(--mythos-space-3); max-width: 380px;
}
.toast {
  background: var(--mythos-surface-card); color: var(--mythos-text-primary);
  border: 1px solid var(--mythos-border-hairline); border-left: 3px solid var(--mythos-info);
  border-radius: var(--mythos-radius-control); box-shadow: var(--mythos-shadow-floating);
  padding: var(--mythos-space-4) var(--mythos-space-5); font-size: 14px;
  animation: erp-toast-in var(--mythos-motion-enter) var(--mythos-ease-enter);
}
.toast.ok { border-left-color: var(--mythos-success); }
.toast.warn { border-left-color: var(--mythos-warning); }
.toast.danger { border-left-color: var(--mythos-danger); }
@keyframes erp-toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* Modal */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: color-mix(in srgb, var(--mythos-ground-deep) 82%, transparent);
}
.modal {
  width: min(640px, calc(100vw - 2 * var(--mythos-space-5))); max-height: calc(100vh - 2 * var(--mythos-space-6));
  overflow: auto; background: var(--mythos-surface); color: var(--mythos-text-primary);
  border: 1px solid var(--mythos-border-hairline); border-radius: var(--mythos-radius-overlay);
  box-shadow: var(--mythos-shadow-overlay); padding: var(--mythos-space-6);
  display: flex; flex-direction: column; gap: var(--mythos-space-4);
  animation: erp-toast-in var(--mythos-motion-overlay) var(--mythos-ease-enter);
}
.modal.wide { width: min(900px, calc(100vw - 2 * var(--mythos-space-5))); }
.modal h2 { font-family: var(--mythos-font-display); font-weight: var(--mythos-weight-semibold); font-size: 20px; }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--mythos-space-3); margin-top: var(--mythos-space-2); }
.modal .field { margin-bottom: 0; }
.modal .field-row { gap: var(--mythos-space-4); }

/* Detail / key-value */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--mythos-space-2) var(--mythos-space-5); font-size: 14px; }
.kv dt { color: var(--mythos-text-secondary); }
.kv dd { font-family: var(--mythos-font-mono); font-size: 13px; }

/* Invoice lines editor */
table.lines td .input { min-height: var(--mythos-size-control-compact); }
.total-row td { font-weight: var(--mythos-weight-semibold); border-top: 1px solid var(--mythos-border-strong); }

/* Chart — SVG bars driven by the categorical chart tokens. */
.chart { width: 100%; height: 220px; display: block; }
.chart .bar { fill: var(--mythos-chart-1); }
.chart .bar.alt { fill: var(--mythos-chart-2); }
.chart .axis { stroke: var(--mythos-border-strong); stroke-width: 1; }
.chart .label { fill: var(--mythos-text-secondary); font-family: var(--mythos-font-mono); font-size: 10px; }
.chart .value { fill: var(--mythos-text-primary); font-family: var(--mythos-font-mono); font-size: 10px; }
.legend { display: flex; gap: var(--mythos-space-4); font-size: 12px; color: var(--mythos-text-secondary); }
.legend .swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; vertical-align: middle; margin-right: var(--mythos-space-2); }
.legend .swatch.c1 { background: var(--mythos-chart-1); }
.legend .swatch.c2 { background: var(--mythos-chart-2); }

/* Row actions and inline status pills */
table.data td .btn-sm { min-height: 32px; }
.row-actions { display: flex; gap: var(--mythos-space-2); justify-content: flex-end; white-space: nowrap; }
.mono { font-family: var(--mythos-font-mono); font-size: 13px; }
.toggle { display: inline-flex; align-items: center; gap: var(--mythos-space-3); min-height: var(--mythos-size-touch-min); cursor: pointer; }

/* Section spacing helpers (replace the inline margins the mock used). */
.section { margin-top: var(--mythos-space-6); }
.stack { display: flex; flex-direction: column; gap: var(--mythos-space-5); }

@media (prefers-reduced-motion: reduce) {
  .skeleton, .toast, .modal { animation: none; }
}
@media (max-width: 700px) {
  .toasts { left: var(--mythos-space-4); right: var(--mythos-space-4); max-width: none; }
  .kv { grid-template-columns: 1fr; }
  .topbar-user { display: none; }
}

/* ── Phase 10: Agenda calendar grid ──────────────────────────────────────── */
.calendar-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px;
  background: var(--mythos-border-hairline); border: 1px solid var(--mythos-border-hairline);
  border-radius: var(--mythos-radius-card); overflow: hidden;
}
.calendar-dow {
  background: var(--mythos-ground-deep); color: var(--mythos-text-secondary);
  font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; text-align: center;
  padding: var(--mythos-space-2);
}
.calendar-cell {
  background: var(--mythos-surface); min-height: 96px; padding: var(--mythos-space-2);
  display: flex; flex-direction: column; gap: var(--mythos-space-2);
}
.calendar-cell.is-empty { background: var(--mythos-ground-deep); }
.calendar-cell.is-today { box-shadow: inset 0 0 0 2px var(--mythos-accent); }
.calendar-daynum { font-family: var(--mythos-font-mono); font-size: 12px; color: var(--mythos-text-secondary); }
.calendar-items { display: flex; flex-direction: column; gap: 2px; }
.calendar-item {
  display: flex; align-items: center; gap: var(--mythos-space-2); appearance: none; border: 0;
  background: var(--mythos-surface-card); color: var(--mythos-text-primary); border-radius: var(--mythos-radius-control);
  padding: 2px var(--mythos-space-2); font-size: 12px; text-align: left; cursor: pointer; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}
.calendar-item:hover { background: var(--mythos-accent-dim); }
.calendar-item.status-done { opacity: 0.55; text-decoration: line-through; }
.calendar-item.status-cancelled { opacity: 0.4; text-decoration: line-through; }
.calendar-more { font-size: 11px; color: var(--mythos-text-secondary); }
@media (max-width: 700px) {
  .calendar-grid { grid-template-columns: repeat(7, minmax(88px, 1fr)); min-width: 620px; }
  .toolbar { overflow-x: auto; }
}
.calendar-grid { overflow-x: auto; }
