/*
 * dashboard.css — Dashboard-specific styles.
 *
 * Does NOT redefine design-system tokens — those come from styles.css.
 * Only adds what doesn't exist in the base sheet:
 *   - 3-zone grid layout (KPI / Spark / Tables)
 *   - KPI card + semi-circle gauge
 *   - Spark/chart card shell
 *   - DataTable chrome (sortable + paginated)
 *   - Skeleton states
 *   - Error / empty states
 *   - Responsive breakpoints
 *
 * Load order in index.html:
 *   <link rel="stylesheet" href="styles.css">
 *   <link rel="stylesheet" href="dashboard.css">
 */

/* ── Tab bar ─────────────────────────────────────────────────────────────── */

.dashboard-tab-bar {
    display: flex;
    gap: 4px;
    padding: 0 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    overflow-x: auto;
    scrollbar-width: none;
}

.dashboard-tab-bar::-webkit-scrollbar { display: none; }

.dashboard-tab-bar .nav-tab {
    padding: 10px 16px;
    font-size: 13px;
    border: none;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
    border-radius: 0;
    transition: color 0.15s, border-color 0.15s;
}

.dashboard-tab-bar .nav-tab:hover  { color: var(--text); }
.dashboard-tab-bar .nav-tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ── Grid stream — 24 columns, 40px/row (mirrors Metabase grid) ─────────── */

.dashboard-body {
    padding: 16px 24px;
}

.dashboard-stream {
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    grid-auto-rows: 40px;
    gap: 8px;
}

/* Read-only viewers/managers: hide edit affordances entirely (the click is
   already gated; this stops inert controls from appearing on hover). */
.dashboard-stream.dash-readonly .dash-card-controls,
.dashboard-stream.dash-readonly .card-drag-handle,
.dashboard-stream.dash-readonly .dash-resize-s,
.dashboard-stream.dash-readonly .dash-resize-e {
    display: none;
}

/* Generic card wrapper. Grid position is set via inline style by MetricRenderer
   (grid-column / grid-row). GridEngine.attach() re-applies after collision check. */
.dash-grid-card {
    position: relative;
    min-width: 0;   /* prevent overflow inside narrow grid cells */
    overflow: hidden;  /* clip content so card never expands beyond its grid rows */
}

/* ── Card slot — hosts drag handle, controls, body, resize handles ───────── */

.dash-card-slot {
    display: flex;
    flex-direction: column;
    position: relative;
    height: 100%;
}

.dash-card-controls {
    position: absolute;
    top: 6px;
    right: 6px;
    display: flex;
    gap: 2px;
    opacity: 0;
    transition: opacity .12s;
    z-index: 2;
}

/* Read-only dashboard: roles with dashboard.view but not dashboard.manage
   (manager, viewer) can't drag or resize cards. Set by dashboard.js. */
.dash-readonly .dash-card-controls,
.dash-readonly .card-drag-handle,
.dash-readonly .dash-resize-s,
.dash-readonly .dash-resize-e {
    display: none !important;
}

.dash-card-slot:hover .dash-card-controls {
    opacity: 1;
}

/* ── Drag handle ─────────────────────────────────────────────────────────── */

.card-drag-handle {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 22px;
    z-index: 2;
    cursor: grab;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity .15s;
    color: var(--text-dim);
    font-size: 13px;
    letter-spacing: 3px;
    user-select: none;
}

.dash-card-slot:hover .card-drag-handle { opacity: 1; }
body.grid-dragging                       { cursor: grabbing !important; user-select: none; }
body.grid-resizing                       { user-select: none; }

/* ── Resize handles ──────────────────────────────────────────────────────── */

/* Bottom edge — resize height */
.dash-resize-s {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 16px;
    height: 12px;
    cursor: ns-resize;
    z-index: 3;
    opacity: 0;
    transition: opacity .2s;
}

.dash-resize-s::after {
    content: "";
    display: block;
    height: 3px;
    margin: 4px 40px;
    border-radius: 2px;
    background: var(--border-light);
}

/* Right edge — resize width */
.dash-resize-e {
    position: absolute;
    top: 0;
    right: 0;
    bottom: 16px;
    width: 12px;
    cursor: ew-resize;
    z-index: 3;
    opacity: 0;
    transition: opacity .2s;
}

.dash-resize-e::after {
    content: "";
    position: absolute;
    top: 40px;
    bottom: 40px;
    right: 4px;
    width: 3px;
    border-radius: 2px;
    background: var(--border-light);
}

.dash-card-slot:hover .dash-resize-s,
.dash-card-slot:hover .dash-resize-e {
    opacity: 1;
}

/* ── Drop ghost (drag-to-move indicator) ─────────────────────────────────── */

.dash-grid-ghost {
    background: color-mix(in srgb, var(--primary, #509EE3) 12%, transparent);
    border: 2px dashed var(--primary-dim, #509EE3);
    border-radius: 8px;
    pointer-events: none;
    z-index: 0;
}

/* ── KPI card ────────────────────────────────────────────────────────────── */

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: border-color .15s;
    flex: 1;
    min-height: 110px;
}

.kpi-card:hover { border-color: var(--border-light); }

.kpi-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
}

.kpi-body {
    display: flex;
    align-items: center;
    gap: 12px;
}

.kpi-value {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
}

.kpi-delta     { font-size: 11px; font-weight: 600; }
.kpi-delta.pos { color: var(--primary); }
.kpi-delta.neg { color: var(--danger); }

.kpi-delta-label {
    color: var(--text-dim);
    font-weight: 400;
}

.kpi-target {
    font-size: 10px;
    color: var(--text-dim);
}

/* Gauge (progress arc) card — stack value above arc, both centered */
.kpi-card.gauge-card { align-items: center; }
.kpi-card.gauge-card .kpi-label { align-self: stretch; }
.kpi-card.gauge-card .kpi-value  { font-size: 24px; }

.kpi-gauge {
    flex-shrink: 0;
}

/* ── Spark / chart card ──────────────────────────────────────────────────── */

.spark-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: border-color .15s;
    overflow: hidden;
    box-sizing: border-box;
}

.spark-card:hover { border-color: var(--border-light); }

.card-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
}

.chart-area {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.pie-slice {
    transition: transform 0.15s;
    transform-box: fill-box;
    transform-origin: center;
}

/* ── Heading cards ───────────────────────────────────────────────────────── */

.dash-heading-card {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 0 4px;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.01em;
    border-bottom: 2px solid var(--primary, #509EE3);
    box-sizing: border-box;
}

/* ── DataTable ───────────────────────────────────────────────────────────── */

.dt-outer-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    height: 100%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
}

.dt-wrapper {
    padding: 16px;
    display: flex;
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.dt-scroll-body {
    flex: 1;
    overflow-x: auto;
    overflow-y: auto;
    min-height: 0;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.data-table th {
    padding: 8px 10px;
    text-align: left;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-light);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    transition: color .15s;
    position: sticky;
    top: 0;
    background: var(--surface);
    z-index: 2;
}

.data-table th:hover,
.data-table th.sorted { color: var(--primary); }

.data-table td {
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td      { background: var(--surface-hover); }

.num-cell  { font-variant-numeric: tabular-nums; }
.pct-cell  { color: var(--primary); font-weight: 600; font-variant-numeric: tabular-nums; }
.hl-cell   { color: var(--primary-dim); font-weight: 600; }

.dt-pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 0 0;
    justify-content: flex-end;
}

.dt-info {
    font-size: 11px;
    color: var(--text-dim);
    margin-right: 8px;
}

.dt-btn {
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    transition: border-color .15s, color .15s;
}

.dt-btn:hover:not(:disabled) {
    border-color: var(--border-light);
    color: var(--text);
}

.dt-btn.active {
    background: var(--primary-glow);
    border-color: var(--primary-dim);
    color: var(--primary);
}

.dt-btn:disabled {
    opacity: .3;
    cursor: not-allowed;
}

/* ── Skeleton loaders ────────────────────────────────────────────────────── */

@keyframes db-shimmer {
    0%   { background-position: -600px 0; }
    100% { background-position:  600px 0; }
}

.db-skeleton {
    background: linear-gradient(90deg,
        var(--surface) 0%,
        var(--surface-hover) 50%,
        var(--surface) 100%);
    background-size: 1200px 100%;
    animation: db-shimmer 1.6s infinite;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.db-skeleton-kpi   { height: 120px; }
.db-skeleton-spark { height: 280px; }
.db-skeleton-table { height: 320px; }

/* ── Error / empty states ────────────────────────────────────────────────── */

.metric-error {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.error-msg { color: var(--danger); font-size: 12px; }

.no-data {
    color: var(--text-dim);
    font-size: 12px;
    text-align: center;
    padding: 24px 0;
}

/* ── Configure modal mini-forms (tab + filter inline forms) ─────────────── */

.config-mini-form {
    padding: 12px;
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.config-mini-fields {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.config-mini-input {
    flex: 1;
    min-width: 120px;
    padding: 7px 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 13px;
}

.config-mini-input:focus {
    border-color: var(--border-light);
    outline: none;
}

.config-mini-input--fixed {
    flex: none;
    min-width: 0;
}

.config-mini-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

.config-mini-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    cursor: pointer;
}

.config-mini-segment {
    display: flex;
    align-items: center;
    gap: 8px;
}

.config-mini-notice {
    padding: 8px 10px;
    background: rgba(214,158,46,0.10);
    border: 1px solid rgba(214,158,46,0.3);
    border-radius: 6px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ── Drag resize handle (spark cards) ───────────────────────────────────── */

.dash-resize-handle {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 12px;
    cursor: ns-resize;
    z-index: 3;
}

.dash-resize-handle::after {
    content: "";
    display: block;
    height: 3px;
    margin: 4px 40px;
    border-radius: 2px;
    background: var(--border-light);
    opacity: 0;
    transition: opacity .2s;
}

.dash-card-slot:hover .dash-resize-handle::after,
.dash-resize-handle:hover::after {
    opacity: 1;
}

body.resizing-chart {
    cursor: ns-resize;
    user-select: none;
}

/* ── Column selector (metric form) ──────────────────────────────────────── */

.dm-col-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}

.dm-col-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-family: monospace;
    color: var(--text);
    cursor: pointer;
    padding: 3px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    transition: border-color .15s;
}

.dm-col-item:hover { border-color: var(--border-light); }
.dm-col-item input[type="checkbox"] { cursor: pointer; margin: 0; }

/* ── Drag resize (legacy — kept so old card heights work during transition) ── */

.dash-resize-handle { display: none; }  /* superseded by .dash-resize-s / .dash-resize-e */

/* ── Settings button on each card ───────────────────────────────────────── */

.dash-card-settings {
    width: 22px;
    height: 22px;
    padding: 0;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1;
    border-radius: 4px;
    cursor: pointer;
    transition: border-color .15s, color .15s;
}
.dash-card-settings:hover {
    border-color: var(--primary-dim);
    color: var(--primary);
}

/* ── SettingsPanel overlay ───────────────────────────────────────────────── */

.viz-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .35);
    z-index: 400;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}
.viz-panel-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* ── SettingsPanel slide-in ──────────────────────────────────────────────── */

.viz-panel {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 320px;
    background: var(--surface);
    border-left: 1px solid var(--border);
    z-index: 401;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform .22s cubic-bezier(.4, 0, .2, 1);
    box-shadow: -4px 0 24px rgba(0, 0, 0, .14);
}
.viz-panel.active { transform: translateX(0); }

.viz-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.viz-panel-title {
    flex: 1;
    background: transparent;
    border: none;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    outline: none;
    padding: 4px 6px;
    border-radius: 4px;
    transition: background .15s;
    min-width: 0;
}
.viz-panel-title:hover,
.viz-panel-title:focus { background: var(--surface-hover); }

.viz-panel-close {
    flex-shrink: 0;
    background: none;
    border: none;
    font-size: 20px;
    line-height: 1;
    color: var(--text-dim);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color .15s, background .15s;
}
.viz-panel-close:hover { color: var(--text); background: var(--surface-hover); }

.viz-panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.viz-tab {
    flex: 1;
    padding: 9px 4px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-dim);
    cursor: pointer;
    transition: color .15s, border-color .15s;
}
.viz-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.viz-tab:hover:not(.active) { color: var(--text); }

.viz-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 4px 0 8px;
}

.viz-panel-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.viz-panel-cancel {
    padding: 6px 14px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: border-color .15s, color .15s;
}
.viz-panel-cancel:hover { border-color: var(--border-light); color: var(--text); }

.viz-panel-save {
    padding: 6px 20px;
    border-radius: 6px;
    background: var(--primary, #509EE3);
    border: 1px solid transparent;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity .15s;
}
.viz-panel-save:hover   { opacity: .88; }
.viz-panel-save:disabled { opacity: .5; cursor: not-allowed; }

/* ── Panel sections ──────────────────────────────────────────────────────── */

.vp-section {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
}
.vp-section:last-child { border-bottom: none; }

.vp-section-title {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.vp-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 0;
}

.vp-label {
    font-size: 12px;
    color: var(--text);
    flex: 1;
    min-width: 0;
}

.vp-select,
.vp-input {
    font-size: 12px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    width: 130px;
    min-width: 0;
}
.vp-input.vp-num { width: 80px; }
.vp-select:focus,
.vp-input:focus  { border-color: var(--primary-dim, #509EE3); outline: none; }

/* ── Toggle (pill switch) ────────────────────────────────────────────────── */

.vp-toggle-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 0;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
    user-select: none;
}

.vp-toggle {
    -webkit-appearance: none;
    appearance: none;
    flex-shrink: 0;
    width: 32px;
    height: 18px;
    border-radius: 9px;
    background: var(--border);
    position: relative;
    cursor: pointer;
    transition: background .15s;
}
.vp-toggle::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
    transition: transform .15s;
}
.vp-toggle:checked             { background: var(--primary, #509EE3); }
.vp-toggle:checked::after      { transform: translateX(14px); }

/* ── Chart type picker ───────────────────────────────────────────────────── */

.vp-chart-picker {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.vp-chart-type {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 4px 6px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: border-color .15s, color .15s, background .15s;
}
.vp-chart-type:hover {
    border-color: var(--primary-dim, #509EE3);
    color: var(--primary, #509EE3);
}
.vp-chart-type.active {
    border-color: var(--primary, #509EE3);
    color: var(--primary, #509EE3);
    background: rgba(80, 158, 227, .1);
}

.vp-ct-icon { width: 24px; height: 24px; }
.vp-ct-icon svg { width: 100%; height: 100%; display: block; }

.vp-ct-label {
    font-size: 9px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
}

/* ── Series rows ─────────────────────────────────────────────────────────── */

.vp-series-row {
    display: grid;
    grid-template-columns: 28px 1fr;
    gap: 8px;
    align-items: start;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.vp-series-row:last-child { border-bottom: none; }

.vp-color-wrap { position: relative; }

.vp-swatch {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, .18);
    cursor: pointer;
    transition: transform .1s;
    display: block;
}
.vp-swatch:hover { transform: scale(1.1); }

.vp-color-hidden {
    position: absolute;
    top: 0; left: 0;
    width: 1px; height: 1px;
    opacity: 0;
    pointer-events: none;
}

.vp-series-title {
    font-size: 12px;
    padding: 4px 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--surface);
    color: var(--text);
    width: 100%;
    box-sizing: border-box;
}
.vp-series-title:focus { border-color: var(--primary-dim, #509EE3); outline: none; }

.vp-series-fmt-opts {
    grid-column: 2;
    margin-top: 4px;
}
.vp-series-fmt-opts .vp-select { width: 100%; }

.vp-series-row.vp-table-row { grid-template-columns: 1fr; }
.vp-series-row.vp-table-row .vp-series-fmt-opts { grid-column: 1; }

.vp-series-line-opts {
    grid-column: 2;
    display: flex;
    gap: 6px;
    margin-top: 4px;
}
.vp-series-line-opts .vp-select { width: auto; flex: 1; }

/* ── Palette row ─────────────────────────────────────────────────────────── */

.vp-palette-row {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    padding-top: 2px;
}
.vp-palette-swatch {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    border: 2px solid rgba(0, 0, 0, .12);
    cursor: pointer;
    transition: transform .1s;
}
.vp-palette-swatch:hover { transform: scale(1.15); }

/* ── Empty state ─────────────────────────────────────────────────────────── */

.vp-empty {
    font-size: 12px;
    color: var(--text-dim);
    text-align: center;
    padding: 24px 14px;
    margin: 0;
}

/* ── Filter bar ─────────────────────────────────────────────────────────── */

.dashboard-filter-bar {
    display: flex;
    gap: 6px;
    padding: 8px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    overflow-x: auto;
    scrollbar-width: none;
    align-items: center;
    min-height: 44px;
}

.dashboard-filter-bar::-webkit-scrollbar { display: none; }

.dash-filter-chip {
    display: inline-flex;
    align-items: stretch;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    transition: border-color 0.15s, background 0.15s;
}

.dash-filter-chip:hover { border-color: var(--border-light); }

.dash-filter-chip.active {
    border-color: var(--primary-dim);
    background: var(--primary-glow);
}

.dash-filter-label {
    display: flex;
    align-items: center;
    padding: 0 9px;
    background: var(--surface-hover);
    border-right: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.dash-filter-chip.active .dash-filter-label {
    color: var(--primary);
    border-right-color: var(--primary-dim);
    background: var(--primary-glow-strong);
}

.dash-filter-select {
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 12px;
    cursor: pointer;
    outline: none;
    padding: 6px 28px 6px 10px;
    max-width: 180px;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='none' viewBox='0 0 10 6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.dash-filter-select:focus { outline: none; }

.dash-filter-daterange {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 8px;
    border-left: 1px solid var(--border);
}

.dash-filter-daterange.hidden { display: none; }

.dash-filter-date-from,
.dash-filter-date-to {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text);
    font-size: 11px;
    padding: 3px 6px;
    width: 116px;
}

.dash-filter-apply-range {
    background: var(--primary);
    color: var(--bg);
    border: none;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    padding: 4px 10px;
    cursor: pointer;
    white-space: nowrap;
}

.dash-filter-apply-range:hover { background: var(--primary-dim); }

/* ── Responsive ──────────────────────────────────────────────────────────── */

@media (max-width: 752px) {
    /* Collapse to single-column flow on mobile — same breakpoint as Metabase. */
    .dashboard-stream {
        grid-template-columns: 1fr;
        grid-auto-rows: auto;
    }
    .dash-grid-card {
        grid-column: 1 / -1 !important;
        grid-row: auto !important;
    }
    /* Chart / table cards need a definite height so the `height: 100%` chain
       (dash-card-slot → dash-card-body → spark-card → chart-area) resolves to
       a real number. Without this, grid-auto-rows: auto makes the containing
       block "auto", height:100% collapses to content, and the chart shrinks
       itself into a ResizeObserver feedback loop. KPI/heading cards excluded. */
    .dash-grid-card:not([data-viz-type="scalar"]):not([data-viz-type="smartscalar"]):not([data-viz-type="progress"]):not([data-viz-type="heading"]) {
        height: 280px;
    }
    /* Heading section dividers: auto height so they never inherit the chart
       fixed-height rule — they should be as tall as their text, not 280px. */
    .dash-grid-card[data-viz-type="heading"] {
        height: auto !important;
        min-height: 52px;
    }
    .card-drag-handle,
    .dash-resize-s,
    .dash-resize-e { display: none; }
    .kpi-value { font-size: 18px; }

    /* SettingsPanel: use dvh so iOS Safari's collapsing URL bar doesn't clip
       the footer Save/Cancel buttons off the bottom of the screen. */
    .viz-panel {
        width: 100%;
        max-height: 100dvh;
    }

    /* Reduce chrome padding so charts get more horizontal space. */
    .dashboard-tab-bar    { padding: 0 12px; }
    #dashboard-filter-bar { padding: 0 16px 10px; }
    .dashboard-body       { padding: 12px 16px; }

    /* Date range inputs: ≥16px prevents iOS Safari auto-zoom on focus;
       min-height gives a comfortable touch target. */
    .dash-filter-date-from,
    .dash-filter-date-to {
        font-size: 16px;
        min-height: 36px;
    }
}

/* ── Phone (≤ 480px) — iPhone 15 Plus / most Android phones ─────────────── */

@media (max-width: 480px) {
    /* 2-column grid for KPI cards so they pair up side-by-side instead of
       stacking as a single tall column — closer to mobile app conventions. */
    .dashboard-stream {
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }
    /* KPI/progress cards occupy one cell each in the 2-col grid */
    .dash-grid-card[data-viz-type="scalar"],
    .dash-grid-card[data-viz-type="smartscalar"],
    .dash-grid-card[data-viz-type="progress"] {
        grid-column: auto !important;
        grid-row: auto !important;
    }
    /* Everything else (charts, tables, headings) spans the full width */
    .dash-grid-card:not([data-viz-type="scalar"]):not([data-viz-type="smartscalar"]):not([data-viz-type="progress"]) {
        grid-column: 1 / -1 !important;
    }
    /* Slightly shorter chart height on phones for better scroll cadence */
    .dash-grid-card:not([data-viz-type="scalar"]):not([data-viz-type="smartscalar"]):not([data-viz-type="progress"]):not([data-viz-type="heading"]) {
        height: 240px;
    }
    /* KPI value: slightly smaller so prefix/suffix don't overflow on narrow cells */
    .kpi-value { font-size: 15px; }
    /* Tighter padding inside the dashboard body */
    .dashboard-body { padding: 8px 12px; }
    /* Filter bar wraps instead of scrolling — easier on phones with few filters */
    .dashboard-filter-bar {
        flex-wrap: wrap;
        gap: 6px;
        overflow-x: hidden;
    }
    /* Chips can grow to fill a row but never overflow */
    .dash-filter-chip { flex-shrink: 1; max-width: 100%; }
    /* Date range: wrap inputs so they don't overflow the chip */
    .dash-filter-daterange { flex-wrap: wrap; }
    .dash-filter-date-from,
    .dash-filter-date-to { flex: 1; width: auto; min-width: 100px; }
    /* Mini-forms: inputs can shrink, buttons fill the row */
    .config-mini-input { min-width: 0; }
    .config-mini-actions .btn-primary,
    .config-mini-actions .btn-secondary { flex: 1; }
}
