:root {
  --ink: #16233B;
  --ink-soft: #55627A;
  --paper: #EFEBDF;
  --panel: #FBF9F3;
  --forest: #1F4B3F;
  --gold: #A97A2E;
  --rust: #8B4030;
  --line: #D9D2BE;
  --line-dark: #2A3A56;
  font-size: 16px;
}

* { box-sizing: border-box; }

/* The hidden attribute must always win over any component's own display
   rule (.app { display: grid }, .modal-backdrop { display: flex }, etc.) -
   without this, elements marked hidden can still render because a later,
   more specific author rule overrides the browser's default [hidden] style. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'IBM Plex Sans', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2 {
  font-family: 'Source Serif 4', Georgia, serif;
  font-weight: 500;
  margin: 0;
}

.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

/* ---------- Auth screen ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ink);
}
.auth-card {
  background: var(--panel);
  border-radius: 8px;
  padding: 32px 32px 26px;
  width: 360px;
  max-width: 90vw;
}
.auth-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}
.auth-brand .brand-name { color: var(--ink); font-size: 19px; }
.auth-tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.auth-tab {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 0 10px;
  font-family: inherit;
  font-size: 14px;
  color: var(--ink-soft);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.auth-tab.active { color: var(--forest); border-bottom-color: var(--forest); }
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-soft); }
.auth-form input {
  font-family: inherit; padding: 9px 10px; border: 1px solid var(--line); border-radius: 5px; font-size: 14px;
}
.auth-form button {
  margin-top: 4px;
  background: var(--forest);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}
.auth-hint { font-size: 12px; color: var(--ink-soft); margin: -4px 0 0; line-height: 1.4; }

/* ---------- Rail ---------- */
.rail {
  background: var(--ink);
  color: #E7E9EF;
  display: flex;
  flex-direction: column;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.rail-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 24px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  flex-shrink: 0;
  display: block;
}

.brand-name {
  font-family: 'Source Serif 4', serif;
  font-size: 17px;
  line-height: 1.2;
}
.brand-name--small { font-size: 14px; color: #E7E9EF; }

.primary-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 6px;
}
.primary-nav-item {
  text-align: left;
  background: none;
  border: none;
  color: #C6CADA;
  padding: 9px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}
.primary-nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.primary-nav-item.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-left: 2px solid var(--gold);
  padding-left: 8px;
}

.rail-nav {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.rail-loading { color: #8892A6; font-size: 14px; padding: 8px 10px; }

.rail-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: 9px 10px;
  border-radius: 5px;
  border: none;
  background: none;
  color: #C6CADA;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  width: 100%;
}

.rail-item:hover { background: rgba(255,255,255,0.06); color: #fff; }

.rail-item.active {
  background: rgba(255,255,255,0.1);
  color: #fff;
  border-left: 2px solid var(--gold);
  padding-left: 8px;
}

.rail-item-sub {
  font-size: 11px;
  color: #8892A6;
}

.rail-divider {
  height: 1px;
  background: var(--line-dark);
  margin: 10px 2px;
}

.rail-add {
  margin-top: 14px;
  background: transparent;
  border: 1px solid var(--line-dark);
  color: #C6CADA;
  padding: 9px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13.5px;
}

.rail-add:hover { border-color: var(--gold); color: #fff; }

.rail-user {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line-dark);
  font-size: 12px;
  color: #8892A6;
  word-break: break-all;
}

/* ---------- Main ---------- */
.main {
  padding: 36px 44px 60px;
  max-width: 980px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 26px;
  gap: 16px;
  flex-wrap: wrap;
}

.eyebrow-plain {
  margin: 0 0 2px;
  color: var(--ink-soft);
  font-size: 13px;
}

.topbar h1 {
  font-size: 28px;
}

.topbar-actions { display: flex; gap: 8px; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13.5px;
}
.btn-ghost:hover { border-color: var(--forest); color: var(--forest); }

/* ---------- Summary ---------- */
.summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 28px;
  padding: 26px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  margin-bottom: 30px;
}

.summary-figure { display: flex; flex-direction: column; gap: 4px; }

.summary-label { font-size: 13px; color: var(--ink-soft); }

.summary-value {
  font-family: 'Source Serif 4', serif;
  font-size: 34px;
  color: var(--forest);
}
.summary-figure:nth-child(2) .summary-value { color: var(--rust); }
.summary-figure--net .summary-value { color: var(--ink); }

/* ---------- Panels ---------- */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 22px 24px;
  margin-bottom: 22px;
}

.panel-head { margin-bottom: 14px; }
.panel-head h2 { font-size: 18px; }
.panel-note { margin: 4px 0 0; font-size: 12.5px; color: var(--ink-soft); }

.chart-wrap { position: relative; }

.bars { display: flex; flex-direction: column; gap: 10px; }

.bar-row { display: grid; grid-template-columns: 140px 1fr 90px; align-items: center; gap: 10px; font-size: 13.5px; }
.bar-row .bar-label { color: var(--ink-soft); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 4px; }
.bar-fill.revenue { background: var(--forest); }
.bar-fill.expense { background: var(--rust); }
.bar-row .bar-value { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Entry form ---------- */
.entry-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.entry-form-wide { grid-column: 1 / -1; }
.entry-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-soft); }
.label-optional { font-weight: 400; color: var(--ink-soft); opacity: 0.75; font-size: 12px; }
.entry-form input, .entry-form select, .entry-form textarea {
  font-family: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
}
.entry-form textarea { resize: vertical; min-height: 64px; }
.entry-form button {
  grid-column: 1 / -1;
  justify-self: start;
  margin-top: 4px;
  background: var(--forest);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
}
.entry-form button:hover { background: #163b31; }

.form-msg { margin: 10px 0 0; font-size: 13px; }
.form-msg.error { color: var(--rust); }
.form-msg.ok { color: var(--forest); }

.import-row { display: flex; gap: 10px; align-items: center; }
.import-row button {
  background: var(--ink);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
}

/* ---------- Table ---------- */
.ledger-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.ledger-table th {
  text-align: left;
  font-weight: 500;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
  padding: 8px 6px;
}
.ledger-table th.num, .ledger-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.ledger-table td {
  padding: 9px 6px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.ledger-table .empty-row { color: var(--ink-soft); text-align: center; padding: 24px 0; }
.ledger-table .del-btn {
  background: none;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 12px;
}
.ledger-table .del-btn:hover { color: var(--rust); }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(22,35,59,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 20;
}
.modal {
  background: var(--panel);
  border-radius: 8px;
  padding: 26px 28px;
  width: 380px;
  max-width: 90vw;
}
.modal h3 { font-family: 'Source Serif 4', serif; margin: 0 0 14px; font-size: 19px; }
.modal label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-soft); margin-bottom: 12px; }
.modal input, .modal select {
  font-family: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 5px; font-size: 14px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.modal-actions button { font-family: inherit; padding: 8px 14px; border-radius: 5px; cursor: pointer; font-size: 13.5px; }
.modal-actions .primary { background: var(--forest); color: #fff; border: none; }
.modal-actions .secondary { background: none; border: 1px solid var(--line); color: var(--ink); }
.modal .ledger-setup-categories { grid-template-columns: 1fr; }
.modal.modal--wide { width: 460px; }

@media (max-width: 780px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: static; height: auto; }
  .main { padding: 24px; }
  .summary { grid-template-columns: 1fr; }
  .entry-form { grid-template-columns: 1fr 1fr; }
}

/* ---------- New sections: dashboard roadmap, settings ---------- */
.panel--roadmap { background: transparent; border-style: dashed; }

.settings-ledger-picker {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  color: var(--ink-soft);
  max-width: 280px;
  margin-bottom: 18px;
}
.settings-ledger-picker select,
.entry-form select {
  font-family: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  font-size: 14px;
}

.settings-categories { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
@media (max-width: 780px) { .settings-categories { grid-template-columns: 1fr; } }

.cat-group h3 { font-size: 14px; font-weight: 500; margin: 0 0 10px; color: var(--ink-soft); }
.cat-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.cat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 13.5px;
}
.cat-row button {
  background: none;
  border: none;
  color: var(--ink-soft);
  cursor: pointer;
  font-size: 12px;
}
.cat-row button:hover { color: var(--rust); }
.cat-add-row { display: flex; gap: 8px; }
.cat-add-row input {
  flex: 1;
  font-family: inherit;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 13.5px;
}
.cat-add-row button {
  background: var(--forest);
  color: #fff;
  border: none;
  padding: 7px 14px;
  border-radius: 5px;
  cursor: pointer;
  font-family: inherit;
  font-size: 13px;
}

.ledger-setup-categories {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-top: 4px;
}
.ledger-setup-categories textarea {
  font-family: inherit;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 13.5px;
  resize: vertical;
  min-height: 60px;
}
