/* Ledger — consultancy invoicing. One stylesheet, no framework.
   Light by default, dark when the device asks or the user picks it. */

:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --panel-2: #fbfbfd;
  --ink: #16202c;
  --ink-soft: #3c4857;
  --muted: #6b7685;
  --faint: #9aa3b0;
  --rule: #e4e8ee;
  --rule-strong: #d2d8e1;
  --accent: #1f6feb;
  --accent-ink: #ffffff;
  --accent-wash: #eaf1fe;
  --ok: #157f4b;
  --ok-wash: #e6f6ed;
  --warn: #946200;
  --warn-wash: #fdf3dd;
  --bad: #b3261e;
  --bad-wash: #fdeceb;
  --shadow: 0 1px 2px rgba(16, 28, 44, .05), 0 8px 24px -14px rgba(16, 28, 44, .18);
  --radius: 12px;
  --radius-sm: 8px;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1319;
    --panel: #151b23;
    --panel-2: #1a222c;
    --ink: #e8edf3;
    --ink-soft: #c3ccd7;
    --muted: #94a0ae;
    --faint: #6f7d8c;
    --rule: #242e3a;
    --rule-strong: #303d4c;
    --accent-wash: #16263f;
    --ok: #4ac98a;
    --ok-wash: #11291e;
    --warn: #e0ad4a;
    --warn-wash: #2b2212;
    --bad: #f28b82;
    --bad-wash: #2c1818;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -16px rgba(0, 0, 0, .7);
  }
}

:root[data-theme="dark"] {
  --bg: #0e1319;
  --panel: #151b23;
  --panel-2: #1a222c;
  --ink: #e8edf3;
  --ink-soft: #c3ccd7;
  --muted: #94a0ae;
  --faint: #6f7d8c;
  --rule: #242e3a;
  --rule-strong: #303d4c;
  --accent-wash: #16263f;
  --ok: #4ac98a;
  --ok-wash: #11291e;
  --warn: #e0ad4a;
  --warn-wash: #2b2212;
  --bad: #f28b82;
  --bad-wash: #2c1818;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 10px 30px -16px rgba(0, 0, 0, .7);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -.016em; line-height: 1.25; }
h1 { font-size: 23px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; }

/* ------------------------------------------------------------------ shell */

.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }

.side {
  background: var(--panel);
  border-right: 1px solid var(--rule);
  padding: 20px 14px 28px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px 0; }
.brand img { width: 34px; height: 34px; border-radius: 9px; display: block; }
.brand b { font-size: 14.5px; font-weight: 650; letter-spacing: -.01em; display: block; }
.brand span { font-size: 11.5px; color: var(--muted); display: block; }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: var(--radius-sm);
  color: var(--ink-soft); font-size: 14px; font-weight: 500;
}
.nav a:hover { background: var(--panel-2); text-decoration: none; color: var(--ink); }
.nav a[aria-current="page"] { background: var(--accent-wash); color: var(--accent); font-weight: 600; }
.nav a svg { width: 17px; height: 17px; flex: none; opacity: .85; }
.nav .count { margin-left: auto; font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }

.side-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; font-size: 12.5px; color: var(--muted); }
.side-foot a { color: var(--muted); }

.main { min-width: 0; padding: 26px 30px 72px; }
.main > header { display: flex; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.main > header .grow { flex: 1; min-width: 200px; }
.main > header p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }

/* ----------------------------------------------------------------- pieces */

.panel {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel > h2, .panel > .panel-head {
  padding: 15px 18px; border-bottom: 1px solid var(--rule);
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.panel-head .grow { flex: 1; }
.panel-body { padding: 18px; }
.panel + .panel { margin-top: 18px; }

.grid { display: grid; gap: 16px; }
.grid.k2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.sidebar-right { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }

.stat { padding: 16px 18px; }
.stat .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.stat .value { font-size: 25px; font-weight: 660; letter-spacing: -.02em; margin-top: 7px; font-variant-numeric: tabular-nums; }
.stat .note { font-size: 12.5px; color: var(--muted); margin-top: 4px; }
.stat .value.bad { color: var(--bad); }
.stat .value.ok { color: var(--ok); }

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

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .055em;
  color: var(--muted); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--rule);
  white-space: nowrap; background: var(--panel-2);
}
td { padding: 12px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--panel-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: var(--mono); font-size: 13px; }
.wrap-table { overflow-x: auto; }
td .sub { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.row-link { color: var(--ink); font-weight: 560; }

.empty { padding: 44px 20px; text-align: center; color: var(--muted); }
.empty h3 { color: var(--ink); margin-bottom: 6px; }

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

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 620; letter-spacing: .01em;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--rule);
  white-space: nowrap;
}
.pill.ok { background: var(--ok-wash); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-wash); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-wash); color: var(--bad); border-color: transparent; }
.pill.info { background: var(--accent-wash); color: var(--accent); border-color: transparent; }
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid var(--rule-strong); background: var(--panel); color: var(--ink);
  font: inherit; font-size: 14px; font-weight: 560; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); text-decoration: none; }
.btn:active { transform: translateY(.5px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); background: var(--accent); }
.btn.danger { color: var(--bad); border-color: var(--rule-strong); }
.btn.danger:hover { background: var(--bad-wash); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--panel-2); }
.btn.sm { padding: 6px 11px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }
.btns { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

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

label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-soft); margin-bottom: 5px; }
label .hint { font-weight: 400; color: var(--muted); }

/* Match every text-like input, including those written without a type
   attribute — an attribute selector would silently skip those. */
input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=submit]),
select, textarea {
  width: 100%; padding: 9px 11px; font: inherit; font-size: 14px;
  color: var(--ink); background: var(--panel);
  border: 1px solid var(--rule-strong); border-radius: var(--radius-sm);
  appearance: none;
}
textarea { min-height: 84px; resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: 1px; border-color: var(--accent);
}
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 54%, calc(100% - 12px) 54%;
  background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; padding-right: 30px;
}
.field { margin-bottom: 14px; }
.field.row { display: flex; align-items: center; gap: 9px; }
.field.row label { margin: 0; font-weight: 500; font-size: 14px; color: var(--ink); }
.fields { display: grid; gap: 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fields .wide { grid-column: 1 / -1; }
.help { font-size: 12.5px; color: var(--muted); margin: 5px 0 0; }
fieldset { border: 0; padding: 0; margin: 0 0 22px; }
fieldset > legend { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 0 0 12px; }

/* --------------------------------------------------------------- messages */

.flash {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-sm); margin-bottom: 18px;
  font-size: 14px; border: 1px solid transparent;
}
.flash.ok { background: var(--ok-wash); color: var(--ok); }
.flash.bad { background: var(--bad-wash); color: var(--bad); }
.flash.info { background: var(--accent-wash); color: var(--accent); }

/* ------------------------------------------------------------ line editor */

.lines { width: 100%; border-collapse: collapse; }
.lines th { background: transparent; border-bottom: 1px solid var(--rule); }
.lines td { padding: 7px 6px; border-bottom: 1px solid var(--rule); vertical-align: top; }
.lines td:first-child, .lines th:first-child { padding-left: 0; }
.lines td:last-child, .lines th:last-child { padding-right: 0; }
.lines input, .lines select { padding: 7px 9px; font-size: 13.5px; }
.lines .drag { color: var(--faint); cursor: grab; width: 18px; text-align: center; user-select: none; }
.lines tr.dragging { opacity: .4; }
.lines .line-total { font-variant-numeric: tabular-nums; font-weight: 600; padding-top: 14px; display: block; text-align: right; }
.lines .detail-input { margin-top: 6px; font-size: 12.5px; }
.lines .kill { color: var(--faint); border: 0; background: transparent; cursor: pointer; padding: 6px; border-radius: 6px; font-size: 16px; line-height: 1; }
.lines .kill:hover { color: var(--bad); background: var(--bad-wash); }

.totals-box { display: flex; flex-direction: column; gap: 9px; font-size: 14px; }
.totals-box .row { display: flex; justify-content: space-between; gap: 14px; }
.totals-box .row span:last-child { font-variant-numeric: tabular-nums; }
.totals-box .row.grand {
  border-top: 1px solid var(--rule); padding-top: 11px; margin-top: 3px;
  font-size: 19px; font-weight: 660; letter-spacing: -.02em;
}
.totals-box .row.muted { color: var(--muted); }

/* --------------------------------------------------------------- timeline */

.timeline { list-style: none; margin: 0; padding: 0; font-size: 13.5px; }
.timeline li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--rule); }
.timeline li:last-child { border-bottom: 0; }
.timeline time { color: var(--muted); white-space: nowrap; font-size: 12.5px; min-width: 96px; }

/* ----------------------------------------------------------------- public */

.paper {
  max-width: 820px; margin: 28px auto 64px; background: var(--panel);
  border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 44px 48px;
}
.paper .letterhead { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; }
.paper .letterhead img { height: 54px; width: auto; }
.paper .doc-title { text-align: right; }
.paper .doc-title .kind { font-size: 21px; font-weight: 680; color: var(--accent); letter-spacing: -.02em; }
.paper .doc-title .no { font-size: 15px; font-weight: 640; margin-top: 2px; }
.paper .meta { margin-top: 12px; font-size: 13px; color: var(--muted); }
.paper .meta b { color: var(--ink); font-weight: 600; }
.paper hr { border: 0; border-top: 1px solid var(--rule); margin: 26px 0; }
.paper .small { font-size: 13px; color: var(--muted); }
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--panel);
  border-bottom: 1px solid var(--rule); padding: 11px 18px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
}
.topbar .grow { flex: 1; min-width: 120px; }
.accept-box { background: var(--panel-2); border: 1px solid var(--rule); border-radius: var(--radius); padding: 20px; margin-top: 26px; }

/* -------------------------------------------------------------- login/2fa */

.gate { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.gate .card { width: 100%; max-width: 384px; }
.gate .card .panel-body { padding: 26px; }
.gate .mark { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 22px; }
.gate .mark img { width: 56px; height: 56px; border-radius: 14px; }
.gate .mark b { font-size: 16px; }
.code-input {
  font-family: var(--mono); font-size: 24px; letter-spacing: .34em;
  text-align: center; padding: 12px !important;
}
.qr { display: grid; place-items: center; padding: 16px; background: #fff; border-radius: var(--radius-sm); border: 1px solid var(--rule); }
.qr svg { width: 196px; height: 196px; display: block; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 7px; font-family: var(--mono); font-size: 14px; }
.codes span { padding: 7px 10px; background: var(--panel-2); border-radius: 6px; text-align: center; letter-spacing: .04em; }

/* ------------------------------------------------------------------ phone */

.tabbar { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .side {
    position: static; height: auto; flex-direction: row; align-items: center;
    padding: 10px 14px; border-right: 0; border-bottom: 1px solid var(--rule);
    gap: 12px;
  }
  .side .nav, .side .side-foot { display: none; }
  .main { padding: 18px 16px calc(78px + env(safe-area-inset-bottom)); }
  .grid.k2, .grid.k3, .grid.k4, .grid.sidebar-right { grid-template-columns: minmax(0, 1fr); }
  .fields { grid-template-columns: minmax(0, 1fr); }
  .paper { margin: 14px; padding: 24px 20px; border-radius: var(--radius); }
  h1 { font-size: 20px; }

  .tabbar {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: color-mix(in srgb, var(--panel) 92%, transparent);
    backdrop-filter: blur(12px);
    border-top: 1px solid var(--rule);
    padding: 7px 6px calc(7px + env(safe-area-inset-bottom));
  }
  .tabbar a {
    flex: 1; display: flex; flex-direction: column; align-items: center; gap: 3px;
    font-size: 10.5px; font-weight: 600; color: var(--muted); padding: 4px 0;
  }
  .tabbar a svg { width: 21px; height: 21px; }
  .tabbar a[aria-current="page"] { color: var(--accent); }
  .tabbar a:hover { text-decoration: none; }

  /* On a phone the line editor stops being a table and becomes cards. */
  .lines, .lines tbody, .lines tr, .lines td { display: block; width: 100%; }
  .lines thead { display: none; }
  .lines tr {
    border: 1px solid var(--rule); border-radius: var(--radius-sm);
    padding: 12px; margin-bottom: 12px; position: relative;
  }
  .lines td { border: 0; padding: 0 0 9px; }
  .lines td[data-label]::before {
    content: attr(data-label); display: block; font-size: 11px; font-weight: 650;
    text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: 4px;
  }
  .lines .drag { display: none; }
  .lines .line-total { text-align: left; padding-top: 0; }
  .lines .kill { position: absolute; top: 8px; right: 8px; }
  .wrap-table table { min-width: 560px; }
}

@media (min-width: 901px) {
  .main { max-width: 1180px; }
}

/* Printing the browser view is a fallback; the PDF is the real document. */
@media print {
  .side, .tabbar, .topbar, .no-print { display: none !important; }
  body { background: #fff; }
  .paper { box-shadow: none; border: 0; margin: 0; max-width: none; padding: 0; }
}
