/* Video department — Budgets tab.
 *
 * Scoped entirely to the `vbg-` prefix. It deliberately does NOT reuse the
 * `.vd-budget-*` names already in video-page.css: those belong to the shoot
 * dashboard's inline budget card and to an archived rollup view, and two of
 * them (.vd-budget-bar, .vd-budget-fill) are already defined twice with
 * different geometry. A separate prefix means this tab can never be broken by
 * an edit to that card, and vice versa.
 *
 * Colour comes from the video department's --vd-* tokens (video-page.css), so
 * light/dark follow the rest of the department for free.
 */

/* === View 1 — period toolbar ============================== */
.vbg-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.vbg-seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border: 1px solid var(--vd-border, #e5e7eb);
  border-radius: 10px;
  background: var(--vd-surface, #fff);
}
.vbg-seg-btn {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--vd-text-2, #6b7280);
  padding: 6px 14px;
  border-radius: 7px;
  transition: background 120ms ease, color 120ms ease;
}
.vbg-seg-btn:hover { background: var(--vd-surface-2, #f8f9fb); color: var(--vd-text, #1a1a1a); }
.vbg-seg-btn.active {
  background: var(--vd-text, #1a1a1a);
  color: #fff;
}

.vbg-nav {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px;
  border: 1px solid var(--vd-border, #e5e7eb);
  border-radius: 10px;
  background: var(--vd-surface, #fff);
}
.vbg-nav-btn {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 5px 10px;
  border-radius: 7px;
  color: var(--vd-text-2, #6b7280);
}
.vbg-nav-btn:hover { background: var(--vd-surface-2, #f8f9fb); color: var(--vd-text, #1a1a1a); }
.vbg-period-label {
  min-width: 122px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--vd-text, #1a1a1a);
}
.vbg-caption {
  font-family: var(--vd-font-mono, monospace);
  font-size: 11px;
  color: var(--vd-text-3, #94a3b8);
}

/* === View 1 — sheet cells ================================= */
.vbg-num {
  font-family: var(--vd-font-mono, monospace);
  font-size: 13px;
  color: var(--vd-text, #1a1a1a);
  white-space: nowrap;
}
.vbg-muted { color: var(--vd-text-3, #94a3b8); font-style: normal; }
/* Over budget. Colour alone is never the only signal — the value also carries
   a leading minus and a title, so it reads without colour vision. */
.vbg-over { color: var(--vd-st-alert-fg, #b91c1c); font-weight: 700; }

.vbg-spent-cell { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.vbg-link {
  display: inline-flex;
  align-items: center;
  cursor: pointer;
  border-radius: 6px;
}
.vbg-link:hover { text-decoration: underline; text-underline-offset: 3px; }
.vbg-link:focus-visible { outline: 2px solid var(--vd-accent, #2563eb); outline-offset: 2px; }

/* === View 1 — totals bar ================================== */
.vbg-totals {
  display: flex;
  align-items: flex-start;
  gap: 32px;
  flex-wrap: wrap;
  padding: 14px 18px;
  border: 1px solid var(--vd-border, #e5e7eb);
  border-radius: var(--vd-radius, 8px);
  background: var(--vd-surface-2, #f8f9fb);
}
.vbg-totals-item { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.vbg-totals-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--vd-text-3, #94a3b8);
}
.vbg-totals-value {
  font-family: var(--vd-font-mono, monospace);
  font-size: 20px;
  font-weight: 700;
  color: var(--vd-text, #1a1a1a);
}
.vbg-totals-sub { font-size: 11px; color: var(--vd-text-2, #6b7280); }

.vbg-warn {
  flex-basis: 100%;
  font-size: 12px;
  line-height: 1.5;
  color: var(--vd-st-alert-fg, #b91c1c);
  background: var(--vd-st-alert-bg, #fef2f2);
  border: 1px solid color-mix(in srgb, var(--vd-st-alert-fg, #b91c1c) 22%, transparent);
  border-radius: var(--vd-radius-sm, 6px);
  padding: 8px 10px;
}

/* === View 2 — header ====================================== */
.vbg-hdr-meta {
  font-family: var(--vd-font-mono, monospace);
  font-size: 12px;
  color: var(--vd-text-3, #94a3b8);
}

/* === View 2 — cap + KPIs ================================== */
.vbg-head-body { display: flex; flex-direction: column; gap: 16px; }

.vbg-cap-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.vbg-cap-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--vd-text-3, #94a3b8);
  flex: 0 0 auto;
}
.vbg-cap-input {
  flex: 1 1 160px;
  min-width: 0;
  padding: 9px 12px;
  border: 1px solid var(--vd-border, #e5e7eb);
  border-radius: 8px;
  background: var(--vd-surface, #fff);
  color: var(--vd-text, #1a1a1a);
  font-family: var(--vd-font-mono, monospace);
  font-size: 15px;
}

.vbg-text-btn {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--vd-text-2, #6b7280);
  padding: 6px 8px;
  border-radius: 6px;
}
.vbg-text-btn:hover { background: var(--vd-surface-2, #f8f9fb); color: var(--vd-text, #1a1a1a); }
.vbg-text-btn:disabled { opacity: 0.5; cursor: default; }

.vbg-kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}
.vbg-kpi {
  display: flex;
  flex-direction: column;
  gap: 3px;
  min-width: 0;
  padding: 12px 14px;
  border: 1px solid var(--vd-border, #e5e7eb);
  border-radius: var(--vd-radius, 8px);
  background: var(--vd-surface-2, #f8f9fb);
}
.vbg-kpi-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--vd-text-3, #94a3b8);
}
.vbg-kpi-value {
  font-family: var(--vd-font-mono, monospace);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.15;
  color: var(--vd-text, #1a1a1a);
  overflow-wrap: anywhere;
}
.vbg-kpi-sub { font-size: 11px; color: var(--vd-text-2, #6b7280); }
.vbg-kpi-warn { font-size: 11px; font-weight: 600; color: var(--vd-st-alert-fg, #b91c1c); }

.vbg-bar {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--vd-st-mute-bg, #f1f5f9);
  overflow: hidden;
}
.vbg-bar-fill {
  height: 100%;
  border-radius: 999px;
  background: var(--vd-st-active-fg, #15803d);
  transition: width 240ms ease;
}
.vbg-bar-fill.over { background: var(--vd-st-alert-fg, #b91c1c); }

/* === View 2 — receipt dropzone ============================ */
.vbg-drop {
  display: block;
  width: 100%;
  padding: 26px 18px;
  text-align: center;
  border: 2px dashed var(--vd-border-2, #d1d5db);
  border-radius: var(--vd-radius, 8px);
  background: var(--vd-surface-2, #f8f9fb);
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}
.vbg-drop:hover { border-color: var(--vd-text-3, #94a3b8); }
.vbg-drop:focus-visible { outline: 2px solid var(--vd-accent, #2563eb); outline-offset: 2px; }
.vbg-drop.is-over {
  border-color: var(--vd-st-cold-fg, #1d4ed8);
  background: var(--vd-st-cold-bg, #eff6ff);
}
.vbg-drop.is-busy { cursor: progress; border-style: solid; }
.vbg-drop-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--vd-text, #1a1a1a);
}
.vbg-drop-hint {
  margin-top: 4px;
  font-size: 12px;
  line-height: 1.55;
  color: var(--vd-text-2, #6b7280);
  max-width: 56ch;
  margin-left: auto;
  margin-right: auto;
}

/* === View 2 — scan report ================================= */
.vbg-scan-report {
  border: 1px solid color-mix(in srgb, var(--vd-st-cold-fg, #1d4ed8) 26%, transparent);
  background: var(--vd-st-cold-bg, #eff6ff);
  border-radius: var(--vd-radius, 8px);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.vbg-scan-report.is-bad {
  border-color: color-mix(in srgb, var(--vd-st-alert-fg, #b91c1c) 26%, transparent);
  background: var(--vd-st-alert-bg, #fef2f2);
}
.vbg-scan-head {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
}
.vbg-scan-summary { font-size: 13px; font-weight: 600; color: var(--vd-text, #1a1a1a); }
.vbg-scan-note { font-size: 12px; line-height: 1.55; color: var(--vd-text-2, #6b7280); }
.vbg-scan-fails { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.vbg-scan-fail {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  font-size: 12px;
  padding: 5px 8px;
  border-radius: var(--vd-radius-sm, 6px);
  background: var(--vd-surface, #fff);
}
.vbg-scan-fail-name { font-weight: 600; color: var(--vd-text, #1a1a1a); overflow-wrap: anywhere; }
.vbg-scan-fail-err { color: var(--vd-st-alert-fg, #b91c1c); overflow-wrap: anywhere; }

/* === View 2 — expense table =============================== */
.vbg-table-body { display: flex; flex-direction: column; gap: 12px; }

/* The table is wide by nature (7 columns, three of them editable text). It
   scrolls INSIDE this box so the page itself never scrolls sideways at 390px. */
.vbg-table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--vd-border, #e5e7eb);
  border-radius: var(--vd-radius, 8px);
}
.vbg-table {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  font-size: 13px;
}
.vbg-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  padding: 9px 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--vd-text-2, #6b7280);
  background: var(--vd-surface-2, #f8f9fb);
  border-bottom: 1px solid var(--vd-border, #e5e7eb);
  white-space: nowrap;
}
.vbg-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #f0f0f2;
  vertical-align: top;
}
.vbg-table tbody tr:last-child td { border-bottom: none; }

.vbg-td-receipt { width: 76px; }
.vbg-td-amount { width: 190px; }
.vbg-td-actions { width: 44px; text-align: right; }
.vbg-td-draft-actions { width: 140px; white-space: nowrap; }

/* Row states. Each is a LEFT BAR plus a tint, never a tint alone, and each is
   paired with a text chip in the row — colour is never the only carrier. */
.vbg-row-new { background: color-mix(in srgb, var(--vd-st-cold-fg, #1d4ed8) 6%, transparent); }
.vbg-row-lowconf { box-shadow: inset 3px 0 0 var(--vd-st-warm-fg, #c2410c); }
.vbg-row-fx { box-shadow: inset 3px 0 0 var(--vd-st-alert-fg, #b91c1c); }
.vbg-row-lowconf.vbg-row-fx {
  box-shadow: inset 3px 0 0 var(--vd-st-alert-fg, #b91c1c);
}
.vbg-row-draft { background: var(--vd-st-mute-bg, #f1f5f9); }

.vbg-empty-cell {
  padding: 34px 18px !important;
  text-align: center;
  color: var(--vd-text-2, #6b7280);
}
.vbg-empty-hint { margin-top: 5px; font-size: 12px; color: var(--vd-text-3, #94a3b8); }

/* Inline-editable cells. They read as text until focused/hovered, so the table
   scans as data rather than as a wall of form fields. */
.vbg-cell-input,
.vbg-cell-select {
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--vd-text, #1a1a1a);
  font: inherit;
  font-size: 13px;
}
.vbg-cell-input:hover,
.vbg-cell-select:hover {
  border-color: var(--vd-border, #e5e7eb);
  background: var(--vd-surface, #fff);
}
.vbg-cell-input:focus,
.vbg-cell-select:focus {
  outline: none;
  border-color: var(--vd-accent, #2563eb);
  background: var(--vd-surface, #fff);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--vd-accent, #2563eb) 16%, transparent);
}
.vbg-cell-input:disabled,
.vbg-cell-select:disabled { opacity: 0.55; cursor: progress; }
.vbg-cell-input::placeholder { color: var(--vd-text-3, #94a3b8); }
.vbg-cell-date { font-family: var(--vd-font-mono, monospace); font-size: 12px; }

.vbg-amount-row { display: flex; gap: 6px; align-items: center; }
.vbg-cell-amount {
  flex: 1 1 auto;
  font-family: var(--vd-font-mono, monospace);
  text-align: right;
}
.vbg-cell-currency { flex: 0 0 74px; width: 74px; font-size: 12px; }
/* The formatted truth under the raw input: what this row actually reads as,
   in its own currency. */
.vbg-amount-display {
  margin-top: 3px;
  padding-right: 8px;
  text-align: right;
  font-family: var(--vd-font-mono, monospace);
  font-size: 12px;
  font-weight: 600;
  color: var(--vd-text-2, #6b7280);
}

.vbg-chips { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 4px; }
.vbg-chip {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.vbg-chip-scan { background: var(--vd-st-cold-bg, #eff6ff); color: var(--vd-st-cold-fg, #1d4ed8); }
.vbg-chip-low  { background: var(--vd-st-warm-bg, #fff7ed); color: var(--vd-st-warm-fg, #c2410c); }
.vbg-chip-fx {
  margin-top: 4px;
  background: var(--vd-st-alert-bg, #fef2f2);
  color: var(--vd-st-alert-fg, #b91c1c);
  border: 1px solid color-mix(in srgb, var(--vd-st-alert-fg, #b91c1c) 30%, transparent);
}
.vbg-td-amount .vbg-chip-fx { display: block; text-align: right; }

/* Receipt thumbnail */
.vbg-thumb {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 40px;
}
.vbg-thumb-link { display: inline-flex; border-radius: 6px; }
.vbg-thumb-link:focus-visible { outline: 2px solid var(--vd-accent, #2563eb); outline-offset: 2px; }
.vbg-thumb-img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--vd-border, #e5e7eb);
  background: var(--vd-surface-2, #f8f9fb);
  display: block;
}
.vbg-thumb-doc {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 6px;
  border: 1px solid var(--vd-border, #e5e7eb);
  background: var(--vd-surface-2, #f8f9fb);
  color: var(--vd-text-2, #6b7280);
  font-size: 10px;
  font-weight: 700;
  text-decoration: none;
}
.vbg-thumb-doc:hover { border-color: var(--vd-border-2, #d1d5db); color: var(--vd-text, #1a1a1a); }
.vbg-thumb-none,
.vbg-thumb-loading {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 6px;
  border: 1px dashed var(--vd-border-2, #d1d5db);
  color: var(--vd-text-3, #94a3b8);
  font-size: 10px;
}
.vbg-thumb-failed { border-color: var(--vd-st-alert-fg, #b91c1c); color: var(--vd-st-alert-fg, #b91c1c); }

.vbg-attach-btn {
  appearance: none;
  cursor: pointer;
  width: 100%;
  padding: 10px 6px;
  border: 1px dashed var(--vd-border-2, #d1d5db);
  border-radius: 6px;
  background: var(--vd-surface, #fff);
  color: var(--vd-text-2, #6b7280);
  font: inherit;
  font-size: 11px;
  font-weight: 600;
}
.vbg-attach-btn:hover { border-color: var(--vd-text-3, #94a3b8); color: var(--vd-text, #1a1a1a); }
.vbg-attach-btn.has-file {
  border-style: solid;
  border-color: var(--vd-st-active-fg, #15803d);
  color: var(--vd-st-active-fg, #15803d);
}

/* 32px square hit area — a bare glyph would be a ~10px target. */
.vbg-del {
  appearance: none;
  border: none;
  background: transparent;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  color: var(--vd-text-3, #94a3b8);
  font-size: 18px;
  line-height: 1;
  transition: background 140ms ease, color 140ms ease;
}
.vbg-del:hover { background: var(--vd-st-alert-bg, #fef2f2); color: var(--vd-st-alert-fg, #b91c1c); }
.vbg-del:disabled { opacity: 0.4; cursor: progress; }

/* Table footer: add-row on the left, the ZAR total (and its exclusions) right. */
.vbg-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.vbg-foot-total {
  display: inline-flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}
.vbg-foot-total-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--vd-text-3, #94a3b8);
}
.vbg-foot-total-value {
  font-family: var(--vd-font-mono, monospace);
  font-size: 18px;
  font-weight: 700;
  color: var(--vd-text, #1a1a1a);
}
.vbg-foot-sep { color: var(--vd-text-3, #94a3b8); }
.vbg-foot-excluded {
  font-size: 12px;
  font-weight: 600;
  color: var(--vd-st-alert-fg, #b91c1c);
}

/* === Responsive =========================================== */
@media (max-width: 900px) {
  .vbg-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .vbg-totals { gap: 20px; }
}

@media (max-width: 560px) {
  .vbg-toolbar { gap: 8px; }
  .vbg-seg { width: 100%; }
  .vbg-seg-btn { flex: 1; padding: 7px 8px; }
  .vbg-nav { width: 100%; justify-content: space-between; }
  .vbg-period-label { flex: 1; }
  .vbg-kpis { grid-template-columns: 1fr; }
  .vbg-kpi-value { font-size: 21px; }
  .vbg-totals { gap: 14px; padding: 12px 14px; }
  .vbg-totals-item { flex: 1 1 100%; }
  .vbg-cap-row { gap: 8px; }
  .vbg-cap-label { flex-basis: 100%; }
  .vbg-cap-input { flex: 1 1 120px; }
  .vbg-foot { align-items: flex-start; flex-direction: column; }
}

/* === Dark theme =========================================== */
/* The --vd-* tokens carry most of it; only the hard-coded values need help. */
html[data-theme="dark"] .vbg-seg-btn.active {
  background: #334155;
  color: #f1f5f9;
}
html[data-theme="dark"] .vbg-table td { border-bottom-color: rgba(255, 255, 255, 0.06); }
html[data-theme="dark"] .vbg-scan-fail { background: rgba(255, 255, 255, 0.06); }
html[data-theme="dark"] .vbg-row-draft { background: rgba(255, 255, 255, 0.04); }

@media (prefers-reduced-motion: reduce) {
  .vbg-bar-fill,
  .vbg-seg-btn,
  .vbg-drop,
  .vbg-del,
  .vbg-cell-input,
  .vbg-cell-select { transition: none; }
}
