/* ===================================================================
   PerFinance — a private ledger, not a SaaS dashboard.
   Warm paper surface, hairline rules, right-aligned tabular amounts.
   Gold is reserved for Zakat / gold-asset content only — never used
   as a decorative accent elsewhere.
   =================================================================== */

:root {
  --paper: #f6f1e7;
  --paper-raised: #fffdf8;
  --paper-sunken: #ece4d3;
  --ink: #1e2430;
  --ink-soft: #6b6456;
  --rule: #d9cfb8;
  --rule-strong: #c2b596;
  --teal: #2f6f62;
  --teal-ink: #16352d;
  --gold: #9c7a2e;
  --gold-soft: #f1e6c8;
  --rust: #a14b3b;
  --rust-soft: #f3e1da;

  --font-serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Book Antiqua", serif;
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

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

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
}

a { color: var(--teal-ink); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

/* ---------- Shell: ledger-spine nav + content ---------- */

.shell { display: flex; min-height: 100vh; align-items: stretch; }

.spine {
  width: 190px;
  flex-shrink: 0;
  background: var(--paper-sunken);
  border-right: 1px solid var(--rule-strong);
  padding: 22px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.spine-brand {
  font-family: var(--font-serif);
  font-size: 19px;
  font-weight: 700;
  color: var(--ink);
  padding: 0 20px 18px;
  border-bottom: 1px solid var(--rule);
  margin-bottom: 10px;
}

.spine nav a {
  display: block;
  padding: 9px 20px;
  color: var(--ink-soft);
  text-decoration: none;
  font-size: 14px;
  border-left: 3px solid transparent;
}

.spine nav a:hover { color: var(--ink); background: var(--paper-raised); }

.spine nav a.active {
  color: var(--teal-ink);
  font-weight: 600;
  border-left-color: var(--teal);
  background: var(--paper-raised);
}

.content { flex: 1; min-width: 0; }

.container { max-width: 880px; margin: 0 auto; padding: 36px 40px 80px; overflow-x: auto; }
.container.wide { max-width: 1180px; }

/* Small screens: spine collapses to a top bar */
@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .spine {
    width: 100%;
    height: auto;
    position: static;
    padding: 14px 0;
    border-right: none;
    border-bottom: 1px solid var(--rule-strong);
  }
  .spine-brand { border-bottom: none; padding-bottom: 10px; margin-bottom: 4px; }
  .spine nav { display: flex; flex-wrap: wrap; gap: 2px; padding: 0 12px; }
  .spine nav a { border-left: none; border-bottom: 3px solid transparent; padding: 6px 10px; }
  .spine nav a.active { border-left-color: transparent; border-bottom-color: var(--teal); }
  .container { padding: 24px 20px 60px; }
}

/* ---------- Typography ---------- */

h1 {
  font-family: var(--font-serif);
  font-size: 26px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--ink);
}

h2 {
  font-family: var(--font-serif);
  font-size: 17px;
  font-weight: 700;
  margin: 32px 0 12px;
  color: var(--ink);
  padding-bottom: 6px;
  border-bottom: 1px solid var(--rule);
}

p.subtitle { color: var(--ink-soft); margin: 0 0 22px; font-size: 14px; }

/* ---------- Ledger figure (dashboard hero number) ---------- */

.ledger-figure { margin-bottom: 28px; }
.ledger-figure .label { color: var(--ink-soft); font-size: 13px; margin-bottom: 2px; }
.ledger-figure .value {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 42px;
  font-weight: 600;
  letter-spacing: -0.01em;
}
.value.positive { color: var(--teal-ink); }
.value.negative { color: var(--rust); }

/* ---------- Ledger rows (replaces the generic card-grid) ---------- */

.ledger {
  border-top: 1px solid var(--rule-strong);
  margin-bottom: 28px;
}
.ledger-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 2px;
  border-bottom: 1px solid var(--rule);
}
.ledger-row .ledger-label { color: var(--ink-soft); font-size: 14px; }
.ledger-row .ledger-amount {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}
.ledger-row.total {
  border-top: 1px solid var(--rule-strong);
  border-bottom: none;
  padding-top: 12px;
  margin-top: 4px;
}
.ledger-row.total .ledger-label { color: var(--ink); font-weight: 600; }
.ledger-row.total .ledger-amount { font-size: 18px; font-weight: 700; }

/* ---------- Panels (replaces the generic SaaS card) ---------- */

.panel {
  background: var(--paper-raised);
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  padding: 18px 20px;
  margin-bottom: 22px;
}

/* ---------- Tables (statement-style) ---------- */

table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
}

th, td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--rule);
  font-size: 14px;
  vertical-align: middle;
}

th {
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--rule-strong);
}

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

tbody tr:hover { background: rgba(47, 111, 98, 0.05); }
tr:last-child td { border-bottom: none; }

.amount-pos { color: var(--teal-ink); }
.amount-neg { color: var(--rust); }

.empty-row td { color: var(--ink-soft); font-style: italic; padding: 18px 10px; }

td.desc {
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

td.cat select { width: 100%; min-width: 150px; }
td.xfer button { white-space: nowrap; }

.pagination {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin: -6px 0 24px;
  font-size: 13px;
  color: var(--ink-soft);
}
.pagination-controls { display: flex; align-items: center; gap: 12px; }
.pagination-page { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Forms ---------- */

form.stacked {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  align-items: end;
}

form.stacked label,
.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--ink-soft);
}

form.stacked .actions { display: flex; align-items: center; }

form.inline { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

input, select, textarea {
  background: var(--paper);
  border: 1px solid var(--rule-strong);
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 2px;
  font-size: 14px;
  font-family: inherit;
}

input:focus, select:focus, textarea:focus { border-color: var(--teal); }

button {
  background: var(--teal);
  color: var(--paper-raised);
  border: none;
  padding: 9px 16px;
  border-radius: 2px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

button.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--rule-strong);
}

button:hover { filter: brightness(0.93); }
button.secondary:hover { background: var(--paper-sunken); filter: none; }

/* htmx in-flight feedback: the one deliberate motion in this UI */
button.htmx-request { opacity: 0.6; cursor: progress; }
.htmx-settling { opacity: 0; }
.htmx-added { transition: opacity 240ms ease-in; }

/* ---------- Status badges ---------- */

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}
.badge.open { background: var(--gold-soft); color: var(--gold); }
.badge.partially_paid { background: #e3eef0; color: var(--teal-ink); }
.badge.settled, .badge.paid, .badge.calculated { background: #e4ede3; color: var(--teal-ink); }

/* ---------- Zakat / gold accent (reserved for this content only) ---------- */

.zakat-note {
  background: var(--gold-soft);
  border: 1px solid #e0cd92;
  color: #6b5420;
  padding: 12px 14px;
  border-radius: 3px;
  font-size: 13px;
  margin-bottom: 22px;
  line-height: 1.5;
}
.zakat-figure .value { color: var(--gold); }

/* ---------- Feedback ---------- */

.error {
  color: #7a2e21;
  background: var(--rust-soft);
  border: 1px solid #e0b6a9;
  padding: 10px 12px;
  border-radius: 3px;
  font-size: 14px;
  margin-bottom: 14px;
}
.success {
  color: var(--teal-ink);
  background: #e4ede3;
  border: 1px solid #c7dcc2;
  padding: 10px 12px;
  border-radius: 3px;
  font-size: 14px;
  margin-bottom: 14px;
}

.empty-state {
  border: 1px dashed var(--rule-strong);
  border-radius: 3px;
  padding: 28px 20px;
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  margin-bottom: 22px;
}

canvas { max-height: 300px; }

/* ---------- Auth pages (setup / login) ---------- */

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--paper-raised);
  border: 1px solid var(--rule-strong);
  border-radius: 3px;
  padding: 28px 28px 24px;
}

.auth-card h1 { font-size: 20px; margin-bottom: 10px; }
.auth-card p.subtitle { margin-bottom: 18px; }
.auth-card form { display: flex; flex-direction: column; gap: 14px; }
.auth-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-soft); }
.auth-card button { width: 100%; padding: 10px; }
.auth-card .qr-wrap { text-align: center; margin: 14px 0; }
.auth-card .qr-wrap img { border: 1px solid var(--rule-strong); border-radius: 3px; background: #fff; padding: 8px; }
.auth-card .totp-secret {
  font-family: var(--font-mono);
  font-size: 13px;
  background: var(--paper-sunken);
  padding: 8px 10px;
  border-radius: 3px;
  text-align: center;
  letter-spacing: 1px;
  word-break: break-all;
  margin-bottom: 14px;
}
