/* =========================================================
   Lists, filters, forms and record pages (phase 4 of the design
   proposal). Loaded before theme.css; colours come from its tokens.
   ========================================================= */

/* ---- Status pills: Bootstrap's solid badges become soft pills --------------- */
.badge.bg-success, .badge.text-bg-success { background-color: var(--fm-income-soft) !important; color: var(--fm-income-text) !important; }
.badge.bg-warning, .badge.text-bg-warning { background-color: var(--fm-warn-soft) !important; color: var(--fm-warn-text) !important; }
.badge.bg-danger,  .badge.text-bg-danger  { background-color: var(--fm-alert-soft) !important; color: var(--fm-alert-text) !important; }
.badge.bg-info,    .badge.text-bg-info    { background-color: var(--fm-brand-soft) !important; color: var(--fm-brand-text) !important; }
.badge.bg-secondary, .badge.text-bg-secondary { background-color: var(--bs-tertiary-bg) !important; color: var(--bs-secondary-color) !important; }
.badge { font-weight: 700; }

/* ---- Tables ------------------------------------------------------------------ */
.table {
  --bs-table-bg: transparent;
  --bs-table-hover-bg: var(--fm-brand-soft);
  --bs-table-hover-color: var(--fm-ink);
  --bs-table-border-color: var(--fm-line);
}
.table > thead, .table > thead.table-light { --bs-table-bg: transparent; --bs-table-color: var(--fm-muted); }
.table > thead > tr > th {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.07em; text-transform: uppercase;
  color: var(--fm-muted); border-bottom: 1px solid var(--fm-line); padding-top: 0.75rem; padding-bottom: 0.75rem;
}
.table > tbody > tr > td { padding-top: 0.7rem; padding-bottom: 0.7rem; vertical-align: middle; }
.table > tbody > tr:last-child > td { border-bottom-width: 0; }
/* ---- Row states in the lists --------------------------------------------------------------
   Template-created expenses get the brand tint, deleted records the alert tint with struck-through
   text (colour is not the only signal). A deleted expense that came from a template shows as deleted. */
.table > tbody > tr.fm-row-template {
  --bs-table-bg: var(--fm-brand-soft);
  --bs-table-color: var(--fm-ink);
  --bs-table-hover-bg: color-mix(in srgb, var(--fm-brand-soft) 78%, var(--fm-brand-text));
  --bs-table-border-color: color-mix(in srgb, var(--fm-brand-soft) 80%, var(--fm-brand-text));
}
.table > tbody > tr.fm-row-deleted {
  --bs-table-bg: var(--fm-alert-soft);
  --bs-table-color: var(--fm-alert-text);
  --bs-table-hover-bg: color-mix(in srgb, var(--fm-alert-soft) 78%, var(--fm-alert-text));
  --bs-table-border-color: color-mix(in srgb, var(--fm-alert-soft) 80%, var(--fm-alert-text));
}
.table > tbody > tr.fm-row-deleted > td:not(:last-child) {   /* the last cell is the Restore link */
  text-decoration: line-through; text-decoration-thickness: 1px;
}
.table > tbody > tr.fm-row-deleted a { color: var(--fm-alert-text); font-weight: 600; white-space: nowrap; }

td.dt-type-numeric, th.dt-type-numeric { font-variant-numeric: tabular-nums; white-space: nowrap; }
td.dt-type-numeric { font-weight: 600; }

/* DataTables controls */
div.dt-container .dt-search input,
div.dt-container .dt-length select {
  min-height: 2.5rem; border-radius: var(--fm-radius-control);
  border: 1px solid var(--bs-border-color); background-color: var(--fm-surface); color: var(--bs-body-color);
}
div.dt-container .dt-info { color: var(--fm-muted); font-size: 0.875rem; }
div.dt-container .page-link { border-radius: 0.6rem; margin: 0 2px; border-color: transparent; }
div.dt-container .page-item.active .page-link { border-color: var(--fm-brand); }
/* A wide table scrolls inside its card instead of widening the page */
div.dt-container div.dt-layout-cell:has(> table) { overflow-x: auto; }
.dt-container { width: 100%; }

/* ---- Filters: header with a count, chips for what is active ------------------- */
.card > .card-header:has(+ .collapse[id$="ilterCollapse"]) { padding: 0.25rem 0.5rem; background: transparent; border-bottom: 0; }
.fm-filter-count {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.4rem; height: 1.4rem; padding: 0 0.4rem; margin-left: 0.5rem;
  border-radius: 99px; background: var(--fm-brand); color: #fff; font-size: 0.75rem; font-weight: 700;
}
.fm-chips { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; padding: 0 0.75rem 0.75rem; }
.fm-chips[hidden] { display: none; }
.fm-chip {
  display: inline-flex; align-items: center; gap: 0.4rem; max-width: 100%;
  min-height: 2.25rem; padding: 0.25rem 0.5rem 0.25rem 0.8rem;
  border: 0; border-radius: 99px; background: var(--fm-brand-soft); color: var(--fm-brand-text);
  font-size: 0.85rem; font-weight: 600;
}
.fm-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fm-chip .bi { font-size: 1rem; }
.fm-chip:hover { background: var(--bs-tertiary-bg); }
.fm-chip:focus-visible, .fm-chips-clear:focus-visible { outline: 3px solid var(--fm-brand-text); outline-offset: 2px; }
.fm-chips-clear {
  border: 0; background: transparent; color: var(--fm-muted); font-size: 0.85rem; font-weight: 600;
  text-decoration: underline; min-height: 2.25rem; padding: 0 0.5rem;
}

/* ---- Forms ---------------------------------------------------------------------- */
.form-label { font-size: 0.875rem; font-weight: 600; color: var(--fm-muted); margin-bottom: 0.35rem; }
.form-control:not(.form-control-sm), .form-select:not(.form-select-sm) { min-height: 2.6rem; }
.input-group-text { background-color: var(--bs-tertiary-bg); border-color: var(--bs-border-color); color: var(--fm-muted); }
.form-control:disabled, .form-control[readonly], .form-select:disabled { background-color: var(--bs-tertiary-bg); }
.card-body > form > hr, .card-body > hr { border-color: var(--fm-line); opacity: 1; margin: 1.75rem 0; }
.card-body h4, .card-body h5.section-title { font-size: 1.05rem; font-weight: 700; }
.card-header { background: transparent; border-bottom-color: var(--fm-line); font-weight: 600; }

/* ---- Record pages: segmented tabs (Record / Log) ---------------------------------- */
.nav-tabs {
  display: inline-flex; flex-wrap: wrap; gap: 0.25rem; padding: 0.25rem;
  border: 0; border-radius: 0.9rem; background: var(--bs-tertiary-bg);
}
.nav-tabs .nav-link {
  border: 0; border-radius: 0.7rem; min-height: 2.5rem; padding: 0.4rem 1rem;
  color: var(--fm-muted); font-weight: 600;
}
.nav-tabs .nav-link:hover { color: var(--fm-ink); }
.nav-tabs .nav-link.active { background: var(--fm-surface); color: var(--fm-brand-text); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.12); }

/* ---- Wizard steps: circles joined by a line (expense template wizard) ----------------- */
.step-circle { position: relative; z-index: 1; }
[class*="col-"]:has(> .step-circle) { position: relative; }
[class*="col-"]:has(> .step-circle)::before,
[class*="col-"]:has(> .step-circle)::after {
  content: ""; position: absolute; top: 19px; height: 2px;
  width: calc(50% - 26px); background: var(--fm-line);
}
[class*="col-"]:has(> .step-circle)::before { left: 0; }
[class*="col-"]:has(> .step-circle)::after { right: 0; }
[class*="col-"]:has(> .step-circle):first-child::before,
[class*="col-"]:has(> .step-circle):last-child::after { display: none; }
/* the part of the line that has been travelled */
[class*="col-"]:has(> .step-circle.completed)::before,
[class*="col-"]:has(> .step-circle.completed)::after,
[class*="col-"]:has(> .step-circle.active)::before { background: var(--fm-brand); }
.step-circle + small { display: block; color: var(--fm-muted); font-weight: 600; }
[class*="col-"]:has(> .step-circle.active) > small { color: var(--fm-ink); font-weight: 700; }
/* the line is the progress indicator; the bar below it would say the same twice */
.row:has(> [class*="col-"] > .step-circle) + .progress { display: none; }

/* ---- Phones --------------------------------------------------------------------------------- */
@media (max-width: 767.98px) {
  .table > tbody > tr > td, .table > thead > tr > th { padding-left: 0.4rem; padding-right: 0.4rem; }
  .table > tbody > tr > td { font-size: 0.92rem; }
  div.dt-container .dt-search, div.dt-container .dt-length { text-align: left !important; }
  div.dt-container .dt-search input { width: 100%; margin-left: 0; }
  div.dt-container .dt-search label { display: block; width: 100%; }
  div.dt-container .dt-paging { text-align: center !important; }
  .nav-tabs { display: flex; }
  .nav-tabs .nav-item { flex: 1 1 0; }
  .nav-tabs .nav-link { width: 100%; text-align: center; }
  h3 { font-size: 1.35rem; }
}

/* ---- Form sections: one card per group of fields --------------------------------------- */
.fm-section > .card-header {
  display: flex; align-items: center; padding: 0.9rem 1.25rem;
  font-size: 1rem; font-weight: 700; color: var(--fm-ink);
}
.fm-section > .card-header .bi { color: var(--fm-brand-text); font-size: 1.15rem; }
.fm-section > .card-body { padding: 1.25rem; }

/* Expense form, product rows: on phones the quantity (unit + - / + stepper) gets the wider column and
   the stepper stays compact so the number remains visible */
.product-row .quantity-minus,
.product-row .quantity-plus {
  padding-left: .6rem;
  padding-right: .6rem;
}
.product-row .quantity-input {
  min-width: 3rem;
}
@media (max-width: 767.98px) {
  .product-row .input-group-text {
    padding-left: .5rem;
    padding-right: .5rem;
  }
  .product-row .price-input,
  .product-row .rebate-input,
  .product-row .total-input {
    padding-left: .35rem;
    padding-right: .35rem;
    font-size: .9rem;
  }
}
