/* ==========================================================================
   Data Prism design system

   One place for the tokens and the shared components every page uses: the
   app shell (sidebar, top bar), page headers, panels, tables, buttons, forms,
   badges, alerts and tabs. Page files (editor-form.css, my-data.css, ...)
   only add what is particular to their page and use these tokens.

   Loaded after Bootstrap and Tabulator so it can restyle them, and before the
   page files. --primary-color comes from the brand (base.html sets it).
   ========================================================================== */

:root {
    /* Brand */
    --primary-color: #1d4ed8;
    --primary-light: #3b82f6;
    --primary-dark: #1e3a8a;
    --primary-soft: color-mix(in srgb, var(--primary-color) 9%, #fff);
    --primary-ring: color-mix(in srgb, var(--primary-color) 22%, transparent);

    /* Status (used for state, never for decoration) */
    --success-color: #15803d;
    --success-soft: #ecfdf3;
    --warning-color: #b45309;
    --warning-soft: #fffaeb;
    --error-color: #b42318;
    --error-soft: #fef3f2;
    --info-color: #175cd3;
    --info-soft: #eff8ff;
    --accent-color: #f59e0b;
    --star-color: #f59e0b;              /* a favourite's star, everywhere */
    --secondary-color: #0e7490;

    /* Neutrals */
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    --canvas: #f4f6f9;
    --surface: #ffffff;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-muted: #475569;
    --text-subtle: #64748b;

    /* Shell */
    --sidebar-width: 232px;
    --sidebar-collapsed: 60px;
    --topbar-height: 40px;
    --brand-height: 52px;
    --sidebar-bg: #0f172a;
    --sidebar-text: #cbd5e1;
    --sidebar-muted: #64748b;
    --sidebar-hover: rgba(255, 255, 255, 0.06);
    --sidebar-active: rgba(255, 255, 255, 0.10);

    /* Type */
    --font-family-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-family-mono: ui-monospace, 'SFMono-Regular', 'Cascadia Mono', Consolas, 'Liberation Mono', monospace;
    --font-size-xs: 11.5px;
    --font-size-sm: 12.5px;
    --font-size-base: 14px;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 12px;
    --spacing-lg: 16px;
    --spacing-xl: 24px;
    --spacing-2xl: 32px;
    --spacing-3xl: 48px;

    /* Shape */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-pill: 999px;           /* chips, tags and counts */
    --radius-xl: 8px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 2px 6px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.12);
    --shadow-xl: 0 16px 40px rgba(15, 23, 42, 0.16);

    --transition-fast: 120ms ease;
    --transition-base: 160ms ease;
    --transition-slow: 240ms ease;

    /* Bootstrap, so its components follow the same tokens */
    --bs-body-font-family: var(--font-family-primary);
    --bs-body-font-size: var(--font-size-base);
    --bs-body-color: var(--text);
    --bs-body-bg: var(--canvas);
    --bs-border-color: var(--border);
    --bs-border-radius: var(--radius-md);
    --bs-border-radius-sm: var(--radius-sm);
    --bs-border-radius-lg: var(--radius-lg);
    --bs-link-color-rgb: 29, 78, 216;
    --bs-secondary-color: var(--text-subtle);
}

/* ---------------------------------------------------------------- base -- */

html { -webkit-text-size-adjust: 100%; }

body {
    background: var(--canvas);
    color: var(--text);
    font-family: var(--font-family-primary);
    font-size: var(--font-size-base);
    line-height: 1.5;
    margin: 0;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 { color: var(--text); font-weight: 600; letter-spacing: -0.01em; }
.main h1, .main .h1 { font-size: 20px; line-height: 1.3; }
.main h2, .main .h2 { font-size: 18px; line-height: 1.3; }
.main h3, .main .h3 { font-size: 16px; }
.main h4, .main .h4 { font-size: 15px; }
.main h5, .main .h5, .main h6, .main .h6 { font-size: 14px; }

a { color: var(--primary-color); text-decoration: none; }
a:hover { color: var(--primary-dark); text-decoration: underline; }
.btn:hover, .nav-link:hover, .dropdown-item:hover, .list-group-item:hover { text-decoration: none; }

.text-muted { color: var(--text-subtle) !important; }
.small, small { font-size: var(--font-size-sm); }
code { color: #9a3412; font-family: var(--font-family-mono); font-size: 0.9em; }

:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ---------------------------------------------------------- app shell -- */

.sidebar {
    background: var(--sidebar-bg);
    bottom: 0;
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    left: 0;
    overflow-x: hidden;
    overflow-y: auto;
    position: fixed;
    /* The menu fits a laptop screen, so normally there is no bar. When it is
       taller than the window (a short window, or Open Data opened), a slim one
       shows that more is below. */
    scrollbar-color: rgba(255, 255, 255, 0.18) transparent;
    scrollbar-width: thin;
    top: 0;
    transition: width var(--transition-base), transform var(--transition-base);
    width: var(--sidebar-width);
    z-index: 1040;
}

.sidebar-brand {
    align-items: center;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    color: #fff;
    display: flex;
    flex: 0 0 var(--brand-height);
    gap: 10px;
    padding: 0 16px;
    text-decoration: none;
    white-space: nowrap;
}
.sidebar-brand:hover { color: #fff; text-decoration: none; }
.brand-mark {
    align-items: center;
    background: var(--primary-color);
    border-radius: 6px;
    display: inline-flex;
    flex: 0 0 28px;
    height: 28px;
    justify-content: center;
    width: 28px;
}
.brand-mark svg { display: block; }
.brand-logo { border-radius: 6px; flex: 0 0 28px; height: 28px; object-fit: contain; width: 28px; }
.brand-name { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.brand-name small { color: var(--sidebar-muted); display: block; font-size: 11px; font-weight: 500; letter-spacing: 0; line-height: 1.1; }

.sidebar-nav { flex: 1; padding: 8px 8px 16px; }

.sidebar .section-title {
    color: var(--sidebar-muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    padding: 12px 10px 4px;
    text-transform: uppercase;
    white-space: nowrap;
}

/* Scoped to the sidebar: .nav-item is also Bootstrap's class. */
.sidebar .nav-item {
    align-items: center;
    border-radius: var(--radius-md);
    color: var(--sidebar-text);
    cursor: pointer;
    display: flex;
    font-size: 13.5px;
    gap: 10px;
    margin: 1px 0;
    padding: 6px 10px;
    position: relative;
    text-decoration: none;
    transition: background-color var(--transition-fast), color var(--transition-fast);
    white-space: nowrap;
}
.sidebar .nav-item .icon { color: var(--sidebar-muted); flex: 0 0 18px; font-size: 18px; transition: color var(--transition-fast); }
.sidebar .nav-item .label { overflow: hidden; text-overflow: ellipsis; }
.sidebar .nav-item:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.sidebar .nav-item:hover .icon { color: var(--sidebar-text); }
.sidebar .nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 500; }
.sidebar .nav-item.active .icon { color: #fff; }
.sidebar .nav-item.active::before {
    background: var(--primary-light);
    border-radius: 0 2px 2px 0;
    bottom: 6px;
    content: '';
    left: -8px;
    position: absolute;
    top: 6px;
    width: 3px;
}
.sidebar .nav-item:focus-visible { outline: 2px solid var(--primary-light); outline-offset: -2px; }

.sidebar .nav-item.has-submenu::after {
    color: var(--sidebar-muted);
    content: '\ea50';               /* bx-chevron-right */
    font-family: boxicons;
    font-size: 16px;
    margin-left: auto;
    transition: transform var(--transition-fast);
}
.sidebar .nav-item.has-submenu.open::after { transform: rotate(90deg); }
.submenu { display: none; }
.submenu.show { display: block; }
.sidebar .submenu .nav-item { font-size: 13px; padding: 6px 10px 6px 38px; }
.sidebar .submenu .nav-item .icon { display: none; }

.sidebar-foot { border-top: 1px solid rgba(255, 255, 255, 0.06); color: var(--sidebar-muted); font-size: 11px; padding: 10px 18px; white-space: nowrap; }

.sidebar.collapsed { width: var(--sidebar-collapsed); }
.sidebar.collapsed .label,
.sidebar.collapsed .section-title,
.sidebar.collapsed .brand-name,
.sidebar.collapsed .sidebar-foot,
.sidebar.collapsed .submenu,
.sidebar.collapsed .nav-item.has-submenu::after { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 8px 0; }
.sidebar.collapsed .sidebar-brand { justify-content: center; padding: 0; }

/* A slim, see-through strip above the page: menu toggle, where you are, account.
   It is part of the page and scrolls away with it, so the whole window height
   goes to the work below. */
.topbar {
    align-items: center;
    background: transparent;
    display: flex;
    gap: 8px;
    height: var(--topbar-height);
    margin-left: var(--sidebar-width);
    padding: 0 20px 0 14px;
    position: relative;
    transition: margin-left var(--transition-base);
    z-index: 1030;
}
.sidebar.collapsed ~ .topbar { margin-left: var(--sidebar-collapsed); }

.topbar-toggle {
    align-items: center;
    background: transparent;
    border: 0;
    border-radius: var(--radius-md);
    color: var(--text-muted);
    display: inline-flex;
    font-size: 18px;
    height: 28px;
    justify-content: center;
    width: 28px;
}
.topbar-toggle:hover { background: var(--gray-100); color: var(--text); }

.topbar-title { color: var(--text-muted); font-size: 13px; font-weight: 500; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-title .crumb-sep { color: var(--gray-300); margin: 0 6px; }
.topbar-title .crumb-root { color: var(--text-subtle); font-weight: 500; }
.topbar-note { border-left: 1px solid var(--gray-300); color: var(--text-subtle); font-weight: 400; margin-left: 12px; padding-left: 12px; }
.topbar-note:empty { display: none; }
@media (max-width: 767.98px) { .topbar-note { display: none; } }
.topbar-controls { align-items: center; display: flex; gap: 8px; margin-left: auto; }

.user-menu-btn {
    align-items: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text);
    display: inline-flex;
    font-size: 13px;
    gap: 8px;
    padding: 2px 6px 2px 2px;
}
.user-menu-btn:hover, .user-menu-btn[aria-expanded="true"] { background: var(--gray-100); border-color: var(--border); }
.avatar {
    align-items: center;
    background: var(--primary-soft);
    border-radius: 50%;
    color: var(--primary-color);
    display: inline-flex;
    flex: 0 0 26px;
    font-size: 11px;
    font-weight: 700;
    height: 26px;
    justify-content: center;
    text-transform: uppercase;
    width: 26px;
}
.user-menu-name { font-weight: 500; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu-header { color: var(--text-subtle); font-size: 12px; padding: 4px 16px 6px; }
.user-menu-header strong { color: var(--text); display: block; font-size: 13px; }

.app-shell { min-height: 100vh; }
.main {
    margin-left: var(--sidebar-width);
    min-width: 0;
    padding: 4px 24px 32px;
    transition: margin-left var(--transition-base);
}
.sidebar.collapsed ~ .main { margin-left: var(--sidebar-collapsed); }
/* Opening a page with the menu already collapsed: no slide (base.html). */
.sidebar.no-slide, .sidebar.no-slide ~ .topbar, .sidebar.no-slide ~ .main { transition: none; }

.sidebar-backdrop { display: none; }

/* A page inside a report workspace frame (base.html "embedded"): content only. */
.embedded .main { margin-left: 0; padding: 8px 12px 16px; }

@media (max-width: 991.98px) {
    .main { padding-left: 16px; padding-right: 16px; }
}

/* Phones and small tablets: the sidebar slides in over the page. */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); width: var(--sidebar-width) !important; }
    .sidebar.show { box-shadow: var(--shadow-xl); transform: translateX(0); }
    /* Never the icon-only look here, even before the resize script runs. */
    .sidebar.collapsed .label, .sidebar.collapsed .section-title, .sidebar.collapsed .brand-name,
    .sidebar.collapsed .sidebar-foot, .sidebar.collapsed .nav-item.has-submenu::after { display: revert; }
    .sidebar.collapsed .submenu.show { display: block; }
    .sidebar.collapsed .nav-item { justify-content: flex-start; padding: 6px 10px; }
    .sidebar.collapsed .submenu .nav-item { padding-left: 38px; }
    .sidebar.collapsed .sidebar-brand { justify-content: flex-start; padding: 0 16px; }
    .topbar, .sidebar.collapsed ~ .topbar { margin-left: 0; padding: 0 12px 0 8px; }
    .main, .sidebar.collapsed ~ .main { margin-left: 0; padding: 4px 12px 24px; }
    .sidebar.show ~ .sidebar-backdrop { background: rgba(15, 23, 42, 0.4); display: block; inset: 0; position: fixed; z-index: 1035; }
    .user-menu-name { display: none; }
}

/* -------------------------------------------------------- page header -- */

.page-header {
    align-items: flex-start;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: space-between;
    margin-bottom: 16px;
}
.page-header h1 { font-size: 20px; margin: 0; }
.page-header .page-subtitle { color: var(--text-subtle); font-size: 13px; margin: 2px 0 0; }
.page-header .page-actions { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; }

/* --------------------------------------------------------------- panels -- */

.card {
    background: var(--surface);
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
}
.card.border-0 { border: 1px solid var(--border) !important; }

.card-header {
    align-items: center;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0 !important;
    color: var(--text);
    font-size: 14px;
    font-weight: 600;
    padding: 10px 16px;
}
.card-header h5, .card-header h6 { font-size: 14px; font-weight: 600; margin: 0; }
.card-body { padding: 16px; }
.card-footer { background: var(--gray-50); border-top: 1px solid var(--border); padding: 10px 16px; }

.list-group-item { border-color: var(--border); color: var(--text); font-size: 13.5px; padding: 9px 16px; }
.list-group-item-action:hover { background: var(--gray-50); }

/* --------------------------------------------------------------- tables -- */

.table {
    --bs-table-bg: transparent;
    --bs-table-striped-bg: transparent;
    --bs-table-hover-bg: var(--gray-50);
    color: var(--text);
    font-size: 13px;
    margin-bottom: 0;
    width: 100% !important;
}
.table thead { position: sticky; top: 0; z-index: 10; }
.table thead th {
    background: var(--gray-50);
    border-bottom: 1px solid var(--border) !important;
    border-top: 0;
    color: var(--text-subtle);
    font-size: var(--font-size-xs);
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 8px 12px;
    text-transform: uppercase;
    vertical-align: middle;
    white-space: nowrap;
}
.table tbody td {
    border-color: var(--border);
    color: var(--text);
    padding: 8px 12px;
    vertical-align: middle;
}
.table-sm thead th, .table-sm tbody td { padding: 6px 10px; }
.table tbody tr { background: transparent; transition: background-color var(--transition-fast); }
.table tbody tr:hover { background: var(--gray-50); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num, .table td.text-end { font-variant-numeric: tabular-nums; }

.table-responsive { border-radius: var(--radius-md); overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-responsive::-webkit-scrollbar { height: 8px; }
.table-responsive::-webkit-scrollbar-track { background: var(--gray-100); border-radius: var(--radius-md); }
.table-responsive::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: var(--radius-md); }
.table-responsive::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* Tabulator (result tables) */
.tabulator {
    background: var(--surface);
    border: 1px solid var(--border) !important;
    border-radius: var(--radius-md);
    font-size: 13px;
}
.tabulator .tabulator-header { background: var(--gray-50); border-bottom: 1px solid var(--border); color: var(--text-subtle); }
.tabulator .tabulator-header .tabulator-col { background: var(--gray-50); border-right: 0; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-content { padding: 7px 12px; }
.tabulator .tabulator-header .tabulator-col .tabulator-col-title { font-size: var(--font-size-xs); font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; }
.tabulator .tabulator-header .tabulator-col.tabulator-sortable:hover { background: var(--gray-100); }
.tabulator .tabulator-row { background: var(--surface); border-bottom: 1px solid var(--gray-100); min-height: 32px; }
.tabulator .tabulator-row.tabulator-row-even { background: var(--surface); }
.tabulator .tabulator-row:hover { background: var(--gray-50); }
.tabulator .tabulator-row .tabulator-cell { border-right: 0; padding: 6px 12px; }
.tabulator .tabulator-footer {
    background: var(--gray-50);
    border-top: 1px solid var(--border);
    color: var(--text-subtle);
    font-size: 12.5px;
    font-weight: 400;
    padding: 6px 12px;
}
.tabulator .tabulator-footer .tabulator-page {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 12.5px;
    margin: 0 2px;
    padding: 2px 8px;
}
.tabulator .tabulator-footer .tabulator-page.active { background: var(--primary-color); border-color: var(--primary-color); color: #fff; }
.tabulator .tabulator-footer .tabulator-page.disabled { opacity: 0.45; }

.result-meta { color: var(--text-subtle); font-size: 12px; font-weight: 400; }
.result-heading { align-items: baseline; display: flex; flex-wrap: wrap; gap: 2px 10px; min-width: 0; }
.result-description { color: var(--text-subtle); font-size: 12px; font-weight: 400; }
.empty-state { color: var(--text-subtle); font-size: 13px; padding: 24px 12px; text-align: center; }

/* Result and table states (TableFactory.stateHtml): loading, empty, error,
   no permission - the same look wherever a table can be. */
.tbl-state {
    align-items: center;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-md);
    color: var(--text-subtle);
    display: flex;
    flex-direction: column;
    font-size: 13px;
    gap: 6px;
    padding: 22px 12px;
    text-align: center;
}
.tbl-state > .bx { color: var(--gray-400); font-size: 22px; }
.tbl-state-title { color: var(--text); font-weight: 600; }
.tbl-state-message { color: var(--text-muted); max-width: 60ch; }
.tbl-state-loading { border-style: solid; border-color: var(--border); }
.tbl-state-error { background: var(--error-soft); border: 1px solid #fecdca; color: #7a271a; }
.tbl-state-error > .bx, .tbl-state-error .tbl-state-title { color: var(--error-color); }
.tbl-state-denied { background: var(--gray-50); border-style: solid; }
.tbl-state .btn { margin-top: 4px; }
/* An error while paging an existing table sits above it, compact. */
.tbl-state.tbl-state-inline { flex-direction: row; justify-content: space-between; margin-bottom: 8px; padding: 8px 12px; text-align: left; }
.tbl-state.tbl-state-inline .btn { margin-top: 0; }
/* TableFactory says what went wrong above the table; Tabulator's own pop-up would repeat it. */
.tabulator .tabulator-alert:has(.tabulator-alert-state-error) { display: none; }

/* -------------------------------------------------------------- buttons -- */

.btn {
    --bs-btn-font-size: 13px;
    --bs-btn-font-weight: 500;
    --bs-btn-padding-x: 12px;
    --bs-btn-padding-y: 5px;
    --bs-btn-border-radius: var(--radius-md);
    --bs-btn-focus-box-shadow: 0 0 0 3px var(--primary-ring);
    align-items: center;
    display: inline-flex;
    gap: 6px;
    justify-content: center;
    line-height: 20px;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}
.btn-sm {
    --bs-btn-font-size: 12.5px;
    --bs-btn-padding-x: 10px;
    --bs-btn-padding-y: 3px;
    --bs-btn-border-radius: var(--radius-md);
}
.btn-lg { --bs-btn-font-size: 14px; --bs-btn-padding-y: 8px; --bs-btn-padding-x: 16px; }
.btn .bx { font-size: 1.15em; line-height: 1; }
.d-grid > .btn, .btn.w-100 { display: flex; }

.btn-primary {
    --bs-btn-bg: var(--primary-color);
    --bs-btn-border-color: var(--primary-color);
    --bs-btn-hover-bg: var(--primary-dark);
    --bs-btn-hover-border-color: var(--primary-dark);
    --bs-btn-active-bg: var(--primary-dark);
    --bs-btn-active-border-color: var(--primary-dark);
    --bs-btn-disabled-bg: var(--primary-color);
    --bs-btn-disabled-border-color: var(--primary-color);
}
.btn-success {
    --bs-btn-bg: #15803d;
    --bs-btn-border-color: #15803d;
    --bs-btn-hover-bg: #166534;
    --bs-btn-hover-border-color: #166534;
    --bs-btn-active-bg: #14532d;
    --bs-btn-disabled-bg: #15803d;
    --bs-btn-disabled-border-color: #15803d;
}
.btn-danger { --bs-btn-bg: #b42318; --bs-btn-border-color: #b42318; --bs-btn-hover-bg: #912018; --bs-btn-hover-border-color: #912018; }

/* Secondary actions are neutral: colour is kept for the one primary action,
   for status and for destructive actions. */
.btn-outline-primary,
.btn-outline-secondary,
.btn-outline-success,
.btn-outline-info,
.btn-outline-warning,
.btn-outline-dark,
.btn-light,
.btn-secondary {
    --bs-btn-bg: var(--surface);
    --bs-btn-color: var(--text);
    --bs-btn-border-color: var(--border-strong);
    --bs-btn-hover-bg: var(--gray-50);
    --bs-btn-hover-color: var(--text);
    --bs-btn-hover-border-color: var(--gray-400);
    --bs-btn-active-bg: var(--gray-100);
    --bs-btn-active-color: var(--text);
    --bs-btn-active-border-color: var(--gray-400);
    --bs-btn-disabled-bg: var(--surface);
    --bs-btn-disabled-color: var(--gray-400);
    --bs-btn-disabled-border-color: var(--border);
    box-shadow: var(--shadow-sm);
}
.btn-outline-primary .bx, .btn-outline-secondary .bx, .btn-outline-info .bx,
.btn-outline-warning .bx, .btn-light .bx, .btn-secondary .bx { color: var(--text-subtle); }
.btn-outline-success .bx { color: var(--success-color); }
.btn-outline-danger {
    --bs-btn-bg: var(--surface);
    --bs-btn-color: var(--error-color);
    --bs-btn-border-color: var(--border-strong);
    --bs-btn-hover-bg: var(--error-soft);
    --bs-btn-hover-color: var(--error-color);
    --bs-btn-hover-border-color: #fda29b;
    --bs-btn-active-bg: var(--error-soft);
    --bs-btn-active-color: var(--error-color);
    box-shadow: var(--shadow-sm);
}
.btn-link { --bs-btn-color: var(--primary-color); --bs-btn-hover-color: var(--primary-dark); box-shadow: none; }
.btn-close:focus { box-shadow: 0 0 0 3px var(--primary-ring); }

.btn-group > .btn { box-shadow: none; }
.btn-check:checked + .btn-outline-primary,
.btn-check:checked + .btn-outline-secondary,
.btn-outline-primary.active,
.btn-outline-secondary.active {
    background: var(--primary-soft);
    border-color: color-mix(in srgb, var(--primary-color) 40%, #fff);
    color: var(--primary-color);
}

/* Row actions: quiet icons that become buttons on hover. */
.row-actions { display: inline-flex; gap: 2px; }
.row-action {
    align-items: center; background: transparent; border: 1px solid transparent; border-radius: var(--radius-md);
    color: var(--text-subtle); display: inline-flex; font-size: 16px; height: 28px; justify-content: center; width: 28px;
}
.row-action:hover { background: var(--surface); border-color: var(--border-strong); color: var(--text); text-decoration: none; }
.row-action-danger:hover { border-color: #fda29b; color: var(--error-color); }

/* Segmented control: a few fixed choices, one active (list scopes, views). */
.segmented {
    background: var(--gray-100); border: 1px solid var(--border); border-radius: var(--radius-md);
    display: inline-flex; flex-wrap: wrap; gap: 2px; padding: 2px;
}
.segment {
    align-items: center; background: transparent; border: 0; border-radius: var(--radius-sm); color: var(--text-muted);
    display: inline-flex; font-size: 12.5px; font-weight: 500; gap: 6px; padding: 3px 10px; white-space: nowrap;
}
.segment:hover { color: var(--text); }
.segment.active { background: var(--surface); box-shadow: 0 1px 2px rgba(15, 23, 42, 0.12); color: var(--text); }
.segment-count { color: var(--text-subtle); font-size: 11px; font-variant-numeric: tabular-nums; }
.segment.active .segment-count { color: var(--primary-color); }

/* The favourite star (reports and dashboards): one colour wherever a star is (--star-color). */
.btn-fav { background: none; border: 0; color: var(--gray-400); cursor: pointer; font-size: 17px; line-height: 1; padding: 2px 4px; }
.btn-fav:hover, .btn-fav[aria-pressed="true"] { color: var(--star-color); }
.btn-fav:focus-visible { outline: 2px solid var(--primary-light); outline-offset: 1px; }
.star-on { color: var(--star-color); }
.col-fav { padding-right: 0 !important; width: 28px; }

/* One look for every small pop-up list: filter suggestions, chart completion, the column picker, people search. */
.popover-list, .param-combo-menu, .chart-complete, .tbl-columns-menu, .dash-user-results {
    background: var(--surface); border: 1px solid var(--border-strong); border-radius: var(--radius-md); box-shadow: var(--shadow-lg);
}
/* A list page's toolbar (Reports, Dashboards, activity): search with its icon, scope chips, filters, the page's action. */
.list-toolbar { align-items: center; display: flex; flex-wrap: wrap; gap: var(--spacing-md); margin-bottom: var(--spacing-md); }
.list-search { width: 260px; }
.list-search .input-group-text { background: var(--surface); border-right: none; color: var(--gray-400); }
.list-search .form-control { border-left: none; padding-left: 0; }
.list-search .form-control:focus { box-shadow: none; }
@media (max-width: 575.98px) { .list-search { width: 100%; } }
/* A row's name and the line under it, in every list. */
.list-name { color: var(--primary-color); text-decoration: none; }
.list-name strong { font-weight: 600; }
.list-name:hover strong { text-decoration: underline; }
.list-desc { color: var(--text-subtle); display: block; font-size: 12.5px; line-height: 1.4; margin-top: 1px; }
/* Tags in a list (Reports, Dashboards): the bar of the most used, a filter each; a row's own, beside its name. */
.report-tag-bar { align-items: center; display: flex; flex-wrap: wrap; gap: 5px; margin: 0 0 10px; }
.report-tag-bar-label { color: var(--gray-500); font-size: 12px; margin-right: 2px; }
.report-tag {
    background: var(--surface); border: 1px solid var(--gray-300); border-radius: var(--radius-pill); color: var(--gray-600);
    cursor: pointer; font-size: 12px; padding: 1px 9px;
}
.report-tag:hover { background: var(--gray-100); }
.report-tag.active { background: var(--primary-color); border-color: var(--primary-color); color: #fff; }
.report-tag-count { opacity: .65; }
.report-row-tags { display: inline; margin-left: 6px; }
.report-row-tag {
    background: var(--gray-100); border: 1px solid var(--border); border-radius: var(--radius-pill); color: var(--text-muted);
    cursor: pointer; font-size: 11px; line-height: 1.5; margin-right: 3px; padding: 0 5px;
}
.report-row-tag:hover { background: var(--gray-200); }
/* The data sources a row reads (#db): plainer than tags, so the two read apart. */
.report-row-sources { display: inline; margin-left: 6px; }
.report-row-source {
    background: none; border: 1px dashed var(--border); border-radius: var(--radius-sm, 4px); color: var(--text-muted);
    cursor: pointer; font-size: 11px; line-height: 1.5; margin-right: 3px; padding: 0 5px;
}
.report-row-source:hover { background: var(--gray-100); }
/* Paging under a list: "Showing 1-25 of 40", rows per page, previous and next. */
.reports-pager { align-items: center; display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between; margin-top: 10px; }
.reports-pager[hidden] { display: none; }
.reports-pager select { width: auto; }

/* "Unsaved changes" beside a Save button (unsaved-changes.js). */
.unsaved-note { align-self: center; color: var(--warning-color); font-size: var(--font-size-xs); font-weight: 500; white-space: nowrap; }

/* A side panel's title, the same in every drawer. */
.offcanvas .offcanvas-title { font-size: 15px; font-weight: 600; margin: 0; }

/* ---------------------------------------------------------------- forms -- */

.form-label { color: var(--text-muted); font-size: 12.5px; font-weight: 500; margin-bottom: 4px; }
.form-control,
.form-select {
    background-color: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-md);
    color: var(--text);
    font-size: 13.5px;
    min-height: 34px;
    padding: 6px 10px;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
.form-select { padding-right: 32px; }
.form-control-sm, .form-select-sm { font-size: 12.5px; min-height: 30px; padding: 4px 8px; }
.form-select-sm { padding-right: 28px; }
textarea.form-control { min-height: auto; }
.form-control::placeholder { color: var(--gray-400); }
.form-control:focus,
.form-select:focus,
.form-check-input:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-ring);
    outline: none;
}
.form-check-input:checked { background-color: var(--primary-color); border-color: var(--primary-color); }
.form-text { color: var(--text-subtle); font-size: 12px; }
.input-group-text { background: var(--gray-50); border-color: var(--border-strong); color: var(--text-subtle); font-size: 13px; }

/* --------------------------------------------------------------- badges -- */

.badge {
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.01em;
    line-height: 1.3;
    padding: 2px 7px;
    text-transform: none;
}
.badge.bg-secondary, .badge.bg-light { background: var(--gray-100) !important; border-color: var(--gray-200); color: var(--gray-700) !important; }
.badge.bg-success { background: var(--success-soft) !important; border-color: #abefc6; color: var(--success-color) !important; }
.badge.bg-info { background: var(--info-soft) !important; border-color: #b2ddff; color: var(--info-color) !important; }
.badge.bg-warning { background: var(--warning-soft) !important; border-color: #fedf89; color: var(--warning-color) !important; }
.badge.bg-danger { background: var(--error-soft) !important; border-color: #fecdca; color: var(--error-color) !important; }
.badge.bg-primary { background: var(--primary-soft) !important; color: var(--primary-color) !important; }
.badge.bg-dark { background: var(--gray-700) !important; color: #fff !important; }
/* A report's or dashboard's status (drl/status_badge.html): the same look and words everywhere. */
.status-badge { border: 1px solid var(--border); font-weight: 500; }
.status-badge.status-draft { background: var(--gray-100); color: var(--text-muted); }
.status-badge.status-ready { background: var(--info-soft); color: var(--info-color); }
.status-badge.status-published { background: var(--success-soft); color: var(--success-color); }
.status-badge.status-deleted { background: var(--error-soft); color: var(--error-color); }

/* --------------------------------------------------------------- alerts -- */

.alert {
    border: 1px solid;
    border-radius: var(--radius-md);
    font-size: 13.5px;
    line-height: 1.5;
    margin-bottom: 16px;
    padding: 10px 14px;
}
.alert-danger { background: var(--error-soft); border-color: #fecdca; color: #7a271a; }
.alert-warning { background: var(--warning-soft); border-color: #fedf89; color: #7a2e0e; }
.alert-info { background: var(--info-soft); border-color: #b2ddff; color: #194185; }
.alert-success { background: var(--success-soft); border-color: #abefc6; color: #074d31; }
.alert strong { color: inherit; font-weight: 600; }

/* ----------------------------------------------------------------- tabs -- */

.nav-tabs { border-bottom: 1px solid var(--border); gap: 4px; }
.nav-tabs .nav-link {
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 0;
    color: var(--text-subtle);
    font-size: 13.5px;
    font-weight: 500;
    margin-bottom: -1px;
    padding: 8px 12px;
}
.nav-tabs .nav-link:hover { color: var(--text); }
.nav-tabs .nav-link.active { background: transparent; border-bottom-color: var(--primary-color); color: var(--text); font-weight: 600; }
.nav-pills .nav-link { border-radius: var(--radius-md); color: var(--text-muted); font-size: 13px; padding: 5px 10px; }
.nav-pills .nav-link.active { background: var(--primary-soft); color: var(--primary-color); }

/* ---------------------------------------------- dropdowns and modals -- */

.dropdown-menu {
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    font-size: 13.5px;
    padding: 4px;
}
.dropdown-item { border-radius: var(--radius-sm); color: var(--text); padding: 6px 12px; }
.dropdown-item:hover, .dropdown-item:focus { background: var(--gray-100); color: var(--text); }
.dropdown-divider { border-color: var(--border); margin: 4px 0; }

.modal-content { border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-xl); }
.modal-header { border-bottom: 1px solid var(--border); padding: 12px 16px; }
.modal-title { font-size: 15px; font-weight: 600; }
.modal-body { padding: 16px; }
.modal-footer { background: var(--gray-50); border-top: 1px solid var(--border); border-radius: 0 0 var(--radius-lg) var(--radius-lg); padding: 10px 16px; }

/* ------------------------------------------------------- summary tiles -- */

/* A row of comparable numbers: label, value, optional note. */
.stat-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 16px; }
/* Two tiles a row on a phone, rather than one tall column of them. */
@media (max-width: 576px) { .stat-grid { gap: 8px; grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    color: inherit;
    display: block;
    padding: 12px 16px;
}
a.stat:hover { border-color: var(--border-strong); text-decoration: none; }
.stat-label { color: var(--text-subtle); font-size: 12px; font-weight: 500; }
.stat-value { color: var(--text); font-size: 22px; font-variant-numeric: tabular-nums; font-weight: 600; line-height: 1.3; }
/* An inline bar in a table cell: a share of the row's column, read beside the number, never instead of it. */
.bar-track { background: var(--gray-100); border-radius: 2px; display: inline-block; height: 8px; vertical-align: middle; width: 100%; max-width: 160px; }
.bar-fill { background: var(--primary-color); border-radius: 2px; height: 100%; opacity: .75; }
.visit-trend { max-height: 420px; overflow-y: auto; }
.visit-filters .segmented { flex-wrap: wrap; }

.pagination { --bs-pagination-color: var(--text); --bs-pagination-border-color: var(--border-strong); --bs-pagination-active-bg: var(--primary-color); --bs-pagination-active-border-color: var(--primary-color); --bs-pagination-hover-bg: var(--gray-50); --bs-pagination-focus-box-shadow: 0 0 0 3px var(--primary-ring); }

/* ----------------------------------------------------------- utilities -- */

.section-label { color: var(--text-subtle); font-size: 11.5px; font-weight: 600; letter-spacing: 0.05em; margin: 0 0 8px; text-transform: uppercase; }
.text-num { font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- print -- */

@media print {
    .sidebar, .topbar, .sidebar-backdrop { display: none !important; }
    .main { margin: 0 !important; padding: 0 !important; }
    body { background: #fff; }
}


/* ==========================================================================
   Report picker (drl/templates/drl/report_picker.html, js/modules/report-picker.js):
   published reports to search and pick, in a drawer from the left. The report
   workspace and the dashboard builder share it.
   ========================================================================== */
.rp-drawer { --bs-offcanvas-width: 360px; }
.rp-drawer .offcanvas-body { padding-top: 0; }
.rp-library { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
.rp-drawer .rp-library { height: 100%; }
.rp-scope { align-self: flex-start; }
.rp-list { flex: 1 1 auto; margin: 0 -4px; min-height: 80px; overflow-y: auto; }
.rp-foot { border-top: 1px solid var(--border); padding-top: 6px; }
.rp-pick { align-items: flex-start; border-left: 2px solid transparent; border-radius: var(--radius-sm); display: flex; gap: 2px; }
.rp-pick:hover { background: var(--gray-100); }
.rp-pick.is-picked { border-left-color: var(--primary-color); }
.rp-pick.is-active { background: var(--primary-soft); }
.rp-pick-main { background: none; border: 0; flex: 1 1 auto; min-width: 0; padding: 6px 8px; text-align: left; }
.rp-pick-main:focus-visible { outline: 2px solid var(--primary-ring); outline-offset: -2px; }
.rp-pick-again { flex: 0 0 auto; margin: 4px 4px 0 0; }
.rp-pick-badge { background: var(--primary-soft); border-radius: var(--radius-pill); color: var(--primary-color); font-size: 11px; font-weight: 600; padding: 0 6px; }
.rp-pick-name { align-items: center; color: var(--text); display: flex; font-size: 13px; font-weight: 500; gap: 4px; }
.rp-pick-name .bxs-star { color: var(--star-color); font-size: 12px; }
.rp-pick-desc { color: var(--text-subtle); display: block; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rp-pick-tags { color: var(--text-subtle); display: block; font-size: 11px; margin-top: 1px; }
.rp-none { color: var(--text-subtle); font-size: 12px; padding: 6px 8px; }
@media (max-width: 768px) { .rp-drawer { --bs-offcanvas-width: 100vw; } }
