/* The officer hub's Budget section (/js/hub/budget.js), its dialogs (/js/hub/budget-editor.js) and the
   dashboard's Budget card. Colors come from the tokens in app.css, so light and dark both work. Money in
   and money out differ by a sign and a word (In, Out) as well as a mark's color; numbers stay in text
   colors. Class names start with bud-.

   The two mark colors (the category bars and the request meters) were checked with the data
   visualization palette validator against both themes' card color (#111a2e dark, #ffffff light): inside
   the lightness band, above the chroma floor, apart for red-green color blindness (Delta E 20) and at
   least 3:1 against the card. Money not here yet (pending, expected, approved) is an outline of the same
   color, not another shade, so it reads by its shape. */

:root {
  --bud-out: #0891b2;
  --bud-in: #65a30d;
}

/* ---------- the top ---------- */

.bud-readonly {
  display: flex; align-items: flex-start; gap: 8px; max-width: 760px;
  margin: -6px 0 16px; padding: 10px 12px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line); color: var(--muted); font-size: 14px;
}
.bud-readonly .hub-icon { flex: none; margin-top: 2px; }

.bud-toolbar { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px 16px; margin: 0 0 14px; }
.bud-term { display: flex; align-items: center; gap: 10px; }
.bud-term label { margin: 0; }
/* The same width as the Attendance view's Term picker (hub-checkin.css). */
.bud-term select { width: auto; min-width: 160px; min-height: 42px; }
.bud-body[aria-busy="true"] { opacity: 0.6; }

/* ---------- the five numbers ---------- */

/* The hub's number tiles (.hub-tile in hub.css), the balance first and a little wider. */
.bud-tiles-wrap { margin: 0 0 28px; }
.bud-tiles { grid-template-columns: minmax(0, 1.3fr) repeat(4, minmax(0, 1fr)); }
.bud-tile.is-balance { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.bud-tile.is-negative .hub-tile-n { color: var(--danger); }
.bud-tile.is-negative .hub-tile-sub { color: var(--danger); font-weight: 650; }
.bud-projected { margin: 10px 0 0; font-size: 13px; }

/* ---------- entries ---------- */

.bud-entries { margin: 0 0 28px; }
.bud-h { margin: 0; font-size: 18px; }
.bud-h:focus { outline: none; }
.bud-section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 10px; }
.bud-filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; margin: 0 0 10px; }
.bud-search { position: relative; flex: 1 1 220px; max-width: 440px; }
.bud-search-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.hub .bud-search input[type="search"] { padding-left: 38px; }
.bud-filter { display: grid; gap: 4px; min-width: 0; }
.bud-filter label { margin: 0; font-size: 13px; color: var(--muted); }
.bud-filter select { width: auto; min-width: 170px; max-width: 100%; min-height: 46px; }
.bud-summary-row { display: flex; align-items: center; flex-wrap: wrap; gap: 2px 8px; margin: 0 0 10px; }
.bud-summary { margin: 0; color: var(--muted); font-size: 14px; }
/* No padding of its own: the row's gap keeps it apart, and wrapped onto its own line it starts where
   the words above start. */
.bud-summary-row .btn.linkish { min-height: 32px; padding: 0; font-size: 14px; }
.bud-receipt-nudge { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; margin: 0 0 10px; font-size: 14px; }
.bud-receipt-nudge .hub-icon { color: var(--warn); }
.bud-receipt-nudge .btn.linkish { min-height: 32px; padding: 0; font-size: 14px; }

/* Never clips: if the table is ever wider than the page, it scrolls sideways inside its box. */
.bud-table-box { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.bud-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; }
.bud-table th, .bud-table td { padding: 11px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.bud-table tbody tr:last-child td { border-bottom: 0; }
.bud-table th { color: var(--muted); font-size: 12px; font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; white-space: nowrap; }
.bud-table tbody tr:hover td { background: color-mix(in srgb, var(--surface-2) 55%, var(--surface)); }
.bud-table .bud-c-date { width: 72px; white-space: nowrap; color: var(--muted); font-variant-numeric: tabular-nums; }
.bud-table .bud-c-desc { min-width: 220px; }
.bud-table .bud-c-cat { min-width: 110px; }
.bud-table .bud-c-status, .bud-table .bud-c-receipt { white-space: nowrap; }
.bud-table .bud-c-amt { text-align: right; white-space: nowrap; }
.bud-table .bud-c-edit { width: 1%; padding-left: 4px; }
.bud-date-cat, .bud-sub-cat, .bud-sub-who { display: none; }
.bud-table td.bud-c-status, .bud-table td.bud-c-edit { padding-top: 9px; }

.bud-open {
  display: inline; padding: 0; margin: 0; border: 0; background: none; color: var(--text);
  font: inherit; font-weight: 750; text-align: left; cursor: pointer; overflow-wrap: anywhere;
  text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px;
}
.bud-open:hover { color: var(--accent); text-decoration-color: var(--accent); }
.bud-open:focus-visible { outline-offset: 3px; border-radius: 4px; }
.bud-sub { display: flex; flex-wrap: wrap; gap: 2px 12px; margin-top: 3px; color: var(--muted); font-size: 13px; }
.bud-party { overflow-wrap: anywhere; }
.bud-tag { display: inline-flex; align-items: center; gap: 4px; overflow-wrap: anywhere; }
.bud-tag .hub-icon { flex: none; }

/* An amount: the number in the text color, then In or Out with a mark of its color. */
.bud-amt { display: inline-flex; align-items: baseline; justify-content: flex-end; gap: 8px; white-space: nowrap; }
.bud-amt-n { font-weight: 800; font-size: 15px; font-variant-numeric: tabular-nums; }
.bud-amt-way {
  display: inline-flex; align-items: center; gap: 5px; min-width: 38px;
  font-size: 11px; font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
}
.bud-amt-way::before { content: ""; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.bud-amt.is-in .bud-amt-way::before { background: var(--bud-in); }
.bud-amt.is-out .bud-amt-way::before { background: var(--bud-out); }
.bud-receipt { font-weight: 650; white-space: nowrap; }
.bud-none { color: var(--muted); }
.bud-no-receipt { color: var(--warn); font-weight: 650; }
/* Two classes, so it outranks .btn.small (app.css) on phones too. */
.btn.bud-edit { min-height: 32px; }

/* Statuses: done ones solid, the ones still waiting dashed. */
.hub-badge.bud-status-planned { --c: var(--muted); border-style: dashed; }
.hub-badge.bud-status-requested { --c: var(--accent); }
.hub-badge.bud-status-approved { --c: var(--warn); }
.hub-badge.bud-status-paid, .hub-badge.bud-status-reimbursed, .hub-badge.bud-status-received { --c: var(--ok); }
.hub-badge.bud-status-expected { --c: var(--accent); border-style: dashed; }
.hub-badge.bud-req-status-draft { --c: var(--muted); border-style: dashed; }
.hub-badge.bud-req-status-submitted { --c: var(--accent); }
.hub-badge.bud-req-status-approved, .hub-badge.bud-req-status-received { --c: var(--ok); }
.hub-badge.bud-req-status-partial { --c: var(--warn); }
.hub-badge.bud-req-status-denied { --c: var(--danger); }

/* The first time: three steps. */
.bud-first { text-align: left; padding: 26px 24px; }
.bud-first .hub-empty-title { text-align: center; }
.bud-steps { max-width: 620px; margin: 12px auto 0; padding-left: 22px; color: var(--muted); display: grid; gap: 8px; }
.bud-steps strong { color: var(--text); }
.bud-first .hub-empty-action { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; }

/* ---------- funding requests and categories ---------- */

.bud-lower { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.bud-panel { padding: 18px 20px 20px; min-width: 0; }
/* As tall as the Add request button, so both panels' titles sit at one height. */
.bud-panel-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px 10px; min-height: 34px; margin: 0 0 4px; }
.bud-panel-lede { margin: 0 0 14px; font-size: 13px; }
.bud-quiet { margin: 0; color: var(--muted); }

/* The hub's small number tiles (.hub-tiles.is-small in hub.css). */
.bud-req-stats { margin: 0 0 8px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
/* An amount is never split ("$1,80" / "0.00"); hub.css lets tile numbers wrap anywhere. */
.bud-tiles .hub-tile-n, .bud-req-stats .hub-tile-n { overflow-wrap: normal; white-space: nowrap; }
.bud-meter-key { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin: 0 0 12px; font-size: 12px; }
.bud-key-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.bud-key-item .bud-key { margin-left: 0; }
.bud-req-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.bud-req { padding: 12px 14px 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); min-width: 0; }
.bud-req-top { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px 8px; }
.bud-source { font-size: 11px; font-weight: 750; letter-spacing: 0.07em; text-transform: uppercase; color: var(--muted); }
.bud-req-title { margin: 6px 0 8px; font-size: 15px; }
.bud-req-nums { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin: 0 0 8px; }
.bud-req-nums dt { font-size: 12px; font-weight: 650; color: var(--muted); }
.bud-req-nums dd { margin: 0; font-weight: 750; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
/* The whole track is the amount asked; the outline is what was approved, the solid part what came in. */
.bud-meter { position: relative; height: 10px; border-radius: 999px; background: color-mix(in srgb, var(--bud-in) 14%, var(--surface-2)); }
.bud-meter-approved, .bud-meter-received { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 999px; }
.bud-meter-approved { box-shadow: inset 0 0 0 1.5px var(--bud-in); }
.bud-meter-received { background: var(--bud-in); }
.bud-req-meta { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 12px; margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.bud-req-link { font-weight: 650; }
.bud-req-nudge { display: flex; align-items: flex-start; flex-wrap: wrap; gap: 6px 8px; margin: 10px 0 0; font-size: 13px; }
.bud-req-nudge > .hub-icon { flex: none; margin-top: 2px; color: var(--warn); }
.bud-req-nudge.is-done > .hub-icon { color: var(--ok); }
.bud-req-nudge p { flex: 1 1 180px; min-width: 0; margin: 0; }
.bud-req-nudge .btn { flex: none; min-height: 34px; }

.bud-cat-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.bud-cat { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: baseline; gap: 2px 10px; }
.bud-cat-pick {
  justify-self: start; min-height: 30px; padding: 0; border: 0; background: none; color: var(--text);
  font: inherit; font-weight: 700; text-align: left; cursor: pointer;
  text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px;
}
.bud-cat-pick:hover { color: var(--accent); text-decoration-color: var(--accent); }
.bud-cat-pick[aria-pressed="true"] { text-decoration-color: currentColor; }
.bud-cat-pick[aria-pressed="true"]::after { content: " (shown)"; font-weight: 600; color: var(--muted); }
.bud-cat-figures { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; text-align: right; }
/* One bar per category, segments 2px apart, square at the start and rounded at the end. */
.bud-cat-bars { grid-column: 1 / -1; display: flex; gap: 2px; height: 10px; }
/* Wide enough that a small amount reads as a bar, not a letter. */
.bud-cat-bar { min-width: 16px; }
.bud-cat-bar:last-child { border-radius: 0 4px 4px 0; }
.bud-cat-bar.is-out, .bud-key.is-out { background: var(--bud-out); }
.bud-cat-bar.is-in, .bud-key.is-in { background: var(--bud-in); }
.bud-cat-bar.is-pending, .bud-key.is-pending { box-shadow: inset 0 0 0 1.5px var(--bud-out); }
.bud-cat-bar.is-expected, .bud-key.is-expected, .bud-key.is-approved { box-shadow: inset 0 0 0 1.5px var(--bud-in); }
.bud-cat-key { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin: 14px 0 0; font-size: 12px; }
.bud-key { display: inline-block; width: 12px; height: 10px; border-radius: 2px; margin-left: 8px; }
.bud-key:first-child { margin-left: 0; }

/* ---------- the dialogs ---------- */

.bud-dialog .hub-field { margin-bottom: 14px; }
.bud-dialog .bud-field-error { margin: 6px 0 0; }
.bud-ed-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.bud-ed-grid > [hidden] { display: none !important; }
.bud-dialog input[type="date"] { min-width: 0; }
.bud-way { margin: 0 0 14px; }
.bud-way-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.bud-way-option { position: relative; margin: 0; cursor: pointer; }
.bud-way-option input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.bud-way-face {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 14px;
  border-radius: 10px; border: 1px solid var(--line-strong); background: var(--bg); font-weight: 700;
}
.bud-way-sign {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  font-size: 18px; font-weight: 800; line-height: 1; background: var(--surface-2); color: var(--text);
}
.bud-way-option input:checked + .bud-way-face { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--surface-2); }
.bud-way-option.is-income input:checked + .bud-way-face .bud-way-sign { background: var(--bud-in); color: #0b1220; }
/* Dark signs on both marks: white on the cyan was 3.7:1, this is over 5:1. */
.bud-way-option.is-expense input:checked + .bud-way-face .bud-way-sign { background: var(--bud-out); color: #0b1220; }
.bud-way-option input:focus-visible + .bud-way-face { outline: 2px solid var(--accent); outline-offset: 2px; }
.bud-money-wrap { position: relative; }
.bud-money-sign { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 700; pointer-events: none; }
.bud-dialog .bud-money-input { padding-left: 28px; font-variant-numeric: tabular-nums; }
.bud-record { margin: 4px 0 0; font-size: 13px; }
.bud-linked { display: flex; align-items: flex-start; gap: 6px; margin: 0 0 8px; font-size: 13px; }
.bud-linked .hub-icon { flex: none; margin-top: 2px; }
.bud-conflict { margin: 0 0 14px; }
.bud-conflict p { margin: 0 0 8px; }
.hub-dialog-actions .bud-ed-delete { margin-right: auto; }

.bud-details { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 16px; margin: 0 0 12px; }
.bud-details dt { color: var(--muted); font-weight: 650; font-size: 14px; }
.bud-details dd { margin: 0; overflow-wrap: anywhere; }
.bud-notes { margin: 0; white-space: pre-wrap; }
.bud-readonly-note { display: flex; align-items: center; gap: 6px; margin: 8px 0 0; font-size: 13px; }

/* ---------- the dashboard's Budget card ---------- */

/* The hub's number tiles, small (.hub-tiles.is-small in hub.css). */
.dash-bud-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.dash-bud-tile.is-negative .hub-tile-n { color: var(--danger); }
.dash-bud-foot { margin: 8px 0 0; font-size: 13px; }

/* ---------- narrower screens ---------- */

@media (max-width: 1099px) {
  .bud-tiles { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .bud-tile.is-balance { grid-column: 1 / -1; }
}

/* Middle widths: Category and Handled by move under what it was for. */
@media (min-width: 900px) and (max-width: 1099px) {
  .bud-table .bud-c-cat, .bud-table .bud-c-who { display: none; }
  .bud-sub-cat, .bud-sub-who { display: inline; }
}

/* Tablets and phones: a card per entry (the table's columns do not fit below 900px). */
@media (max-width: 899px) {
  .bud-lower { grid-template-columns: minmax(0, 1fr); }

  /* Positioned, so the column titles kept for screen readers stay inside it instead of reaching past the page. */
  .bud-table-box { position: relative; background: transparent; border: 0; box-shadow: none; border-radius: 0; overflow: visible; }
  .bud-table, .bud-table thead, .bud-table tbody { display: block; width: 100%; }
  .bud-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  /* A card: what it was for and the amount, then the day and category, the status and who, then the
     receipt and Change. */
  .bud-table tbody tr {
    display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 6px 10px; align-items: center;
    grid-template-areas: "desc desc amt" "date date date" "status who who" "receipt receipt edit";
    margin-bottom: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
  }
  .bud-table td { display: block; min-width: 0; width: auto; padding: 0; border: 0; background: transparent; white-space: normal; overflow-wrap: anywhere; }
  .bud-table tbody tr:hover td { background: transparent; }
  .bud-table td.bud-c-desc { grid-area: desc; align-self: start; min-width: 0; }
  .bud-table td.bud-c-amt { grid-area: amt; align-self: start; }
  .bud-table .bud-amt { display: grid; justify-items: end; gap: 0; }
  .bud-table td.bud-c-date { grid-area: date; width: auto; }
  .bud-table td.bud-c-cat { display: none; }
  .bud-date-cat { display: inline; color: var(--muted); }
  .bud-date-cat::before { content: "\00B7"; margin: 0 8px; }
  .bud-table td.bud-c-status { grid-area: status; padding: 0; }
  .bud-table td.bud-c-who { grid-area: who; display: block; color: var(--text); }
  .bud-table td.bud-c-who:not(:empty)::before { content: "Handled by "; color: var(--muted); }
  .bud-table td.bud-c-receipt { grid-area: receipt; }
  .bud-table td.bud-c-receipt.is-empty { visibility: hidden; }
  .bud-table tr.is-readonly td.bud-c-receipt.is-empty { display: none; }
  .bud-table td.bud-c-edit { grid-area: edit; width: auto; padding: 0; justify-self: end; }
  .btn.bud-edit { min-height: 44px; padding: 0 16px; }
}

/* Tablets: two cards across, so a card is not 736px wide for three short lines. */
@media (min-width: 600px) and (max-width: 899px) {
  .bud-table tbody { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .bud-table tbody tr { margin-bottom: 0; align-content: start; }
}

/* Phones: the filters one under the other, the numbers two across. */
@media (max-width: 759px) {
  /* Tap targets of at least 44 px (app.css): an entry's title opens it (for read-only seats the only
     way), its Receipt link, a request's link, the category filters and Show it. The negative margin
     keeps the row as it was. */
  .bud-open, .bud-receipt, .bud-req-link { display: inline-block; min-height: 44px; padding: 12px 0; margin: -12px 0; }
  .bud-cat-pick { min-height: 44px; }
  .bud-summary-row .btn.linkish, .bud-receipt-nudge .btn.linkish, .hub .btn.linkish { min-height: 44px; }
  .bud-toolbar { align-items: stretch; }
  .bud-term { width: 100%; }
  .bud-term select { flex: 1 1 auto; min-width: 0; }
  .bud-toolbar .btn { width: 100%; min-height: 44px; }
  .bud-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .bud-tiles .hub-tile-n { font-size: 22px; }
  .bud-tile.is-balance .hub-tile-n { font-size: 26px; }
  .bud-tiles .hub-tile-sub { font-size: 12px; }
  .bud-filters { display: grid; grid-template-columns: minmax(0, 1fr); }
  .bud-search { max-width: none; }
  .bud-filter select { width: 100%; min-width: 0; }

  .bud-panel { padding: 16px; }
  .bud-req-stats { gap: 6px; }
  /* .hub-tiles.is-small in the selectors: hub.css's small tiles (padding 9px 12px, 21px) outranked these. */
  .hub-tiles.is-small.bud-req-stats .hub-tile { padding: 8px; }
  .hub-tiles.is-small.bud-req-stats .hub-tile-n { font-size: 16px; }
  .bud-req-nums dd { font-size: 14px; }
  .bud-req-nudge .btn { min-height: 44px; }
  .bud-cat { grid-template-columns: minmax(0, 1fr); }
  .bud-cat-figures { text-align: left; }
  .bud-first { padding: 22px 16px; }
  .bud-first .hub-empty-action .btn { flex: 1 1 100%; min-height: 44px; }

  .bud-ed-grid { grid-template-columns: minmax(0, 1fr); }
  .bud-details { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .bud-details dd { margin-bottom: 8px; }
}

/* Three amounts across need about 100 px each ("$1,800.00" is 83 px at 16px, measured): below 420 wide
   they stack, one a row. */
@media (max-width: 419px) {
  .bud-req-stats { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 359px) {
  .bud-tiles { grid-template-columns: minmax(0, 1fr); }
  .bud-req-nums { grid-template-columns: minmax(0, 1fr); }
  .bud-way-options { grid-template-columns: minmax(0, 1fr); }
}
