/* Base system: every value reads a theme token (themes.css). Layout lives in
   shell.css, screens in documents.css and pages.css. */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: var(--size-base)/var(--leading) var(--font-ui);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "ss01", "cv11";
}
::selection { background: var(--selection); color: var(--ink); }
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
img { max-width: 100%; }
[hidden] { display: none !important; }

a { color: var(--accent); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { color: var(--accent-hover); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

h1, h2, h3 { margin: 0; letter-spacing: var(--head-tracking); text-wrap: balance; }
h1 { font-size: 1.7rem; line-height: 1.2; font-weight: 600; margin-bottom: 1rem; }
h2 { font-size: 1.07rem; line-height: 1.35; font-weight: 600; margin: 2rem 0 0.75rem; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0 0 0.75rem; }
small { color: var(--ink-muted); font-size: 0.86rem; }

.mono, code { font-family: var(--font-mono); font-size: 0.92em; font-variant-numeric: tabular-nums; }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-muted); }
.sr-only {
  position: absolute !important; width: 1px !important; height: 1px !important; min-height: 0 !important;
  padding: 0 !important; margin: -1px !important; border: 0 !important; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
svg.i {
  width: 16px; height: 16px; flex: none;
  stroke: currentColor; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}
.kbd {
  font: 11px/1 var(--font-mono); padding: 3px 5px; color: var(--ink-2);
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--surface);
}

/* --- Buttons. Bare <button> is the neutral button so older screens fit. ---- */
button, .btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 0 14px; margin: 0;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink);
  font: 500 0.93rem/1.2 var(--font-ui); white-space: nowrap; text-decoration: none;
  box-shadow: var(--shadow-sm); cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
button:hover, .btn:hover { background: var(--surface-alt); border-color: var(--ink-faint); color: var(--ink); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; transform: none; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover, .btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
button.primary:disabled { opacity: .45; }
button.danger, .btn.danger { color: var(--err); }
button.danger:hover { background: var(--err-bg); border-color: var(--err); color: var(--err); }
button.ghost, .btn.ghost { border-color: transparent; background: transparent; box-shadow: none; color: var(--ink-2); }
button.ghost:hover, .btn.ghost:hover { background: var(--surface-muted); border-color: transparent; }
button.small, .btn.sm, button.sm { min-height: 30px; padding: 0 10px; font-size: 0.86rem; }
.btn.lg, button.lg { min-height: 48px; padding: 0 20px; font-size: 1.07rem; }
.btn.block, button.block { width: 100%; }
.icon-btn {
  width: 32px; min-height: 32px; padding: 0; border: 0; box-shadow: none;
  background: transparent; color: var(--ink-muted); border-radius: calc(var(--radius) - 2px);
}
.icon-btn:hover { background: var(--surface-muted); color: var(--ink); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* --- Forms --------------------------------------------------------------- */
form { margin: 0 0 1rem; }
label { display: block; font-size: 0.9rem; font-weight: 500; color: var(--ink-2); margin-bottom: 1rem; }
label > input, label > select, label > textarea { margin-top: 6px; }
label small { display: block; font-weight: 400; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=search], input[type=file], select, textarea {
  display: block; width: 100%; min-height: 38px; padding: 7px 10px;
  border: 1px solid var(--border-strong); border-radius: var(--radius);
  background: var(--surface); color: var(--ink); font: inherit; font-size: 0.93rem;
  box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--ink-muted); opacity: 1; }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 18%, transparent);
}
input[type=checkbox], input[type=radio] { accent-color: var(--accent); width: 16px; height: 16px; }
textarea { min-height: 120px; resize: vertical; line-height: 1.55; }
input[type=file] { padding: 6px; }
input[type=file]::file-selector-button {
  margin-right: 10px; border: 1px solid var(--border-strong); border-radius: calc(var(--radius) - 2px);
  background: var(--surface-alt); color: var(--ink); font: 500 0.86rem var(--font-ui); padding: 5px 10px; cursor: pointer;
}
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 4px; margin: 0 0 12px; }
legend { padding: 0 4px; font-size: 0.86rem; font-weight: 600; }

/* --- Tables -------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; margin-bottom: 1rem; font-size: 0.93rem; }
th {
  text-align: left; font-weight: 500; font-size: 0.86rem; color: var(--ink-muted);
  padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: var(--pad-cell); border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-alt); }

/* --- Disclosure, preformatted ------------------------------------------- */
details { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px; background: var(--surface); }
summary {
  display: flex; align-items: center; gap: 8px; padding: 10px 14px; cursor: pointer;
  font-weight: 500; list-style: none; border-radius: var(--radius);
}
summary::-webkit-details-marker { display: none; }
summary::before {
  content: ""; width: 6px; height: 6px; flex: none; margin: 0 4px 0 2px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(-45deg); transition: transform .15s;
}
details[open] > summary::before { transform: rotate(45deg); }
details[open] > summary { border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.details-body { padding: 14px; }
pre {
  font: 0.86rem/1.6 var(--font-mono); white-space: pre-wrap; overflow-wrap: anywhere; margin: 0 0 1rem;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-alt);
}

/* --- Feedback ------------------------------------------------------------ */
.msg { margin-bottom: 12px; font-size: 0.93rem; }
.msg:empty { display: none; }
.error, .success, .callout {
  --tone: var(--err); --tone-bg: var(--err-bg);
  color: var(--tone); background: var(--tone-bg);
  border: 1px solid color-mix(in srgb, var(--tone) 30%, var(--surface));
  border-radius: var(--radius); padding: 10px 12px;
}
.success, .callout.green { --tone: var(--ok); --tone-bg: var(--ok-bg); }
.callout.yellow { --tone: var(--warn); --tone-bg: var(--warn-bg); }
.callout { margin: 0 0 16px; font-weight: 500; }
.callout.banner { margin: 8px 0 24px; }
.notice { font-size: 0.93rem; color: var(--ink-muted); margin-bottom: 8px; }
.loading { color: var(--ink-muted); font-size: 0.93rem; }
.skeleton {
  border-radius: var(--radius); min-height: 14px;
  background: linear-gradient(90deg, var(--surface-muted), var(--surface-alt), var(--surface-muted));
  background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Status pills (pill) and the older type/status badges (badge). */
.pill, .badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 8px;
  border-radius: var(--badge-radius); border: 1px solid var(--border);
  font-size: 0.82rem; font-weight: 500; white-space: nowrap; vertical-align: middle;
  color: var(--ink-2); background: var(--surface-muted);
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.waiting, .badge-status-pending { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.pill.done, .badge-status-completed { color: var(--ok); background: var(--ok-bg); border-color: var(--accent-line); }
.pill.draft, .badge-status-draft { color: var(--ink-2); background: var(--surface-muted); border-color: var(--border); }
.badge-type-pdf, .badge-type-text { color: var(--info); background: var(--info-bg); border-color: transparent; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60; translate: -50% 0; max-width: calc(100vw - 32px);
  padding: 10px 14px; border-radius: var(--radius); background: var(--ink); color: var(--bg);
  font-size: 0.93rem; box-shadow: var(--shadow-lg); opacity: 0; pointer-events: none;
  transition: opacity .2s, translate .2s cubic-bezier(.16, 1, .3, 1);
}
.toast:not(:empty) { opacity: 1; translate: -50% -4px; }
.toast.err { background: var(--err); color: #fff; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important;
  }
}

dialog.confirm {
  width: min(420px, calc(100vw - 32px)); padding: 22px; border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg);
}
dialog.confirm::backdrop { background: rgba(10, 10, 10, .32); }
dialog.confirm h2 { margin: 0 0 8px; }
dialog.confirm p { color: var(--ink-muted); }
dialog.confirm form { margin: 0; }
dialog.confirm .btn-row { justify-content: flex-end; margin-top: 18px; }
