/* ==========================================================================
   SmallStack Component Styles
   ==========================================================================
   This file provides consistent styling for all SmallStack UI components.
   It sits between theme.css (variables) and per-page templates, ensuring
   that plain HTML tables, forms, pagination, etc. look correct in any theme
   without requiring per-page CSS overrides.

   Load order: admin/base.css → theme.css → palettes.css → components.css
   ========================================================================== */


/* --------------------------------------------------------------------------
   HTMX Swap Transitions
   --------------------------------------------------------------------------
   Fade-out on swap, fade-in on settle. Requires hx-swap="… swap:150ms" so
   the htmx-swapping class stays long enough for the CSS transition.
   -------------------------------------------------------------------------- */

#crud-display-area {
    transition: opacity 150ms ease;
}

#crud-display-area.htmx-swapping {
    opacity: 0;
}


/* --------------------------------------------------------------------------
   Stable Table Height
   --------------------------------------------------------------------------
   Uses --paginate-by CSS custom property (set on #crud-display-area via
   template) to keep the container at a consistent min-height regardless
   of how many rows the current page has. Only applies when a .crud-table
   is present (cards are excluded).
   -------------------------------------------------------------------------- */

#crud-display-area:has(.crud-table) {
    min-height: calc(7.7rem + var(--paginate-by, 0) * 2.7rem);
}


/* --------------------------------------------------------------------------
   Tables
   --------------------------------------------------------------------------
   Use class="crud-table" on any <table> for themed styling.
   Also applies baseline styling to all tables within .main-content to catch
   plain <table> elements written without a class.
   -------------------------------------------------------------------------- */

.crud-table,
.table-plain,
.main-content table {
    width: 100%;
    border-collapse: collapse;
}

/* Fixed layout: column widths determined by header row only, immune to content changes */
.crud-table {
    table-layout: fixed;
}

.crud-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Checkbox and actions columns should never truncate */
.crud-table td:has(.bulk-select-row),
.crud-table td.crud-actions-cell {
    overflow: visible;
    text-overflow: clip;
}

/* Reset inherited admin/tables2 backgrounds */
.crud-table tr:nth-child(odd),
.crud-table tr:nth-child(even),
.table-plain tr:nth-child(odd),
.table-plain tr:nth-child(even),
.main-content table tr:nth-child(odd),
.main-content table tr:nth-child(even) {
    background: transparent;
}

/* Table headers */
.crud-table thead tr,
.table-plain thead tr,
.main-content table thead tr {
    background-color: color-mix(in srgb, var(--primary) 15%, var(--body-bg)) !important;
    border: none !important;
}

.crud-table thead th,
.table-plain thead th,
.main-content table thead th {
    text-transform: uppercase;
    font-size: 0.8rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    padding: 10px 16px;
    border: none !important;
    background-color: transparent !important;
    color: var(--body-quiet-color) !important;
    text-align: left;
}

/* Table body rows */
.crud-table tbody tr,
.table-plain tbody tr,
.main-content table tbody tr {
    border: none !important;
}

.crud-table tbody tr:nth-child(odd),
.table-plain tbody tr:nth-child(odd),
.main-content table tbody tr:nth-child(odd) {
    background-color: color-mix(in srgb, var(--primary) 4%, var(--body-bg)) !important;
}

.crud-table tbody tr:nth-child(even),
.table-plain tbody tr:nth-child(even),
.main-content table tbody tr:nth-child(even) {
    background-color: color-mix(in srgb, var(--primary) 12%, var(--body-bg)) !important;
}

.crud-table tbody td,
.crud-table tbody th,
.table-plain tbody td,
.table-plain tbody th,
.main-content table tbody td,
.main-content table tbody th {
    border: none !important;
    padding: 10px 16px;
    font-size: 0.85rem;
    text-align: left;
}

.crud-table tbody tr:hover,
.table-plain tbody tr:hover,
.main-content table tbody tr:hover {
    background-color: color-mix(in srgb, var(--primary) 20%, var(--body-bg)) !important;
}

/* Table links */
.crud-table a,
.table-plain a,
.main-content table a {
    color: var(--primary);
    text-decoration: none;
}

.crud-table a:hover,
.table-plain a:hover,
.main-content table a:hover {
    text-decoration: underline;
}

/* Table action cells */
.crud-actions-cell {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.crud-action-delete {
    color: var(--delete-button-bg, #dc3545) !important;
}


/* --------------------------------------------------------------------------
   django-tables2 Sort Indicators
   -------------------------------------------------------------------------- */

.crud-table thead th a {
    color: var(--body-quiet-color);
    text-decoration: none;
}

.crud-table thead th a:hover {
    color: var(--primary);
}

.crud-table thead th.asc a::after {
    content: " \25B2";
    font-size: 0.65rem;
}

.crud-table thead th.desc a::after {
    content: " \25BC";
    font-size: 0.65rem;
}


/* --------------------------------------------------------------------------
   Pagination
   --------------------------------------------------------------------------
   Handles both CRUDView's custom pagination and django-tables2's <ul>.
   -------------------------------------------------------------------------- */

.table-container .pagination,
.table-container ul.pagination,
ul.pagination {
    display: flex;
    justify-content: center;
    gap: 0.25rem;
    list-style: none !important;
    padding: 1rem 0 0 !important;
    margin: 0 !important;
}

.table-container .pagination li,
.table-container ul.pagination li,
ul.pagination li {
    list-style: none !important;
}

.table-container .pagination li a,
.table-container .pagination li span,
.table-container ul.pagination li a,
.table-container ul.pagination li span,
ul.pagination li a,
ul.pagination li span {
    display: inline-block;
    padding: 0.3rem 0.75rem;
    border-radius: var(--radius-sm, 4px);
    color: var(--body-quiet-color);
    text-decoration: none;
    font-size: 0.85rem;
}

.table-container .pagination li a:hover,
.table-container ul.pagination li a:hover,
ul.pagination li a:hover {
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 10%, var(--body-bg));
    text-decoration: none;
}

.table-container .pagination li.active a,
.table-container .pagination li.active span,
.table-container ul.pagination li.active a,
.table-container ul.pagination li.active span,
ul.pagination li.active a,
ul.pagination li.active span {
    background: var(--primary);
    color: var(--button-fg);
    text-decoration: none;
}


/* --------------------------------------------------------------------------
   Bare Element Defaults (inside .content-wrapper)
   --------------------------------------------------------------------------
   Ensure that plain HTML elements dropped into block content look themed
   without requiring specific CSS classes. A developer writing <button>,
   <input>, <select>, or <label> should get reasonable SmallStack styling
   out of the box. Class-based components (.btn-primary, .crud-form, etc.)
   provide more refined styling and should be preferred.
   -------------------------------------------------------------------------- */

/* Buttons: use :where() for zero specificity so any class (.btn-primary,
   .tab-btn, .filter-toggle, .crud-modal-btn-*, etc.) naturally overrides. */
:where(.content-wrapper) button,
:where(.content-wrapper) input[type="submit"],
:where(.content-wrapper) input[type="button"] {
    background: var(--primary);
    color: var(--button-fg);
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    transition: background 0.15s;
}

:where(.content-wrapper) button:hover,
:where(.content-wrapper) input[type="submit"]:hover,
:where(.content-wrapper) input[type="button"]:hover {
    background: var(--primary-hover);
}

/* Form inputs: use :where() so .crud-form rules (higher specificity) override. */
:where(.content-wrapper) input[type="text"],
:where(.content-wrapper) input[type="email"],
:where(.content-wrapper) input[type="url"],
:where(.content-wrapper) input[type="number"],
:where(.content-wrapper) input[type="password"],
:where(.content-wrapper) input[type="date"],
:where(.content-wrapper) input[type="datetime-local"],
:where(.content-wrapper) input[type="tel"],
:where(.content-wrapper) input[type="search"],
:where(.content-wrapper) select,
:where(.content-wrapper) textarea {
    width: 100%;
    min-height: var(--control-height, 36px);
    padding: 0.7rem 0.9rem;
    font-size: 0.9rem;
    border: 1px solid color-mix(in srgb, var(--body-fg) 20%, var(--body-bg));
    border-radius: var(--radius-sm, 6px);
    background: color-mix(in srgb, var(--body-fg) 5%, var(--body-bg));
    color: var(--body-fg);
    transition: border-color 0.15s;
    box-sizing: border-box;
}

:where(.content-wrapper) input::placeholder,
:where(.content-wrapper) textarea::placeholder {
    color: var(--body-quiet-color);
    opacity: 0.6;
}

:where(.content-wrapper) input:focus,
:where(.content-wrapper) select:focus,
:where(.content-wrapper) textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 20%, transparent);
}

:where(.content-wrapper) textarea {
    min-height: 120px;
    resize: vertical;
}

:where(.content-wrapper) select {
    appearance: auto;
    min-height: var(--control-height, 36px);
}

:where(.content-wrapper) input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--primary);
}

:where(.content-wrapper) input[type="file"] {
    width: 100%;
    padding: 0.5rem;
    font-size: 0.85rem;
    border: 1px dashed color-mix(in srgb, var(--body-fg) 20%, var(--body-bg));
    border-radius: var(--radius-sm, 6px);
    background: color-mix(in srgb, var(--body-fg) 3%, var(--body-bg));
    color: var(--body-fg);
    cursor: pointer;
}

:where(.content-wrapper) input[type="file"]:hover {
    border-color: var(--primary);
}

:where(.content-wrapper) input[type="file"]::file-selector-button {
    background: var(--primary);
    color: var(--button-fg);
    border: none;
    border-radius: var(--radius-sm, 4px);
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    margin-right: 0.75rem;
    transition: background 0.15s;
}

:where(.content-wrapper) input[type="file"]::file-selector-button:hover {
    background: var(--primary-hover);
}

:where(.content-wrapper) label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--body-fg);
}

[data-theme="dark"] :where(.content-wrapper) select {
    color-scheme: dark;
}

[data-theme="dark"] :where(.content-wrapper) select option {
    background: var(--card-bg);
    color: var(--body-fg);
}


/* --------------------------------------------------------------------------
   Forms
   --------------------------------------------------------------------------
   Use class="crud-form" on <form> elements for more refined form styling
   with field grouping, help text, error states, and layout.
   -------------------------------------------------------------------------- */

.crud-form .crud-field {
    margin-bottom: 1.5rem;
}

.crud-form .crud-label {
    display: block;
    margin-bottom: 0.4rem;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--body-fg);
}

.crud-form .crud-label .required {
    color: var(--delete-button-bg, #dc3545);
    margin-left: 0.15rem;
}

.crud-form .crud-help {
    color: var(--body-quiet-color);
    font-size: 0.8rem;
    margin-top: 0.35rem;
    line-height: 1.4;
}

.crud-form .crud-error {
    color: var(--delete-button-bg, #dc3545);
    font-size: 0.8rem;
    margin-top: 0.35rem;
}

/* Text inputs, selects, textareas */
.crud-form input[type="text"],
.crud-form input[type="email"],
.crud-form input[type="url"],
.crud-form input[type="number"],
.crud-form input[type="password"],
.crud-form input[type="date"],
.crud-form input[type="datetime-local"],
.crud-form input[type="tel"],
.crud-form input[type="search"],
.crud-form select,
.crud-form textarea {
    width: 100%;
    min-height: var(--control-height, 36px);
    padding: 0.7rem 0.9rem;
    font-size: 0.9rem;
    border: 1px solid color-mix(in srgb, var(--body-fg) 20%, var(--body-bg));
    border-radius: var(--radius-sm, 6px);
    background: color-mix(in srgb, var(--body-fg) 5%, var(--body-bg));
    color: var(--body-fg);
    transition: border-color 0.15s;
    box-sizing: border-box;
}

.crud-form input::placeholder,
.crud-form textarea::placeholder {
    color: var(--body-quiet-color);
    opacity: 0.6;
}

.crud-form input:focus,
.crud-form select:focus,
.crud-form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 20%, transparent);
}

.crud-form textarea {
    min-height: 120px;
    resize: vertical;
}

/* Select dropdowns */
.crud-form select {
    appearance: auto;
    min-height: var(--control-height, 36px);
    color-scheme: dark light;
}

[data-theme="dark"] .crud-form select {
    color-scheme: dark;
}

[data-theme="dark"] .crud-form select option {
    background: var(--card-bg);
    color: var(--body-fg);
}

/* Checkboxes */
.crud-form .crud-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0;
}

.crud-form .crud-checkbox input[type="checkbox"] {
    width: 1.1rem;
    height: 1.1rem;
    accent-color: var(--primary);
}

.crud-form .crud-checkbox label {
    font-weight: 400;
    cursor: pointer;
}

/* File inputs */
.crud-form input[type="file"] {
    width: 100%;
    padding: 0.5rem;
    font-size: 0.85rem;
    border: 1px dashed color-mix(in srgb, var(--body-fg) 20%, var(--body-bg));
    border-radius: var(--radius-sm, 6px);
    background: color-mix(in srgb, var(--body-fg) 3%, var(--body-bg));
    color: var(--body-fg);
    cursor: pointer;
}

.crud-form input[type="file"]:hover {
    border-color: var(--primary);
}

.crud-form input[type="file"]::file-selector-button {
    background: var(--primary);
    color: var(--button-fg);
    border: none;
    border-radius: var(--radius-sm, 4px);
    padding: 0.4rem 1rem;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    margin-right: 0.75rem;
    transition: background 0.15s;
}

.crud-form input[type="file"]::file-selector-button:hover {
    background: var(--primary-hover);
}

/* Image preview */
.crud-form .crud-image-preview {
    margin-bottom: 0.5rem;
}

.crud-form .crud-image-preview img {
    max-width: 120px;
    max-height: 120px;
    border-radius: var(--radius-sm, 6px);
    border: 1px solid color-mix(in srgb, var(--body-fg) 15%, var(--body-bg));
}

/* Error state */
.crud-form .crud-field.has-error input,
.crud-form .crud-field.has-error select,
.crud-form .crud-field.has-error textarea {
    border-color: var(--delete-button-bg, #dc3545);
}

/* Form row — side-by-side fields */
.crud-form .crud-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

@media (max-width: 600px) {
    .crud-form .crud-row {
        grid-template-columns: 1fr;
    }
}

/* Form actions */
.crud-form .crud-actions {
    margin-top: 2rem;
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.crud-form .crud-actions .btn-save {
    background: var(--primary);
    color: var(--button-fg);
    padding: 0.6rem 2rem;
    border: none;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
}

.crud-form .crud-actions .btn-save:hover {
    background: var(--primary-hover);
}

.crud-form .crud-actions .btn-cancel {
    padding: 0.6rem 1.5rem;
    color: var(--body-quiet-color);
    text-decoration: none;
    font-size: 0.9rem;
}

.crud-form .crud-actions .btn-cancel:hover {
    color: var(--body-fg);
}

/* --------------------------------------------------------------------------
   Grid Form Layout (label left, field right — matches detail grid)
   --------------------------------------------------------------------------
   Add class="crud-form-grid" alongside "crud-form" to switch from stacked
   to a two-column grid where labels sit left and inputs sit right, matching
   the detail grid display pattern.
   -------------------------------------------------------------------------- */

.crud-form-grid {
    border: 1px solid color-mix(in srgb, var(--body-fg) 12%, var(--body-bg));
    border-radius: var(--radius-sm, 6px);
    overflow: hidden;
}

.crud-form-grid .crud-field {
    display: grid;
    grid-template-columns: minmax(140px, 0.35fr) 1fr;
    border-bottom: 1px solid color-mix(in srgb, var(--body-fg) 12%, var(--body-bg));
    margin-bottom: 0;
}

.crud-form-grid .crud-field:last-of-type {
    border-bottom: none;
}

.crud-form-grid .crud-field-label {
    padding: 0.7rem 0.9rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--body-fg);
    background: color-mix(in srgb, var(--body-fg) 5%, var(--body-bg));
    border-right: 1px solid color-mix(in srgb, var(--body-fg) 12%, var(--body-bg));
    display: flex;
    align-items: center;
}

.crud-form-grid .crud-field-label .required {
    color: var(--delete-button-bg, #dc3545);
    margin-left: 0.15rem;
}

.crud-form-grid .crud-field-input {
    padding: 0.5rem 0.9rem;
    background: color-mix(in srgb, var(--body-fg) 2%, var(--body-bg));
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.25rem;
}

.crud-form-grid .crud-field-input input[type="text"],
.crud-form-grid .crud-field-input input[type="email"],
.crud-form-grid .crud-field-input input[type="url"],
.crud-form-grid .crud-field-input input[type="number"],
.crud-form-grid .crud-field-input input[type="password"],
.crud-form-grid .crud-field-input input[type="date"],
.crud-form-grid .crud-field-input input[type="datetime-local"],
.crud-form-grid .crud-field-input input[type="tel"],
.crud-form-grid .crud-field-input input[type="search"],
.crud-form-grid .crud-field-input select,
.crud-form-grid .crud-field-input textarea {
    width: 100%;
    box-sizing: border-box;
}

.crud-form-grid .crud-field-input .crud-checkbox {
    padding: 0.2rem 0;
}

.crud-form-grid .crud-field.has-error .crud-field-label {
    color: var(--delete-button-bg, #dc3545);
}

@media (max-width: 600px) {
    .crud-form-grid .crud-field {
        grid-template-columns: 1fr;
    }
    .crud-form-grid .crud-field-label {
        border-right: none;
        border-bottom: 1px solid color-mix(in srgb, var(--body-fg) 12%, var(--body-bg));
    }
}


/* Date/datetime input wrapper */
.crud-date-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.crud-date-wrapper input {
    padding-right: 2.8rem !important;
}

.crud-date-btn {
    position: absolute;
    right: 8px;
    background: none;
    border: none;
    color: var(--body-quiet-color);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    border-radius: 4px;
    transition: color 0.15s;
}

.crud-date-btn:hover {
    color: var(--primary);
}

.crud-date-wrapper input::-webkit-calendar-picker-indicator {
    display: none;
}


/* --------------------------------------------------------------------------
   Field Preview (truncated text modal)
   -------------------------------------------------------------------------- */

.field-preview-trigger {
    cursor: pointer;
}

.field-preview-trigger:hover {
    color: var(--primary);
}

.field-preview-more {
    display: inline-block;
    margin-left: 3px;
    padding: 0 5px;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 1px;
    line-height: 1.5;
    vertical-align: middle;
    border-radius: 3px;
    background: color-mix(in srgb, var(--primary) 15%, var(--body-bg));
    color: var(--primary);
    transition: background 0.15s;
}

.field-preview-trigger:hover .field-preview-more {
    background: color-mix(in srgb, var(--primary) 30%, var(--body-bg));
}

.field-preview-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.field-preview-overlay.open {
    display: flex;
}

.field-preview-panel {
    width: min(680px, 90vw);
    height: min(520px, 80vh);
    display: flex;
    flex-direction: column;
    background: var(--card-bg, var(--body-bg));
    border: 1px solid var(--card-border, color-mix(in srgb, var(--body-fg) 10%, var(--body-bg)));
    border-radius: var(--radius-md, 8px);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.field-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    border-bottom: 1px solid color-mix(in srgb, var(--body-fg) 10%, var(--body-bg));
    flex-shrink: 0;
    background: color-mix(in srgb, var(--primary) 8%, var(--body-bg));
}

.field-preview-tabs {
    display: flex;
    gap: 2px;
}

.field-preview-tab {
    padding: 5px 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--body-quiet-color);
    border: none;
    background: none;
    cursor: pointer;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.field-preview-tab:hover {
    color: var(--body-fg);
    background: color-mix(in srgb, var(--body-fg) 8%, transparent);
}

.field-preview-tab.active {
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 15%, var(--body-bg));
}

.field-preview-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.field-preview-copy {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--body-quiet-color);
    border: 1px solid color-mix(in srgb, var(--body-fg) 15%, var(--body-bg));
    border-radius: 4px;
    background: none;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}

.field-preview-copy:hover {
    color: var(--primary);
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 8%, transparent);
}

.field-preview-copy.copied {
    color: var(--success-fg, #22863a);
    border-color: var(--success-fg, #22863a);
}

[data-theme="dark"] .field-preview-copy.copied {
    color: var(--success-fg, #85e89d);
    border-color: var(--success-fg, #85e89d);
}

.field-preview-close {
    border: none;
    background: none;
    color: var(--body-quiet-color);
    cursor: pointer;
    padding: 2px 6px;
    font-size: 1.3rem;
    line-height: 1;
    transition: color 0.15s;
}

.field-preview-close:hover {
    color: var(--body-fg);
}

.field-preview-content {
    padding: 16px 20px;
    font-size: 0.85rem;
    line-height: 1.6;
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

.field-preview-content pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.82rem;
    font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
    line-height: 1.6;
}

/* JSON syntax highlighting */
.field-preview-content .json-key { color: var(--primary); }
.field-preview-content .json-str { color: #22863a; }
.field-preview-content .json-num { color: #005cc5; }
.field-preview-content .json-bool { color: #d73a49; }
.field-preview-content .json-null { color: var(--body-quiet-color); }

[data-theme="dark"] .field-preview-content .json-str { color: #85e89d; }
[data-theme="dark"] .field-preview-content .json-num { color: #79b8ff; }
[data-theme="dark"] .field-preview-content .json-bool { color: #f97583; }

/* Markdown preview */
.field-preview-content .md-preview h1,
.field-preview-content .md-preview h2,
.field-preview-content .md-preview h3 {
    margin: 0.8em 0 0.4em;
    font-weight: 700;
    color: var(--body-fg);
}

.field-preview-content .md-preview h1 { font-size: 1.25em; }
.field-preview-content .md-preview h2 { font-size: 1.1em; }
.field-preview-content .md-preview h3 { font-size: 1em; }

.field-preview-content .md-preview p {
    margin: 0.4em 0;
}

.field-preview-content .md-preview code {
    background: color-mix(in srgb, var(--body-fg) 8%, var(--body-bg));
    padding: 2px 5px;
    border-radius: 3px;
    font-size: 0.9em;
    font-family: ui-monospace, "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;
}

.field-preview-content .md-preview ul,
.field-preview-content .md-preview ol {
    padding-left: 1.5em;
    margin: 0.4em 0;
}

.field-preview-content .md-preview li {
    margin: 0.15em 0;
}

.field-preview-content .md-preview blockquote {
    margin: 0.5em 0;
    padding: 0.4em 0.8em;
    border-left: 3px solid var(--primary);
    color: var(--body-quiet-color);
    background: color-mix(in srgb, var(--primary) 5%, var(--body-bg));
    border-radius: 0 4px 4px 0;
}

.field-preview-content .md-preview a {
    color: var(--primary);
    text-decoration: none;
}

.field-preview-content .md-preview a:hover {
    text-decoration: underline;
}


/* --------------------------------------------------------------------------
   Modals
   -------------------------------------------------------------------------- */

.crud-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(2px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.crud-modal {
    background: var(--card-bg);
    border: 1px solid var(--card-border, color-mix(in srgb, var(--body-fg) 10%, var(--body-bg)));
    border-radius: var(--radius-md, 8px);
    width: 90%;
    max-width: 420px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    overflow: hidden;
}

.crud-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid color-mix(in srgb, var(--body-fg) 10%, var(--body-bg));
    background: color-mix(in srgb, var(--primary) 8%, var(--body-bg));
}

.crud-modal-body {
    padding: 16px;
}

.crud-modal-close {
    border: none;
    background: none;
    color: var(--body-quiet-color);
    cursor: pointer;
    font-size: 1.3rem;
    line-height: 1;
    padding: 2px 6px;
}

.crud-modal-close:hover {
    color: var(--body-fg);
}


/* --------------------------------------------------------------------------
   Tabs
   -------------------------------------------------------------------------- */

.tab-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--hairline-color, color-mix(in srgb, var(--body-fg) 10%, var(--body-bg)));
    margin-bottom: 1rem;
}

.tab-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--body-quiet-color);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
    border-radius: var(--radius-sm, 4px) var(--radius-sm, 4px) 0 0;
}

.tab-btn:hover {
    color: var(--body-fg);
    background-color: color-mix(in srgb, var(--body-fg) 5%, transparent);
}

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

.tab-count {
    display: inline-block;
    padding: 1px 7px;
    border-radius: 10px;
    background: color-mix(in srgb, var(--primary) 15%, var(--card-bg, var(--body-bg)));
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 0.3rem;
}

.tab-panel {
    display: none;
}

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

/* View switcher — larger variant for top-level section switching */

.view-bar {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--hairline-color, color-mix(in srgb, var(--body-fg) 10%, var(--body-bg)));
    margin-bottom: 0;
}

.view-btn {
    padding: 12px 24px;
    background: none;
    border: none;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--body-quiet-color);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
    border-radius: var(--radius-sm, 4px) var(--radius-sm, 4px) 0 0;
}

.view-btn:hover {
    color: var(--body-fg);
    background-color: color-mix(in srgb, var(--body-fg) 5%, transparent);
}

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

.view-panel {
    display: none;
}

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


/* --------------------------------------------------------------------------
   Badges / Pills
   -------------------------------------------------------------------------- */

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.badge-success {
    background: color-mix(in srgb, var(--success-fg, #22863a) 15%, var(--body-bg));
    color: var(--success-fg, #22863a);
}

.badge-warning {
    background: color-mix(in srgb, var(--warning-fg, #b08800) 15%, var(--body-bg));
    color: var(--warning-fg, #b08800);
}

.badge-error {
    background: color-mix(in srgb, var(--error-fg, #dc3545) 15%, var(--body-bg));
    color: var(--error-fg, #dc3545);
}

.badge-info {
    background: color-mix(in srgb, var(--primary) 15%, var(--body-bg));
    color: var(--primary);
}


/* --------------------------------------------------------------------------
   Page Header / Title Bar
   -------------------------------------------------------------------------- */

.page-header {
    background: color-mix(in srgb, var(--primary) 15%, var(--body-bg));
    margin: -24px -24px 24px -24px;
    padding: 24px;
    border-radius: 8px 8px 0 0;
}

.page-header-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--body-fg);
    margin: 0;
}

.page-header-subtitle {
    font-size: 0.9rem;
    color: var(--body-quiet-color);
    margin-top: 0.25rem;
}

.page-header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.page-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
}


/* --------------------------------------------------------------------------
   Stat Cards
   -------------------------------------------------------------------------- */

.stat-cards {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.stat-card {
    flex: 1;
    min-width: 120px;
    padding: 1rem;
    text-align: center;
    border: 1px solid color-mix(in srgb, var(--primary) 15%, var(--body-bg));
    border-radius: var(--radius-md, 8px);
    background: color-mix(in srgb, var(--primary) 4%, var(--body-bg));
}

.stat-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-card-label {
    font-size: 0.75rem;
    color: var(--body-quiet-color);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-top: 0.25rem;
}


/* --------------------------------------------------------------------------
   Search Bar
   -------------------------------------------------------------------------- */

.search-input {
    width: 100%;
    max-width: 400px;
    padding: 0.5rem 0.75rem 0.5rem 2.2rem;
    font-size: 0.85rem;
    border: 1px solid color-mix(in srgb, var(--body-fg) 20%, var(--body-bg));
    border-radius: var(--radius-sm, 4px);
    background: color-mix(in srgb, var(--body-fg) 5%, var(--body-bg));
    color: var(--body-fg);
    transition: border-color 0.15s;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='16' height='16' fill='%23888'%3E%3Cpath d='M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: 0.65rem center;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 20%, transparent);
}

.search-input::placeholder {
    color: var(--body-quiet-color);
    opacity: 0.6;
}


/* --------------------------------------------------------------------------
   Buttons (extending Django admin's .button class)
   -------------------------------------------------------------------------- */

.btn-primary,
a.btn-primary:link,
a.btn-primary:visited {
    background: var(--primary);
    color: var(--button-fg);
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    display: inline-block;
    box-sizing: border-box;
    font-family: inherit;
    transition: background 0.15s;
}

.btn-primary:hover {
    background: var(--primary-hover);
    color: var(--button-fg);
    text-decoration: none;
}

.btn-outline,
a.btn-outline:link,
a.btn-outline:visited {
    background: transparent;
    color: var(--body-quiet-color);
    padding: 0.5rem 1rem;
    border: 1px solid color-mix(in srgb, var(--body-fg) 20%, var(--body-bg));
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    display: inline-block;
    transition: border-color 0.15s, color 0.15s;
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
    text-decoration: none;
}

.btn-danger,
a.btn-danger:link,
a.btn-danger:visited {
    background: var(--delete-button-bg, #dc3545);
    color: #fff;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    line-height: 1.2;
    text-decoration: none;
    display: inline-block;
    box-sizing: border-box;
    font-family: inherit;
}

.btn-danger:hover {
    opacity: 0.9;
}

.btn-secondary,
a.btn-secondary:link,
a.btn-secondary:visited {
    background: color-mix(in srgb, var(--primary) 15%, var(--body-bg));
    color: var(--primary);
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius-sm, 6px);
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    display: inline-block;
    transition: background 0.15s;
}

.btn-secondary:hover {
    background: color-mix(in srgb, var(--primary) 25%, var(--body-bg));
    color: var(--primary);
    text-decoration: none;
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}


/* --------------------------------------------------------------------------
   Action Cards (icon + label, used in page headers)
   -------------------------------------------------------------------------- */

.action-cards {
    display: flex;
    gap: 12px;
    align-items: stretch;
}

.action-card {
    border: 2px solid color-mix(in srgb, var(--primary) 30%, transparent);
    border-radius: var(--radius-md, 8px);
    background: var(--card-bg, var(--body-bg));
    min-width: 160px;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.action-card:hover {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 8%, var(--card-bg, var(--body-bg)));
}

.action-card-body {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
}

.action-card-icon {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
    fill: var(--primary);
}

.action-card-title {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--primary);
}

.action-card-subtitle {
    color: var(--body-quiet-color);
    font-size: 0.75rem;
}

/* Color variants */
.action-card-success {
    border-color: color-mix(in srgb, var(--success-fg) 40%, transparent);
}

.action-card-success:hover {
    border-color: var(--success-fg);
    background: color-mix(in srgb, var(--success-fg) 6%, var(--card-bg, var(--body-bg)));
}

.action-card-success .action-card-icon { fill: var(--success-fg); }
.action-card-success .action-card-title { color: var(--success-fg); }

.action-card-danger {
    border-color: color-mix(in srgb, var(--delete-button-bg, #dc3545) 40%, transparent);
}

.action-card-danger:hover {
    border-color: var(--delete-button-bg, #dc3545);
    background: color-mix(in srgb, var(--delete-button-bg, #dc3545) 6%, var(--card-bg, var(--body-bg)));
}

.action-card-danger .action-card-icon { fill: var(--delete-button-bg, #dc3545); }
.action-card-danger .action-card-title { color: var(--delete-button-bg, #dc3545); }

/* Non-clickable status variant */
.action-card-static {
    cursor: default;
}


/* --------------------------------------------------------------------------
   Filter Toggles (small pill buttons for inline filtering)
   -------------------------------------------------------------------------- */

.filter-toggles {
    display: flex;
    gap: 4px;
}

.filter-toggle {
    padding: 4px 10px;
    font-size: 0.75rem;
    font-weight: 500;
    border: 1px solid color-mix(in srgb, var(--body-fg) 20%, var(--body-bg));
    border-radius: var(--radius-sm, 4px);
    background: var(--card-bg, var(--body-bg));
    color: var(--body-fg);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.filter-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.filter-toggle.active {
    background: color-mix(in srgb, var(--primary) 15%, var(--body-bg));
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}


/* --------------------------------------------------------------------------
   Utility: uppercase label
   -------------------------------------------------------------------------- */

.label-upper {
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--body-quiet-color);
}


/* --------------------------------------------------------------------------
   Card Grid Display (generic — peer to TableDisplay)
   -------------------------------------------------------------------------- */

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

.card-grid-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.9rem;
    padding: 1rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm, 6px);
    text-decoration: none;
    color: inherit;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s, background 0.15s;
}

.card-grid-item:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
    transform: translateY(-1px);
}

/* Selected state (bulk checkbox checked) — uses :has() */
.card-grid-item:has(.bulk-select-row:checked) {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 8%, var(--card-bg));
}

.card-grid-check {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 1;
}

.card-grid-check input { cursor: pointer; }

.card-grid-avatar {
    flex: 0 0 56px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    overflow: hidden;
    background: color-mix(in srgb, var(--primary) 15%, var(--body-bg));
    border: 1px solid color-mix(in srgb, var(--primary) 25%, var(--body-bg));
    display: flex;
    align-items: center;
    justify-content: center;
}

.card-grid-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.card-grid-initials {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: 0.03em;
}

.card-grid-body {
    flex: 1;
    min-width: 0;
}

.card-grid-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--body-fg);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-grid-subtitle {
    font-size: 0.78rem;
    color: var(--body-quiet-color);
    margin-top: 0.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.card-grid-pill {
    display: inline-flex;
    align-items: baseline;
    gap: 0.3rem;
    margin-top: 0.5rem;
    padding: 0.15rem 0.5rem;
    background: color-mix(in srgb, var(--primary) 8%, var(--body-bg));
    border: 1px solid color-mix(in srgb, var(--primary) 15%, var(--body-bg));
    border-radius: var(--radius-sm, 4px);
}

.card-grid-pill-value {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
}

.card-grid-pill-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--body-quiet-color);
}

/* Key-value card variant — stacks label:value rows under the title */
.card-grid-item--keyvalue {
    align-items: stretch;
}

.card-grid-item--keyvalue .card-grid-title {
    padding-bottom: 0.4rem;
    margin-bottom: 0.4rem;
    border-bottom: 1px solid var(--hairline-color);
}

.card-grid-rows {
    margin: 0;
    display: grid;
    gap: 0.25rem;
}

.card-grid-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.75rem;
}

.card-grid-row-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--body-quiet-color);
    margin: 0;
    flex-shrink: 0;
}

.card-grid-row-value {
    font-size: 0.8rem;
    color: var(--body-fg);
    margin: 0;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}


/* --------------------------------------------------------------------------
   Calendar Display (month grid)
   --------------------------------------------------------------------------
   Generic month-grid layout. Events render as chips placed on their date
   cell. Used by CalendarDisplay for any model with a date/datetime field.
   -------------------------------------------------------------------------- */

.calendar-display {
    background: var(--card-bg, var(--body-bg));
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm, 6px);
    overflow: hidden;
}

.calendar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.65rem 1rem;
    background: color-mix(in srgb, var(--body-fg) 4%, var(--body-bg));
    border-bottom: 1px solid var(--hairline-color);
}

.calendar-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.calendar-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm, 4px);
    background: var(--body-bg);
    color: var(--body-fg);
    text-decoration: none;
    font-size: 1.1rem;
    line-height: 1;
    transition: border-color 0.15s, background 0.15s;
}

.calendar-nav-btn:link,
.calendar-nav-btn:visited {
    color: var(--body-fg);
}

.calendar-nav-btn:hover {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 8%, var(--body-bg));
}

.calendar-title {
    margin: 0 0.5rem;
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--body-fg);
}

.calendar-today-btn {
    margin-left: 0.5rem;
    padding: 0.25rem 0.6rem;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm, 4px);
    background: var(--body-bg);
    color: var(--body-quiet-color);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    text-decoration: none;
    transition: border-color 0.15s, color 0.15s;
}

.calendar-today-btn:link,
.calendar-today-btn:visited {
    color: var(--body-quiet-color);
}

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

.calendar-count {
    display: flex;
    align-items: baseline;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    background: color-mix(in srgb, var(--primary) 8%, var(--body-bg));
    border: 1px solid color-mix(in srgb, var(--primary) 15%, var(--body-bg));
    border-radius: var(--radius-sm, 4px);
}

.calendar-count-value {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
}

.calendar-count-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--body-quiet-color);
}

.calendar-weekdays {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    background: color-mix(in srgb, var(--body-fg) 3%, var(--body-bg));
    border-bottom: 1px solid var(--hairline-color);
}

.calendar-weekday {
    padding: 0.4rem 0.5rem;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--body-quiet-color);
    text-align: center;
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: minmax(68px, auto);
}

.calendar-cell {
    position: relative;
    padding: 0.2rem;
    border-right: 1px solid var(--hairline-color);
    border-bottom: 1px solid var(--hairline-color);
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
}

.calendar-cell:nth-child(7n) {
    border-right: none;
}

.calendar-cell--blank {
    background: color-mix(in srgb, var(--body-fg) 2%, var(--body-bg));
}

.calendar-cell--today {
    background: color-mix(in srgb, var(--primary) 6%, var(--body-bg));
}

.calendar-cell-day {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--body-quiet-color);
    padding: 0 0.15rem 0.1rem;
}

.calendar-cell--today .calendar-cell-day {
    color: var(--primary);
    font-weight: 700;
}

.calendar-event {
    position: relative;
    display: block;
    padding: 0.2rem 0.4rem;
    background: color-mix(in srgb, var(--primary) 12%, var(--body-bg));
    border-left: 3px solid var(--primary);
    border-radius: var(--radius-sm, 3px);
    font-size: 0.78rem;
    color: var(--body-fg);
    text-decoration: none;
    transition: background 0.15s;
}

.calendar-event-label {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calendar-event:link,
.calendar-event:visited {
    color: var(--body-fg);
}

.calendar-event:hover {
    background: color-mix(in srgb, var(--primary) 22%, var(--body-bg));
    z-index: 2;
}

/* Status modifiers — muted green/yellow/red tint based on event outcome.
   Uses the theme's paired alert vars which are designed for light/dark legibility.
   :link/:visited selectors are required to beat the global a:visited color rule. */
.calendar-event--success,
.calendar-event--success:link,
.calendar-event--success:visited {
    background: var(--success-bg);
    border-left-color: var(--success-fg);
    color: var(--success-fg);
}

.calendar-event--success:hover {
    background: color-mix(in srgb, var(--success-fg) 25%, var(--success-bg));
}

.calendar-event--warning,
.calendar-event--warning:link,
.calendar-event--warning:visited {
    background: var(--warning-bg);
    border-left-color: var(--warning-fg);
    color: var(--warning-fg);
}

.calendar-event--warning:hover {
    background: color-mix(in srgb, var(--warning-fg) 25%, var(--warning-bg));
}

.calendar-event--danger,
.calendar-event--danger:link,
.calendar-event--danger:visited {
    background: var(--error-bg);
    border-left-color: var(--error-fg);
    color: var(--error-fg);
}

.calendar-event--danger:hover {
    background: color-mix(in srgb, var(--error-fg) 25%, var(--error-bg));
}

/* Block variant — taller cells with one large colored block per day.
   Use for status/stat calendars (e.g. daily uptime), not event lists. */
.calendar-display--block .calendar-grid {
    grid-auto-rows: minmax(90px, auto);
}

.calendar-display--block .calendar-cell {
    padding: 0.3rem;
    gap: 0.25rem;
}

.calendar-display--block .calendar-event {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem 0.5rem;
    border-left-width: 4px;
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.calendar-display--block .calendar-event-label {
    text-align: center;
}

/* Hover detail tooltip */
.calendar-event-tooltip {
    position: absolute;
    left: 0;
    top: 100%;
    margin-top: 4px;
    min-width: 200px;
    max-width: 280px;
    padding: 0.5rem 0.65rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm, 4px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
    font-size: 0.7rem;
    color: var(--body-fg);
    white-space: normal;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity 0.12s, transform 0.12s, visibility 0.12s;
    pointer-events: none;
    z-index: 10;
}

.calendar-event:hover .calendar-event-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.calendar-event-tooltip-title {
    font-weight: 700;
    font-size: 0.75rem;
    margin-bottom: 0.35rem;
    padding-bottom: 0.3rem;
    border-bottom: 1px solid var(--hairline-color);
    color: var(--body-fg);
    white-space: normal;
}

.calendar-event-tooltip-row {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.15rem;
}

.calendar-event-tooltip-label {
    text-transform: uppercase;
    font-size: 0.6rem;
    letter-spacing: 0.03em;
    color: var(--body-quiet-color);
    font-weight: 600;
}

/* Flip tooltip to the left on right-edge cells to avoid overflow */
.calendar-cell:nth-child(7n) .calendar-event-tooltip,
.calendar-cell:nth-child(7n-1) .calendar-event-tooltip {
    left: auto;
    right: 0;
}


/* CRUD page title — uppercase for list & detail headings */
.crud-title {
    text-transform: uppercase;
    letter-spacing: 0.03em;
}


/* --------------------------------------------------------------------------
   List Toolbar (search, filters, display palette)
   --------------------------------------------------------------------------
   Sits inside .card-body above the table/display area. Only renders when
   search_fields or filter_fields are configured on the CRUDView.
   -------------------------------------------------------------------------- */

.list-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 0 0 12px 0;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--hairline-color);
}

/* Search input */
.list-toolbar-search {
    position: relative;
    width: 200px;
    flex-shrink: 1;
    min-width: 140px;
}

.list-toolbar-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary);
    opacity: 0.7;
    pointer-events: none;
    z-index: 1;
}

.list-toolbar-search-input {
    width: 100%;
    height: var(--control-height, 36px);
    min-height: var(--control-height, 36px);
    padding: 0 10px 0 30px !important;
    border: 1px solid color-mix(in srgb, var(--primary) 15%, var(--body-bg)) !important;
    border-radius: var(--radius-sm, 4px) !important;
    background: color-mix(in srgb, var(--primary) 6%, var(--body-bg)) !important;
    color: var(--body-fg) !important;
    font-size: 0.8rem !important;
    font-weight: 500;
    transition: border-color 0.15s, background 0.15s;
    box-sizing: border-box;
}

.list-toolbar-search-input:hover {
    border-color: color-mix(in srgb, var(--primary) 30%, var(--body-bg)) !important;
}

.list-toolbar-search-input:focus {
    border-color: color-mix(in srgb, var(--primary) 45%, var(--body-bg)) !important;
    background: color-mix(in srgb, var(--primary) 10%, var(--body-bg)) !important;
    outline: none;
}

.list-toolbar-search-input:focus + .list-toolbar-search-icon,
.list-toolbar-search:focus-within .list-toolbar-search-icon {
    opacity: 1;
}

.list-toolbar-search-input::placeholder {
    color: var(--body-quiet-color);
    font-weight: 400;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.03em;
}

/* Filter controls — inline with search */
.list-toolbar-filters {
    display: contents;
}

/* Filter wrapper — stat-card style container with inline label */
.list-toolbar-filter {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: var(--control-height, 36px);
    max-width: 220px;
    padding: 0 0.4rem 0 0.6rem;
    border: 1px solid color-mix(in srgb, var(--primary) 15%, var(--body-bg));
    border-radius: var(--radius-sm, 4px);
    background: color-mix(in srgb, var(--primary) 6%, var(--body-bg));
    box-sizing: border-box;
    flex: 0 0 auto;
    transition: border-color 0.15s, background 0.15s;
    cursor: pointer;
    overflow: hidden;
}

.list-toolbar-filter:hover {
    border-color: color-mix(in srgb, var(--primary) 30%, var(--body-bg));
}

.list-toolbar-filter-label {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--body-quiet-color);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
    pointer-events: none;
}

.list-toolbar-filter.is-filtered {
    border-color: color-mix(in srgb, var(--primary) 35%, var(--body-bg));
    background: color-mix(in srgb, var(--primary) 12%, var(--body-bg));
}

.list-toolbar-filter.is-filtered .list-toolbar-filter-label {
    color: var(--primary);
}

/* Select inside wrapper — borderless, transparent */
.list-toolbar-filter .list-toolbar-filter-select {
    height: auto !important;
    min-height: 0 !important;
    padding: 2px 18px 2px 2px !important;
    border: none !important;
    background: transparent !important;
    color: var(--body-fg) !important;
    font-size: 0.8rem !important;
    font-weight: 500;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: linear-gradient(45deg, transparent 50%, var(--body-quiet-color) 50%), linear-gradient(135deg, var(--body-quiet-color) 50%, transparent 50%) !important;
    background-position: calc(100% - 10px) 50%, calc(100% - 6px) 50% !important;
    background-size: 4px 4px, 4px 4px !important;
    background-repeat: no-repeat !important;
    max-width: 100%;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
}

.list-toolbar-filter .list-toolbar-filter-select:focus {
    outline: none !important;
    box-shadow: none !important;
}

/* Bare text filter (no wrapper) */
.list-toolbar-filter-text {
    height: var(--control-height, 36px);
    min-height: var(--control-height, 36px);
    padding: 4px 8px !important;
    border: 1px solid var(--input-border) !important;
    border-radius: var(--radius-sm, 4px) !important;
    background: var(--body-bg) !important;
    color: var(--body-fg) !important;
    font-size: 0.75rem !important;
    transition: border-color 0.15s;
    box-sizing: border-box;
    flex: 0 0 auto;
    width: 140px;
}

.list-toolbar-filter-text:focus {
    border-color: var(--primary) !important;
}

.list-toolbar-filter-text.is-filtered {
    border-left: 3px solid var(--primary) !important;
    background: color-mix(in srgb, var(--primary) 6%, var(--body-bg)) !important;
}

/* Overflow toggle button (4+ filters) */
.list-toolbar-overflow-toggle {
    height: var(--control-height, 36px);
    padding: 4px 10px;
    border: 1px dashed var(--input-border);
    border-radius: var(--radius-sm, 4px);
    background: var(--body-bg);
    color: var(--body-quiet-color);
    font-size: 0.75rem;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color 0.15s, color 0.15s;
}

.list-toolbar-overflow-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.list-toolbar.show-overflow .list-toolbar-overflow-toggle {
    border-color: var(--primary);
    color: var(--primary);
}

/* Overflow panel — hidden by default, 2-col grid */
.list-toolbar-overflow-panel {
    display: none;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 8px;
    padding-top: 10px;
    margin-top: 4px;
    border-top: 1px solid var(--hairline-color);
    width: 100%;
}

.list-toolbar.show-overflow .list-toolbar-overflow-panel {
    display: grid;
}

.list-toolbar-overflow-panel .list-toolbar-filter,
.list-toolbar-overflow-panel .list-toolbar-filter-text {
    width: 100%;
}

.list-toolbar-overflow-panel .list-toolbar-filter .list-toolbar-filter-select {
    flex: 1;
}

/* Spacer pushes right-side content */
.list-toolbar-spacer {
    flex: 1;
}

/* Result count — stat-card style */
.list-toolbar-count {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.75rem;
    background: color-mix(in srgb, var(--primary) 8%, var(--body-bg));
    border: 1px solid color-mix(in srgb, var(--primary) 15%, var(--body-bg));
    border-radius: var(--radius-sm, 4px);
    white-space: nowrap;
}

.list-toolbar-count-value {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--primary);
    line-height: 1;
}

.list-toolbar-count-label {
    font-size: 0.7rem;
    color: var(--body-quiet-color);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Clear button */
.list-toolbar-clear {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 0.75rem;
    color: var(--body-quiet-color);
    text-decoration: none;
    padding: 4px 8px;
    border-radius: var(--radius-sm, 4px);
    white-space: nowrap;
    transition: color 0.15s, background 0.15s;
}

.list-toolbar-clear:hover {
    color: var(--body-fg);
    background: color-mix(in srgb, var(--primary) 10%, var(--body-bg));
}

/* Display palette (in card-header / page-header-actions) */
.display-palette {
    display: inline-flex;
    gap: 0.25rem;
    margin-right: 0.75rem;
}

.display-palette-btn {
    padding: 0.5rem 0.6rem;
    border: 1px solid var(--input-border) !important;
    border-radius: var(--radius-sm, 4px);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    background: var(--card-bg) !important;
    color: var(--body-fg) !important;
    transition: background 0.15s, color 0.15s;
}

.display-palette-btn.active {
    background: var(--primary) !important;
    color: var(--button-fg) !important;
}

.display-palette-btn:hover:not(.active) {
    background: color-mix(in srgb, var(--primary) 15%, var(--body-bg)) !important;
}

/* Responsive: stack on small screens */
@media (max-width: 768px) {
    .list-toolbar {
        flex-wrap: wrap;
    }
    .list-toolbar-search {
        width: 100%;
    }
    .list-toolbar-filters {
        flex-wrap: wrap;
    }
}


/* --------------------------------------------------------------------------
   CRUD Accessories (stat cards above list)
   -------------------------------------------------------------------------- */

.crud-accessories {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.crud-stat-card {
    background: var(--card-bg, var(--body-bg));
    border: 1px solid var(--hairline-color, rgba(128, 128, 128, 0.2));
    border-radius: 8px;
    padding: 16px;
    text-align: center;
}

.crud-stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
    color: var(--primary);
}

.crud-stat-label {
    font-size: 0.75rem;
    color: var(--body-quiet-color);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}


/* --------------------------------------------------------------------------
   Bulk Selection & Actions Bar
   --------------------------------------------------------------------------
   Inline bar between toolbar and table (Django admin style). Hidden by
   default, shown via .visible when rows are selected.
   -------------------------------------------------------------------------- */

.bulk-select-all,
.bulk-select-row {
    appearance: none;
    width: 16px;
    height: 16px;
    border: 1.5px solid color-mix(in srgb, var(--body-fg) 35%, transparent);
    border-radius: 3px;
    background: color-mix(in srgb, var(--body-fg) 10%, var(--body-bg));
    cursor: pointer;
    position: relative;
}

.bulk-select-all:checked,
.bulk-select-row:checked {
    background: var(--primary);
    border-color: var(--primary);
}

.bulk-select-all:checked::after,
.bulk-select-row:checked::after {
    content: "";
    position: absolute;
    left: 4px;
    top: 1px;
    width: 5px;
    height: 9px;
    border: solid var(--body-bg);
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

.crud-table tbody tr.bulk-selected {
    background-color: color-mix(in srgb, var(--primary) 25%, var(--body-bg)) !important;
}

.card-display-item.bulk-selected {
    border-color: var(--primary) !important;
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 30%, transparent) !important;
}

/* Bar layout — left-aligned single line, smooth reveal */
.bulk-actions-bar {
    display: flex;
    justify-content: flex-start;
    overflow: hidden;
    max-height: 0;
    padding: 0;
    opacity: 0;
    transition: max-height 0.2s ease, padding 0.2s ease, opacity 0.15s ease;
}

.bulk-actions-bar.visible {
    max-height: 3rem;
    padding: 0.5rem 0;
    opacity: 1;
}

/* Nav container — mirrors .paginator-nav */
.bulk-nav {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    border: 1px solid var(--hairline-color);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

/* Count — mirrors .paginator-current */
.bulk-nav-current {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0 0.6rem;
    height: 2rem;
    color: var(--body-fg);
    font-weight: 600;
    font-size: 0.85rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.bulk-nav-of {
    font-weight: 400;
    color: var(--body-quiet-color);
}

/* Buttons — mirrors .paginator-btn */
.bulk-nav-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 2rem;
    padding: 0 0.85rem;
    background: none;
    color: var(--body-quiet-color);
    font-size: 0.85rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast, 0.15s);
}

.bulk-nav-btn:hover {
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 10%, var(--body-bg));
}

/* Delete — red text to signal danger */
.bulk-nav-delete {
    color: #dc3545 !important;
    font-weight: 600;
}

.bulk-nav-delete:hover {
    background: color-mix(in srgb, #dc3545 12%, var(--body-bg)) !important;
    color: #c82333 !important;
}


/* --------------------------------------------------------------------------
   Dashboard Widgets
   --------------------------------------------------------------------------
   Grid and card styling for DashboardWidget output. Shared between the
   main /smallstack/ dashboard and the Explorer group/app widget toggle.
   -------------------------------------------------------------------------- */

.dashboard-widget-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

a.dashboard-widget,
a.dashboard-widget:link,
a.dashboard-widget:visited,
a.dashboard-widget:hover,
a.dashboard-widget:active {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    background: color-mix(in srgb, var(--primary) 6%, var(--body-bg));
    border: 1px solid transparent;
    border-radius: var(--radius-sm, 6px);
    padding: 1.25rem;
    text-decoration: none !important;
    color: var(--body-fg) !important;
    transition: border-color 0.15s, background 0.15s;
}

a.dashboard-widget:hover {
    border-color: var(--primary);
    background: color-mix(in srgb, var(--primary) 12%, var(--body-bg));
}

.dashboard-widget .widget-header {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.dashboard-widget .widget-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    background: color-mix(in srgb, var(--primary) 15%, var(--body-bg));
    color: var(--primary);
    flex-shrink: 0;
}

.dashboard-widget .widget-title {
    font-size: 0.85rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--body-quiet-color);
}

.dashboard-widget .widget-headline {
    font-size: 1.25rem;
    font-weight: 600;
    line-height: 1.2;
}

.dashboard-widget .widget-detail {
    font-size: 0.85rem;
    color: var(--body-quiet-color);
}

.dashboard-widget.widget-status-operational .widget-headline { color: var(--success-fg); }
.dashboard-widget.widget-status-degraded .widget-headline { color: var(--warning-fg); }
.dashboard-widget.widget-status-down .widget-headline { color: var(--error-fg); }

.dashboard-widget-span-2 { grid-column: span 2; }
.dashboard-widget-span-3 { grid-column: span 3; }
