/* =====================================================================
   BASE — reset + shared components (top bar, buttons, inputs, mosaic).
   Uses tokens from tokens.css only.
   ===================================================================== */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--c-ground);
  color: var(--c-ink);
  font-family: var(--f-text);
  font-size: var(--t-body);
  line-height: var(--lh-text);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, p, dl, dd, figure { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }
[hidden] { display: none !important; }
::selection { background: var(--c-accent); color: var(--c-accent-ink); }
:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 3px; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}

/* ---- Top bar ------------------------------------------------------- */
.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-4);
  width: 100%;
  max-width: calc(var(--max) + 2 * var(--gutter));
  margin: 0 auto;
  padding: var(--s-5) var(--gutter);
}
.wordmark {
  font-family: var(--f-display);
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
  text-decoration: none;
}
.wordmark-sub { color: var(--c-ink-2); font-weight: 500; margin-left: var(--s-2); }
.bar-link {
  font-size: var(--t-small);
  font-weight: 500;
  text-decoration: none;
  color: var(--c-ink-2);
  padding: var(--s-2) 0;
  transition: color var(--dur-fast);
}
.bar-link:hover { color: var(--c-ink); }

/* ---- Header controls: language + day/night ------------------------ */
.bar-controls { display: flex; align-items: center; gap: var(--s-3); }

.lang { display: inline-flex; }
.lang-select {
  appearance: none;
  -webkit-appearance: none;
  min-height: 38px;
  padding: 0 30px 0 var(--s-3);
  border: 0;
  border-radius: 999px;
  background: var(--c-surface-2);
  color: var(--c-ink);
  font-size: var(--t-small);
  font-weight: 500;
  cursor: pointer;
  /* chevron */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 16px;
  transition: background-color var(--dur-fast);
}
.lang-select:hover { background-color: var(--c-surface-3); }
.lang-select:focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }

.theme {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: var(--c-surface-2);
}
.theme-btn {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--c-ink-2);
  cursor: pointer;
  transition: background-color var(--dur-fast), color var(--dur-fast);
}
.theme-btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.theme-btn:hover { color: var(--c-ink); }
.theme-btn[aria-pressed="true"] { background: var(--c-ground); color: var(--c-accent); }
.theme-btn[data-theme-set="dark"] svg { fill: currentColor; stroke: none; }

@media (max-width: 520px) {
  /* Bigger touch targets and no crowding against the "find another invoice" link. */
  .lang-select { padding-right: 26px; font-size: 0.8125rem; min-height: 40px; }
  .theme-btn { width: 40px; height: 40px; }
  .bar-controls { gap: var(--s-2); }
  .bar-link { display: none; } /* the ALAS wordmark already returns to the lookup */
}

/* ---- Buttons ------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s-2);
  min-height: var(--control-h);
  padding: 0 var(--s-5);
  border: 0;
  border-radius: var(--radius);
  font-weight: 600;
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--dur-fast), color var(--dur-fast), transform var(--dur-fast) var(--ease-out);
}
.btn:active { transform: translateY(1px) scale(0.98); }
.btn[disabled] { opacity: 0.5; cursor: progress; }

.btn-primary { background: var(--c-accent); color: var(--c-accent-ink); }
.btn-primary:hover { background: var(--c-ink); }

.btn-ghost { background: var(--c-surface-2); color: var(--c-ink); }
.btn-ghost:hover { background: var(--c-surface-3); }

.btn-danger { background: transparent; color: var(--c-danger); padding: 0 var(--s-3); }
.btn-danger:hover { background: var(--c-surface-2); }

.btn-small { min-height: 40px; padding: 0 var(--s-4); font-size: var(--t-small); }

/* ---- Inputs -------------------------------------------------------- */
.field-label {
  display: block;
  font-size: var(--t-small);
  font-weight: 500;
  color: var(--c-ink-2);
  margin-bottom: var(--s-2);
}
.field-input {
  width: 100%;
  min-height: var(--control-h);
  padding: 0 var(--s-4);
  border: 0;
  border-radius: var(--radius);
  background: var(--c-surface-2);
  transition: background-color var(--dur-fast), box-shadow var(--dur-fast);
}
.field-input::placeholder { color: var(--c-ink-2); opacity: 0.8; }
.field-input:hover { background: var(--c-surface-3); }
.field-input:focus { outline: none; box-shadow: inset 0 0 0 2px var(--c-accent); background: var(--c-surface-2); }
.field-input[aria-invalid="true"] { box-shadow: inset 0 0 0 2px var(--c-danger); }
select.field-input { cursor: pointer; padding-right: var(--s-3); }
input[type="date"].field-input { cursor: text; }
.field-input.is-code { font-family: var(--f-code); letter-spacing: 0.02em; text-transform: uppercase; }
.field-error { color: var(--c-danger); font-size: var(--t-small); margin-top: var(--s-2); min-height: 0; }
.field-error:empty { display: none; }
.field-hint { color: var(--c-ink-2); font-size: var(--t-small); margin-top: var(--s-2); }

/* ---- Invoice status dot ------------------------------------------- */
.status-dot { width: 8px; height: 8px; flex: none; border-radius: 50%; background: var(--c-status-unpaid); }
.status-dot[data-status="paid"]      { background: var(--c-status-paid); }
.status-dot[data-status="expired"]   { background: var(--c-status-expired); }
.status-dot[data-status="cancelled"] { background: var(--c-status-cancelled); }

/* ---- Mosaic: the generated signature of an invoice number ---------- */
.mosaic { display: block; width: 100%; height: auto; }
.mosaic rect {
  fill: var(--mosaic-0);
  transition: fill var(--dur) var(--ease-out);
  transition-delay: calc(var(--i, 0) * 9ms);
}
.mosaic rect.m1 { fill: var(--mosaic-1); }
.mosaic rect.m2 { fill: var(--mosaic-2); }
.mosaic rect.m3 { fill: var(--mosaic-3); filter: drop-shadow(var(--mosaic-glow)); }

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