/* ============================================
   MARGIN DASHBOARD
   Sky console light theme. Local --md-*
   tokens are remapped onto the shared
   tokens in style.css :root, with literal
   fallbacks. Dollar figures are the headline.
   ============================================ */

:root {
  --md-navy: var(--d-ink, #10283f);
  --md-sapphire: var(--d-accent, #2d7dd2);
  --md-paper: var(--d-bg, #e9f1f9);
  --md-paper-edge: var(--d-line, #dbe7f2);
  --md-edge-strong: var(--d-line-strong, #bcd3e6);
  --md-positive: var(--d-ok, #15803d);
  --md-negative: var(--d-danger, #b91c1c);
  --md-text: var(--d-ink, #10283f);
  --md-text-muted: var(--d-ink-2, #44617c);
  --md-text-faint: var(--d-ink-3, #6e8aa3);
  --md-white: var(--d-surface, #ffffff);
  --md-row-hover: var(--d-surface-2, #dcebf7);
  --md-radius: 10px;
  --md-shadow: 0 1px 2px rgba(16,40,63,0.08);
  --md-shadow-strong: 0 6px 16px rgba(16,40,63,0.10);
}

.md-root {
  padding: 0.5rem 0 1.5rem 0;
  color: var(--md-text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ============================================
   FULL-WIDTH MARGIN VIEW
   When the Margin tab is active, body gets
   `view-margin-active`. We hide the map and
   let the sidebar (which hosts the margin
   content) span the full viewport so the
   tiles and tables get room to breathe.
   ============================================ */
body.view-margin-active .app-container {
  grid-template-columns: 1fr;
}
body.view-margin-active .map-container {
  display: none;
}
body.view-margin-active .sidebar {
  border-right: none;
}
/* Give the margin content area generous breathing room
   when it owns the full viewport. The other tabs keep
   the default 1.25rem padding from .tab-content. */
body.view-margin-active #tab-margin.tab-content {
  padding: 1.5rem 2rem;
  max-width: 1600px;
  width: 100%;
  margin: 0 auto;
}

/* ----- ZONE A: KPI cards ---------------------------------- */
.md-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

/* Six-card layout used by the expanded daily-tracking view. */
.md-kpis-6 {
  grid-template-columns: repeat(6, minmax(0, 1fr));
}

/* Seven-card layout used once material cost was added as its own card.
   At full width seven cards fit on one row; responsive rules below
   collapse it to 4, 3, 2, then 1 column as the viewport shrinks. */
.md-kpis-7 {
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 12px;
}

.md-kpi {
  background: var(--md-white);
  border: 1px solid var(--md-paper-edge);
  border-radius: var(--md-radius);
  box-shadow: var(--md-shadow);
  padding: 18px 20px;
  min-height: 128px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  cursor: pointer;
  transition: box-shadow 140ms ease, border-color 140ms ease;
  user-select: none;
}
.md-kpi:hover {
  border-color: var(--md-edge-strong);
}
.md-kpi:focus-visible {
  outline: 2px solid var(--md-sapphire);
  outline-offset: 2px;
}

.md-kpi-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-text-muted);
  margin-bottom: 0.45rem;
}

.md-kpi-value {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.1;
  color: var(--md-navy);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.md-kpi-value.md-positive { color: var(--md-positive); }
.md-kpi-value.md-negative { color: var(--md-negative); }

/* Colour variants for the expanded KPI grid. */
.md-kpi-value.md-kpi-navy        { color: var(--md-navy); }
.md-kpi-value.md-kpi-sapphire    { color: var(--md-sapphire); }
.md-kpi-value.md-kpi-navy-muted  { color: var(--md-text-muted); }

/* Realised profit card is the headline business number, slightly larger. */
.md-kpi.md-kpi-headline {
  border-color: var(--md-sapphire);
  background: var(--md-white);
}
.md-kpi-value.md-kpi-headline-value {
  font-size: 28px;
}

/* Day-on-day delta line under each KPI. */
.md-kpi-delta {
  margin-top: 0.35rem;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  line-height: 1.3;
}
.md-kpi-delta-muted    { color: var(--md-text-muted); font-weight: 500; }
.md-kpi-delta-positive { color: var(--md-positive); }
.md-kpi-delta-negative { color: var(--md-negative); }

/* ----- Performance split (Installed vs To Be Installed) ----- */
.md-perf-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.md-perf-card {
  border-radius: var(--md-radius);
  padding: 32px;
  box-shadow: var(--md-shadow);
  border: 1px solid var(--md-paper-edge);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  cursor: pointer;
  transition: box-shadow 140ms ease, border-color 140ms ease;
}
.md-perf-card:hover {
  box-shadow: var(--md-shadow-strong);
  border-color: var(--md-edge-strong);
}
.md-perf-card:focus-visible {
  outline: 2px solid var(--md-sapphire);
  outline-offset: 2px;
}

/* Card A: Installed - white surface */
.md-perf-card.md-perf-installed {
  background: var(--md-white);
}

/* Card B: To Be Installed - same dark surface, accent left rail */
.md-perf-card.md-perf-pipeline {
  background: var(--md-white);
  border-left: 2px solid var(--md-sapphire);
}

.md-perf-header {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.md-perf-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--md-navy);
  letter-spacing: -0.01em;
}
.md-perf-subtitle {
  font-size: 12.5px;
  color: var(--md-text-muted);
  font-weight: 500;
}

.md-perf-stats {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  margin: 0;
}
.md-perf-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 13.5px;
}
.md-perf-row dt {
  color: var(--md-text-muted);
  font-weight: 500;
}
.md-perf-row dd {
  margin: 0;
  font-weight: 700;
  color: var(--md-navy);
  font-variant-numeric: tabular-nums;
}
.md-perf-note {
  font-size: 11px;
  color: var(--md-text-faint);
  font-weight: 500;
  margin-left: 0.35rem;
}

.md-perf-headline {
  margin-top: 0.35rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--md-paper-edge);
}
.md-perf-card.md-perf-pipeline .md-perf-headline {
  border-top-color: var(--md-paper-edge);
}
.md-perf-headline-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-text-muted);
  margin-bottom: 0.2rem;
}
.md-perf-headline-value {
  font-size: 32px;
  font-weight: 800;
  line-height: 1.05;
  color: var(--md-navy);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.md-perf-headline-value.md-positive { color: var(--md-positive); }
.md-perf-headline-value.md-negative { color: var(--md-negative); }
.md-perf-headline-value.md-perf-sapphire { color: var(--md-sapphire); }
.md-perf-sapphire { color: var(--md-sapphire); }

.md-perf-margin {
  font-size: 12.5px;
  color: var(--md-text-muted);
}
.md-perf-margin strong { font-weight: 700; color: var(--md-navy); }

.md-perf-footer {
  font-size: 12.5px;
  color: var(--md-text-muted);
  border-top: 1px solid var(--md-paper-edge);
  padding-top: 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.md-perf-card.md-perf-pipeline .md-perf-footer {
  border-top-color: var(--md-paper-edge);
}
.md-perf-locked-note {
  font-size: 12.5px;
  color: var(--md-text-faint);
}

/* ----- Footer note ----------------------------------------- */
.md-footer-note {
  margin-top: 24px;
  padding: 0.75rem 0.9rem;
  font-size: 12.5px;
  color: var(--md-text-muted);
  text-align: center;
  border-top: 1px solid var(--md-paper-edge);
  line-height: 1.4;
}

/* ----- Snapshot bar + Trend strip --------------------------- */
.md-snapshot-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.55rem;
  font-size: 12.5px;
  color: var(--md-text-muted);
}
.md-snapshot-text { flex: 1; }
.md-snapshot-now {
  background: transparent;
  border: 1px solid var(--md-edge-strong);
  color: var(--md-text);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: var(--radius, 8px);
  cursor: pointer;
  font-family: inherit;
  transition: background 130ms ease, border-color 130ms ease;
}
.md-snapshot-now:hover {
  border-color: var(--md-edge-strong);
  background: var(--md-row-hover);
}
.md-snapshot-now:disabled {
  opacity: 0.45;
  cursor: default;
}

.md-trend-strip {
  background: var(--md-white);
  border: 1px solid var(--md-paper-edge);
  border-radius: var(--md-radius);
  box-shadow: var(--md-shadow);
  padding: 0.6rem 0.85rem;
  margin-bottom: 24px;
  font-size: 13px;
  color: var(--md-text);
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}
.md-trend-row { line-height: 1.35; }
.md-trend-row strong { color: var(--md-navy); }
.md-trend-label {
  font-weight: 600;
  color: var(--md-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 11px;
  margin-right: 0.3rem;
}
.md-trend-loading { color: var(--md-text-muted); font-style: italic; }

.md-kpi-sub {
  margin-top: 0.4rem;
  font-size: 12.5px;
  color: var(--md-text-muted);
  line-height: 1.35;
}

/* ----- Settings panel (Material cost per metre) --------------- */
.md-settings {
  margin-bottom: 24px;
}
.md-settings-card {
  background: var(--md-white);
  border: 1px solid var(--md-paper-edge);
  border-radius: var(--md-radius);
  box-shadow: var(--md-shadow);
  overflow: hidden;
}
.md-settings-card.open {
  border-color: var(--md-sapphire);
}
.md-settings-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 0.9rem;
  background: transparent;
  border: none;
  cursor: pointer;
  font-family: inherit;
  text-align: left;
  color: var(--md-text);
  transition: background 130ms ease;
}
.md-settings-toggle:hover {
  background: var(--md-row-hover);
}
.md-settings-toggle:focus-visible {
  outline: 2px solid var(--md-sapphire);
  outline-offset: -2px;
}
.md-settings-caret {
  color: var(--md-text-faint);
  font-size: 0.7rem;
  width: 0.85rem;
  display: inline-block;
}
.md-settings-title {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--md-navy);
  letter-spacing: 0.01em;
}
.md-settings-summary {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--md-text-muted);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.md-settings-body {
  padding: 0.85rem 1rem 1rem 1rem;
  border-top: 1px solid var(--md-paper-edge);
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  background: var(--md-paper);
}

.md-settings-field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}
.md-settings-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-text-muted);
}
.md-settings-input-wrap {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  background: var(--md-white);
  border: 1px solid var(--md-paper-edge);
  border-radius: var(--radius, 8px);
  padding: 0.35rem 0.6rem;
  max-width: 320px;
  min-height: 36px;
  transition: border-color 130ms ease, box-shadow 130ms ease;
}
.md-settings-input-wrap:focus-within {
  border-color: var(--md-sapphire);
  box-shadow: 0 0 0 3px var(--d-ring, rgba(45,125,210,0.25));
}
.md-settings-prefix,
.md-settings-suffix {
  color: var(--md-text-muted);
  font-size: 13px;
  font-weight: 600;
}
.md-settings-input-wrap input {
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
  color: var(--md-navy);
  width: 110px;
  padding: 0.15rem 0;
}
.md-settings-help {
  font-size: 12.5px;
  color: var(--md-text-muted);
  line-height: 1.4;
  max-width: 60ch;
}

.md-settings-actions {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  flex-wrap: wrap;
}
.md-settings-save {
  background: var(--d-btn, #2d7dd2);
  color: #ffffff;
  border: 1px solid var(--d-btn, #2d7dd2);
  font-weight: 600;
  font-size: 13px;
  padding: 8px 14px;
  min-height: 36px;
  border-radius: var(--radius, 8px);
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.01em;
  transition: background 130ms ease, border-color 130ms ease;
}
.md-settings-save:hover {
  background: #1e6abf;
  border-color: #1e6abf;
}
.md-settings-save:disabled {
  opacity: 0.45;
  cursor: default;
}
.md-settings-updated {
  font-size: 12.5px;
  color: var(--md-text-muted);
}

/* ----- ZONE B: Filter bar ---------------------------------- */
.md-filterbar {
  background: var(--md-white);
  border: 1px solid var(--md-paper-edge);
  border-radius: var(--md-radius);
  padding: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 24px;
  box-shadow: var(--md-shadow);
}

.md-filterbar label {
  display: flex;
  flex-direction: column;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-text-muted);
  gap: 0.2rem;
}

.md-filterbar select {
  font-family: inherit;
  font-size: 13.5px;
  padding: 7px 10px;
  min-height: 36px;
  border: 1px solid var(--md-paper-edge);
  border-radius: var(--radius, 8px);
  background: var(--md-white);
  color: var(--md-text);
  min-width: 140px;
  transition: border-color 130ms ease, box-shadow 130ms ease;
}
.md-filterbar select:focus {
  outline: none;
  border-color: var(--md-sapphire);
  box-shadow: 0 0 0 3px var(--d-ring, rgba(45,125,210,0.25));
}

/* Brand segmented control - margin-scoped dark overrides on top of the
   shared .brand-filter styles in style.css. Active brand keeps its
   identity colour; track sits on the recessed page background. */
.md-filterbar .brand-filter {
  background: var(--md-paper);
  border: 1px solid var(--md-paper-edge);
  margin-bottom: 0;
}
.md-filterbar .brand-filter-btn {
  color: var(--md-text-faint);
}
.md-filterbar .brand-filter-btn:hover { color: var(--md-text); }
.md-filterbar .brand-filter-btn.is-active {
  background: var(--md-row-hover);
  color: var(--md-text);
  box-shadow: var(--md-shadow);
}
.md-filterbar .brand-filter-btn[data-brand="GGI"].is-active { color: var(--d-brand-ggi, #2d7dd2); }
.md-filterbar .brand-filter-btn[data-brand="MGG"].is-active { color: var(--d-brand-mgg, #ea7317); }

.md-filter-summary {
  margin-left: auto;
  font-size: 12.5px;
  color: var(--md-text-muted);
  text-align: right;
}

.md-warning-chip {
  width: 100%;
  background: transparent;
  border: 1px solid var(--md-paper-edge);
  color: var(--d-warn, #b45309);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius, 8px);
  font-size: 12.5px;
  line-height: 1.35;
}
.md-warning-chip::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--d-warn, #b45309);
  margin-right: 0.45rem;
  vertical-align: middle;
}

/* ----- ZONE C: Breakdown tables ---------------------------- */
/* Four panels: installer, region, month, lead source.
   On wide screens we lay them out in a 2x2 grid so each panel has
   breathing room for its columns (lead source has six columns and
   needs the width). The medium/narrow breakpoints below collapse
   gracefully. */
.md-breakdowns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

/* Generous column widths so headers and data don't truncate
   when the dashboard is full-width. */
table.md-table th:first-child,
table.md-table td:first-child {
  min-width: 120px;
}
table.md-table th:not(:first-child),
table.md-table td:not(:first-child) {
  min-width: 100px;
}

.md-card {
  background: var(--md-white);
  border: 1px solid var(--md-paper-edge);
  border-radius: var(--md-radius);
  padding: 0.85rem 0.85rem 0.6rem;
  box-shadow: var(--md-shadow);
  display: flex;
  flex-direction: column;
  min-width: 0;
  transition: box-shadow 140ms ease;
}
.md-card:hover {
  box-shadow: var(--md-shadow-strong);
}

.md-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--md-navy);
  margin-bottom: 0.5rem;
}

.md-table-wrap {
  overflow-x: auto;
}

table.md-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

table.md-table th,
table.md-table td {
  padding: 0.5rem 0.4rem;
  text-align: right;
  white-space: nowrap;
  border-bottom: 1px solid var(--md-paper-edge);
}

table.md-table td {
  color: var(--md-text-muted);
}
table.md-table td:not(:first-child) {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--md-text);
}

table.md-table th:first-child,
table.md-table td:first-child {
  text-align: left;
}

table.md-table th {
  font-weight: 600;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-text-muted);
  cursor: pointer;
  user-select: none;
  background: var(--md-white);
  border-bottom: 1px solid var(--md-paper-edge);
}
table.md-table th.md-sort-asc::after { content: ' \25B2'; font-size: 0.7em; }
table.md-table th.md-sort-desc::after { content: ' \25BC'; font-size: 0.7em; }
table.md-table th.md-not-sortable { cursor: default; }

table.md-table tbody tr {
  cursor: pointer;
  transition: background 130ms ease;
}
table.md-table tbody tr:hover {
  background: var(--md-row-hover);
}

table.md-table td.md-positive, td.md-positive { color: var(--md-positive); font-weight: 600; }
table.md-table td.md-negative, td.md-negative { color: var(--md-negative); font-weight: 600; }

.md-trend {
  display: inline-block;
  margin-left: 0.25rem;
  font-size: 0.85em;
}
.md-trend.up { color: var(--md-positive); }
.md-trend.down { color: var(--md-negative); }
.md-trend.flat { color: var(--md-text-faint); }

.md-show-all {
  margin-top: 0.5rem;
  background: transparent;
  border: 1px solid var(--md-edge-strong);
  color: var(--md-text);
  font-weight: 600;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: var(--radius, 8px);
  cursor: pointer;
  align-self: flex-start;
  transition: background 130ms ease, border-color 130ms ease;
}
.md-show-all:hover {
  border-color: var(--md-edge-strong);
  background: var(--md-row-hover);
}

.md-empty {
  padding: 1rem;
  text-align: center;
  color: var(--md-text-muted);
  font-size: 13px;
  background: var(--md-paper);
  border-radius: var(--radius, 8px);
}
.md-empty strong { color: var(--md-navy); display: block; margin-bottom: 0.2rem; }

/* ----- Drill modal ----------------------------------------- */
.md-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16,40,63,0.40);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 9000;
  padding: 1rem;
}
.md-modal-backdrop.open { display: flex; }

.md-modal {
  background: var(--md-white);
  border-radius: var(--md-radius);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--md-paper-edge);
  box-shadow: 0 16px 40px rgba(16,40,63,0.18);
  overflow: hidden;
}

.md-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--md-paper-edge);
  background: var(--md-white);
}

.md-modal-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--md-navy);
}
.md-modal-sub {
  font-size: 12.5px;
  color: var(--md-text-muted);
  margin-top: 0.1rem;
}

.md-modal-close {
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--md-text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 0 0.25rem;
  border-radius: var(--radius-sm, 6px);
  transition: color 130ms ease;
}
.md-modal-close:hover { color: var(--md-navy); }

.md-modal-body {
  padding: 0.75rem 1rem 1rem;
  overflow-y: auto;
  flex: 1;
}

.md-modal-jobcard {
  background: var(--md-white);
  border: 1px solid var(--md-paper-edge);
  border-radius: var(--radius, 8px);
  padding: 0.6rem 0.75rem;
  margin-bottom: 0.55rem;
  cursor: pointer;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.2rem 0.75rem;
  transition: border-color 130ms ease, background 130ms ease;
}
.md-modal-jobcard:hover {
  border-color: var(--md-edge-strong);
  background: var(--md-row-hover);
}
.md-modal-jobcard-name {
  font-weight: 600;
  color: var(--md-navy);
}
.md-modal-jobcard-addr {
  grid-column: 1 / -1;
  font-size: 12.5px;
  color: var(--md-text-muted);
}
.md-modal-jobcard-status {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--md-sapphire);
}
.md-modal-jobcard-money {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  font-size: 12.5px;
  color: var(--md-text-muted);
  margin-top: 0.2rem;
  font-variant-numeric: tabular-nums;
}
.md-modal-jobcard-money strong { color: var(--md-navy); }
.md-modal-jobcard-money .md-positive { color: var(--md-positive); }
.md-modal-jobcard-money .md-negative { color: var(--md-negative); }

/* ----- Excluded-from-margin visuals ------------------------ */

/* Row of action buttons under a job card in the drill modal. */
.md-modal-jobcard-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  margin-top: 0.4rem;
}

/* Quiet text-style action button that lives on each card. */
.md-jobcard-action {
  background: none;
  border: none;
  padding: 2px 4px;
  font-size: 12.5px;
  color: var(--md-text-muted);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
  font-family: inherit;
  transition: color 130ms ease;
}
.md-jobcard-action:hover { color: var(--md-navy); }
.md-jobcard-action:disabled { opacity: 0.45; cursor: default; text-decoration: none; }

.md-jobcard-include { color: var(--md-sapphire); }
.md-jobcard-include:hover { color: #7cbcff; }

/* Card itself when the underlying job is excluded from margin. Faded
   look + danger-tinted border to read as "muted from the totals". */
.md-modal-jobcard.md-jobcard-excluded {
  background: var(--md-white);
  border-color: rgba(185,28,28,0.35);
  opacity: 0.7;
}
.md-modal-jobcard.md-jobcard-excluded:hover {
  background: var(--md-row-hover);
  border-color: var(--md-negative);
  opacity: 1;
}

/* Inline EXCLUDED marker rendered alongside the customer name.
   Dot + coloured text, no filled chip. */
.md-excluded-pill {
  display: inline-block;
  margin-left: 0.4rem;
  padding: 0;
  background: transparent;
  color: var(--md-negative);
  border: none;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  vertical-align: middle;
}
.md-excluded-pill::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--md-negative);
  margin-right: 0.35rem;
  vertical-align: middle;
}

/* Chip at the very top of the dashboard summarising how many jobs
   the current filter has hidden via the exclusion flag. */
.md-excluded-chip {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: transparent;
  border: 1px solid var(--md-paper-edge);
  color: var(--d-warn, #b45309);
  padding: 0.45rem 0.75rem;
  border-radius: var(--radius, 8px);
  font-size: 12.5px;
  margin-bottom: 0.75rem;
}
.md-excluded-chip::before {
  content: '';
  flex: none;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--d-warn, #b45309);
}
.md-excluded-chip-text { flex: 1; }
.md-excluded-chip-link {
  background: none;
  border: none;
  color: var(--d-warn, #b45309);
  font-weight: 600;
  font-size: 12.5px;
  cursor: pointer;
  text-decoration: underline;
  padding: 2px 4px;
  font-family: inherit;
}
.md-excluded-chip-link:hover { color: #fcd34d; }

/* Checkbox-style toggle in the filter bar. */
.md-show-excluded-toggle {
  flex-direction: row !important;
  align-items: center !important;
  gap: 0.4rem !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  color: var(--md-text) !important;
  cursor: pointer;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--md-paper-edge);
  border-radius: var(--radius, 8px);
  background: var(--md-white);
}
.md-show-excluded-toggle input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--md-sapphire);
  margin: 0;
}

/* ----- Responsive ------------------------------------------ */
/* Large screens (1300-1599px): 6 KPI cards still fit, slightly tighter.
   The 7-card layout collapses to 4 columns here so the cards stay readable. */
@media (max-width: 1599px) {
  .md-kpis-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .md-kpis-7 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .md-kpi-value { font-size: 20px; }
  .md-kpi-value.md-kpi-headline-value { font-size: 24px; }
}

/* Medium-large (1100-1299px): 3x grid for both 6 and 7 layouts. */
@media (max-width: 1299px) {
  .md-kpis,
  .md-kpis-6,
  .md-kpis-7 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .md-kpi-value { font-size: 21px; }
  .md-kpi-value.md-kpi-headline-value { font-size: 25px; }
}

/* Medium screens (720-1099px): 2x KPI grid; breakdowns stay 2x2. */
@media (max-width: 1099px) {
  .md-kpis,
  .md-kpis-6,
  .md-kpis-7 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .md-kpi-value { font-size: 22px; }
  .md-kpi-value.md-kpi-headline-value { font-size: 26px; }
  .md-breakdowns {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .md-snapshot-bar { flex-wrap: wrap; }
}

/* Narrow screens (<720px): stack everything. */
@media (max-width: 719px) {
  .md-kpis,
  .md-kpis-6,
  .md-kpis-7 { grid-template-columns: 1fr; }
  .md-kpi { min-height: 0; padding: 14px 16px; }
  .md-kpi-value { font-size: 21px; }
  .md-kpi-value.md-kpi-headline-value { font-size: 23px; }
  .md-perf-split { grid-template-columns: 1fr; }
  .md-perf-card { padding: 24px; }
  .md-perf-headline-value { font-size: 26px; }
  .md-breakdowns { grid-template-columns: 1fr; }
  .md-filterbar { padding: 0.6rem; }
  .md-filterbar select { width: 100%; min-width: 0; }
  .md-filterbar label { width: 100%; }
  .md-filter-summary { margin-left: 0; width: 100%; text-align: left; }
  table.md-table { font-size: 12.5px; }
  table.md-table th, table.md-table td { padding: 0.4rem 0.3rem; }
  body.view-margin-active #tab-margin.tab-content {
    padding: 1rem 1rem;
  }
}

/* iOS Safari auto-zoom fix: 16px minimum on inputs for touch devices */
@media (hover: none) and (pointer: coarse) {
  input[type="text"],
  input[type="email"],
  input[type="tel"],
  input[type="number"],
  input[type="search"],
  input[type="password"],
  input[type="date"],
  textarea,
  select {
    font-size: 16px !important;
  }
  /* Keep 44px tap targets on touch devices (desktop uses 36px controls). */
  .md-settings-save,
  .md-snapshot-now,
  .md-show-all,
  .md-filterbar select {
    min-height: 44px;
  }
}
