/* ============================================================
   CCMAR Components — UI Component Library
   Sleek control panel components
   ============================================================ */

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    line-height: 1;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-default);
    white-space: nowrap;
    user-select: none;
    text-decoration: none;
    height: 34px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* Primary */
.btn-primary {
    background-color: var(--accent);
    color: var(--text-on-accent);
    border-color: var(--accent);
}
.btn-primary:hover {
    background-color: var(--accent-hover);
    border-color: var(--accent-hover);
}

/* Secondary */
.btn-secondary {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border-color: var(--border-primary);
}
.btn-secondary:hover {
    background-color: var(--bg-surface-hover);
    border-color: var(--border-hover);
}

/* Ghost */
.btn-ghost {
    background-color: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}
.btn-ghost:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
}

/* Danger */
.btn-danger {
    background-color: var(--danger);
    color: white;
    border-color: var(--danger);
}
.btn-danger:hover {
    background-color: hsl(0, 84%, 53%);
}

/* Outline */
.btn-outline {
    background-color: transparent;
    color: var(--accent-text);
    border-color: var(--accent);
}
.btn-outline:hover {
    background-color: var(--accent-muted);
}

/* "Unpublished changes" state — amber border ring on a header action button
   (questionnaire builder Publish button when the draft is dirty + studies use
   it). Layered on top of whatever base .btn-* variant the button already has. */
.btn.btn-dirty {
    border: 2px solid var(--warning-text, #e0a800);
    box-shadow: 0 0 0 3px rgba(224, 168, 0, 0.18);
}

/* Icon Button */
.btn-icon {
    width: 34px;
    height: 34px;
    padding: 0;
}

/* Sizes */
.btn-xs {
    height: 24px;
    padding: 0 var(--space-2);
    font-size: var(--text-xs);
}
.btn-sm {
    height: 28px;
    padding: var(--space-1) var(--space-3);
    font-size: var(--text-xs);
}
.btn-lg {
    height: 40px;
    padding: var(--space-3) var(--space-6);
    font-size: var(--text-md);
}

/* Icon-button variant of .btn-xs — overrides .btn-icon's 34px square.
   Sized just slightly larger than the SVG glyph so the click target hugs
   the icon (20px button + 14px glyph → 3px halo on each side). */
.btn-icon.btn-xs {
    width: 20px;
    height: 20px;
    padding: 0;
}


/* ============================================================
   CARDS
   ============================================================ */
/* Compact card style — site-wide standard. Lighter background, smaller
   radius, subdued small title, no header bottom-border. Started as a
   bespoke style on the panel project log; now the global default. */
.card {
    background-color: var(--bg-primary);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.card-header {
    padding: 8px 16px;
    border-bottom: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
}

.card-body {
    padding: var(--space-4);
}

.card-footer {
    padding: var(--space-4) var(--space-5);
    border-top: 1px solid var(--border-secondary);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
}

/* Stat Card */
.stat-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
}

.stat-card-label {
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    margin-bottom: var(--space-2);
}

.stat-card-value {
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    letter-spacing: var(--tracking-tight);
}

.stat-card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xl);
    margin-bottom: var(--space-3);
}

.stat-card-icon.accent  { background: var(--accent-muted); color: var(--accent-text); }
.stat-card-icon.success { background: var(--success-muted); color: var(--success-text); }
.stat-card-icon.warning { background: var(--warning-muted); color: var(--warning-text); }
.stat-card-icon.danger  { background: var(--danger-muted);  color: var(--danger-text); }
.stat-card-icon.info    { background: var(--info-muted);    color: var(--info-text); }


/* ============================================================
   FORMS
   ============================================================ */
.form-group {
    margin-bottom: var(--space-4);
}

.form-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-secondary);
    margin-bottom: var(--space-2);
}

.form-label.required::after {
    content: ' *';
    color: var(--danger-text);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--text-primary);
    background-color: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-md);
    transition: border-color var(--duration-fast) var(--ease-default),
                box-shadow var(--duration-fast) var(--ease-default);
    height: 34px;
    outline: none;
}

.form-textarea {
    height: auto;
    min-height: 80px;
    resize: vertical;
    line-height: var(--leading-normal);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.form-input:disabled,
.form-select:disabled,
.form-textarea:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background-color: var(--bg-surface);
}

/* <select> dropdown <option> elements get their own background+color because
   most browsers ignore the parent <select>'s color/bg for the popup list.
   Pairs with the page-level `color-scheme` in variables.css — between the
   two, the dropdown reads correctly in both light and dark themes across
   Chrome/Firefox/Edge/Safari. */
.form-input option,
.form-select option {
    background-color: var(--bg-input);
    color: var(--text-primary);
}

/* Disabled checkboxes/radios: replace the browser's washed-out default with
   custom rendering so checked vs. unchecked stays clearly visible. Uses
   :where() so component-specific overrides like .form-switch (which keeps
   the native input visually hidden) win naturally without !important. */
:where(input[type="checkbox"]:disabled),
:where(input[type="radio"]:disabled) {
    appearance: none;
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    border: 1.5px solid var(--border-primary);
    background-color: transparent;
    cursor: not-allowed;
    margin: 0;
    flex-shrink: 0;
    vertical-align: middle;
    opacity: 0.9;
}

:where(input[type="checkbox"]:disabled) { border-radius: 3px; }
:where(input[type="radio"]:disabled)    { border-radius: 50%; }

:where(input[type="checkbox"]:disabled:checked) {
    background-color: var(--accent);
    border-color: var(--accent);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='none' stroke='white' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round' d='M3 8l3.5 3.5L13 5'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: 80%;
}

:where(input[type="radio"]:disabled:checked) {
    border-color: var(--accent);
    background-image: radial-gradient(circle, var(--accent) 35%, transparent 40%);
}

.form-input::placeholder {
    color: var(--text-disabled);
}

/* Date-picker icon in dark mode: `color-scheme: dark` (variables.css) already
   makes the browser render the native calendar/clock indicator light/white, so
   we must NOT invert it — a previous `filter: invert(1)` flipped the already-
   white glyph back to a dark, off-theme icon. Just keep the pointer cursor. */
[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="month"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="week"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
}

/* Hide Chrome's webkit inner-spin-button on date/time inputs — they're noisy
   and the native calendar/clock picker icon is enough affordance. */
input[type="datetime-local"]::-webkit-inner-spin-button,
input[type="time"]::-webkit-inner-spin-button,
input[type="date"]::-webkit-inner-spin-button,
input[type="month"]::-webkit-inner-spin-button,
input[type="week"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    display: none;
}

/* Select */
.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg width='10' height='6' viewBox='0 0 10 6' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M1 1L5 5L9 1' stroke='%236b7280' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    padding-right: var(--space-8);
    cursor: pointer;
}

/* Switch */
.form-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    cursor: pointer;
    user-select: none;
}

.form-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.form-switch-track {
    width: 36px;
    height: 20px;
    background-color: var(--border-primary);
    border-radius: var(--radius-full);
    position: relative;
    transition: background-color var(--duration-normal) var(--ease-default);
    flex-shrink: 0;
}

.form-switch-thumb {
    width: 16px;
    height: 16px;
    background-color: white;
    border-radius: 50%;
    position: absolute;
    top: 2px;
    left: 2px;
    transition: transform var(--duration-normal) var(--ease-default);
    box-shadow: var(--shadow-xs);
}

.form-switch input:checked + .form-switch-track {
    background-color: var(--accent);
}

.form-switch input:checked + .form-switch-track .form-switch-thumb {
    transform: translateX(16px);
}

.form-switch-label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* Input Group (with append buttons) */
.input-group {
    display: flex;
    gap: 0;
}

.input-group .form-input {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
    flex: 1;
}

.input-group .btn {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
    border-left: none;
}

/* Form Row (inline fields) */
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-3);
}
.form-row > .form-group { margin-bottom: 0; }

/* Form Help Text */
.form-help {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    margin-top: var(--space-1);
}

.form-error {
    font-size: var(--text-xs);
    color: var(--danger-text);
    margin-top: var(--space-1);
}


/* ============================================================
   TABLES
   ============================================================ */
.data-table-wrapper {
    overflow: hidden;
}

.data-table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) 0;
    gap: var(--space-4);
    border-bottom: 1px solid var(--border-secondary);
    flex-wrap: wrap;
}

.data-table-toolbar-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.data-table-toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.data-table-search {
    width: 240px;
    position: relative;
}

.data-table-search input {
    width: 100%;
    padding: var(--space-2) var(--space-3) var(--space-2) var(--space-8);
    font-family: var(--font-sans);
    font-size: var(--text-sm);
    color: var(--text-primary);
    background-color: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-md);
    height: 32px;
    outline: none;
    transition: all var(--duration-fast) var(--ease-default);
}

.data-table-search input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.data-table-search-icon {
    position: absolute;
    left: var(--space-3);
    top: calc(50% + 3px);
    transform: translateY(-50%);
    color: var(--text-tertiary);
    font-size: var(--text-sm);
    pointer-events: none;
}

.data-table-scroll {
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}

.data-table thead {
    background-color: var(--table-header-bg);
}

/* Sticky header variant — opt-in via the `.data-table--sticky-head` class on
   the <table>. Each <th> sticks to the top of the nearest scrolling ancestor
   (usually the page). For this to stick to the WINDOW rather than an
   overflow-x wrapper, the wrapper must have explicit overflow-y:visible (the
   WIP page sets that inline). Background keeps cells from bleeding through. */
.data-table--sticky-head thead th {
    position: sticky;
    top: 0;
    z-index: 3;
    background-color: var(--table-header-bg);
}

.data-table th {
    padding: var(--space-2) var(--space-3);
    text-align: left;
    font-weight: var(--weight-semibold);
    color: var(--text-secondary);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: var(--tracking-wide);
    white-space: nowrap;
    border-bottom: 1px solid var(--border-secondary);
    user-select: none;
}

.data-table th.sortable {
    cursor: pointer;
    transition: color var(--duration-fast) var(--ease-default);
}

.data-table th.sortable:hover {
    color: var(--text-primary);
}

.data-table th .sort-icon {
    display: inline-block;
    margin-left: var(--space-1);
    opacity: 0.3;
    font-size: var(--text-xs);
}

.data-table th.sort-asc .sort-icon,
.data-table th.sort-desc .sort-icon {
    opacity: 1;
    color: var(--accent-text);
}

.data-table td {
    padding: var(--space-2) var(--space-3);
    border-bottom: 1px solid var(--border-secondary);
    color: var(--text-primary);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background-color var(--duration-fast) var(--ease-default);
}

.data-table tbody tr:nth-child(even) {
    background-color: var(--table-row-alt);
}

.data-table tbody tr:hover {
    background-color: var(--table-row-hover);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

/* Voided rows — the whole row is dimmed + struck through. Cells flagged
   .void-exempt (the VOIDED badge + edit-icon columns) stay full-opacity and
   un-struck so the badge reads clearly and the row is still editable.
   Opt in via createServerTable's rowClass hook + per-column className. */
.data-table tbody tr.voided-row td {
    opacity: 0.55;
    text-decoration: line-through;
}
.data-table tbody tr.voided-row td.void-exempt {
    opacity: 1;
    text-decoration: none;
}

/* Gridlines modifier — opt-in via `.data-table--grid` on the <table>.
   Adds vertical separators between columns plus a perimeter border, on
   top of the base striping/hover. Used by the Petty Cash History register. */
.data-table--grid {
    border: 1px solid var(--border-secondary);
}
.data-table--grid th,
.data-table--grid td {
    border-right: 1px solid var(--border-secondary);
}
.data-table--grid th:last-child,
.data-table--grid td:last-child {
    border-right: none;
}

/* Table Pagination */
.data-table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-5);
    border-top: 1px solid var(--border-secondary);
    font-size: var(--text-sm);
    color: var(--text-secondary);
    flex-wrap: wrap;
    gap: var(--space-3);
}

.data-table-info {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.data-table-pagination {
    display: flex;
    align-items: center;
    gap: var(--space-1);
}

.data-table-page-btn {
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    background: transparent;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    cursor: pointer;
    transition: all var(--duration-fast) var(--ease-default);
    font-family: var(--font-sans);
}

.data-table-page-btn:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-primary);
}

.data-table-page-btn.active {
    background: var(--accent);
    color: var(--text-on-accent);
    border-color: var(--accent);
}

.data-table-page-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Page Length Select */
.data-table-page-length {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.data-table-page-length select {
    padding: var(--space-1) var(--space-2);
    font-size: var(--text-xs);
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: var(--font-sans);
    outline: none;
    cursor: pointer;
}

/* Empty / Loading States */
.data-table-empty {
    text-align: center;
    padding: var(--space-12) var(--space-6);
    color: var(--text-tertiary);
}

.data-table-empty-icon {
    font-size: var(--text-4xl);
    margin-bottom: var(--space-4);
    opacity: 0.3;
}

.data-table-loading {
    text-align: center;
    padding: var(--space-8);
}


/* ============================================================
   MODALS
   ============================================================ */
.modal {
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-height: 85vh;
    display: flex;
    flex-direction: column;
    transform: scale(0.96) translateY(8px);
    transition: transform var(--duration-normal) var(--ease-out);
    overflow: hidden;
}

.modal-overlay.open .modal {
    transform: scale(1) translateY(0);
}

.modal-sm  { max-width: 400px; }
.modal-md  { max-width: 560px; }
.modal-lg  { max-width: 720px; }
.modal-xl  { max-width: 960px; }
.modal-2xl { max-width: 1600px; }
.modal-2xl { max-width: 1180px; }
.modal-3xl { max-width: 1440px; }

.modal-header {
    padding: var(--space-5) var(--space-6);
    border-bottom: 1px solid var(--border-secondary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-md);
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-xl);
    transition: all var(--duration-fast) var(--ease-default);
}

.modal-close:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-6);
    overflow-y: auto;
    /* Body sizes to its natural content; shrinks (with overflow scroll) only if
       the modal hits its 85vh max-height. The previous `flex: 1` over-stretched
       short modals into the empty 85vh frame, producing thin sub-pixel scrollbars
       even when content fit comfortably. */
    flex: 0 1 auto;
}

/* Opt-in for full-bleed viewer modals (PDF, Office, etc.). The body grows to
   fill the remaining vertical space inside the 85vh-capped modal so an
   iframe child set to `height: 100%` sits flush with the modal bottom and
   the document's own scrollbar is the only one visible. min-height: 0 lets
   the flex child shrink below its intrinsic content size. */
.modal-body-fill {
    flex: 1 1 auto;
    min-height: 0;
    padding: 0;
    overflow: hidden;
    display: flex;
}

/* Pair with .modal-body-fill: pin the modal to a tall 90vh viewport so
   the iframe inside has a real height to fill (otherwise the modal
   collapses to its intrinsic content height, which is ~0 for an iframe
   asking for height:100%). Also widens to 95vw on smaller screens via
   the existing modal-3xl max-width. */
.modal-fill {
    height: 90vh;
    max-height: 90vh;
    width: 95vw;
}

.modal-footer {
    padding: var(--space-4) var(--space-6);
    border-top: 1px solid var(--border-secondary);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--space-3);
    flex-shrink: 0;
}


/* ============================================================
   TOASTS
   ============================================================ */
.toast {
    pointer-events: all;
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    min-width: 300px;
    max-width: 420px;
    animation: toastIn var(--duration-slow) var(--ease-out);
    font-size: var(--text-sm);
}

.toast.removing {
    animation: toastOut var(--duration-normal) var(--ease-in) forwards;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(20px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes toastOut {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(20px); }
}

.toast-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    margin-top: 1px;
}

.toast-content {
    flex: 1;
    min-width: 0;
}

.toast-message {
    color: var(--text-primary);
    line-height: var(--leading-tight);
    white-space: pre-line;
}

.toast-close {
    width: 20px;
    height: 20px;
    border: none;
    background: transparent;
    color: var(--text-tertiary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
    font-size: var(--text-md);
    transition: color var(--duration-fast);
}
.toast-close:hover { color: var(--text-primary); }

.toast.success { border-left: 3px solid var(--success); }
.toast.error   { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.info    { border-left: 3px solid var(--info); }

.toast.success .toast-icon { color: var(--success-text); }
.toast.error   .toast-icon { color: var(--danger-text); }
.toast.warning .toast-icon { color: var(--warning-text); }
.toast.info    .toast-icon { color: var(--info-text); }


/* ============================================================
   BADGES
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: var(--text-xs);
    font-weight: var(--weight-medium);
    border-radius: var(--radius-full);
    white-space: nowrap;
}

.badge-default { background: var(--bg-surface-hover); color: var(--text-secondary); }
.badge-accent  { background: var(--accent-muted);  color: var(--accent-text); }
.badge-success { background: var(--success-muted); color: var(--success-text); }
.badge-warning { background: var(--warning-muted); color: var(--warning-text); }
.badge-danger  { background: var(--danger-muted);  color: var(--danger-text); }
.badge-info    { background: var(--info-muted);    color: var(--info-text); }


/* ============================================================
   TABS
   ============================================================ */
.tabs {
    display: flex;
    border-bottom: 1px solid var(--border-secondary);
    gap: 0;
    overflow-x: auto;
}

.tab {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-tertiary);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all var(--duration-fast) var(--ease-default);
    white-space: nowrap;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
    font-family: var(--font-sans);
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    color: var(--accent-text);
    border-bottom-color: var(--accent);
}


/* ============================================================
   SPINNER
   ============================================================ */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-primary);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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


/* ============================================================
   PROGRESS BAR
   Stacking convention: the survey-engine progress bar (defined in
   new2survey.ccmar.com/css/engine.css as `.survey-progress`) lives at
   the very top of the viewport (top:0, height:3px). When the two bars
   coexist this one sits IMMEDIATELY BELOW it at top:3px. On the admin
   site (where no survey-progress bar exists) the 3px offset is
   visually negligible — looks essentially flush with the top.
   ============================================================ */
.progress-bar-container {
    position: fixed;
    top: 3px;
    left: 0;
    right: 0;
    height: 3px;
    z-index: var(--z-toast);
    background: transparent;
}

.progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), hsl(280, 70%, 55%));
    border-radius: 0 var(--radius-full) var(--radius-full) 0;
    transition: width var(--duration-normal) var(--ease-default);
    box-shadow: 0 0 8px var(--accent-glow);
}


/* ============================================================
   EMPTY STATE
   ============================================================ */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--space-16) var(--space-6);
    text-align: center;
}

.empty-state-icon {
    font-size: 48px;
    opacity: 0.15;
    margin-bottom: var(--space-4);
}

.empty-state-title {
    font-size: var(--text-lg);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.empty-state-text {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
    max-width: 400px;
}


/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-primary);
}

.login-card {
    width: 100%;
    max-width: 400px;
    padding: var(--space-10);
    text-align: center;
}

.login-logo {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-xl);
    background: linear-gradient(135deg, var(--accent) 0%, hsl(280, 70%, 55%) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto var(--space-6);
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    color: white;
}

.login-title {
    font-size: var(--text-2xl);
    font-weight: var(--weight-bold);
    color: var(--text-primary);
    margin-bottom: var(--space-2);
    letter-spacing: var(--tracking-tight);
}

.login-subtitle {
    font-size: var(--text-md);
    color: var(--text-tertiary);
    margin-bottom: var(--space-8);
}

.login-btn {
    width: 100%;
    height: 44px;
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    margin-bottom: var(--space-4);
}

.login-divider {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    margin: var(--space-6) 0;
    color: var(--text-tertiary);
    font-size: var(--text-xs);
}

.login-divider::before,
.login-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-secondary);
}

.login-office-link {
    font-size: var(--text-sm);
    color: var(--text-tertiary);
    cursor: pointer;
    transition: color var(--duration-fast);
}

.login-office-link:hover {
    color: var(--accent-text);
}


/* ============================================================
   UTILITY CLASSES
   ============================================================ */
.text-success { color: var(--success-text); }
.text-warning { color: var(--warning-text); }
.text-danger  { color: var(--danger-text); }
.text-info    { color: var(--info-text); }
.text-muted   { color: var(--text-tertiary); }
.text-mono    { font-family: var(--font-mono); font-size: var(--text-sm); }

.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.grid { display: grid; }
.grid-cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid-cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid-cols-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 767px) {
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: 1fr;
    }
}

@media (min-width: 768px) and (max-width: 1199px) {
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr);
    }
}

.w-full { width: 100%; }
.text-center { text-align: center; }
.text-right { text-align: right; }
.font-mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flex-wrap { flex-wrap: wrap; }
.justify-center { justify-content: center; }
.py-8 { padding-top: var(--space-16); padding-bottom: var(--space-16); }
.gap-1 { gap: var(--space-1); }
.gap-6 { gap: var(--space-6); }
.text-sm { font-size: var(--text-sm); }


/* ============================================================
   TABLE LINK
   ============================================================ */
.table-link {
    color: var(--accent-text);
    text-decoration: none;
    font-weight: var(--weight-medium);
    cursor: pointer;
    transition: color var(--duration-fast) var(--ease-default);
}
.table-link:hover {
    color: var(--accent);
    text-decoration: underline;
}


/* ============================================================
   CARD HOVER (clickable card)
   ============================================================ */
.card-hover {
    transition: all var(--duration-normal) var(--ease-default);
}
.card-hover:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent-glow), var(--shadow-md);
    transform: translateY(-2px);
}


/* ============================================================
   CALENDAR GRID (Job Calendar)
   ============================================================ */
.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-left: 1px solid var(--border-secondary);
    border-top: 1px solid var(--border-secondary);
}

.cal-header {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
    font-weight: var(--weight-semibold);
    text-transform: uppercase;
    color: var(--text-tertiary);
    text-align: center;
    border-right: 1px solid var(--border-secondary);
    border-bottom: 1px solid var(--border-secondary);
    background: var(--table-header-bg);
    letter-spacing: var(--tracking-wide);
}

.cal-cell {
    min-height: 90px;
    padding: var(--space-1) var(--space-2);
    border-right: 1px solid var(--border-secondary);
    border-bottom: 1px solid var(--border-secondary);
    position: relative;
    background: var(--bg-surface);
    transition: background-color var(--duration-fast);
}

.cal-cell:hover {
    background: var(--bg-surface-hover);
}

.cal-cell.other-month {
    opacity: 0.35;
}

.cal-cell.today {
    background: var(--accent-muted);
}

.cal-cell.today .cal-cell-date {
    color: var(--accent-text);
    font-weight: var(--weight-bold);
}

.cal-cell-date {
    font-size: var(--text-sm);
    font-weight: var(--weight-medium);
    color: var(--text-primary);
    margin-bottom: var(--space-1);
}

.cal-cell-events {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.cal-event {
    font-size: 14px;
    padding: 2px 5px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: opacity var(--duration-fast);
}

.cal-event:hover {
    opacity: 0.8;
}

.cal-event-start {
    background: var(--success-muted);
    color: var(--success-text);
    border-left: 2px solid var(--success);
}

.cal-event-end {
    background: var(--danger-muted);
    color: var(--danger-text);
    border-left: 2px solid var(--danger);
}

/* "Span" display mode — a uniform neutral chip drawn on every active day of an
   event (no start/end distinction). Also reused as the span legend swatch. */
.cal-event-span {
    background: var(--accent-muted);
    color: var(--accent-text);
    border-left: 2px solid var(--accent);
}

.cal-legend {
    display: flex;
    gap: 16px;
    padding: 10px 4px 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.cal-legend-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.cal-legend-swatch {
    display: inline-block;
    width: 16px;
    height: 12px;
    border-radius: 3px;
}

@media (max-width: 767px) {
    .cal-cell { min-height: 60px; }
    .cal-event { font-size: 12px; }
}


/* ============================================================
   FORM COLUMN CLASSES
   ============================================================ */
.col-lg-1  { grid-column: 1 / -1; }
.col-lg-2  { grid-column: 1 / -1; }
.col-lg-3  { grid-column: 1 / -1; }
.col-lg-4  { grid-column: 1 / -1; }
.col-lg-5  { grid-column: 1 / -1; }
.col-lg-6  { grid-column: 1 / -1; }
.col-lg-7  { grid-column: 1 / -1; }
.col-lg-8  { grid-column: 1 / -1; }
.col-lg-9  { grid-column: 1 / -1; }
.col-lg-10 { grid-column: 1 / -1; }
.col-lg-11 { grid-column: 1 / -1; }
.col-lg-12 { grid-column: 1 / -1; }

@media (min-width: 768px) {
    .form-row { grid-template-columns: repeat(12, 1fr); }
    .col-lg-1  { grid-column: span 1; }
    .col-lg-2  { grid-column: span 2; }
    .col-lg-3  { grid-column: span 3; }
    .col-lg-4  { grid-column: span 4; }
    .col-lg-5  { grid-column: span 5; }
    .col-lg-6  { grid-column: span 6; }
    .col-lg-7  { grid-column: span 7; }
    .col-lg-8  { grid-column: span 8; }
    .col-lg-9  { grid-column: span 9; }
    .col-lg-10 { grid-column: span 10; }
    .col-lg-11 { grid-column: span 11; }
    .col-lg-12 { grid-column: span 12; }
}

/* Compact Form Variant for Bid Editors */
.form-builder.compact-form .form-group {
    margin-bottom: 4px !important;
    display: flex;
    align-items: center;
    gap: 6px;
}
.form-builder.compact-form .form-label {
    margin-bottom: 0 !important;
    font-size: 13px;
    flex: 0 0 auto;
    white-space: nowrap;
}
.form-builder.compact-form.aligned-labels .form-label {
    flex: 0 0 160px;
    white-space: normal;
}
/* Narrower label column for the respondent info form — labels on that page
   are all ≤10 chars so 160px left a huge gap between the label and input. */
.form-builder.compact-form.aligned-labels.resp-labels .form-label {
    flex: 0 0 90px;
}
/* Widen the gap between grid columns so labels starting a later column on the
   same row don't butt right up against the previous column's input. Only the
   inter-column space grows — labels in column 1 stay flush with the edge.  */
.form-builder.compact-form.resp-labels .form-row {
    column-gap: 20px !important;
}
.form-builder.compact-form .form-label:not(.no-colon)::after {
    content: ':';
    margin-left: 1px;
}
.form-builder.compact-form .form-input,
.form-builder.compact-form .form-select,
.form-builder.compact-form .form-textarea { padding: 4px 6px; font-size: 14px; height: 30px; flex: 1 1 auto; min-width: 0; }
.form-builder.compact-form .form-textarea { height: auto; min-height: unset; }
.form-builder.compact-form .input-group { flex: 1 1 auto; min-width: 0; }
.form-builder.compact-form .input-group .btn { height: 30px; padding: 4px 10px; font-size: 14px; }
.form-builder.compact-form .form-row { row-gap: 6px !important; column-gap: 8px !important; }
.form-builder.compact-form .form-group-block { display: block; }
.form-builder.compact-form .form-group-block .form-label { margin-bottom: 4px !important; }
.form-builder.compact-form .form-error { flex-basis: 100%; margin-left: 0; }
.col-break { grid-column: 1 / -1 !important; height: auto; }

/* Dense variant for the Job Field Management page: shorter inputs, smaller
   row gap, smaller labels. Scoped so it doesn't leak to other pages. */
.jobmanage-dense .form-input,
.jobmanage-dense .form-select,
.jobmanage-dense .form-textarea { height: 24px !important; min-height: 24px !important; padding: 2px 6px !important; font-size: 13px !important; line-height: 1.2 !important; }
.jobmanage-dense .form-textarea { height: 56px !important; }
.jobmanage-dense .form-row { row-gap: 3px !important; column-gap: 8px !important; }
.jobmanage-dense .form-group { margin-bottom: 0 !important; }
.jobmanage-dense .form-label { font-size: 13px !important; }

/* ============================================================
   Panelist Filter Modal — search-aware accordion of categories
   ============================================================ */

/* Sticky search bar — pill-style input that stays at the top of the modal
   body while the user scrolls through the long category list.            */
.panel-filter-search {
    position: sticky;
    top: 0;
    z-index: 2;
    margin-bottom: var(--space-3);
    height: 38px;
    padding: 0 var(--space-4);
    border-radius: 999px;
    background: var(--bg-input);
}

.panel-filter-search:focus {
    background: var(--bg-input);
}

/* Pinned Contact Info card at the top of the modal. Mirrors the .card
   surface tokens so it feels native in light/dark themes.                */
.panel-filter-pinned {
    background: var(--bg-surface);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    padding: var(--space-4) var(--space-5);
    margin-bottom: var(--space-3);
}

.panel-filter-pinned-header {
    margin-bottom: var(--space-3);
    padding-bottom: var(--space-3);
    border-bottom: 1px solid var(--border-secondary);
}

.panel-filter-pinned-title {
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
}

.panel-filter-pinned-subtitle {
    font-size: var(--text-xs);
    color: var(--text-muted);
    margin-top: 2px;
}

/* Tighten label width inside the pinned section — labels are short so
   90px (resp-labels default) feels right. Override the inherited 160px.  */
.panel-filter-pinned .form-builder.compact-form.aligned-labels.resp-labels .form-label {
    flex: 0 0 88px;
    color: var(--text-secondary);
}

/* Accordion stack ─────────────────────────────────────────────────────── */
.panel-filter-accordion {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.panel-filter-category {
    background: var(--bg-surface);
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-md);
    overflow: hidden;
    transition: border-color var(--duration-fast) var(--ease-default);
}

.panel-filter-category[open] {
    border-color: var(--border-hover);
}

.panel-filter-summary {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--space-3) var(--space-4);
    cursor: pointer;
    user-select: none;
    list-style: none;
    transition: background-color var(--duration-fast) var(--ease-default);
}

.panel-filter-summary::-webkit-details-marker { display: none; }

.panel-filter-summary:hover {
    background: var(--bg-surface-hover);
}

.panel-filter-cat-name {
    font-size: var(--text-md);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    position: relative;
    padding-left: 20px;
}

.panel-filter-cat-name::before {
    content: '';
    position: absolute;
    left: 4px;
    top: 6px;
    width: 6px;
    height: 6px;
    border-right: 2px solid var(--text-tertiary);
    border-bottom: 2px solid var(--text-tertiary);
    transform: rotate(-45deg);
    transform-origin: 70% 70%;
    transition: transform var(--duration-fast) var(--ease-default);
}

.panel-filter-category[open] > .panel-filter-summary .panel-filter-cat-name::before {
    transform: rotate(45deg);
}

.panel-filter-cat-desc {
    font-size: var(--text-xs);
    color: var(--text-muted);
    padding-left: 20px;
}

/* Per-category content area (attribute rows under the summary).         */
.panel-filter-rows {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--space-3);
    align-items: start;
    padding: var(--space-4);
    border-top: 1px solid var(--border-secondary);
    background: var(--bg-secondary);
}

.panel-filter-attr {
    display: flex;
    flex-direction: column;
    min-width: 0;                 /* let cards shrink inside the grid (no overflow) */
    gap: var(--space-2);
    padding: var(--space-3);
    background: var(--bg-surface);
    border: 1px solid var(--border-secondary);
    border-radius: var(--radius-sm);
    transition: border-color var(--duration-fast) var(--ease-default);
}

.panel-filter-attr:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.panel-filter-attr-label {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.panel-filter-attr-name {
    font-size: var(--text-sm);
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
}

.panel-filter-attr-desc {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    line-height: 1.4;
}

/* Modern checkbox + radio rendering — pill-style chips with the brand
   accent color when checked. Uses native input + accent-color so we get
   keyboard focus and a11y for free.                                      */
.panel-filter-checkboxes {
    display: flex;
    flex-direction: column;       /* options stack vertically (one per line) */
    align-items: flex-start;      /* pills stay content-width, left-aligned */
    gap: 6px;
}

.panel-filter-checkbox-label,
.panel-filter-radio-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    font-size: var(--text-sm);
    color: var(--text-secondary);
    background: var(--bg-input);
    border: 1px solid var(--border-input);
    border-radius: 999px;
    cursor: pointer;
    user-select: none;
    transition: all var(--duration-fast) var(--ease-default);
}

.panel-filter-checkbox-label:hover,
.panel-filter-radio-label:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-hover);
    color: var(--text-primary);
}

.panel-filter-checkbox-label:has(input:checked),
.panel-filter-radio-label:has(input:checked) {
    background: var(--accent-muted);
    border-color: var(--accent);
    color: var(--accent-text);
}

.panel-filter-checkbox-label input,
.panel-filter-radio-label input {
    accent-color: var(--accent);
    margin: 0;
    cursor: pointer;
}

.panel-filter-radios {
    display: flex;
    flex-direction: column;       /* options stack vertically (one per line) */
    align-items: flex-start;
    gap: 6px;
}

.panel-filter-empty-options {
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-style: italic;
    padding: 4px 0;
}

/* Range pairs (age range, zipcode + radius). Two inputs separated by a
   small connector word ("to" / "within") and trailed by a unit label.   */
.panel-filter-range {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.panel-filter-range .form-input {
    flex: 0 0 auto;
}

.panel-filter-range-sep {
    font-size: var(--text-sm);
    color: var(--text-muted);
}

.panel-filter-range-suffix {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

/* ============================================================
   PROJECT FILES TREE — accordion-style folder browser used on
   the Job Field Management page (jobs.js → buildFilesCard).
   Folders are native <details>/<summary>; chevron rotates on
   [open]. Drop targets highlight when a draggable item hovers.
   ============================================================ */
.project-files-tree {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-height: 40px;
}

/* The Files card header doubles as the move-to-root drop target. Drag a
   file/folder over the header to drop it at the project root level. */
#job-files-card .card-header.tree-drop-over {
    outline: 2px dashed var(--accent, #1a5fd1);
    outline-offset: -2px;
    background: var(--bg-surface-hover);
}

.tree-folder-summary {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    cursor: pointer;
    user-select: none;
    list-style: none;
    border-radius: var(--radius-sm);
}

.tree-folder-summary::-webkit-details-marker { display: none; }

.tree-folder-summary:hover {
    background: var(--bg-surface-hover);
}

.tree-folder-summary.tree-drop-over,
.project-files-tree.tree-drop-over {
    outline: 2px dashed var(--accent, #1a5fd1);
    outline-offset: -2px;
    background: var(--bg-surface-hover);
}

.tree-chevron {
    display: inline-flex;
    width: 14px;
    color: var(--text-tertiary);
    transition: transform var(--duration-fast) var(--ease-default);
}

.tree-folder[open] > .tree-folder-summary .tree-chevron {
    transform: rotate(90deg);
}

.tree-folder-icon {
    display: inline-flex;
    color: var(--accent, #1a5fd1);
}

.tree-folder-name {
    font-weight: var(--weight-semibold);
    color: var(--text-primary);
    flex: 0 0 auto;
}

.tree-folder-count {
    font-size: var(--text-xs);
    color: var(--text-muted);
}

.tree-folder-actions {
    margin-left: auto;
    display: inline-flex;
    gap: var(--space-1);
}

.tree-icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.tree-icon-btn:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.tree-icon-btn-danger:hover {
    background: var(--danger, #ef4444);
    color: #fff;
}

/* "On" state for toggle-style icon buttons (e.g., Share when shared='yes'). */
.tree-icon-btn-active {
    background: var(--accent, #1a5fd1);
    color: #fff;
}

.tree-icon-btn-active:hover {
    background: var(--accent, #1a5fd1);
    color: #fff;
    opacity: 0.9;
}

.tree-folder-body {
    padding-left: var(--space-5);
    margin-left: var(--space-3);
    border-left: 1px solid var(--border-secondary);
    margin-top: 2px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding-bottom: var(--space-1);
}

/* File rows use a six-column grid where every column except the name is a
   fixed width. Because the right edge of every nested .tree-folder-body
   stays flush with the parent's right edge, the right-anchored columns
   (type/size/owner/date/actions) line up across every nesting depth.
   The name column is the only flex track and absorbs the indent cost as
   folders nest deeper. */
.tree-file-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 130px 70px 130px 150px 220px;
    gap: var(--space-3);
    align-items: center;
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
}

.tree-file-row:hover {
    background: var(--bg-surface-hover);
}

/* Tiger-stripe rows. CSS :nth-child can't make every *visible* row alternate
   across nested folder levels (each level resets its own counter, and rows
   appear/disappear when folders open/close), so the .tree-stripe-alt class
   is applied imperatively in file-tree-card.js after each render and on
   every <details> toggle. The single rule here just paints whichever rows
   carry that class. */
.tree-file-row.tree-stripe-alt,
.tree-folder.tree-stripe-alt > .tree-folder-summary {
    background: var(--table-row-alt);
}

.tree-file-name {
    min-width: 0;
}

.tree-cell {
    font-size: var(--text-xs);
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-align: left;
}

.tree-cell-size,
.tree-cell-date {
    text-align: right;
    justify-self: end;
}

.tree-file-actions {
    display: flex;
    gap: var(--space-1);
    flex-wrap: wrap;
    justify-content: flex-end;
}

.tree-folder-picker {
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border-primary);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
}

.tree-folder-picker-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    cursor: pointer;
    color: var(--text-primary);
}

.tree-folder-picker-row:hover {
    background: var(--bg-surface-hover);
}

.tree-folder-picker-row.selected {
    background: var(--accent, #1a5fd1);
    color: #fff;
}

@media (max-width: 900px) {
    /* Drop the uploader column once we lose horizontal room. */
    .tree-file-row {
        grid-template-columns: minmax(0, 1fr) 110px 70px 140px 200px;
    }
    .tree-cell-owner { display: none; }
}

@media (max-width: 640px) {
    /* Mobile: stack everything vertically. */
    .tree-file-row {
        grid-template-columns: 1fr;
    }
    .tree-cell-owner { display: inline; }
}

/* Drag-to-reorder drop indicator. Single floating element managed by
   makeDragReorder() — sits on the gap above or below the hovered row to
   match exactly where the drop will land. position:fixed so it doesn't
   shift any layout. */
.drag-drop-indicator {
    position: fixed;
    height: 2px;
    background: var(--accent, #1a5fd1);
    pointer-events: none;
    z-index: 9999;
    display: none;
    border-radius: 1px;
    box-shadow: 0 0 4px var(--accent, #1a5fd1);
}

/* ============================================================
   NO-MOTION OVERRIDE
   Snappy UI — kill every transition and decorative animation
   site-wide. Spinners are preserved below so loading states
   still indicate progress.
   ============================================================ */
*, *::before, *::after {
    transition: none !important;
    animation: none !important;
}

.spinner {
    animation: spin 0.6s linear infinite !important;
}

/* ===== Admin edit-answer iframe overlay ============================== */
/* Used by studies.js openEditAnswerIframe() — full-viewport overlay
   containing an iframe that points at new2survey.ccmar.com/edit-answer.php.
   The iframe renders ONE survey question via the real engine; on save it
   postMessages the answer back to this page. */

.admin-edit-iframe-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay, rgba(0,0,0,0.5));
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.admin-edit-iframe-frame {
    position: relative;
    width: 100%;
    max-width: 1600px;
    height: 95vh;
    max-height: 95vh;
    background: var(--bg-elevated);
    border: 1px solid var(--border-primary);
    border-radius: 8px;
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.admin-edit-iframe-close {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    border-radius: 4px;
    z-index: 1;
}
.admin-edit-iframe-close:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}
.admin-edit-iframe-wrap {
    flex: 1 1 auto;
    min-height: 600px;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    overflow: hidden;
}
.admin-edit-iframe {
    width: 100%;
    height: 100%;
    min-height: 600px;
    border: none;
    background: var(--bg-secondary);
}
.admin-edit-iframe-loading {
    padding: 32px;
    color: var(--text-secondary);
    font-style: italic;
    text-align: center;
    width: 100%;
}

/* ===== Database Backups page (js/pages/backups.js) ============== */
/* Tabs: bottom-border style, accent underline on the active one. */
.backups-tab {
    background: transparent;
    border: 0;
    padding: 8px 16px;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    font-weight: var(--weight-medium);
    font-size: 0.95rem;
    margin-bottom: -1px; /* overlap the .backups-tabs bottom border */
}
.backups-tab:hover {
    color: var(--text-primary);
}
.backups-tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent, var(--success-text));
}
/* Leaf rows inside the backup trees — columns line up across rows. */
.backups-leaf {
    display: grid;
    /* glyph | db name | kind | time | size | duration | author | s3 url */
    grid-template-columns: 16px 170px 60px 50px 75px 75px 130px minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 4px 8px;
    font-size: 0.9em;
}
.backups-leaf.has-date {
    /* glyph | db name | kind | date | time | size | duration | author | s3 url */
    grid-template-columns: 16px 170px 60px 95px 50px 75px 75px 130px minmax(0, 1fr);
}
.backups-leaf-glyph {
    width: 16px;
    text-align: center;
}
.backups-leaf-db {
    font-family: monospace;
    font-size: 0.95em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.backups-leaf-kind {
    font-weight: var(--weight-medium);
    font-size: 0.85em;
}
.backups-leaf-col-date,
.backups-leaf-col-time {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    font-size: 0.85em;
}
.backups-leaf-col-num {
    color: var(--text-secondary);
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-size: 0.85em;
}
.backups-leaf-author {
    color: var(--text-secondary);
    font-size: 0.85em;
    font-style: italic;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
/* Used by the "no backups recorded" placeholder under empty DBs. */
.backups-leaf-meta {
    color: var(--text-secondary);
    font-size: 0.9em;
}
.backups-leaf-s3url {
    font-family: monospace;
    font-size: 0.8em;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    user-select: all;  /* triple-click selects whole URL for easy copy */
}
.backups-leaf-s3url-empty {
    user-select: auto;
}
.backups-leaf-error-row {
    padding: 0 8px 6px 36px;  /* indent past glyph column */
}
.backups-leaf-error {
    color: var(--danger-text);
    font-family: monospace;
    font-size: 0.85em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
    max-width: 100%;
}
/* Empty-DB row in the By-Database tree — for DBs that have no backups recorded. */
.backups-empty-db {
    padding: 8px 12px;
    color: var(--text-secondary);
    font-size: 0.9em;
}

/* ===== AWS Cost Estimator page (js/pages/aws-costs.js) ============= */
.aws-cost-section-header {
    margin: 24px 0 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.aws-cost-section-title {
    margin: 0;
    font-size: 1.0rem;
    font-weight: var(--weight-medium);
}
.aws-cost-section-subtitle {
    color: var(--text-secondary);
    font-size: 0.85em;
}
.aws-cost-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    margin-bottom: 8px;
}
.aws-cost-table th {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    font-weight: var(--weight-medium);
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.aws-cost-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-secondary, var(--border));
    vertical-align: middle;
}
.aws-cost-resource-id {
    font-family: monospace;
    font-size: 0.85em;
    color: var(--text-secondary);
}
.aws-cost-state {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.8em;
    font-weight: var(--weight-medium);
}
.aws-cost-state-running    { background: rgba(0, 200, 100, 0.15); color: var(--success-text); }
.aws-cost-state-stopped    { background: var(--border); color: var(--text-secondary); }
.aws-cost-state-in-use     { background: rgba(0, 200, 100, 0.15); color: var(--success-text); }
.aws-cost-state-available  { background: rgba(255, 180, 0, 0.15); color: var(--warning-text); }
.aws-cost-state-warning    { background: rgba(255, 180, 0, 0.15); color: var(--warning-text); }
.aws-cost-state-pending,
.aws-cost-state-stopping   { background: rgba(255, 180, 0, 0.15); color: var(--warning-text); }
.aws-cost-state-terminated { background: rgba(200, 0, 0, 0.10); color: var(--danger-text); }
.aws-cost-sparkline {
    display: inline-block;
    vertical-align: middle;
}
.aws-cost-empty {
    padding: 16px;
    color: var(--text-secondary);
    font-style: italic;
}
.aws-cost-loading,
.aws-cost-refreshing {
    padding: 20px;
    text-align: center;
    color: var(--text-secondary);
}
.aws-cost-error {
    padding: 16px;
    color: var(--danger-text);
}
.aws-cost-errors {
    color: var(--warning-text);
    font-family: monospace;
    font-size: 0.85em;
    padding-left: 20px;
}
.aws-cost-amis-info {
    padding: 12px 16px;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.95em;
}
.aws-cost-totals-card {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-elevated);
    padding: 14px 18px;
    margin: 12px 0 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.aws-cost-totals-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
}
.aws-cost-totals-label {
    color: var(--text-secondary);
}
.aws-cost-totals-value {
    font-size: 1.1em;
    font-weight: var(--weight-medium);
    font-family: monospace;
}
.aws-cost-totals-grand {
    padding-top: 6px;
    margin-top: 4px;
    border-top: 1px solid var(--border);
}
.aws-cost-totals-grand .aws-cost-totals-value {
    font-size: 1.2em;
}

/* Cost Estimator tab toolbar (AWS / AI Services) — same visual style as
   .backups-tab on /backupslist for consistency. */
.cost-tab {
    background: transparent;
    border: 0;
    padding: 8px 16px;
    cursor: pointer;
    color: var(--text-secondary);
    border-bottom: 2px solid transparent;
    font-weight: var(--weight-medium);
    font-size: 0.95rem;
    margin-bottom: -1px;
}
.cost-tab:hover { color: var(--text-primary); }
.cost-tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent, var(--success-text));
}
.aws-cost-cooldown {
    color: var(--warning-text);
}
.aws-cost-header-line {
    /* header line container — children styled inline */
}
/* Summary / totals row at the bottom of each section's table */
.aws-cost-totals-tr td {
    border-top: 2px solid var(--border);
    border-bottom: none;
    background: var(--surface-elevated);
    padding-top: 10px;
    padding-bottom: 10px;
    font-size: 0.92em;
}

/* ===== System Images (AMI) tab ===== */
.sys-image-help {
    margin: 12px 0;
    padding: 8px 12px;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 0.9em;
}
.sys-image-help-body {
    padding: 4px 8px 8px;
    color: var(--text-primary);
}
.sys-image-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 16px 0 8px;
}
.sys-image-header-title {
    margin: 0;
    font-size: 1.05rem;
}
.sys-image-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    margin-top: 8px;
}
.sys-image-table th {
    text-align: left;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
    font-weight: var(--weight-medium);
    font-size: 0.85em;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.sys-image-table td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-secondary, var(--border));
    vertical-align: middle;
}
.sys-image-row-deregistered {
    opacity: 0.55;
}
.sys-image-name {
    font-family: monospace;
    font-size: 0.95em;
}
.sys-image-amiid {
    font-family: monospace;
    font-size: 0.85em;
    color: var(--text-secondary);
}
.sys-image-created {
    color: var(--text-secondary);
}
.sys-image-initiator {
    color: var(--text-secondary);
    font-size: 0.9em;
}
.sys-image-actions {
    text-align: right;
}
.sys-image-meta-muted {
    color: var(--text-secondary);
    font-size: 0.85em;
    font-style: italic;
}
.sys-image-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: var(--weight-medium);
    white-space: nowrap;
}
.sys-image-status-success { color: var(--success-text); }
.sys-image-status-failed  { color: var(--danger-text); }
.sys-image-status-pending { color: var(--warning-text); }
.sys-image-status-muted   { color: var(--text-secondary); }
.sys-image-spinner {
    display: inline-block;
    animation: sys-image-spin 1.4s linear infinite;
}
@keyframes sys-image-spin {
    from { transform: rotate(0deg); }
    to   { transform: rotate(360deg); }
}
/* Inline progress bar inside the status cell. */
.sys-image-bar {
    display: inline-block;
    width: 80px;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
    vertical-align: middle;
    margin-left: 6px;
}
.sys-image-bar-fill {
    display: block;
    height: 100%;
    background: var(--warning-text);
    transition: width 0.3s ease;
}

/* Floating progress card mounted above the page while a sys-image is in flight. */
.sys-image-progress-card {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface-elevated);
    padding: 14px 18px;
    margin: 8px 0 16px;
}
.sys-image-progress-title {
    font-weight: var(--weight-medium);
    font-size: 0.95rem;
    margin-bottom: 6px;
}
.sys-image-progress-status {
    color: var(--text-secondary);
    margin-bottom: 10px;
    font-size: 0.9em;
}
.sys-image-progress-status-success { color: var(--success-text); }
.sys-image-progress-status-failed  { color: var(--danger-text); }
.sys-image-progress-bar {
    width: 100%;
    height: 10px;
    background: var(--border);
    border-radius: 5px;
    overflow: hidden;
    margin-bottom: 6px;
}
.sys-image-progress-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--warning-text), var(--success-text));
    transition: width 0.5s ease;
}
.sys-image-progress-elapsed {
    color: var(--text-secondary);
    font-size: 0.85em;
}
