/* ---------------------------------------------------------------------- *
 * Syntaxion Bookkeep — design system
 * Tokens mirror syntaxion.co.uk:
 *   light: #fff bg, #0a0a14 fg, #f7f7fb surface, #e63864 accent
 *   dark : #07070c bg, #f2f2f7 fg, #0f0f18 surface, #ff4f7e accent
 * Typography: Geist + Geist Mono (loaded in base.html).
 * ---------------------------------------------------------------------- */

:root {
  --background: #ffffff;
  --foreground: #0a0a14;
  --muted: #5a5a6e;
  --border: #e7e7ee;
  --border-strong: #d4d4dd;
  --surface: #f7f7fb;
  --accent: #e82853;
  --accent-hover: #cf1f48;
  --accent-soft: rgba(232, 40, 83, 0.08);

  --danger: #d1342f;
  --success: #138a5c;
  --warning: #b07300;

  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 999px;

  --shadow-sm: 0 1px 2px rgba(10, 10, 20, 0.04);
  --shadow-md: 0 4px 14px rgba(10, 10, 20, 0.06);

  --font-sans: "Geist", ui-sans-serif, system-ui, -apple-system,
               "Segoe UI", Roboto, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Menlo, Monaco,
               Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --background: #07070c;
    --foreground: #f2f2f7;
    --muted: #9a9ab0;
    --border: #1c1c2a;
    --border-strong: #2a2a3a;
    --surface: #0f0f18;
    --accent: #ff4f7e;
    --accent-hover: #ff6b91;
    --accent-soft: rgba(255, 79, 126, 0.12);
    --danger: #f6585a;
    --success: #4dc596;
    --warning: #e4ae3a;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html {
  margin: 0;
  padding: 0;
  min-height: 100%;
  color: var(--foreground);
  /* Ambient radial-gradient glow as a stacked background on html itself,
     attached so it stays put as the page scrolls. Putting the gradient on
     html instead of a ::before pseudo-element avoids z-index fights with
     the body's own background. */
  background:
    radial-gradient(circle at 8% -8%,
      var(--accent-soft), transparent 36%),
    radial-gradient(circle at 92% 105%,
      var(--accent-soft), transparent 42%),
    var(--background);
  background-attachment: fixed;
  background-repeat: no-repeat;
}

body {
  margin: 0;
  padding: 0;
  background: transparent;
  font: 15px/1.55 var(--font-sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- typography ---------- */

h1, h2, h3, h4 {
  margin: 0 0 12px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  color: var(--foreground);
}
h1 { font-size: 28px; font-weight: 700; }
h2 { font-size: 19px; font-weight: 600; }
h3 { font-size: 16px; font-weight: 600; }
p  { margin: 0 0 12px; }
p:last-child { margin-bottom: 0; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.mono  { font-family: var(--font-mono); font-size: 13px; }

/* ---------- top nav ---------- */

header.topnav {
  background: var(--background);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  gap: 28px;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(180%) blur(8px);
}
header.topnav h1 { display: none; }

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--foreground);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.02em;
  text-decoration: none;
}
.brand:hover { color: var(--foreground); text-decoration: none; }
.brand-logo {
  display: block;
  height: 22px;
  width: auto;
  /* Dark-mode safety: the logo paths are pink so they show on either bg */
}
.brand-sep    { color: var(--muted); font-weight: 400; align-self: center; }
.brand-product {
  color: var(--accent);
  font-weight: 600;
  align-self: center;
}

header.topnav nav { display: flex; gap: 2px; }
header.topnav nav a {
  display: inline-block;
  padding: 7px 12px;
  font-size: 14px;
  color: var(--muted);
  border-radius: var(--radius-md);
  text-decoration: none;
}
header.topnav nav a:hover {
  color: var(--foreground);
  background: var(--surface);
  text-decoration: none;
}

header.topnav .spacer { flex: 1; }
header.topnav .who {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

/* ---------- layout ---------- */

main {
  max-width: 1100px;
  margin: 40px auto 80px;
  padding: 0 28px;
}
main.narrow { max-width: 440px; margin-top: 80px; }

.page-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}
.page-header > h1,
.page-header > h2 { margin: 0; flex: 1; }

/* ---------- cards ---------- */

.card {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
}
.card > h2:first-child,
.card > h3:first-child { margin-top: 0; }

.card.empty {
  text-align: center;
  padding: 56px 24px;
  background: var(--surface);
  border-style: dashed;
}
.card.empty h2 { margin-top: 0; }
.card.empty p { color: var(--muted); }
.card.empty .btn { margin-top: 8px; }

.card.filters {
  padding: 16px 20px;
  background: var(--surface);
}

/* ---------- forms ---------- */

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
  font-weight: 500;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 14px;
  background: var(--background);
  color: var(--foreground);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="checkbox"] {
  width: auto;
  margin-right: 8px;
  accent-color: var(--accent);
}
textarea { resize: vertical; min-height: 80px; }

.form-row { margin-bottom: 16px; }
.form-row:last-of-type { margin-bottom: 20px; }
.form-row .small,
.form-row .muted { margin-top: 6px; }

/* ---------- buttons ---------- */

.btn, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  font: inherit;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.2;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: var(--radius-md);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, transform 0.05s;
  white-space: nowrap;
}
.btn:hover, button:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
  text-decoration: none;
}
.btn:active, button:active { transform: translateY(1px); }

.btn.ghost, button.ghost {
  background: transparent;
  color: var(--foreground);
  border-color: var(--border);
}
.btn.ghost:hover, button.ghost:hover {
  background: var(--surface);
  color: var(--foreground);
  border-color: var(--border-strong);
}

.btn.danger, button.danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.btn.danger:hover, button.danger:hover {
  background: var(--danger);
  filter: brightness(0.9);
}

.btn.small, button.small {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
}

/* ---------- sub-nav (left rail) ---------- */

/* The company sub-nav is a fixed left sidebar beneath the top nav. Pages
   that don't have a sub-nav (login, /companies, /users, dashboard) stay
   full-width — :has() handles the layout shift without per-template flags. */
:root {
  --sidebar-width: 220px;
  --sidebar-gutter: 36px;
  --topnav-height: 55px;
}

nav.subnav {
  position: fixed;
  top: var(--topnav-height);
  left: 0;
  bottom: 0;
  width: var(--sidebar-width);
  padding: 24px 12px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 5;
}
nav.subnav a {
  display: block;
  padding: 8px 14px;
  text-decoration: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  border-radius: var(--radius-md);
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
nav.subnav a:hover {
  background: color-mix(in oklab, var(--border) 40%, transparent);
  color: var(--foreground);
  text-decoration: none;
}
nav.subnav a.active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Shift main content right when the sidebar is present. */
main:has(nav.subnav) {
  padding-left: calc(var(--sidebar-width) + var(--sidebar-gutter));
  max-width: calc(1100px + var(--sidebar-width) + var(--sidebar-gutter));
}

/* Mobile / narrow: collapse to a horizontal scroll strip under the topnav. */
@media (max-width: 820px) {
  nav.subnav {
    position: static;
    flex-direction: row;
    width: auto;
    padding: 8px 16px;
    border-right: none;
    border-bottom: 1px solid var(--border);
    gap: 2px;
    overflow-x: auto;
    margin: 0 -28px 24px;
  }
  nav.subnav a { padding: 6px 12px; }
  main:has(nav.subnav) { padding-left: 28px; max-width: 100%; }
}

/* ---------- rows ---------- */

.row {
  display: flex;
  gap: 12px;
  align-items: flex-end;
}
.row > * { flex: 1; min-width: 0; }
.row > .shrink { flex: 0 0 auto; }

form.inline { display: inline; }

/* ---------- tables ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
thead th {
  text-align: left;
  padding: 10px 14px;
  font-weight: 500;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--surface); }

/* Table inside a card: lose double-border padding around the edges */
.card > table:only-child,
.card > h2 + table {
  margin: -1px;
}

/* ---------- metric tiles ---------- */

.card-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  margin-bottom: 24px;
}
.metric-card {
  display: block;
  padding: 22px 24px;
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  text-decoration: none;
  color: var(--foreground);
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
}
.metric-card:hover {
  border-color: var(--accent);
  color: var(--foreground);
  text-decoration: none;
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}
.metric-value {
  font-size: 32px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--foreground);
  font-variant-numeric: tabular-nums;
}
.metric-label {
  color: var(--muted);
  font-size: 13px;
  margin-top: 6px;
}

/* ---------- key/value layout ---------- */

dl.kv {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 10px 24px;
  margin: 0;
}
dl.kv dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}
dl.kv dd { margin: 0; font-size: 14px; }

/* ---------- banners ---------- */

.banner {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  border: 1px solid;
  font-size: 14px;
  line-height: 1.45;
}
.banner.ok {
  background: rgba(19, 138, 92, 0.06);
  border-color: rgba(19, 138, 92, 0.25);
  color: var(--success);
}
.banner.warn {
  background: rgba(176, 115, 0, 0.07);
  border-color: rgba(176, 115, 0, 0.3);
  color: var(--warning);
}
.banner.err {
  background: rgba(209, 52, 47, 0.07);
  border-color: rgba(209, 52, 47, 0.3);
  color: var(--danger);
}
@media (prefers-color-scheme: dark) {
  .banner.ok, .banner.warn, .banner.err { color: var(--foreground); }
}

/* ---------- tags / pills ---------- */

.tag {
  display: inline-block;
  padding: 2px 10px;
  border-radius: var(--radius-full);
  font-size: 12px;
  font-weight: 500;
  background: var(--surface);
  color: var(--muted);
  border: 1px solid var(--border);
  line-height: 1.5;
}
.tag.admin {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: rgba(230, 56, 100, 0.25);
}
.tag.disabled {
  background: rgba(209, 52, 47, 0.07);
  color: var(--danger);
  border-color: rgba(209, 52, 47, 0.25);
}

/* ---------- auth flow specifics ---------- */

.qr {
  display: flex;
  justify-content: center;
  margin: 16px 0;
}
.qr svg {
  width: 220px;
  height: 220px;
  background: #fff;
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.totp-input {
  font-family: var(--font-mono);
  font-size: 22px;
  letter-spacing: 8px;
  text-align: center;
  padding: 14px;
}

/* ---------- money / numeric ---------- */

.money-pos { color: var(--success); }
.money-neg { color: var(--danger); }

/* ---------- filter pills (invoices, bills lists) ---------- */

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.filter-pills .pill {
  display: inline-block;
  padding: 5px 12px;
  font-size: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--muted);
  background: var(--background);
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.filter-pills .pill:hover {
  color: var(--foreground);
  border-color: var(--border-strong);
  text-decoration: none;
}
.filter-pills .pill.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---------- reconcile rows ---------- */

.reconcile-row .reconcile-tx {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
}
.reconcile-candidate {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-top: 1px dashed var(--border);
}
.reconcile-candidate:first-of-type { border-top: none; }
.reconcile-actions {
  display: flex; gap: 8px;
  margin-top: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

/* ---------- VAT boxes table ---------- */

table.vat-boxes th {
  font-weight: 500;
  font-size: 14px;
  letter-spacing: 0;
  text-transform: none;
  color: var(--foreground);
  background: transparent;
}

/* ---------- pagination ---------- */

nav.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 16px 0 24px;
  gap: 16px;
  flex-wrap: wrap;
}
nav.pagination .pager {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
nav.pagination .btn.disabled,
nav.pagination .btn.ghost.disabled {
  opacity: 0.4;
  pointer-events: none;
  background: transparent;
  border-color: var(--border);
  color: var(--muted);
}
p.pagination-summary { margin: 12px 0 24px; }

/* ---------- danger zone (destructive admin) ---------- */

.card.danger-zone {
  border-color: rgba(209, 52, 47, 0.4);
  background: rgba(209, 52, 47, 0.03);
  margin-top: 40px;
}
.card.danger-zone h2 { color: var(--danger); margin-bottom: 8px; }

/* Ambient gradient now lives on `html` (see top of file) — keeps it
   underneath body content with no z-index/stacking pitfalls. */
