:root {
  --paper: #f3efe6;
  --ink: #1d211c;
  --muted: #6b6560;
  --line: #d8d0c4;
  --sidebar: #1b2420;
  --sidebar-text: #d7ddd6;
  --accent: #9b4324;
  --accent-dark: #7d341c;
  --paid: #2d6a4f;
  --moved: #9a6b2f;
  --cancelled: #6b6560;
  --planned: #2c5f7c;
  --panel: #fbf8f2;
  --white: #fffdf8;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "IBM Plex Sans", sans-serif;
  background: var(--paper);
  color: var(--ink);
}

a { color: inherit; }
h1, h2, h3 { font-family: "IBM Plex Serif", serif; font-weight: 600; margin: 0; }
h1 { font-size: 28px; letter-spacing: -0.02em; }
h2 { font-size: 18px; }
h3 { font-size: 14px; font-family: "IBM Plex Sans", sans-serif; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

.shell { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-text);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand-mark {
  width: 36px; height: 36px;
  border: 1px solid #c4b8a4;
  display: grid; place-items: center;
  font-family: "IBM Plex Serif", serif;
  font-weight: 600;
}
.brand-title { font-weight: 600; font-size: 14px; }
.brand-sub { color: #9aa59a; font-size: 12px; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a {
  text-decoration: none;
  padding: 8px 10px;
  color: var(--sidebar-text);
  border-left: 2px solid transparent;
}
.nav a.is-active, .nav a:hover { border-left-color: #c4b8a4; background: rgba(255,255,255,0.04); }
.sidebar-user { margin-top: auto; font-size: 13px; }
.user-name { font-weight: 600; }
.user-login { color: #9aa59a; margin-bottom: 8px; }
.link-btn {
  background: none; border: 0; color: #c4b8a4; cursor: pointer; padding: 0; font: inherit;
}

.main { padding: 28px 36px 64px; max-width: 1400px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 22px; }
.eyebrow { font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.muted { color: var(--muted); }
.head-actions, .form-actions, .dialog-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); background: var(--white);
  color: var(--ink); text-decoration: none; cursor: pointer;
  padding: 8px 12px; font: inherit; font-size: 13px;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: #8a2f2f; border-color: #8a2f2f; color: #fff; }
.btn-tiny { padding: 4px 8px; font-size: 12px; }
.btn-block { width: 100%; }
.inline-form { display: inline; }

.date-jump input { height: 36px; border: 1px solid var(--line); background: var(--white); font: inherit; padding: 0 8px; }

.totals { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.totals-five { grid-template-columns: repeat(5, 1fr); }
.stat { background: var(--panel); border: 1px solid var(--line); padding: 14px 16px; }
.stat-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.stat-value { font-family: "IBM Plex Serif", serif; font-size: 22px; margin-top: 6px; }
.stat-count { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat.is-paid .stat-value { color: var(--paid); }
.stat.is-moved .stat-value { color: var(--moved); }
.stat.is-cancelled .stat-value { color: var(--cancelled); }
.stat.is-overdue .stat-value { color: var(--accent); }

.filters { display: grid; grid-template-columns: 2fr 1.4fr 1.1fr 1.1fr auto; gap: 8px; margin-bottom: 22px; }
.field-input, select.field-input, textarea.field-input {
  width: 100%; border: 1px solid var(--line); background: var(--white);
  font: inherit; padding: 8px 10px; color: var(--ink);
}
textarea.field-input { resize: vertical; }

.org-block { margin-bottom: 28px; background: var(--panel); border: 1px solid var(--line); }
.org-head { display: flex; justify-content: space-between; align-items: baseline; padding: 14px 16px; border-bottom: 1px solid var(--line); background: #ece6da; }
.org-total { font-family: "IBM Plex Serif", serif; font-size: 18px; }
.cost-block { padding: 8px 0 4px; }
.cost-head { display: flex; justify-content: space-between; padding: 10px 16px 6px; color: var(--muted); }

.ledger { width: 100%; border-collapse: collapse; font-size: 13px; }
.ledger th { text-align: left; font-weight: 500; color: var(--muted); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.ledger td { padding: 10px 12px; border-bottom: 1px solid #efe8dc; vertical-align: top; }
.col-amount { width: 140px; font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.col-date { width: 110px; white-space: nowrap; }
.col-status { width: 160px; }
.col-tags { width: 150px; }
.col-actions { width: 210px; white-space: nowrap; }
.purpose { text-decoration: none; font-weight: 500; }
.purpose:hover { text-decoration: underline; }

.badge { display: inline-block; font-size: 11px; letter-spacing: 0.04em; text-transform: uppercase; padding: 3px 7px; border: 1px solid currentColor; }
.badge.is-planned, .badge.is-planned { color: var(--planned); }
.badge.is-paid { color: var(--paid); }
.badge.is-moved, .badge.is-rescheduled { color: var(--moved); }
.badge.is-cancelled { color: var(--cancelled); }
.moved-to { font-size: 12px; margin-top: 4px; color: var(--moved); }
.moved-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
tr.is-paid td { color: #3d5a45; }
tr.is-cancelled td { color: var(--cancelled); text-decoration: line-through; }
tr.is-cancelled .col-actions, tr.is-cancelled .badge, tr.is-cancelled .tag { text-decoration: none; }
tr.is-moved td { background: #f7f0e4; }
tr.is-overdue td { background: #f8ece6; }
.overdue-why { font-size: 12px; margin-top: 4px; color: var(--accent); }
.bucket { margin-bottom: 28px; }
.bucket-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 10px; }
.bucket-head h2 { font-size: 20px; }
.bucket-meta { color: var(--muted); font-size: 13px; }
.bucket-overdue .bucket-head h2 { color: var(--accent); }

.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 6px;
  margin: 0 4px 4px 0;
  border: 1px solid var(--tag, var(--line));
  color: var(--tag, var(--ink));
}

.empty, .flash { padding: 14px 16px; border: 1px solid var(--line); background: var(--white); margin-bottom: 12px; }
.flash-error, .flash-error { border-color: #c47a7a; }
.flash-success { border-color: #8aaa96; }
.flash-stack { margin-bottom: 12px; }

.panel { background: var(--panel); border: 1px solid var(--line); padding: 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.form-stack { display: flex; flex-direction: column; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.field span, .field legend { color: var(--muted); }
.field-wide { grid-column: 1 / -1; }
.field-error { color: #9b2c2c; font-size: 12px; }
.tag-checks { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 10px 16px; }
.tag-checks label { display: flex; gap: 6px; align-items: center; }
.form-actions { margin-top: 8px; }

.detail-grid { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.kv { display: grid; gap: 10px; margin: 0; }
.kv div { display: grid; grid-template-columns: 180px 1fr; gap: 10px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.timeline { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-direction: column; gap: 14px; }
.timeline .time { font-size: 12px; color: var(--muted); }
.timeline .move { font-family: "IBM Plex Serif", serif; margin: 2px 0; }

.tabs { display: flex; gap: 0; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs a { text-decoration: none; padding: 8px 14px; color: var(--muted); }
.tabs a.is-active { color: var(--ink); border-bottom: 2px solid var(--accent); }
.split { display: grid; grid-template-columns: 320px 1fr; gap: 16px; }
.row-form { display: flex; gap: 8px; align-items: center; padding: 8px 0; }
.row-form .field-input { flex: 1; }
.check-inline { display: flex; gap: 6px; align-items: center; font-size: 13px; white-space: nowrap; }

.phone-qr-btn { margin: 10px 0 12px; width: 100%; }
.phone-qr-box { padding: 20px; display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center; }
.phone-qr-box img { width: 240px; height: 240px; background: #fff; border: 1px solid var(--line); }
.phone-qr-url { font-size: 12px; color: var(--muted); word-break: break-all; margin: 0; }
.dialog { border: 1px solid var(--line); background: var(--white); padding: 0; width: min(480px, 92vw); }
.dialog form { padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.dialog::backdrop { background: rgba(29, 33, 28, 0.35); }
.dialog-lead { margin: 0; color: var(--muted); }

.login-body { min-height: 100vh; display: grid; place-items: center; background: var(--sidebar); }
.login-card { width: 360px; background: var(--paper); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.brand-login { color: var(--ink); margin-bottom: 8px; }

.form-stack p { margin: 0; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.form-stack label { color: var(--muted); }

@media (max-width: 1100px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; }
  .nav { flex-direction: row; }
  .sidebar-user { margin-top: 0; }
  .totals, .totals-five, .filters, .form-grid, .detail-grid, .split { grid-template-columns: 1fr; }
  .col-actions { white-space: normal; }
  .phone-qr-btn { display: none; }
}
