:root {
    --ds-space-1: .25rem;
    --ds-space-2: .5rem;
    --ds-space-3: .75rem;
    --ds-space-4: 1rem;
    --ds-space-5: 1.5rem;
    --ds-space-6: 2rem;
    --ds-radius-sm: 8px;
    --ds-radius-md: 12px;
    --ds-radius-lg: 18px;
    --ds-elevation-1: 0 4px 12px rgba(31, 45, 61, .06);
    --ds-elevation-2: 0 12px 30px rgba(31, 45, 61, .10);
    --ds-elevation-3: 0 24px 60px rgba(31, 45, 61, .16);
    --ds-success: #168052;
    --ds-warning: #a86e10;
    --ds-danger: #b42318;
    --ds-info: #4966aa;
}

.ds-panel,
.dashboard-card,
.settings-section,
.analytics-panel,
.communications-panel,
.api-docs-section {
    border-radius: var(--ds-radius-lg);
    box-shadow: var(--ds-elevation-1);
}

.ds-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: var(--ds-space-4);
}

.ds-form-actions,
.ds-toolbar,
.ds-pagination {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--ds-space-3);
}

.ds-form-actions,
.ds-pagination {
    justify-content: flex-end;
}

.modal-content,
.ds-modal .modal-content {
    border-radius: var(--ds-radius-lg);
    box-shadow: var(--ds-elevation-3);
}

.ds-modal .modal-header,
.ds-modal .modal-footer,
.ds-modal .modal-body {
    padding: var(--ds-space-5);
}

/* Wide modals (modal-xl) grow with the screen on large viewports.
   Keeps a 1.75rem margin each side and stops at 1400px. Narrower
   viewports keep Bootstrap's own widths. */
@media (min-width: 1200px) {
    .modal-dialog.modal-xl {
        --bs-modal-width: min(1400px, calc(100vw - 3.5rem));
    }
}

.dropdown-menu {
    border-radius: var(--ds-radius-md);
    box-shadow: var(--ds-elevation-2);
}

.alert,
.ds-alert {
    border-radius: var(--ds-radius-md);
}

.ds-empty-state {
    display: grid;
    min-height: 180px;
    place-items: center;
    padding: var(--ds-space-6);
    border: 1px dashed var(--app-border);
    border-radius: var(--ds-radius-lg);
    color: var(--app-muted);
    background: var(--app-panel-bg);
    text-align: center;
}

.ds-empty-state i {
    display: block;
    margin-bottom: var(--ds-space-3);
    color: var(--app-accent);
    font-size: 2rem;
}

.ds-empty-state h2,
.ds-empty-state h3 {
    color: var(--app-ink);
}

.ds-skeleton {
    position: relative;
    overflow: hidden;
    border-radius: var(--ds-radius-sm);
    background: var(--app-hover-bg);
}

.ds-skeleton::after {
    position: absolute;
    inset: 0;
    content: "";
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.42), transparent);
    transform: translateX(-100%);
    animation: ds-skeleton-shimmer 1.35s ease-in-out infinite;
}

.ds-skeleton-line {
    height: .85rem;
    margin-bottom: var(--ds-space-3);
}

.ds-skeleton-card {
    height: 112px;
}

.ds-badge,
.badge {
    border-radius: 999px;
}

.badge-success,
.ds-badge-success {
    color: #fff;
    background: var(--ds-success);
}

.badge-warning,
.ds-badge-warning {
    color: #fff;
    background: var(--ds-warning);
}

.badge-danger,
.ds-badge-danger {
    color: #fff;
    background: var(--ds-danger);
}

.badge-info,
.ds-badge-info {
    color: #fff;
    background: var(--ds-info);
}

.ds-pagination {
    padding: var(--ds-space-4);
}

.ds-toast-region {
    position: fixed;
    right: 1rem;
    top: 1rem;
    z-index: 1080;
    display: grid;
    width: min(360px, calc(100vw - 2rem));
    gap: var(--ds-space-3);
    pointer-events: none;
}

.ds-toast {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: start;
    gap: var(--ds-space-3);
    border: 1px solid var(--app-border);
    border-radius: var(--ds-radius-md);
    padding: .85rem 1rem;
    color: var(--app-ink);
    background: var(--app-surface);
    box-shadow: var(--ds-elevation-3);
    pointer-events: auto;
    animation: ds-toast-enter .18s ease-out;
}

.ds-toast.is-success i {
    color: var(--ds-success);
}

.ds-toast.is-error i {
    color: var(--ds-danger);
}

.ds-toast.is-warning i {
    color: var(--ds-warning);
}

.ds-toast button {
    border: 0;
    color: var(--app-muted);
    background: transparent;
}

:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--app-primary) 58%, transparent);
    outline-offset: 3px;
}

@keyframes ds-skeleton-shimmer {
    to { transform: translateX(100%); }
}

@keyframes ds-toast-enter {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 575.98px) {
    .ds-form-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .ds-form-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .ds-form-actions .btn {
        width: 100%;
    }

    .ds-modal .modal-header,
    .ds-modal .modal-footer,
    .ds-modal .modal-body {
        padding: var(--ds-space-4);
    }

    .ds-toast-region {
        right: .5rem;
        top: .5rem;
        width: calc(100vw - 1rem);
    }
}

@media (prefers-reduced-motion: reduce) {
    .ds-skeleton::after,
    .ds-toast {
        animation: none;
    }

    .ds-loading-overlay {
        transition: none;
    }
}

/* The spinner is not turned off by reduced motion. It shows on every data refresh. */

/* Frosted glass loading. Content stays visible, blurred behind a translucent panel with a spinner in the middle. */
.ds-loading-host {
    position: relative;
}

.ds-loading-overlay {
    position: absolute;
    inset: 0;
    z-index: 5;
    display: flex;
    align-items: center;
    justify-content: center;
    background: color-mix(in srgb, var(--app-surface) 55%, transparent);
    -webkit-backdrop-filter: blur(6px) saturate(1.15);
    backdrop-filter: blur(6px) saturate(1.15);
    border-radius: inherit;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity .18s ease;
}

.ds-loading-overlay.is-visible {
    opacity: 1;
    pointer-events: auto;
}

/* The spinner in the middle of the frosted panel. It always turns, including when reduced motion is set. */
.ds-spinner {
    position: relative;
    z-index: 1;
    flex: 0 0 auto;
    width: 2.6rem;
    height: 2.6rem;
    border: 3px solid var(--app-border);
    border-top-color: var(--app-primary);
    border-radius: 50%;
    animation: ds-spin .8s linear infinite;
}


@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
    .ds-loading-overlay {
        background: color-mix(in srgb, var(--app-surface) 88%, transparent);
    }
}

.ds-loading-card {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: .6rem;
    padding: .55rem 1rem;
    border: 1px solid var(--app-border);
    border-radius: 999px;
    background: var(--app-surface);
    color: var(--app-ink);
    box-shadow: var(--app-shadow);
    font-size: .9rem;
    font-weight: 600;
}

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

body {
    font-family: var(--user-font-family, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);
    font-size: var(--user-base-size, 16px);
}

.admin-main h1,
.print-profile-header h1 {
    font-family: var(--user-font-family, inherit);
    font-size: var(--user-page-heading-size, inherit) !important;
    font-weight: var(--user-page-heading-weight, inherit) !important;
}

.dashboard-card h2,
.settings-section h2,
.analytics-panel h2,
.api-docs-section h2,
.communications-panel h2,
.users-panel h2,
.card-header h2 {
    font-size: var(--user-card-heading-size, inherit) !important;
    font-weight: var(--user-card-heading-weight, inherit) !important;
}

.admin-main table thead th,
.admin-main table thead th button {
    font-size: var(--user-table-header-size, inherit) !important;
    font-weight: var(--user-table-header-weight, inherit) !important;
}

.admin-main table tbody td,
.admin-main table tbody th {
    font-size: var(--user-table-cell-size, inherit) !important;
    font-weight: var(--user-table-cell-weight, inherit) !important;
}

.admin-main table[data-density="compact"] > :not(caption) > * > * {
    padding-block: .35rem;
    padding-inline: .5rem;
}

.user-table-preference-toolbar {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: .75rem;
}

.user-table-density {
    display: grid;
    min-width: 150px;
    gap: .25rem;
    color: var(--app-muted);
    font-size: .75rem;
}

.user-table-column-panel {
    position: relative;
}

.user-table-column-panel > summary,
.dashboard-personalization > summary {
    cursor: pointer;
    color: var(--app-accent);
    font-size: .85rem;
    font-weight: 650;
}

.user-table-column-panel[open] {
    z-index: 4;
}

.user-table-column-list {
    display: grid;
    max-height: 320px;
    min-width: min(100%, 340px);
    gap: .35rem;
    overflow: auto;
    margin-top: .5rem;
    padding: .6rem;
    border: 1px solid var(--app-border);
    border-radius: 10px;
    background: var(--app-surface);
    box-shadow: var(--app-shadow);
}

.user-table-column-item,
.dashboard-widget-preference {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    color: var(--app-ink);
    font-size: .85rem;
}

.user-table-column-item > label,
.dashboard-widget-preference > label {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: .5rem;
}

.user-table-column-move,
.dashboard-widget-move,
.user-table-preference-actions {
    display: flex;
    flex: 0 0 auto;
    gap: .35rem;
}

.user-table-column-move .btn,
.dashboard-widget-move .btn {
    min-width: 32px;
}

.user-table-preference-actions {
    margin-top: .35rem;
}

.user-table-preference-status,
.dashboard-preference-status {
    min-height: 1.25rem;
    color: var(--app-muted);
    font-size: .75rem;
}

.dashboard-personalization {
    padding: 1rem 1.25rem;
    border: 1px solid var(--app-border);
    border-radius: 14px;
    background: var(--app-surface);
}

.dashboard-widget-preference-list {
    display: grid;
    max-width: 560px;
    gap: .6rem;
}

@media print {
    .admin-sidebar,
    .admin-sidebar-header,
    .admin-sidebar-toggle,
    .maintenance-footer,
    .ds-form-actions,
    .ds-toast-region,
    .modal,
    .btn,
    button {
        display: none !important;
    }

    body,
    .dashboard-page,
    .admin-layout,
    .admin-main {
        height: auto !important;
        min-height: 0 !important;
        overflow: visible !important;
        color: #111 !important;
        background: #fff !important;
    }

    .admin-main {
        width: 100% !important;
        padding: 12.7mm !important;
    }

    .ds-panel,
    .dashboard-card,
    .settings-section,
    .analytics-panel,
    .communications-panel,
    .api-docs-section,
    .table,
    .card,
    .modal-content {
        break-inside: avoid;
        border: 1px solid #bbb !important;
        color: #111 !important;
        background: #fff !important;
        box-shadow: none !important;
    }

    .table {
        width: 100% !important;
        border-collapse: collapse !important;
    }

    .table th,
    .table td {
        color: #111 !important;
        border: 1px solid #bbb !important;
        background: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    @page {
        margin: 12.7mm;
    }
}

/* User color choices (Settings > Appearance > Custom colors).
   These rules only match when the user has picked that color, so the theme's own colors are unchanged otherwise. */
:root[style*="--user-card-bg"] .card,
:root[style*="--user-card-bg"] .dashboard-card,
:root[style*="--user-card-bg"] .settings-section,
:root[style*="--user-card-bg"] .modal-content,
:root[style*="--user-card-bg"] .dropdown-menu {
    background-color: var(--user-card-bg);
}

:root[style*="--user-table-line"] .admin-main table {
    --bs-table-border-color: var(--user-table-line);
}

:root[style*="--user-table-line"] .admin-main table th,
:root[style*="--user-table-line"] .admin-main table td {
    border-color: var(--user-table-line);
}
