/* Relay Accounting — a ledger on a screen.
   Dense, quiet, and readable at a glance: numbers right-aligned and
   tabular so columns line up, and nothing coloured that is not a signal. */

:root {
  --bg: #fbfaf8;
  --panel: #ffffff;
  --fg: #1c1a17;
  --muted: #6b6660;
  --faint: #918b83;
  --line: #e4e0d9;
  --line-strong: #cfcac1;
  --accent: #1d4ed8;
  --accent-fg: #ffffff;
  --good: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --good-bg: #ecfdf3;
  --warn-bg: #fffbeb;
  --bad-bg: #fef2f2;
  --shadow: 0 8px 28px rgba(28, 26, 23, .14);
  --radius: 8px;
}

/* Dark is opt-in, not inherited from the operating system.
   A ledger is read beside paper and printed reports, and a set of books that
   flips to dark because somebody's laptop is on a schedule is a surprise, not
   a feature. `data-theme="dark"` on <html> is the only thing that turns it on,
   and the toggle remembers the choice. */
:root[data-theme="dark"] {
  --bg: #161513; --panel: #1e1d1a; --fg: #eceae6; --muted: #9b958d;
  --faint: #7c766e; --line: #2e2c28; --line-strong: #403d38;
  --accent: #7ea2ff; --accent-fg: #10131c;
  --good: #4ade80; --warn: #fbbf24; --bad: #f87171;
  --good-bg: #0e2a1a; --warn-bg: #2a2210; --bad-bg: #2c1516;
  --shadow: 0 8px 28px rgba(0, 0, 0, .5);
}
/* The date picker's own popup renders light by default too. */
:root { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font: 14px/1.5 ui-sans-serif, -apple-system, "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.boot { padding: 4rem; color: var(--muted); text-align: center; }

/* ---- Shell ------------------------------------------------------------- */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 1rem .75rem; display: flex; flex-direction: column; gap: .25rem;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { font-weight: 650; letter-spacing: -.01em; padding: .25rem .5rem 1rem; font-size: 15px; }
.brand small { display: block; font-weight: 400; color: var(--faint); font-size: 12px; }
.navlink {
  display: flex; justify-content: space-between; align-items: center; gap: .5rem;
  padding: .4rem .55rem; border-radius: 6px; color: var(--muted);
  text-decoration: none; cursor: pointer; border: 0; background: none;
  font: inherit; text-align: left; width: 100%;
}
.navlink:hover { background: color-mix(in srgb, var(--fg) 6%, transparent); color: var(--fg); }
.navlink.active { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--fg); font-weight: 550; }
.navgroup { font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
            color: var(--faint); padding: 1rem .55rem .25rem; }
.badge { font-size: 11px; background: var(--accent); color: var(--accent-fg);
         border-radius: 999px; padding: .05rem .4rem; font-variant-numeric: tabular-nums; }
.sidebar-foot { margin-top: auto; padding-top: 1rem; border-top: 1px solid var(--line);
                font-size: 12px; color: var(--faint); }

.main { padding: 1.5rem 2rem 5rem; max-width: 1200px; }
h1 { font-size: 1.35rem; margin: 0 0 .15rem; letter-spacing: -.01em; }
h2 { font-size: 1rem; margin: 1.75rem 0 .6rem; }
.sub { color: var(--muted); margin: 0 0 1.5rem; }

/* ---- Panels and tables ------------------------------------------------- */
.panel { background: var(--panel); border: 1px solid var(--line);
         border-radius: var(--radius); overflow: hidden; margin-bottom: 1.25rem; }
.panel-head { padding: .7rem 1rem; border-bottom: 1px solid var(--line);
              display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.panel-head h3 { margin: 0; font-size: 13px; font-weight: 600; }
.panel-body { padding: 1rem; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 550; color: var(--muted); font-size: 11.5px;
     text-transform: uppercase; letter-spacing: .04em;
     padding: .5rem 1rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: .5rem 1rem; border-bottom: 1px solid var(--line); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: color-mix(in srgb, var(--fg) 3%, transparent); }
/* Money lines up only if the digits are the same width. */
.num { text-align: right; font-variant-numeric: tabular-nums;
       font-feature-settings: "tnum"; white-space: nowrap; }
.neg { color: var(--bad); }
.total td { font-weight: 650; border-top: 2px solid var(--line-strong); border-bottom: 0; }
.dim { color: var(--muted); }
.tiny { font-size: 12px; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }

/* ---- Controls ---------------------------------------------------------- */
button, .btn {
  font: inherit; padding: .38rem .75rem; border-radius: 6px;
  border: 1px solid var(--line-strong); background: var(--panel); color: var(--fg);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--fg); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
button.danger { color: var(--bad); }
button.link { border: 0; background: none; color: var(--accent); padding: .1rem .2rem; text-decoration: underline; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }

input, select, textarea {
  font: inherit; padding: .38rem .55rem; border-radius: 6px;
  border: 1px solid var(--line-strong); background: var(--bg); color: var(--fg);
  max-width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input.num-input { text-align: right; font-variant-numeric: tabular-nums; }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: .2rem; }
.field { margin-bottom: .75rem; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .75rem; }

/* ---- Status ------------------------------------------------------------ */
.pill { display: inline-block; font-size: 11px; padding: .1rem .45rem; border-radius: 999px;
        border: 1px solid var(--line-strong); color: var(--muted); white-space: nowrap; }
.pill.good { background: var(--good-bg); color: var(--good); border-color: transparent; }
.pill.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.pill.bad  { background: var(--bad-bg);  color: var(--bad);  border-color: transparent; }

.note { padding: .7rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 13px; }
.note.good { background: var(--good-bg); color: var(--good); }
.note.warn { background: var(--warn-bg); color: var(--warn); }
.note.bad  { background: var(--bad-bg);  color: var(--bad); }
.note.info { background: color-mix(in srgb, var(--accent) 10%, transparent); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .75rem; margin-bottom: 1.5rem; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; }
.stat .k { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.stat .v { font-size: 1.35rem; font-variant-numeric: tabular-nums; margin-top: .15rem; letter-spacing: -.01em; }
.stat .m { font-size: 12px; color: var(--faint); margin-top: .1rem; }

/* ---- Auth -------------------------------------------------------------- */
.auth { max-width: 360px; margin: 12vh auto; padding: 0 1rem; }
.auth h1 { margin-bottom: .25rem; }

/* ---- Modal ------------------------------------------------------------- */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid;
            place-items: center; padding: 1rem; z-index: 50; overflow-y: auto; }
.modal { background: var(--panel); border-radius: 12px; border: 1px solid var(--line);
         width: min(640px, 100%); max-height: 90vh; overflow-y: auto; }
.modal-head { padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); font-weight: 600; }
.modal-body { padding: 1.25rem; }
.modal-foot { padding: 1rem 1.25rem; border-top: 1px solid var(--line);
              display: flex; justify-content: flex-end; gap: .5rem; }

.confidence { display: inline-block; width: 34px; height: 5px; border-radius: 3px;
              background: var(--line); overflow: hidden; vertical-align: middle; }
.confidence > i { display: block; height: 100%; background: var(--good); }
.confidence.low > i { background: var(--warn); }

@media (max-width: 780px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
  .navgroup { display: none; }
  .main { padding: 1rem; }
  th, td { padding: .45rem .6rem; }
}

/* ---- Date picker --------------------------------------------------------
   A calendar, not the browser's. The native control renders differently in
   every browser, is close to invisible in some, and cannot be styled — and
   picking a period end is the single most common thing done on these screens. */
.datefield { position: relative; display: inline-flex; align-items: stretch; }
.datefield input {
  border-top-right-radius: 0; border-bottom-right-radius: 0;
  border-right: 0; width: 8.5rem;
}
.datefield button.cal {
  border-top-left-radius: 0; border-bottom-left-radius: 0;
  padding: .38rem .5rem; line-height: 1; display: grid; place-items: center;
}
.datefield button.cal svg { display: block; }
.calendar {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 60;
  background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 10px; box-shadow: var(--shadow); padding: .6rem; width: 17rem;
}
.calendar .cal-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .25rem; margin-bottom: .4rem;
}
.calendar .cal-head strong { font-size: 13px; font-weight: 600; }
.calendar .cal-head button { padding: .2rem .45rem; line-height: 1; }
.calendar .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 1px; }
.calendar .cal-grid span {
  text-align: center; font-size: 10.5px; color: var(--faint);
  text-transform: uppercase; letter-spacing: .03em; padding: .2rem 0;
}
.calendar .cal-grid button {
  border: 0; background: none; padding: .32rem 0; border-radius: 5px;
  font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--fg);
}
.calendar .cal-grid button:hover { background: color-mix(in srgb, var(--fg) 8%, transparent); }
.calendar .cal-grid button.other { color: var(--faint); }
.calendar .cal-grid button.today { box-shadow: inset 0 0 0 1px var(--line-strong); }
.calendar .cal-grid button.picked { background: var(--accent); color: var(--accent-fg); }
.calendar .cal-foot {
  display: flex; justify-content: space-between; gap: .4rem; margin-top: .5rem;
  padding-top: .5rem; border-top: 1px solid var(--line);
}
.calendar .cal-foot button { font-size: 12px; padding: .25rem .5rem; }

/* ---- Dropzone ----------------------------------------------------------- */
.dropzone {
  border: 2px dashed var(--line-strong); border-radius: 12px;
  padding: 2.5rem 1.5rem; text-align: center; color: var(--muted);
  background: var(--panel); transition: border-color .12s, background .12s;
  cursor: pointer;
}
.dropzone.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 7%, var(--panel)); }
.dropzone strong { display: block; color: var(--fg); font-size: 15px; margin-bottom: .25rem; }
.bar { height: 4px; background: var(--line); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); transition: width .3s; }
