:root {
  /* Brand */
  --dark: #1b1a17;
  --dark-2: #232019;
  --gold: #b8935a;
  --gold-light: #e2ac4c;
  --gold-tint: #f6efe3;
  --bg: #f5f3ee;
  --surface: #ffffff;
  --border: #e7e1d6;
  --border-strong: #d9d1c2;
  --text: #26241f;
  --text-soft: #5b564c;
  --muted: #928c7e;
  --danger: #b3402f;
  --danger-tint: #fbeae7;
  --success: #3a7d44;
  --success-tint: #e9f3ea;
  --warn: #a06b1b;
  --warn-tint: #fbf1de;
  /* System */
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(28,25,20,.05), 0 1px 3px rgba(28,25,20,.04);
  --shadow: 0 1px 2px rgba(28,25,20,.04), 0 6px 20px -8px rgba(28,25,20,.14);
  --shadow-lg: 0 12px 40px -12px rgba(28,25,20,.28);
  --ring: 0 0 0 3px rgba(184,147,90,.25);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App shell ─────────────────────────────────────────── */
.app-shell { display: flex; min-height: 100vh; align-items: stretch; }

.sidebar {
  width: 244px; flex: 0 0 244px;
  background: linear-gradient(180deg, var(--dark-2) 0%, var(--dark) 100%);
  color: #fff; display: flex; flex-direction: column;
  position: sticky; top: 0; align-self: flex-start;
  height: 100vh; overflow-y: auto;
  padding: 26px 0 16px;
  box-shadow: inset -1px 0 0 rgba(255,255,255,.05);
}
.sidebar .brand {
  text-align: center; padding: 0 20px 20px; margin-bottom: 14px;
  border-bottom: 1px solid rgba(255,255,255,.10);
}
.sidebar .brand img { max-width: 150px; max-height: 68px; width: auto; height: auto; }
.sidebar .brand .brand-sub {
  margin-top: 10px; font-size: 10.5px; font-weight: 700; color: var(--gold-light);
  text-transform: uppercase; letter-spacing: 1.4px;
}
.sidebar nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 4px 12px; }
.sidebar nav a {
  color: rgba(255,255,255,.72); padding: 10px 13px; border-radius: var(--radius-sm);
  font-size: 14px; font-weight: 500; letter-spacing: .1px; position: relative;
  transition: background .15s, color .15s;
}
.sidebar nav a:hover { background: rgba(255,255,255,.07); text-decoration: none; color: #fff; }
.sidebar nav a.active {
  background: linear-gradient(180deg, var(--gold-light), var(--gold)); color: #1b1a17; font-weight: 600;
  box-shadow: 0 2px 8px -2px rgba(184,147,90,.5);
}
.sidebar-footer {
  padding: 16px 20px 4px; margin-top: 12px;
  border-top: 1px solid rgba(255,255,255,.10); font-size: 13px;
}
.sidebar-footer .user-name { color: #fff; font-weight: 600; margin-bottom: 6px; }
.sidebar-footer a { color: rgba(255,255,255,.55); }
.sidebar-footer a:hover { color: #fff; }

.main { flex: 1; min-width: 0; }
.container { max-width: 1120px; margin: 0; padding: 34px 40px 72px; }
.container.narrow { max-width: 480px; }

/* ── Headings ──────────────────────────────────────────── */
h1 { font-size: 25px; line-height: 1.2; margin: 0 0 20px; letter-spacing: -.4px; font-weight: 700; }
h2 { font-size: 17px; margin: 0 0 15px; letter-spacing: -.2px; font-weight: 650; }
h3 { font-size: 14px; margin: 0 0 10px; font-weight: 650; }

/* ── Cards ─────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px 24px; margin-bottom: 20px;
  box-shadow: var(--shadow-sm);
}
/* Tables: keep money / dates / badges on one line, but let long text (emails, notes)
   WRAP so a table never forces the whole page to scroll sideways. A table that is still
   genuinely too wide scrolls inside its own card — never the page. */
.card { overflow-x: auto; -webkit-overflow-scrolling: touch; }
/* Headers and text columns WRAP so wide tables fit inside the card instead of
   forcing a horizontal scroll. Money, numbers, badges and buttons stay on one
   line (money also uses a non-breaking space in View::money). */
td, th { white-space: normal; overflow-wrap: break-word; }
td.text-right, th.text-right, .num, td .badge, td .btn, td button, .nowrap { white-space: nowrap; overflow-wrap: normal; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll > table { min-width: 100%; }
/* opt-in wrapping cell for long free text (e.g. payment Description) inside a scroll table,
   so it wraps within a bounded width instead of forcing the whole table wide */
.table-scroll td.wrap-cell { white-space: normal; overflow-wrap: anywhere; min-width: 180px; max-width: 280px; }
/* compact table: smaller type + tighter padding for very wide tables (e.g. payment history,
   12 columns) so the whole thing fits inside the card without horizontal scrolling */
.table-scroll table.compact th, .table-scroll table.compact td { font-size: 11px; padding: 6px 7px; }
.table-scroll table.compact th { font-size: 9.5px; letter-spacing: .3px; }
.table-scroll table.compact td.wrap-cell { min-width: 130px; max-width: 190px; }
.card > table:last-child, .card > .flex-between + table { margin-bottom: -6px; }

/* ── Stat cards ────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow-sm); transition: box-shadow .18s, transform .18s;
  position: relative; overflow: hidden;
}
.stat-card::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: linear-gradient(180deg, var(--gold-light), var(--gold)); opacity: .0; transition: opacity .18s;
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-card:hover::before { opacity: 1; }
.stat-card .value { font-size: 26px; font-weight: 750; color: var(--dark); letter-spacing: -.6px; font-variant-numeric: tabular-nums; }
.stat-card .label { font-size: 12.5px; color: var(--muted); margin-top: 5px; line-height: 1.35; }

/* ── Tables ────────────────────────────────────────────── */
.card { -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th, td { text-align: left; padding: 9px 11px; border-bottom: 1px solid var(--border); font-size: 12px; vertical-align: middle; }
th {
  color: var(--muted); font-weight: 700; font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  background: #faf8f4; border-bottom: 1px solid var(--border-strong); white-space: normal;
}
/* header sub-labels like "(informational)" drop to their own line so long headers
   (e.g. "Term / End (informational)") stay narrow instead of forcing the table wide */
th .muted { display: block; font-size: 10px; margin-top: 1px; }
thead th, tr:first-child th { position: relative; }
tbody tr:hover td, table tr:hover td { background: #fcfaf6; }
tr:last-child td { border-bottom: none; }
td.text-right, th.text-right { text-align: right; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Forms ─────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
label { display: block; font-size: 12.5px; font-weight: 650; margin-bottom: 6px; color: var(--text); }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=month], input[type=file], textarea, select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit; background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--gold); box-shadow: var(--ring); }
textarea { resize: vertical; min-height: 100px; }
.help-text { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ── Buttons ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: linear-gradient(180deg, var(--gold-light), var(--gold)); color: #201a10; border: none;
  padding: 10px 18px; border-radius: var(--radius-sm); font-size: 13.5px; font-weight: 650; cursor: pointer;
  text-decoration: none; white-space: nowrap; box-shadow: 0 1px 2px rgba(28,25,20,.12); transition: filter .15s, transform .05s, box-shadow .15s;
}
.btn:hover { filter: brightness(1.04); text-decoration: none; box-shadow: var(--shadow); color: #201a10; }
.btn:active { transform: translateY(1px); }
.btn-secondary { background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); box-shadow: none; }
.btn-secondary:hover { background: var(--gold-tint); border-color: var(--gold); color: var(--text); filter: none; }
.btn-danger { background: var(--surface); color: var(--danger); border: 1px solid #eec4bd; box-shadow: none; }
.btn-danger:hover { background: var(--danger); color: #fff; filter: none; }
.btn-small { padding: 6px 12px; font-size: 12.5px; }
.btn-link { display: inline-flex; align-items: center; justify-content: center; background: var(--surface); color: var(--danger); border: 1px solid #eec4bd; padding: 6px 12px; border-radius: var(--radius-sm); font-size: 12.5px; font-weight: 650; cursor: pointer; text-decoration: none; font-family: inherit; white-space: nowrap; transition: background .15s, color .15s, border-color .15s; }
.btn-link:hover { background: var(--danger); color: #fff; text-decoration: none; }
.inline-form { display: inline; }
.table-actions { display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; }
/* tighten the horizontal gap between row action buttons (Open / Delete / + New Round),
   which sit in separate table cells, by trimming those cells' side padding */
td:has(.btn-small), td:has(.btn-link), td:has(.inline-form) { padding-left: 5px; padding-right: 5px; }

/* ── Badges ────────────────────────────────────────────── */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 650; letter-spacing: .2px; border: 1px solid transparent; white-space: nowrap; }
.badge-active { background: var(--success-tint); color: var(--success); border-color: #cfe6d3; }
.badge-invited { background: var(--warn-tint); color: var(--warn); border-color: #eeddba; }
.badge-disabled { background: var(--danger-tint); color: var(--danger); border-color: #f0cec7; }
.badge-closed { background: #efece6; color: var(--muted); border-color: #e2ddd3; }

/* ── Alerts ────────────────────────────────────────────── */
.alert { padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 18px; font-size: 14px; border: 1px solid transparent; }
.alert-error { background: var(--danger-tint); color: var(--danger); border-color: #f0c6bf; }
.alert-success { background: var(--success-tint); color: var(--success); border-color: #c3e0c9; }

/* ── Login ─────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(120% 120% at 50% 0%, var(--dark-2), var(--dark)); padding: 20px; }
.login-box { background: var(--surface); border-radius: 16px; padding: 40px; width: 380px; max-width: 100%; box-shadow: var(--shadow-lg); }
.login-box .brand { text-align: center; margin-bottom: 6px; }
.login-box .brand img { max-width: 210px; max-height: 88px; width: auto; height: auto; }
.login-box .sub { text-align: center; color: var(--muted); font-size: 13px; margin-bottom: 24px; }

/* ── Utilities ─────────────────────────────────────────── */
.muted { color: var(--muted); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 6px; }
.breadcrumb { font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--gold); }
.token-list { font-family: ui-monospace, Menlo, monospace; font-size: 13px; background: var(--gold-tint); padding: 12px 16px; border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* ── Form sections & payment-method cards ──────────────── */
/* A small uppercase divider to group a long form into readable sections. */
.form-section-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted);
  font-weight: 700; margin: 26px 0 14px; padding-bottom: 8px; border-bottom: 1px solid var(--border);
}
.form-section-title:first-child { margin-top: 0; }
.form-section-title .hint { text-transform: none; letter-spacing: 0; font-weight: 500; color: var(--muted); }

/* Payment-method inputs grouped into distinct, colour-accented cards so the
   eye lands on the right field and the wrong one is hard to type into. */
.method-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; align-items: start; }
.method-card {
  border: 1px solid var(--border); border-left: 4px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 15px 16px 16px; background: var(--surface);
}
.method-card h4 {
  margin: 0 0 12px; font-size: 13px; font-weight: 700; color: var(--text);
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.method-card .method-tag {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.method-card .form-group { margin-bottom: 12px; }
.method-card .form-group:last-child { margin-bottom: 0; }
.method-card .help-text { margin-top: 5px; }
.method-cash   { border-left-color: var(--success); }
.method-cash   .method-tag { background: var(--success-tint); color: var(--success); }
.method-bank   { border-left-color: #2f6690; }
.method-bank   .method-tag { background: #e7f0f7; color: #2f6690; }
.method-kruger { border-left-color: var(--gold); }
.method-kruger .method-tag { background: var(--gold-tint); color: #9a6b1b; }
.method-forex  { border-left-color: #6b4f9e; }
.method-forex  .method-tag { background: #efe9f7; color: #6b4f9e; }

/* Settlement-type blocks (reinvest / capital payout): clearly separated, each
   with its own accent, so these principal-changing actions stand apart from an
   ordinary payout. */
.settlement-block {
  border: 1px solid var(--border); border-left: 4px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 14px 16px; margin-bottom: 14px; background: var(--surface);
}
.settlement-block.is-reinvest { border-left-color: var(--success); }
.settlement-block.is-capital { border-left-color: var(--gold); }
.settlement-block > label:first-child { margin-bottom: 0; }
.settlement-detail { margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--border-strong); }

/* ── Responsive ────────────────────────────────────────── */
@media (max-width: 860px) {
  .container { padding: 22px 18px 48px; }
  h1 { font-size: 22px; }
  .flex-between { flex-wrap: wrap; }
}
@media (max-width: 760px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%; flex: none; position: sticky; top: 0; z-index: 20; height: auto;
    flex-direction: row; flex-wrap: nowrap; align-items: center; padding: 12px 14px; gap: 8px;
    overflow-x: auto; box-shadow: 0 2px 12px -6px rgba(0,0,0,.4);
  }
  .sidebar .brand { display: flex; align-items: center; border-bottom: none; padding: 0; margin: 0 8px 0 0; flex: 0 0 auto; }
  .sidebar .brand img { max-height: 34px; max-width: 92px; }
  .sidebar .brand .brand-sub { display: none; }
  .sidebar nav { flex-direction: row; flex: 1; padding: 0; gap: 4px; overflow-x: auto; }
  .sidebar nav a { padding: 8px 12px; white-space: nowrap; }
  .sidebar nav a.active { box-shadow: none; }
  .sidebar nav > div { display: none; } /* hide the "Admin Tools" divider label on mobile */
  .sidebar-footer { border-top: none; margin: 0; padding: 0; margin-left: auto; text-align: right; flex: 0 0 auto; }
  .sidebar-footer .user-name { display: none; }
  .stat-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
  .stat-card .value { font-size: 22px; }
}
