:root {
  --gold: #7f6d40;
  --gold-soft: #a8955f;
  --teal: #7fc4dc;
  --cream: #fffbea;
  --bg: #161614;
  --surface: #1f1f1c;
  --surface-2: #282824;
  --ink: #f4f1e6;
  --muted: #a7a291;
  --line: #3a3832;
  --danger: #e0786b;
  --ok: #7fc99a;
  --warn: #e7c06b;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: var(--cream);
  --surface: #ffffff;
  --surface-2: #f6f1df;
  --ink: #1f1f1f;
  --muted: #6d6857;
  --line: #e4dcc3;
  --danger: #b4483b;
  --ok: #2f7d4d;
  --warn: #9a6d12;
  --shadow: 0 10px 30px rgba(60, 50, 20, .12);
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 14px/1.5 Poppins, system-ui, sans-serif; }
h1, h2, h3 { font-family: Besley, Georgia, serif; font-weight: 700; margin: 0; line-height: 1.2; }
h1 { font-size: 28px; }
h2 { font-size: 19px; }
h3 { font-size: 15px; }
a { color: var(--teal); }
button, input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.right { text-align: right; }
.num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.hidden { display: none !important; }
.nw { white-space: nowrap; }
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }

/* Layout */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side { border-right: 2px solid var(--line); padding: 22px 16px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { font-family: Besley, Georgia, serif; font-size: 24px; font-weight: 700; padding: 0 10px 2px; }
.brand-sub { padding: 0 10px 18px; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; text-decoration: none; color: var(--ink); border: 2px solid transparent; }
.nav a:hover { background: var(--surface-2); }
.nav a.on { border-color: var(--gold); background: var(--surface); }
.nav .soon { font-size: 10px; color: var(--muted); margin-left: auto; }
.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 0 4px; }
.main { padding: 28px 34px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 14px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head .grow { flex: 1; }

/* Cards and forms */
.card { background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); padding: 20px; }
.card + .card { margin-top: 16px; }
.card h2 { margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
label.f { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 500; }
label.f > span { letter-spacing: .02em; }
input[type=text], input[type=email], input[type=number], input[type=date], input[type=search], select, textarea {
  width: 100%; background: var(--bg); border: 2px solid var(--line); border-radius: 8px; padding: 8px 10px; color: var(--ink); font-size: 14px;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold); }
input:disabled, select:disabled { opacity: .55; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; color: var(--ink); }
.check input { width: 16px; height: 16px; accent-color: var(--gold); }
.hint { font-size: 12px; color: var(--muted); }
.hint.warn { color: var(--warn); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 9px 16px; border-radius: 8px; border: 2px solid var(--gold); background: transparent; color: var(--ink); cursor: pointer; font-weight: 600; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--gold); color: #fff; }
.btn.primary:hover { background: var(--gold-soft); border-color: var(--gold-soft); }
.btn.ghost { border-color: var(--line); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px 6px; border-radius: 6px; font-size: 16px; line-height: 1; }
.icon-btn:hover { color: var(--danger); background: var(--surface-2); }

/* Tables */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 2px solid var(--line); }
table.list td { padding: 11px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr.click { cursor: pointer; }
table.list tr.click:hover td { background: var(--surface-2); }
.empty { padding: 40px 10px; text-align: center; color: var(--muted); }

.pill { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 11px; font-weight: 600; letter-spacing: .03em; border: 1.5px solid currentColor; }
.pill.draft { color: var(--muted); }
.pill.sent { color: var(--teal); }
.pill.overdue { color: var(--danger); }
.pill.paid { color: var(--ok); }
.pill.void { color: var(--muted); text-decoration: line-through; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tabs button { border: 2px solid var(--line); background: none; padding: 6px 14px; border-radius: 99px; cursor: pointer; color: var(--muted); font-weight: 500; }
.tabs button.on { border-color: var(--gold); color: var(--ink); background: var(--surface); }

.stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); }
.stat .v { font-family: Besley, Georgia, serif; font-size: 22px; font-weight: 700; margin-top: 4px; }
.stat .v small { font-family: Poppins, sans-serif; font-size: 12px; color: var(--muted); font-weight: 500; display: block; }

/* Invoice editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 18px; align-items: start; }
.aside { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 14px; }
.aside .btn { width: 100%; }
.lines { width: 100%; border-collapse: collapse; }
.lines th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); text-align: left; padding: 6px 6px; border-bottom: 2px solid var(--line); font-weight: 600; }
.lines td { padding: 8px 6px; vertical-align: top; border-bottom: 1px solid var(--line); }
.lines textarea { min-height: 40px; }
.lines .q { width: 78px; }
.lines .u { width: 120px; }
.lines .a { width: 120px; padding-top: 16px; }
.lines .t { width: 46px; text-align: center; padding-top: 16px; }
.lines .x { width: 32px; padding-top: 12px; }
.lines .flag { font-size: 11px; color: var(--warn); display: block; margin-top: 3px; }
.line-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; align-items: center; }
.line-actions select { width: auto; min-width: 220px; }
.totals { margin-left: auto; width: min(340px, 100%); margin-top: 16px; }
.totals div { display: flex; justify-content: space-between; padding: 5px 0; }
.totals .grand { border-top: 2px solid var(--gold); margin-top: 6px; padding-top: 10px; font-weight: 700; font-size: 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 2px solid var(--line); border-radius: 99px; padding: 4px 11px; font-size: 12px; cursor: pointer; user-select: none; color: var(--muted); }
.chip.on { border-color: var(--gold); color: var(--ink); background: var(--surface-2); }
.brandbar { height: 6px; border-radius: 6px 6px 0 0; margin: -20px -20px 16px; }
.timeline { list-style: none; margin: 0; padding: 0; font-size: 12px; }
.timeline li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 10px; }
.timeline li:last-child { border-bottom: 0; }
.status-row { display: flex; align-items: center; justify-content: space-between; }
.balance { font-family: Besley, Georgia, serif; font-size: 26px; font-weight: 700; }

/* Business cards */
.biz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.biz { cursor: pointer; transition: border-color .15s; }
.biz:hover { border-color: var(--gold); }
.biz .logo { height: 48px; display: flex; align-items: center; margin-bottom: 12px; }
.biz .logo img { max-height: 48px; max-width: 180px; }
.biz .swatches { display: flex; gap: 6px; margin-top: 10px; }
.biz .swatches span { width: 22px; height: 22px; border-radius: 6px; border: 1px solid var(--line); }
.logo-drop { border: 2px dashed var(--line); border-radius: 8px; padding: 14px; display: flex; align-items: center; gap: 14px; background: var(--bg); }
.logo-drop img { max-height: 56px; max-width: 200px; background: #fff; padding: 6px; border-radius: 6px; }
.colour { display: flex; gap: 8px; align-items: center; }
.colour input[type=color] { width: 42px; height: 38px; border: 2px solid var(--line); border-radius: 8px; background: none; padding: 2px; cursor: pointer; }
.preview-head { background: #fff; color: #1f1f1f; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); }
.preview-head .bar { height: 6px; }
.preview-head .in { padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.preview-head .t { font-family: Helvetica, Arial, sans-serif; font-weight: 700; font-size: 15px; }
.preview-head .row { color: #fff; font: 700 10px Helvetica, Arial, sans-serif; letter-spacing: .05em; padding: 6px 16px; }
code.k { background: var(--surface-2); border: 1px solid var(--line); padding: 1px 6px; border-radius: 5px; font-size: 12px; word-break: break-all; }

/* Modal + toast */
.modal-bg { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow: auto; }
.modal { width: min(560px, 100%); background: var(--surface); border: 2px solid var(--gold); border-radius: 12px; box-shadow: var(--shadow); padding: 22px; }
.modal h2 { margin-bottom: 16px; }
.modal .foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--surface); border: 2px solid var(--gold); padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow); z-index: 60; max-width: 90vw; }
.toast.err { border-color: var(--danger); }

/* Login */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login .card { width: min(400px, 100%); padding: 32px; }
.login h1 { margin-bottom: 6px; }

@media (max-width: 1000px) {
  .editor { grid-template-columns: minmax(0, 1fr); }
  .aside { position: static; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 2px solid var(--line); padding: 12px; }
  .brand-sub { display: none; }
  .brand { padding: 0 8px 0 4px; font-size: 20px; }
  .nav { display: flex; gap: 4px; flex-wrap: wrap; }
  .nav a { padding: 6px 9px; }
  .nav .soon { display: none; }
  .side-foot { margin: 0 0 0 auto; flex-direction: row; }
  .main { padding: 20px 14px 60px; }
  .g2, .g3, .g4, .stats { grid-template-columns: minmax(0, 1fr); }
  .lines thead { display: none; }
  .lines tr { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
  .lines td { border: 0; padding: 0; width: auto !important; }
  .lines td.d { grid-column: 1 / -1; }
  .lines .a, .lines .t, .lines .x { padding-top: 8px; }
  .hide-sm { display: none; }
  table.list td, table.list th { padding: 10px 6px; }
}
