/*
 * Ledger — hand-rolled CSS. No framework.
 *
 * Console treatment: one monospace family, hairline panels on deep navy, and
 * colour reserved for meaning — cyan is interactive, green is credit, red is
 * debit, amber is pending. Nothing is coloured for decoration.
 *
 * Propshaft picks up every .css file in this directory via stylesheet_link_tag :app.
 */

:root {
  color-scheme: dark;

  /* Ground */
  --void:       #060a12;
  --frame:      #0a1020;
  --panel:      #0c1424;
  --panel-head: #101a2d;
  --well:       #070d18;

  /* Hairlines */
  --rule:       #1b2c49;
  --rule-lit:   #294a78;

  /* Ink */
  --ink:        #c3d4ea;
  --ink-bright: #e8f1fb;
  --dim:        #5f7b9d;
  --dimmer:     #3d5678;

  /* Meaning */
  --cyan:    #22d3ee;
  --cyan-lit:#67e8f9;
  --credit:  #34d399;
  --debit:   #fb7185;
  --pending: #fbbf24;
  --violet:  #a78bfa;
  --magenta: #e879f9;

  /* Aliases — existing inline styles and partials resolve through these */
  --bg: var(--void);
  --surface: var(--panel);
  --border: var(--rule);
  --text: var(--ink);
  --text-muted: var(--dim);
  --primary: var(--cyan);
  --primary-hover: var(--cyan-lit);
  --success: var(--credit);
  --danger: var(--debit);
  --warning: var(--pending);

  --radius: 3px;
  --radius-sm: 2px;
  --shadow-sm: none;
  --shadow-md: 0 28px 70px rgba(0, 0, 0, 0.65);

  --font-body: "JetBrains Mono", ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --font-mono: var(--font-body);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--void);
  color: var(--ink);
  font: 13px/1.55 var(--font-body);
  -webkit-font-smoothing: antialiased;
  scrollbar-color: var(--rule-lit) transparent;
}

/* Faint survey grid, fading out below the fold. Decoration, kept near-invisible. */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(41, 74, 120, 0.15) 1px, transparent 1px),
    linear-gradient(90deg, rgba(41, 74, 120, 0.15) 1px, transparent 1px);
  background-size: 54px 54px;
  -webkit-mask-image: radial-gradient(ellipse 120% 85% at 50% 0%, #000 0%, transparent 72%);
          mask-image: radial-gradient(ellipse 120% 85% at 50% 0%, #000 0%, transparent 72%);
}

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

:focus-visible { outline: 1px solid var(--cyan); outline-offset: 2px; }

::selection { background: rgba(34, 211, 238, 0.25); color: var(--ink-bright); }

code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--well);
  border: 1px solid var(--rule);
  color: var(--cyan);
  padding: 0.05em 0.35em;
  border-radius: var(--radius-sm);
}

hr { border: 0; border-top: 1px solid var(--rule); margin: 24px 0; }

/* ── Window shell ───────────────────────────────────────────────────────── */

.app-shell {
  position: relative;
  z-index: 1;
  max-width: 1440px;
  margin: 20px auto;
  background: var(--frame);
  border: 1px solid var(--rule-lit);
  border-radius: 5px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
/* The one bright edge in the interface. */
.app-shell::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--magenta), var(--violet) 45%, var(--cyan));
  opacity: 0.9;
}

.app-titlebar {
  display: flex;
  align-items: center;
  gap: 20px;
  height: 42px;
  padding: 0 16px;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(180deg, rgba(41, 74, 120, 0.12), transparent);
}
.tb-brand {
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--ink-bright);
  font-size: 13px;
}
.tb-mark { color: var(--cyan); letter-spacing: 0; font-size: 14px; }
.tb-version { font-weight: 400; letter-spacing: 0.04em; color: var(--dimmer); font-size: 11px; }
.tb-tagline {
  flex: 1;
  text-align: right;
  color: var(--dim);
  font-size: 11.5px;
  letter-spacing: 0.03em;
}
.tb-tagline em { font-style: normal; color: var(--dimmer); padding: 0 6px; }
.tb-session {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 18px;
  border-left: 1px solid var(--rule);
  font-size: 11.5px;
  color: var(--dim);
}
.tb-session form { display: inline; margin: 0; }
.tb-session button {
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--dim);
  font: inherit;
  padding: 3px 7px;
  cursor: pointer;
}
.tb-session button:hover { color: var(--debit); border-color: rgba(251, 113, 133, 0.4); }

.app-body {
  display: grid;
  grid-template-columns: 214px minmax(0, 1fr);
  min-height: calc(100vh - 105px);
}

/* ── Sidebar ────────────────────────────────────────────────────────────── */

.app-nav {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 16px 12px;
  border-right: 1px solid var(--rule);
  background: rgba(6, 10, 18, 0.4);
}
.nav-links { display: flex; flex-direction: column; gap: 2px; }
.nav-links a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--dim);
  font-size: 12.5px;
}
.nav-links a svg { width: 15px; height: 15px; flex: none; opacity: 0.9; }
.nav-links a:hover {
  color: var(--ink);
  background: rgba(41, 74, 120, 0.18);
  text-decoration: none;
}
.nav-links a.active {
  color: var(--cyan);
  border-color: rgba(34, 211, 238, 0.45);
  background: rgba(34, 211, 238, 0.07);
  box-shadow: inset 0 0 20px rgba(34, 211, 238, 0.06);
}
.nav-links.nav-secondary { margin-top: auto; padding-top: 16px; border-top: 1px solid var(--rule); }

.nav-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 10px 2px;
  color: var(--dimmer);
  font-size: 10.5px;
  line-height: 1.5;
}
.nav-footer .mark {
  flex: none;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border: 1px solid var(--rule-lit);
  border-radius: var(--radius-sm);
  color: var(--cyan);
  font-size: 12px;
}
.nav-footer strong {
  display: block;
  color: var(--dim);
  font-weight: 700;
  letter-spacing: 0.16em;
  font-size: 10px;
}

/* ── Main + status bar ──────────────────────────────────────────────────── */

.app-main { padding: 22px 26px 40px; min-width: 0; }

.app-statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 32px;
  padding: 0 16px;
  border-top: 1px solid var(--rule);
  background: rgba(6, 10, 18, 0.5);
  color: var(--dimmer);
  font-size: 10.5px;
  letter-spacing: 0.04em;
}
.app-statusbar .live { color: var(--credit); }

/* ── Flash ──────────────────────────────────────────────────────────────── */

.flash {
  padding: 9px 14px;
  margin-bottom: 18px;
  border: 1px solid;
  border-left-width: 3px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
}
.flash-notice { background: rgba(52, 211, 153, 0.07); border-color: rgba(52, 211, 153, 0.45); color: var(--credit); }
.flash-alert  { background: rgba(251, 113, 133, 0.07); border-color: rgba(251, 113, 133, 0.45); color: var(--debit); }

/* ── Page header ────────────────────────────────────────────────────────── */

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--rule);
}
.page-header h1 {
  margin: 0;
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--ink-bright);
}
.page-header .lede { margin: 6px 0 0; color: var(--dim); font-size: 12px; }

/* ── Panels ─────────────────────────────────────────────────────────────── */

.panel {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  overflow: hidden;
}
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--rule);
  background: var(--panel-head);
}
.panel-title {
  margin: 0;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink-bright);
}
.panel-head .meta { font-size: 10.5px; letter-spacing: 0.1em; color: var(--dim); text-transform: uppercase; }
.panel-body { padding: 14px; }
.panel > .data-table, .panel > .empty-state { border: 0; border-radius: 0; }

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
  align-items: start;
}

/* ── KPI cards ──────────────────────────────────────────────────────────── */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 13px 16px 16px;
}
.kpi-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--dim);
  font-weight: 600;
  margin-bottom: 10px;
}
.kpi-source { margin-top: 9px; font-size: 11px; color: var(--dim); }
.kpi-source code { font-size: 10.5px; padding: 0.05em 0.3em; }

.kpi-value {
  font-size: 27px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--ink-bright);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.015em;
}

/* ── Sections ───────────────────────────────────────────────────────────── */

.audit-log h2,
.account-group h2 {
  font-size: 10.5px;
  font-weight: 700;
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--dim);
}
.account-group { margin-bottom: 26px; }

/* ── Tables ─────────────────────────────────────────────────────────────── */

.data-table {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  font-variant-numeric: tabular-nums;
}
.data-table th {
  padding: 9px 14px;
  text-align: left;
  background: var(--panel-head);
  border-bottom: 1px solid var(--rule);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--dim);
}
.data-table td {
  padding: 9px 14px;
  text-align: left;
  border-bottom: 1px solid rgba(27, 44, 73, 0.55);
}
.data-table tbody tr:nth-child(even) td { background: rgba(41, 74, 120, 0.05); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: rgba(34, 211, 238, 0.05); }
.data-table td.num, .data-table th.num { text-align: right; }
.data-table tbody td:first-child { white-space: nowrap; }
.data-table tfoot td { background: var(--panel-head); border-bottom: 0; }
.data-table .total td, .data-table td.total { font-weight: 700; color: var(--ink-bright); }

.muted { color: var(--dim); }
.pos { color: var(--credit); }
.neg { color: var(--debit); }

/* ── Empty state ────────────────────────────────────────────────────────── */

.empty-state {
  padding: 34px 20px;
  margin: 0;
  text-align: center;
  color: var(--dim);
  background: var(--panel);
  border: 1px dashed var(--rule-lit);
  border-radius: var(--radius);
  font-size: 12.5px;
}

/* ── Forms ──────────────────────────────────────────────────────────────── */

.app-form {
  background: var(--panel);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 20px;
  max-width: 560px;
}
.app-form-wide { max-width: 960px; }
.app-form.filter-bar {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
  max-width: none;
  padding: 14px 16px;
  margin-bottom: 20px;
}
.app-form.filter-bar .field { margin: 0; }
.inline-form { display: inline-block; margin-top: 4px; }

.app-form .field { margin-bottom: 15px; }
.app-form label {
  display: block;
  font-weight: 600;
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  margin-bottom: 6px;
  color: var(--dim);
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="file"],
input[type="search"],
select,
textarea {
  padding: 8px 10px;
  font: inherit;
  border: 1px solid var(--rule);
  border-radius: var(--radius-sm);
  background: var(--well);
  color: var(--ink);
}
.app-form input[type="text"],
.app-form input[type="email"],
.app-form input[type="password"],
.app-form input[type="number"],
.app-form input[type="date"],
.app-form input[type="file"],
.app-form select,
.app-form textarea { width: 100%; }
input::placeholder, textarea::placeholder { color: var(--dimmer); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 2px rgba(34, 211, 238, 0.16);
}
textarea { resize: vertical; min-height: 60px; }
.app-form .form-actions {
  margin-top: 18px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.app-form .form-errors {
  background: rgba(251, 113, 133, 0.07);
  border: 1px solid rgba(251, 113, 133, 0.45);
  color: var(--debit);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  font-size: 12.5px;
}
.app-form .form-errors ul { margin: 0; padding-left: 18px; }

/* ── Line-item sheets ───────────────────────────────────────────────────
   Invoice, expense and journal lines are a grid you tab through, so the cells
   drop their boxes and behave like a spreadsheet: the row is the control.      */

.line-items, .journal-lines { border: 0; padding: 0; margin: 20px 0; min-width: 0; }
.line-items legend, .journal-lines legend {
  padding: 0 0 8px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  color: var(--dim);
}

.data-table.sheet { margin-bottom: 8px; table-layout: auto; }
.data-table.sheet td { padding: 0; }
.data-table.sheet td.num { padding: 0; }
.data-table.sheet td > input,
.data-table.sheet td > select {
  width: 100%;
  padding: 8px 12px;
  border: 0;
  box-shadow: none;
  border-radius: 0;
  background: transparent;
  color: var(--ink);
  font: inherit;
}
.data-table.sheet td > input:focus,
.data-table.sheet td > select:focus {
  outline: none;
  background: rgba(34, 211, 238, 0.08);
  box-shadow: inset 0 0 0 1px var(--cyan);
}
.data-table.sheet td.num > input { text-align: right; }
.data-table.sheet td > select { padding-right: 6px; }
.data-table.sheet td[data-line-items-target="rowTotal"],
.data-table.sheet td[data-journal-lines-target] { padding: 8px 12px; }
.data-table.sheet td > .btn { padding: 2px 8px; margin: 0 8px; }
/* Chrome draws number spinners in a light box; the sheet has its own rhythm. */
.data-table.sheet input[type="number"] { -moz-appearance: textfield; }
.data-table.sheet input[type="number"]::-webkit-outer-spin-button,
.data-table.sheet input[type="number"]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Totals rows — used by the sheets and by every report. */
.data-table .subtotal td {
  font-weight: 600;
  color: var(--ink);
  border-top: 1px solid var(--rule);
}
.data-table .grand-total td {
  font-weight: 700;
  font-size: 14px;
  color: var(--ink-bright);
  border-top: 1px solid var(--rule-lit);
}
.data-table tbody tr:hover .subtotal td { background: var(--panel-head); }

/* Native file pickers render as a light chip otherwise. */
.app-form input[type="file"] { padding: 7px 10px; color: var(--dim); }
input[type="file"]::-webkit-file-upload-button,
input[type="file"]::file-selector-button {
  font: inherit;
  margin-right: 10px;
  padding: 4px 10px;
  border: 1px solid var(--rule-lit);
  border-radius: var(--radius-sm);
  background: rgba(41, 74, 120, 0.16);
  color: var(--ink);
  cursor: pointer;
}
input[type="file"]::-webkit-file-upload-button:hover,
input[type="file"]::file-selector-button:hover { background: rgba(41, 74, 120, 0.3); }

/* ── Buttons ────────────────────────────────────────────────────────────── */

.btn {
  display: inline-block;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--rule-lit);
  background: rgba(41, 74, 120, 0.16);
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: none;
  transition: background 90ms ease, border-color 90ms ease, color 90ms ease;
}
.btn:hover { background: rgba(41, 74, 120, 0.3); color: var(--ink-bright); text-decoration: none; }
.btn-primary {
  border-color: rgba(34, 211, 238, 0.5);
  background: rgba(34, 211, 238, 0.1);
  color: var(--cyan);
}
.btn-primary:hover {
  background: rgba(34, 211, 238, 0.2);
  border-color: var(--cyan);
  color: var(--cyan-lit);
}
.btn-secondary { background: transparent; color: var(--dim); }
.btn-secondary:hover { background: rgba(41, 74, 120, 0.22); color: var(--ink); }

/* ── Badges ─────────────────────────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  border: 1px solid transparent;
}
.badge-paid,
.badge-matched   { background: rgba(52, 211, 153, 0.1);  color: var(--credit);  border-color: rgba(52, 211, 153, 0.45); }
.badge-partial,
.badge-unmatched { background: rgba(251, 191, 36, 0.1);  color: var(--pending); border-color: rgba(251, 191, 36, 0.45); }
.badge-open      { background: rgba(34, 211, 238, 0.1);  color: var(--cyan);    border-color: rgba(34, 211, 238, 0.45); }
.badge-overdue   { background: rgba(251, 113, 133, 0.1); color: var(--debit);   border-color: rgba(251, 113, 133, 0.45); }
.badge-ignored   { background: rgba(41, 74, 120, 0.2);   color: var(--dim);     border-color: var(--rule-lit); }

/* ── Notices ────────────────────────────────────────────────────────────── */

.notice {
  background: rgba(251, 191, 36, 0.06);
  border: 1px solid rgba(251, 191, 36, 0.4);
  border-left-width: 3px;
  color: var(--pending);
  padding: 13px 16px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: 12.5px;
}
.notice a { color: var(--pending); text-decoration: underline; }
.notice p { margin: 0 0 8px; }
.notice p:last-child { margin-bottom: 0; }
.notice ul { margin: 4px 0; padding-left: 20px; }
.notice-info {
  background: rgba(34, 211, 238, 0.06);
  border-color: rgba(34, 211, 238, 0.4);
  color: var(--cyan);
}
.notice-info a { color: var(--cyan); }

/* ── Sign-in ────────────────────────────────────────────────────────────── */

.guest-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
  z-index: 1;
}
.guest-shell > main { width: 100%; max-width: 390px; }
.guest-card {
  position: relative;
  width: 100%;
  max-width: 390px;
  margin: 0;
  background: var(--frame);
  border: 1px solid var(--rule-lit);
  border-radius: 5px;
  padding: 30px 28px 28px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.guest-card::before {
  content: "";
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--magenta), var(--violet) 45%, var(--cyan));
}
.guest-card .guest-brand {
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--ink-bright);
  margin-bottom: 4px;
}
.guest-card .guest-brand span { color: var(--cyan); letter-spacing: 0; }
.guest-card h1 {
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.04em;
  color: var(--dim);
  margin: 0 0 22px;
  text-align: left;
}
.guest-card .app-form { background: none; border: 0; padding: 0; max-width: none; }
.guest-card .form-actions .btn { width: 100%; text-align: center; }
.guest-card input[inputmode="numeric"] {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: 0.45em;
  text-indent: 0.45em;
  text-align: center;
  color: var(--cyan);
  padding: 12px 10px;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 900px) {
  .app-shell { margin: 0; border: 0; border-radius: 0; }
  .app-body { grid-template-columns: 1fr; min-height: 0; }
  .app-nav {
    flex-direction: row;
    align-items: center;
    gap: 12px;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--rule);
    padding: 10px 12px;
  }
  .nav-links { flex-direction: row; gap: 4px; }
  .nav-links a { white-space: nowrap; }
  .nav-links.nav-secondary { margin: 0; padding: 0 0 0 12px; border-top: 0; border-left: 1px solid var(--rule); }
  .nav-footer { display: none; }
  .tb-tagline { display: none; }
  .app-main { padding: 18px 14px 32px; }

  /* Wide tables keep their shape and scroll inside the panel rather than
     squeezing columns into unreadable stacks. */
  .data-table { display: block; overflow-x: auto; white-space: nowrap; }
  .data-table thead, .data-table tbody, .data-table tfoot { display: table; width: 100%; }
  .app-form-wide, .app-form { max-width: none; }
  .page-header { align-items: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ── Print: documents leave the console behind and go back to paper ─────── */

@media print {
  body::before { display: none; }
  html, body { background: #fff; color: #111; }
  .app-shell {
    margin: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none;
    background: #fff;
    max-width: none;
  }
  .app-shell::before,
  .app-titlebar,
  .app-nav,
  .app-statusbar,
  .flash,
  .print-hide { display: none !important; }
  .app-body { display: block; }
  .app-main { padding: 0; }
}
