/* ============================================================
   PART 1. B8 widget, copied from design/q4-widget-B8.html.
   LOCKED. Do not change colours, type sizes, spacing or the glass
   recipe. The demo `body` rule from that file is left out.
   ============================================================ */

:root {
  /* Surface */
  --w-bg:        #15140F;
  --w-tint-a:    rgba(36,34,30,0.88);
  --w-tint-b:    rgba(18,17,15,0.74);
  --w-tint-c:    rgba(27,25,22,0.84);
  --w-glow-warm: #2A4643;   /* top-left radial */
  --w-glow-cool: #352B47;   /* bottom-right radial */

  /* Ink */
  --w-fg:     #FAF9F5;
  --w-muted:  rgba(250,249,245,0.60);
  --w-track:  rgba(255,255,255,0.12);

  /* Edges */
  --w-border: rgba(255,255,255,0.16);
  --w-radius: 22px;
}

.q4w {
  width: 364px;
  height: 170px;
  box-sizing: border-box;
  border-radius: var(--w-radius);
  background-color: var(--w-bg);
  background-image:
    linear-gradient(135deg, var(--w-tint-a) 0%, var(--w-tint-b) 48%, var(--w-tint-c) 100%),
    radial-gradient(85% 130% at 6% -10%, var(--w-glow-warm) 0%, rgba(42,70,67,0) 58%),
    radial-gradient(80% 120% at 104% 110%, var(--w-glow-cool) 0%, rgba(53,43,71,0) 60%);
  -webkit-backdrop-filter: blur(28px) saturate(170%);
  backdrop-filter: blur(28px) saturate(170%);
  border: 1px solid var(--w-border);
  box-shadow:
    0 14px 36px rgba(0,0,0,0.40),
    inset 0 1px 0 rgba(255,255,255,0.18),
    inset 0 -1px 0 rgba(0,0,0,0.35);
  color: var(--w-fg);
  font-family: Inter, system-ui, sans-serif;
  font-variant-numeric: tabular-nums;
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.q4w-head   { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.q4w-kicker { font-size: 9.5px; letter-spacing: 0.09em; text-transform: uppercase; color: var(--w-muted); font-weight: 500; }
.q4w-hero   { font-family: 'Instrument Serif', Georgia, serif; font-size: 46px; line-height: 1; letter-spacing: -0.02em; margin-top: 6px; }
.q4w-days   { text-align: right; flex: none; }
.q4w-dnum   { font-family: 'Instrument Serif', Georgia, serif; font-size: 40px; line-height: 1; letter-spacing: -0.015em; }
.q4w-dlab   { font-size: 9.5px; color: var(--w-muted); margin-top: 5px; line-height: 1.3; }

.q4w-track  { height: 4px; border-radius: 999px; background: var(--w-track); overflow: hidden; }
.q4w-fill   { height: 100%; background: var(--w-fg); border-radius: 999px; }
.q4w-foot   { font-size: 10px; color: var(--w-muted); margin-top: 9px; }
.q4w-pct    { color: var(--w-fg); font-weight: 500; }

/* Only addition to the widget: never wider than a phone screen. */
.q4w { max-width: 100%; }
.q4w-fill { width: 0; }


/* ============================================================
   PART 2. Dashboard. Extends the B8 palette for page, table and
   form. Nothing here touches the widget above.
   ============================================================ */

:root {
  --d-page:    #0E0D0B;
  --d-panel:   rgba(255,255,255,0.035);
  --d-line:    rgba(255,255,255,0.08);
  --d-faint:   rgba(250,249,245,0.38);
  --d-input:   rgba(255,255,255,0.06);
  --d-warn:    #F0A07A;
  --d-warn-bg: rgba(240,160,122,0.08);
}

*, *::before, *::after { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--d-page);
  background-image:
    radial-gradient(60% 50% at 0% 0%, rgba(42,70,67,0.35) 0%, rgba(42,70,67,0) 70%),
    radial-gradient(50% 50% at 100% 100%, rgba(53,43,71,0.30) 0%, rgba(53,43,71,0) 70%);
  background-attachment: fixed;
  color: var(--w-fg);
  font-family: Inter, system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.panel {
  background: var(--d-panel);
  border: 1px solid var(--d-line);
  border-radius: var(--w-radius);
}

/* ---------- Buttons and inputs ---------- */

.btn {
  font: inherit; font-size: 13px; font-weight: 500;
  color: var(--w-fg);
  background: var(--d-input);
  border: 1px solid var(--w-border);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
}
.btn:hover { background: rgba(255,255,255,0.1); }
.btn-primary { background: var(--w-fg); color: var(--w-bg); border-color: var(--w-fg); }
.btn-primary:hover { background: #fff; }
.btn-danger { color: var(--d-warn); border-color: rgba(240,160,122,0.4); background: transparent; }
.btn-danger:hover { background: var(--d-warn-bg); }
.btn:disabled { opacity: 0.5; cursor: progress; }

.btn-link {
  font: inherit; font-size: 12px; color: var(--w-muted);
  background: none; border: 0; padding: 4px 0; cursor: pointer;
}
.btn-link:hover { color: var(--w-fg); }

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--w-muted); font-weight: 500; }
.field .hint { font-size: 11px; color: var(--d-faint); }
.field input, .field select, .field textarea {
  font: inherit; font-size: 14px; color: var(--w-fg);
  background: var(--d-input);
  border: 1px solid var(--d-line);
  border-radius: 10px;
  padding: 9px 11px;
  width: 100%;
}
.field textarea { resize: vertical; min-height: 64px; }
.field input:focus, .field select:focus, .field textarea:focus,
.btn:focus-visible, .btn-link:focus-visible, .sort:focus-visible {
  outline: 2px solid rgba(250,249,245,0.5); outline-offset: 2px;
}
.field input:disabled { color: var(--w-muted); }
.field .err { font-size: 11px; color: var(--d-warn); min-height: 0; }
.field.has-error input, .field.has-error select { border-color: var(--d-warn); }

.form-error { color: var(--d-warn); font-size: 13px; margin: 0; min-height: 1.2em; }

/* ---------- Login ---------- */

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: 100%; max-width: 340px; padding: 28px; display: flex; flex-direction: column; gap: 18px; }

/* ---------- Layout ---------- */

.app { max-width: 1180px; margin: 0 auto; padding: 20px 16px 40px; }
@media (min-width: 720px) { .app { padding: 28px 32px 48px; } }

.topbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }

.banner {
  margin: 0 0 16px; padding: 10px 14px; border-radius: 12px;
  background: var(--d-warn-bg); color: var(--d-warn); border: 1px solid rgba(240,160,122,0.3);
}

.top { display: flex; flex-wrap: wrap; gap: 20px; align-items: stretch; margin-bottom: 32px; }
.top .q4w { flex: none; }

/* ---------- Tier summary ---------- */

.summary {
  flex: 1 1 320px; margin: 0; padding: 18px 22px;
  display: grid; grid-template-columns: 1fr auto; column-gap: 24px; row-gap: 7px;
  align-content: center;
}
.summary dt { color: var(--w-muted); font-size: 13px; }
.summary dd { margin: 0; text-align: right; font-size: 13px; font-weight: 500; white-space: nowrap; }
.summary .rule { grid-column: 1 / -1; height: 1px; background: var(--d-line); margin: 4px 0; }
.summary .strong dt { color: var(--w-fg); font-weight: 500; }
.summary .strong dd { font-family: 'Instrument Serif', Georgia, serif; font-size: 22px; font-weight: 400; line-height: 1.1; }
.summary .dim dt, .summary .dim dd { color: var(--d-faint); }
.summary .sub { color: var(--d-faint); font-weight: 400; margin-left: 6px; }
.summary .warn dt, .summary .warn dd { color: var(--d-warn); }
.summary > div { display: contents; }

/* ---------- Ledger table ---------- */

.ledger-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.ledger-head h2 { font-family: 'Instrument Serif', Georgia, serif; font-weight: 400; font-size: 28px; margin: 0; letter-spacing: -0.01em; }

.table-wrap { overflow-x: auto; border: 1px solid var(--d-line); border-radius: 16px; background: var(--d-panel); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  text-align: left; font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--w-muted); font-weight: 500; padding: 12px 12px; border-bottom: 1px solid var(--d-line);
  white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--d-line); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; white-space: nowrap; }
.table .client { font-weight: 500; white-space: nowrap; }
.table .muted { color: var(--w-muted); }
.table .note { color: var(--w-muted); font-size: 12px; min-width: 220px; max-width: 340px; }
.table .nowrap { white-space: nowrap; }

.sort {
  font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit;
  background: none; border: 0; padding: 0; cursor: pointer;
}
.sort:hover { color: var(--w-fg); }
.sort[aria-sort="ascending"]::after  { content: " ↑"; }
.sort[aria-sort="descending"]::after { content: " ↓"; }

/* Status: one tone, told apart by the dot, not by colour. */
.status { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.status::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%; flex: none;
  border: 1.5px solid var(--w-fg);
}
.status-Paid::before        { background: var(--w-fg); }
.status-Unpaid::before      { background: var(--w-muted); border-color: var(--w-muted); }
.status-Estimate::before    { background: transparent; }
.status-Unconfirmed::before { background: transparent; border-style: dashed; border-color: var(--d-faint); }
.status-Unconfirmed         { color: var(--d-faint); }

tr.is-overdue td { background: var(--d-warn-bg); }
tr.is-overdue td:first-child { box-shadow: inset 3px 0 0 var(--d-warn); }
.overdue-tag { display: block; color: var(--d-warn); font-size: 11px; font-weight: 500; }

/* ---------- Row form ---------- */

.row-form {
  padding: 18px;
  display: grid; gap: 14px;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
}
.row-form .wide { grid-column: 1 / -1; }
.row-form .actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row-form .actions .spacer { flex: 1; }
#add-slot .row-form { margin-bottom: 16px; }
.table td.edit-cell { padding: 0; background: rgba(255,255,255,0.03); }

/* ---------- Footer ---------- */

.foot {
  margin-top: 28px; display: flex; flex-wrap: wrap; gap: 6px 22px;
  font-size: 12px; color: var(--w-muted);
}
.foot .dim { color: var(--d-faint); }
