/* ============================================================
   InvoicePDFs — bespoke UI system
   Apple-grade product surface, fully tokenized.
   Themes: light · dark · system (follows OS via prefers-color-scheme).
   Every color routes through a custom property so the three
   modes are pure token swaps — components never hardcode a color.
   ============================================================ */

/* ---------- Light tokens (default) ---------- */
:root {
  color-scheme: light;

  --bg:        #fbfbfd;   /* Apple off-white page */
  --surface:   #ffffff;
  --surface-2: #f5f5f7;   /* recessed / hover fills */

  --ink:   #1d1d1f;
  --ink-2: #6e6e73;
  --ink-3: #86868b;

  --line:      #d2d2d7;
  --line-soft: #e8e8ed;

  --accent:       #7C9ED9;   /* brand "pdfs" blue */
  --accent-hover: #6B90D0;
  --accent-press: #5E82C7;
  --link:         #5877BE;   /* deeper for readable link text */
  --btn-ink:      #0F172A;   /* dark button text on light theme */

  --ok-bg:   #e6f6ec;  --ok-ink:   #1a7f46;
  --info-bg: #e6f0fb;  --info-ink: #0067c7;
  --warn-bg: #fdeede;  --warn-ink: #9a5b00;
  --mute-bg: #ececef;  --mute-ink: #6e6e73;
  --bad-bg:  #fdecec;  --bad-ink:  #c0362c;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 4px 24px rgba(0,0,0,.06);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.10);

  --hover-fill:   rgba(0,0,0,.04);
  --focus-ring:   rgba(124,158,217,.5);
  --focus-shadow: 0 0 0 4px rgba(124,158,217,.2);
  --nav-bg:       rgba(251,251,253,.72);

  --radius:      18px;
  --radius-sm:   12px;
  --radius-pill: 980px;
  --ease: cubic-bezier(.28,.11,.32,1);

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
          "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

/* ---------- Dark palette (shared values) ---------- */
/* Applied for explicit dark, and for system mode when the OS is dark.
   Kept in two selector blocks because a media query and a plain
   selector can't share one rule; values are identical. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg:        #000000;
  --surface:   #1c1c1e;
  --surface-2: #2c2c2e;

  --ink:   #f5f5f7;
  --ink-2: #aeaeb2;
  --ink-3: #8d8d93;

  --line:      #38383a;
  --line-soft: #2c2c2e;

  --accent:       #5E82C7;   /* deeper brand blue: readable button bg */
  --accent-hover: #6E90D5;
  --accent-press: #4F72B5;
  --link:         #AFCBFF;   /* brand "pdfs" blue (dark logo) for links */
  --btn-ink:      #FFFFFF;   /* light button text on dark theme */

  --ok-bg:   rgba(48,209,88,.18);   --ok-ink:   #30d158;
  --info-bg: rgba(41,151,255,.18);  --info-ink: #6cb6ff;
  --warn-bg: rgba(255,159,10,.18);  --warn-ink: #ff9f0a;
  --mute-bg: rgba(120,120,128,.28); --mute-ink: #c7c7cc;
  --bad-bg:  rgba(255,69,58,.18);   --bad-ink:  #ff6961;

  --shadow-sm: 0 1px 2px rgba(0,0,0,.5);
  --shadow-md: 0 4px 24px rgba(0,0,0,.55);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.6);

  --hover-fill:   rgba(255,255,255,.06);
  --focus-ring:   rgba(175,203,255,.6);
  --focus-shadow: 0 0 0 4px rgba(175,203,255,.28);
  --nav-bg:       rgba(20,20,22,.72);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    color-scheme: dark;

    --bg:        #000000;
    --surface:   #1c1c1e;
    --surface-2: #2c2c2e;

    --ink:   #f5f5f7;
    --ink-2: #aeaeb2;
    --ink-3: #8d8d93;

    --line:      #38383a;
    --line-soft: #2c2c2e;

    --accent:       #5E82C7;   /* deeper brand blue: readable button bg */
    --accent-hover: #6E90D5;
    --accent-press: #4F72B5;
    --link:         #AFCBFF;   /* brand "pdfs" blue (dark logo) for links */
    --btn-ink:      #FFFFFF;   /* light button text on dark theme */

    --ok-bg:   rgba(48,209,88,.18);   --ok-ink:   #30d158;
    --info-bg: rgba(41,151,255,.18);  --info-ink: #6cb6ff;
    --warn-bg: rgba(255,159,10,.18);  --warn-ink: #ff9f0a;
    --mute-bg: rgba(120,120,128,.28); --mute-ink: #c7c7cc;
    --bad-bg:  rgba(255,69,58,.18);   --bad-ink:  #ff6961;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.5);
    --shadow-md: 0 4px 24px rgba(0,0,0,.55);
    --shadow-lg: 0 12px 40px rgba(0,0,0,.6);

    --hover-fill:   rgba(255,255,255,.06);
    --focus-ring:   rgba(175,203,255,.6);
    --focus-shadow: 0 0 0 4px rgba(175,203,255,.28);
    --nav-bg:       rgba(20,20,22,.72);
    --select-arrow: %238d8d93;
  }
}

:root[data-theme="system"] { color-scheme: light dark; }

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "kern" 1;
  transition: background .3s var(--ease), color .3s var(--ease);
}
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

h2, h3, h4 { color: var(--ink); font-weight: 600; letter-spacing: -.021em; margin: 0 0 .5em; }
h2 { font-size: 2.1rem; line-height: 1.1; letter-spacing: -.025em; }
h3 { font-size: 1.4rem; margin-top: 2.4rem; }
h4 { font-size: 1.05rem; letter-spacing: -.01em; }
p  { margin: 0 0 1rem; }
small { color: var(--ink-3); font-size: .82rem; }
code {
  font-family: var(--mono); font-size: .85em;
  background: var(--surface-2); border: 1px solid var(--line-soft);
  padding: .12em .45em; border-radius: 6px; color: var(--ink);
}

/* ---------- Layout ---------- */
.container {
  width: 100%;
  max-width: 1024px;
  margin-inline: auto;
  padding-inline: 24px;
}
main.container { padding-block: 40px 72px; }

.grid {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
@media (max-width: 720px) { .grid { grid-auto-flow: row; } }

/* ---------- Top navigation (frosted) ---------- */
body > nav.container {
  position: sticky; top: 0; z-index: 50;
  max-width: none; width: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 0 max(24px, calc((100% - 1024px) / 2 + 24px));
  height: 52px;
  background: var(--nav-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid var(--line-soft);
}
body > nav.container ul {
  list-style: none; margin: 0; padding: 0;
  display: flex; align-items: center; gap: 4px;
}
body > nav.container > ul:first-child { margin-right: auto; }
body > nav.container a {
  color: var(--ink-2); font-size: .88rem; letter-spacing: -.01em;
  padding: 6px 12px; border-radius: 8px;
  transition: color .2s var(--ease), background .2s var(--ease);
}
body > nav.container a:hover { color: var(--ink); background: var(--hover-fill); text-decoration: none; }
body > nav.container a.active { color: var(--ink); font-weight: 500; }
body > nav.container strong a,
body > nav.container a.contrast {
  color: var(--ink); font-weight: 600; font-size: 1.02rem; letter-spacing: -.02em; padding-left: 0;
}
body > nav.container strong a:hover { background: transparent; }

/* ---------- Theme switch (segmented) ---------- */
.theme-switch {
  display: inline-flex; align-items: center; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--radius-pill); padding: 2px;
}
.theme-switch button {
  all: unset; box-sizing: border-box;
  width: 28px; height: 24px; display: grid; place-items: center;
  border-radius: var(--radius-pill); cursor: pointer;
  color: var(--ink-3); font-size: .82rem; line-height: 1;
  transition: background .2s var(--ease), color .2s var(--ease);
}
.theme-switch button:hover { color: var(--ink); }
.theme-switch button[aria-pressed="true"] {
  background: var(--surface); color: var(--ink); box-shadow: var(--shadow-sm);
}
.theme-switch button:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.theme-switch svg { width: 15px; height: 15px; display: block; }

/* ---------- Page header (hgroup) ---------- */
hgroup { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 1.6rem; flex-wrap: wrap; }
hgroup h2 { margin: 0; }
hgroup p { margin: 0; }

/* ---------- Cards (article) ---------- */
article {
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 22px 24px;
  margin: 0 0 20px;
  box-shadow: var(--shadow-sm);
}
article > header {
  font-size: .8rem; font-weight: 500; letter-spacing: .01em;
  text-transform: uppercase; color: var(--ink-3);
  margin-bottom: .4rem; padding: 0; border: 0; background: none;
}
article h3, article h4 { margin: 0; }

.grid > article h3 { font-size: 2.6rem; font-weight: 600; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.grid > article h4 { font-size: 1.9rem; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }

/* ---------- Buttons ---------- */
button,
a[role="button"],
input[type="submit"] {
  display: inline-flex; align-items: center; justify-content: center;
  font-family: inherit; font-size: .95rem; font-weight: 500; letter-spacing: -.01em;
  padding: 9px 20px; border-radius: var(--radius-pill);
  background: var(--accent); color: var(--btn-ink); border: 1px solid transparent;
  cursor: pointer; white-space: nowrap;
  transition: background .2s var(--ease), transform .08s var(--ease), box-shadow .2s var(--ease), color .2s var(--ease);
}
button:hover,
a[role="button"]:hover,
input[type="submit"]:hover { background: var(--accent-hover); text-decoration: none; }
button:active,
a[role="button"]:active { transform: scale(.97); background: var(--accent-press); }

.contrast:not(a), button.contrast, a[role="button"].contrast { background: var(--ink); color: var(--bg); }
button.contrast:hover, a[role="button"].contrast:hover { background: var(--ink); opacity: .88; }

button.secondary, a[role="button"].secondary {
  background: var(--surface-2); color: var(--ink); border-color: var(--line);
}
button.secondary:hover, a[role="button"].secondary:hover { background: var(--line-soft); }

button.outline, a[role="button"].outline {
  background: transparent; color: var(--link); border-color: var(--line);
}
button.outline:hover, a[role="button"].outline:hover { background: var(--hover-fill); }
button.outline.secondary, a[role="button"].outline.secondary { color: var(--ink-2); border-color: var(--line); }
button.outline.secondary:hover { color: var(--ink); background: var(--hover-fill); }

button:focus-visible, a:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--focus-ring); outline-offset: 2px;
}

/* ---------- Forms ---------- */
form { margin: 0; }
label {
  display: block; margin-bottom: 16px;
  font-size: .82rem; font-weight: 500; color: var(--ink-2); letter-spacing: -.005em;
}
input, select, textarea {
  display: block; width: 100%; margin-top: 6px;
  font-family: inherit; font-size: 1rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 10px 14px;
  transition: border-color .18s var(--ease), box-shadow .18s var(--ease), background .3s var(--ease);
  -webkit-appearance: none; appearance: none;
}
textarea { resize: vertical; min-height: 84px; }
select {
  /* fixed mid-grey arrow — data-URI can't read CSS vars; this grey reads on both themes */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2386868b' d='M6 8 0 2l1.4-1.4L6 5.2 10.6.6 12 2z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 38px;
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: var(--focus-shadow);
}
label input, label select, label textarea { font-weight: 400; }
form > button[type="submit"] { margin-top: 4px; }

.line-item { padding: 16px; background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); margin-bottom: 12px; }
.line-item label:last-child { margin-bottom: 0; }
#line-items + button { margin-bottom: 8px; }

/* ---------- Tables ---------- */
figure { margin: 0 0 20px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  border: 1px solid var(--line-soft); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow-sm); }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
thead th {
  text-align: left; font-weight: 500; font-size: .74rem; letter-spacing: .02em; text-transform: uppercase;
  color: var(--ink-3); padding: 14px 18px; border-bottom: 1px solid var(--line-soft); white-space: nowrap;
}
tbody td { padding: 14px 18px; border-bottom: 1px solid var(--line-soft); color: var(--ink); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr { transition: background .15s var(--ease); }
tbody tr:hover { background: var(--surface-2); }
tfoot td { padding: 14px 18px; border-top: 1px solid var(--line); font-variant-numeric: tabular-nums; }
td:nth-child(n+2) { font-variant-numeric: tabular-nums; }

/* ---------- Status badges ---------- */
mark, .badge {
  display: inline-flex; align-items: center;
  font-size: .74rem; font-weight: 600; letter-spacing: .005em;
  padding: 3px 10px; border-radius: var(--radius-pill);
  background: var(--mute-bg); color: var(--mute-ink); text-transform: capitalize; line-height: 1.4;
}
.badge-paid      { background: var(--ok-bg);   color: var(--ok-ink); }
.badge-sent      { background: var(--info-bg); color: var(--info-ink); }
.badge-finalized { background: var(--info-bg); color: var(--info-ink); }
.badge-draft     { background: var(--mute-bg); color: var(--mute-ink); }
.badge-void      { background: var(--bad-bg);  color: var(--bad-ink); }
.badge-archived  { background: var(--mute-bg); color: var(--ink-3); }
.badge-overdue   { background: var(--warn-bg); color: var(--warn-ink); }

/* ---------- Filter tabs (invoices nav) ---------- */
main nav { margin-bottom: 1.5rem; }
main nav ul { list-style: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 0; padding: 0; }
main nav li { margin: 0; }
main nav ul a {
  display: inline-block; font-size: .86rem; font-weight: 500; color: var(--ink-2);
  padding: 6px 14px; border-radius: var(--radius-pill); transition: all .18s var(--ease);
}
main nav ul a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
main nav ul a[aria-current="page"] { background: var(--ink); color: var(--bg); }
main nav a[role="button"] { color: var(--link); }
main nav a[role="button"][aria-current] { background: var(--accent); color: var(--btn-ink); }

/* ---------- Flash messages ---------- */
.flash-error, .flash-success, .flash-info {
  border: 1px solid var(--line-soft); border-left-width: 3px;
  padding: 14px 18px; margin-bottom: 20px; border-radius: var(--radius-sm);
  font-size: .92rem; box-shadow: var(--shadow-sm);
}
.flash-error   { border-left-color: var(--bad-ink);  background: var(--bad-bg);  color: var(--bad-ink); }
.flash-success { border-left-color: var(--ok-ink);   background: var(--ok-bg);   color: var(--ok-ink); }
.flash-info    { border-left-color: var(--info-ink); background: var(--info-bg); color: var(--info-ink); }

/* ---------- Footer ---------- */
body > footer.container { border-top: 1px solid var(--line-soft); padding: 28px 24px; text-align: center; }
body > footer.container small { color: var(--ink-3); }

/* ---------- Auth (login) ---------- */
.auth-shell { position: relative; min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-shell article { width: 100%; max-width: 400px; margin: 0; padding: 36px 32px; box-shadow: var(--shadow-lg); border-color: var(--line-soft); }
.auth-shell article > header { text-transform: none; }
.auth-shell h2 { font-size: 1.7rem; letter-spacing: -.022em; margin-bottom: 4px; color: var(--ink); }
.auth-shell header p { color: var(--ink-3); font-size: .95rem; margin: 0 0 20px; }
.auth-shell button { width: 100%; margin-top: 8px; }
.auth-theme { position: absolute; top: 20px; right: 20px; }

/* Quota hint under the usage meter. Deliberately plain text, not a banner —
   it should read as information, not as an interruption. */
.quota-note { margin: 10px 0 0; font-size: .84rem; color: var(--ink-2); }
.quota-note--over { color: var(--warn-ink); }

/* Sign-in / sign-up: provider button, "or" divider, helper links. */
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 20px 0 16px; color: var(--ink-3); font-size: .82rem; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line-soft); }
.auth-provider { display: flex; align-items: center; justify-content: center; gap: 10px;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); }
.auth-provider:hover { background: var(--hover-fill); }
.auth-links { margin: 16px 0 0; text-align: center; font-size: .9rem; color: var(--ink-3); }
.auth-error { margin: 10px 0 0; color: var(--bad-ink); font-size: .88rem; }
.auth-notice { color: var(--ink-2); font-size: .92rem; line-height: 1.5; margin: 0; }
.auth-fallback { margin-top: 22px; border-top: 1px solid var(--line-soft); padding-top: 14px; }
.auth-fallback summary { cursor: pointer; color: var(--ink-3); font-size: .86rem; }
.auth-fallback summary:hover { color: var(--ink-2); }
.auth-fallback form { margin-top: 12px; }

/* ---------- Motion ---------- */
main.container { animation: rise .5s var(--ease) both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* ---------- Document type tabs ---------- */
fieldset.doctype { border: 0; padding: 0; margin: 0 0 22px; }
fieldset.doctype legend { padding: 0; font-size: .82rem; font-weight: 500; color: var(--ink-2); margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips .chip { display: inline-block; padding: 7px 15px; border-radius: var(--radius-pill); border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); font-size: .86rem; font-weight: 500; transition: background .18s var(--ease), color .18s var(--ease), border-color .18s var(--ease); }
.chips a.chip:hover { border-color: var(--ink-3); color: var(--ink); text-decoration: none; }
.chips .chip.active { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.chips a.chip:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }

/* Informational banner (per document type) */
.doc-note { background: var(--surface-2); border: 1px solid var(--line-soft); border-left: 3px solid var(--accent); border-radius: var(--radius-sm); padding: 12px 16px; margin: 0 0 20px; color: var(--ink-2); font-size: .9rem; }

/* ---------- Rich line items ---------- */
.li-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(116px, 1fr)); gap: 12px 14px; align-items: end; }
.li-grid > label { margin: 0; }
.li-grid .li-desc { grid-column: 1 / -1; }
.li-grid .li-disc { grid-column: span 2; }
input[type="checkbox"], input[type="radio"] {
  -webkit-appearance: auto; appearance: auto; accent-color: var(--accent);
  width: auto; height: auto; display: inline-block; margin: 0; padding: 0; vertical-align: middle;
}
.li-check { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.disc-field { display: flex; gap: 8px; margin-top: 6px; }
.disc-field select { width: auto; flex: none; min-width: 78px; margin-top: 0; }
.disc-field input { margin-top: 0; }
.li-remove { margin-top: 12px; padding: 6px 14px; font-size: .82rem; }

/* ---------- Totals preview (create screen) ---------- */
.totals-preview { max-width: 320px; margin: 8px 0 22px auto; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); padding: 12px 18px; }
.tp-row { display: flex; justify-content: space-between; gap: 16px; font-size: .9rem; color: var(--ink-2); padding: 5px 0; font-variant-numeric: tabular-nums; }
.tp-total { border-top: 1px solid var(--line); margin-top: 6px; padding-top: 10px; color: var(--ink); font-weight: 600; font-size: 1.06rem; }
.tp-cur { color: var(--ink-3); font-weight: 400; font-size: .82em; }

/* ---------- Detail: line meta + totals breakdown ---------- */
.li-meta { display: inline-block; margin-left: 8px; color: var(--ink-3); font-size: .78rem; }
tfoot td { border-top: 0; color: var(--ink-2); }
tfoot tr:first-child td { border-top: 1px solid var(--line-soft); }
tfoot tr.grand td { border-top: 1px solid var(--line); color: var(--ink); }

/* ---------- Utility ---------- */
.muted { color: var(--ink-3); }
.stack > * + * { margin-top: 12px; }

/* ---------- API logs ---------- */
.logs { display: flex; flex-direction: column; gap: 10px; }
.log { background: var(--surface); border: 1px solid var(--line-soft); border-radius: var(--radius-sm); box-shadow: var(--shadow-sm); overflow: hidden; }
.log > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 14px; padding: 12px 16px; }
.log > summary::-webkit-details-marker { display: none; }
.log > summary:hover { background: var(--surface-2); }
.log[open] > summary { border-bottom: 1px solid var(--line-soft); }
.method { font-family: var(--mono); font-size: .72rem; font-weight: 700; letter-spacing: .03em; padding: 3px 8px; border-radius: 6px; background: var(--mute-bg); color: var(--mute-ink); min-width: 54px; text-align: center; }
.method-get { background: var(--info-bg); color: var(--info-ink); }
.method-post { background: var(--ok-bg); color: var(--ok-ink); }
.method-put, .method-patch { background: var(--warn-bg); color: var(--warn-ink); }
.method-delete { background: var(--bad-bg); color: var(--bad-ink); }
.log-path { flex: 1; font-family: var(--mono); font-size: .82rem; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-meta { color: var(--ink-3); font-size: .8rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.badge.log-ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge.log-info { background: var(--info-bg); color: var(--info-ink); }
.badge.log-warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.log-bad { background: var(--bad-bg); color: var(--bad-ink); }
.log-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 16px; }
@media (max-width: 720px) { .log-detail { grid-template-columns: 1fr; } }
.log-col h4 { font-size: .74rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); margin: 0 0 8px; }
.log-detail pre { margin: 0; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 10px; padding: 12px 14px; font-family: var(--mono); font-size: .78rem; line-height: 1.5; color: var(--ink); overflow: auto; max-height: 340px; white-space: pre; }

/* ---------- Live API activity sidebar ---------- */
.devbar { display: none; position: fixed; top: 0; right: 0; bottom: 0; width: 360px;
  background: var(--surface); border-left: 1px solid var(--line-soft); flex-direction: column; z-index: 40; }
/* Closed until asked for. It is a developer tool that costs 360px of a page
   most people are reading, so the handle is the default and the rail is the
   opt-in. `devbar-open` is set from localStorage in base.html's head script,
   before first paint, so a developer who opened it does not watch it appear. */
@media (min-width: 1280px) {
  html.devbar-open body { padding-right: 360px; }
  html.devbar-open .devbar { display: flex; }
}
.devbar-head { display: flex; align-items: center; justify-content: space-between; min-height: 52px;
  padding: 0 18px; border-bottom: 1px solid var(--line-soft);
  font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.devbar-head-actions { display: flex; align-items: center; gap: 10px; }
.devbar-all { font-size: .78rem; font-weight: 500; text-transform: none; letter-spacing: 0; }
.devbar-x { width: auto; margin: 0; padding: 0 6px; background: none; border: none; box-shadow: none;
  color: var(--ink-3); font-size: 1.25rem; line-height: 1; cursor: pointer; border-radius: 6px; }
.devbar-x:hover { background: var(--line-soft); color: var(--ink-1); }
.devbar-list { flex: 1; overflow-y: auto; padding: 10px; }

/* Retract / reopen the activity sidebar */
.devbar-reopen { display: none; width: auto; margin: 0; position: fixed; top: 50%; right: 0;
  transform: translateY(-50%); z-index: 60; cursor: pointer;
  align-items: center; gap: 6px; padding: 14px 8px;
  background: var(--accent); color: var(--btn-ink); border: none;
  border-radius: 12px 0 0 12px; box-shadow: -3px 3px 16px rgba(0,0,0,.20);
  writing-mode: vertical-rl; font-size: .72rem; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; line-height: 1; }
.devbar-reopen::before { content: "‹"; writing-mode: horizontal-tb; font-size: 1.1rem; font-weight: 400; }
.devbar-reopen:hover { filter: brightness(1.08); }
@media (min-width: 1280px) {
  .devbar-reopen { display: inline-flex; }
  html.devbar-open .devbar-reopen { display: none; }
}

/* Nav dropdown menus (Setup / Developer / Account) */
.nav-menu { position: relative; }
/* Specificity kept above `body > nav.container ul` so the menu stacks
   vertically and stays hidden until opened. */
body > nav.container .nav-menu { position: relative; }
body > nav.container .nav-menu summary {
  list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 5px;
  color: var(--ink-2); font-size: .88rem; letter-spacing: -.01em; padding: 6px 12px; border-radius: 8px;
  transition: color .2s var(--ease), background .2s var(--ease);
}
body > nav.container .nav-menu summary::-webkit-details-marker { display: none; }
body > nav.container .nav-menu summary::marker { content: ""; }
body > nav.container .nav-menu summary:hover { color: var(--ink); background: var(--hover-fill); }
body > nav.container .nav-menu summary.active { color: var(--ink); font-weight: 500; }
body > nav.container .nav-menu .acct-caret { font-size: .58em; opacity: .55; margin-top: 1px; }
body > nav.container .nav-menu ul {
  display: none; position: absolute; right: 0; top: calc(100% + 6px); margin: 0; padding: 6px;
  min-width: 160px; flex-direction: column; align-items: stretch; gap: 2px;
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: 11px; box-shadow: 0 10px 30px rgba(0,0,0,.12); z-index: 60;
}
body > nav.container .nav-menu details[open] ul { display: flex; }
body > nav.container .nav-menu ul li { margin: 0; width: 100%; }
body > nav.container .nav-menu ul a {
  display: block; width: 100%; padding: 8px 12px; border-radius: 7px; color: var(--ink-2); font-size: .88rem;
}
body > nav.container .nav-menu ul a:hover { background: var(--hover-fill); color: var(--ink); }
.dl-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.dl { border: 1px solid var(--line-soft); border-radius: 10px; background: var(--surface); overflow: hidden; }
.dl > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 8px 10px; }
.dl > summary::-webkit-details-marker { display: none; }
.dl > summary:hover { background: var(--surface-2); }
.dl .method { min-width: 46px; font-size: .64rem; padding: 2px 5px; }
.dl-path { flex: 1; font-family: var(--mono); font-size: .72rem; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl .badge { font-size: .64rem; padding: 2px 7px; }

/* PDF template picker (invoice detail "Download PDF") */
.pdf-menu { position: relative; margin: 0; }
.pdf-menu > summary { list-style: none; }
.pdf-menu > summary::-webkit-details-marker { display: none; }
.pdf-menu > summary::marker { content: ""; }
.pdf-menu .pdf-caret { font-size: .62em; opacity: .55; }
.pdf-menu > ul {
  display: none; position: absolute; left: 0; top: calc(100% + 6px); margin: 0; padding: 6px;
  min-width: 210px; list-style: none;
  background: var(--surface); border: 1px solid var(--line-soft);
  border-radius: 11px; box-shadow: 0 10px 30px rgba(0,0,0,.12); z-index: 60;
}
.pdf-menu[open] > ul { display: block; }
.pdf-menu > ul li { margin: 0; list-style: none; }
.pdf-menu > ul a {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 8px 10px; border-radius: 7px; color: var(--ink-2); font-size: .88rem;
}
.pdf-menu > ul a:hover { background: var(--hover-fill); color: var(--ink); }
.pdf-menu > ul a small { color: var(--ink-3); font-size: .7rem; text-transform: uppercase; letter-spacing: .04em; }
.dl-body { padding: 2px 10px 10px; border-top: 1px solid var(--line-soft); }
.dl-time { display: block; color: var(--ink-3); font-size: .72rem; margin: 7px 0 2px; font-variant-numeric: tabular-nums; }
.dl-sec { font-size: .68rem; font-weight: 600; text-transform: uppercase; letter-spacing: .03em; color: var(--ink-3); margin-top: 9px; }
.dl-body pre { margin: 4px 0 0; background: var(--surface-2); border: 1px solid var(--line-soft); border-radius: 8px;
  padding: 8px 10px; font-family: var(--mono); font-size: .7rem; line-height: 1.45; color: var(--ink); overflow: auto; max-height: 180px; white-space: pre; }
.dl-empty { padding: 24px 16px; font-size: .85rem; }

/* ---------- Brand logo (theme-aware wordmark) ---------- */
.brand { display: inline-flex; align-items: center; }
.brand-logo { display: block; height: 34px; width: auto; }
.brand-logo--lg { height: 46px; margin: 0 auto 8px; }
.brand-logo--dark { display: none; }                 /* light mode: show the dark wordmark */
:root[data-theme="dark"] .brand-logo--light { display: none; }
:root[data-theme="dark"] .brand-logo--dark  { display: block; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] .brand-logo--light { display: none; }
  :root[data-theme="system"] .brand-logo--dark  { display: block; }
}

/* Renders-usage panel + tokenized progress bar */
.usage-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.meter {
  appearance: none; -webkit-appearance: none;
  display: block; width: 100%; height: 8px; margin-top: 14px;
  border: none; border-radius: 999px; background: var(--surface-2); overflow: hidden;
}
.meter::-webkit-progress-bar   { background: var(--surface-2); border-radius: 999px; }
.meter::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
.meter::-moz-progress-bar      { background: var(--accent); border-radius: 999px; }

/* ---------- Responsive top nav (hamburger under 720px) ---------- */
.nav-toggle { display: none; }
@media (max-width: 720px) {
  .nav-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    margin-left: auto; width: 40px; height: 40px; padding: 0;
    background: transparent; border: 1px solid var(--line-soft); border-radius: 9px;
    color: var(--ink-2); cursor: pointer;
  }
  .nav-toggle:hover { background: var(--hover-fill); color: var(--ink); }
  body > nav.container > ul:first-child { margin-right: 0; }

  /* collapse the links into a dropdown panel below the header */
  body > nav.container .nav-links {
    position: absolute; top: 52px; left: 0; right: 0;
    display: none; flex-direction: column; align-items: stretch;
    gap: 2px; padding: 10px 16px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--line-soft); box-shadow: var(--shadow-md);
    max-height: calc(100vh - 52px); overflow-y: auto;
  }
  body > nav.container .nav-links.nav-open { display: flex; }
  body > nav.container .nav-links > li { width: 100%; }
  body > nav.container .nav-links > li > a { display: block; padding: 10px 12px; font-size: .95rem; border-radius: 8px; }

  /* dropdowns expand inline (accordion) instead of floating panels */
  body > nav.container .nav-menu { position: static; }
  body > nav.container .nav-menu summary { padding: 10px 12px; }
  body > nav.container .nav-menu ul {
    position: static; right: auto; top: auto; min-width: 0;
    background: transparent; border: none; box-shadow: none; padding: 2px 0 6px 12px;
  }
}

/* ---------- Developer quickstart (dashboard) ---------- */
/* Alpine sets the tab after boot; without this every pane paints at once. */
[x-cloak] { display: none !important; }

.qs {
  margin-top: 2.4rem;
  background: var(--surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 22px 24px 18px;
}
.qs-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.qs-title { margin: 0 0 .25rem; font-size: 1.15rem; }
.qs-sub { margin: 0; font-size: .9rem; }
.qs-guides { font-size: .88rem; white-space: nowrap; }

.qs-steps { list-style: none; margin: 18px 0 0; padding: 0; }
.qs-step { display: flex; gap: 14px; padding: 0 0 18px; }
.qs-step:last-child { padding-bottom: 6px; }
.qs-num {
  flex: none; width: 22px; height: 22px; margin-top: 1px;
  display: grid; place-items: center;
  border-radius: var(--radius-pill);
  background: var(--surface-2); border: 1px solid var(--line-soft);
  color: var(--ink-2); font-size: .78rem; font-variant-numeric: tabular-nums;
}
.qs-body { flex: 1; min-width: 0; }
.qs-step-title { margin: 0 0 .35rem; font-weight: 500; color: var(--ink); }
.qs-note { margin: .6rem 0 0; font-size: .86rem; }

.qs-tabs { display: flex; gap: 4px; margin: 0 0 8px; }
.qs-tab {
  padding: 4px 10px; font-size: .82rem; line-height: 1.6;
  background: transparent; color: var(--ink-2);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .15s var(--ease), color .15s var(--ease);
}
.qs-tab:hover { background: var(--hover-fill); color: var(--ink); }
.qs-tab.is-on { background: var(--surface-2); border-color: var(--line-soft); color: var(--ink); }

.qs-code { position: relative; }
.qs-code pre {
  margin: 0; padding: 14px 76px 14px 14px;
  background: var(--surface-2); border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  /* A full invoice body is ~25 lines pretty-printed; scroll it rather than let
     one card push the rest of the dashboard off the screen. */
  max-height: 320px; overflow: auto;
}
.qs-code code {
  background: none; border: none; padding: 0;
  font-family: var(--mono); font-size: .8rem; line-height: 1.55;
  color: var(--ink); white-space: pre;
}
.qs-copy {
  position: absolute; top: 8px; right: 8px;
  padding: 3px 10px; font-size: .76rem; line-height: 1.6;
  background: var(--surface); color: var(--ink-2);
  border: 1px solid var(--line); border-radius: var(--radius-sm);
  cursor: pointer; opacity: 0; transition: opacity .15s var(--ease);
}
.qs-code:hover .qs-copy, .qs-copy:focus-visible { opacity: 1; }
.qs-copy:hover { color: var(--ink); }

.qs-foot {
  display: flex; flex-wrap: wrap; gap: 16px;
  margin-top: 4px; padding-top: 14px;
  border-top: 1px solid var(--line-soft);
  font-size: .86rem;
}

@media (max-width: 640px) {
  .qs { padding: 18px 16px 14px; }
  .qs-head { flex-direction: column; gap: 6px; }
  /* Touch has no hover, so the button has to stay visible. */
  .qs-copy { opacity: 1; }
}

/* Flash-message copy button: a one-time "copy now or lose it" key, so it
   can't rely on hover-to-reveal like the quickstart snippets do. */
.flash-key { margin-top: 10px; }
.flash-key .qs-copy { opacity: 1; }
