/* Components — flat surfaces, 1px rules, no heavy shadows.
   Office density: 32px rows. Tabular numerals everywhere numbers align. */

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

body {
  margin: 0;
  background: var(--ground);
  color: var(--on-surface);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 20px;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, nav, th, .label { font-family: var(--font-display); }
h1 { font-size: 32px; line-height: 40px; font-weight: 700; margin: 0; }
h2 { font-size: 20px; line-height: 28px; font-weight: 600; margin: 0; }
h3 { font-size: 16px; line-height: 24px; font-weight: 600; margin: 0; }
p  { margin: 0; }
a  { color: var(--primary-container); }

.label {
  font-size: 11px; line-height: 16px; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase;
  color: var(--on-surface-variant);
}

/* Batch codes and system IDs — mono, in a tinted container. */
.code {
  font-family: var(--font-mono);
  font-size: 13px; line-height: 16px; font-weight: 500; letter-spacing: .02em;
  background: var(--surface-highest);
  color: var(--on-surface);
  padding: 2px 6px;
  border-radius: var(--radius);
  white-space: nowrap;
}

/* ---------- shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }

.sidebar {
  background: var(--nav-bg);
  color: var(--nav-fg);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 20px var(--gutter); border-bottom: 1px solid var(--nav-hairline); }
.brand .name { font-family: var(--font-display); font-size: 18px; font-weight: 700; line-height: 22px; }
.brand .sub  { font-size: 11px; color: var(--nav-fg-dim); margin-top: 2px; }

.nav { padding: 12px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav .group { padding: 14px 8px 6px; font-size: 10px; letter-spacing: .08em; text-transform: uppercase;
              color: var(--nav-fg-dim); font-family: var(--font-display); font-weight: 700; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius);
  color: var(--nav-fg); text-decoration: none;
  font-size: 14px; font-family: var(--font-display); font-weight: 600;
}
.nav a:hover { background: rgba(255,255,255,.08); }
.nav a[aria-current="page"] { background: var(--nav-active); }
.nav a .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--nav-fg-dim); flex: none; }
.nav a[aria-current="page"] .dot { background: var(--secondary-container); }

.main { display: flex; flex-direction: column; min-width: 0; }

/* Top bar carries the week — rule 9: the week is always on screen. */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: var(--gutter);
  padding: 0 var(--margin); height: 56px;
  background: var(--surface-lowest);
  border-bottom: 1px solid var(--outline-variant);
}
.topbar .spacer { flex: 1; }

.week-switch {
  display: flex; align-items: center; gap: 8px;
  border: 1px solid var(--outline-variant); border-radius: var(--radius);
  padding: 3px 4px 3px 10px; background: var(--surface-lowest);
}
.week-switch .lbl { font-family: var(--font-display); font-size: 10px; font-weight: 700;
                    letter-spacing: .08em; text-transform: uppercase; color: var(--on-surface-variant); }
.week-switch .val {
  font-family: var(--font-mono); font-size: 13px; font-weight: 500;
  background: var(--secondary-container); color: var(--on-secondary-container);
  padding: 3px 8px; border-radius: var(--radius);
}
.week-switch select {
  font-family: var(--font-mono); font-size: 13px;
  border: none; background: transparent; color: var(--on-surface); cursor: pointer;
}

.content { padding: var(--margin); display: flex; flex-direction: column; gap: var(--gutter); }
.page-head { display: flex; align-items: flex-start; gap: var(--gutter); }
.page-head .spacer { flex: 1; }
.page-head .sub { color: var(--on-surface-variant); margin-top: 4px; }

/* ---------- pills ---------- */
/* Status carries shape + text, never colour alone. */
.pill {
  display: inline-flex; align-items: center; gap: 5px;
  border-radius: 9999px; padding: 2px 10px;
  font-family: var(--font-display); font-size: 11px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill-ok   { background: var(--ok-bg);       color: var(--ok); }
.pill-warn { background: var(--warn-bg);     color: var(--warn); }
.pill-crit { background: var(--critical-bg); color: var(--critical); }
.pill-neut { background: var(--surface-highest); color: var(--on-surface-variant); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 14px; border-radius: var(--radius);
  font-family: var(--font-display); font-size: 13px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; text-decoration: none;
  background: var(--primary-container); color: #fff;
}
.btn:hover { background: var(--primary); }
.btn-secondary { background: transparent; color: var(--primary-container); border-color: var(--primary-container); }
.btn-secondary:hover { background: var(--primary-soft); }
.btn-ghost { background: transparent; color: var(--on-surface-variant); border-color: var(--outline-variant); }
.btn-ghost:hover { border-color: var(--outline); }
.btn-danger { background: transparent; color: var(--critical); border-color: var(--critical); }

/* ---------- cards & filters ---------- */
.card {
  background: var(--surface-lowest);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-lg);
}
.card-pad { padding: var(--gutter); }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.input, select.input {
  height: 32px; padding: 0 10px;
  border: 1px solid var(--outline-variant); border-radius: var(--radius);
  background: var(--surface-lowest); color: var(--on-surface);
  font-family: var(--font-body); font-size: 14px; min-width: 0;
}
.input:focus-visible, .btn:focus-visible, .nav a:focus-visible, select:focus-visible {
  outline: 2px solid var(--secondary); outline-offset: 1px;
}
.input.search { width: 320px; }

/* ---------- tables ---------- */
/* Sticky headers are mandatory. Row height 32px in office mode. */
.tablewrap { overflow-x: auto; border-radius: var(--radius-lg); border: 1px solid var(--outline-variant); background: var(--surface-lowest); }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.data thead th {
  position: sticky; top: 0; z-index: 5;
  background: var(--surface-high); color: var(--on-surface-variant);
  font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase;
  text-align: left; padding: 0 12px; height: var(--row-office); white-space: nowrap;
  border-bottom: 1px solid var(--outline-variant);
}
table.data tbody td {
  padding: 0 12px; height: var(--row-office);
  border-bottom: 1px solid var(--surface-highest);
  vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--surface-low); }
/* Every column of digits aligns. */
table.data .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}
table.data .sticky-col {
  position: sticky; left: 0; z-index: 4;
  background: var(--surface-lowest);
  border-right: 1px solid var(--outline-variant);
}
table.data tbody tr:hover .sticky-col { background: var(--surface-low); }
table.data thead th.sticky-col { z-index: 6; background: var(--surface-high); }

.muted { color: var(--on-surface-variant); }
/* Blank is not zero — rule 2. A dash means "not applicable", and looks nothing like 0. */
.na { color: var(--outline); }

.unit { font-size: 11px; color: var(--on-surface-variant); margin-left: 4px; }

/* ---------- empty state ---------- */
.empty { padding: 48px var(--margin); text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.empty h3 { color: var(--on-surface); }
.empty p { color: var(--on-surface-variant); max-width: 46ch; }

/* ---------- key figures ---------- */
.figs { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 1px;
        background: var(--outline-variant); border: 1px solid var(--outline-variant); border-radius: var(--radius-lg); overflow: hidden; }
.fig { background: var(--surface-lowest); padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; }
.fig b { font-family: var(--font-display); font-size: 26px; font-weight: 700; line-height: 30px;
         color: var(--primary-container); font-variant-numeric: tabular-nums; }
.fig span { font-size: 11px; letter-spacing: .05em; text-transform: uppercase; color: var(--on-surface-variant);
            font-family: var(--font-display); font-weight: 700; }

/* ---------- lifecycle ---------- */
.flow { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.flow .step {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: .04em;
  padding: 4px 9px; border-radius: var(--radius);
  background: var(--surface-highest); color: var(--on-surface-variant);
}
.flow .step.done { background: var(--ok-bg); color: var(--ok); }
.flow .step.now  { background: var(--secondary-container); color: var(--on-secondary-container); font-weight: 700; }
.flow .arrow { color: var(--outline-variant); font-family: var(--font-mono); }

.dl { display: grid; grid-template-columns: 160px 1fr; gap: 8px 16px; font-size: 14px; }
.dl dt { color: var(--on-surface-variant); font-size: 12px; padding-top: 2px; }
.dl dd { margin: 0; }

.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { font-size: 12px; background: var(--surface-highest); color: var(--on-surface-variant);
       padding: 2px 8px; border-radius: var(--radius); }

.htmx-request .spin { visibility: visible; }
.spin { visibility: hidden; font-size: 12px; color: var(--on-surface-variant); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .input.search { width: 100%; }
}

/* ---------- auth pages ---------- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center;
  padding: var(--margin); background: var(--ground);
}
.auth-card {
  width: 100%; max-width: 380px;
  display: flex; flex-direction: column; gap: 20px;
}
.auth-brand { display: flex; flex-direction: column; gap: 2px; }
.auth-brand .name { font-family: var(--font-display); font-size: 24px; font-weight: 700; line-height: 28px; }
.auth-brand .sub { font-size: 12px; color: var(--on-surface-variant); }
.auth-panel {
  background: var(--surface-lowest); border: 1px solid var(--outline-variant);
  border-radius: var(--radius-lg); padding: 20px;
  display: flex; flex-direction: column; gap: 16px;
}
.auth-panel h2 { font-size: 18px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; font-weight: 600; color: var(--on-surface-variant); }
.field .input { width: 100%; }
.field .help { font-size: 11px; color: var(--on-surface-variant); }
.field .err { font-size: 12px; color: var(--critical); }
.field.has-error .input { border-color: var(--critical); }
.btn-block { width: 100%; justify-content: center; height: 38px; }
.auth-foot { font-size: 12px; color: var(--on-surface-variant); text-align: center; }

/* Inline alerts — never colour alone, always a word. */
.alert {
  display: flex; gap: 8px; align-items: flex-start;
  padding: 10px 12px; border-radius: var(--radius); font-size: 13px;
  border: 1px solid transparent;
}
.alert b { font-family: var(--font-display); }
.alert-error { background: var(--critical-bg); color: var(--critical); border-color: var(--critical); }
.alert-warn  { background: var(--warn-bg);     color: var(--warn); }
.alert-ok    { background: var(--ok-bg);       color: var(--ok); }
.alert-info  { background: var(--surface-high); color: var(--on-surface-variant); }

/* ---------- user menu ---------- */
.usermenu { display: flex; align-items: center; gap: 10px; }
.usermenu .who { display: flex; flex-direction: column; align-items: flex-end; line-height: 14px; }
.usermenu .who .nm { font-size: 12px; font-weight: 600; }
.usermenu .who .rl { font-size: 10px; letter-spacing: .06em; text-transform: uppercase; color: var(--on-surface-variant); font-family: var(--font-display); font-weight: 700; }
.usermenu .avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--primary-container); color: #fff;
  display: grid; place-items: center;
  font-family: var(--font-display); font-size: 11px; font-weight: 700;
}

/* ---------- dashboards ---------- */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; align-items: start; }
.dash-wide { grid-column: 1 / -1; }

.panel { background: var(--surface-lowest); border: 1px solid var(--outline-variant);
         border-radius: var(--radius-lg); padding: var(--gutter);
         display: flex; flex-direction: column; gap: 10px; }
.panel > header { display: flex; align-items: baseline; gap: 8px; }
.panel > header .spacer { flex: 1; }

/* Cards whose data does not exist yet say so, rather than showing a fake number. */
.panel-pending { background: transparent; border-style: dashed; }
.pending-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.pending-list li { display: flex; align-items: center; gap: 8px; padding: 7px 0;
                   border-bottom: 1px solid var(--surface-highest); font-size: 13px; color: var(--on-surface-variant); }
.pending-list li:last-child { border-bottom: none; }
.pending-list .spacer { flex: 1; }
.ms-tag { font-family: var(--font-mono); font-size: 10px; font-weight: 500;
          background: var(--surface-highest); color: var(--on-surface-variant);
          padding: 2px 6px; border-radius: var(--radius); }

.greet { display: flex; flex-direction: column; gap: 2px; }
.greet .date { font-size: 12px; color: var(--on-surface-variant); }

.rowlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.rowlist li { display: flex; align-items: center; gap: 10px; padding: 7px 0;
              border-bottom: 1px solid var(--surface-highest); font-size: 13px; }
.rowlist li:last-child { border-bottom: none; }
.rowlist .spacer { flex: 1; }

/* ---------- tabs (queue pattern) ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--outline-variant); }
.tabs a {
  padding: 8px 14px; text-decoration: none; font-size: 13px;
  font-family: var(--font-display); font-weight: 600;
  color: var(--on-surface-variant); border-bottom: 2px solid transparent;
  display: inline-flex; align-items: center; gap: 6px;
}
.tabs a:hover { color: var(--on-surface); }
.tabs a[aria-current="page"] { color: var(--primary-container); border-bottom-color: var(--primary-container); }
.tabs .count {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--surface-highest); color: var(--on-surface-variant);
  padding: 1px 6px; border-radius: 9999px;
}
.tabs a[aria-current="page"] .count { background: var(--primary-soft); color: var(--primary-container); }

/* Row severity — a stripe plus a tint, so it reads without colour vision. */
table.data tbody tr.row-crit { background: var(--critical-bg); box-shadow: inset 3px 0 0 var(--critical); }
table.data tbody tr.row-warn { background: var(--warn-bg);     box-shadow: inset 3px 0 0 var(--warn); }
/* Neutral stripe: not a failure, but not being counted either — an unscheduled
   or paused row must not read as "fine". */
table.data tbody tr.row-neut { background: var(--surface-low); box-shadow: inset 3px 0 0 var(--outline-variant); }
table.data tbody tr.row-crit:hover, table.data tbody tr.row-warn:hover,
table.data tbody tr.row-neut:hover { filter: brightness(.98); }
table.data td.action { text-align: right; white-space: nowrap; }
table.data td.action .btn { height: 24px; padding: 0 10px; font-size: 12px; }

/* Segmented control */
.segmented { display: inline-flex; border: 1px solid var(--outline-variant); border-radius: var(--radius); overflow: hidden; }
.segmented a {
  padding: 5px 12px; font-size: 12px; text-decoration: none;
  font-family: var(--font-display); font-weight: 600; color: var(--on-surface-variant);
  background: var(--surface-lowest);
}
.segmented a + a { border-left: 1px solid var(--outline-variant); }
.segmented a[aria-current="page"] { background: var(--primary-container); color: #fff; }

.subnav { display: flex; flex-wrap: wrap; gap: 6px; }
.subnav a { font-size: 12px; text-decoration: none; color: var(--on-surface-variant);
            border: 1px solid var(--outline-variant); border-radius: var(--radius); padding: 3px 10px; }
.subnav a:hover { border-color: var(--outline); color: var(--on-surface); }
.subnav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary-container); border-color: var(--primary-container); }

/* ---------- grid totals ----------
   Totals live in a tfoot so they never scroll away into the data, and there is
   one row per unit of measure — rule 1 means a kg row and a pcs row, never a
   single combined row. */
table.data tfoot td, table.data tfoot th {
  padding: 0 12px; height: var(--row-office);
  background: var(--surface-high); color: var(--on-surface);
  font-family: var(--font-display); font-weight: 700; font-size: 12px;
  text-align: left; white-space: nowrap;
  border-top: 1px solid var(--outline-variant);
}
table.data tfoot tr:first-child td, table.data tfoot tr:first-child th {
  border-top: 2px solid var(--outline);
}
table.data tfoot .sticky-col { background: var(--surface-high); }

/* ---------- modal ----------
   Add and edit happen over the current page. The backdrop and the close
   control both clear #modal, so there is no state to get stuck in. */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(13, 31, 28, .45);
}
.modal {
  position: fixed; z-index: 61;
  top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 64px);
  display: flex; flex-direction: column;
  background: var(--surface-lowest);
  border: 1px solid var(--outline-variant);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
}
.modal form { display: flex; flex-direction: column; min-height: 0; }
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px var(--gutter);
  border-bottom: 1px solid var(--outline-variant);
}
.modal-head h2 { flex: 1; font-size: 18px; line-height: 24px; }
.modal-x {
  border: none; background: transparent; cursor: pointer;
  font-size: 22px; line-height: 1; color: var(--on-surface-variant);
  padding: 0 4px; border-radius: var(--radius);
}
.modal-x:hover { color: var(--on-surface); }
.modal-body { padding: var(--gutter); overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-help { font-size: 12px; color: var(--on-surface-variant); }
.modal-fields { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.modal-fields .field-check { grid-column: 1 / -1; }
.modal-fields .field-check label { display: flex; align-items: center; gap: 8px; font-weight: 400; color: var(--on-surface); }
.modal-fields textarea.input { min-height: 64px; padding: 8px 10px; height: auto; resize: vertical; }
.modal-fields select.input[multiple] { height: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px var(--gutter);
  border-top: 1px solid var(--outline-variant);
  background: var(--surface-low);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
