/* ============================================================================
   Kery invoicing - application layer.

   Sits on top of tokens.css, which is dropped in unedited. Everything here
   either extends the design system with something it does not define (nav,
   breakpoints, the card/table split) or adapts a token for a phone.

   Light only. Kery ships no dark mode and adding one is a brand violation, not
   a courtesy - do not add a prefers-color-scheme block.

   Built narrow-first: the base rules are the phone layout, and the media
   queries widen it. A whole invoicing cycle has to be runnable from a phone.
   ========================================================================= */

@font-face {
  font-family: "TT Firs Text";
  src: url("/static/fonts/TT-Firs-Text-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "TT Firs Text";
  src: url("/static/fonts/TT-Firs-Text-Medium.ttf") format("truetype");
  font-weight: 500;
  font-display: swap;
}

/* --- adapting the scale for small screens ---------------------------------
   --screen-h1 is 3rem, which is too large at 375px. tokens.css must not be
   edited, so the scale is clamped here instead - adding rules after it is the
   sanctioned way to extend it. */
:root {
  --screen-h1: clamp(1.75rem, 1.2rem + 2.6vw, 3rem);
  --screen-h2: clamp(1.375rem, 1.05rem + 1.6vw, 2.25rem);
  --screen-h3: clamp(1.15rem, 1rem + 0.8vw, 1.75rem);
  --gutter: var(--space-4);
  --tap: 44px;          /* minimum touch target */
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--surface-sunken);
  /* Never let the page itself scroll sideways; wide content scrolls in its
     own container instead. */
  overflow-x: hidden;
}

.wrap {
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--space-5) var(--gutter) var(--space-10);
}

/* --- nav ------------------------------------------------------------------
   The design system defines no nav, so this is ours. A top bar that wraps
   rather than a menu button: with three links, a hamburger would be more
   chrome than content. */
.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.nav-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--space-3) var(--gutter);
  display: flex;
  align-items: center;
  gap: var(--space-4);
  flex-wrap: wrap;
}
.nav-logo { height: 30px; width: auto; display: block; }
.nav-links { display: flex; gap: var(--space-2); flex: 1 1 auto; flex-wrap: wrap; }
.nav a {
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  font-size: var(--screen-small);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-pill);
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
}
.nav a:hover { background: var(--hover-tint); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-tint); color: var(--text); }
.nav-user {
  font-size: var(--screen-caption);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* --- headings and blocks --------------------------------------------------- */

h1 { margin: 0 0 var(--space-2); }
h2 { margin: var(--space-6) 0 var(--space-3); }
.lede { color: var(--text-secondary); margin: 0 0 var(--space-5); }

.panel {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
  margin-bottom: var(--space-5);
}
.panel-header {
  background: var(--surface-header);
  margin: calc(var(--space-5) * -1) calc(var(--space-5) * -1) var(--space-5);
  padding: var(--space-4) var(--space-5);
  font-weight: 500;
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

/* --- buttons: pill radius is a brand rule ---------------------------------- */

.btn {
  font-family: var(--font);
  font-weight: 500;
  font-size: var(--screen-body);
  border-radius: var(--radius-pill);
  padding: var(--space-3) var(--space-5);
  border: 1px solid transparent;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap);
  text-decoration: none;
  transition: background-color 120ms ease, color 120ms ease;
}
.btn-primary { background: var(--accent); color: var(--text-on-accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: var(--kery-stone-3); cursor: not-allowed; }
.btn-secondary { background: transparent; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--hover-tint); }
.btn-block { width: 100%; }

/* --- forms ----------------------------------------------------------------- */

.input, select.input {
  font-family: var(--font);
  font-size: var(--screen-body);
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  min-height: var(--tap);
  width: 100%;
}
.input::placeholder { color: var(--text-muted); }
.input:focus-visible { border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-4); }
.field label { font-size: var(--screen-small); font-weight: 500; }
.row { display: flex; flex-direction: column; gap: var(--space-3); }

/* --- status: colour never carries meaning on its own ----------------------- */

.chip {
  display: inline-block;
  border-radius: var(--radius-pill);
  padding: 4px 12px;
  font-size: var(--screen-caption);
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--kery-graphite);   /* graphite on tone-3, per the contrast table */
  white-space: nowrap;
}
.chip-ok      { background: var(--kery-verdant-3); }
.chip-warn    { background: var(--kery-yellow-3); }
.chip-blocked { background: var(--kery-red-3); }
.chip-quiet   { background: var(--kery-stone-2); }

.callout {
  border-left: 4px solid var(--accent);
  background: var(--kery-stone-1);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  padding: var(--space-4) var(--space-5);
  margin: var(--space-4) 0;
}
.callout-warn { border-left-color: var(--status-warning); }
.callout-quiet { border-left-color: var(--kery-stone-3); }

.total {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
  align-items: baseline;
  margin-top: var(--space-4);
}
.total-figure { font-size: var(--screen-h3); font-weight: 500; }
.muted { color: var(--text-secondary); font-size: var(--screen-small); }
.tiny { color: var(--text-muted); font-size: var(--screen-caption); }
.numeric { font-variant-numeric: tabular-nums; }

/* --- the invoice list ------------------------------------------------------
   Two presentations of one dataset. Below 640px each invoice is a card, because
   seven columns on a 375px screen is a sideways scroll, and money should not be
   reviewed sideways. The table appears from 640px up. */

.cards { display: grid; gap: var(--space-3); }
.inv-card {
  background: var(--surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  box-shadow: var(--shadow-sm);
}
.inv-card-top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: var(--space-3);
}
.inv-card-client { font-weight: 500; }
.inv-card-amount { font-weight: 500; font-size: var(--screen-h5); white-space: nowrap; }
.inv-card-meta {
  margin-top: var(--space-2);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-4);
  color: var(--text-secondary);
  font-size: var(--screen-small);
}

.inv-table { display: none; }

table { width: 100%; border-collapse: collapse; font-size: var(--screen-small); }
thead th {
  background: var(--surface-header);
  text-align: left;
  font-weight: 500;
  padding: var(--space-3) var(--space-4);
  white-space: nowrap;
}
tbody td { padding: var(--space-3) var(--space-4); border-top: 1px solid var(--border-subtle); }
tbody tr:hover { background: var(--hover-tint); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }

@media (min-width: 640px) {
  :root { --gutter: var(--space-6); }
  .cards { display: none; }
  .inv-table { display: block; }
  .row { flex-direction: row; align-items: flex-end; }
  .row > * { flex: 1 1 auto; }
  .row > .btn { flex: 0 0 auto; }
  .btn-block { width: auto; }
}

/* --- the confirm dialog ----------------------------------------------------
   Matters more on a phone, where a mis-tap is likelier: full-width buttons and
   Create deliberately not adjacent to Cancel. */

dialog.confirm {
  border: none;
  border-radius: var(--radius-lg);
  padding: 0;
  max-width: 460px;
  width: calc(100% - var(--space-5) * 2);
  box-shadow: var(--shadow-lg);
  color: var(--text);
  background: var(--surface);
}
dialog.confirm::backdrop { background: rgba(34, 34, 34, 0.45); }
.confirm-body { padding: var(--space-5); }
.confirm-figure {
  font-size: var(--screen-h3);
  font-weight: 500;
  margin: var(--space-3) 0;
}
.confirm-actions {
  display: flex;
  flex-direction: column-reverse;   /* Cancel below Create, never beside it */
  gap: var(--space-3);
  padding: 0 var(--space-5) var(--space-5);
}

/* --- ornament --------------------------------------------------------------
   Shapes are files from the approved library, never drawn. One accent, beside a
   heading, never behind text. */
.accent-shape { height: 40px; width: auto; flex: 0 0 auto; }
.title-row { display: flex; align-items: center; gap: var(--space-4); }

@media (max-width: 480px) {
  .accent-shape { display: none; }   /* ornament is the first thing to go */
}

/* --- selecting which clients to invoice ------------------------------------
   Whole card is the hit area on a phone; the table gets a narrow tick column. */

.inv-card.selectable { cursor: pointer; }
.inv-card.selectable:has(input:not(:checked)) { opacity: 0.55; }
.inv-card.selectable:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input[type="checkbox"] {
  width: 20px;
  height: 20px;
  accent-color: var(--accent);
  margin-right: var(--space-2);
  vertical-align: -3px;
  flex: 0 0 auto;
  cursor: pointer;
}

th.tick, td.tick { width: 1%; padding-right: 0; }
tbody tr:has(input[data-mirror]:not(:checked)) { color: var(--text-muted); }

.btn-link {
  background: none;
  border: none;
  padding: var(--space-2);
  min-height: var(--tap);
  font-family: var(--font);
  font-size: var(--screen-small);
  font-weight: 500;
  color: var(--accent);
  cursor: pointer;
  text-decoration: underline;
}

.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;
}

/* --- the resolved date range ----------------------------------------------
   Invoicing the wrong fortnight is the costliest mistake this screen can make,
   so the range it resolved to sits in the heading rather than in body text. */

.period-badge {
  display: inline-block;
  background: var(--accent-tint);
  color: var(--text);
  border-radius: var(--radius-pill);
  padding: 2px 14px;
  font-size: var(--screen-small);
  font-weight: 500;
  vertical-align: middle;
  white-space: nowrap;
}

/* --- preview harness -------------------------------------------------------
   Rendered only when tools/preview.py sets `preview_notice`. Real runs never
   set it, so fixture data can never be mistaken for the ledger. */

.preview-banner {
  background: var(--kery-yellow-3);
  color: var(--kery-graphite);
  text-align: center;
  padding: var(--space-3) var(--gutter);
  font-size: var(--screen-small);
  font-weight: 500;
}
