:root {
  color-scheme: light;
  --brand: #16a34a;
  --primary: #087a35;
  --primary-hover: #06652c;
  --primary-soft: #e8f7ed;
  --bg: #f4f7f5;
  --surface: #fff;
  --surface-elevated: #fff;
  --surface-subtle: #eef3f0;
  --text: #152019;
  --muted: #627069;
  --border: #d9e2dc;
  --border-strong: #c7d3cb;
  --success: #087a35;
  --warning: #9a6700;
  --danger: #b42318;
  --focus: #2563eb;
  --shadow-sm: 0 1px 2px rgba(16, 24, 18, .05);
  --shadow-lg: 0 18px 50px rgba(16, 24, 18, .14);
  --sidebar-width: 252px;
  --serious: #c2410c;
  --s1: #2a78d6; --s2: #eb6834; --s3: #1baf7a; --s4: #eda100; --s5: #e87ba4; --s6: #008300;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); scroll-behavior: smooth; }
body { min-height: 100vh; margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button,input,select { font: inherit; }
button,select { color: inherit; }
button:focus-visible,input:focus-visible,select:focus-visible,a:focus-visible,[tabindex]:focus-visible { outline: 3px solid color-mix(in srgb, var(--focus) 35%, transparent); outline-offset: 2px; }
button:disabled { cursor: not-allowed; opacity: .48; }
[hidden] { display: none !important; }
svg { width: 20px; height: 20px; fill: currentColor; }
.skip-link { position: fixed; z-index: 100; top: 8px; left: 8px; padding: 10px 14px; transform: translateY(-150%); border-radius: 10px; background: var(--surface); color: var(--text); box-shadow: var(--shadow-lg); }
.skip-link:focus { transform: translateY(0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }

.auth-layout { display: grid; min-height: 100vh; place-items: center; padding: 24px; background: radial-gradient(circle at 50% -8%, #d6f4df 0, transparent 42%), var(--bg); }
.auth-card { width: min(440px, 100%); padding: 42px; border: 1px solid var(--border); border-radius: 26px; background: var(--surface); box-shadow: var(--shadow-lg); text-align: center; }
.brand-mark { display: grid; width: 44px; height: 44px; flex: 0 0 auto; place-items: center; border-radius: 14px; background: linear-gradient(145deg, #14a447, #087a35); color: #fff; font-size: 20px; font-weight: 900; box-shadow: 0 9px 22px rgba(8,122,53,.24); }
.auth-card .brand-mark { margin: 0 auto 18px; }
.eyebrow { margin: 0 0 4px; color: var(--primary); font-size: 11px; font-weight: 850; letter-spacing: .09em; text-transform: uppercase; }
.auth-card h1 { margin: 7px 0 10px; font-size: 29px; line-height: 1.2; }
.auth-card p:not(.eyebrow) { color: var(--muted); }
.auth-card small { display: block; margin-top: 20px; color: var(--muted); font-size: 12px; }

.primary-button,.ghost-button,.icon-button,.text-button,.danger-button { min-height: 42px; border-radius: 11px; cursor: pointer; transition: border-color .16s ease, color .16s ease, background .16s ease, transform .16s ease; }
.primary-button { width: 100%; margin-top: 12px; padding: 0 18px; border: 0; background: var(--primary); color: #fff; font-weight: 800; }
.primary-button:hover { background: var(--primary-hover); transform: translateY(-1px); }
.ghost-button { padding: 0 14px; border: 1px solid var(--border); background: transparent; color: var(--muted); }
.ghost-button:hover { border-color: var(--danger); color: var(--danger); }
.icon-button { display: grid; min-width: 42px; padding: 0 12px; place-items: center; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 750; }
.icon-button:hover { border-color: var(--border-strong); background: var(--surface-subtle); }
.text-button { padding: 0; border: 0; background: transparent; color: var(--primary); font-weight: 800; }
.danger-button { padding: 0 16px; border: 1px solid color-mix(in srgb, var(--danger) 45%, var(--border)); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); color: var(--danger); font-weight: 800; }
.danger-button:hover:not(:disabled) { border-color: var(--danger); background: color-mix(in srgb, var(--danger) 13%, var(--surface)); transform: translateY(-1px); }

.admin-shell { display: grid; min-height: 100vh; grid-template-columns: var(--sidebar-width) minmax(0,1fr); }
.sidebar { position: sticky; z-index: 30; top: 0; display: flex; height: 100vh; flex-direction: column; padding: 22px 15px; border-right: 1px solid var(--border); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 24px; }
.brand > span:last-child { display: flex; flex-direction: column; }
.brand b { font-size: 17px; }
.brand small { color: var(--muted); font-size: 11px; letter-spacing: .03em; }
nav { display: grid; gap: 5px; }
.nav-item { display: grid; min-height: 46px; grid-template-columns: 24px minmax(0,1fr); align-items: center; gap: 11px; padding: 0 12px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); text-align: left; cursor: pointer; }
.nav-item svg { width: 19px; height: 19px; }
.nav-item:hover { background: var(--surface-subtle); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 800; }
.sidebar-footer { display: grid; gap: 10px; margin-top: auto; }
.read-only-badge { display: flex; min-height: 36px; align-items: center; justify-content: center; gap: 7px; border-radius: 10px; background: var(--surface-subtle); color: var(--muted); font-size: 12px; }
.read-only-badge span { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 4px color-mix(in srgb, var(--success) 13%, transparent); }

.workspace { min-width: 0; }
.topbar { position: sticky; z-index: 20; top: 0; display: flex; height: 66px; align-items: center; gap: 12px; padding: 0 30px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface) 90%, transparent); backdrop-filter: blur(14px); }
.topbar-title { display: none; flex-direction: column; line-height: 1.15; }
.topbar-title small { color: var(--muted); font-size: 10px; }
.topbar-title b { font-size: 14px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.return-to-app { display: inline-flex; min-height: 42px; align-items: center; gap: 8px; padding: 0 14px; border: 1px solid color-mix(in srgb, var(--primary) 28%, var(--border)); border-radius: 11px; background: var(--primary-soft); color: var(--primary); font-weight: 800; text-decoration: none; transition: border-color .16s ease, background .16s ease, transform .16s ease; }
.return-to-app:hover { border-color: var(--primary); background: color-mix(in srgb, var(--primary-soft) 72%, var(--surface)); transform: translateY(-1px); }
.return-to-app svg { width: 18px; height: 18px; }
.environment-badge,.role-badge,.status-badge { display: inline-flex; min-height: 27px; align-items: center; padding: 0 9px; border-radius: 999px; font-size: 11px; font-weight: 850; white-space: nowrap; }
.environment-badge { border: 1px solid #e8c56e; background: #fff8e6; color: #805500; letter-spacing: .07em; }
.environment-badge.production { border-color: #e5aaa4; background: #fff0ef; color: #9f261d; }
.role-badge { background: var(--primary-soft); color: var(--primary); }
.menu-button { display: none; }
.sidebar-backdrop { position: fixed; z-index: 25; inset: 0; border: 0; background: rgba(10, 18, 13, .36); backdrop-filter: blur(2px); }

main { max-width: 1540px; margin: 0 auto; padding: 30px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: clamp(25px, 3vw, 31px); line-height: 1.2; letter-spacing: -.025em; }
.page-head p:not(.eyebrow) { margin: 6px 0 0; color: var(--muted); }
.page-actions { display: flex; align-items: center; gap: 10px; }
.refresh-button { width: auto; white-space: nowrap; }
.segmented { display: flex; padding: 3px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.segmented button { min-height: 36px; padding: 0 12px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; font-weight: 750; }
.segmented button.active { background: var(--primary-soft); color: var(--primary); box-shadow: var(--shadow-sm); }

.kpi-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 14px; }
.kpi-grid-wide { grid-template-columns: repeat(5,minmax(0,1fr)); }
.card { padding: 19px; border: 1px solid var(--border); border-radius: 17px; background: var(--surface); box-shadow: var(--shadow-sm); }
.kpi-card { position: relative; min-height: 120px; overflow: hidden; }
.kpi-card::after { position: absolute; width: 80px; height: 80px; top: -35px; right: -25px; border-radius: 50%; background: var(--surface-subtle); content: ""; }
.kpi-card small { color: var(--muted); font-size: 12px; }
.kpi-card strong { display: block; margin-top: 14px; font-size: 29px; line-height: 1; letter-spacing: -.03em; }
.kpi-card > span { display: block; margin-top: 7px; color: var(--muted); font-size: 11px; }
.success-card { border-color: color-mix(in srgb, var(--success) 28%, var(--border)); background: linear-gradient(145deg, var(--surface), var(--primary-soft)); }
.success-card strong { color: var(--success); }
.funnel-card { margin-top: 14px; }
.metric-ok { color: var(--success); }
.metric-warn { color: var(--warning); }
.capacity-card {
  --capacity-color: var(--success);
  grid-column: 1 / -1;
  margin-top: 14px;
  overflow: hidden;
}
.capacity-card.capacity-attention { --capacity-color: #b77900; }
.capacity-card.capacity-high { --capacity-color: #d56716; }
.capacity-card.capacity-critical { --capacity-color: var(--danger); }
.capacity-overview { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.capacity-overview h2 { margin: 0; font-size: 21px; }
.capacity-overview > div:first-child > p:last-child { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.capacity-score { display: flex; align-items: center; gap: 12px; color: var(--capacity-color); }
.capacity-score strong { min-width: 74px; font-size: 31px; line-height: 1; text-align: right; letter-spacing: -.035em; }
.capacity-status { display: inline-flex; min-height: 29px; align-items: center; padding: 0 10px; border-radius: 999px; background: color-mix(in srgb, var(--capacity-color) 11%, var(--surface)); color: var(--capacity-color); font-size: 11px; font-weight: 850; }
.capacity-status::before { width: 7px; height: 7px; margin-right: 6px; border-radius: 50%; background: currentColor; content: ""; }
.capacity-main-track,.capacity-track { overflow: hidden; background: var(--surface-subtle); }
.capacity-main-track { height: 10px; margin-top: 17px; border-radius: 999px; }
.capacity-main-track > span,.capacity-track > span { display: block; height: 100%; border-radius: inherit; background: var(--capacity-color); transition: width .35s ease; }
.capacity-layout { display: grid; grid-template-columns: minmax(300px,.8fr) minmax(420px,1.2fr); gap: 24px; margin-top: 21px; }
.capacity-resources { display: grid; align-content: start; gap: 12px; }
.capacity-resource { --capacity-color: var(--success); }
.capacity-resource.capacity-attention { --capacity-color: #b77900; }
.capacity-resource.capacity-high { --capacity-color: #d56716; }
.capacity-resource.capacity-critical { --capacity-color: var(--danger); }
.capacity-resource-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 6px; }
.capacity-resource-head > span { display: flex; min-width: 0; flex-direction: column; }
.capacity-resource-head small { overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.capacity-resource-head strong { color: var(--capacity-color); font-size: 13px; }
.capacity-track { height: 7px; border-radius: 999px; }
.capacity-chart-wrap { min-width: 0; padding: 5px 10px 0; border: 1px solid var(--border); border-radius: 13px; background: var(--surface-subtle); }
.capacity-chart { display: block; width: 100%; height: 168px; overflow: visible; }
.chart-guide { stroke-width: 1; stroke-dasharray: 5 5; }
.chart-guide-attention { stroke: color-mix(in srgb, var(--warning) 42%, transparent); }
.chart-guide-high { stroke: color-mix(in srgb, var(--danger) 42%, transparent); }
.chart-line { fill: none; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
.chart-line-average { stroke: var(--primary); stroke-width: 3; }
.chart-line-peak { stroke: color-mix(in srgb, var(--warning) 75%, var(--danger)); stroke-width: 1.5; stroke-dasharray: 5 4; }
.chart-axis,.chart-legend { display: flex; align-items: center; justify-content: space-between; color: var(--muted); font-size: 9px; }
.chart-legend { justify-content: flex-end; gap: 15px; padding: 5px 0 9px; }
.chart-legend span::before { display: inline-block; width: 12px; height: 2px; margin: 0 5px 2px 0; background: currentColor; content: ""; }
.legend-average { color: var(--primary); }
.legend-peak { color: var(--warning); }
.capacity-empty { display: grid; min-height: 206px; place-items: center; padding: 24px; border: 1px dashed var(--border); border-radius: 13px; color: var(--muted); text-align: center; }
.cycle-summary { display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 8px; margin-top: 18px; }
.cycle-summary span { min-width: 0; padding: 11px 12px; border-radius: 11px; background: var(--surface-subtle); }
.cycle-summary small,.cycle-summary b { display: block; }
.cycle-summary small { color: var(--muted); font-size: 9px; }
.cycle-summary b { overflow: hidden; margin-top: 4px; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.capacity-footnote { margin: 14px 0 0; color: var(--muted); font-size: 10px; }
.dashboard-grid { display: grid; grid-template-columns: 1.25fr 1fr; gap: 14px; margin-top: 14px; }
.audit-card { grid-column: 1/-1; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.card h2,.drawer-head h2 { margin: 0; font-size: 18px; letter-spacing: -.01em; }
.delivery-metrics { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px 20px; }
.metric-row { display: grid; min-height: 38px; grid-template-columns: 10px minmax(0,1fr) auto; align-items: center; gap: 9px; border-bottom: 1px solid var(--border); }
.metric-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.metric-dot.status-sent { background: var(--success); }
.metric-dot.status-pending,.metric-dot.status-retry { background: var(--warning); }
.metric-dot.status-failed,.metric-dot.status-blocked { background: var(--danger); }
.retention-grid { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 10px; }
.retention-item { min-width: 0; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-subtle); }
.retention-item span,.retention-item strong,.retention-item small { display: block; }
.retention-item span { color: var(--text); font-size: 12px; font-weight: 750; }
.retention-item strong { margin-top: 8px; color: var(--primary); font-size: 25px; line-height: 1; letter-spacing: -.025em; }
.retention-item small { margin-top: 7px; color: var(--muted); font-size: 11px; line-height: 1.35; }
.info-note { margin: 15px 0 0; padding: 11px 13px; border-radius: 11px; background: var(--surface-subtle); color: var(--muted); font-size: 11px; }
.source-list,.audit-list { display: grid; gap: 3px; }
.source-row,.audit-row { display: grid; min-height: 50px; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); }
.source-row:first-child,.audit-row:first-child { border-top: 0; }
.source-row span,.audit-row > span:first-child { display: flex; min-width: 0; flex-direction: column; }
.source-row small,.audit-row small { color: var(--muted); font-size: 11px; }

.toolbar { display: flex; gap: 10px; margin-bottom: 13px; }
.toolbar-wrap { flex-wrap: wrap; }
.search-input,.select-input { min-height: 43px; padding: 0 13px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface); color: var(--text); }
.search-input { width: min(420px,100%); }
.select-input { min-width: 160px; }
.table-card { padding: 0; overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table caption { padding: 15px 18px; color: var(--muted); text-align: left; }
.data-table th,.data-table td { padding: 13px 15px; border-top: 1px solid var(--border); text-align: left; vertical-align: middle; }
.data-table th { background: var(--surface-subtle); color: var(--muted); font-size: 11px; letter-spacing: .025em; white-space: nowrap; }
.data-table td { font-size: 12px; }
.data-table td b,.data-table td small { display: block; }
.data-table td small { margin-top: 2px; color: var(--muted); }
.data-table-dense td { max-width: 320px; }
.interactive-row { cursor: pointer; transition: background .14s ease; }
.interactive-row:hover { background: color-mix(in srgb, var(--primary-soft) 55%, transparent); }
.row-action { width: 42px; color: var(--primary); font-size: 18px !important; font-weight: 800; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 9px; padding: 13px 15px; border-top: 1px solid var(--border); }
.pagination span { margin-right: 3px; color: var(--muted); font-size: 11px; }
.pagination .icon-button { min-width: 38px; min-height: 38px; padding: 0; }
.source-tags,.chip-list,.summary-list { display: flex; flex-wrap: wrap; gap: 5px; }
.source-tags span,.data-chip,.summary-pill { display: inline-flex; min-height: 25px; align-items: center; gap: 4px; padding: 3px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-subtle); color: var(--text); font-size: 10px; white-space: nowrap; }
.data-chip small { display: inline !important; margin: 0 !important; color: var(--muted); }
.status-badge { gap: 6px; background: var(--surface-subtle); color: var(--muted); }
.status-badge::before { width: 7px; height: 7px; border-radius: 50%; background: currentColor; content: ""; }
.status-sent,.status-success,.status-active,.status-paid { background: var(--primary-soft); color: var(--success); }
.status-pending,.status-retry,.status-created { background: #fff7e1; color: var(--warning); }
.status-failed,.status-denied,.status-blocked,.status-inactive { background: #fff0ef; color: var(--danger); }
.status-account_blocked { background: #fff0ef; color: var(--danger); }
.status-admin { background: color-mix(in srgb, var(--primary) 12%, var(--surface)); color: var(--primary); }
.status-cancelled,.status-refunded { background: var(--surface-subtle); color: var(--muted); }
.user-badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.blocked-row { background: color-mix(in srgb, var(--danger) 3%, var(--surface)); }
.admin-grant-card { display: grid; grid-template-columns: minmax(220px,1fr) minmax(360px,1.4fr); gap: 18px; align-items: end; margin-bottom: 15px; padding: 18px; }
.admin-grant-card h2 { margin: 3px 0 5px; font-size: 17px; }
.admin-grant-card p { margin: 0; color: var(--muted); font-size: 12px; }
.admin-grant-form { display: grid; grid-template-columns: minmax(140px,1fr) minmax(150px,.8fr) auto; gap: 9px; }
.error-copy { display: -webkit-box; overflow: hidden; color: var(--danger); -webkit-box-orient: vertical; -webkit-line-clamp: 2; }

.stat-strip { display: grid; grid-template-columns: repeat(auto-fit,minmax(166px,1fr)); gap: 10px; }
.stat-tile { display: grid; align-content: start; gap: 3px; padding: 13px 15px 11px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-sm); }
.stat-tile > small { color: var(--muted); font-size: 11px; font-weight: 600; }
.stat-row { display: flex; align-items: baseline; gap: 8px; }
.stat-row b { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.delta { font-size: 11px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.is-up { color: var(--success); }
.delta.is-down { color: var(--danger); }
.delta.is-flat { color: var(--muted); font-weight: 600; }
.spark { display: block; width: 100%; height: 26px; margin-top: 3px; }
.spark-empty { height: 26px; margin-top: 3px; }

.dashboard-grid-wide { grid-template-columns: minmax(0,1.5fr) minmax(0,1fr); align-items: start; }
.dashboard-column { display: grid; min-width: 0; align-content: start; gap: 14px; }
/* Grid items default to min-width:auto: without this the source table's own
   width pushed its card past the viewport instead of scrolling inside it. */
.dashboard-column > .card { min-width: 0; }
.card-note { color: var(--muted); font-size: 11px; }
.chart-card .card-head { flex-wrap: wrap; row-gap: 8px; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-left: auto; }
.chart-legend span { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; font-weight: 600; }
.swatch { width: 9px; height: 9px; flex: none; border-radius: 2px; }
.source-chart-legend { gap: 6px 8px; padding: 0; }
.source-chart-legend span { padding: 4px 7px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-subtle); color: var(--text); }
.source-chart-legend span::before { display: none; content: none; }
.source-chart-legend .swatch { width: 12px; height: 12px; border-radius: 50%; background: var(--legend-color); box-shadow: 0 0 0 1px color-mix(in srgb,var(--legend-color) 55%,var(--border-strong)); }
.trend-chart { display: block; width: 100%; max-width: 100%; height: auto; overflow: visible; }
.chart-axis { fill: var(--muted); font-size: 10px; }
.gridline { stroke: var(--surface-subtle); stroke-width: 1; }
.crosshair { stroke: var(--border-strong); stroke-width: 1; stroke-dasharray: 3 3; }
.chart-tip { position: fixed; z-index: 30; min-width: 156px; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface-elevated); box-shadow: var(--shadow-lg); pointer-events: none; font-size: 12px; }
.chart-tip h4 { margin: 0 0 5px; color: var(--muted); font-size: 11px; font-weight: 600; }
.tip-row { display: flex; align-items: center; gap: 7px; padding: 1px 0; }
.tip-row b { margin-left: auto; font-variant-numeric: tabular-nums; }
.tip-row.is-total { margin-top: 5px; padding-top: 5px; border-top: 1px solid var(--border); }

.table-scroll { overflow-x: auto; }
.quality-table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.quality-table th { padding: 0 8px 7px; color: var(--muted); font-size: 11px; font-weight: 600; text-align: right; white-space: nowrap; }
.quality-table th:first-child,.quality-table td:first-child { padding-left: 0; text-align: left; }
.quality-table th:last-child,.quality-table td:last-child { padding-right: 0; }
.quality-table td { padding: 7px 8px; border-top: 1px solid var(--border); text-align: right; }
.src-name { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.src-bar { height: 6px; min-width: 2px; flex: none; border-radius: 3px; }
.quality-chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 20px; background: var(--surface-subtle); font-size: 11px; font-weight: 600; }
.quality-chip i { width: 7px; height: 7px; flex: none; border-radius: 50%; background: currentColor; }
.quality-chip.is-healthy { color: var(--success); }
.quality-chip.is-degraded { color: var(--warning); }
.quality-chip.is-failed { color: var(--danger); }
.quality-chip.is-unknown { color: var(--muted); }

.delivery-bar { display: flex; overflow: hidden; height: 26px; gap: 2px; margin-bottom: 10px; border-radius: 6px; background: var(--surface-subtle); }
.delivery-segment { height: 100%; }
.delivery-list { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 5px 18px; }
.delivery-row { display: flex; align-items: center; gap: 7px; font-size: 12px; }
.delivery-row i { width: 7px; height: 7px; flex: none; border-radius: 50%; }
.delivery-row b { margin-left: auto; font-variant-numeric: tabular-nums; }

.funnel-list { display: grid; gap: 0; }
.funnel-group { margin: 15px 0 6px; color: var(--muted); font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; }
.funnel-group:first-child { margin-top: 0; }
.funnel-step { display: grid; grid-template-columns: 180px minmax(0,1fr) 76px; align-items: center; gap: 12px; padding: 5px 0; }
.funnel-name { color: var(--muted); font-weight: 600; }
.funnel-track { overflow: hidden; height: 22px; border-radius: 5px; background: var(--surface-subtle); }
.funnel-bar { display: block; height: 100%; border-radius: 0 5px 5px 0; background: var(--primary); }
.funnel-value { font-variant-numeric: tabular-nums; font-weight: 700; text-align: right; }
.funnel-drop { margin: 0 0 4px; padding-left: 192px; color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.funnel-drop b { color: var(--danger); }

.summary-block { display: grid; gap: 9px; margin-bottom: 15px; }
.summary-strip { display: grid; grid-template-columns: repeat(auto-fill,minmax(172px,1fr)); gap: 10px; }
.summary-notes { display: flex; flex-wrap: wrap; gap: 5px 22px; margin: 0; padding-inline: 3px; color: var(--text); font-size: 12px; }
.summary-notes small { margin-right: 5px; color: var(--muted); }
.summary-cell { display: grid; align-content: start; gap: 3px; padding: 13px 15px; border: 1px solid var(--border); border-left: 3px solid var(--border-strong); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow-sm); }
.summary-cell small { color: var(--muted); font-size: 11px; }
.summary-cell b { font-size: 21px; font-variant-numeric: tabular-nums; }
.summary-cell > span { color: var(--muted); font-size: 11px; }
.summary-cell.is-good { border-left-color: var(--success); }
.summary-cell.is-warn { border-left-color: var(--warning); }
.summary-cell.is-bad { border-left-color: var(--danger); }
.summary-inline { display: block; font-size: 13px; font-weight: 600; line-height: 1.35; }
.time-stack { display: grid; gap: 1px; }
.time-stack small { color: var(--muted); font-size: 11px; }

.source-error-list { display: grid; gap: 6px; margin: 0; padding: 11px 13px; border-radius: 12px; background: var(--surface-subtle); list-style: none; }
.source-error-list li { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; font-size: 12px; }
.source-error-list b { font-weight: 600; }
.source-error-list small { display: block; color: var(--muted); font-size: 10px; }
.source-error-reason { color: var(--danger); text-align: right; }
.source-error-reason small { color: var(--muted); }
.source-card.is-failed { border-left: 3px solid var(--danger); }
.source-card.is-degraded { border-left: 3px solid var(--warning); }
.source-card.is-healthy { border-left: 3px solid var(--success); }
.source-card.is-unknown { border-left: 3px solid var(--border-strong); }

.source-grid { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 14px; }
.source-card { display: grid; gap: 17px; }
.source-card-head,.source-card-head > div { display: flex; align-items: center; justify-content: space-between; gap: 11px; }
.source-card-head > div > span:last-child { display: flex; flex-direction: column; }
.source-card-head small { color: var(--muted); font-size: 11px; }
.source-avatar { display: grid; width: 41px; height: 41px; place-items: center; border-radius: 12px; background: var(--primary-soft); color: var(--primary); font-size: 12px; font-weight: 900; }
.source-kpis { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; }
.source-kpis div { padding: 12px; border-radius: 12px; background: var(--surface-subtle); }
.source-kpis small,.source-kpis b { display: block; }
.source-kpis small { color: var(--muted); font-size: 10px; }
.source-kpis b { margin-top: 7px; font-size: 19px; }
.source-foot { display: flex; flex-wrap: wrap; gap: 8px 18px; color: var(--muted); font-size: 11px; }
.source-foot b { color: var(--text); }
.qa-card { display: grid; gap: 16px; margin-top: 14px; }
.qa-card.is-passed { border-color: color-mix(in srgb, var(--success) 35%, var(--border)); }
.qa-card.is-failed { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)); }
.qa-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.qa-card-head h2,.qa-card > div h2 { margin: 3px 0 6px; font-size: 18px; }
.qa-card-head p,.qa-card > div > p:last-child { margin: 0; color: var(--muted); font-size: 12px; }
.qa-kpis { max-width: 680px; }
.qa-cell-list { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; margin: 0; padding: 0; list-style: none; }
.qa-cell { display: flex; min-width: 0; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-subtle); }
.qa-cell > span { display: grid; min-width: 0; gap: 3px; }
.qa-cell > span:last-child { flex: 0 0 auto; text-align: right; }
.qa-cell b { overflow: hidden; color: var(--text); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.qa-cell small { overflow: hidden; color: var(--muted); font-size: 9px; text-overflow: ellipsis; white-space: nowrap; }
.qa-cell.is-passed { border-color: color-mix(in srgb, var(--success) 24%, var(--border)); background: color-mix(in srgb, var(--success) 4%, var(--surface-subtle)); }
.qa-cell.is-failed { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); background: color-mix(in srgb, var(--danger) 5%, var(--surface-subtle)); }
.qa-cell.is-empty { border-style: dashed; }
.real-filter-summary { grid-template-columns: repeat(4,minmax(0,1fr)); max-width: none; }
.real-filter-list { display: grid; gap: 8px; }
.real-filter-row { overflow: hidden; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-subtle); }
.real-filter-row.is-attention { border-color: color-mix(in srgb, var(--danger) 36%, var(--border)); }
.real-filter-row.is-blocked { border-color: color-mix(in srgb, var(--warning) 38%, var(--border)); }
.real-filter-row summary { display: flex; min-height: 58px; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 15px; cursor: pointer; list-style: none; }
.real-filter-row summary::-webkit-details-marker { display: none; }
.real-filter-row summary > span:first-child { display: grid; min-width: 0; gap: 3px; }
.real-filter-row summary b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.real-filter-row summary small { color: var(--muted); font-size: 10px; }
.real-filter-status { flex: 0 0 auto; padding: 7px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 10px; font-weight: 850; }
.real-filter-row.is-no_results .real-filter-status { background: var(--surface-elevated); color: var(--muted); }
.real-filter-row.is-attention .real-filter-status { background: var(--danger-soft); color: var(--danger); }
.real-filter-row.is-blocked .real-filter-status { background: color-mix(in srgb, var(--warning) 12%, var(--surface)); color: var(--warning); }
.real-filter-row[open] summary { border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--primary-soft) 36%, transparent); }
.real-filter-kpis { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 8px; padding: 14px 14px 0; }
.real-filter-kpis > span { display: grid; gap: 4px; padding: 10px; border-radius: 11px; background: var(--surface); }
.real-filter-kpis small { color: var(--muted); font-size: 9px; }
.real-filter-kpis b { font-size: 16px; }
.audit-issue-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 12px 14px 0; }
.audit-issue { padding: 6px 8px; border-radius: 9px; background: var(--danger-soft); color: var(--danger); font-size: 9px; font-weight: 750; }
.real-filter-chain { display: flex; gap: 7px; padding: 14px; overflow-x: auto; scrollbar-width: thin; }
.real-filter-step { position: relative; display: grid; min-width: 112px; gap: 4px; padding: 9px 10px; border: 1px solid color-mix(in srgb, var(--success) 30%, var(--border)); border-radius: 10px; background: var(--surface); }
.real-filter-step:not(:last-child)::after { position: absolute; top: 50%; right: -8px; color: var(--muted); content: '›'; transform: translateY(-50%); }
.real-filter-step.is-zero { border-color: var(--border); color: var(--muted); }
.real-filter-step b { font-size: 9px; }
.real-filter-step small { color: var(--primary); font-size: 12px; font-weight: 850; }
.real-filter-step.is-zero small { color: var(--muted); }
.real-filter-note { margin: 0; padding: 0 14px 14px; color: var(--muted); font-size: 10px; }

.drawer-backdrop { position: fixed; z-index: 40; inset: 0; border: 0; background: rgba(8, 14, 10, .34); backdrop-filter: blur(2px); }
.detail-drawer { position: fixed; z-index: 41; top: 0; right: 0; display: flex; width: min(480px,100%); height: 100vh; flex-direction: column; gap: 22px; padding: 25px; overflow: auto; border-left: 1px solid var(--border); background: var(--surface-elevated); box-shadow: var(--shadow-lg); animation: drawer-in .2s ease-out; }
.drawer-navigation { position: sticky; z-index: 3; top: -25px; display: flex; min-height: 58px; align-items: center; margin: -25px -25px 0; padding: 8px 25px; border-bottom: 1px solid var(--border); background: color-mix(in srgb, var(--surface-elevated) 92%, transparent); backdrop-filter: blur(14px); }
.drawer-back-button { display: inline-flex; min-height: 42px; align-items: center; gap: 9px; padding: 0 12px 0 8px; border: 0; border-radius: 11px; background: transparent; color: var(--primary); font-weight: 800; cursor: pointer; transition: background .16s ease, transform .16s ease; }
.drawer-back-button:hover { background: var(--primary-soft); transform: translateX(-1px); }
.drawer-back-button svg { width: 19px; height: 19px; }
@keyframes drawer-in { from { transform: translateX(30px); opacity: 0; } }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding-bottom: 17px; border-bottom: 1px solid var(--border); }
.drawer-head > div > small,.drawer-meta { color: var(--muted); font-size: 11px; }
.drawer-kpis { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
.drawer-kpis div { padding: 13px; border-radius: 12px; background: var(--surface-subtle); }
.drawer-kpis small,.drawer-kpis b { display: block; }
.drawer-kpis small { color: var(--muted); font-size: 10px; }
.drawer-kpis b { margin-top: 5px; font-size: 20px; }
.detail-drawer h3 { margin: 0 0 10px; font-size: 14px; }
.drawer-list { display: grid; gap: 8px; }
.drawer-list-item { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 12px; }
.drawer-list-item > div:first-child { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.drawer-admin-actions { display: grid; gap: 12px; padding: 15px; border: 1px solid color-mix(in srgb, var(--danger) 25%, var(--border)); border-radius: 14px; background: color-mix(in srgb, var(--danger) 4%, var(--surface)); }
.drawer-admin-actions h3 { margin-bottom: 4px; }
.drawer-admin-actions p { margin: 0; color: var(--muted); font-size: 11px; }
.drawer-admin-actions .danger-button { width: 100%; }
.drawer-account-actions,.drawer-admin-access { display: grid; gap: 12px; padding: 15px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface-subtle); }
.drawer-account-actions.is-blocked { border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); background: color-mix(in srgb, var(--danger) 5%, var(--surface)); }
.drawer-account-actions h3,.drawer-admin-access h3 { margin-bottom: 4px; }
.drawer-account-actions p,.drawer-admin-access p { margin: 0; color: var(--muted); font-size: 11px; }
.drawer-account-actions .primary-button,.drawer-account-actions .danger-button { width: 100%; }
.admin-access-controls { display: grid; grid-template-columns: 1fr; gap: 8px; }
.action-feedback:empty { display: none; }
.action-feedback.success { padding: 9px 10px; border-radius: 9px; background: var(--primary-soft); color: var(--success); }
.action-feedback.error { padding: 9px 10px; border-radius: 9px; background: color-mix(in srgb, var(--danger) 9%, var(--surface)); color: var(--danger); }
.drawer-loading { margin: auto; color: var(--muted); }
.drawer-meta { margin-top: auto; }

.empty,.inline-error { padding: 30px; color: var(--muted); text-align: center; }
.inline-error { border: 1px solid #efc3bf; border-radius: 14px; background: #fff2f1; color: var(--danger); }
.inline-error p { margin: 6px 0 15px; }
.skeleton { position: relative; min-height: 112px; overflow: hidden; }
.skeleton::after { position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg,transparent,rgba(255,255,255,.65),transparent); animation: shimmer 1.2s infinite; content: ""; }
@keyframes shimmer { to { transform: translateX(100%); } }

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0c1310;
  --surface: #141d18;
  --surface-elevated: #18231d;
  --surface-subtle: #1c2921;
  --text: #eff5f1;
  --muted: #a5b5aa;
  --border: #304238;
  --border-strong: #486052;
  --primary: #62dc88;
  --primary-hover: #7ce49a;
  --primary-soft: #173b24;
  --success: #62dc88;
  --warning: #f2c45e;
  --danger: #ff8379;
  --focus: #78a9ff;
  --serious: #f0956a;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70; --s4: #c98500; --s5: #d55181; --s6: #0f9d0f;
}
html[data-theme="dark"] .environment-badge { border-color: #765f2d; background: #342d1c; color: #f2c45e; }
html[data-theme="dark"] .environment-badge.production { border-color: #70413d; background: #352221; color: #ff8379; }
html[data-theme="dark"] .status-pending,html[data-theme="dark"] .status-retry { background: #362f1c; }
html[data-theme="dark"] .summary-cell,html[data-theme="dark"] .source-error-list { background: var(--surface-subtle); }
html[data-theme="dark"] .status-failed,html[data-theme="dark"] .status-denied,html[data-theme="dark"] .status-blocked,html[data-theme="dark"] .status-inactive { background: #392321; }
html[data-theme="dark"] .status-account_blocked { background: #392321; }
html[data-theme="dark"] .inline-error { border-color: #70413d; background: #352221; }

@media (max-width: 1180px) {
  .kpi-grid-wide { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .data-table th,.data-table td { padding-inline: 11px; }
}

@media (max-width: 960px) {
  :root { --sidebar-width: 76px; }
  .sidebar { padding-inline: 10px; }
  .brand { justify-content: center; padding-inline: 6px; }
  .brand > span:last-child,.nav-item > span,.sidebar-footer .read-only-badge { display: none; }
  .nav-item { grid-template-columns: 1fr; padding: 0; place-items: center; }
  .sidebar-footer .ghost-button { padding: 0; font-size: 0; }
  .sidebar-footer .ghost-button::after { font-size: 18px; content: "↪"; }
  .kpi-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .capacity-layout { grid-template-columns: 1fr; }
  .source-grid { grid-template-columns: 1fr; }
}

@media (max-width: 700px) {
  .admin-shell { display: block; }
  .sidebar { position: fixed; width: 278px; padding: 20px 15px calc(20px + env(safe-area-inset-bottom)); transform: translateX(-106%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
  .sidebar.open { transform: translateX(0); }
  .brand { justify-content: flex-start; }
  .brand > span:last-child,.nav-item > span,.sidebar-footer .read-only-badge { display: flex; }
  .nav-item { grid-template-columns: 24px minmax(0,1fr); padding: 0 12px; place-items: initial; }
  .sidebar-footer .ghost-button { padding: 0 14px; font-size: 14px; }
  .sidebar-footer .ghost-button::after { content: none; }
  .menu-button { display: grid; }
  .topbar { height: 62px; padding: 0 14px; }
  .topbar-title { display: flex; }
  .environment-badge { display: none; }
  .return-to-app { min-width: 42px; padding: 0; justify-content: center; }
  .return-to-app span { display: none; }
  .role-badge { padding-inline: 8px; }
  main { padding: 20px 13px calc(24px + env(safe-area-inset-bottom)); }
  .page-head { align-items: stretch; flex-direction: column; margin-bottom: 17px; }
  .page-head h1 { font-size: 25px; }
  .page-actions { align-items: stretch; flex-direction: column; }
  .segmented { width: 100%; }
  .segmented button { flex: 1; }
  .refresh-button { width: 100%; }
  .kpi-grid,.kpi-grid-wide { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 9px; }
  .card { padding: 15px; border-radius: 15px; }
  .kpi-card { min-height: 108px; }
  .kpi-card strong { font-size: 24px; }
  .delivery-metrics { grid-template-columns: 1fr; }
  .retention-grid { grid-template-columns: 1fr; }
  .capacity-overview { align-items: stretch; flex-direction: column; }
  .capacity-score { justify-content: space-between; }
  .capacity-layout { gap: 16px; }
  .capacity-chart { height: 145px; }
  .cycle-summary { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .toolbar { display: grid; grid-template-columns: 1fr; }
  .admin-grant-card { grid-template-columns: 1fr; }
  .admin-grant-form { grid-template-columns: 1fr; }
  .search-input,.select-input { width: 100%; min-width: 0; }
  .table-card { border-radius: 15px; }
  .data-table,.data-table tbody,.data-table tr,.data-table td { display: block; }
  .data-table thead { display: none; }
  .data-table caption { padding: 13px 14px; }
  .data-table tr { padding: 13px 14px; border-top: 1px solid var(--border); }
  .data-table td { display: flex; max-width: none; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 5px 0; border: 0; text-align: right; }
  .data-table td::before { flex: 0 0 38%; color: var(--muted); font-size: 10px; content: attr(data-label); text-align: left; }
  .data-table td:first-child { display: block; text-align: left; }
  .data-table td:first-child::before { display: none; }
  .data-table td.row-action { display: none; }
  .data-table .time-stack { justify-items: end; text-align: right; }
  .data-table .chip-list,.data-table .source-tags { justify-content: flex-end; }
  .pagination { justify-content: space-between; }
  .pagination span { margin-right: auto; }
  .summary-strip { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
  .dashboard-grid-wide { grid-template-columns: minmax(0,1fr); }
  .stat-strip { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
  .stat-tile { padding: 11px 12px 9px; }
  .stat-row b { font-size: 20px; }
  .chart-legend { width: 100%; margin-left: 0; }
  .source-chart-legend { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); }
  .source-chart-legend span { min-width: 0; }
  .delivery-list { grid-template-columns: 1fr; }
  .funnel-step { grid-template-columns: minmax(0,1fr) auto; gap: 3px 10px; }
  .funnel-name { grid-area: 1 / 1; }
  .funnel-value { grid-area: 1 / 2; }
  .funnel-track { grid-area: 2 / 1 / 3 / -1; height: 16px; }
  .funnel-drop { padding-left: 0; }
  .chart-axis { font-size: 13px; }
  .summary-notes { flex-direction: column; gap: 4px; }
  .summary-cell { padding: 11px 13px; }
  .summary-cell b { font-size: 18px; }
  .source-card { gap: 13px; }
  .source-error-list li { align-items: flex-start; flex-direction: column; gap: 2px; }
  .source-error-reason { text-align: left; }
  .source-kpis { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .source-kpis div { padding: 9px; }
  .source-kpis b { font-size: 17px; }
  .qa-card-head { align-items: stretch; flex-direction: column; }
  .qa-cell-list { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .real-filter-summary,.real-filter-kpis { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .detail-drawer { padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
  .drawer-navigation { top: -20px; margin: -20px -16px 0; padding-inline: 16px; }
}

@media (max-width: 410px) {
  .summary-cell { padding: 9px 11px; }
  .summary-cell b { font-size: 17px; }
  .kpi-grid,.kpi-grid-wide { grid-template-columns: 1fr 1fr; }
  .source-kpis { grid-template-columns: 1fr; }
  .real-filter-summary { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .source-kpis div { display: flex; align-items: center; justify-content: space-between; }
  .capacity-score strong { font-size: 28px; }
  .capacity-chart-wrap { padding-inline: 4px; }
  .source-kpis b { margin: 0; }
  .qa-cell-list { grid-template-columns: 1fr; }
  .real-filter-row summary { align-items: flex-start; flex-direction: column; }
  .real-filter-status { align-self: flex-start; }
}

@media (prefers-reduced-motion: reduce) {
  *,*::before,*::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
