:root {
  color-scheme: dark;
  --bg: #0a101b;
  --bg-glow: rgba(48, 114, 255, .12);
  --panel: #111b2b;
  --panel-raised: #162238;
  --soft: #0d1726;
  --text: #eff5ff;
  --muted: #8fa1ba;
  --faint: #63738a;
  --line: #23334a;
  --line-strong: #344967;
  --accent: #4f88ff;
  --accent-strong: #2f6ff2;
  --accent-soft: rgba(79, 136, 255, .13);
  --cyan: #38c9dc;
  --green: #37d29c;
  --red: #fb7185;
  --violet: #a68aff;
  --gold: #f5bf61;
  --shadow: 0 16px 42px rgba(0, 0, 0, .16);
  --radius: 16px;
  --grid-row: 64px;
  --grid-gap: 16px;
}

html[data-theme="graphite"] {
  --bg: #101113; --bg-glow: rgba(255,255,255,.04); --panel: #181a1e; --panel-raised: #202329;
  --soft: #131518; --text: #f3f4f6; --muted: #9ca3af; --faint: #6b7280; --line: #2c3036;
  --line-strong: #42474f; --accent: #e5e7eb; --accent-strong: #c9cdd3; --accent-soft: rgba(255,255,255,.08);
  --cyan: #79d4dc; --green: #6dd7ac; --violet: #b7a1ee; --gold: #e7bc72;
}

html[data-theme="cloud"] {
  color-scheme: light;
  --bg: #edf2f8; --bg-glow: rgba(50, 104, 220, .1); --panel: #ffffff; --panel-raised: #f7f9fc;
  --soft: #f3f6fa; --text: #182337; --muted: #66758a; --faint: #8996a7; --line: #dce4ee;
  --line-strong: #c7d2e1; --accent: #346feb; --accent-strong: #225bd3; --accent-soft: #e9f0ff;
  --cyan: #24a8bf; --green: #148462; --red: #cf4961; --violet: #7969ce; --gold: #cf9134;
  --shadow: 0 14px 36px rgba(26, 50, 89, .07);
}

html[data-theme="paper"] {
  color-scheme: light;
  --bg: #f7f6f2; --bg-glow: rgba(108, 83, 44, .07); --panel: #fffefa; --panel-raised: #f8f5ef;
  --soft: #f4f1ea; --text: #292721; --muted: #716d63; --faint: #999287; --line: #e7e1d5;
  --line-strong: #d7cebd; --accent: #8b6a35; --accent-strong: #725326; --accent-soft: #f1e9da;
  --cyan: #4c8b91; --green: #507c65; --red: #b55e63; --violet: #7d7098; --gold: #b8863f;
  --shadow: 0 14px 36px rgba(54, 45, 30, .05);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--text); background: radial-gradient(circle at 72% -10%, var(--bg-glow), transparent 32rem), var(--bg); font: 14px/1.45 "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif; transition: background .25s, color .25s; }
button, input { font: inherit; }
button { color: inherit; }
button, input[type="checkbox"] { cursor: pointer; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg { width: 18px; height: 18px; display: block; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
h1, h2, p { margin: 0; }
.app-shell { width: min(1800px, 100%); margin: 0 auto; padding: 24px clamp(16px, 2.3vw, 40px) 28px; }

.topbar { min-height: 58px; display: flex; justify-content: space-between; align-items: center; gap: 24px; margin-bottom: 22px; }
.brand, .top-actions, .sync-state, .theme-switcher, .button, .widget-head, .legend, .filter-note, .filter-footer, .filter-actions, .layout-toolbar, .table-footer { display: flex; align-items: center; }
.brand { gap: 13px; min-width: 0; }
.brand-mark { width: 42px; height: 42px; flex: none; border-radius: 13px; display: grid; place-items: center; color: white; background: linear-gradient(145deg, #5590ff, #2563eb); box-shadow: 0 8px 24px rgba(47, 111, 242, .28); }
.brand-mark svg { width: 27px; height: 27px; fill: currentColor; stroke: none; }
.eyebrow, .section-kicker { color: var(--faint); font-size: 10px; line-height: 1.2; font-weight: 720; letter-spacing: .14em; }
h1 { margin-top: 3px; font-size: clamp(19px, 1.7vw, 24px); line-height: 1.2; letter-spacing: -.02em; }
.top-actions { justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.auth-menu-wrap { position: relative; z-index: 30; flex: none; }
.auth-user-trigger { max-width: 180px; background: var(--soft); }
.auth-user-trigger span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.auth-user-trigger svg { width: 14px; height: 14px; flex: none; }
.auth-menu { position: absolute; top: calc(100% + 5px); left: 0; width: max-content; min-width: 190px; max-width: min(310px, calc(100vw - 24px)); padding: 6px; border: 1px solid var(--line); border-radius: 11px; background: var(--panel); box-shadow: 0 10px 24px rgba(0, 0, 0, .13); }
.auth-menu-row { display: flex; align-items: center; gap: 9px; width: 100%; min-height: 34px; padding: 7px 9px; border-radius: 7px; font-size: 13px; text-align: left; }
.auth-menu-row svg { width: 15px; height: 15px; flex: none; color: var(--muted); }
.auth-menu-id span { min-width: 0; overflow-wrap: anywhere; }
.auth-menu-id code { font: inherit; user-select: all; }
.auth-menu-action { border: 0; background: transparent; }
.auth-menu-action:hover, .auth-menu-action:focus-visible { background: var(--soft); }
.sync-state { gap: 7px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 999px; color: var(--muted); font-size: 12px; background: color-mix(in srgb, var(--panel) 84%, transparent); }
.sync-state b { color: var(--faint); font-weight: 500; padding-left: 7px; border-left: 1px solid var(--line); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px color-mix(in srgb, var(--green) 15%, transparent); }
.theme-switcher { gap: 4px; padding: 4px; border: 1px solid var(--line); background: var(--panel); border-radius: 11px; }
.theme-button { width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 8px; background: transparent; }
.theme-button span { width: 14px; height: 14px; border-radius: 50%; background: var(--swatch); box-shadow: inset 0 0 0 1px rgba(128,128,128,.3); }
.theme-button[aria-pressed="true"] { background: var(--accent-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 36%, transparent); }
.button { min-height: 38px; justify-content: center; gap: 7px; border: 1px solid var(--line); border-radius: 9px; padding: 0 14px; background: var(--panel); font-weight: 620; font-size: 13px; white-space: nowrap; }
.button:hover { border-color: var(--line-strong); transform: translateY(-1px); }
.button:active { transform: translateY(0); }
.button.primary { color: white; background: var(--accent-strong); border-color: var(--accent-strong); box-shadow: 0 7px 18px color-mix(in srgb, var(--accent) 22%, transparent); }
html[data-theme="graphite"] .button.primary { color: #15171a; }
.button.ghost { color: var(--muted); background: transparent; }
.button.secondary { color: var(--text); background: var(--panel); }
.button.small { min-height: 32px; padding: 0 11px; font-size: 12px; }

.filter-card, .widget { background: color-mix(in srgb, var(--panel) 96%, transparent); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.filter-card { padding: 18px 20px 16px; margin-bottom: 18px; position: relative; z-index: 20; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.section-heading h2, .widget-head h2 { margin-top: 4px; font-size: 15px; line-height: 1.25; letter-spacing: -.01em; }
.filter-heading { margin-bottom: 16px; }
.filter-note { gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.filter-note span { color: var(--muted); font-size: 11px; padding: 4px 8px; border-radius: 999px; background: var(--soft); border: 1px solid var(--line); }
.filter-grid { display: grid; grid-template-columns: 1.5fr repeat(6, minmax(130px, 1fr)); gap: 12px; }
.field-group { min-width: 0; position: relative; }
.field-group > label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; font-weight: 550; }
.multi-trigger, .date-range-trigger { width: 100%; height: 40px; border: 1px solid var(--line); border-radius: 9px; color: var(--text); background: var(--soft); }
.date-range-trigger { display: flex; align-items: center; gap: 8px; padding: 0 9px 0 11px; text-align: left; }
.date-range-trigger > svg:first-child { width: 15px; height: 15px; color: var(--accent); flex: none; }
.date-range-trigger span { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-variant-numeric: tabular-nums; }
.date-range-trigger .date-chevron { width: 15px; height: 15px; color: var(--faint); transition: transform .18s; }
.date-range.open .date-range-trigger { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.date-range.open .date-chevron { transform: rotate(180deg); }
.date-range-popover { position: absolute; z-index: 55; top: calc(100% + 7px); left: 0; width: min(740px, calc(100vw - 56px)); min-height: 352px; display: grid; grid-template-columns: 126px minmax(0, 1fr); overflow: hidden; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--panel-raised); box-shadow: 0 22px 60px rgba(0,0,0,.28); }
.quick-ranges { max-height: 370px; overflow-y: auto; padding: 8px; border-right: 1px solid var(--line); scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.quick-ranges button { width: 100%; min-height: 32px; padding: 0 8px; border: 0; border-radius: 7px; color: var(--text); background: transparent; text-align: left; font-size: 12px; }
.quick-ranges button:hover, .quick-ranges button.is-active { color: var(--accent); background: var(--accent-soft); }
.calendar-area { min-width: 0; padding: 10px 12px 12px; }
.date-pick-hint { min-height: 20px; color: var(--muted); font-size: 11px; text-align: center; }
.calendar-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.calendar-month { min-width: 0; }
.calendar-head { min-height: 36px; display: grid; grid-template-columns: 30px minmax(0,1fr) 30px; align-items: center; }
.calendar-head strong { text-align: center; font-size: 13px; font-weight: 680; }
.calendar-nav { width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 7px; background: transparent; color: var(--text); }
.calendar-nav:hover { background: var(--accent-soft); color: var(--accent); }
.calendar-nav svg { width: 16px; height: 16px; }
.calendar-nav-placeholder { width: 30px; height: 30px; }
.calendar-week, .calendar-days { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.calendar-week span { height: 29px; display: grid; place-items: center; color: var(--muted); font-size: 11px; font-weight: 620; }
.calendar-day { position: relative; height: 34px; display: grid; place-items: center; border: 0; border-radius: 0; color: var(--text); background: transparent; font-size: 11px; font-variant-numeric: tabular-nums; }
.calendar-day:hover { z-index: 1; color: var(--accent); background: var(--accent-soft); border-radius: 7px; }
.calendar-day.is-outside { color: var(--faint); opacity: .58; }
.calendar-day.is-in-range { background: color-mix(in srgb, var(--accent) 13%, transparent); }
.calendar-day.is-range-start, .calendar-day.is-range-end { z-index: 2; color: white; background: var(--accent-strong); border-radius: 7px; font-weight: 720; }
html[data-theme="graphite"] .calendar-day.is-range-start, html[data-theme="graphite"] .calendar-day.is-range-end { color: #14161a; }
.calendar-day.is-today:not(.is-range-start):not(.is-range-end) { box-shadow: inset 0 0 0 1px var(--accent); border-radius: 7px; color: var(--accent); font-weight: 680; }
.calendar-nav.mobile-only { display: none; }
.multi-select { position: relative; }
.multi-trigger { padding: 0 9px 0 11px; display: flex; align-items: center; justify-content: space-between; gap: 7px; text-align: left; }
.multi-trigger span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.multi-trigger svg { width: 15px; height: 15px; color: var(--faint); transition: transform .18s; }
.multi-select.open .multi-trigger { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.multi-select.open .multi-trigger svg { transform: rotate(180deg); }
.multi-clear { display: none; position: absolute; right: 5px; top: 7px; width: 26px; height: 26px; padding: 0; border: 0; border-radius: 50%; background: var(--soft); color: var(--muted); font-size: 21px; line-height: 1; opacity: 0; }
.multi-clear:hover { color: var(--text); background: var(--line); }
.multi-select.has-selection .multi-trigger { padding-right: 38px; }
.multi-select.has-selection .multi-trigger svg { position: absolute; right: 11px; }
@media (hover: hover) {
  .multi-select.has-selection .multi-clear { display: block; }
  .multi-clear:hover, .multi-clear:focus-visible { opacity: 1; }
  .multi-select:has(> .multi-clear:hover) .multi-trigger svg,
  .multi-select:has(> .multi-clear:focus-visible) .multi-trigger svg { visibility: hidden; }
}
.multi-menu { display: none; position: absolute; z-index: 40; left: 0; top: calc(100% + 6px); width: max(100%, 235px); max-height: 280px; overflow: auto; padding: 7px; border: 1px solid var(--line-strong); border-radius: 11px; background: var(--panel-raised); box-shadow: 0 18px 48px rgba(0,0,0,.24); }
.multi-select.open .multi-menu { display: block; }
.option-controls { position: sticky; z-index: 2; top: -7px; margin: -7px -7px 4px; padding: 7px; border-bottom: 1px solid var(--line); background: var(--panel-raised); }
.option-search { width: 100%; height: 34px; border: 1px solid var(--line); border-radius: 8px; background: var(--soft); color: var(--text); padding: 0 9px; margin-bottom: 5px; }
.option-select-all { min-height: 30px; display: flex; align-items: center; gap: 8px; padding: 4px 8px; border-radius: 7px; color: var(--muted); font-size: 11px; font-weight: 650; cursor: pointer; }
.option-select-all:hover { color: var(--accent); background: var(--accent-soft); }
.option-select-all input { accent-color: var(--accent); }
.option-row { min-height: 36px; display: flex; align-items: center; gap: 9px; padding: 7px 8px; border-radius: 8px; color: var(--text); font-size: 12px; }
.option-row:hover { background: var(--accent-soft); }
.option-row input { accent-color: var(--accent); }
.option-row span { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.option-row.is-unavailable { color: var(--faint); }
.option-row.is-unavailable span::after { content: "当前条件下无数据"; display: block; font-size: 10px; color: var(--red); }
.filter-footer { justify-content: space-between; gap: 18px; padding-top: 14px; margin-top: 15px; border-top: 1px solid var(--line); }
.filter-footer p { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.filter-actions { gap: 8px; }

.layout-toolbar { position: sticky; top: 10px; z-index: 18; justify-content: space-between; gap: 18px; margin: 0 0 14px; padding: 12px 14px; border-radius: 12px; color: var(--text); border: 1px solid color-mix(in srgb, var(--accent) 36%, var(--line)); background: color-mix(in srgb, var(--panel-raised) 92%, transparent); box-shadow: 0 10px 32px rgba(0,0,0,.16); backdrop-filter: blur(14px); }
.layout-toolbar > div { display: flex; align-items: center; gap: 10px; }
.layout-toolbar strong { font-size: 13px; }
.layout-toolbar span { font-size: 12px; color: var(--muted); }

.dashboard-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); grid-auto-rows: var(--grid-row); grid-auto-flow: row; gap: var(--grid-gap); align-items: stretch; }
.widget { position: relative; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 18px; overflow: hidden; grid-column: var(--start, auto) / span var(--cols); grid-row: span var(--rows); transition: border-color .18s, background .25s, box-shadow .18s; }
.widget-head, .table-footer { flex-shrink: 0; }
.widget > .chart, .widget > .chart-fallback, .widget > .table-wrap, .widget > .kpi-grid { flex: 1; min-height: 0; }
.widget-layout-controls { display: none; flex: none; flex-wrap: wrap; align-items: center; gap: 6px; padding-bottom: 10px; }
.dashboard-grid.editing .widget-layout-controls { display: flex; }
.widget-layout-controls label { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 11px; }
.widget-layout-controls button, .widget-layout-controls select { height: 28px; border: 1px solid var(--line-strong); border-radius: 6px; background: var(--panel-raised); color: var(--text); font-size: 11px; padding: 0 6px; }
.widget-layout-controls button:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.widget-layout-controls button:disabled { opacity: .4; cursor: default; }
.widget:hover { border-color: var(--line-strong); }
.widget-head { min-height: 42px; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 10px; }
.widget-sub, .widget-meta { color: var(--muted); font-size: 11px; margin-top: 5px; }
.widget-head-actions { display: flex; align-items: flex-start; justify-content: flex-end; gap: 12px; }
.legend { flex-wrap: wrap; justify-content: flex-end; gap: 12px; color: var(--muted); font-size: 11px; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend i { width: 8px; height: 8px; border-radius: 2px; }
.legend span.is-hidden { opacity: .42; text-decoration: line-through; }
.legend-blue { background: var(--accent); }.legend-cyan { background: var(--cyan); }.legend-violet { background: var(--violet); }.legend-gold { background: var(--gold); }
.view-menu-wrap { position: relative; flex: none; }
.view-menu-trigger { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid transparent; border-radius: 8px; color: var(--muted); background: transparent; }
.view-menu-trigger:hover, .view-menu-trigger[aria-expanded="true"] { color: var(--text); border-color: var(--line); background: var(--soft); }
.view-menu-trigger svg { width: 18px; height: 18px; }
.view-menu-trigger circle { fill: currentColor; stroke: none; }
.view-menu { position: absolute; z-index: 18; top: calc(100% + 6px); right: 0; width: 218px; max-height: 390px; overflow-y: auto; padding: 9px; border: 1px solid var(--line-strong); border-radius: 11px; background: var(--panel-raised); box-shadow: 0 18px 50px rgba(0,0,0,.28); scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
.view-menu-wide { width: 286px; }
.view-menu-title { padding: 4px 7px 6px; color: var(--faint); font-size: 10px; font-weight: 720; letter-spacing: .1em; }
.view-option { min-height: 34px; display: flex; align-items: center; gap: 9px; padding: 6px 7px; border-radius: 7px; color: var(--text); font-size: 12px; cursor: pointer; }
.view-option:hover { background: var(--accent-soft); }
.view-option input { width: 14px; height: 14px; margin: 0; accent-color: var(--accent); }
.view-option i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.view-option span { min-width: 0; }
.view-menu-divider { height: 1px; margin: 7px 5px; background: var(--line); }
.detail-column-options { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.widget[data-widget-id="overview"] { align-self: start; height: auto; min-height: 0; padding-block: 10px; }
.widget[data-widget-id="overview"] > .kpi-grid { flex: none; }
.widget[data-widget-id="overview"] .widget-head { flex-direction: row; align-items: center; }
.widget[data-widget-id="overview"] .widget-head-actions { width: auto; margin-left: auto; align-items: center; justify-content: flex-end; }
.widget[data-widget-id="overview"].overview-empty .widget-head { margin-bottom: 0; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, 170px); grid-auto-rows: 70px; align-content: start; justify-content: start; gap: 10px; }
.kpi { width: 170px; height: 70px; min-width: 0; display: grid; grid-template-rows: 14px 24px 12px; gap: 1px; padding: 8px 10px; border-radius: 10px; background: var(--soft); border: 1px solid color-mix(in srgb, var(--line) 82%, transparent); }
.kpi.featured { background: linear-gradient(135deg, var(--accent-soft), var(--soft)); border-color: color-mix(in srgb, var(--accent) 30%, var(--line)); }
.kpi-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--muted); font-size: 11px; line-height: 14px; }
.kpi-top span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kpi-top svg { flex: none; width: 12px; height: 12px; color: var(--accent); }
.kpi-value { margin: 0; font-size: 22px; line-height: 24px; font-weight: 720; letter-spacing: -.035em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.kpi-foot { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--faint); font-size: 9px; line-height: 12px; }
.kpi-foot .positive { color: var(--green); }.kpi-foot .negative { color: var(--red); }
.metric-config-trigger { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 8px; color: var(--muted); background: var(--soft); }
.metric-config-trigger:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.metric-config-trigger svg { width: 16px; height: 16px; }

body.modal-open { overflow: hidden; }
.metric-modal { position: fixed; z-index: 220; inset: 0; display: grid; place-items: center; padding: 24px; background: rgba(4, 9, 17, .62); backdrop-filter: blur(5px); }
.metric-modal-panel { width: min(1180px, 100%); max-height: min(860px, calc(100vh - 48px)); display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; border: 1px solid var(--line-strong); border-radius: 16px; color: var(--text); background: var(--panel); box-shadow: 0 28px 90px rgba(0,0,0,.42); }
.metric-modal-head, .metric-modal-foot { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 15px 18px; border-bottom: 1px solid var(--line); }
.metric-modal-head h2 { margin-top: 3px; font-size: 17px; }
.metric-modal-head > button { width: 32px; height: 32px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; font-size: 23px; line-height: 1; }
.metric-modal-head > button:hover { color: var(--text); background: var(--soft); }
.metric-modal-body { min-height: 0; overflow-y: auto; padding: 16px 18px 20px; }
.metric-selected-heading { display: flex; align-items: baseline; gap: 9px; margin-bottom: 10px; }
.metric-selected-heading strong { font-size: 13px; }
.metric-selected-heading span { color: var(--accent); font-size: 11px; }
.metric-selected-heading small { margin-left: auto; color: var(--faint); font-size: 10px; }
.metric-selected-list { min-height: 76px; display: grid; grid-template-columns: repeat(6, minmax(130px, 1fr)); gap: 10px; margin-bottom: 18px; padding-bottom: 17px; border-bottom: 1px solid var(--line); }
.metric-selected-card { position: relative; min-width: 0; min-height: 66px; display: grid; grid-template-columns: 18px minmax(0, 1fr) 22px; align-items: center; gap: 6px; padding: 9px 7px; border: 1px solid var(--line-strong); border-radius: 9px; background: var(--panel-raised); cursor: grab; }
.metric-selected-card:active { cursor: grabbing; }
.metric-selected-card .metric-drag { color: var(--faint); font-size: 17px; }
.metric-selected-card strong, .metric-selected-card small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.metric-selected-card strong { font-size: 12px; }
.metric-selected-card small { margin-top: 4px; color: var(--muted); font-size: 11px; }
.metric-selected-card button { width: 22px; height: 22px; border: 0; border-radius: 50%; color: var(--faint); background: var(--soft); font-size: 16px; }
.metric-selected-card button:hover { color: white; background: var(--red); }
.metric-picker-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.metric-picker-head label { font-size: 13px; font-weight: 650; }
.metric-picker-head input { width: min(330px, 60vw); height: 36px; margin-left: auto; padding: 0 11px; border: 1px solid var(--line); border-radius: 8px; color: var(--text); background: var(--soft); }
.metric-options { display: grid; grid-template-columns: repeat(5, minmax(145px, 1fr)); gap: 10px; }
.metric-option { min-height: 92px; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px; color: var(--muted); background: var(--soft); text-align: left; }
.metric-option:hover { border-color: var(--accent); transform: translateY(-1px); }
.metric-option.is-selected { border-color: var(--accent); color: var(--text); background: var(--accent-soft); box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 20%, transparent); }
.metric-option span { font-size: 11px; }
.metric-option strong { margin-top: 3px; color: var(--text); font-size: 16px; }
.metric-option small { width: 100%; margin-top: 6px; overflow: hidden; color: var(--faint); font-size: 9px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.metric-no-results { grid-column: 1 / -1; padding: 36px; color: var(--muted); text-align: center; }
.metric-modal-foot { justify-content: flex-end; border-top: 1px solid var(--line); border-bottom: 0; }
.chart { width: 100%; height: calc(100% - 55px); min-height: 200px; }
.chart-fallback { height: calc(100% - 55px); min-height: 200px; display: grid; place-items: center; color: var(--muted); background: var(--soft); border-radius: 10px; text-align: center; padding: 20px; }

.table-wrap { height: calc(100% - 100px); overflow: auto; border: 1px solid var(--line); border-radius: 10px; background: var(--soft); }
table { width: 100%; min-width: 1320px; border-collapse: collapse; font-size: 12px; }
#detail-table { table-layout: fixed; min-width: 0; }
#detail-table th { padding-right: 18px; }
#detail-table th, #detail-table td, #detail-table td strong, #detail-table td small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#detail-table td small { max-width: none; }
#detail-table .status-stack { max-width: none; white-space: normal; }
.column-resize-handle { position: absolute; z-index: 2; top: 0; right: 0; bottom: 0; width: 8px; cursor: col-resize; touch-action: none; }
.column-resize-handle::after { content: ""; position: absolute; top: 25%; bottom: 25%; left: 3px; width: 2px; background: var(--line-strong); }
.column-resize-handle:hover::after, .column-resize-handle:focus::after { background: var(--accent); }
body.resizing-column, body.resizing-column * { cursor: col-resize !important; user-select: none !important; }
th { position: sticky; top: 0; z-index: 1; color: var(--muted); background: var(--panel-raised); font-size: 11px; font-weight: 620; text-align: left; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:hover { background: var(--accent-soft); }
td strong { display: block; font-weight: 620; color: var(--text); }
td small { display: block; margin-top: 3px; color: var(--muted); max-width: 230px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.status-stack { display: flex; flex-wrap: wrap; gap: 4px; max-width: 170px; }
.status-pill { padding: 3px 6px; border-radius: 999px; font-size: 9px; font-weight: 650; letter-spacing: .02em; background: var(--panel-raised); border: 1px solid var(--line); color: var(--muted); }
.status-pill.enabled { color: var(--green); }.status-pill.paused { color: var(--gold); }.status-pill.archived { color: var(--faint); }
.table-footer { min-height: 38px; justify-content: space-between; padding-top: 8px; color: var(--muted); font-size: 11px; }
.pagination-actions { display: flex; align-items: center; gap: 5px; }
.pagination-pages { display: flex; align-items: center; gap: 3px; }
.page-number, .page-arrow { min-width: 28px; height: 28px; display: grid; place-items: center; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--text); font-size: 11px; }
.page-number:hover, .page-arrow:hover:not(:disabled) { color: var(--accent); border-color: var(--line-strong); background: var(--accent-soft); }
.page-number.is-active { color: white; border-color: var(--accent); background: var(--accent-strong); font-weight: 700; }
.page-arrow:disabled { color: var(--faint); opacity: .45; }
.page-ellipsis { min-width: 22px; text-align: center; color: var(--faint); }
.page-jump { display: flex; align-items: center; gap: 5px; margin-left: 5px; white-space: nowrap; }
.page-jump input { width: 54px; height: 28px; border: 1px solid var(--line); border-radius: 6px; background: var(--soft); color: var(--text); text-align: center; font-size: 11px; }
.page-jump input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.table-empty { min-height: 160px; display: grid; place-items: center; color: var(--muted); }
.resize-handle { display: none; position: absolute; z-index: 5; right: 4px; bottom: 4px; width: 28px; height: 28px; place-items: center; border: 0; background: transparent; color: var(--accent); cursor: nwse-resize; touch-action: none; }
.resize-handle svg { width: 18px; height: 18px; }
.dashboard-grid.editing .widget { border-color: color-mix(in srgb, var(--accent) 48%, var(--line)); background-image: linear-gradient(135deg, transparent 94%, var(--accent-soft)); }
.dashboard-grid.editing .drag-handle { cursor: grab; user-select: none; touch-action: none; }
.dashboard-grid.editing .drag-handle:active { cursor: grabbing; }
.dashboard-grid.editing .resize-handle { display: grid; }
.widget.dragging { opacity: .45; border-style: dashed; }
.widget.drop-before { box-shadow: 0 -5px 0 var(--accent), var(--shadow); }
.widget.drop-after { box-shadow: 0 5px 0 var(--accent), var(--shadow); }

.footer { display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-top: 18px; color: var(--faint); font-size: 11px; }
.toast { position: fixed; z-index: 100; left: 50%; bottom: 24px; transform: translateX(-50%); display: flex; align-items: center; gap: 14px; width: max-content; max-width: calc(100vw - 32px); padding: 11px 15px; border-radius: 10px; color: var(--panel); background: var(--text); box-shadow: 0 14px 42px rgba(0,0,0,.25); font-size: 12px; }
.toast-message { min-width: 0; overflow-wrap: anywhere; line-height: 1.6; user-select: text; }
.toast-copy { flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; padding: 6px; border: 0; border-radius: 6px; color: inherit; background: transparent; cursor: pointer; }
.toast-copy svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.toast-copy:hover, .toast-copy:focus-visible { background: color-mix(in srgb, currentColor 15%, transparent); }
.toast-copy:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }
.loading-bar { position: fixed; z-index: 120; top: 0; left: 0; width: 45%; height: 3px; background: var(--accent); box-shadow: 0 0 18px var(--accent); animation: loading 1s ease-in-out infinite alternate; }
@keyframes loading { from { transform: translateX(-80%); } to { transform: translateX(210%); } }

@media (max-width: 1320px) {
  .filter-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .date-range { grid-column: span 2; }
  .metric-selected-list { grid-template-columns: repeat(4, minmax(130px, 1fr)); }
  .metric-options { grid-template-columns: repeat(4, minmax(145px, 1fr)); }
}
@media (max-width: 900px) {
  .topbar { align-items: flex-start; flex-direction: column; }
  .top-actions { width: 100%; justify-content: space-between; }
  .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: auto; }
  .widget { grid-column: span 2 !important; grid-row: auto !important; min-height: 420px; }
  .widget[data-widget-id="overview"] { min-height: auto; }
  .widget[data-widget-id="detail"] { min-height: 590px; }
  .kpi-grid { height: auto; }
  .chart { height: 340px; }
  .table-wrap { height: 465px; }
  .table-footer { align-items: flex-start; flex-direction: column; gap: 7px; }
  .pagination-actions { width: 100%; overflow-x: auto; padding-bottom: 3px; }
  .dashboard-grid.editing .resize-handle { display: none; }
  .widget-layout-controls .layout-size-control { display: none; }
  .widget > .chart, .widget > .chart-fallback { flex: none; height: 340px; }
  .widget > .table-wrap { flex: none; height: 465px; }
  .widget > .kpi-grid { flex: none; height: auto; }
}
@media (max-width: 680px) {
  .app-shell { padding: 17px 12px 22px; }
  .brand-mark { width: 38px; height: 38px; border-radius: 11px; }
  .eyebrow { font-size: 8px; }
  .sync-state b { display: none; }
  .top-actions { justify-content: flex-start; }
  .auth-menu { left: auto; right: 0; }
  .top-actions #edit-layout { margin-left: auto; }
  .filter-card, .widget { border-radius: 13px; padding: 15px; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .date-range { grid-column: 1 / -1; }
  .date-range-popover { position: fixed; top: 92px; left: 12px; right: 12px; width: auto; min-height: 0; max-height: calc(100vh - 110px); grid-template-columns: minmax(0, 1fr); overflow-y: auto; }
  .quick-ranges { display: flex; max-height: none; overflow-x: auto; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .quick-ranges button { width: auto; flex: none; padding: 0 11px; }
  .calendar-area { padding: 10px 14px 15px; }
  .calendar-pair { grid-template-columns: minmax(0, 1fr); }
  .calendar-month-right { display: none; }
  .calendar-nav.mobile-only { display: grid; }
  .calendar-day { height: 38px; font-size: 12px; }
  .filter-heading { align-items: flex-start; }
  .filter-note span:last-child { display: none; }
  .filter-footer { align-items: flex-start; flex-direction: column; }
  .filter-footer p { white-space: normal; }
  .filter-actions { width: 100%; justify-content: flex-end; }
  .layout-toolbar, .layout-toolbar > div { align-items: flex-start; }
  .layout-toolbar { flex-direction: column; }
  .layout-toolbar span { display: block; }
  .metric-modal { padding: 8px; }
  .metric-modal-panel { max-height: calc(100vh - 16px); border-radius: 12px; }
  .metric-modal-body { padding: 14px; }
  .metric-selected-list, .metric-options { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric-selected-heading small { display: none; }
  .metric-picker-head { align-items: flex-start; flex-direction: column; }
  .metric-picker-head input { width: 100%; margin-left: 0; }
  .widget-head { flex-direction: column; }
  .widget-head-actions { width: 100%; justify-content: space-between; }
  .legend { justify-content: flex-start; }
  .view-menu { right: 0; max-width: calc(100vw - 60px); }
  .chart { height: 310px; }
  .footer { line-height: 1.7; }
}
@media (max-width: 410px) {
  .theme-switcher { order: 3; width: 100%; justify-content: space-around; }
  .filter-grid { grid-template-columns: minmax(0, 1fr); }
  .date-range { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

/* Independent loading and on-demand details. */
.module-status { padding: 10px 12px; margin-bottom: 10px; border-radius: 8px; background: var(--panel-raised); color: var(--muted); font-size: 12px; }
.module-status[hidden] { display: none; }
.module-status button, #filter-load-status button { margin-left: 8px; color: var(--accent); background: none; border: 0; cursor: pointer; }
#filter-load-status { font-size: 12px; color: var(--muted); margin: 8px 0; }
#filter-load-status:empty { display: none; }
.open-details { flex: none; margin-left: auto; padding: 6px 9px; border: 1px solid var(--line); border-radius: 7px; background: var(--panel-raised); color: var(--accent); font: inherit; font-size: 11px; cursor: pointer; }
.open-details:disabled { opacity: .45; cursor: default; }
.kpi[role="button"] { cursor: pointer; }
.kpi[role="button"]:focus-visible, .open-details:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.widget[data-load-state="loading"] > .table-wrap { opacity: .45; pointer-events: none; }
#drilldown-dialog { width: min(1440px, 94vw); max-width: 94vw; max-height: 90vh; padding: 0; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); box-shadow: 0 28px 90px #0005; }
#drilldown-dialog::backdrop { background: #08132199; backdrop-filter: blur(4px); }
.drilldown-panel { display: flex; flex-direction: column; max-height: 88vh; }
.drilldown-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding: 24px 24px 12px; }
.drilldown-header h2 { margin: 5px 0 10px; font-size: 21px; }
#drilldown-scope { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.7; overflow-wrap: anywhere; }
#drilldown-close { flex: none; border: 0; background: none; color: var(--muted); font-size: 28px; cursor: pointer; }
#drilldown-dimensions { display: flex; flex-wrap: wrap; gap: 7px; padding: 10px 24px; }
#drilldown-dialog button:not(#drilldown-close) { padding: 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-raised); color: var(--text); font: inherit; font-size: 12px; cursor: pointer; }
#drilldown-dialog #drilldown-dimensions button[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); }
#drilldown-dialog button:disabled { opacity: .4; cursor: default; }
.drilldown-message { display: flex; align-items: center; gap: 12px; min-height: 42px; padding: 0 24px 10px; color: var(--muted); font-size: 12px; }
.drilldown-table-wrap { overflow: auto; min-height: 180px; margin: 0 24px; border: 1px solid var(--line); border-radius: 9px; }
.drilldown-table-wrap table { width: max-content; min-width: 100%; border-collapse: collapse; table-layout: auto; }
.drilldown-table-wrap th { position: sticky; top: 0; z-index: 1; background: var(--panel-raised); }
.drilldown-table-wrap th, .drilldown-table-wrap td { padding: 11px 13px; border-bottom: 1px solid var(--line); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.drilldown-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 24px; color: var(--muted); font-size: 12px; }
.drilldown-footer > div { display: flex; gap: 8px; }
@media (max-width: 680px) { .drilldown-header { padding: 16px 12px 8px; } #drilldown-dimensions { padding: 8px 12px; } .drilldown-message { padding: 0 12px 8px; } .drilldown-table-wrap { margin: 0 12px; } .drilldown-footer { padding: 12px; } }

#drilldown-dialog #drilldown-body button { border: 0; background: none; color: var(--accent); padding: 0; text-align: left; text-decoration: underline; text-underline-offset: 3px; }

.drilldown-footer { flex: none; flex-direction: column; align-items: stretch; gap: 6px; }
.drilldown-pagination { align-items: center; justify-content: flex-end; flex-wrap: wrap; color: var(--text); }
#drilldown-page { white-space: nowrap; margin-right: 2px; }
.drilldown-page-navigation, #drilldown-pages, .drilldown-jump { display: flex; align-items: center; gap: 4px; }
.drilldown-page-navigation { flex: none; }
.drilldown-jump { white-space: nowrap; color: var(--muted); }
.drilldown-footer select, .drilldown-footer input { box-sizing: border-box; height: 32px; padding: 4px 7px; border: 1px solid var(--line-strong); border-radius: 2px; color: var(--text); background: var(--panel-raised); font: inherit; }
#drilldown-limit { width: 100px; margin: 0 4px; }
#drilldown-jump { width: 46px; text-align: center; appearance: textfield; }
#drilldown-jump::-webkit-inner-spin-button, #drilldown-jump::-webkit-outer-spin-button { appearance: none; margin: 0; }
#drilldown-dialog .drilldown-footer button:not(#drilldown-close) { min-width: 28px; height: 32px; padding: 0 6px; border: 0; border-radius: 3px; background: transparent; color: var(--text); }
#drilldown-dialog .drilldown-footer button:not(#drilldown-close):hover:not(:disabled) { color: var(--accent); background: var(--soft); }
#drilldown-dialog .drilldown-footer #drilldown-prev, #drilldown-dialog .drilldown-footer #drilldown-next { color: var(--muted); font-size: 24px; line-height: 1; }
#drilldown-dialog #drilldown-pages button[aria-current="page"] { opacity: 1; color: var(--accent); background: color-mix(in srgb, var(--accent) 12%, transparent); }
#drilldown-pages .page-ellipsis { min-width: 24px; text-align: center; }
.drilldown-footer select:disabled, .drilldown-footer input:disabled { opacity: .45; }
#drilldown-page-error { color: var(--muted); font-size: 12px; text-align: right; }
#drilldown-page-error:empty { display: none; }
#drilldown-jump[aria-invalid="true"] { border-color: #dc5b63; }
@media (max-width: 480px) { .drilldown-page-navigation { gap: 1px; } #drilldown-pages { gap: 1px; } #drilldown-dialog .drilldown-footer button:not(#drilldown-close) { min-width: 24px; padding: 0 4px; } }

#drilldown-columns-toggle { margin-left: auto; white-space: nowrap; }
#drilldown-columns-panel { position: absolute; z-index: 5; top: 80px; right: 24px; bottom: 16px; width: min(470px, calc(100% - 48px)); overflow: hidden; padding: 16px; border: 1px solid var(--line-strong); border-radius: 12px; background: var(--panel); box-shadow: 0 12px 40px #0003; font-size: 12px; }
#drilldown-columns-panel:not([hidden]) { display: flex; flex-direction: column; }
.drilldown-columns-toolbar { flex: none; background: var(--panel); }
#drilldown-columns-list { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.drilldown-columns-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.drilldown-columns-heading strong { font-size: 14px; white-space: nowrap; }
#drilldown-columns-panel p { margin: 10px 0 0; color: var(--muted); line-height: 1.6; }
.drilldown-columns-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: 6px 0 12px; color: var(--muted); font-size: 11px; }
#drilldown-columns-panel #drilldown-columns-scope { margin: 0; font-size: inherit; }
#drilldown-columns-status:empty { display: none; }
.drilldown-column-option { display: flex; align-items: center; gap: 6px; padding: 7px 0; border-top: 1px solid var(--line); }
.drilldown-column-option > label:first-child { flex: 1; display: flex; align-items: center; gap: 7px; min-width: 0; }
.drilldown-width-label { display: flex; align-items: center; gap: 4px; }
.drilldown-width-label input { width: 66px; padding: 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel-raised); color: var(--text); }
.drilldown-columns-actions { display: flex; align-items: center; gap: 8px; }
#drilldown-dialog .drilldown-columns-actions button:not(#drilldown-close) { box-sizing: border-box; height: 32px; padding: 0 12px; line-height: 30px; white-space: nowrap; border-radius: 6px; }
#drilldown-dialog .drilldown-columns-actions #drilldown-columns-close { color: white; background: var(--accent); border-color: var(--accent); }
#drilldown-table { table-layout: fixed; min-width: 0; }
#drilldown-table th, #drilldown-table td { box-sizing: border-box; max-width: none; }
#drilldown-table th { padding-right: 18px; text-align: right; }
.drilldown-column-title { display: inline-block; max-width: calc(100% - 23px); overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.drilldown-sort-buttons { display: inline-flex; flex-direction: column; vertical-align: middle; margin-left: 4px; }
#drilldown-dialog #drilldown-head .drilldown-sort-buttons button { display: block; padding: 0 3px; height: 10px; line-height: 10px; font-size: 9px; border: 0; border-radius: 2px; background: transparent; color: var(--muted); }
#drilldown-dialog #drilldown-head .drilldown-sort-buttons button[aria-pressed="true"], #drilldown-dialog #drilldown-head .drilldown-sort-buttons button:hover:not(:disabled) { color: var(--accent); background: var(--soft); }
