/* Lending ledger -- dense, legible, tabular. Light and dark both first-class. */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #d9dde3;
  --border-strong: #b9c0ca;
  --text: #15181d;
  --text-dim: #5c646f;
  --accent: #1f5c8b;
  --accent-soft: #e5eef6;
  --positive: #1d6b4a;
  --negative: #a32b2b;
  --warning: #8a5a10;
  --warning-soft: #fdf3e0;
  --error-soft: #fbeaea;
  --ok-soft: #e8f3ed;
  --radius: 6px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --surface: #1c2027;
    --surface-2: #23282f;
    --border: #333a44;
    --border-strong: #46505d;
    --text: #e6e9ee;
    --text-dim: #99a2ae;
    --accent: #6fa8d6;
    --accent-soft: #1f2e3c;
    --positive: #6cc39b;
    --negative: #e58a8a;
    --warning: #d8ab5e;
    --warning-soft: #332a18;
    --error-soft: #35201f;
    --ok-soft: #1b2b24;
  }
}

* { box-sizing: border-box; }

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

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

/* ----------------------------------------------------------- layout --- */

header.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar .brand {
  font-weight: 650;
  letter-spacing: -0.01em;
  color: var(--text);
  white-space: nowrap;
}

.topbar nav {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 14px;
}

.topbar .spacer { flex: 1 1 auto; }

.topbar .who { color: var(--text-dim); font-size: 13px; }

main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px 16px 72px;
}

.crumbs {
  font-size: 13px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -0.015em; }
h2 { font-size: 16px; margin: 0 0 10px; letter-spacing: -0.01em; }
h3 { font-size: 14px; margin: 0 0 8px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }

.subtitle { color: var(--text-dim); font-size: 14px; margin: 0 0 18px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card > h2 { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.card > h2 .hint { font-size: 12px; font-weight: 400; color: var(--text-dim); text-transform: none; letter-spacing: 0; }

.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* ------------------------------------------------------------ stats --- */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
}

.stat { background: var(--surface); padding: 12px 14px; }
.stat .label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-dim); }
.stat .value { font: 600 19px/1.25 var(--mono); font-variant-numeric: tabular-nums; margin-top: 4px; }
.stat .note { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.stat.accent .value { color: var(--accent); }
.stat.warn .value { color: var(--warning); }
.stat.bad .value { color: var(--negative); }

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

.table-wrap { overflow-x: auto; margin: 0 -4px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

th, td {
  padding: 7px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

thead th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
  font-weight: 600;
}

tbody tr:hover { background: var(--surface-2); }
tbody tr.muted td { color: var(--text-dim); }
tbody tr.voided td { text-decoration: line-through; color: var(--text-dim); }

tfoot td {
  font-weight: 650;
  border-top: 1px solid var(--border-strong);
  border-bottom: none;
}

td.num, th.num {
  text-align: right;
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

td.neg { color: var(--negative); }
td.pos { color: var(--positive); }

.empty { color: var(--text-dim); font-size: 13.5px; padding: 10px 0; font-style: italic; }

/* ------------------------------------------------------------ chips --- */

.chip {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 7px;
  border-radius: 10px;
  background: var(--surface-2);
  color: var(--text-dim);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.chip.active, .chip.posted, .chip.ok { background: var(--ok-soft); color: var(--positive); border-color: transparent; }
.chip.draft, .chip.inactive { background: var(--surface-2); }
.chip.voided, .chip.closed, .chip.error { background: var(--error-soft); color: var(--negative); border-color: transparent; }
.chip.matured, .chip.warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.chip.agent, .chip.lead { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

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

form.stack { display: grid; gap: 10px; }

.field { display: grid; gap: 4px; }
.field label { font-size: 12px; color: var(--text-dim); font-weight: 500; }
.field .help { font-size: 11.5px; color: var(--text-dim); }

.row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

input, select, textarea, button {
  font: inherit;
  color: var(--text);
}

input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 6px 8px;
  width: 100%;
  font-size: 14px;
}

input[type="number"], input.amount { font-family: var(--mono); text-align: right; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input:disabled, select:disabled { background: var(--surface-2); color: var(--text-dim); }

textarea { min-height: 60px; resize: vertical; }

button, .btn {
  background: var(--accent);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 7px 13px;
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
}

button:hover, .btn:hover { filter: brightness(1.08); text-decoration: none; }
button:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }

button.secondary, .btn.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
}

button.danger { background: var(--negative); }

button.link {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  font-size: 13px;
  font-weight: 500;
  text-decoration: underline;
}

.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

details.form-block {
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-top: 12px;
}

details.form-block > summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
}

details.form-block[open] > summary { margin-bottom: 12px; }

/* ------------------------------------------------------------- tabs --- */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border-strong);
  margin-bottom: 16px;
  overflow-x: auto;
}

.tabs button {
  background: none;
  color: var(--text-dim);
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 550;
}

.tabs button[aria-selected="true"] { color: var(--accent); border-bottom-color: var(--accent); }
.tabs button:hover { color: var(--text); filter: none; }

.tab-panel[hidden] { display: none; }

/* ----------------------------------------------------------- notices --- */

.notice {
  border-radius: var(--radius);
  padding: 10px 13px;
  margin-bottom: 14px;
  font-size: 14px;
  border: 1px solid transparent;
}

.notice.error { background: var(--error-soft); color: var(--negative); }
.notice.warning { background: var(--warning-soft); color: var(--warning); }
.notice.success, .notice.ok { background: var(--ok-soft); color: var(--positive); }
.notice.info { background: var(--accent-soft); color: var(--accent); }

#toast-stack {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  z-index: 60;
  max-width: min(420px, calc(100vw - 32px));
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 14px;
  box-shadow: 0 6px 20px rgb(0 0 0 / 0.18);
}

.toast.error { border-left-color: var(--negative); }
.toast.success { border-left-color: var(--positive); }

/* ------------------------------------------------------------- misc --- */

/* A filter above the dashboard tiles. */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 12px;
}
.filter-bar label { font-size: 13px; color: var(--text-dim); font-weight: 500; }
.filter-bar select { width: auto; min-width: 220px; }

/* Account settings: archive, restore, delete. */
.archived-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.settings-action {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  border-top: 1px solid var(--border);
  margin-top: 16px;
  padding-top: 14px;
}
.settings-action p { margin: 4px 0 0; max-width: 60ch; }
.danger-zone {
  border: 1px solid var(--negative);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 14px;
}
.danger-zone h3 { color: var(--negative); }
.danger-zone p { margin: 0 0 12px; }

/* Public demo: the strip above the top bar, and the landing page. */
.demo-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13.5px;
  padding: 7px 16px;
  text-align: center;
}
.demo-banner form { display: inline; }
.demo-welcome { max-width: 720px; margin: 6vh auto 0; }
.demo-welcome h1 { font-size: 28px; line-height: 1.25; margin-bottom: 10px; }
.demo-welcome .eyebrow {
  font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--accent); font-weight: 650; margin: 0 0 8px;
}
.demo-tries { margin: 0; padding-left: 18px; display: grid; gap: 8px; font-size: 14.5px; }

/* What a draw comes to against availability, shown while the form is filled. */
.draw-preview {
  background: var(--surface-2);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 9px 12px;
  font-size: 13.5px;
  display: grid;
  gap: 3px;
  font-variant-numeric: tabular-nums;
}
.draw-preview .amount { font-weight: 650; }
.draw-preview .over { color: var(--negative); font-weight: 600; }
.draw-preview .warn { color: var(--warning); font-weight: 600; }

label.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  cursor: pointer;
}
label.checkbox input { width: auto; margin: 0; }

/* An inline editor opened beneath a table row. */
tr.edit-row > td { background: var(--surface-2); padding: 12px 14px 14px; }
tr.edit-row:hover { background: none; }
.edit-panel table { background: var(--surface); }

/* A participation set read as a list, share first. The percentages sit in a
   fixed right-aligned column so the decimal points line up down the list. */
.share-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 3px;
  font-size: 13.5px;
}

.share-list li {
  display: grid;
  grid-template-columns: 4.75em 1fr auto;
  align-items: baseline;
  gap: 8px;
}

.share-list .share-pct {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  text-align: right;
  white-space: nowrap;
}

.share-list .share-lender { min-width: 0; overflow-wrap: anywhere; }

dl.terms { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13.5px; margin: 0; }
dl.terms dt { color: var(--text-dim); }
dl.terms dd { margin: 0; font-variant-numeric: tabular-nums; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dim { color: var(--text-dim); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }

.auth-shell {
  max-width: 400px;
  margin: 8vh auto;
  padding: 0 16px;
}

.segments {
  font-family: var(--mono);
  font-size: 12px;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 8px 10px;
  margin-top: 6px;
  overflow-x: auto;
}

@media (max-width: 640px) {
  main { padding: 14px 12px 60px; }
  .card { padding: 13px; }
  header.topbar { padding: 9px 12px; }
}
