  :root {
    --light-grey: #F6F9FC;
    --dark-terminal-color: #0A2540;
    --accent-color: #635BFF;
    --radius: 6px;

    --card-bg: #ffffff;
    --border: #e6ebf1;
    --muted: #6b7c93;
    --text: var(--dark-terminal-color);
    --chip-bg: var(--light-grey);
    --chip-text: var(--dark-terminal-color);
    --accent: var(--accent-color);
    --heading-text: #0f172a;
    --on-strong: #ffffff;
    --surface-0: #ffffff;
    --surface-1: #f8fafc;
    --surface-2: #eef2f7;
    --card-header-bg: var(--dark-terminal-color);
    --card-header-text: #ffffff;
    --overlay-soft: rgba(255, 255, 255, 0.75);
    --overlay-strong: rgba(255, 255, 255, 0.85);
    --spinner-track: #cbd5e1;
    --backdrop: rgba(15, 23, 42, 0.6);
    --modal-backdrop: rgba(15, 23, 42, 0.45);
    --fullscreen-shadow: 0 30px 60px rgba(15, 23, 42, 0.25);
    --modal-shadow: 0 24px 40px rgba(15, 23, 42, 0.2);
    --panel-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
    --ma-button-bg: #f8fafc;
    --ma-button-text: #0f172a;
    --ma-button-hover-bg: #eef2f7;
    --ma-button-hover-border: #d1d5db;
    --ma-button-active-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.15);
    --focus-ring: #93c5fd;
    --ma-primary-bg: #eff6ff;
    --ma-primary-border: #bfdbfe;
    --ma-primary-text: #1d4ed8;
    --ma-primary-hover-bg: #dbeafe;
    --ma-primary-hover-border: #93c5fd;
    --accent-soft-bg: #eef2ff;
    --accent-soft-text: #4338ca;
    --accent-soft-border: #c7d2fe;
    --critical-bg: #fef2f2;
    --critical-border: #fecaca;
    --critical-text: #991b1b;
    --stab-overlay-bg: rgba(2, 6, 23, 0.55);
    --stab-card-bg: #ffffff;
    --stab-card-border: rgba(226, 232, 240, 1);
    --stab-card-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    --stab-card-text: #0f172a;
    --stab-sub-text: #475569;
    --stab-bar-bg: #f1f5f9;
    --stab-bar-border: #e2e8f0;
    --stab-fill-start: #2563eb;
    --stab-fill-end: #60a5fa;
    --stab-meta-text: #64748b;
    --cancel-border: #e5e7eb;
    --danger-soft-bg: #fee2e2;
    --danger-soft-border: #fecaca;
    --danger-soft-text: #991b1b;
    --input-color-scheme: light;
    --cohort-heat-start-rgb: 241, 238, 255;
    --cohort-heat-end-rgb: 194, 185, 255;

    --ok-bg: #ecfdf5;
    --ok-border: #bbf7d0;
    --ok-text: #166534;

    --warn-bg: #fff7ed;
    --warn-border: #fed7aa;
    --warn-text: #92400e;
    --shadow-under-bg: rgb(15 23 42 / 20%);

    --shadow: 0 6px 12px -8px rgb(50 50 93 / 26%),
    0 2px 6px -4px rgb(0 0 0 / 22%);
  }

  @media (prefers-color-scheme: dark) {
    :root {
      --light-grey: #0b1220;
      --dark-terminal-color: #e2e8f0;
      --accent-color: #8b89ff;

      --card-bg: #101a2b;
      --border: #273449;
      --muted: #93a4bf;
      --text: #e6edf7;
      --chip-bg: #162234;
      --chip-text: #e6edf7;
      --accent: var(--accent-color);
      --heading-text: #e6edf7;
      --on-strong: #f8fafc;
      --surface-0: #101a2b;
      --surface-1: #162234;
      --surface-2: #1d2b40;
      --card-header-bg: #1d2b40;
      --card-header-text: #e6edf7;
      --overlay-soft: rgba(11, 18, 32, 0.75);
      --overlay-strong: rgba(11, 18, 32, 0.85);
      --spinner-track: #475569;
      --backdrop: rgba(2, 6, 23, 0.75);
      --modal-backdrop: rgba(2, 6, 23, 0.75);
      --fullscreen-shadow: 0 30px 60px rgba(0, 0, 0, 0.65);
      --modal-shadow: 0 24px 40px rgba(0, 0, 0, 0.5);
      --panel-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
      --ma-button-bg: #162234;
      --ma-button-text: #e6edf7;
      --ma-button-hover-bg: #1d2b40;
      --ma-button-hover-border: #334155;
      --ma-button-active-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.55);
      --focus-ring: #60a5fa;
      --ma-primary-bg: #1e3a8a;
      --ma-primary-border: #2563eb;
      --ma-primary-text: #dbeafe;
      --ma-primary-hover-bg: #1d4ed8;
      --ma-primary-hover-border: #60a5fa;
      --accent-soft-bg: #1f2a44;
      --accent-soft-text: #c7d2fe;
      --accent-soft-border: #3f4b65;
      --critical-bg: #3f1a1d;
      --critical-border: #7f1d1d;
      --critical-text: #fca5a5;
      --stab-overlay-bg: rgba(0, 0, 0, 0.72);
      --stab-card-bg: #101a2b;
      --stab-card-border: #273449;
      --stab-card-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
      --stab-card-text: #e6edf7;
      --stab-sub-text: #93a4bf;
      --stab-bar-bg: #162234;
      --stab-bar-border: #273449;
      --stab-fill-start: #3b82f6;
      --stab-fill-end: #93c5fd;
      --stab-meta-text: #93a4bf;
      --cancel-border: #334155;
      --danger-soft-bg: #3f1a1d;
      --danger-soft-border: #7f1d1d;
      --danger-soft-text: #fca5a5;
      --input-color-scheme: dark;

      --ok-bg: #052e1b;
      --ok-border: #14532d;
      --ok-text: #86efac;

      --warn-bg: #3f290d;
      --warn-border: #92400e;
      --warn-text: #fdba74;
      --shadow-under-bg: rgb(0 0 0 / 55%);
      --cohort-heat-start-rgb: 16, 24, 40;
      --cohort-heat-end-rgb: 76, 85, 176;

      --shadow: 0 8px 14px -9px rgb(0 0 0 / 70%),
      0 3px 8px -6px rgb(0 0 0 / 62%);
    }
  }

  body {
    color: var(--text);
    background: var(--light-grey);
  }

  .card {
    position: relative;
    z-index: 0;
    isolation: isolate;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: var(--shadow);
    overflow: visible;
    margin: 0 0 12px 0;
  }
  .card > .card__bar,
  .card > .card-header {
    border-top-left-radius: inherit;
    border-top-right-radius: inherit;
  }
  .card > .card-body,
  .card > .card_body,
  .card > .card__body,
  .card > .kpi-grid,
  .card > .exceptions-body {
    border-bottom-left-radius: inherit;
    border-bottom-right-radius: inherit;
  }
  .card-body,
  .card_body {
    position: relative;
    z-index: 1;
    background: var(--surface-0);
    box-sizing: border-box;
    width: 100%;
    padding: 12px 14px;
  }
  .table-card {
  }

  .card__bar,
  .card-header {
    position: relative;
    z-index: 1;
    display: block;
    box-sizing: border-box;
    width: 100%;
    background: var(--card-header-bg);
    color: var(--card-header-text);
    padding: 10px 14px;
    font: 800 13px/1.2 system-ui;
    letter-spacing: .02em;
  }
  .card__bar a,
  .card-header a {
    color: inherit;
  }
  .card__body {
    position: relative;
    z-index: 1;
    box-sizing: border-box;
    width: 100%;
  }

  .confirm-card {
    border-color: var(--accent-soft-border);
  }

  .confirm-card__bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
  }

  .confirm-card__badge {
    background: var(--accent-soft-bg);
    color: var(--accent-soft-text);
    border: 1px solid var(--accent-soft-border);
  }

  .confirm-summary {
    margin-bottom: 12px;
    background: transparent;
    border: 0;
    padding: 0;
    box-shadow: none;
  }

  .confirm-summary__divider {
    margin-top: 0;
  }

  .confirm-summary__value {
    width: auto;
    max-width: 100%;
    flex: 0 1 auto;
  }

  .confirm-summary__value--json {
    flex: 1 1 560px;
    width: min(100%, 760px);
    font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
    white-space: pre;
  }

  .confirm-summary__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 10px;
  }

/* KPI grid: 2 rows × 3 columns */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-auto-rows: minmax(min-content, max-content);
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface-0);
  position: relative;
}
  .kpi-grid.is-loading .kpi { opacity: 0.35; }
  .kpi-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay-soft);
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease-in-out;
  }
  .kpi-grid.is-loading .kpi-loader { opacity: 1; }

  .kpi {
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 10px 10px;
    background: var(--surface-0);
  }

  .kpi .label {
    color: var(--muted);
    font: 800 11px/1.2 system-ui;
    text-transform: uppercase;
    letter-spacing: .02em;
    margin-bottom: 8px;
  }

  .kpi .value {
    font: 900 18px/1.1 system-ui;
    color: var(--text);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
  }

  .kpi .sub {
    margin-top: 6px;
    color: var(--muted);
    font: 600 11px/1.2 system-ui;
    font-variant-numeric: tabular-nums;
  }
  .kpi-section {
    grid-column: 1 / -1;
    font: 800 12px/1.2 system-ui;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 4px 2px;
  }

  .table-wrap {
    overflow: visible;
    -webkit-overflow-scrolling: touch;
    background: var(--surface-0);
    padding: 12px 0;
    max-height: none;
    margin: 12px 14px 18px 14px;
    position: relative;
  }
  .table-wrap.is-loading table { opacity: 0; }
  .table-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay-strong);
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease-in-out;
  }
  .table-wrap.is-loading .table-loader { opacity: 1; }
  .table-wrap--cohort {
    overflow-x: auto;
    margin: 12px 18px 18px;
    padding: 0;
  }
  .table-wrap--merchant {
    overflow-x: auto;
    max-width: 100%;
    margin: 12px 18px 18px;
    padding: 0;
  }
  .cohort-cell {
    font-variant-numeric: tabular-nums;
  }
  .cohort-table thead th,
  .cohort-table tbody td {
    padding: 6px 8px;
    font-size: 11px;
    line-height: 1.1;
  }
  .cohort-table thead th,
  #cohort-head th {
    white-space: nowrap !important;
    word-break: normal;
    hyphens: none;
    max-width: none;
  }
  .cohort-table thead th:first-child,
  .cohort-table tbody td:first-child {
    min-width: 140px;
  }
  .cohort-footer th {
    background: var(--light-grey);
    color: var(--heading-text);
    border-top: 1px solid var(--border);
    font-weight: 800;
  }
  .dataTables_wrapper { width: 100%; }
  .dataTables_scrollBody { overflow: auto !important; }
  .dataTables_scrollHeadInner, .dataTables_scrollBody table { width: 100% !important; }

  table.t {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 1500px;
  }

  .t thead th {
    text-align: left;
    padding: 10px 12px;
    font: 800 11px/1.2 system-ui;
    color: var(--heading-text);
    background: var(--light-grey);
    border-bottom: 1px solid var(--border);

    /* wrapped labels (2+ lines) */
    white-space: normal;
    line-height: 1.15;
    max-width: 160px;
    word-break: break-word;
    hyphens: auto;
    vertical-align: bottom;
  }
  .t-compact-head thead th {
    font-size: 9px;
    line-height: 1.1;
  }
  table.dataTable thead > tr > th.sorting,
  table.dataTable thead > tr > th.sorting_asc,
  table.dataTable thead > tr > th.sorting_desc,
  table.dataTable thead > tr > th.sorting_asc_disabled,
  table.dataTable thead > tr > th.sorting_desc_disabled,
  table.dataTable thead > tr > td.sorting,
  table.dataTable thead > tr > td.sorting_asc,
  table.dataTable thead > tr > td.sorting_desc,
  table.dataTable thead > tr > td.sorting_asc_disabled,
  table.dataTable thead > tr > td.sorting_desc_disabled {
    padding-right: 20px;
  }
  .dt-hidden { display: none; }

  .t tbody td {
    padding: 10px 12px;
    font: 600 12px/1.25 system-ui;
    color: var(--text);
    vertical-align: top;
    background: var(--surface-0);
    white-space: nowrap;
  }
  .t tbody td.wrap {
    white-space: normal;
    word-break: break-word;
    max-width: 240px;
  }
  .v-sep {
    border-right: 2px solid var(--border);
  }

  .t tbody tr:last-child td { border-bottom: 0; }

  .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
  }

  .muted { color: var(--muted); font-weight: 600; }
  .muted--label { font-size: 11px; }
  .cell-pad-lg { padding: 14px; }

  .badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 8px;
    border-radius: 999px;
    color: var(--chip-text);
    font: 800 11px/1 system-ui;
    white-space: nowrap;
  }
  .badge--wrap {
    white-space: normal;
    word-break: break-word;
  }
  .badge a { color: inherit; text-decoration: none; }
  .badge a:hover { text-decoration: underline; }

  .panel {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
    margin: 12px 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  .panel--charts {
    margin-top: 0;
  }
  .merchant-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    padding: 12px 18px;
  }
  .merchant-controls .button,
  .merchant-controls .muted {
    align-self: center;
  }
  .merchant-controls .button {
    margin-bottom: 2px;
  }
  .merchant-controls .muted {
  }
  .stack--min-220 {
    min-width: 220px;
  }
  .section-pad-y {
    padding: 12px 0;
  }
  .cohort-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 10px;
    padding: 0 18px;
  }
  .stack--ghost .stack-spacer {
    visibility: hidden;
  }
  .stack--ghost {
    justify-content: flex-end;
    align-items: stretch;
  }
  .dash-controls__right .stack-spacer {
    line-height: 1;
  }
.card.is-disabled {
  opacity: 0.45;
  pointer-events: none;
}
  .exceptions-note {
    background: var(--surface-1);
    border: 1px dashed var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    margin-top: 10px;
    margin-bottom: 10px;
  }
  .exceptions-body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    height: auto;
    padding: 12px 14px;
  }
  #exceptions-list {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
  }
  .exceptions-note .title {
    font: 800 11px/1.2 system-ui;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text);
    margin-bottom: 6px;
  }
  .exceptions-note ul {
    margin: 0;
    padding-left: 16px;
    font: 600 11px/1.35 system-ui;
    color: var(--muted);
  }
  .dash-controls {
    padding: 12px 14px;
    margin-top: 24px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: end;
    position: sticky;
    top: 24px;
    z-index: 1000;
    background: var(--card-bg);
    border: 1px solid var(--border);
    max-width: 1600px;
    margin-left: auto;
    margin-right: auto;
    justify-content: space-between;
  }
  .dash-controls__right {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: flex-end;
    flex: 1 1 auto;
  }
  .report-logo {
    height: 52px;
    width: auto;
    margin-right: 8px;
    align-self: center;
  }
  .dash-controls--mobile-menu .dash-controls__toggle {
    display: none;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-0);
    color: var(--text);
    font: 700 12px/1.2 system-ui;
    cursor: pointer;
  }
  .dash-controls--mobile-menu .dash-controls__toggle:hover {
    background: var(--surface-1);
  }
  .dash-controls--mobile-menu .dash-controls__toggle-bars {
    position: relative;
    display: inline-block;
    width: 16px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    transition: background-color 120ms ease-in-out;
  }
  .dash-controls--mobile-menu .dash-controls__toggle-bars::before,
  .dash-controls--mobile-menu .dash-controls__toggle-bars::after {
    content: "";
    position: absolute;
    left: 0;
    width: 16px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
    transition: transform 120ms ease-in-out;
  }
  .dash-controls--mobile-menu .dash-controls__toggle-bars::before {
    top: -5px;
  }
  .dash-controls--mobile-menu .dash-controls__toggle-bars::after {
    top: 5px;
  }
  .dash-controls--mobile-menu.is-open .dash-controls__toggle-bars {
    background: transparent;
  }
  .dash-controls--mobile-menu.is-open .dash-controls__toggle-bars::before {
    transform: translateY(5px) rotate(45deg);
  }
  .dash-controls--mobile-menu.is-open .dash-controls__toggle-bars::after {
    transform: translateY(-5px) rotate(-45deg);
  }
  @media (max-width: 900px) {
    .dash-controls--mobile-menu {
      display: grid;
      grid-template-columns: minmax(0, 1fr) auto;
      gap: 10px;
      align-items: center;
      top: 8px;
    }
    .dash-controls--mobile-menu .report-logo {
      height: 44px;
      margin-right: 0;
    }
    .dash-controls--mobile-menu .dash-controls__toggle {
      display: inline-flex;
      justify-self: end;
    }
    .dash-controls--mobile-menu .dash-controls__right {
      display: none;
      grid-column: 1 / -1;
      flex-direction: column;
      align-items: stretch;
      justify-content: flex-start;
      gap: 10px;
      width: 100%;
      padding-top: 10px;
      border-top: 1px solid var(--border);
    }
    .dash-controls--mobile-menu.is-open .dash-controls__right {
      display: flex;
    }
    .dash-controls--mobile-menu .dash-controls__right .stack {
      width: 100%;
    }
    .dash-controls--mobile-menu .dash-controls__right .week,
    .dash-controls--mobile-menu .dash-controls__right select.week {
      width: 100%;
      max-width: none;
      min-width: 0;
    }
  }

  /* Hide Django admin top bar for this view only */
  #header {
    display: none !important;
  }

  nav {
    display: none !important;
  }

  /* Remove extra spacing left by the header */
  #content {
    margin-top: 0 !important;
  }

  .panel-title {
    font: 800 14px/1.2 system-ui;
    color: var(--text);
  }

  .panel-sub {
    color: var(--muted);
    font: 500 12px/1.25 system-ui;
  }
  .panel-sub--spaced {
    margin: 6px 0 12px;
  }

  .chart-wrap {
    height: 270px;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px 12px;
    background: var(--surface-0);
    margin: 14px 0;
    display: flex;
    flex-direction: column;
    overflow: visible;
    position: relative;
    cursor: zoom-in;
  }
  .chart-wrap:not(.is-fullscreen) {
    padding-bottom: 0;
    margin-bottom: 8px;
  }
  .chart-wrap--low {
    height: 270px;
  }
  .chart-body {
    flex: 1 1 auto;
    min-height: 0;
    position: relative;
    width: 100%;
    height: 100%;
  }
  .chart-body canvas {
    display: block;
    position: absolute;
    inset: 0;
    height: 100% !important;
    width: 100% !important;
  }
  .chart-wrap.is-loading canvas { opacity: 0; }
  .chart-wrap .panel-title {
    padding: 6px 4px 8px 4px;
  }
  .chart-loader {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--overlay-strong);
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease-in-out;
  }
  .chart-wrap.is-loading .chart-loader { opacity: 1; }
  .chart-spinner {
    width: 28px;
    height: 28px;
    border: 3px solid var(--spinner-track);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: chart-spin 0.8s linear infinite;
  }
  @keyframes chart-spin { to { transform: rotate(360deg); } }
  .chart-close {
    position: absolute;
    top: 10px;
    right: 10px;
    border: 1px solid var(--border);
    background: var(--surface-0);
    color: var(--text);
    border-radius: 999px;
    font: 700 11px/1 system-ui;
    padding: 6px 10px;
    display: none;
    cursor: pointer;
  }
  .chart-close:hover { background: var(--light-grey); }
  .chart-wrap.is-fullscreen .chart-close { display: inline-flex; }

  .chart-fullscreen-backdrop {
    position: fixed;
    inset: 0;
    background: var(--backdrop);
    opacity: 0;
    pointer-events: none;
    transition: opacity 150ms ease-in-out;
    z-index: 1500;
  }
  .chart-fullscreen-backdrop.show {
    opacity: 1;
    pointer-events: auto;
  }
  .chart-wrap.is-fullscreen {
    position: fixed;
    top: 8vh;
    left: 5vw;
    right: 5vw;
    bottom: 8vh;
    z-index: 2001;
    height: 84vh;
    width: 90vw;
    margin: 0;
    cursor: zoom-out;
    box-shadow: var(--fullscreen-shadow);
  }
  /* Fullscreen charts can be trapped under the body-level backdrop because `.card`
     creates a stacking context (`z-index: 0` + `isolation`). Remove that stacking
     context only while the chart host card is marked as active by `modern_admin.js`. */
  .card.is-chart-fullscreen-host {
    z-index: auto;
    isolation: auto;
  }
  .card.is-chart-fullscreen-host > .card-body,
  .card.is-chart-fullscreen-host > .card_body,
  .card.is-chart-fullscreen-host > .card__body {
    z-index: auto;
  }
  body.no-scroll { overflow: hidden; }

  .filters {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: end;
  }

  .stack {
    display: flex;
    flex-direction: column;
    gap: 6px;
  }
  .stack--merchant {
    align-items: stretch;
  }
  .stack--merchant > span {
    text-align: left;
  }
  .stack--merchant .muted {
    align-self: flex-start;
  }

  .week {
    min-height: 36px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-0);
    color: var(--text);
    font: 600 12px/1.2 system-ui;
    height: 36px;
    line-height: 1.2;
    box-sizing: border-box;
  }
  input.week[type="date"] {
    color-scheme: var(--input-color-scheme);
  }
  select.week {
    min-width: 200px;
    max-width: 340px;
  }
  #merchant-search,
  #search-input,
  #min-group-threshold,
  .mdg-controls .mdg-input {
    background: var(--surface-0);
    color: var(--text);
    border-color: var(--border);
    color-scheme: var(--input-color-scheme);
  }
  #merchant-search::placeholder,
  #search-input::placeholder,
  #min-group-threshold::placeholder,
  .mdg-controls .mdg-input::placeholder {
    color: var(--muted);
    opacity: 1;
  }
  #merchant-search:-webkit-autofill,
  #merchant-search:-webkit-autofill:hover,
  #merchant-search:-webkit-autofill:focus,
  #search-input:-webkit-autofill,
  #search-input:-webkit-autofill:hover,
  #search-input:-webkit-autofill:focus,
  #min-group-threshold:-webkit-autofill,
  #min-group-threshold:-webkit-autofill:hover,
  #min-group-threshold:-webkit-autofill:focus,
  .mdg-controls .mdg-input:-webkit-autofill,
  .mdg-controls .mdg-input:-webkit-autofill:hover,
  .mdg-controls .mdg-input:-webkit-autofill:focus {
    -webkit-text-fill-color: var(--text);
    box-shadow: 0 0 0 1000px var(--surface-0) inset;
  }

  /* severity row highlight */
  .tr-ok { border-left: 4px solid transparent; }
  .tr-warning { border-left: 4px solid var(--warn-border); background: var(--warn-bg); }
  .tr-critical { border-left: 4px solid var(--critical-border); background: var(--critical-bg); }

  .issue-pill {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--chip-bg);
    font: 800 11px/1 system-ui;
    color: var(--text);
    white-space: nowrap;
    margin: 0 6px 6px 0;
  }
  .issue-pill--warning { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }
  .issue-pill--critical {
    background: var(--critical-bg);
    border-color: var(--critical-border);
    color: var(--critical-text);
  }
  .issue-modal-trigger {
    cursor: pointer;
  }
  .exceptions-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
  }
  .exceptions-row__label {
    min-width: 110px;
  }
  .exceptions-row__meta {
    margin-top: 6px;
  }
  .exceptions-row__body {
    flex: 1;
  }
  .exceptions-row__title {
    font: 800 12px/1.2 system-ui;
    color: var(--text);
    margin-bottom: 6px;
  }
  .modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 999;
  }
  .modal.is-open { display: flex; }
  .modal-backdrop {
    position: absolute;
    inset: 0;
    background: var(--modal-backdrop);
  }
  .modal-card {
    position: relative;
    z-index: 1;
    background: var(--surface-0);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: min(520px, calc(100vw - 32px));
    box-shadow: var(--modal-shadow);
  }
  .modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    font: 800 12px/1.2 system-ui;
  }
  .modal-body {
    padding: 14px;
    font: 600 12px/1.4 system-ui;
    color: var(--text);
  }
  .modal-list {
    margin: 10px 0 0;
    padding-left: 16px;
  }
  .issues-list {
    margin: 6px 0 0;
    padding-left: 16px;
    font: 600 11px/1.3 system-ui;
    color: var(--text);
  }
  .modal-close {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 8px;
    font: 700 11px/1 system-ui;
    cursor: pointer;
  }
  body.modal-open { overflow: hidden; }
  .issues-text {
    font: 700 10px/1.2 system-ui;
    color: var(--muted);
    white-space: normal;
  }
  .search-divider td { border-bottom: 2px solid var(--border); }

  /* nice responsive KPIs */
  @media (max-width: 1200px) { .kpi-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
  @media (max-width: 760px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.dash-top {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 12px;
  align-items: stretch;
  margin-top: 24px;
  margin-bottom: 12px;
}

.dash-kpis, .dash-exc {
  height: 100%;
}
.dash-exc {
  display: flex;
  flex-direction: column;
}

/* Stack on small screens */
@media (max-width: 1100px) {
  .dash-top {
    grid-template-columns: 1fr;
  }
}
  /* 3 charts side by side */
.charts-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

@media (max-width: 1500px) {
  .charts-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 900px) {
  .charts-row {
    grid-template-columns: 1fr;
  }
}

.charts-row--5 {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}
@media (max-width: 1700px) {
  .charts-row--5 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
@media (max-width: 1200px) {
  .charts-row--5 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 900px) {
  .charts-row--5 {
    grid-template-columns: 1fr;
  }
}

.charts-row--2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
@media (max-width: 900px) {
  .charts-row--2 {
    grid-template-columns: 1fr;
  }
}

.charts-row--3 {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
@media (max-width: 1500px) {
  .charts-row--3 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
@media (max-width: 900px) {
  .charts-row--3 {
    grid-template-columns: 1fr;
  }
}

.charts-section-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(0, 3fr);
  gap: 12px;
}
@media (max-width: 1300px) {
  .charts-section-grid {
    grid-template-columns: 1fr;
  }
}

/* ===================== Merchant Detail Graph ===================== */
#workspace.mdg-workspace {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.mdg-net-card {
  flex: 3;
  min-width: 0;
}

#net.mdg-net {
  height: 80vh;
  min-height: 460px;
  border: 1px solid var(--border);
  border-radius: 10px;
}

#controls.mdg-controls {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mdg-controls .card-body,
.mdg-controls .card_body,
.mdg-controls .card__body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mdg-controls .pw-section {
  gap: 6px;
}

.mdg-controls .pw-admin-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mdg-row {
  margin-top: 6px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.mdg-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font: 600 12px system-ui;
}

.mdg-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mdg-input {
  padding: 6px 10px;
  font: 14px system-ui;
  border: 1px solid var(--border);
  border-radius: 8px;
  width: 100%;
  box-sizing: border-box;
}

.mdg-input--sm {
  padding: 6px 8px;
  font: 13px system-ui;
}

.mdg-flex {
  flex: 1;
}

@media (max-width: 1360px) {
  #workspace.mdg-workspace {
    flex-direction: column;
    align-items: stretch;
  }

  .mdg-net-card,
  #controls.mdg-controls {
    flex: none;
    width: 100%;
  }

  #net.mdg-net {
    height: 62vh;
    min-height: 420px;
  }
}

@media (max-width: 900px) {
  #net.mdg-net {
    height: 56vh;
    min-height: 340px;
  }

  .mdg-controls .pw-admin-links {
    flex-direction: column;
    align-items: stretch;
  }

  .mdg-row .pw-btn,
  .mdg-controls .pw-admin-links .pw-btn {
    width: 100%;
  }

  .pw-header {
    align-items: stretch;
  }

  .pw-header-meta {
    flex-direction: column;
  }

  .pw-actions {
    margin-left: 0;
    width: 100%;
  }

  .pw-links {
    grid-template-columns: 1fr;
  }
}

/* Widget (pw) */
.pw {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  box-shadow: var(--panel-shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.pw-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
}

.pw-media {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.pw-header-meta {
  width: 100%;
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.pw-media-link {
  display: block;
  width: 100%;
  height: 100%;
  color: inherit;
  text-decoration: none;
}

.pw-avatar {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--accent-soft-bg);
  display: grid;
  place-items: center;
  font: 600 20px/1 system-ui;
  color: var(--accent-soft-text);
}

.pw-cover-photo {
  width: 112px;
  height: 56px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--accent-soft-bg);
}

.pw-cover-photo img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.pw-avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  border-radius: 50%;
}

.pw-title {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pw-name {
  font: 700 16px/1.1 system-ui;
  color: var(--text);
}

.pw-badge {
  font: 600 10px/1 system-ui;
  padding: 4px 6px;
  border-radius: 6px;
  background: var(--accent-soft-bg);
  color: var(--accent-soft-text);
  border: 1px solid var(--accent-soft-border);
  letter-spacing: 0.02em;
}

.pw-sub {
  color: var(--muted);
  font: 500 12px/1.2 system-ui;
  margin-top: 2px;
}

.pw-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
}

.pw-btn {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--ma-button-bg);
  font: 600 12px system-ui;
  color: var(--ma-button-text);
  text-decoration: none;
}

.pw-btn--primary {
  background: var(--ma-primary-bg);
  border-color: var(--ma-primary-border);
  color: var(--ma-primary-text);
}

/* Global button styling */
.button,
button,
input[type="button"],
input[type="submit"],
input[type="reset"] {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--ma-button-bg);
  font: 600 12px system-ui;
  color: var(--ma-button-text);
  text-decoration: none;
  cursor: pointer;
  transition: background 120ms ease, border-color 120ms ease, color 120ms ease,
    box-shadow 120ms ease, transform 120ms ease;
}

.button.default,
.button.primary,
button.primary,
input[type="submit"].default,
input[type="submit"].primary {
  background: var(--ma-primary-bg);
  border-color: var(--ma-primary-border);
  color: var(--ma-primary-text);
}

.button:hover,
button:hover,
input[type="button"]:hover,
input[type="submit"]:hover,
input[type="reset"]:hover {
  background: var(--ma-button-hover-bg);
  border-color: var(--ma-button-hover-border);
}

.button.default:hover,
.button.primary:hover,
button.primary:hover,
input[type="submit"].default:hover,
input[type="submit"].primary:hover {
  background: var(--ma-primary-hover-bg);
  border-color: var(--ma-primary-hover-border);
  color: var(--ma-primary-text);
}

.button:active,
button:active,
input[type="button"]:active,
input[type="submit"]:active,
input[type="reset"]:active {
  transform: translateY(1px);
  box-shadow: var(--ma-button-active-shadow);
}

.button:focus-visible,
button:focus-visible,
input[type="button"]:focus-visible,
input[type="submit"]:focus-visible,
input[type="reset"]:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

.pw-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.pw-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 8px 10px;
}

.pw-label {
  color: var(--text);
  font: 600 11px system-ui;
}

.pw-value {
  font: 700 13px system-ui;
  color: var(--text);
}

.pw-value--status-list {
  display: flex;
  justify-content: flex-end;
}

.pw-status-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}

.pw-status-list--stacked {
  flex-direction: column;
  flex-wrap: nowrap;
  align-items: flex-end;
}

.pw-status-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font: 700 11px/1 system-ui;
}

.pw-status-list--stacked .pw-status-item {
  justify-content: flex-end;
}

.pw-status-item--ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
  color: var(--ok-text);
}

.pw-status-item--critical {
  background: var(--critical-bg);
  border-color: var(--critical-border);
  color: var(--critical-text);
}

.pw-status-item--warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn-text);
}

.pw-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.pw-status-dot--ok {
  background: var(--ok-text);
}

.pw-status-dot--critical {
  background: var(--critical-text);
}

.pw-status-dot--warn {
  background: var(--warn-text);
}

.pw-status-item-state {
  opacity: 0.8;
}

.pw-links {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.pw-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--heading-text);
}

.pw-row--grid3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 5px;
}

.stat {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.stat .pw-label {
  color: var(--muted);
  font: 600 11px/1.2 system-ui;
}

.stat .pw-value {
  font: 700 14px/1.2 system-ui;
  color: var(--text);
}

@media (max-width: 600px) {
  .pw-row--grid3 {
    grid-template-columns: 1fr;
  }
}

.hide {
  display: none !important;
}

/* Legend */
.mdg-legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mdg-legend-item {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mdg-legend-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
}

.mdg-legend-dot--user {
  background: #97c2fc;
}

.mdg-legend-dot--merchant {
  background: #ffff00;
}

.mdg-legend-dot--install {
  background: #fb7e81;
}

.mdg-legend-line {
  width: 20px;
  height: 2px;
  display: inline-block;
}

.mdg-legend-line--client {
  background: #2b7ce9;
}

.mdg-legend-line--owner {
  background: #2ecc71;
}

.mdg-legend-line--referral {
  background: repeating-linear-gradient(
    to right,
    #e67e22 0 5px,
    transparent 5px 10px
  );
}

.mdg-legend-line--installation {
  background: repeating-linear-gradient(
    to right,
    #2b7ce9 0 5px,
    transparent 5px 10px
  );
}

/* Overlays */
.stab-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--stab-overlay-bg);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.stab-card {
  width: min(520px, 92vw);
  background: var(--stab-card-bg);
  border: 1px solid var(--stab-card-border);
  border-radius: 18px;
  box-shadow: var(--stab-card-shadow);
  padding: 16px 16px 14px;
  font: 500 13px/1.4 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--stab-card-text);
}

.stab-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.stab-title {
  font: 800 15px/1.2 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  letter-spacing: 0.01em;
}

.stab-percent {
  font: 800 13px/1 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  color: var(--ma-primary-text);
  background: var(--ma-primary-bg);
  border: 1px solid var(--ma-primary-border);
  padding: 6px 8px;
  border-radius: 10px;
  min-width: 56px;
  text-align: center;
}

.stab-sub {
  margin-top: 6px;
  color: var(--stab-sub-text);
  font: 600 12px/1.35 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.stab-bar {
  margin-top: 12px;
  height: 10px;
  background: var(--stab-bar-bg);
  border: 1px solid var(--stab-bar-border);
  border-radius: 999px;
  overflow: hidden;
}

.stab-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--stab-fill-start), var(--stab-fill-end));
  border-radius: 999px;
  transition: width 120ms linear;
}

.stab-meta {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--stab-meta-text);
  font: 700 12px/1 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

.stab-dot {
  opacity: 0.8;
}

@media (prefers-reduced-motion: reduce) {
  .stab-bar-fill {
    transition: none;
  }

  .stab-overlay {
    backdrop-filter: none;
    -webkit-backdrop-filter: none;
  }
}

.stab-actions {
  margin-top: 14px;
  display: flex;
  justify-content: center;
}

.stab-cancel-btn {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--cancel-border);
  background: var(--ma-button-bg);
  font: 700 12px system-ui;
  cursor: pointer;
}

.stab-cancel-btn:hover {
  background: var(--danger-soft-bg);
  border-color: var(--danger-soft-border);
  color: var(--danger-soft-text);
}
