/* Base elements and shared components for every surface. */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-hover); text-decoration: underline; }

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

.mono { font-family: var(--font-mono); }
.num, table, .money { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-secondary); }
.meta { font-size: 12px; color: var(--text-secondary); }

.page-title { font-size: 28px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.2; }
.section-label {
  font-size: 14px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-strong-muted);
}

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-body { padding: var(--space-5); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 36px; padding: 0 var(--space-4);
  border: 1px solid var(--border-input); border-radius: var(--radius);
  background: var(--surface); color: var(--text-strong-muted);
  font: 500 14px/1 var(--font-sans); cursor: pointer;
}
.btn:hover { background: var(--surface-muted); text-decoration: none; color: var(--text); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); color: #fff; }
.btn-block { width: 100%; }
.btn-link {
  background: none; border: 0; padding: 0; color: var(--brand);
  font: inherit; cursor: pointer;
}
.btn-link:hover { color: var(--brand-hover); text-decoration: underline; }

/* Status pills: always colour plus a text label (design.md). */
.pill {
  width: fit-content; justify-self: start;
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 500; line-height: 18px; white-space: nowrap;
}
.pill-neutral   { background: var(--neutral-bg);   color: var(--neutral-text); }
.pill-info      { background: var(--info-bg);      color: var(--info-text); }
.pill-success   { background: var(--success-bg);   color: var(--success-text); }
.pill-attention { background: var(--attention-bg); color: var(--attention-text); }
.pill-critical  { background: var(--critical-bg);  color: var(--critical-text); }

/* Forms */
.field { display: grid; gap: 6px; margin-bottom: var(--space-4); }
.field label { font-size: 13px; font-weight: 500; color: var(--text-strong-muted); }
.input {
  width: 100%; min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--border-input); border-radius: var(--radius);
  background: var(--surface); color: var(--text); font: 14px var(--font-sans);
}
.input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14, 122, 85, 0.15); }
.field-error { font-size: 12px; color: var(--critical-text); }

/* Flash */
.flash {
  padding: 10px 14px; border-radius: var(--radius); font-size: 13px;
  margin-bottom: var(--space-4);
}
.flash-notice { background: var(--success-bg); color: var(--success-text); }
.flash-alert  { background: var(--critical-bg); color: var(--critical-text); }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  background: var(--surface-muted); color: var(--text-secondary);
  font-size: 12px; font-weight: 500; text-align: left;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--divider); vertical-align: top; }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }

/* Brand mark */
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 600; font-size: 15px; }
.brand:hover { text-decoration: none; color: var(--text); }
.brand-mark { width: 28px; height: 28px; flex: none; }

/* Utilities */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.nowrap { white-space: nowrap; }
.empty { padding: var(--space-6) var(--space-5); color: var(--text-secondary); text-align: center; font-size: 13px; }

.btn-sm { min-height: 30px; padding: 0 var(--space-3); font-size: 13px; }
.input-sm { min-height: 32px; padding: 5px 10px; font-size: 13px; }

.table-card { overflow-x: auto; }
.table-card .table th:first-child, .table-card .table td:first-child { padding-left: var(--space-5); }
.table-card .table th:last-child, .table-card .table td:last-child { padding-right: var(--space-5); }
.table .row-detail { display: block; font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.input-affix {
  display: inline-flex; align-items: stretch;
  border: 1px solid var(--border-input); border-radius: var(--radius); background: var(--surface);
}
.input-affix:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14, 122, 85, 0.15); }
.input-affix .input { border: 0; box-shadow: none; min-width: 0; }
.input-affix .affix { display: flex; align-items: center; padding: 0 10px; color: var(--text-secondary); font-size: 13px; }

.inline-form { display: grid; gap: var(--space-2); justify-items: end; }
.inline-fields { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: flex-end; }
.inline-fields .input-affix .input { width: 110px; text-align: right; }
.inline-actions { display: flex; gap: var(--space-2); }

.setting-value { width: 1%; white-space: nowrap; }
.setting-value .value { font-weight: 600; margin-right: var(--space-3); }
.setting-meta { width: 180px; }
.setting-value.setting-text { width: 320px; white-space: normal; text-align: right; }
.setting-text .value { display: block; margin: 0 0 var(--space-2); overflow-wrap: anywhere; }
.inline-fields .input.input-text { width: 100%; min-width: 220px; text-align: left; }

.input[aria-invalid="true"], .input-affix:has(.input[aria-invalid="true"]) { border-color: var(--critical-text); }

/* Tabs (filters that are mutually exclusive) */
.tabs { display: flex; gap: var(--space-1); margin-bottom: var(--space-3); flex-wrap: wrap; }
.tab {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-strong-muted); font-size: 13px; font-weight: 500;
}
.tab:hover { text-decoration: none; color: var(--text); background: var(--surface-muted); }
.tab[aria-current="page"] { background: var(--text); border-color: var(--text); color: #fff; }
.tab-count { font-variant-numeric: tabular-nums; opacity: 0.7; }

/* Forms on their own page */
.form-card { max-width: 640px; }
.form-grid { display: grid; gap: var(--space-1); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
fieldset.field { border: 0; padding: 0; margin: 0 0 var(--space-4); min-width: 0; }
fieldset.field legend { font-size: 13px; font-weight: 500; color: var(--text-strong-muted); margin-bottom: 6px; padding: 0; }
.form-actions {
  display: flex; justify-content: flex-end; gap: var(--space-2);
  padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); background: var(--surface-muted);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}
.form-errors ul { margin: 6px 0 0; padding-left: 18px; }
.back-link { display: inline-block; font-size: 13px; margin-bottom: 4px; }
.back-link::before { content: "‹ "; }
.checkbox { display: flex; gap: var(--space-2); align-items: flex-start; font-size: 14px; }
.checkbox input { margin-top: 3px; accent-color: var(--brand); }
select.input { appearance: auto; }
[hidden] { display: none !important; }

.segmented { display: inline-flex; border: 1px solid var(--border-input); border-radius: var(--radius); overflow: hidden; width: fit-content; }
.segment { position: relative; }
.segment input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.segment span { display: block; padding: 7px 14px; font-size: 13px; font-weight: 500; color: var(--text-strong-muted); }
.segment + .segment span { border-left: 1px solid var(--border-input); }
.segment input:checked + span { background: var(--brand); color: #fff; }
.segment input:focus-visible + span { outline: 2px solid var(--brand); outline-offset: -2px; }
.segment input:disabled { cursor: not-allowed; }
.segment input:disabled + span { color: var(--text-secondary); background: var(--surface-muted); text-decoration: line-through; }
fieldset.field .input-affix { margin-top: var(--space-2); width: fit-content; }
.form-grid .input-affix .input { width: 140px; }

@media (max-width: 600px) { .field-row { grid-template-columns: 1fr; } }
.form-grid .input-affix { width: fit-content; }
.row-actions { display: flex; gap: var(--space-2); justify-content: flex-end; }
form.inline { display: inline; }
.mpin-input { width: 160px; letter-spacing: 0.3em; font-family: var(--font-mono); }
.filter-bar { display: flex; gap: var(--space-2); align-items: center; margin-bottom: var(--space-3); flex-wrap: wrap; }
.filter-bar .input { width: auto; min-width: 220px; }
.check-col { width: 40px; }
.check-col input { accent-color: var(--brand); width: 16px; height: 16px; }
.sticky-actions {
  position: sticky; bottom: 0; display: flex; justify-content: flex-end;
  padding: var(--space-3) 0; background: linear-gradient(to top, var(--bg) 70%, transparent);
}
.field-row.three { grid-template-columns: repeat(3, 1fr); }
.field-note { margin: calc(-1 * var(--space-3)) 0 var(--space-4); }
code { font-family: var(--font-mono); font-size: 12px; background: var(--surface-muted); border: 1px solid var(--border); border-radius: 4px; padding: 1px 4px; }

/* Receive stock */
.card-title { margin-bottom: var(--space-3); }
.card-title-row { display: flex; justify-content: space-between; align-items: baseline; }
.invoice-form .field-row.three .field, .invoice-form .field-row .field { margin-bottom: var(--space-3); }
.line-table td { vertical-align: top; }
.line-table select.input { min-width: 260px; }
.qty-input { width: 90px; text-align: right; }
.line-table .input-affix .input { width: 110px; text-align: right; }
.remove-line { color: var(--text-secondary); font-size: 13px; padding-top: 10px; }
.form-actions.bare { background: none; border: 0; padding: 0; }
.invoice-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: var(--space-4); align-items: start; }
.invoice-side { display: grid; gap: var(--space-4); }
.invoice-photo { width: 100%; border-radius: var(--radius); border: 1px solid var(--border); }
.table tfoot td { background: var(--surface-muted); border-top: 1px solid var(--border); border-bottom: 0; padding-top: 8px; padding-bottom: 8px; }
.table .total-row td { font-weight: 600; }
.post-box { display: grid; gap: var(--space-3); }
.irreversible { color: var(--attention-text); }
.btn-danger { color: var(--critical-text); border-color: #F9C5C0; }
.btn-danger:hover { background: var(--critical-bg); color: var(--critical-text); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
@media (max-width: 1100px) { .invoice-layout { grid-template-columns: 1fr; } }
.row-muted td { color: var(--text-secondary); }
.negative { color: var(--critical-text); }
.positive { color: var(--success-text); }
.filter-check { align-items: center; font-size: 13px; }
.invoice-photo { max-height: 360px; object-fit: contain; background: var(--surface-muted); }
.invoice-form .input-affix { width: fit-content; } .invoice-form .field > .input-affix .input { width: 140px; }
.form-card.wide { max-width: 860px; }
.version-card summary { display: flex; gap: var(--space-3); align-items: center; cursor: pointer; list-style: none; }
.version-card summary::-webkit-details-marker { display: none; }
.terms-body { border-top: 1px solid var(--divider); color: var(--text-strong-muted); max-width: 72ch; }
.terms-body p { margin-bottom: var(--space-3); }
.section-gap { margin-top: var(--space-4); }
