/* =========================================================
   Ledger — design tokens
   A working accountant's admin: ink + paper + a gold seal.
   ========================================================= */
:root {
  --ink: #0E2E29;
  --ink-2: #16413A;
  --ink-3: #1E5349;
  --paper: #EFF2EE;
  --paper-card: #FFFFFF;
  --line: #DDE2DA;
  --text: #16241F;
  --text-dim: #5B685F;
  --gold: #C99A3B;
  --gold-dark: #A87C24;
  --positive: #1F7A4D;
  --positive-bg: #E7F3EC;
  --negative: #B23A3A;
  --negative-bg: #FBEAEA;
  --pending: #9C6B14;
  --pending-bg: #FBF1DC;

  --font-display: 'Fraunces', Georgia, serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --radius: 8px;
  --shadow: 0 1px 2px rgba(14,46,41,0.06), 0 4px 12px rgba(14,46,41,0.05);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--paper);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 600; margin: 0; color: var(--ink); }
a { color: inherit; text-decoration: none; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------- layout shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 236px; flex-shrink: 0;
  background: var(--ink);
  color: #DCE9E4;
  display: flex; flex-direction: column;
  position: relative;
}
.sidebar::after {
  content: ""; position: absolute; top: 0; right: 0; width: 3px; height: 100%;
  background: linear-gradient(180deg, var(--gold) 0%, transparent 100%);
  opacity: .7;
}
.brand {
  padding: 22px 22px 18px;
  font-family: var(--font-display);
  font-size: 20px; font-weight: 600; letter-spacing: .3px;
  color: #F5EFE0;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  display: flex; align-items: center; gap: 10px;
}
.brand .mark {
  width: 26px; height: 26px; border-radius: 6px;
  background: var(--gold); color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono); font-weight: 700; font-size: 13px;
}
.nav { padding: 14px 12px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 6px;
  color: #B9CCC4; font-size: 13.5px; font-weight: 500;
  transition: background .12s, color .12s;
}
.nav a svg { width: 16px; height: 16px; opacity: .85; }
.nav a:hover { background: var(--ink-2); color: #fff; }
.nav a.active { background: var(--ink-3); color: #fff; box-shadow: inset 3px 0 0 var(--gold); }
.nav .section-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em;
  color: #6F8B81; margin: 14px 12px 4px; font-weight: 600;
}
.sidebar-foot {
  padding: 14px 22px; font-size: 11.5px; color: #6F8B81;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 62px; flex-shrink: 0;
  background: var(--paper-card); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 26px;
}
.topbar h1 { font-size: 19px; }
.topbar .subtitle { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.topbar-actions { display: flex; gap: 10px; align-items: center; }

.content { padding: 24px 26px 60px; flex: 1; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: var(--font-body); font-weight: 600; font-size: 13px;
  padding: 9px 16px; border-radius: 6px; border: 1px solid transparent;
  cursor: pointer; transition: all .12s; white-space: nowrap;
}
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-2); }
.btn-gold { background: var(--gold); color: var(--ink); }
.btn-gold:hover { background: var(--gold-dark); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-ghost:hover { border-color: var(--ink); }
.btn-danger { background: transparent; color: var(--negative); border-color: var(--negative-bg); }
.btn-danger:hover { background: var(--negative-bg); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--paper-card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
}
.stat-card .label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-dim); font-weight: 600; }
.stat-card .value { font-family: var(--font-mono); font-size: 26px; font-weight: 600; margin-top: 8px; color: var(--ink); }
.stat-card .value.positive { color: var(--positive); }
.stat-card .value.negative { color: var(--negative); }
.stat-card .delta { font-size: 12px; margin-top: 6px; color: var(--text-dim); }

/* ---------- cards / panels ---------- */
.panel {
  background: var(--paper-card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.panel-head {
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; justify-content: space-between;
}
.panel-head h3 { font-size: 15.5px; }
.panel-body { padding: 18px 20px; }

/* ---------- tables ---------- */
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-dim); font-weight: 600; padding: 10px 20px; border-bottom: 1px solid var(--line);
  background: #FAFBF9;
}
table.data td { padding: 12px 20px; border-bottom: 1px solid var(--line); font-size: 13.5px; vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tr:hover td { background: #FAFBF9; }
table.data td.amount { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.amount.positive { color: var(--positive); }
.amount.negative { color: var(--negative); }

.badge {
  display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600; text-transform: capitalize;
}
.badge.pending { background: var(--pending-bg); color: var(--pending); }
.badge.approved { background: #E4EEFB; color: #2A5C97; }
.badge.paid { background: var(--positive-bg); color: var(--positive); }
.badge.rejected { background: var(--negative-bg); color: var(--negative); }

.empty-state { text-align: center; padding: 50px 20px; color: var(--text-dim); }
.empty-state .glyph { font-size: 30px; margin-bottom: 8px; }

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-dim); margin-bottom: 5px; }
input[type=text], input[type=number], input[type=date], input[type=tel], input[type=email], input[type=file], select, textarea {
  width: 100%; padding: 9px 11px; border-radius: 6px; border: 1px solid var(--line);
  font-family: var(--font-body); font-size: 13.5px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--gold); outline-offset: 1px; border-color: var(--gold); }
.select-with-add { display: flex; gap: 6px; }
.select-with-add select { flex: 1; }
.inline-add-row { display: none; gap: 8px; margin-top: 8px; }
.inline-add-row.open { display: flex; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.hint { font-size: 11.5px; color: var(--text-dim); margin-top: 4px; }
.field-error { color: var(--negative); font-size: 12px; margin-top: 4px; display: none; }
.reimbursement-fields { display: none; padding: 14px; border: 1px solid #BFD4ED; border-radius: 7px; background: #F4F8FD; }
.linked-summary { margin-top: 10px; padding: 11px 12px; background: #fff; border: 1px solid var(--line); border-radius: 6px; font-size: 12.5px; line-height: 1.6; color: var(--text-dim); }
.linked-summary a { color: #2A5C97; text-decoration: underline; }

/* ---------- modal ---------- */
.modal-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(14,46,41,0.45);
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--paper-card); border-radius: 10px; width: 100%; max-width: 560px;
  max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,0.25);
}
.modal-head { padding: 18px 22px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { font-size: 16px; }
.modal-close { cursor: pointer; background: none; border: none; font-size: 18px; color: var(--text-dim); }
.modal-body { padding: 20px 22px; }

/* ---------- filters row ---------- */
.filters { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.filters .field { min-width: 150px; }
.custom-period { display: none; }
.filters:has([data-period-select] option[value="custom"]:checked) .custom-period { display: block; }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 22px; right: 22px; z-index: 200;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 7px;
  font-size: 13px; font-weight: 500; box-shadow: var(--shadow);
  display: none; align-items: center; gap: 8px;
}
#toast.show { display: flex; }
#toast.error { background: var(--negative); }

/* ---------- P&L statement ---------- */
.pl-statement { max-width: 640px; margin: 0 auto; }
.pl-row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px dashed var(--line); font-size: 13.5px; }
.pl-row.total { border-top: 2px solid var(--ink); border-bottom: none; font-weight: 700; padding-top: 14px; margin-top: 6px; }
.pl-row .amount { font-family: var(--font-mono); }
.pl-section-title {
  font-family: var(--font-display); font-size: 15px; color: var(--ink);
  margin: 22px 0 6px; padding-bottom: 6px; border-bottom: 2px solid var(--gold);
}

@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .form-grid { grid-template-columns: 1fr; }
}
