/* VeriSmart shared look: teal light and dark, for VeriSmart Books.
   The palettes and chip colours are exactly those in the "Shared look" section of VeriSmart-Server-Plan.md.
   Every colour on the Books pages is one of the variables below. tests/test_books_theme.py fails if a palette
   drifts from the plan, if a colour is hard-coded anywhere else, or if a text-on-colour pair drops below
   WCAG AA (4.5:1). */

:root {
  color-scheme: light;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --radius: 12px;

  /* Light palette (the default) */
  --bg: #f6f9f9;
  --card: #ffffff;
  --line: #dce6e6;
  --text: #12262b;
  --muted: #566d72;
  --accent: #0f6e68;
  --good: #167a52;
  --bad: #a33a2a;
  --warning: #9a5b12;

  /* Tints and hover shades made from the palette */
  --surface: #edf3f3;
  --field: #fbfdfd;
  --field-line: #9fb3b5;
  --accent-soft: #e4f1ef;
  --accent-hover: #0b5a55;
  --bad-soft: #f9eae7;
  --good-soft: #e3f2ea;
  --shadow: #12262b14;

  /* Solid status chips, the same in both themes */
  --chip-green: #1f7f51;
  --chip-green-text: #f2f7f4;
  --chip-red: #a83c28;
  --chip-red-text: #fdeeea;
  --chip-amber: #b9891f;
  --chip-amber-text: #1d1405;
  --chip-orange: #cf6a3c;
  --chip-orange-text: #2b1207;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0d1618;
  --card: #141f22;
  --line: #253538;
  --text: #e2ecec;
  --muted: #9aacb0;
  --accent: #5bc4b8;
  --good: #5fbf94;
  --bad: #e08573;
  --warning: #d9a05b;
  --surface: #1b282b;
  --field: #101b1d;
  --field-line: #46595d;
  --accent-soft: #132b2a;
  --accent-hover: #7fd3c9;
  --bad-soft: #2b1916;
  --good-soft: #14271f;
  --shadow: #00000066;
}

/* Without JavaScript, follow the device setting. Keep identical to the dark block above (a test checks). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0d1618;
    --card: #141f22;
    --line: #253538;
    --text: #e2ecec;
    --muted: #9aacb0;
    --accent: #5bc4b8;
    --good: #5fbf94;
    --bad: #e08573;
    --warning: #d9a05b;
    --surface: #1b282b;
    --field: #101b1d;
    --field-line: #46595d;
    --accent-soft: #132b2a;
    --accent-hover: #7fd3c9;
    --bad-soft: #2b1916;
    --good-soft: #14271f;
    --shadow: #00000066;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 var(--font);
  color: var(--text);
  background: var(--bg);
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
code { font-size: 0.9em; }

h1 { margin: 0; font-size: 1.5rem; line-height: 1.25; }
h2 { margin: 0; font-size: 1.1rem; line-height: 1.3; }
.muted { margin: 0; color: var(--muted); }
.secondary-text { color: var(--muted); }
.nowrap { white-space: nowrap; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

.wrap { max-width: 1100px; margin: 0 auto; padding-inline: 16px; }
main { padding-block: 24px 48px; }

/* Top bar */
.topbar { background: var(--card); border-bottom: 1px solid var(--line); }
.topbar-row { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; padding-block: 12px; }
.brand { color: var(--text); font-size: 1.15rem; font-weight: 700; letter-spacing: -0.01em; text-decoration: none; }
.brand:hover { color: var(--text); }
.brand span { color: var(--accent); }
.topbar-tools { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.topbar-tools form { margin: 0; }

/* Light / System / Dark switch. The head script marks the saved choice before paint; books.js sets aria-pressed. */
.theme-switch { display: inline-flex; gap: 2px; padding: 3px; border: 1px solid var(--line); border-radius: 999px; background: var(--card); }
.theme-switch button { padding: 4px 12px; font-size: 0.8rem; font-weight: 600; color: var(--muted); background: transparent; border-radius: 999px; }
.theme-switch button:hover { color: var(--text); background: var(--surface); }
.theme-switch button[aria-pressed="true"],
:root[data-theme-choice="light"] .theme-switch [data-set-theme="light"],
:root[data-theme-choice="system"] .theme-switch [data-set-theme="system"],
:root[data-theme-choice="dark"] .theme-switch [data-set-theme="dark"] { color: var(--bg); background: var(--accent); }

/* Tooltips: teal accent with page-background text, drawn by books.js (never the browser's title tooltip) */
.tip {
  position: fixed;
  z-index: 1000;
  max-width: min(320px, calc(100vw - 16px));
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--bg);
  background: var(--accent);
  font: 500 0.85rem/1.4 var(--font);
  white-space: pre-wrap;
  box-shadow: 0 2px 8px var(--shadow);
  pointer-events: none;
}

/* Page layout */
.page-head { margin-bottom: 20px; }
.page-head .muted { margin-top: 4px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px var(--shadow);
}
.card + .card { margin-top: 20px; }
.card-head { display: flex; flex-wrap: wrap; gap: 12px 16px; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.card-head .muted { margin-top: 2px; font-size: 0.875rem; }
.card-body { padding: 24px; }
.card-foot { padding: 10px 20px; border-top: 1px solid var(--line); font-size: 0.85rem; }
.stack > * + * { margin-top: 16px; }

.notice { margin: 0 0 20px; padding: 10px 14px; border-radius: 8px; color: var(--text); background: var(--accent-soft); }
.alert { margin: 0 0 20px; padding: 10px 14px; border-radius: 8px; font-weight: 500; }
.alert-good { color: var(--good); background: var(--good-soft); }
.alert-bad { color: var(--bad); background: var(--bad-soft); }

/* Forms */
label { display: block; margin-bottom: 6px; font-weight: 600; font-size: 0.9rem; }
input[type=password], input[type=date] {
  padding: 8px 10px;
  font: inherit;
  color: var(--text);
  background: var(--field);
  border: 1px solid var(--field-line);
  border-radius: 6px;
}
input:focus { outline: 3px solid color-mix(in srgb, var(--accent) 25%, transparent); border-color: var(--accent); }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 0; }
.inline-form label { margin: 0; }
.login { max-width: 420px; margin: 32px auto 0; }
.login input { width: 100%; }

/* Buttons: primary is the teal accent with page-background text */
button, .button {
  display: inline-block;
  padding: 8px 18px;
  font: inherit;
  font-weight: 600;
  color: var(--bg);
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
button:hover, .button:hover { color: var(--bg); background: var(--accent-hover); }
button:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 2px; }
button.secondary { color: var(--text); background: var(--surface); box-shadow: inset 0 0 0 1px var(--line); }
button.secondary:hover { color: var(--text); background: var(--line); }
button.link { padding: 6px 4px; color: var(--accent); background: none; }
button.link:hover { color: var(--accent-hover); background: none; text-decoration: underline; }
button.small { padding: 4px 12px; font-size: 0.85rem; }

/* Tables */
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { padding: 9px 16px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); background: var(--surface); font-size: 0.75rem; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tfoot td { font-weight: 700; border-top: 2px solid var(--line); border-bottom: 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.num-left { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.actions { width: 1%; text-align: right; }
td.actions form { margin: 0; }
.empty { margin: 0; padding: 28px 20px; text-align: center; color: var(--muted); }

/* Status chips */
.chip { display: inline-block; margin-left: 4px; padding: 1px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; line-height: 1.6; white-space: nowrap; vertical-align: middle; }
td > .chip:first-child { margin-left: 0; }
.chip-green { color: var(--chip-green-text); background: var(--chip-green); }
.chip-red { color: var(--chip-red-text); background: var(--chip-red); }
.chip-amber { color: var(--chip-amber-text); background: var(--chip-amber); }
.chip-orange { color: var(--chip-orange-text); background: var(--chip-orange); }

@media (max-width: 640px) {
  .card-head, .card-body { padding: 14px; }
  th, td { padding: 8px 10px; }
}

/* books.js switches to the light colours while printing. */
@media print {
  .topbar-tools, .tip, td.actions, .notice { display: none; }
  .card { box-shadow: none; }
}
