/* BlackBudget web theme -- a faithful port of the desktop's QSS (ui/styles/theme.qss).
   Tokens and structures mirror the PySide6 app: ivory base, charcoal text,
   per-page accent bars (Budget charcoal / Income olive / Expense red), bordered
   group frames with on-border titles, compact tables with alternating rows,
   slim olive scrollbars, dot-leader rows, sign-colored money.

   Layout philosophy (matches the desktop window): page grids take a DEFINITE
   height from the viewport and frames scroll INTERNALLY -- never the page.
   (Indefinite-height fr-grids size against the largest frame's content, which
   blew the first cut up; definite heights are the structural fix.)
   The mobile arrangement (web/DESIGN.md) arrives in a later phase. */

:root {
  --ivory: #F2EFDE; --charcoal: #2E2E2E; --red: #7A2D32; --olive: #464A3C;
  --light: #E6E2D5; --light-hover: #DAD4C2; --light-press: #CFC8B2;
  --gridline: #DAD4C2; --alt-row: #ECE8D6; --table-border: #BFB9A6;
  --neg-wash: #EEE0E2; --disabled: #9B9B9B;
  --miss-amber: #C8860D; --miss-red: #B23A3A;
  --accent: var(--olive); /* per-page; overridden by body[data-page] */
}
body[data-page="budget"]   { --accent: var(--charcoal); }
body[data-page="income"]   { --accent: var(--olive); }
body[data-page="expense"]  { --accent: var(--red); }
body[data-page="settings"] { --accent: var(--charcoal); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--ivory); color: var(--charcoal);
  font-family: "Reem Kufi", "Segoe UI", sans-serif; font-size: 15px;
}

/* ---- Chrome: accent banner with the three tabs (mirrors NavBar) ---- */
.banner {
  background: var(--accent); display: flex; align-items: flex-end;
  padding: 7px 16px 0 16px; gap: 2px; min-height: 44px;
}
.banner .tab {
  background: rgba(242, 239, 222, .25); color: var(--ivory);
  padding: 7px 24px 8px 24px; font-weight: bold; text-decoration: none;
  border-radius: 3px 3px 0 0; font-size: 14px;
}
.banner .tab.active { background: var(--ivory); color: var(--accent); }
/* The settings gear sits at the banner's far left (top-left corner). */
.banner .gear {
  color: var(--ivory); text-decoration: none; font-size: 17px;
  padding: 4px 8px 8px 2px; align-self: center;
}
.banner .gear.active, .banner .gear:hover { color: var(--light-press); }
.banner .tab:hover:not(.active) { background: rgba(242, 239, 222, .4); }
.banner .spacer { flex: 1; }
.banner .session { color: var(--ivory); font-size: 12px; padding-bottom: 9px; display: flex; gap: 12px; align-items: center; }
/* Flash messages live INSIDE the banner so the page never shifts; they fill
   whatever space the tabs leave and shrink/ellipsize as tabs are added. */
.banner .banner-flash {
  flex: 1 1 0; min-width: 0; align-self: center; padding-bottom: 7px;
  color: var(--ivory); font-size: 12px; font-style: italic; text-align: center;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.banner .banner-flash .error { font-weight: bold; font-style: normal; }
.banner .session a, .banner .session button {
  background: none; border: 0; color: var(--ivory); text-decoration: underline;
  cursor: pointer; font-size: 12px; padding: 0; font-family: inherit;
}

/* Sub-view strip (Expense page): centered small buttons, as on the desktop. */
.subview-strip { display: flex; justify-content: center; gap: 6px; padding: 5px 0; }
.subview-strip a {
  background: var(--light); border: 1px solid var(--olive); border-radius: 3px;
  color: var(--charcoal); text-decoration: none; font-size: 12px; padding: 3px 15px;
}
.subview-strip a.active { background: var(--accent); color: var(--ivory); border-color: var(--accent); }

/* ---- Page scaffold ---- */
.page { max-width: 1720px; margin: 0 auto; padding: 4px 14px 10px 14px; }
.page-title {
  font-size: 24px; font-weight: bold; text-align: center;
  color: var(--accent); margin: 4px 0 8px 0;
}
/* 14px bottom clearance: on-border frame titles extend 9px above their frame. */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.toolbar .right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.status { color: var(--olive); font-style: italic; font-size: 13px; margin-top: 8px; min-height: 18px; }
.asof { color: var(--olive); font-size: 12px; text-align: right; margin: 0 0 10px 0; display: block; }

/* ---- Frames (QGroupBox imitation: 1px accent border, title on the border) ----
   Stacked frames need >=14px gaps so an on-border title never collides with
   the frame above it. */
.frame {
  position: relative; border: 1px solid var(--accent); border-radius: 4px;
  background: var(--ivory); padding: 13px 7px 7px 7px; min-width: 0; min-height: 0;
}
.frame > .frame-title {
  position: absolute; top: -9px; left: 10px; background: var(--ivory);
  padding: 0 5px; font-size: 12px; color: var(--accent); line-height: 16px;
  white-space: nowrap;
}
.frame .scroll { overflow-y: auto; min-height: 0; }

/* Slim olive scrollbars (10px, rounded handle) */
.scroll { scrollbar-width: thin; scrollbar-color: var(--olive) var(--ivory); }
.scroll::-webkit-scrollbar { width: 10px; height: 10px; background: var(--ivory); }
.scroll::-webkit-scrollbar-thumb { background: var(--olive); border-radius: 4px; }

/* ---- Tables (compact, alternating, bold light headers) ---- */
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  background: var(--light); font-weight: bold; text-align: left;
  padding: 2px 7px 3px 7px; border-bottom: 1px solid var(--table-border);
  position: sticky; top: 0; z-index: 1;
}
table.grid td { padding: 2px 7px; border-bottom: 1px solid var(--gridline); }
table.grid th.money { text-align: right; }  /* outranks the generic left-aligned th */
table.grid tr:nth-child(even) td { background: var(--alt-row); }
table.grid tr.neg-wash td { background: var(--neg-wash); }
table.grid tr td.wash { background: var(--neg-wash); }
td.money, th.money { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
td.date { white-space: nowrap; }
.pos { color: var(--olive); }
.neg { color: var(--red); }
.muted { color: var(--olive); }
.italic { font-style: italic; }

/* Reconciliation-miss dot: LEFT of the label; amber on the first miss, red
   from the second (mirrors ui/widgets/charge_table.py). */
.miss-dot { font-size: 10px; margin-right: 4px; vertical-align: 1px; }
.miss-dot.amber { color: var(--miss-amber); }
.miss-dot.red { color: var(--miss-red); }

/* Dot-leader rows (the desktop's LeaderRow) */
.leader { display: flex; align-items: baseline; gap: 5px; font-size: 13px; padding: 1px 2px; }
.leader .dots { flex: 1; border-bottom: 1px dotted var(--charcoal); transform: translateY(-3px); min-width: 12px; }
.leader .val { white-space: nowrap; font-variant-numeric: tabular-nums; }
.leader.bold { font-weight: bold; }
.leader-rule { border: 0; border-top: 1px solid var(--olive); width: 90px; margin: 2px 0 2px auto; }

/* ---- Page grids (desktop arrangements; definite heights, internal scroll) ---- */
.budget-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: minmax(0, 7fr) minmax(0, 3fr);
  height: calc(100vh - 168px); min-height: 540px;
}
.budget-grid .frame, .analysis-grid .frame, .stack .frame { display: flex; flex-direction: column; }
.budget-grid .frame .scroll, .analysis-grid .frame .scroll, .stack .frame .scroll { flex: 1; }
.span2 { grid-column: span 2; }

.outlook-people { display: flex; gap: 8px; }
.outlook-people .person { flex: 1; min-width: 0; }
.outlook-people .person h4 { margin: 0 0 3px 0; font-size: 12px; text-align: center; }

/* Income: panels left (receivables beneath them); yearly boxes own the right. */
.income-layout { display: grid; grid-template-columns: 3fr 1fr; gap: 14px; align-items: start; }
.income-left { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.income-people { display: flex; gap: 14px; align-items: stretch; }
.income-people .frame { flex: 1; min-width: 0; }
.income-yearly { display: flex; flex-direction: column; gap: 14px; }
.headline { display: grid; grid-template-columns: auto auto; gap: 2px 28px; justify-content: center; margin: 6px 0 8px 0; font-size: 13px; }
.deductions-header { display: flex; align-items: center; justify-content: space-between; margin-top: 5px; }
.deductions-header span { font-size: 12px; text-decoration: underline; }
.deductions-header hr { border: 0; border-top: 1px solid var(--olive); width: 90px; margin: 0; }

/* Expense Overview: three columns sharing one definite height; each column's
   frames split it evenly (as the desktop's stacked boxes do). */
.expense-overview {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px;
  height: calc(100vh - 196px); min-height: 520px;
}
.expense-overview .stack { display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.expense-overview .stack .frame { flex: 1; }

.analysis-grid {
  display: grid; gap: 14px;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
  height: calc(100vh - 196px); min-height: 520px;
}

.misc-layout { display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: start; }
.misc-layout .frame { display: flex; flex-direction: column; }
.misc-layout .frame .scroll { max-height: calc(100vh - 220px); }
.misc-actions { display: flex; flex-direction: column; gap: 8px; padding-top: 24px; }

/* ---- Buttons ---- */
button, .btn, input[type="submit"] {
  background: var(--light); border: 1px solid var(--olive); border-radius: 3px;
  color: var(--charcoal); padding: 5px 14px; cursor: pointer;
  font-family: inherit; font-size: 14px; text-decoration: none; display: inline-block;
}
button:hover, .btn:hover { background: var(--light-hover); }
button:active, .btn:active { background: var(--light-press); }
button:disabled { color: var(--disabled); border-color: var(--disabled); cursor: not-allowed; background: var(--light); }
.btn-accent, button.btn-accent { background: var(--red); color: var(--ivory); border-color: #5A1F23; }
.btn-accent:hover { background: #8C3A40; }
.icon-btn {
  width: 28px; height: 28px; padding: 0; font-weight: bold; font-size: 17px;
  line-height: 1; display: inline-flex; align-items: center; justify-content: center;
  flex: none;
}
.mark-btn { width: 42px; height: 42px; font-size: 23px; font-weight: bold; flex: none; }
.mark-btn.ok { color: var(--olive); }
.mark-btn.no { color: var(--red); }

/* ---- Action controls (the desktop's arrows / selection / dialogs) ---- */
form.mini { display: inline; margin: 0; }
.arrow-btn {
  background: none; border: 0; padding: 0 3px; cursor: pointer;
  font-size: 13px; line-height: 1; vertical-align: middle;
}
.arrow-btn.red { color: var(--red); }
.arrow-btn.green { color: var(--olive); }
td.act { width: 1%; white-space: nowrap; text-align: center; }
.payday-toggle { font-size: 12px; display: flex; align-items: center; gap: 4px; }
.frame > form.payday-toggle { margin: 0 2px 6px 0; }

/* Double-click editing happens on the value itself (desktop parity); no text
   selection flicker on interactive cells/rows. */
[data-edit-action], [data-cycle-action],
tr[data-select] td, tr[data-mark-select] td { user-select: none; }
[data-edit-action], [data-cycle-action] { cursor: pointer; }

/* Selection highlight (CLAUDE.md s10): the page accent fills the whole row,
   ivory bold text -- black on Budget, olive on Income, red on Expense. The
   selector must outrank the alternating-row and wash rules. */
table.grid tr.selected td,
table.grid tr:nth-child(even).selected td,
table.grid tr.selected td.wash {
  background: var(--accent); color: var(--ivory); font-weight: bold;
}
table.grid tr.selected td span,
table.grid tr.selected td .pos, table.grid tr.selected td .neg,
table.grid tr.selected td .muted,
table.grid tr.selected td .arrow-btn { color: var(--ivory); background: transparent; }

/* Drag-to-rank affordance on the misc table. */
tr[draggable="true"] { cursor: grab; }
tr[draggable="true"]:active { cursor: grabbing; }

/* Busy feedback while an action posts (perceived snappiness). */
body.busy, body.busy * { cursor: progress; }
body.busy button, body.busy .arrow-btn { pointer-events: none; opacity: .65; }

#actionHint { color: var(--red); font-size: 12px; min-width: 0; }

/* Styled dialogs: the web port of the desktop's frameless StyledDialog card
   (bordered ivory panel, centered accent title, accent action buttons). */
dialog.bb-dialog {
  border: 1px solid var(--accent); border-radius: 4px; background: var(--ivory);
  color: var(--charcoal); padding: 1rem 1.4rem; min-width: 360px;
  box-shadow: 0 3px 16px rgba(46, 46, 46, .35);
}
dialog.bb-dialog::backdrop { background: rgba(46, 46, 46, .45); }
dialog.bb-dialog h2 { margin: 0 0 .7rem 0; font-size: 15px; text-align: center; color: var(--accent); }
.dialog-grid { display: grid; grid-template-columns: auto 1fr; gap: 7px 10px; align-items: center; }
.dialog-grid .full { grid-column: 1 / -1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.icon-btn img { width: 18px; height: 18px; display: block; }

/* ---- Inputs ---- */
input, select, textarea {
  background: var(--ivory); border: 1px solid var(--olive); border-radius: 3px;
  color: var(--charcoal); padding: 2px 5px; font-family: inherit; font-size: 14px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--red); }
label { font-size: 13px; }
ul.errorlist { color: var(--red); padding-left: 1rem; margin: 4px 0; }

/* Selectable indicators (CLAUDE.md s10): one look everywhere -- a thin
   charcoal outline, empty until selected; checkbox -> check mark, radio ->
   filled dark center dot. */
input[type="checkbox"], input[type="radio"] {
  appearance: none; -webkit-appearance: none;
  width: 14px; height: 14px; padding: 0; margin: 0 4px 0 0;
  border: 1px solid var(--charcoal); border-radius: 2px; background: var(--ivory);
  display: inline-block; vertical-align: -2px; cursor: pointer;
}
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]:checked::before {
  content: "✓"; display: block; text-align: center;
  font-size: 11px; line-height: 12px; font-weight: bold; color: var(--charcoal);
}
input[type="radio"]:checked::before {
  content: ""; display: block; width: 8px; height: 8px; margin: 2px;
  border-radius: 50%; background: var(--charcoal);
}

/* ---- Flash messages ---- */
.flash { border: 1px solid var(--olive); border-radius: 4px; padding: .4rem .9rem; margin: .4rem auto; max-width: 1720px; font-size: 13px; }
.flash-error { border-color: var(--red); color: var(--red); }
.flash-success { color: var(--olive); }

/* ---- Simple card pages (Data / placeholders) ---- */
.card {
  border: 1px solid var(--accent); border-radius: 4px; background: var(--ivory);
  padding: 1rem 1.5rem; margin: 1.2rem auto; max-width: 680px;
}

/* ---- Auth pages (login art shell: edge-to-edge background, floats on top) ----
   The real artwork is user-co-designed (web/DESIGN.md); until it lands, the
   background is a palette-only abstract placeholder. Applies ONLY to pages
   using the auth layout. */
body.auth {
  min-height: 100vh; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  background:
    radial-gradient(ellipse 90% 60% at 12% 8%, rgba(70, 74, 60, .55), transparent 60%),
    radial-gradient(ellipse 70% 55% at 88% 90%, rgba(122, 45, 50, .5), transparent 60%),
    radial-gradient(ellipse 45% 40% at 78% 18%, rgba(230, 226, 213, .8), transparent 70%),
    radial-gradient(ellipse 55% 45% at 25% 85%, rgba(46, 46, 46, .35), transparent 65%),
    var(--ivory);
  background-attachment: fixed;
}
body.auth .auth-wordmark { max-width: min(380px, 70vw); height: auto; margin-bottom: 1rem; }
body.auth .auth-card {
  background: rgba(242, 239, 222, .92); border: 1px solid var(--olive);
  border-radius: 4px; padding: 1.3rem 1.7rem; min-width: min(360px, 90vw);
  box-shadow: 0 2px 14px rgba(46, 46, 46, .25);
}
body.auth .auth-card h2 { margin-top: 0; font-size: 16px; color: var(--charcoal); }
body.auth .auth-card label { display: block; margin-top: .6rem; }
body.auth .auth-card input[type=text], body.auth .auth-card input[type=password] {
  width: 100%; padding: 5px 7px; margin-top: 2px;
}
body.auth .auth-card button { margin-top: .9rem; }

/* Mobile is a later phase (web/DESIGN.md); until then, allow horizontal scroll
   rather than breaking the desktop-fidelity grids on a narrow screen. */
@media (max-width: 1000px) {
  .page { overflow-x: auto; }
}
