/* AECS4U Finance — app-level styles layered on aecs4u-theme + Bootstrap.
   Everything here is token-driven and dark-mode aware; no inline colours. */

:root {
  /* AA-contrast on white / light cards */
  --fin-primary: #1d4ed8;
  --fin-success: #047857;
  --fin-danger: #b91c1c;
  --fin-accent: #6d28d9;
  --fin-warning: #b45309;
}

[data-bs-theme="dark"] {
  /* AA-contrast on the dark card surface */
  --fin-primary: #60a5fa;
  --fin-success: #34d399;
  --fin-danger: #f87171;
  --fin-accent: #a78bfa;
  --fin-warning: #fbbf24;
}

/* ── KPI cards ─────────────────────────────────────────────────────────── */
.kpi-card {
  --kpi-color: var(--fin-primary);
  box-shadow: inset 4px 0 0 var(--kpi-color), var(--bs-box-shadow-sm);
}
.kpi-card--primary { --kpi-color: var(--fin-primary); }
.kpi-card--success { --kpi-color: var(--fin-success); }
.kpi-card--danger  { --kpi-color: var(--fin-danger); }
.kpi-card--accent  { --kpi-color: var(--fin-accent); }
.kpi-card--warning { --kpi-color: var(--fin-warning); }

.kpi-card .card-body { padding: 1rem 1.25rem; }
.kpi-label {
  color: var(--bs-secondary-color);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  overflow-wrap: anywhere;
}
.kpi-value {
  color: var(--kpi-color);
  font-size: clamp(1.25rem, 1rem + 1vw, 1.75rem);
  line-height: 1.2;
  overflow-wrap: anywhere;
}

/* ── Lists / surfaces ──────────────────────────────────────────────────── */
/* Keep list-group rows on the card surface in both colour schemes. */
.finance-list .list-group-item { background-color: transparent; }
.expenses-scroll { max-height: min(75vh, 800px); overflow-y: auto; }
/* The theme clips .table with overflow:hidden, which would make the table (not
   this wrapper) the scroll container and silently disable sticky headers. */
.expenses-scroll table { width: 100%; min-width: 100%; overflow: visible; }
.expenses-scroll [data-expense-column].expense-column-hidden { display: none !important; }
.expense-table-tools { position: relative; z-index: 4; }
.expense-column-menu { position: relative; }
.expense-column-menu > summary {
  display: inline-flex;
  align-items: center;
  list-style: none;
  cursor: pointer;
}
.expense-column-menu > summary::-webkit-details-marker { display: none; }
.expense-column-menu-panel {
  position: absolute;
  inset-inline-end: 0;
  top: calc(100% + 0.25rem);
  z-index: 5;
  min-width: 13rem;
  padding: 0.75rem;
  color: var(--bs-body-color);
  background: var(--bs-body-bg);
  border: 1px solid var(--bs-border-color);
  border-radius: var(--bs-border-radius);
  box-shadow: var(--bs-box-shadow);
}
.expenses-message { min-height: 1.35rem; }
.cashflow-chart-scroll { overflow-x: auto; }
.cashflow-chart { display: block; max-width: none; }
.cashflow-gridline { stroke: var(--bs-border-color); stroke-dasharray: 3 4; }
.cashflow-axis-label,
.cashflow-year-label,
.cashflow-value-label { fill: var(--bs-secondary-color); font-family: var(--bs-body-font-family); font-size: 12px; }
.cashflow-year-label { fill: var(--bs-body-color); font-size: 13px; }
.cashflow-value-label { font-size: 11px; }
.cashflow-bar { fill: var(--fin-primary); }
.bank-cashflow-zero { stroke: var(--bs-secondary-color); stroke-width: 1.25; }
.bank-cashflow-income { fill: var(--bs-success, #198754); }
.bank-cashflow-expense { fill: var(--bs-danger, #dc3545); }
.bank-cashflow-legend { display: inline-block; width: 0.7rem; height: 0.7rem; margin-right: 0.4rem; border-radius: 2px; }
.bank-cashflow-legend.bank-cashflow-income { background-color: var(--bs-success, #198754); }
.bank-cashflow-legend.bank-cashflow-expense { background-color: var(--bs-danger, #dc3545); }
/* Keep the column headers visible while the rows scroll. Sticky is applied
   to the cells (not <thead>) because that is what browsers support reliably,
   and the cells need their own opaque background to cover the rows. */
.expenses-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background-color: var(--bs-tertiary-bg, #f8f9fa);
  box-shadow: inset 0 -1px 0 var(--bs-border-color, #dee2e6);
}
/* The filtered total stays in view at the bottom of the scroll area. */
.expenses-scroll tfoot th,
.expenses-scroll tfoot td {
  position: sticky;
  bottom: 0;
  z-index: 2;
  background-color: var(--bs-tertiary-bg, #f8f9fa);
  box-shadow: inset 0 1px 0 var(--bs-border-color, #dee2e6);
}

/* Sortable headers: the whole header label is a button. */
.sort-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  /* Bootstrap resets these on buttons; inherit so sortable headers match the
     plain ones (Note, Comment, Receipt). */
  text-transform: inherit;
  letter-spacing: inherit;
  text-align: start;
  cursor: pointer;
}
.sort-icon { font-size: 0.7em; opacity: 0.4; }
.sort-btn:hover .sort-icon,
th[aria-sort="ascending"] .sort-icon,
th[aria-sort="descending"] .sort-icon { opacity: 1; }

/* Editable cells: look like text, reveal an edit affordance on hover/focus. */
.cell-value {
  display: inline-block;
  min-width: 2rem;
  border-bottom: 1px dashed transparent;
  cursor: text;
}
.cell-value:empty::before { content: "\2014"; color: var(--bs-tertiary-color); }
.cell-value[data-placeholder]:empty::before { content: attr(data-placeholder); white-space: nowrap; }
tr:hover .cell-value,
.cell-value:focus-visible { border-bottom-color: var(--bs-border-color); }
.cell-input { min-width: 10rem; }
.cell-input[type="date"] { min-width: 9rem; }
.cell-input[type="number"] { min-width: 7rem; width: 8rem; }
.cell-select { min-width: 5.75rem; max-width: 8rem; width: 100%; }
/* Long free-text columns wrap instead of stretching the table. */
.cell-item { min-width: 9rem; }
.cell-wide { min-width: 7rem; max-width: 16rem; overflow-wrap: anywhere; }
/* The wide table scrolls sideways; keep the item name in view while it does.
   Table cells are already opaque (--bs-table-bg), so rows scroll beneath it. */
.expenses-scroll .col-sticky { position: sticky; left: 0; z-index: 1; }
.expenses-scroll thead .col-sticky { z-index: 3; }
.expenses-scroll .col-sticky::after {
  content: "";
  position: absolute;
  inset-block: 0;
  right: 0;
  width: 1px;
  background-color: var(--bs-border-color);
}
/* Receipt links are truncated to one line; the full name is in the tooltip. */
.receipt-links { max-width: 10rem; }
.receipt-link {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* With a pointer, per-row dropdowns stay quiet until the row is hovered or
   the control is focused (the chevron keeps them recognisable). */
@media (hover: hover) {
  .expenses-scroll .cell-select:not(:focus):not(:disabled) {
    border-color: transparent;
    background-color: transparent;
  }
  .expenses-scroll tr:hover .cell-select:not(:focus) {
    border-color: var(--bs-border-color);
  }
}
td.is-saving { opacity: 0.6; }
.paid-toggle { white-space: nowrap; min-width: 6.5rem; }

/* Main application sections fill the main area (the theme's <main> already
   supplies the outer padding and sidebar offset) instead of Bootstrap's
   fixed-width, centred .container. */
.finance-page {
  width: 100%;
  max-width: none;
  margin-inline: 0;
  padding-inline: 0;
}

/* Long-form prose pages (help, contact) stay at a readable measure. */
.page-narrow { max-width: 760px; }

/* ── Dashboard iframe (Panel) ──────────────────────────────────────────── */
.finance-dashboard-frame {
  display: block;
  width: 100%;
  min-height: 600px;
  height: calc(100vh - 170px); /* until the embedded document reports its height */
  border: 0;
  color-scheme: normal;
}

/* ── Mobile header: let brand shrink so the avatar/menu never clip ─────── */
@media (max-width: 575.98px) {
  .navbar-main .navbar-brand { min-width: 0; }
  .navbar-main .logo-text {
    display: inline-block;
    max-width: 8.5rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
  }
  .navbar-main .navbar-actions { gap: 0.25rem !important; }
  .navbar-main .user-menu-btn > span:not(.user-avatar) { display: none; }
}
