/* ============================================================
   Marketing Dashboard — Light Theme
   DR-WALTER corporate colors
   ============================================================ */

:root {
    --bg: #ffffff;
    --bg-card: #f8f9fa;
    --card-border: #e9ecef;
    --radius: 12px;
    --radius-sm: 8px;
    --primary: #ef4601;
    --primary-hover: #d63e01;
    --primary-light: rgba(239, 70, 1, 0.08);
    --text: rgb(33, 37, 41);
    --text-secondary: #999;
    --text-muted: #bbb;
    --positive: #22c55e;
    --negative: #ef4444;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    padding: 0 24px 48px;
    -webkit-font-smoothing: antialiased;
    /* Suppress page-level horizontal scroll on desktop — individual
       scroll containers (.table-wrap, .biz-vkn-dropdown, …) keep their
       own overflow so wide tables still scroll internally. */
    overflow-x: clip;
    max-width: 100vw;
}

.tab-content, .tab-panel {
    min-width: 0;        /* allow grid/flex children to shrink below content */
}

/* ---- Card ---- */
.glass-card {
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
}

/* ============================================================
   Header
   ============================================================ */
.header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    column-gap: 24px;
    align-items: center;
    padding: 24px 0 16px;
}

.header-left {
    display: flex;
    align-items: center;
    justify-self: start;
}

.header-brand {
    justify-self: end;
}

.header-brand h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
    text-align: right;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    justify-self: end;
}

.header-updated {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.header-signout {
    background: transparent;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 6px 12px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.header-signout:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-light);
}

.header-logo {
    height: 20px;
    width: auto;
}

/* ============================================================
   Filter Bar
   ============================================================ */
.filter-bar {
    display: flex;
    align-items: flex-end;
    gap: 20px;
    padding: 16px 24px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.filter-group label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
}

.filter-control {
    background: var(--bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 8px 12px;
    font-size: 0.85rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.2s;
    min-width: 140px;
}

.filter-control:focus {
    border-color: var(--primary);
}

select.filter-control {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23999' stroke-width='1.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    padding-right: 32px;
}

select.filter-control option {
    background: var(--bg);
    color: var(--text);
}

/* Vergleich (compare) widget — lives inside the filter bar next to the date
   pickers. Collapsed state is just the checkbox + label; expanded reveals the
   mode toggle (Vorperiode / YoY) and a second pair of date inputs. */
.filter-group--compare {
    gap: 8px;
}

/* Per-section Vergleich (Business tab) — one inline widget per section,
   sits just to the right of the section's period badge. Collapsed state is
   only the checkbox + label; ticking the box expands the mode toggle and a
   second pair of date inputs horizontally to the right. */
.biz-section-compare {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-left: 4px;
}

.biz-compare-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
}

.biz-compare-toggle input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: #2e7d32;
    cursor: pointer;
}

.biz-compare-controls {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.biz-compare-controls[hidden] { display: none; }

.biz-compare-mode {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    background: var(--bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
}

.biz-compare-mode-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 4px 9px;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    border-radius: calc(var(--radius-sm) - 2px);
    transition: background-color 0.15s, color 0.15s;
}

.biz-compare-mode-btn:hover:not(.is-active) {
    background: rgba(46, 125, 50, 0.08);
    color: var(--text);
}

.biz-compare-mode-btn.is-active {
    background: #2e7d32;
    color: #fff;
}

.biz-compare-dates {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.biz-compare-dates .filter-control {
    min-width: auto;
    width: 128px;
    padding: 5px 8px;
    font-size: 0.78rem;
}

.compare-toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    cursor: pointer;
    user-select: none;
    padding-bottom: 8px;
}

.compare-toggle input[type="checkbox"] {
    width: 14px;
    height: 14px;
    accent-color: #2e7d32;
    cursor: pointer;
}

.compare-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* `display: flex` above overrides the native `hidden` attribute, so the
   collapsed state wouldn't actually hide. Restore it here. */
.compare-controls[hidden] {
    display: none;
}

.compare-mode {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    background: var(--bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
}

.compare-mode-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 5px 10px;
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    border-radius: calc(var(--radius-sm) - 2px);
    transition: background-color 0.15s, color 0.15s;
}

.compare-mode-btn:hover:not(.is-active) {
    background: rgba(46, 125, 50, 0.08);
    color: var(--text);
}

.compare-mode-btn.is-active {
    background: #2e7d32;
    color: #fff;
}

.compare-dates {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.compare-dates-label {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

.filter-control--compare {
    min-width: 130px;
    padding: 6px 10px;
    font-size: 0.8rem;
}

/* Period Toggle */
.period-toggle {
    display: flex;
    background: var(--bg);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--card-border);
}

.period-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 8px 16px;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: all 0.2s;
}

.period-btn.active {
    background: var(--primary);
    color: #fff;
}

.period-btn:hover:not(.active) {
    background: var(--primary-light);
    color: var(--text);
}

/* ============================================================
   Tabs
   ============================================================ */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--card-border);
    padding-bottom: 0;
}

.tab-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 12px 24px;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.2s;
    margin-bottom: -1px;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

.tab-btn:hover:not(.active) {
    color: var(--text);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* ============================================================
   KPI Cards
   ============================================================ */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.kpi-card {
    padding: 20px;
    text-align: center;
}

.kpi-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.kpi-value {
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.2;
    color: var(--text);
}

/* Vergleich: previous-period value rendered inline inside .kpi-value, grey
   and slightly smaller than the current value, with a small gap. */
.kpi-prev {
    display: inline-block;
    margin-left: 10px;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0;
    vertical-align: baseline;
}

.kpi-delta {
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 6px;
    min-height: 1.2em;
}

.kpi-delta.positive {
    color: var(--positive);
}

.kpi-delta.negative {
    color: var(--negative);
}

/* ============================================================
   Charts
   ============================================================ */
.charts-grid {
    display: grid;
    /* `min(420px, 100%)` lets a card shrink below 420 on narrow viewports
       instead of forcing the whole page to overflow horizontally. */
    grid-template-columns: repeat(auto-fit, minmax(min(420px, 100%), 1fr));
    gap: 20px;
    margin-bottom: 24px;
    min-width: 0;
}

.charts-grid--single {
    grid-template-columns: 1fr;
    max-width: 720px;
}

/* Forces 4 equal columns on wide screens (like the KPI row above), degrades
   to 2×2 on medium and 1-col on narrow. Used by Section 0's per-VKN charts. */
.charts-grid--row-of-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}
@media (max-width: 1200px) {
    .charts-grid--row-of-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .charts-grid--row-of-4 { grid-template-columns: 1fr; }
}

.chart-card {
    padding: 24px;
}

.chart-card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.chart-header h3 {
    margin-bottom: 0;
}

.chart-header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.viz-toggle {
    display: flex;
    background: var(--bg);
    border-radius: var(--radius-sm);
    overflow: hidden;
    border: 1px solid var(--card-border);
}

.viz-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 4px 8px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    line-height: 1;
}

.viz-btn.active {
    background: var(--primary);
    color: #fff;
}

.viz-btn:hover:not(.active) {
    background: var(--primary-light);
    color: var(--text);
}

/* Business-tab 3-way metric toggle (Abschlüsse / Prämie / Courtage).
   Sits in the chart-card between the <h3> and the <canvas>; sized to be
   unobtrusive so it reads as a tool, not a header. */
.metric-toggle {
    display: inline-flex;
    gap: 2px;
    padding: 2px;
    margin: -8px 0 12px;
    background: var(--bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
}

.metric-toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 3px 10px;
    font-size: 0.78rem;
    font-weight: 500;
    line-height: 1;
    cursor: pointer;
    border-radius: calc(var(--radius-sm) - 2px);
    transition: background-color 0.15s, color 0.15s;
}

.metric-toggle-btn:hover:not(.is-active) {
    background: rgba(46, 125, 50, 0.08);
    color: var(--text);
}

.metric-toggle-btn.is-active {
    background: #2e7d32;
    color: #fff;
}

.chart-table-wrap {
    overflow-x: auto;
    max-height: 300px;
    overflow-y: auto;
}

.chart-table-wrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}

.chart-table-wrap th {
    text-align: left;
    padding: 6px 10px;
    font-weight: 600;
    font-size: 0.7rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--card-border);
    cursor: default;
    position: sticky;
    top: 0;
    background: var(--bg-card);
}

.chart-table-wrap td {
    padding: 6px 10px;
    border-bottom: 1px solid #f0f0f0;
    color: var(--text-secondary);
}

.chart-table-wrap tr:hover td {
    background: var(--primary-light);
    color: var(--text);
}

.chart-table-wrap .bar-cell {
    width: 40%;
}

.chart-table-wrap .bar-bg {
    background: #f0f0f0;
    border-radius: 3px;
    height: 14px;
    position: relative;
    overflow: hidden;
}

.chart-table-wrap .bar-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--primary);
}

.filter-control--sm {
    font-size: 0.75rem;
    padding: 4px 8px;
    max-width: 160px;
}

.chart-card canvas {
    width: 100% !important;
    max-height: 300px;
}

.chart-empty-notice {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.82rem;
    line-height: 1.55;
    padding: 24px 16px;
    min-height: 220px;
    max-width: 46ch;
    margin: 0 auto;
}

/* ============================================================
   Tables
   ============================================================ */
.table-card {
    padding: 24px;
    margin-bottom: 24px;
}

.table-card h3 {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 16px;
}

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

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

th {
    text-align: left;
    padding: 10px 14px;
    font-weight: 600;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--card-border);
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
}

th:hover {
    color: var(--primary);
}

th.sort-asc::after {
    content: ' \25B2';
    font-size: 0.6rem;
}

th.sort-desc::after {
    content: ' \25BC';
    font-size: 0.6rem;
}

td {
    padding: 10px 14px;
    border-bottom: 1px solid #f0f0f0;
    white-space: nowrap;
    color: var(--text-secondary);
}

tr:hover td {
    background: var(--primary-light);
    color: var(--text);
}

/* Positive / Negative in table cells */
.cell-positive {
    color: var(--positive);
    font-weight: 600;
}

.cell-negative {
    color: var(--negative);
    font-weight: 600;
}

/* Indexed dot */
.dot-indexed {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--positive);
}

.dot-not-indexed {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    border: 1px solid var(--text-secondary);
}

/* Intent badge */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.badge-informational { background: rgba(239, 70, 1, 0.1); color: var(--primary); }
.badge-transactional { background: rgba(34, 197, 94, 0.12); color: var(--positive); }
.badge-navigational  { background: rgba(33, 37, 41, 0.08); color: var(--text); }
.badge-commercial    { background: rgba(37, 99, 235, 0.12); color: #2563eb; }

/* Cannibalization warning */
.cannibal-warn {
    color: var(--negative);
    font-size: 0.75rem;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================================
   Empty State
   ============================================================ */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
    font-size: 0.95rem;
}

/* ============================================================
   Loading spinner
   ============================================================ */
.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.7);
    z-index: 100;
    align-items: center;
    justify-content: center;
}

.loading-overlay.visible {
    display: flex;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--card-border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   Table header row (title + action button)
   ============================================================ */
.table-header-row {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    margin-bottom: 16px;
}

.table-header-row h3 {
    margin-bottom: 0;
    text-align: left;
}

.table-header-row .table-header-actions {
    margin-left: auto;
}

.table-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.table-search {
    background: var(--bg);
    border: 1px solid var(--card-border);
    color: var(--text);
    font-family: var(--font);
    font-size: 0.82rem;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    min-width: 220px;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.table-search::placeholder {
    color: var(--text-secondary);
    opacity: 0.7;
}

.table-search:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(239, 70, 1, 0.15);
}

/* Fokusseiten — narrow, wrap-friendly first column so table fits viewport */
.table-focus {
    table-layout: fixed;
    width: 100%;
}

.table-focus th,
.table-focus td {
    overflow-wrap: break-word;
    word-break: break-word;
}

.table-focus th:first-child,
.table-focus td.seite-cell {
    width: 32%;
    white-space: normal;
    line-height: 1.35;
}

.table-focus th:not(:first-child) {
    white-space: normal;
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
    background: var(--bg);
    border: 1px solid var(--card-border);
    color: var(--text-secondary);
    padding: 8px 16px;
    font-size: 0.82rem;
    font-weight: 500;
    font-family: var(--font);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
}

.btn:hover {
    background: #f0f0f0;
    color: var(--text);
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.08);
    border-color: rgba(239, 68, 68, 0.2);
    color: var(--negative);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.15);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.75rem;
}

/* Aktualisieren button (filter bar) */
.filter-group--action { align-self: flex-end; }
.filter-refresh {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 0.85rem;
    line-height: 1;
    white-space: nowrap;
}
.filter-refresh .refresh-icon {
    display: inline-block;
    font-size: 1rem;
    line-height: 1;
    transition: transform 0.3s ease;
}
.filter-refresh:hover .refresh-icon { transform: rotate(60deg); }
.filter-refresh[disabled],
.filter-refresh.is-loading {
    opacity: 0.7;
    cursor: progress;
}
.filter-refresh.is-loading .refresh-icon {
    animation: refresh-spin 0.9s linear infinite;
    transform: none;
}
@keyframes refresh-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(33, 37, 41, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 200;
    align-items: center;
    justify-content: center;
}

.modal-overlay.visible {
    display: flex;
}

.modal {
    width: 90%;
    max-width: 640px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    background: var(--bg);
    box-shadow: 0 20px 60px rgba(33, 37, 41, 0.15);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--card-border);
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
}

.modal-close:hover {
    color: var(--text);
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    flex: 1;
}

/* Content page rows inside modal */
.content-page-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid #f0f0f0;
    gap: 12px;
}

.content-page-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    flex: 1;
}

.content-page-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text);
}

.content-page-url {
    font-size: 0.72rem;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.content-page-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* Form row for add / inline edit */
.form-row {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    align-items: center;
}

.form-row .filter-control {
    flex: 1;
    min-width: 0;
}

.form-row--edit {
    margin-top: 0;
    flex: 1;
}

.kpi-value.kpi-awaiting {
    font-size: 0.95rem;
    font-weight: 500;
    font-style: italic;
    color: var(--muted, #94a3b8);
    letter-spacing: 0;
    cursor: help;
}

/* Info (i) icon next to each KPI label — hover shows a definition
   tooltip; clicking opens the walkthrough tour at the matching step
   (tour.js). */
.kpi-card { overflow: visible; position: relative; }

.kpi-info {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-left: 6px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.08);
    color: var(--text-secondary);
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 0.7rem;
    font-weight: 700;
    font-style: italic;
    line-height: 1;
    letter-spacing: 0;
    text-transform: none;
    cursor: pointer;
    user-select: none;
    position: relative;
    transition: background 0.15s ease, color 0.15s ease;
    vertical-align: middle;
}
.kpi-info:hover,
.kpi-info:focus {
    background: var(--primary);
    color: #fff;
    outline: none;
}

/* Old CSS pseudo-element tooltip for .kpi-info was replaced by the
   richer hover popover shown by tour.js (see .kpi-info-popover below).
   .kpi-warn still uses the pseudo-element tooltip. */

/* Warning variant of .kpi-info — reuses the same tooltip mechanics, tinted
   orange to signal "value is capped / needs context". Used next to the KPI
   value when the raw ratio is not comparable (e.g. offline-heavy Vermittler
   with tiny URL-tagged session base). Placement is inline so it flows with
   the KPI number instead of the label. */
.kpi-warn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    margin-left: 6px;
    border-radius: 50%;
    background: rgba(239, 70, 1, 0.15);
    color: var(--primary);
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1;
    letter-spacing: 0;
    text-transform: none;
    cursor: help;
    user-select: none;
    position: relative;
    transition: background 0.15s ease, color 0.15s ease;
    vertical-align: middle;
}
.kpi-warn:hover,
.kpi-warn:focus {
    background: var(--primary);
    color: #fff;
    outline: none;
}
.kpi-warn::after {
    content: attr(data-tooltip);
    position: absolute;
    left: 50%;
    bottom: calc(100% + 8px);
    transform: translateX(-50%);
    width: max-content;
    max-width: 280px;
    padding: 10px 12px;
    background: rgba(15, 23, 42, 0.97);
    color: #f1f5f9;
    /* Explicit — otherwise `inherit` picks up the parent icon's Georgia
       serif (used for the italic "i" / "!" letter), which clashes with the
       dashboard's sans-serif body text. */
    font-family: var(--font);
    font-size: 0.78rem;
    font-weight: 400;
    font-style: normal;
    line-height: 1.5;
    text-align: left;
    text-transform: none;
    letter-spacing: normal;
    border-radius: 6px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
    white-space: normal;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 0.15s ease;
    z-index: 100;
}
.kpi-warn::before {
    content: '';
    position: absolute;
    left: 50%;
    bottom: calc(100% + 2px);
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: rgba(15, 23, 42, 0.97);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.15s ease;
    z-index: 100;
}
.kpi-warn:hover::after,
.kpi-warn:hover::before,
.kpi-warn:focus::after,
.kpi-warn:focus::before {
    opacity: 1;
    visibility: visible;
}
/* When the warn badge lives inside a table cell, anchor its tooltip to the
   right so it can't get clipped by narrow columns. */
td .kpi-warn::after { left: auto; right: 0; transform: none; }
td .kpi-warn::before { left: auto; right: 4px; transform: none; }

.placeholder-banner {
    position: relative;
    background: rgba(239, 70, 1, 0.06);
    border: 1px solid rgba(239, 70, 1, 0.2);
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm);
    padding: 14px 44px 14px 18px;
    margin-bottom: 24px;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text);
}
.placeholder-banner .banner-close {
    position: absolute;
    top: 6px;
    right: 8px;
    appearance: none;
    background: transparent;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    color: var(--primary);
    opacity: 0.75;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}
.placeholder-banner .banner-close:hover {
    background: rgba(239, 70, 1, 0.12);
    opacity: 1;
}

.placeholder-banner strong {
    color: var(--primary);
    margin-right: 4px;
}

.business-section {
    margin-bottom: 32px;
}

.business-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    padding: 12px 20px;
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
}

/* Legacy chevron — superseded by the gear-icon controls group. */
.biz-section-toggle { display: none !important; }

.business-section-header h2 {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
    flex: 1;
}

.biz-section-toggle {
    appearance: none;
    background: transparent;
    border: none;
    padding: 4px 8px;
    margin-right: 4px;
    cursor: pointer;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
}
.biz-section-toggle:hover,
.biz-section-toggle:focus-visible {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text);
    outline: none;
}
.biz-section-toggle-chevron {
    display: inline-block;
    font-size: 0.85rem;
    line-height: 1;
    transition: transform 0.2s ease;
}
.biz-section-toggle[aria-expanded="false"] .biz-section-toggle-chevron {
    transform: rotate(-90deg);
}

.business-section[data-collapsed="true"] > *:not(.business-section-header) {
    display: none;
}
.business-section[data-collapsed="true"] .business-section-header {
    margin-bottom: 0;
}

/* Collapsible .table-card — chevron sits before the h3, table body hides on collapse. */
.table-card-toggle {
    appearance: none;
    background: transparent;
    border: none;
    padding: 4px 8px;
    margin-right: 4px;
    cursor: pointer;
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
}
.table-card-toggle:hover,
.table-card-toggle:focus-visible {
    background: rgba(0, 0, 0, 0.05);
    color: var(--text);
    outline: none;
}
.table-card-toggle-chevron {
    display: inline-block;
    font-size: 0.85rem;
    line-height: 1;
    transition: transform 0.2s ease;
}
.table-card-toggle[aria-expanded="false"] .table-card-toggle-chevron {
    transform: rotate(-90deg);
}
.table-card[data-collapsed="true"] .table-wrap,
.table-card[data-collapsed="true"] .empty-state {
    display: none;
}

/* Shows the active reporting period next to a section header. Populated
   from range.from/range.to when data loads. */
.section-period-badge {
    font-size: 0.72rem;
    font-weight: 500;
    color: var(--text-secondary);
    padding: 3px 10px;
    border-radius: 999px;
    background: rgba(0, 0, 0, 0.04);
    white-space: nowrap;
    margin-left: 4px;
    user-select: none;
    transition: background 0.12s ease, color 0.12s ease, box-shadow 0.12s ease;
}
.section-period-badge[role="button"] {
    cursor: pointer;
    border: 1px solid transparent;
}
.section-period-badge[role="button"]::before {
    content: "📅  ";
    font-size: 0.7rem;
    opacity: 0.65;
}
.section-period-badge[role="button"]:hover,
.section-period-badge[role="button"]:focus-visible {
    background: rgba(0, 0, 0, 0.07);
    color: var(--text);
    outline: none;
    border-color: var(--card-border);
}
.section-period-badge[aria-expanded="true"] {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.section-period-badge:empty { display: none; }

/* ============================================================
   Section-period popover (per-section date / week / month / quarter picker)
   ============================================================ */
.biz-period-popover {
    position: absolute;
    z-index: 1200;
    min-width: 280px;
    background: var(--bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.14);
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--text);
}
.biz-period-popover h4 {
    margin: 0;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}
.biz-period-popover .pp-row {
    display: flex;
    align-items: center;
    gap: 8px;
}
.biz-period-popover label {
    font-size: 0.78rem;
    color: var(--text-secondary);
    min-width: 44px;
}
.biz-period-popover input[type="date"],
.biz-period-popover input[type="week"],
.biz-period-popover input[type="month"],
.biz-period-popover select {
    flex: 1;
    font-size: 0.85rem;
    padding: 4px 8px;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
}
.biz-period-popover input:focus,
.biz-period-popover select:focus {
    outline: none;
    border-color: var(--primary);
}
.biz-period-popover .pp-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    margin-top: 4px;
}
.biz-period-popover .pp-btn {
    font-size: 0.78rem;
    padding: 4px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--card-border);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
}
.biz-period-popover .pp-btn.pp-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
}
.biz-period-popover .pp-btn.pp-primary:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}
.biz-period-popover .pp-btn:hover { filter: brightness(0.97); }
.biz-period-popover .pp-partial {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--text-secondary);
}

.cadence-badge {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 3px 10px;
}

.biz-section-controls {
    display: flex;
    align-items: center;
    gap: 10px;
}
.biz-tariff-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
}
.biz-tariff-sel {
    font-size: 0.85rem;
    padding: 4px 8px;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    background: var(--bg-card);
    color: var(--text);
    cursor: pointer;
    max-width: 240px;
}
.biz-tariff-sel:focus {
    outline: none;
    border-color: var(--primary);
}

/* ============================================================
   Business VKN (Vermittler) multi-select picker
   ============================================================ */
.biz-vkn-picker {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
}

.biz-vkn-label {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.biz-vkn-control {
    position: relative;
}

.biz-vkn-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-width: 240px;
    padding: 8px 12px;
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    font-size: 0.85rem;
    color: var(--text);
    cursor: pointer;
    transition: border-color 0.15s;
}
.biz-vkn-toggle:hover { border-color: var(--primary); }
.biz-vkn-toggle:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
.biz-vkn-summary { flex: 1; text-align: left; }
.biz-vkn-caret { color: var(--text-secondary); font-size: 0.7rem; }

.biz-vkn-dropdown {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    z-index: 20;
    min-width: 320px;
    max-height: 360px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
    padding: 6px;
}

.biz-vkn-dropdown-actions {
    display: flex;
    gap: 4px;
    padding: 4px 8px 6px;
    border-bottom: 1px solid var(--card-border);
    margin-bottom: 4px;
}
.biz-vkn-link {
    background: none;
    border: none;
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}
.biz-vkn-link:hover { background: rgba(239, 70, 1, 0.08); }

.biz-vkn-options {
    display: flex;
    flex-direction: column;
}

.biz-vkn-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    font-size: 0.85rem;
    color: var(--text);
    border-radius: 4px;
    cursor: pointer;
}
.biz-vkn-option:hover { background: rgba(0, 0, 0, 0.03); }
.biz-vkn-option input[type=checkbox] { margin: 0; cursor: pointer; }
.biz-vkn-name { font-weight: 500; }
.biz-vkn-platform {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.biz-vkn-empty {
    padding: 10px 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
}

.biz-vkn-swatch {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.biz-vkn-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.biz-vkn-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 8px 4px 8px;
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 999px;
    font-size: 0.75rem;
    color: var(--text);
}
.biz-vkn-chip-x {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 2px;
    margin-left: 2px;
}
.biz-vkn-chip-x:hover { color: var(--primary); }

/* ============================================================
   Datenquellen
   ============================================================ */
.sources-card {
    padding: 20px 24px;
    margin-bottom: 16px;
}

.sources-card h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 16px;
}

.sources-subnote {
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-secondary);
}

.sources-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

.source-row {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--card-border);
}

.source-row:last-child {
    border-bottom: none;
}

.source-text {
    flex: 1;
    min-width: 0;
}

.source-refresh {
    appearance: none;
    background: transparent;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: var(--font);
    font-size: 0.78rem;
    font-weight: 500;
    padding: 6px 12px;
    cursor: pointer;
    white-space: nowrap;
    align-self: center;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.source-refresh:hover:not(:disabled) {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-light);
}

.source-refresh:disabled {
    opacity: 0.65;
    cursor: wait;
}

.source-name {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text);
}

.source-name a {
    color: var(--primary);
    text-decoration: none;
    word-break: break-word;
}

.source-name a:hover {
    text-decoration: underline;
}

.source-detail {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.source-last {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.status-dot {
    flex-shrink: 0;
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-top: 5px;
    border: 1px solid rgba(0, 0, 0, 0.08);
}

.status-green  { background: #22c55e; box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.15); }
.status-yellow { background: #f59e0b; box-shadow: 0 0 0 2px rgba(245, 158, 11, 0.15); }
.status-red    { background: #ef4444; box-shadow: 0 0 0 2px rgba(239, 68, 68, 0.15); }

.sources-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 12px 24px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.sources-legend span {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.sources-legend .status-dot {
    margin-top: 0;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 768px) {
    body {
        padding: 0 12px 32px;
    }

    .filter-bar {
        padding: 12px 16px;
        gap: 12px;
    }

    .kpi-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-grid {
        grid-template-columns: 1fr;
    }

    .tab-btn {
        padding: 10px 14px;
        font-size: 0.8rem;
    }

    .header-logo {
        height: 16px;
    }
}

/* Dependency-audit banner — sits above the header on every tab when
   pip-audit reports ≥ 1 CVE against a runtime dependency. Uses the same
   primary-orange palette as .kpi-warn so it reads as a "needs admin action"
   surface rather than a hard error. */
.dep-audit-banner {
    padding: 10px 20px;
    background: rgba(239, 70, 1, 0.12);
    color: #7a1f00;
    border-bottom: 1px solid var(--primary);
    font-size: 0.9rem;
    text-align: center;
    line-height: 1.4;
}
.dep-audit-banner strong {
    color: var(--primary);
    margin-right: 4px;
}

/* ============================================================
   Produkte tab
   ============================================================ */
.products-page {
    display: grid;
    grid-template-columns: 320px 1fr;
    gap: 20px;
    align-items: start;
}
@media (max-width: 900px) {
    .products-page { grid-template-columns: 1fr; }
}

.products-list-pane {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    position: sticky;
    top: 20px;
}
.products-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.products-list-header h2 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}
.products-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 60vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.products-list li {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    transition: background 0.15s;
}
.products-list li:hover { background: rgba(0,0,0,0.04); }
.products-list li.active {
    background: var(--primary);
    color: #fff;
}
.products-list li.active .products-list-count { color: rgba(255,255,255,0.85); }
.products-list-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.products-list-count {
    font-size: 0.8rem;
    color: #666;
    flex-shrink: 0;
}
.products-empty {
    padding: 16px;
    color: #888;
    text-align: center;
    font-size: 0.9rem;
}

.products-detail-pane {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.products-detail-pane[hidden] { display: none; }
.products-detail-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.products-detail-header h2 { margin: 0; font-size: 1.1rem; }
.products-detail-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.products-detail-placeholder {
    padding: 40px 20px;
    text-align: center;
    color: #888;
    font-size: 0.95rem;
}

.products-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.form-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.form-label {
    font-size: 0.85rem;
    font-weight: 500;
    color: #333;
}
.form-label-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.form-label-row .table-search { max-width: 200px; }
.form-hint { color: #888; font-weight: 400; font-size: 0.8rem; }
.form-input {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid rgba(0,0,0,0.12);
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 0.9rem;
    background: #fff;
    color: var(--text);
    box-sizing: border-box;
}
.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(239,70,1,0.15);
}
textarea.form-input { resize: vertical; min-height: 48px; }

.products-codes-list {
    max-height: 360px;
    overflow-y: auto;
    border: 1px solid rgba(0,0,0,0.08);
    border-radius: var(--radius-sm);
    background: #fafafa;
    padding: 4px;
    display: flex;
    flex-direction: column;
}
.products-code-row {
    display: grid;
    grid-template-columns: 20px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 6px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
}
.products-code-row:hover { background: rgba(0,0,0,0.04); }
.products-code-row input[type="checkbox"] { margin: 0; cursor: pointer; }
.products-code-row.checked { background: rgba(239,70,1,0.06); }
.products-code-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.products-code-text { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.products-code-meta { font-size: 0.75rem; color: #666; }
.products-code-meta .in-product {
    display: inline-block;
    background: rgba(239,70,1,0.08);
    color: var(--primary);
    padding: 1px 6px;
    border-radius: 10px;
    margin-right: 4px;
    font-size: 0.7rem;
}
.products-code-closings {
    font-variant-numeric: tabular-nums;
    color: #666;
    font-size: 0.78rem;
}
.products-codes-empty {
    padding: 20px;
    text-align: center;
    color: #888;
    font-size: 0.85rem;
}

.products-feedback {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}
.products-feedback.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--negative);
    border: 1px solid rgba(239, 68, 68, 0.25);
}
.products-feedback.success {
    background: rgba(34, 197, 94, 0.1);
    color: #15803d;
    border: 1px solid rgba(34, 197, 94, 0.25);
}

.products-confirm {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}
.products-confirm[hidden] { display: none; }
.products-confirm-dialog {
    max-width: 420px;
    padding: 24px;
    text-align: center;
}
.products-confirm-dialog h3 { margin: 0 0 10px; font-size: 1.1rem; }
.products-confirm-dialog p { margin: 0 0 16px; color: #555; font-size: 0.9rem; }
.products-confirm-actions {
    display: flex;
    justify-content: center;
    gap: 10px;
}

/* AMS upload modal — generic enough to reuse for other CSV-import flows. */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 110;
}
.modal-card {
    background: #fff;
    border-radius: 10px;
    padding: 24px;
    width: min(440px, 90vw);
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-card h3 { margin: 0 0 10px; font-size: 1.1rem; }
.modal-help { margin: 0 0 16px; color: #555; font-size: 0.9rem; }
.modal-help code {
    background: #f4f4f4;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.85em;
}
.modal-card form { display: flex; flex-direction: column; gap: 12px; }
.modal-card label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.85rem;
    color: #333;
}
.modal-card input[type="file"],
.modal-card input[type="date"] {
    padding: 6px 8px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font: inherit;
}
.modal-status {
    min-height: 1.3em;
    font-size: 0.85rem;
    color: #444;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 4px;
}
.btn-ghost {
    background: transparent;
    border: 1px solid #ccc;
    color: #333;
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
}
.btn-ghost:hover { background: #f4f4f4; }

/* ============================================================
   Login screen
   ============================================================ */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    background: var(--bg-card);
}
.login-card {
    background: var(--bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 2px 20px rgba(0, 0, 0, 0.04);
}
.login-head {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 24px;
}
.login-logo {
    display: block;
    width: 100%;
    height: auto;
    object-fit: contain;
}
.login-head h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.01em;
    text-align: center;
}
.login-error {
    background: #fee;
    color: #a40000;
    border: 1px solid #f3b7b7;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin-bottom: 16px;
    font-size: 0.85rem;
}
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form label {
    display: flex; flex-direction: column; gap: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}
.login-form input {
    padding: 10px 12px;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 0.9rem;
    color: var(--text);
    background: var(--bg);
}
.login-form input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.login-submit {
    margin-top: 8px;
    padding: 10px 14px;
    background: var(--primary);
    color: #fff;
    border: 0;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.15s;
}
.login-submit:hover { background: var(--primary-hover); }

/* ============================================================
   Admin — users
   ============================================================ */
.admin-wrap {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
}
.admin-card {
    background: var(--bg-card);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 20px 24px;
}
.admin-card h2 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 14px;
    letter-spacing: -0.01em;
}
.admin-flash {
    padding: 10px 36px 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    position: relative;
    transition: opacity 280ms ease, transform 280ms ease;
}
.admin-flash.is-leaving {
    opacity: 0;
    transform: translateY(-4px);
}
.admin-flash-close {
    position: absolute;
    top: 4px;
    right: 6px;
    background: transparent;
    border: 0;
    font-size: 1.1rem;
    line-height: 1;
    color: inherit;
    opacity: 0.6;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
}
.admin-flash-close:hover,
.admin-flash-close:focus { opacity: 1; outline: none; }
.admin-flash-info    { background: #eef5ff; color: #1a3b78; border: 1px solid #cfe0ff; }
.admin-flash-ok      { background: #e8f8ee; color: #0d6b2a; border: 1px solid #b7e4c7; }
.admin-flash-error   { background: #fee; color: #a40000; border: 1px solid #f3b7b7; }
.admin-current { font-size: 0.9rem; color: var(--text-secondary); }
.admin-form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
.admin-form-grid label,
.admin-inline-form label {
    display: flex; flex-direction: column; gap: 4px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}
.admin-form-grid input,
.admin-form-grid textarea,
.admin-inline-form input,
.admin-inline-form textarea {
    padding: 8px 10px;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 0.85rem;
    color: var(--text);
    background: var(--bg);
}
.admin-form-grid textarea,
.admin-inline-form textarea { font-family: 'SFMono-Regular', Menlo, Consolas, monospace; }
.admin-checkbox {
    flex-direction: row !important;
    align-items: center;
    gap: 8px;
}
.admin-form-actions { grid-column: 1 / -1; }
.btn-primary {
    padding: 8px 14px;
    background: var(--primary);
    color: #fff;
    border: 0;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger {
    padding: 8px 14px;
    background: #fff;
    color: #a40000;
    border: 1px solid #f3b7b7;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
}
.btn-danger:hover { background: #fee; }
button[disabled].is-busy,
button.is-busy[disabled] {
    opacity: 0.78;
    cursor: progress;
    position: relative;
}
button.is-busy::after {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-left: 8px;
    border: 2px solid currentColor;
    border-top-color: transparent;
    border-radius: 50%;
    vertical-align: -1px;
    animation: adminBusySpin 0.7s linear infinite;
}
@keyframes adminBusySpin { to { transform: rotate(360deg); } }
.admin-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.admin-table th,
.admin-table td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid var(--card-border);
    vertical-align: top;
}
.admin-table th {
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.admin-muted { color: var(--text-secondary); font-size: 0.78rem; }
.admin-ips { display: flex; flex-wrap: wrap; gap: 4px; }
.admin-ip-chip {
    display: inline-block;
    padding: 2px 6px;
    background: var(--bg);
    border: 1px solid var(--card-border);
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: 'SFMono-Regular', Menlo, Consolas, monospace;
}
.admin-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 600;
}
.admin-badge-ok    { background: #e8f8ee; color: #0d6b2a; }
.admin-badge-warn  { background: #fff4e5; color: #8a4b00; }
.admin-row-actions details { font-size: 0.82rem; }
.admin-row-actions summary {
    cursor: pointer;
    color: var(--primary);
    font-weight: 500;
}
.admin-inline-form {
    display: flex; flex-direction: column; gap: 8px;
    padding: 10px 0 2px;
    border-top: 1px dashed var(--card-border);
    margin-top: 10px;
}

/* KPI formula KaTeX previews on /admin/kpis + /me/kpis */
.kpi-formula-preview { font-size: 0.95rem; }
.kpi-formula-preview .katex-display { margin: 0; }
.kpi-formula-live {
    display: flex; flex-direction: column; gap: 4px;
    padding: 8px 10px;
    background: #fafbfc;
    border: 1px solid var(--card-border);
    border-radius: 6px;
}
.kpi-formula-live-render { min-height: 24px; }
.kpi-formula-live-render .katex-display { margin: 0; }

/* ---- KPI edit modal (<dialog>) ---- */
.kpi-dialog {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin: 0;
    border: none;
    border-radius: 10px;
    padding: 0;
    width: min(720px, 92vw);
    max-height: 90vh;
    box-shadow: 0 20px 60px rgba(13, 20, 36, 0.25);
    background: #fff;
    color: #1a2235;
    overflow: hidden;
}
.kpi-dialog::backdrop {
    background: rgba(13, 20, 36, 0.45);
    backdrop-filter: blur(2px);
}
.kpi-dialog-form {
    display: flex;
    flex-direction: column;
    max-height: 90vh;
}
.kpi-dialog-head {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--card-border);
    background: #fafbfc;
}
.kpi-dialog-head h3 { margin: 0; font-size: 1.05rem; }
.kpi-dialog-head .admin-muted { font-size: 0.78rem; margin-top: 2px; }
.kpi-dialog-close {
    background: none; border: none; cursor: pointer;
    font-size: 1.5rem; line-height: 1;
    color: #6b7585;
    padding: 4px 10px;
    border-radius: 6px;
}
.kpi-dialog-close:hover { background: #eef0f3; color: #1a2235; }
.kpi-dialog-body {
    padding: 16px 18px;
    overflow-y: auto;
    display: flex; flex-direction: column; gap: 12px;
    flex: 1 1 auto;
}
.kpi-dialog-body label {
    display: flex; flex-direction: column; gap: 4px;
    font-size: 0.85rem; font-weight: 500;
}
.kpi-dialog-body input,
.kpi-dialog-body textarea,
.kpi-dialog-body select {
    font: inherit;
    padding: 8px 10px;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    background: #fff;
    width: 100%;
    box-sizing: border-box;
}
.kpi-dialog-body textarea {
    font-family: 'SFMono-Regular', Menlo, Consolas, monospace;
    resize: vertical;
}
.kpi-dialog-foot {
    display: flex; justify-content: flex-end; gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid var(--card-border);
    background: #fafbfc;
}
/* Buttons inside the dialog share one size (matching the admin-table body
   font) so Abbrechen and Speichern are visually equivalent. Primary keeps
   its heavier weight for emphasis. */
.kpi-dialog-foot button {
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
}
.kpi-dialog-foot .btn-primary { font-weight: 600; }
.kpi-edit-trigger { white-space: nowrap; }

/* ---- KPI overview grid (replaces the horizontal table) ---- */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
    gap: 14px;
}
.kpi-card-item {
    display: flex; flex-direction: column; gap: 10px;
    padding: 14px 16px;
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(13, 20, 36, 0.04);
    min-width: 0; /* allow children to shrink + wrap long tokens */
}
.kpi-card-item[hidden] { display: none; }
.kpi-card-head {
    display: flex; justify-content: space-between; align-items: flex-start;
    gap: 10px;
}
.kpi-card-head h3 {
    margin: 0;
    font-size: 0.95rem;
    line-height: 1.3;
    overflow-wrap: anywhere;
}
.kpi-card-head .admin-muted {
    font-size: 0.78rem;
    margin-top: 2px;
    overflow-wrap: anywhere;
}
.kpi-card-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}
.kpi-card-actions .btn-ghost {
    white-space: nowrap;
}
.kpi-card-fields {
    display: grid;
    grid-template-columns: 70px 1fr;
    column-gap: 10px;
    row-gap: 8px;
    margin: 0;
    font-size: 0.82rem;
    min-width: 0;
}
.kpi-card-fields dt {
    font-weight: 600;
    color: #6b7585;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    font-size: 0.7rem;
    padding-top: 3px;
}
.kpi-card-fields dd {
    margin: 0;
    min-width: 0;
    overflow-wrap: anywhere;
}
.kpi-card-fields dd .kpi-formula-preview { font-size: 0.9rem; }
.kpi-card-fields dd .kpi-formula-preview .katex { font-size: 0.95em; }
.kpi-card-fields dd .admin-ip-chip { word-break: break-all; }

/* ---- Formel help / cheatsheet inside the KPI dialog ---- */
.kpi-formula-help {
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 8px 10px;
    background: #fafbfc;
}
.kpi-formula-help > summary {
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
    color: #0d1424;
    user-select: none;
}
.kpi-formula-help[open] > summary { margin-bottom: 8px; }
.kpi-formula-help p { overflow-wrap: anywhere; margin: 6px 0 0; }
.kpi-formula-help a { word-break: break-word; }
.kpi-cheatsheet {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
}
.kpi-cheatsheet th,
.kpi-cheatsheet td {
    padding: 5px 8px;
    text-align: left;
    border-top: 1px solid var(--card-border);
    vertical-align: middle;
}
.kpi-cheatsheet th {
    background: #f1f3f5;
    font-weight: 600;
    border-top: none;
}
.kpi-cheatsheet code {
    background: #eef0f3;
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 0.78rem;
}
.kpi-cheatsheet td:last-child { min-width: 90px; }
.kpi-cheatsheet .katex { font-size: 0.95em; }

/* ---- Tag-pill multi-select for KPI sources ---- */
.kpi-source-field { display: flex; flex-direction: column; gap: 6px; }
.kpi-source-field > label { font-size: 0.85rem; font-weight: 500; }
.kpi-tag-list {
    display: flex; flex-wrap: wrap; gap: 6px;
    min-height: 32px;
    padding: 6px 8px;
    background: #fff;
    border: 1px solid var(--card-border);
    border-radius: 6px;
    align-items: center;
}
.kpi-tag {
    display: inline-flex; align-items: center; gap: 6px;
    background: #e8edf5;
    color: #1a2235;
    border-radius: 999px;
    padding: 3px 4px 3px 10px;
    font-size: 0.8rem;
    line-height: 1.2;
}
.kpi-tag-remove {
    display: inline-flex; align-items: center; justify-content: center;
    width: 18px; height: 18px;
    border: none; background: #c7d1e0; color: #1a2235;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0;
}
.kpi-tag-remove:hover { background: #ab7979; color: #fff; }
.kpi-tag-empty { font-size: 0.8rem; }
.kpi-tag-input-row { display: flex; gap: 6px; }
.kpi-tag-input-row input { flex: 1 1 auto; }
.kpi-tag-add { white-space: nowrap; }

/* ============================================================
   Per-user layout — dash-grid / dash-section
   ============================================================
   Managed tab-panels become a 4-column CSS grid. Each child
   `.dash-section` occupies `grid-column: span N` where N comes
   from the `.span-N` class applied by layout.js. Default spans
   are picked to visually match the pre-layout dashboard: KPI rows
   and tables span 4, chart-cards span 2 (or 1 inside "row-of-4"
   contexts), and composite .business-section blocks span 4.
   ============================================================ */

.tab-panel.dash-grid.active {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 20px;
    align-items: start;
}

/* The grid handles spacing, so flatten any bottom-margin set by
   element-specific styles (e.g. .kpi-row, .business-section). */
.tab-panel.dash-grid > .dash-section {
    margin-bottom: 0;
    min-width: 0;
}

.tab-panel.dash-grid > .dash-section.span-1 { grid-column: span 1; }
.tab-panel.dash-grid > .dash-section.span-2 { grid-column: span 2; }
.tab-panel.dash-grid > .dash-section.span-3 { grid-column: span 3; }
.tab-panel.dash-grid > .dash-section.span-4 { grid-column: span 4; }

@media (max-width: 1100px) {
    .tab-panel.dash-grid.active { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .tab-panel.dash-grid > .dash-section.span-1,
    .tab-panel.dash-grid > .dash-section.span-2 { grid-column: span 1; }
    .tab-panel.dash-grid > .dash-section.span-3,
    .tab-panel.dash-grid > .dash-section.span-4 { grid-column: span 2; }
}
@media (max-width: 640px) {
    .tab-panel.dash-grid.active { grid-template-columns: 1fr; }
    .tab-panel.dash-grid > .dash-section { grid-column: span 1 !important; }
}

.dash-section {
    position: relative;
}

/* Collapsed: hide every direct child except the section's own
   header/title row and our controls group. Chart-cards may wrap their
   title in .chart-header (title + viz-toggle + filters); table-cards
   use .table-header-row; business-sections use .business-section-header;
   kpi-cards have no header, just .kpi-label as a direct child. */
.dash-section.dash-collapsed > *:not(.dash-ctl-group):not(h3):not(h2):not(.chart-header):not(.business-section-header):not(.table-header-row):not(.kpi-label),
.dash-subsection.dash-collapsed > *:not(.dash-ctl-group):not(h3):not(h2):not(.chart-header):not(.kpi-label) {
    display: none !important;
}
.dash-section.dash-collapsed,
.dash-subsection.dash-collapsed {
    padding-bottom: 8px;
}
/* A collapsed kpi-card shrinks to a slim label-only chip so the user
   can still see which KPI was tucked away and expand it back. */
.dash-subsection.kpi-card.dash-collapsed {
    padding: 10px 14px;
    text-align: left;
    min-height: 36px;
}
.dash-subsection.kpi-card.dash-collapsed .kpi-label {
    margin-bottom: 0;
}

/* ---- Gear-icon settings group ----
   Each managed section/sub-section gets a .dash-ctl-group containing a
   gear button and a .dash-controls bar. The gear is always visible; the
   bar slides out to the LEFT of the gear when the user clicks it. The
   gear glyph flips to × while open. When the section has a header row
   (business-section-header / chart-header / table-header-row), the group
   is .is-inline and flows inside the header so it aligns vertically with
   the datepicker, viz-toggle, etc. Otherwise it is absolute-positioned in
   the top-right corner of the section. */
.dash-ctl-group {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    z-index: 5;
    flex-direction: row;
}
.dash-ctl-group:not(.is-inline) {
    position: absolute;
    top: 6px;
    right: 6px;
}
.dash-ctl-group.is-inline {
    margin-left: auto;
}

.dash-controls {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    max-width: 0;
    overflow: hidden;
    opacity: 0;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0);
    pointer-events: none;
    transition: max-width 0.22s ease, opacity 0.18s ease,
                background-color 0.18s ease, border-color 0.18s ease,
                padding 0.18s ease;
}
.dash-ctl-group.open .dash-controls {
    max-width: 320px;
    opacity: 1;
    padding: 2px 4px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border-color: rgba(0, 0, 0, 0.08);
    pointer-events: auto;
}

.dash-gear-btn {
    appearance: none;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    width: 24px;
    height: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary, #555);
    padding: 0;
    user-select: none;
    opacity: 0.55;
    transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
}
.dash-section:hover .dash-gear-btn,
.dash-subsection:hover .dash-gear-btn,
.dash-gear-btn:focus-visible,
.dash-ctl-group.open .dash-gear-btn {
    opacity: 1;
}
.dash-gear-btn:hover {
    background: #fff;
    color: var(--text, #111);
}
.dash-ctl-group.open .dash-gear-btn {
    background: #fff;
    color: var(--text, #111);
    font-size: 16px;
}

.dash-ctl {
    appearance: none;
    background: transparent;
    border: none;
    border-radius: 4px;
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary, #555);
    padding: 0;
    user-select: none;
}
.dash-ctl:hover:not(:disabled) {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text, #111);
}
.dash-ctl:disabled {
    opacity: 0.35;
    cursor: default;
}
.dash-span-indicator {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 14px;
    padding: 0 2px;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-secondary, #666);
    font-variant-numeric: tabular-nums;
}
.dash-ctl-sep {
    width: 1px;
    height: 14px;
    background: rgba(0, 0, 0, 0.1);
    margin: 0 2px;
}

/* ---- Sub-sections (individual KPIs / inner charts) ----
   kpi-cards inside any .kpi-row, and chart-cards inside a
   business-section's .charts-grid, each become .dash-subsection
   with their own hover controls bar: ◂/▸ reorder, −/span/+ width
   stepper, and ▾ collapse. The parent container becomes a 4-col
   grid so sub-widths snap predictably. */
.dash-sub-container {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
}
.dash-subsection {
    position: relative;
    min-width: 0;
    grid-column: span 1;
}
.dash-subsection.sub-span-1 { grid-column: span 1; }
.dash-subsection.sub-span-2 { grid-column: span 2; }
.dash-subsection.sub-span-3 { grid-column: span 3; }
.dash-subsection.sub-span-4 { grid-column: span 4; }

/* At narrow parent-section widths, collapse the sub-grid to fewer
   cols so single-column sub-items don't become unreadably narrow.
   Overrides the 4-col default above via higher specificity. */
.dash-section.span-1 > .dash-sub-container,
.dash-section.span-1 .dash-sub-container {
    grid-template-columns: 1fr !important;
}
.dash-section.span-1 .dash-subsection {
    grid-column: span 1 !important;
}
.dash-section.span-2 > .dash-sub-container,
.dash-section.span-2 .dash-sub-container {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}
.dash-section.span-2 .dash-subsection {
    grid-column: span 1 !important;
}
.dash-section.span-2 .dash-subsection.sub-span-3,
.dash-section.span-2 .dash-subsection.sub-span-4 {
    grid-column: span 2 !important;
}

/* Match the pre-existing responsive breakpoints of .charts-grid--row-of-4
   so the sub-grid stays readable on tablet / mobile. */
@media (max-width: 1200px) {
    .dash-sub-container {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }
    .dash-subsection.sub-span-3,
    .dash-subsection.sub-span-4 {
        grid-column: span 2 !important;
    }
}
@media (max-width: 640px) {
    .dash-sub-container {
        grid-template-columns: 1fr !important;
    }
    .dash-subsection {
        grid-column: span 1 !important;
    }
}
/* Sub-level: compact gear + buttons so inner KPIs/charts don't look
   crowded. Only one gear menu can be open at a time, so the two tiers
   never visually collide. */
.dash-ctl-group--sub:not(.is-inline) {
    top: 4px;
    right: 4px;
}
.dash-ctl-group--sub .dash-gear-btn {
    width: 20px;
    height: 20px;
    font-size: 12px;
}
.dash-ctl-group--sub.open .dash-gear-btn {
    font-size: 14px;
}
.dash-ctl-group--sub .dash-ctl {
    width: 20px;
    height: 20px;
    font-size: 11px;
}

/* ---- Tab-nav ◂/▸ chips ----
   Hidden by default; the gear button at the far right of the tab bar
   gates them. Click the gear → nav gets .tabs-reorder-open → chips fade
   in and the gear flips to ×. */
.tabs {
    align-items: center;
}
.tabs .tab-btn {
    position: relative;
}
.tab-nav-ctl {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: var(--text-secondary, #666);
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s ease;
    user-select: none;
    z-index: 2;
    line-height: 1;
}
.tab-nav-ctl--left { left: 2px; }
.tab-nav-ctl--right { right: 2px; }
.tabs.tabs-reorder-open .tab-nav-ctl:not(.is-disabled) {
    opacity: 1;
    pointer-events: auto;
}
.tab-nav-ctl:hover { background: #fff; color: var(--text, #111); }
.tab-nav-ctl.is-disabled { pointer-events: none; }

.tabs-gear-btn {
    appearance: none;
    margin-left: auto;
    background: rgba(255, 255, 255, 0.72);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 6px;
    width: 26px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    color: var(--text-secondary, #555);
    padding: 0;
    user-select: none;
    opacity: 0.55;
    transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease;
    align-self: center;
}
.tabs:hover .tabs-gear-btn,
.tabs-gear-btn:focus-visible,
.tabs.tabs-reorder-open .tabs-gear-btn {
    opacity: 1;
}
.tabs-gear-btn:hover {
    background: #fff;
    color: var(--text, #111);
}
.tabs.tabs-reorder-open .tabs-gear-btn {
    background: #fff;
    color: var(--text, #111);
    font-size: 16px;
}

/* ---- Narrow-span overflow safety ----
   By default a grid item won't shrink below its content's intrinsic
   min width; `min-width: 0` releases that lock. Then at span-1 (and
   partly span-2) we collapse inner grids and let flex headers wrap
   so chart canvases, KPI rows, and header controls stay inside their
   dash-section box instead of punching out to the right. */
.tab-panel.dash-grid > .dash-section,
.tab-panel.dash-grid > .dash-section > *,
.tab-panel.dash-grid .business-section > * {
    min-width: 0;
}

.dash-section canvas {
    max-width: 100% !important;
    height: auto;
}

.dash-section .chart-header,
.dash-section .chart-header-controls,
.dash-section .table-header-row,
.dash-section .table-header-actions,
.dash-section .business-section-header,
.dash-section .biz-section-controls {
    flex-wrap: wrap;
    row-gap: 8px;
}

/* span-1: single-column stack for every inner grid; KPI cards and
   chart tiles stack vertically full-width. */
.dash-section.span-1 .kpi-row,
.dash-section.span-1 .charts-grid,
.dash-section.span-1 .charts-grid--single,
.dash-section.span-1 .charts-grid--row-of-4 {
    grid-template-columns: 1fr !important;
}

/* span-2: give inner grids 2 columns max (down from 4-column defaults). */
.dash-section.span-2 .charts-grid--row-of-4 {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
}
.dash-section.span-2 .kpi-row {
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)) !important;
}

/* Tables are naturally wide — scroll them inside the card rather than
   stretching the card. .table-wrap already has overflow-x:auto. */
.dash-section .table-wrap {
    max-width: 100%;
}

/* ============================================================
   Walkthrough tour overlay (tour.js)
   ============================================================ */
.tour-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;
    pointer-events: auto;
    background: transparent;
}
body.tour-active {
    overflow: hidden;
}
.tour-spotlight {
    position: fixed;
    border-radius: 10px;
    box-shadow: 0 0 0 9999px rgba(10, 15, 25, 0.62);
    outline: 2px solid rgba(80, 160, 255, 0.9);
    outline-offset: 2px;
    transition: top 0.25s ease, left 0.25s ease, width 0.25s ease, height 0.25s ease;
    pointer-events: none;
}
.tour-popover {
    position: fixed;
    width: 360px;
    max-width: calc(100vw - 32px);
    background: #ffffff;
    color: #1b2230;
    border-radius: 12px;
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.28);
    padding: 18px 20px 14px;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    z-index: 9100;
    pointer-events: auto;
}
.tour-popover-progress {
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: #6b7585;
    margin-bottom: 6px;
}
.tour-popover-title {
    margin: 0 0 10px;
    font-size: 17px;
    font-weight: 600;
    color: #0d1424;
}
.tour-popover-body {
    font-size: 13.5px;
    line-height: 1.5;
    color: #2a3344;
}
.tour-popover-body p {
    margin: 0 0 8px;
}
.tour-popover-body p:last-child {
    margin-bottom: 0;
}
.tour-popover-body strong {
    color: #0d1424;
    font-weight: 600;
}
.tour-popover-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 14px;
    gap: 10px;
}
.tour-popover-nav {
    display: flex;
    gap: 8px;
}
.tour-btn {
    font: inherit;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    font-size: 13px;
    transition: background 0.15s ease, border-color 0.15s ease;
}
.tour-btn-ghost {
    background: transparent;
    color: #4a5668;
    border-color: #d6dae2;
}
.tour-btn-ghost:hover {
    background: #f1f3f7;
}
.tour-btn-ghost:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}
.tour-btn-primary {
    background: #2e9e5b;
    color: #ffffff;
    border-color: #2e9e5b;
}
.tour-btn-primary:hover {
    background: #26854b;
    border-color: #26854b;
}
#tourStartBtn {
    cursor: pointer;
}

/* Hover popover shown by tour.js when hovering a KPI (i) icon.
   Same look as the full-tour popover but smaller, no nav buttons,
   no backdrop. Click still opens the full tour at the matching step. */
.kpi-info-popover {
    position: fixed;
    width: 320px;
    max-width: calc(100vw - 24px);
    background: #ffffff;
    color: #1b2230;
    border-radius: 10px;
    box-shadow: 0 10px 32px rgba(0, 0, 0, 0.22);
    padding: 14px 16px 12px;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    z-index: 8800;
    pointer-events: auto;
    opacity: 0;
    transition: opacity 0.12s ease;
}
.kpi-info-popover.is-visible {
    opacity: 1;
}
.kpi-info-popover-title {
    margin: 0 0 8px;
    font-size: 15px;
    font-weight: 600;
    color: #0d1424;
}
.kpi-info-popover-body {
    font-size: 13px;
    line-height: 1.5;
    color: #2a3344;
}
.kpi-info-popover-body p {
    margin: 0 0 6px;
}
.kpi-info-popover-body p:last-child {
    margin-bottom: 0;
}
.kpi-info-popover-body strong {
    color: #0d1424;
    font-weight: 600;
}
.kpi-info-popover-hint {
    margin-top: 10px;
    font-size: 11px;
    color: #6b7585;
    letter-spacing: 0.02em;
}

/* KPI formula rendered via KaTeX inside the tour / hover popover. KaTeX's
   display block ships with its own margins — reset them so the formula hugs
   the surrounding "Berechnung:" line. */
.tour-formula {
    margin: 4px 0 2px;
    overflow-x: auto;
}
.tour-formula .katex-display { margin: 0; }
.tour-formula .katex { font-size: 1.0em; }
.kpi-info-popover-body .tour-formula .katex { font-size: 0.95em; }

/* "KPI bearbeiten" link in the tour / hover popover. Only shown when the
   current user may edit the KPI (admin or owner). */
.tour-edit-row { margin-top: 8px !important; }
.tour-edit-btn {
    display: inline-block;
    padding: 6px 12px;
    background: var(--primary, #3156b4);
    color: #fff;
    border-radius: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    text-decoration: none;
    line-height: 1.2;
}
.tour-edit-btn:hover {
    background: var(--primary-hover, #2946a0);
    color: #fff;
    text-decoration: none;
}

/* Current-page highlight in the shared header nav. Overrides .header-signout
   so the active item stands out without being loud. */
.header-signout.is-active {
    background: rgba(31, 59, 137, 0.08);
    color: var(--primary, #1f3b89);
    font-weight: 600;
    cursor: default;
}
.header-signout.is-active:hover {
    background: rgba(31, 59, 137, 0.12);
}

/* KPI grid toolbar (header + instant filter). */
.kpi-grid-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.kpi-grid-head h2 {
    margin: 0;
}
.kpi-grid-filter {
    flex: 0 1 320px;
    min-width: 220px;
    padding: 7px 12px;
    border: 1px solid var(--card-border, #e9ecef);
    border-radius: 6px;
    font: inherit;
    font-size: 0.9rem;
    background: #fff;
}
.kpi-grid-filter:focus {
    outline: none;
    border-color: var(--primary, #1f3b89);
    box-shadow: 0 0 0 3px rgba(31, 59, 137, 0.15);
}
.kpi-grid-empty {
    margin: 8px 0 0;
}

/* Admin tables (users / sites): same filter pattern as the KPI grid. */
.admin-table-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.admin-table-head h2 { margin: 0; }
.admin-table-filter {
    flex: 0 1 300px;
    min-width: 200px;
    padding: 7px 12px;
    border: 1px solid var(--card-border, #e9ecef);
    border-radius: 6px;
    font: inherit;
    font-size: 0.9rem;
    background: #fff;
}
.admin-table-filter:focus {
    outline: none;
    border-color: var(--primary, #1f3b89);
    box-shadow: 0 0 0 3px rgba(31, 59, 137, 0.15);
}

/* Site-wide footer with Confluence docs link. */
.site-footer {
    margin: 32px auto 20px;
    padding: 12px 24px 0;
    text-align: center;
    font-size: 0.82rem;
    color: #6c757d;
    border-top: 1px solid var(--card-border, #e9ecef);
    max-width: 1600px;
}
.site-footer a {
    color: #6c757d;
    text-decoration: none;
}
.site-footer a:hover {
    color: var(--primary, #1f3b89);
    text-decoration: underline;
}
.site-footer-links {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}
.site-footer-sep {
    color: #cbd0d6;
}
.site-footer-copy {
    margin-top: 6px;
    font-size: 0.78rem;
    color: #9099a2;
}

/* Legal / privacy pages: readable prose column. */
.legal-wrap { max-width: 900px; }
.legal-section h2 {
    margin: 24px 0 8px;
    font-size: 1.05rem;
    letter-spacing: -0.01em;
}
.legal-section h2:first-of-type { margin-top: 0; }
.legal-section h3 {
    margin: 16px 0 6px;
    font-size: 0.95rem;
}
.legal-section p,
.legal-section ul {
    line-height: 1.6;
    font-size: 0.9rem;
    color: var(--text-primary, #212529);
}
.legal-section ul {
    padding-left: 20px;
    margin: 6px 0 12px;
}
.legal-section em {
    color: #a06000;
    font-style: normal;
    background: #fff6e0;
    padding: 0 4px;
    border-radius: 3px;
}
