/* Reggie components. Reads tokens.css; load tokens first. */

/* Base and browser surfaces */
*, *::before, *::after { box-sizing: border-box; }
html { color-scheme: light; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  color: var(--ink);
  background: var(--steel-ground);
  font-variant-numeric: tabular-nums;
  caret-color: var(--expo-blue);
  scrollbar-color: var(--steel-header-lip) transparent;
}
::selection { background: var(--selection); color: var(--ink); }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; border-radius: var(--radius-control); }
h1, h2, h3, h4 { margin: 0; line-height: var(--leading-tight); text-wrap: balance; font-weight: var(--weight-bold); }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3 { font-size: var(--text-lg); }
p { margin: 0; text-wrap: pretty; }
a { color: var(--expo-blue); text-decoration-thickness: 1px; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }
code, kbd, .data { font-family: var(--font-data); font-size: 0.95em; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* Icons */
.icon { width: 20px; height: 20px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 36px; padding: 0 var(--space-4);
  font: var(--weight-semibold) var(--text-md)/1 var(--font-ui);
  color: var(--ink); background: var(--paper);
  border: 1px solid var(--field-border); border-radius: var(--radius-control);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color var(--duration-quick) var(--ease-out), border-color var(--duration-quick) var(--ease-out), box-shadow var(--duration-quick) var(--ease-out);
}
.btn:hover { background: var(--paper-sunk); }
.btn:active { box-shadow: inset 0 1px 2px var(--ink-press); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { color: var(--paper); background: var(--ink-soft); border-color: var(--ink-soft); }
.btn-primary:hover { background: var(--ink); }
.btn-danger { color: var(--printer-red); border-color: currentColor; background: var(--paper); }
.btn-danger:hover { background: var(--printer-red-wash); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--ink-overlay); }
.btn-sm { min-height: 30px; padding: 0 var(--space-3); font-size: var(--text-sm); }
.btn-group { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.btn-group .btn-danger { margin-inline-start: auto; }

/* Form fields */
.field { display: grid; gap: var(--space-1); align-content: start; margin-block-end: var(--space-4); }
.field-label { font-size: var(--text-sm); font-weight: var(--weight-semibold); }
.field-hint { font-size: var(--text-sm); color: var(--text-muted); }
.field-error { font-size: var(--text-sm); color: var(--printer-red); font-weight: var(--weight-semibold); }
.input, .select, .textarea {
  width: 100%; min-height: 36px; padding: var(--space-2) var(--space-3);
  font: var(--text-md)/var(--leading-normal) var(--font-ui); color: var(--ink);
  background: var(--field-ground); border: 1px solid var(--field-border); border-radius: var(--radius-control);
  transition: border-color var(--duration-quick) var(--ease-out), box-shadow var(--duration-quick) var(--ease-out);
}
.textarea { min-height: 96px; resize: vertical; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--ink); }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible {
  outline: none; border-color: var(--focus-ring); box-shadow: 0 0 0 3px var(--expo-blue-wash);
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--printer-red); }
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }

/* Password show/hide toggle */
.password-field { position: relative; display: grid; }
.password-field .input { padding-inline-end: 2.75rem; }
.password-toggle {
  position: absolute; inset-block-start: 50%; inset-inline-end: 4px; transform: translateY(-50%);
  display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0;
  color: var(--text-muted); background: transparent; border: 0; border-radius: var(--radius-control); cursor: pointer;
  transition: color var(--duration-quick) var(--ease-smooth-out), background-color var(--duration-quick) var(--ease-smooth-out);
}
.password-toggle:hover { color: var(--ink); background: var(--paper-sunk); }
.password-toggle:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.password-toggle .icon { width: 18px; height: 18px; }

/* Status stamps: outlined, one colour per state */
.stamp {
  display: inline-flex; align-items: center; min-height: 22px; padding: 0 var(--space-2);
  font: var(--weight-bold) var(--text-xs)/1 var(--font-ui); letter-spacing: var(--tracking-stamp); text-transform: uppercase;
  color: var(--status-open); border: 1.5px solid currentColor; border-radius: var(--radius-paper);
  background: transparent; white-space: nowrap;
}
.stamp-new { color: var(--status-new); }
.stamp-open { color: var(--status-open); }
.stamp-pending { color: var(--status-pending); }
.stamp-resolved { color: var(--status-resolved); }
.stamp-closed { color: var(--status-closed); }
.stamp.is-fresh { animation: stamp-press var(--duration-quick) var(--ease-smooth-out) both; }
@keyframes stamp-press { from { transform: scale(1.12); opacity: 0.4; } to { transform: scale(1); opacity: 1; } }

/* Priority mark */
.priority { font: var(--weight-bold) var(--text-xs)/1 var(--font-ui); letter-spacing: var(--tracking-stamp); text-transform: uppercase; color: var(--text-muted); }
.priority-high { color: var(--priority-high); }

/* Receipt stub: the signature container */
.stub {
  position: relative; display: grid; gap: var(--space-2);
  padding: var(--space-4) var(--space-4) var(--space-3);
  background: var(--paper); color: var(--ink);
  border-radius: 0 0 var(--radius-paper) var(--radius-paper);
  box-shadow: var(--shadow-paper);
  margin-block-start: var(--perforation);
}
.stub::before {
  content: ""; position: absolute; inset-inline: 0; top: calc(var(--perforation) * -1); height: var(--perforation);
  background: radial-gradient(circle at 6px var(--perforation), transparent 3.5px, var(--paper) 4px) 0 0 / 12px var(--perforation) repeat-x;
}
a.stub { text-decoration: none; transition: box-shadow var(--duration-fast) var(--ease-smooth-out), transform var(--duration-fast) var(--ease-smooth-out); }
a.stub:hover { box-shadow: var(--shadow-lift); transform: translateY(-1px); }
.stub-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); }
.stub-number { font: var(--weight-bold) var(--text-sm)/1 var(--font-data); }
.stub-subject { font-size: var(--text-lg); font-weight: var(--weight-bold); line-height: var(--leading-tight); }
.stub-meta { display: flex; justify-content: space-between; gap: var(--space-2); font-size: var(--text-sm); color: var(--text-muted); }
.stub-time {
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-1) var(--space-3);
  padding-block-start: var(--space-2); border-top: 1px dashed var(--rule-dashed);
  font: var(--weight-bold) var(--text-sm)/1.2 var(--font-data);
}
.stub-time > span { white-space: nowrap; }
.stub-time .is-late { color: var(--late); }
.stub-lg .stub-number { font-size: var(--text-md); }
.stub-lg .stub-subject { font-size: var(--text-3xl); }

/* Data table */
.table-wrap { overflow-x: auto; background: var(--paper); border-radius: var(--radius-paper); box-shadow: var(--shadow-paper); }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-md); }
.table th {
  position: sticky; top: 0; z-index: 1; text-align: start; white-space: nowrap;
  padding: var(--space-2) var(--space-3); background: var(--paper-sunk);
  font: var(--weight-bold) var(--text-xs)/1.2 var(--font-ui); letter-spacing: var(--tracking-stamp); text-transform: uppercase; color: var(--text-muted);
  border-bottom: 1px solid var(--rule);
}
.table td { height: var(--row-height); padding: var(--space-1) var(--space-3); border-bottom: 1px solid var(--rule); vertical-align: middle; }
.table tbody tr:hover td { background: var(--paper-sunk); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .data { font-weight: var(--weight-semibold); }

/* View chips */
.chips { display: flex; flex-wrap: wrap; gap: var(--space-2); }
.chip {
  display: inline-flex; align-items: center; gap: var(--space-1); min-height: 30px; padding: 0 var(--space-3);
  font-size: var(--text-sm); font-weight: var(--weight-semibold); color: var(--ink); text-decoration: none;
  background: var(--paper); border: 1px solid var(--field-border); border-radius: var(--radius-control);
}
.chip:hover { background: var(--paper-sunk); }
.chip[aria-current="page"], .chip.is-active { color: var(--paper); background: var(--ink-soft); border-color: var(--ink-soft); }
.chip-count { font-family: var(--font-data); font-weight: var(--weight-regular); }

/* Panels and sections */
.panel { background: var(--paper); border-radius: var(--radius-paper); box-shadow: var(--shadow-paper); padding: var(--space-5); }
.panel + .panel:not(:where(.desk-tiles, .record-list, .catalog-grid, .catalog-list) > *) { margin-block-start: var(--space-4); }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-block: var(--space-6) var(--space-3); }
.panel > .section-head:first-child { margin-block-start: 0; }
.muted { color: var(--text-muted); font-size: var(--text-sm); }

/* Alerts */
.alert { display: flex; gap: var(--space-2); align-items: flex-start; padding: var(--space-3) var(--space-4); border-radius: var(--radius-control); font-size: var(--text-md); }
.alert-error { background: var(--printer-red-wash); color: var(--printer-red); font-weight: var(--weight-semibold); }
.alert-success { background: var(--tile-green-wash); color: var(--tile-green); font-weight: var(--weight-semibold); }
.alert-info { background: var(--expo-blue-wash); color: var(--expo-blue); }

/* Empty state */
.empty { display: grid; justify-items: start; gap: var(--space-2); padding: var(--space-8) var(--space-6); background: var(--paper); border-radius: var(--radius-paper); box-shadow: var(--shadow-paper); }
.empty-title { font-size: var(--text-lg); font-weight: var(--weight-bold); }

/* Timeline (activity, status history, conversation) */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; gap: var(--space-1); padding: var(--space-3) 0; border-bottom: 1px solid var(--rule); }
.timeline li:last-child { border-bottom: 0; }
.timeline-meta { font-size: var(--text-sm); color: var(--text-muted); }

/* Touch: 40px controls on narrow screens */
@media (max-width: 720px) {
  .btn, .chip, .input, .select { min-height: 40px; }
  .btn-sm { min-height: 36px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; scroll-behavior: auto !important; }
  a.stub:hover { transform: none; }
}
