/* ==========================================================================
   Reusable components: cards, buttons, forms, tables, badges, modal,
   dropdown, dynamic island, alerts, tabs, pagination, empty/loading/error states.
   ========================================================================== */

/* ---------- Cards ---------- */
.card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}
.card-header { display: flex; align-items: center; justify-content: space-between; gap: .75rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border-color); }
.card-header h2, .card-header h3 { margin: 0; font-size: 1rem; }
.card-body { padding: 1.25rem; }
.card-footer { padding: .85rem 1.25rem; border-top: 1px solid var(--border-color); }
.card-link { color: inherit; display: block; transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition); }
.card-link:hover { text-decoration: none; border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); align-items: start; }
.stack { display: grid; gap: 1rem; align-content: start; }
/* Nor may a card (a long name, a wide table) widen the stack past the screen: what doesn't fit wraps or scrolls inside it. */
.stack > * { min-width: 0; }

/* minmax(0, …), not a bare 1fr: a 1fr column widens to its longest unbreakable line, and the page then runs off a phone's screen. */
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .grid-main { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 760px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* ---------- Stat cards ---------- */
.stat { display: flex; gap: .9rem; align-items: center; padding: 1.1rem 1.2rem; }
.stat-icon { width: 44px; height: 44px; border-radius: 11px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary-text); flex-shrink: 0; }
.stat-icon.success { background: var(--success-soft); color: var(--success); }
.stat-icon.warning { background: var(--warning-soft); color: var(--warning); }
.stat-icon.danger { background: var(--danger-soft); color: var(--danger); }
.stat-icon.info { background: var(--info-soft); color: var(--info); }
.stat-icon.violet { background: color-mix(in srgb, var(--chart-4) 14%, transparent); color: var(--chart-4); }
.stat-icon.muted { background: var(--bg-inset); color: var(--text-muted); box-shadow: inset 0 0 0 1px var(--border-color); }
.stat-icon.sm { width: 36px; height: 36px; border-radius: 9px; }
.stat-icon.sm svg.icon { width: 16px; height: 16px; }
.stat-value { font-size: 1.55rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--text-secondary); font-size: .82rem; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
    padding: .55rem .95rem;
    border: 1px solid transparent; border-radius: 8px;
    font: inherit; font-weight: 600; font-size: .86rem; line-height: 1.2;
    cursor: pointer; white-space: nowrap;
    transition: background var(--transition), border-color var(--transition), color var(--transition), opacity var(--transition);
}
.btn:hover { text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--bg-secondary); color: var(--text-primary); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--bg-hover); }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(.95); }
.btn-success { background: var(--success); color: #fff; }
.btn-sm { padding: .35rem .6rem; font-size: .8rem; border-radius: 7px; }
.btn-lg { padding: .75rem 1.2rem; font-size: .95rem; }
.btn-block { width: 100%; }
.btn-icon { padding: .4rem; }
.btn .spinner { width: 14px; height: 14px; border-width: 2px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1rem; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 640px) { .form-grid { grid-template-columns: 1fr; } }
/* A labelled group of fields inside one form. */
.form-section { margin-top: 1.25rem; padding-top: 1.15rem; border-top: 1px solid var(--border-color); }
.form-section-title { display: flex; align-items: center; gap: .45rem; margin-bottom: .85rem; font-size: .76rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted); }
.form-section-title svg.icon { width: 15px; height: 15px; }
/* Helper text and the submit button on one footer row. */
.form-actions { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; }
/* Inside a form section, checkbox fields read as option rows rather than loose ticks. */
.form-section .field:has(> .checkbox) { padding: .65rem .8rem; border: 1px solid var(--border-color); border-radius: var(--radius); background: var(--bg-inset); transition: border-color var(--transition), background var(--transition); }
.form-section .field:has(> .checkbox input:checked) { border-color: color-mix(in srgb, var(--primary) 35%, transparent); background: var(--primary-soft); }

.field { display: grid; gap: .3rem; align-content: start; }
.field label, .label { font-weight: 600; font-size: .82rem; color: var(--text-secondary); }
.field .required::after { content: " *"; color: var(--danger); }
.field-help { font-size: .76rem; color: var(--text-muted); }
/* What a field's lookup() found out about the value (core/form.js), e.g. the FormFlow form behind a link. */
.field-lookup { font-size: .78rem; color: var(--text-secondary); }
.field-lookup[hidden] { display: none; }
/* One-tap due dates under an activity's Due date (dueQuickPicks() in activities/fields.js). */
.due-picks { display: flex; flex-wrap: wrap; gap: .35rem; }
.feedback-draft { display: flex; flex-direction: column; align-items: flex-start; gap: .4rem; margin-top: .5rem; }
.feedback-draft .field-help { display: flex; align-items: flex-start; gap: .4rem; margin: 0; }
.feedback-draft .field-help svg.icon { width: 14px; height: 14px; flex-shrink: 0; margin-top: .15rem; }
.field-lookup.success { color: var(--success); }
.field-lookup.warning { color: var(--warning); }
.field-lookup.danger { color: var(--danger); }

/* What a chosen picture looks like, shown under the file input before it is uploaded. */
.file-preview { margin-top: .5rem; border: 1px solid var(--border-color); border-radius: 10px; overflow: hidden; background: var(--bg-inset); }
.file-preview[hidden] { display: none; }
.file-preview-frame { display: block; position: relative; }
.file-preview-frame img { display: block; width: 100%; max-height: 220px; object-fit: contain; background: var(--bg-tertiary); }
.file-preview-meta { display: block; padding: .4rem .65rem; border-top: 1px solid var(--border-color); font-size: .74rem; color: var(--text-muted); word-break: break-all; }
/* The banner variant frames the picture exactly as a course cover is shown, scrim and all,
   so the darkening that keeps the course code readable is no surprise after uploading. */
.file-preview-banner .file-preview-frame img { aspect-ratio: 3 / 1; max-height: none; object-fit: cover; }
.file-preview-banner .file-preview-frame::after {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background: linear-gradient(180deg, rgba(0, 0, 0, .12) 0%, rgba(0, 0, 0, .58) 100%);
}

/* A cheat sheet folded into a field's help, for a field whose text is formatted (lesson content). */
.field-guide { margin-top: .4rem; border: 1px solid var(--border-color); border-radius: 10px; background: var(--bg-inset); }
.field-guide summary { display: flex; align-items: center; gap: .4rem; padding: .45rem .65rem; cursor: pointer; list-style: none; font-size: .78rem; font-weight: 600; color: var(--text-secondary); }
.field-guide summary::-webkit-details-marker { display: none; }
.field-guide summary:hover { color: var(--text-primary); }
.field-guide summary svg.icon { width: 15px; height: 15px; color: var(--text-muted); }
.field-guide[open] summary { border-bottom: 1px solid var(--border-color); }
.field-guide-body { display: grid; gap: .55rem; padding: .65rem; font-size: .76rem; line-height: 1.55; color: var(--text-muted); }
.field-guide-row { display: grid; grid-template-columns: minmax(6rem, 9rem) 1fr; gap: .25rem .75rem; align-items: start; }
.field-guide-row > code { justify-self: start; white-space: pre; }
.field-guide-row strong { color: var(--text-secondary); }
@media (max-width: 560px) { .field-guide-row { grid-template-columns: 1fr; } }
.field-guide-lead { margin: 0; color: var(--text-secondary); }

/* Lesson content editor (lessons/editor.js): format buttons and Write | Preview on a bar joined to the box. */
.lesson-editor { border: 1px solid var(--border-strong); border-radius: 8px; background: var(--bg-secondary); overflow: hidden; transition: border-color var(--transition), box-shadow var(--transition); }
.lesson-editor:focus-within { border-color: var(--primary); box-shadow: var(--focus-ring); }
.lesson-editor .textarea, .lesson-editor .textarea:focus { display: block; border: 0; border-radius: 0; box-shadow: none; }
.lesson-editor-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .4rem; padding: .3rem .35rem; border-bottom: 1px solid var(--border-color); background: var(--bg-inset); }
.lesson-editor-tools { display: flex; flex-wrap: wrap; gap: .15rem; }
.lesson-editor-tool {
    display: inline-flex; align-items: center; gap: .35rem; height: 30px; padding: 0 .55rem;
    border: 0; border-radius: 6px; background: transparent; color: var(--text-secondary);
    font: inherit; font-size: .8rem; font-weight: 600; cursor: pointer;
    transition: background var(--transition), color var(--transition);
}
.lesson-editor-tool:hover:not(:disabled) { background: var(--bg-hover); color: var(--text-primary); }
.lesson-editor-tool:disabled { opacity: .45; cursor: default; }
.lesson-editor-tool svg.icon { width: 15px; height: 15px; }
.lesson-editor-mode { display: inline-flex; gap: 2px; padding: 2px; border-radius: 8px; background: var(--switch-track); }
.lesson-editor-mode button {
    height: 26px; padding: 0 .7rem; border: 0; border-radius: 6px; background: transparent; color: var(--text-secondary);
    font: inherit; font-size: .78rem; font-weight: 600; cursor: pointer;
}
.lesson-editor-mode button:hover { color: var(--text-primary); }
.lesson-editor-mode button[aria-pressed="true"] { background: var(--switch-thumb); box-shadow: var(--switch-thumb-shadow); color: var(--text-primary); }
.lesson-editor-preview { min-height: 110px; max-height: 60vh; overflow-y: auto; padding: .8rem .95rem; }
.lesson-editor-toc { margin-bottom: 1rem; padding: .55rem .8rem; border: 1px solid var(--border-color); border-radius: 8px; font-size: .8rem; color: var(--text-secondary); }
.lesson-editor-toc strong { color: var(--text-primary); }
.lesson-editor-toc ul { margin: .25rem 0 0; padding-left: 1.1rem; }
.lesson-editor-empty { margin: 0; color: var(--text-muted); font-size: .86rem; }
/* A phone keeps the icons; each button still says what it does to a screen reader. */
@media (max-width: 560px) { .lesson-editor-tool span { display: none; } }
.field-error { font-size: .78rem; color: var(--danger); }
.field-error:empty { display: none; }

.input, .select, .textarea {
    width: 100%;
    padding: .55rem .75rem;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus-ring); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--bg-tertiary); color: var(--text-muted); }
.input[readonly] { background: var(--bg-inset); color: var(--text-secondary); cursor: default; }
.input[readonly]:focus { border-color: var(--border-strong); box-shadow: none; }
.textarea { min-height: 110px; resize: vertical; }
.select {
    appearance: none;
    padding-right: 2rem;
    background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%);
    background-position: calc(100% - 16px) 52%, calc(100% - 11px) 52%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}
.select option { background: var(--bg-secondary); color: var(--text-primary); }
/* A select that sits in a card header next to the title. */
.select-sm { width: auto; padding: .3rem 1.9rem .3rem .6rem; font-size: .8rem; border-radius: 7px; background-position: calc(100% - 14px) 52%, calc(100% - 9px) 52%; }
input[type="date"].input, input[type="datetime-local"].input { color-scheme: inherit; }
input[type="file"].input { padding: .4rem; }
input[type="file"].input::file-selector-button { border: 1px solid var(--border-strong); border-radius: 6px; background: var(--bg-tertiary); color: var(--text-primary); padding: .3rem .6rem; margin-right: .6rem; cursor: pointer; }

.checkbox { display: inline-flex; align-items: center; gap: .5rem; font-weight: 500; color: var(--text-primary); cursor: pointer; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }
.checklist { display: grid; gap: .5rem; }
.checklist-options { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .5rem 1rem; }

.input-group { position: relative; }
.input-group svg { position: absolute; left: .7rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.input-group .input, .input-group .select { padding-left: 2.25rem; }
.field .input-group > svg { transition: color var(--transition); }
.field .input-group:focus-within > svg { color: var(--primary); }
.field .input-group:has([aria-invalid="true"]) > svg { color: var(--danger); }

/* Textarea character count (core/form.js) */
.field-count { justify-self: end; margin-top: -.1rem; font-size: .72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.field-count.near-limit { color: var(--warning); }

/* Choice cards: a radio group shown as selectable cards (field type 'choice') */
.choice-group { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .6rem; }
.choice {
    position: relative; display: flex; align-items: flex-start; gap: .65rem;
    padding: .7rem .8rem; border: 1px solid var(--border-strong); border-radius: var(--radius);
    background: var(--bg-secondary); cursor: pointer;
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}
.choice:hover { border-color: color-mix(in srgb, var(--primary) 55%, var(--border-strong)); }
.choice input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.choice-icon { width: 32px; height: 32px; border-radius: 9px; display: grid; place-items: center; flex-shrink: 0; background: var(--primary-soft); color: var(--primary-text); }
.choice-icon svg.icon { width: 16px; height: 16px; }
.choice-icon.success { background: var(--success-soft); color: var(--success); }
.choice-icon.warning { background: var(--warning-soft); color: var(--warning); }
.choice-icon.danger { background: var(--danger-soft); color: var(--danger); }
.choice-icon.muted { background: var(--bg-tertiary); color: var(--text-secondary); }
.choice-text { display: grid; gap: .1rem; min-width: 0; padding-right: 1.1rem; }
.choice-text strong { font-size: .86rem; color: var(--text-primary); }
.choice-text small { font-size: .74rem; line-height: 1.35; color: var(--text-muted); }
.choice-check { position: absolute; top: .5rem; right: .5rem; width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: #fff; opacity: 0; transform: scale(.6); transition: opacity var(--transition), transform var(--transition); }
.choice-check svg.icon { width: 11px; height: 11px; stroke-width: 3; }
.choice:has(input:checked) { border-color: var(--primary); background: color-mix(in srgb, var(--primary-soft) 60%, var(--bg-secondary)); box-shadow: 0 0 0 1px var(--primary); }
.choice:has(input:checked) .choice-check { opacity: 1; transform: none; }
.choice:has(input:focus-visible) { box-shadow: var(--focus-ring); }
.choice:has(input:disabled) { opacity: .6; cursor: default; }
.field:has([data-error-for]:not(:empty)) .choice { border-color: var(--danger); }

/* ---------- Toolbar / filters ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; padding: .9rem 1.25rem; border-bottom: 1px solid var(--border-color); }
.toolbar .input-group { flex: 1 1 220px; max-width: 360px; }
.toolbar .select { width: auto; min-width: 150px; }
@media (max-width: 640px) { .toolbar .select, .toolbar .input-group { flex: 1 1 100%; max-width: none; } }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; }
/* A table wider than the screen scrolls sideways: its empty or error message keeps to the part in view
   (the wrapper's width, 100cqi) instead of being centered on the whole table. 2.5rem: the cell's padding. */
.table-wrap:has(td > .state) { container-type: inline-size; }
.table-wrap td > .state { position: sticky; left: 1.25rem; width: calc(100cqi - 2.5rem); }
.table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.table th, .table td { padding: .7rem 1.25rem; text-align: left; border-bottom: 1px solid var(--border-color); vertical-align: middle; }
.table th { font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); background: var(--bg-inset); white-space: nowrap; }
.table tbody tr { transition: background var(--transition); }
/* The row that is in effect right now (e.g. the current term); hover still wins. */
.table tbody tr.row-current { background: color-mix(in srgb, var(--success) 7%, transparent); }
.table tbody tr.row-current td:first-child { box-shadow: inset 3px 0 0 var(--success); }
.table tbody tr:hover { background: var(--bg-hover); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .sortable { cursor: pointer; user-select: none; }
.table .sortable:hover { color: var(--text-primary); }
.table .sort-indicator { opacity: .7; margin-left: .25rem; }
.table .actions { text-align: right; white-space: nowrap; }
.table .cell-title { font-weight: 600; color: var(--text-primary); }
/* More than one badge in a cell: side by side while they fit, stacked when they don't. */
.table .cell-badges { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; }
/* A title that opens a record looks like a link: brand color, underlined on hover or keyboard focus. */
.table a.cell-title {
    color: var(--primary-text);
    text-decoration: underline; text-decoration-color: transparent; text-underline-offset: 3px; text-decoration-thickness: 1.5px;
    transition: color var(--transition), text-decoration-color var(--transition);
}
.table a.cell-title::after {
    content: "\2192"; display: inline-block; margin-left: .35rem;
    opacity: 0; transform: translateX(-4px);
    transition: opacity var(--transition), transform var(--transition);
}
.table a.cell-title:hover, .table a.cell-title:focus-visible,
.table tbody tr:has(a.cell-title):hover a.cell-title { text-decoration-color: currentColor; }
.table a.cell-title:focus-visible::after,
.table tbody tr:has(a.cell-title):hover a.cell-title::after { opacity: 1; transform: none; }
/* The whole row opens the record (app.js initRowLinks). */
.table tbody tr:has(a.cell-title) { cursor: pointer; }
@media (prefers-reduced-motion: reduce) { .table a.cell-title::after { transition: none; transform: none; } }
.table .cell-sub { display: block; font-size: .76rem; color: var(--text-muted); }
/* A row that opens to the rows under it (DataTable rowAfter): the Activities page's row of an
   activity's copies, each copy a .row-child, its place lined up under the title. */
.table .row-toggle {
    display: inline-flex; align-items: center; gap: .35rem;
    padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.table .row-toggle svg.icon { width: 16px; height: 16px; color: var(--text-muted); transition: transform var(--transition); }
.table .row-toggle[aria-expanded="true"] svg.icon { transform: rotate(90deg); }
.table .row-toggle:hover .cell-title { color: var(--primary-text); }
.table .row-toggle:focus-visible { outline: none; box-shadow: var(--focus-ring); border-radius: 4px; }
.table tbody tr:has(.row-toggle) { cursor: pointer; }
.table tbody tr.row-child td { padding-top: .45rem; padding-bottom: .45rem; }
.table tbody tr.row-child td.child-title { padding-left: calc(1.25rem + 16px + .35rem); }
@media (prefers-reduced-motion: reduce) { .table .row-toggle svg.icon { transition: none; } }
.table-compact th, .table-compact td { padding: .5rem .9rem; }
/* A phone cannot show eight columns side by side, so a labelled row becomes a
   card: each cell carries its column header as its own label (data-label and
   .is-row-title are filled in by render() in core/dom.js). Print keeps the
   real table, and a table meant to stay a grid opts out with data-no-stack. */
@media screen and (max-width: 640px) {
    .table-wrap:has(.table-stack) { overflow-x: visible; }
    .table-stack thead { display: none; }
    .table-stack, .table-stack tbody, .table-stack td { display: block; width: auto; }

    /* A column, so the row title can lead and the buttons can close the card. */
    .table-stack tr { display: flex; flex-direction: column; padding: .7rem .9rem; border-bottom: 1px solid var(--border-color); }
    .table-stack tr:last-child { border-bottom: 0; }
    .table-stack tbody tr.row-current td:first-child { box-shadow: none; }
    .table-stack tbody tr.row-current { box-shadow: inset 3px 0 0 var(--success); }

    .table-stack td { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .2rem 1rem; padding: .22rem 0; border: 0; text-align: right; }
    .table-stack td[data-label]::before {
        content: attr(data-label);
        flex: 0 0 auto; max-width: 45%;
        text-align: left; font-size: .67rem; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--text-muted);
    }
    /* Anything secondary in a cell takes a line of its own rather than crowding the value. */
    .table-stack td .cell-sub, .table-stack td .progress { flex-basis: 100%; text-align: right; }
    .table-stack td .cell-badges { justify-content: flex-end; }

    .table-stack td.is-row-title { order: -1; display: block; margin-bottom: .35rem; text-align: left; }
    .table-stack td.is-row-title::before { display: block; margin-bottom: .1rem; }
    .table-stack td.is-row-title .cell-sub { text-align: left; }
    .table-stack td.is-row-title .cell-title { font-size: .95rem; }

    /* Checkbox and buttons carry no header, so they bookend the card. */
    .table-stack td.select-col { order: -2; justify-content: flex-start; padding-bottom: .25rem; }
    .table-stack td.actions { order: 99; justify-content: flex-end; margin-top: .4rem; padding-top: .45rem; border-top: 1px solid var(--border-color); }
    /* An empty or error state still spans the card. */
    .table-stack td:not([data-label]):only-child { display: block; text-align: left; }

    /* A row under another (a copy under its activity) is a card set in under it, without its empty
       cells; the row it opens from has no buttons of its own. */
    .table-stack tr.row-child { padding-left: 1.75rem; }
    .table-stack tr.row-child td:empty, .table-stack tr:has(.row-toggle) td.actions:empty { display: none; }
    .table.table-stack tbody tr.row-child td.child-title { padding-left: 0; }
}


/* Row selection + bulk actions (DataTable bulkActions) */
.table .select-col { width: 1%; padding-right: 0; }
.table .select-col input { width: 16px; height: 16px; margin: 0; vertical-align: middle; cursor: pointer; accent-color: var(--primary); }
.table tbody tr.is-selected, .table tbody tr.is-selected:hover { background: var(--primary-soft); }
.bulk-bar {
    display: flex; flex-wrap: wrap; align-items: center; gap: .5rem;
    padding: .55rem 1.25rem;
    background: var(--primary-soft); border-bottom: 1px solid var(--border-color);
}
.bulk-count { font-weight: 650; color: var(--primary-text); font-size: .86rem; }
.bulk-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-left: auto; }
.bulk-failures { margin: 0; padding: 0; list-style: none; display: grid; gap: .5rem; max-height: 50vh; overflow-y: auto; }
.bulk-failures li { padding: .55rem .75rem; border-radius: var(--radius); background: var(--danger-soft); }
.bulk-failures strong { display: block; color: var(--text-primary); }
.bulk-failures span { font-size: .84rem; color: var(--text-secondary); }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: .3rem;
    padding: .15rem .55rem;
    border-radius: 999px;
    font-size: .72rem; font-weight: 650; line-height: 1.5;
    background: var(--bg-tertiary); color: var(--text-secondary);
    white-space: nowrap; text-transform: capitalize;
}
.badge-primary { background: var(--primary-soft); color: var(--primary-text); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-info { background: var(--info-soft); color: var(--info); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
/* An inline snippet of configuration: an env var, a flag, a code value. */
.code-chip { display: inline-block; padding: .1rem .4rem; border-radius: 6px; background: var(--bg-inset); border: 1px solid var(--border-color); font-family: var(--font-mono); font-size: .74rem; color: var(--text-secondary); }
.badge-dot { padding-left: .45rem; }
.badge-dot .dot { width: 6px; height: 6px; }

/* ---------- Alerts ---------- */
.alert { display: flex; gap: .7rem; align-items: flex-start; padding: .8rem 1rem; border-radius: var(--radius); border: 1px solid transparent; font-size: .86rem; }
.alert svg { margin-top: 1px; }
.alert-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.alert-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.alert-warning { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }
.alert-danger { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert strong { color: inherit; }
.alert p { margin: 0; color: var(--text-primary); }

/* ---------- Dropdown ---------- */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 6px);
    min-width: 200px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: .35rem;
    z-index: 50;
}
.dropdown-menu[hidden] { display: none; }
/* In a page header's actions a menu opens from its button's left edge: where the actions wrap under the
   heading (a phone, a tablet) the button sits at the left, and a menu ending at its right edge opens off the screen. */
.page-actions .dropdown-menu { left: 0; right: auto; }
.dropdown-item {
    display: flex; align-items: center; gap: .6rem; width: 100%;
    padding: .5rem .65rem; border: 0; border-radius: 7px;
    background: transparent; color: var(--text-primary);
    font: inherit; text-align: left; cursor: pointer;
}
.dropdown-item:hover { background: var(--bg-hover); text-decoration: none; }
.dropdown-divider { height: 1px; background: var(--border-color); margin: .35rem 0; }

/* Theme switch (partials/theme-menu.php: the top bar, the sign-in page, the Download page): one button
   showing the theme's icon, which opens Light, Dark and System as a short list, the chosen one with a
   check: no tinted row, no heading (design B, 2026-10-28). */
.theme-switch-toggle[aria-expanded="true"] { background: var(--bg-hover); color: var(--text-primary); }
.theme-switch-menu { min-width: 216px; padding: 6px; }
.theme-switch-item {
    min-height: 44px; gap: .75rem; padding: 0 .75rem; border-radius: 8px;
    color: var(--text-secondary); font-size: .875rem; font-weight: 500;
}
.theme-switch-item:hover, .theme-switch-item[aria-pressed="true"] { color: var(--text-primary); }
.theme-switch-item[aria-pressed="true"] { font-weight: 600; }
.theme-switch-item > span { flex: 1; }
.theme-switch-item svg.icon { width: 18px; height: 18px; flex: none; }
.theme-switch-check { visibility: hidden; color: var(--primary-text); }
.theme-switch-item[aria-pressed="true"] .theme-switch-check { visibility: visible; }
@media (max-width: 640px) {
    /* On a phone the menu opens under the bar's right edge. */
    .topbar .theme-switch { position: static; }
    .topbar .theme-switch-menu { right: .75rem; }
}

/* Settings → Appearance (settings/index.js): the three side by side in a sunken track, each with its
   word, the choice on a raised thumb that slides to it (design C, 2026-10-28). */
.theme-switch-track {
    --seg-i: 0; --seg-gap: 4px; --seg-pad: 4px;
    position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--seg-gap);
    padding: var(--seg-pad); border: 1px solid var(--border-color); border-radius: 12px;
    background: var(--switch-track);
}
.theme-switch-option {
    position: relative; display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
    height: 44px; padding: 0 .5rem;
    border: 0; border-radius: 9px; background: transparent; color: var(--text-secondary);
    font: inherit; font-size: .875rem; font-weight: 600; cursor: pointer;
    transition: color var(--transition);
}
.theme-switch-option svg.icon { width: 17px; height: 17px; }
.theme-switch-option:hover, .theme-switch-option[aria-pressed="true"] { color: var(--text-primary); }
.theme-switch-option:focus-visible { box-shadow: 0 0 0 2px var(--primary); }
.theme-switch-thumb {
    position: absolute; top: var(--seg-pad); left: var(--seg-pad);
    width: calc((100% - 2 * var(--seg-pad) - 2 * var(--seg-gap)) / 3); height: 44px; border-radius: 9px;
    background: var(--switch-thumb); box-shadow: var(--switch-thumb-shadow);
    transform: translateX(calc(var(--seg-i) * (100% + var(--seg-gap))));
    pointer-events: none;
}
/* Placed by :has() from the buttons' aria-pressed, which core/theme.js keeps. */
.theme-switch-track:has([data-theme-set="dark"][aria-pressed="true"]) { --seg-i: 1; }
.theme-switch-track:has([data-theme-set="system"][aria-pressed="true"]) { --seg-i: 2; }
.theme-switch-track:not(:has([aria-pressed="true"])) .theme-switch-thumb { visibility: hidden; }
/* It slides only under the pointer or the keyboard, so no page opens with it moving; !important outlasts .theme-switching. */
.theme-switch-track:is(:hover, :focus-within) .theme-switch-thumb { transition: transform 260ms cubic-bezier(.3, .7, .4, 1) !important; }
@media (prefers-reduced-motion: reduce) {
    .theme-switch-track:is(:hover, :focus-within) .theme-switch-thumb { transition: none !important; }
}

/* Notification panel */
.notification-panel { width: min(380px, calc(100vw - 1.5rem)); padding: 0; }
.notification-panel-header { display: flex; justify-content: space-between; align-items: center; padding: .75rem 1rem; border-bottom: 1px solid var(--border-color); }
.notification-list { max-height: 380px; overflow-y: auto; }
.notification-item { display: flex; gap: .7rem; padding: .75rem 1rem; border-bottom: 1px solid var(--border-color); color: var(--text-primary); cursor: pointer; }
.notification-item:hover { background: var(--bg-hover); text-decoration: none; }
.notification-item.unread { background: color-mix(in srgb, var(--primary-soft) 55%, transparent); }
.notification-item .n-icon { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; background: var(--bg-tertiary); color: var(--text-secondary); flex-shrink: 0; }
.notification-item .n-title { font-weight: 600; font-size: .84rem; }
.notification-item .n-meta { font-size: .76rem; color: var(--text-muted); }
/* The Notifications page's Delete: on the row under the pointer or the keyboard, always on a touch screen. */
.notification-item .n-delete { flex-shrink: 0; align-self: center; width: 32px; height: 32px; padding: 0; color: var(--text-muted); opacity: 0; }
.notification-item .n-delete svg.icon { width: 16px; height: 16px; }
.notification-item:is(:hover, :focus-within) .n-delete { opacity: 1; }
.notification-item .n-delete:hover { color: var(--danger); background: var(--danger-soft); }
@media (hover: none) { .notification-item .n-delete { opacity: 1; } }
.notification-panel-footer { padding: .6rem; text-align: center; }
@media (max-width: 640px) {
    /* The panel hangs from the top bar, edge to edge: under the bell it ran off the left of a phone. */
    .notification-bell { position: static; }
    .notification-panel { left: .75rem; right: .75rem; width: auto; }
    .notification-list { max-height: min(380px, calc(100dvh - var(--topbar-height) - 8rem)); }
    /* The Notifications page: Mark read goes under the text instead of narrowing it to a column; Delete stays beside it. */
    .notification-item { flex-wrap: wrap; row-gap: .25rem; }
    .notification-item > .grow { flex-basis: calc(100% - 32px - .7rem); }
    .notification-item:has(> .n-delete) > .grow { flex-basis: calc(100% - 64px - 1.4rem); }
    .notification-item > [data-mark] { order: 1; margin-left: calc(32px + .7rem - .6rem); }
}

/* ---------- Modal ---------- */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 100;
    background: var(--overlay);
    display: flex; align-items: flex-start; justify-content: center;
    padding: 5vh 1rem;
    overflow-y: auto;
    animation: fade-in 120ms ease;
}
.modal {
    width: 100%; max-width: 560px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: modal-in 160ms ease;
}
.modal-lg { max-width: 780px; }

/* ---------- File viewer (core/viewer.js) ---------- */
.modal.modal-viewer { max-width: min(1100px, 100%); display: flex; flex-direction: column; height: 90vh; height: 90dvh; }
.modal-viewer .modal-body { flex: 1; min-height: 0; padding: 0; display: flex; }
.viewer { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.viewer-toolbar { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .5rem 1rem; border-bottom: 1px solid var(--border-color); }
.viewer-file { display: inline-flex; align-items: center; gap: .4rem; min-width: 0; flex: 1 1 180px; font-size: .8rem; color: var(--text-secondary); }
.viewer-file > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-file svg.icon { width: 15px; height: 15px; }
.viewer-status { font-size: .78rem; color: var(--text-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.viewer-zoom { display: inline-flex; align-items: center; gap: .15rem; font-size: .76rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.viewer-zoom [data-zoom-out] span { display: inline-block; width: 18px; font-size: 1.1rem; line-height: 18px; }
.viewer-body { flex: 1; min-height: 0; overflow: auto; scrollbar-gutter: stable; background: var(--bg-tertiary); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.viewer-body:focus-visible { outline: none; box-shadow: inset var(--focus-ring); }
.viewer-state { height: 100%; min-height: 240px; display: grid; place-content: center; justify-items: center; gap: .6rem; padding: 2rem; text-align: center; color: var(--text-secondary); }
.viewer-state > svg.icon { width: 36px; height: 36px; color: var(--text-muted); }
.viewer-state p { margin: 0; max-width: 28rem; }
/* PDF pages and the Word page stay white paper in both themes, like the printed document. */
.viewer-pdf { padding: 1rem; }
.pdf-page { margin: 0 auto 1rem; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .2), 0 4px 14px rgba(0, 0, 0, .08); }
.pdf-page canvas { display: block; width: 100%; height: 100%; }
.viewer-doc { padding: 1.25rem; }
.doc-page {
    max-width: 816px; margin: 0 auto; padding: 3.5rem 4rem;
    background: #fff; color: #1f2328; box-shadow: 0 1px 3px rgba(0, 0, 0, .2), 0 4px 14px rgba(0, 0, 0, .08);
    font-family: Calibri, Carlito, "Segoe UI", Arial, sans-serif; font-size: 11pt; line-height: 1.5; overflow-wrap: anywhere;
}
.doc-page h1, .doc-page h2, .doc-page h3, .doc-page h4 { color: #1f3864; margin: 1.2em 0 .5em; line-height: 1.25; }
.doc-page h1 { font-size: 20pt; } .doc-page h2 { font-size: 16pt; } .doc-page h3 { font-size: 13pt; }
.doc-page p { margin: 0 0 .7em; }
.doc-page a { color: #0b57d0; }
.doc-page img { max-width: 100%; height: auto; }
.doc-page table { border-collapse: collapse; margin: .5em 0 1em; max-width: 100%; }
.doc-page td, .doc-page th { border: 1px solid #b7bdc6; padding: .35em .55em; vertical-align: top; }
.doc-page ul, .doc-page ol { margin: 0 0 .7em; padding-left: 1.6em; }
.viewer-text { margin: 1rem; padding: 1rem 1.25rem; background: var(--bg-secondary); color: var(--text-primary); border: 1px solid var(--border-color); border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: anywhere; font-size: .84rem; }
.viewer-media { min-height: 100%; display: grid; place-items: center; padding: 1rem; }
.viewer-media img, .viewer-media video { max-width: 100%; max-height: calc(90dvh - 9rem); border-radius: var(--radius-sm); }
.viewer-media audio { width: min(480px, 100%); }
@media (max-width: 640px) {
    .modal-backdrop:has(.modal-viewer) { padding: 0; }
    .modal.modal-viewer { height: 100dvh; border-radius: 0; border: 0; }
    .modal-viewer .modal-header { border-radius: 0; }
    .viewer-label { display: none; }
    .viewer-pdf, .viewer-doc { padding: .5rem; }
    .doc-page { padding: 1.5rem 1.1rem; font-size: 10.5pt; }
}

/* A submitted file with View and Download (activities) */
.file-chip { display: flex; align-items: center; gap: .6rem; padding: .45rem .5rem .45rem .6rem; border: 1px solid var(--border-color); border-radius: var(--radius); background: var(--bg-inset); }
.file-chip-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; background: var(--info-soft); color: var(--info); }
.file-chip-icon svg.icon { width: 15px; height: 15px; }
.file-chip-name { flex: 1; min-width: 0; font-size: .84rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-sm { max-width: 420px; }
.modal-header {
    --header-tint: var(--primary);
    position: relative; overflow: hidden;
    display: flex; justify-content: space-between; align-items: center; gap: .75rem;
    padding: 1.05rem 1.25rem; border-bottom: 1px solid var(--border-color);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    background: linear-gradient(120deg, color-mix(in srgb, var(--header-tint) 13%, transparent), transparent 62%);
}
.modal-header.tone-danger { --header-tint: var(--danger); }
.modal-header.tone-warning { --header-tint: var(--warning); }
.modal-header.tone-success { --header-tint: var(--success); }
.modal-header.tone-info { --header-tint: var(--info); }
.modal-header > :not(.modal-header-art) { position: relative; }
/* Large faded copy of the header icon; decorative. */
.modal-header svg.modal-header-art { position: absolute; right: 3.2rem; top: 58%; width: 112px; height: 112px; stroke-width: 1.2; color: var(--header-tint); opacity: .1; transform: translateY(-50%); pointer-events: none; }
.modal-header h2 { margin: 0; font-size: 1.05rem; }
.modal-heading { display: flex; align-items: center; gap: .8rem; min-width: 0; }
.modal-titles { min-width: 0; }
.modal-subtitle { margin: .15rem 0 0; font-size: .8rem; color: var(--text-secondary); }
.modal-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex-shrink: 0; background: var(--primary-soft); color: var(--primary-text); box-shadow: inset 0 0 0 1px color-mix(in srgb, currentColor 22%, transparent); }
.modal-icon svg.icon { width: 19px; height: 19px; }
.modal-icon.success { background: var(--success-soft); color: var(--success); }
.modal-icon.warning { background: var(--warning-soft); color: var(--warning); }
.modal-icon.danger { background: var(--danger-soft); color: var(--danger); }
.modal-icon.info { background: var(--info-soft); color: var(--info); }
/* Confirmation: a larger round icon with the message set under the title. */
.modal-confirm .modal-header { border-bottom: 0; align-items: flex-start; padding-bottom: 0; background: none; }
.modal-confirm .modal-header-art { display: none; }
.modal-confirm .modal-heading { gap: .9rem; padding-top: .15rem; }
.modal-confirm .modal-icon { width: 42px; height: 42px; border-radius: 50%; }
.modal-confirm .modal-icon svg.icon { width: 20px; height: 20px; }
.modal-confirm .modal-body { padding: .35rem 1.25rem 1.25rem calc(1.25rem + 42px + .9rem); color: var(--text-secondary); }
@media (max-width: 480px) { .modal-confirm .modal-body { padding-left: 1.25rem; } }
.modal-body { padding: 1.25rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: .5rem; padding: .9rem 1.25rem; border-top: 1px solid var(--border-color); background: var(--bg-inset); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
body.modal-open { overflow: hidden; }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.modal.modal-pulse { animation: modal-pulse 220ms ease; }
@keyframes modal-pulse { 50% { transform: scale(1.015); } }

/* ---------- Dynamic Island (toasts, activity, new notifications) ---------- */
/* One pill of dark frosted glass at the top center in both themes, as the app's island (FrostedGlass): the page
   shows through blurred, under a tint deep enough for its light text over the white top bar (lighter in dark mode).
   core/island.js sets its size to fit the content. */
.island {
    --island-bg: rgba(10, 11, 15, .8);
    --island-text: #f5f7fb;
    --island-muted: #c3cad6;
    --island-accent: #34d399;
    --island-spring: cubic-bezier(.34, 1.3, .64, 1);
    --island-ease: cubic-bezier(.32, .72, 0, 1);

    position: fixed; top: max(.6rem, env(safe-area-inset-top)); left: 50%; z-index: 200;
    width: 120px; height: 36px; max-width: calc(100vw - 1.5rem);
    border-radius: 18px;
    background: linear-gradient(rgba(255, 255, 255, .16), rgba(255, 255, 255, .04)), var(--island-bg);
    -webkit-backdrop-filter: blur(22px) saturate(160%);
    backdrop-filter: blur(22px) saturate(160%);
    color: var(--island-text);
    box-shadow: 0 12px 30px rgba(8, 10, 16, .28), inset 0 0 0 1px rgba(255, 255, 255, .24);
    overflow: hidden;
    font-size: .86rem;
    transform: translateX(-50%);
    transition:
        width 560ms var(--island-spring), height 560ms var(--island-spring), border-radius 560ms var(--island-ease),
        transform 460ms var(--island-spring), opacity 240ms ease;
}
[data-theme="dark"] .island { --island-bg: rgba(10, 11, 15, .46); box-shadow: 0 12px 36px rgba(0, 0, 0, .6), inset 0 0 0 1px rgba(255, 255, 255, .24); }
/* No blur to frost it, or a viewer who asks for less transparency: the solid pill. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
    .island, [data-theme="dark"] .island { --island-bg: #0a0b0f; }
}
@media (prefers-reduced-transparency: reduce) {
    .island, [data-theme="dark"] .island { --island-bg: #0a0b0f; -webkit-backdrop-filter: none; backdrop-filter: none; }
}
.island[data-state="idle"] { opacity: 0; transform: translateX(-50%) translateY(-12px) scale(.6); pointer-events: none; }

.island-inner {
    position: absolute; top: 0; left: 50%;
    display: flex; align-items: center; gap: .65rem;
    width: max-content; max-width: min(440px, calc(100vw - 1.5rem));
    padding: .55rem .55rem .6rem;
    opacity: 0; filter: blur(6px);
    transform: translateX(-50%) scale(.9);
    transition: opacity 260ms ease 110ms, filter 300ms ease 90ms, transform 460ms var(--island-ease) 60ms;
}
.island-inner.entered { opacity: 1; filter: none; transform: translateX(-50%); }
.island-inner.leaving { opacity: 0; filter: blur(4px); transform: translateX(-50%) scale(.95); transition-duration: 180ms; transition-delay: 0s; }

.island-inner[data-type="success"] { --island-accent: #34d399; }
.island-inner[data-type="error"] { --island-accent: #f87171; }
.island-inner[data-type="warning"] { --island-accent: #fbbf24; }
.island-inner[data-type="info"] { --island-accent: #60a5fa; }
.island-inner[data-type="notify"] { --island-accent: #a78bfa; }

.island-busy { padding: .45rem 1rem .45rem .6rem; gap: .55rem; }
.island-busy-label { font-weight: 600; letter-spacing: .01em; white-space: nowrap; }
.island-spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, .18); border-top-color: var(--island-accent); animation: spin .75s linear infinite; }

.island-icon {
    width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
    display: grid; place-items: center;
    color: var(--island-accent);
    background: color-mix(in srgb, var(--island-accent) 18%, transparent);
}
.island-icon svg.icon { width: 17px; height: 17px; }
.island-inner.entered[data-type="notify"] .island-icon { animation: island-ring 1.1s ease-out 2; }
.island-inner.entered[data-type="notify"] .island-icon svg { animation: island-swing 1.1s ease-in-out; transform-origin: 50% 15%; }

.island-text { display: grid; gap: 1px; min-width: 0; line-height: 1.35; padding-right: .15rem; overflow-wrap: anywhere; }
.island-text strong { font-weight: 650; }
.island-text strong + span { color: var(--island-muted); font-size: .8rem; }

.island-link { display: flex; align-items: center; gap: .65rem; min-width: 0; color: inherit; border-radius: 12px; }
.island-link:hover { text-decoration: none; }
.island-link:hover .island-chevron { color: var(--island-text); transform: translateX(2px); }
.island-chevron { color: var(--island-muted); transition: transform var(--transition), color var(--transition); }

.island-close {
    width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; margin-left: .1rem;
    display: grid; place-items: center;
    border: 0; background: rgba(255, 255, 255, .08); color: var(--island-muted); cursor: pointer;
    transition: background var(--transition), color var(--transition);
}
.island-close:hover { background: rgba(255, 255, 255, .16); color: var(--island-text); }
.island-close svg.icon { width: 14px; height: 14px; }
.island-close:focus-visible, .island-link:focus-visible { outline: 2px solid var(--island-accent); outline-offset: 2px; }

.island-progress { position: absolute; left: 18px; right: 18px; bottom: 3px; height: 2px; border-radius: 2px; background: var(--island-accent); opacity: .5; transform-origin: left center; }

@keyframes island-ring {
    0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--island-accent) 45%, transparent); }
    100% { box-shadow: 0 0 0 9px transparent; }
}
@keyframes island-swing {
    0%, 100% { transform: rotate(0); } 20% { transform: rotate(14deg); } 40% { transform: rotate(-11deg); }
    60% { transform: rotate(7deg); } 80% { transform: rotate(-4deg); }
}
@media (max-width: 760px) { .island { top: max(.5rem, env(safe-area-inset-top)); } }
@media (prefers-reduced-motion: reduce) { .island-progress { opacity: 0; } }

/* ---------- Tabs ---------- */
/* Tabs: underline bar; the selected tab gets a rounded brand indicator, hover a soft tile. */
.tabs {
    display: flex; gap: .2rem; margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto; overflow-y: hidden; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
    position: relative; flex-shrink: 0;
    display: inline-flex; align-items: center; gap: .5rem;
    padding: .7rem .95rem .8rem;
    border: 0; border-radius: 9px 9px 0 0; background: none;
    color: var(--text-secondary); font: inherit; font-size: .9rem; font-weight: 600; white-space: nowrap;
    cursor: pointer;
    transition: color var(--transition), background var(--transition);
}
.tab::after {
    content: ""; position: absolute; left: .6rem; right: .6rem; bottom: 0; height: 3px;
    border-radius: 3px 3px 0 0; background: var(--primary);
    transform: scaleX(0); opacity: 0;
    transition: transform 220ms cubic-bezier(.2, .8, .2, 1), opacity 160ms ease;
}
.tab svg.icon { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-muted); transition: color var(--transition); }
.tab:hover { color: var(--text-primary); background: var(--bg-hover); }
.tab:hover svg.icon { color: var(--text-secondary); }
.tab:focus-visible { outline: none; box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--primary) 55%, transparent); }
.tab[aria-selected="true"] { color: var(--primary-text); }
.tab[aria-selected="true"]::after { transform: scaleX(1); opacity: 1; box-shadow: 0 -2px 10px color-mix(in srgb, var(--primary) 45%, transparent); }
.tab[aria-selected="true"] svg.icon { color: var(--primary); }
.tab[aria-selected="true"]:hover { background: color-mix(in srgb, var(--primary) 7%, transparent); }
.tab-count {
    min-width: 1.5rem; padding: .08rem .45rem; border-radius: 999px;
    font-size: .7rem; font-weight: 700; line-height: 1.45; text-align: center; font-variant-numeric: tabular-nums;
    color: var(--text-secondary); background: var(--bg-tertiary);
    transition: color var(--transition), background var(--transition);
}
.tab:hover .tab-count { color: var(--text-primary); background: var(--border-strong); }
.tab[aria-selected="true"] .tab-count { color: var(--on-primary); background: var(--primary); }
@media (prefers-reduced-motion: reduce) { .tab::after { transition: none; } }
/*
 * Phones: a scrolling strip with a hidden scrollbar hides whichever tabs fall off the
 * edge, with nothing to say they are there. The tabs wrap into pills instead, so every
 * tab is visible and each is a comfortable tap target.
 */
@media (max-width: 640px) {
    .tabs { flex-wrap: wrap; gap: .4rem; overflow: visible; border-bottom: 0; }
    .tab {
        flex: 1 1 auto; justify-content: center; gap: .4rem;
        min-height: 40px; padding: .45rem .8rem;
        border: 1px solid var(--border-color); border-radius: 999px;
        font-size: .84rem;
    }
    .tab::after { display: none; }
    .tab[aria-selected="true"] { border-color: color-mix(in srgb, var(--primary) 55%, transparent); background: var(--primary-soft); }
    .tab[aria-selected="true"]:hover { background: var(--primary-soft); }
}

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap; padding: .8rem 1.25rem; border-top: 1px solid var(--border-color); font-size: .82rem; color: var(--text-secondary); }
.pagination-pages { display: flex; gap: .25rem; flex-wrap: wrap; }
.pagination-info { display: flex; align-items: center; gap: .5rem 1rem; flex-wrap: wrap; }
.per-page { display: flex; align-items: center; gap: .5rem; margin: 0; font-weight: 400; }
.per-page .select { width: auto; padding-block: .3rem; font-size: .82rem; }
.page-btn { min-width: 32px; height: 32px; padding: 0 .5rem; border: 1px solid var(--border-color); border-radius: 7px; background: var(--bg-secondary); color: var(--text-primary); font: inherit; cursor: pointer; }
.page-btn:hover:not(:disabled) { background: var(--bg-hover); }
.page-btn[aria-current="page"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.page-btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- States ---------- */
.state { padding: 2.5rem 1.25rem; text-align: center; color: var(--text-secondary); }
.state > svg { width: 40px; height: 40px; color: var(--text-muted); margin-bottom: .5rem; stroke-width: 1.6; }
.state h3 { margin-bottom: .25rem; }
.state p { margin: 0 auto .75rem; max-width: 26rem; color: var(--text-muted); }
.state-error > svg { color: var(--danger); }
.state-sm { padding: 1.25rem; }
.state-sm > svg { width: 30px; height: 30px; }
.state p:last-child { margin-bottom: 0; }

.spinner { width: 22px; height: 22px; border: 3px solid var(--border-strong); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton { background: linear-gradient(90deg, var(--skeleton) 25%, var(--skeleton-shine) 50%, var(--skeleton) 75%); background-size: 200% 100%; animation: shimmer 1.3s infinite; border-radius: 6px; min-height: 12px; }
.skeleton-line { height: 12px; margin: .45rem 0; }
.skeleton-card { height: 110px; border-radius: var(--radius-lg); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Progress & charts ---------- */
.progress { height: 8px; border-radius: 99px; background: var(--chart-track); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: inherit; background: var(--primary); transition: width 400ms ease; }
.progress.success > span { background: var(--success); }
.progress.warning > span { background: var(--warning); }
.progress.danger > span { background: var(--danger); }
.progress-xs { height: 5px; max-width: 220px; }

.bar-chart { display: grid; gap: .7rem; }
.bar-row { display: grid; grid-template-columns: minmax(80px, 150px) 1fr auto; gap: .75rem; align-items: center; font-size: .82rem; }
.bar-row .bar-label { color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .bar-track { display: block; height: 10px; border-radius: 99px; background: var(--chart-track); overflow: hidden; }
.bar-row .bar-fill { display: block; height: 100%; border-radius: inherit; background: var(--chart-1); }
.bar-row .bar-value { font-weight: 650; min-width: 2.5rem; text-align: right; }

.donut-wrap { display: flex; align-items: center; gap: 1.25rem; flex-wrap: wrap; }
.donut { width: 132px; height: 132px; }
.donut circle { fill: none; stroke-width: 16; }
.donut .donut-track { stroke: var(--chart-track); }
.donut text { fill: var(--text-primary); font-weight: 700; font-size: 20px; }
.legend { display: grid; gap: .4rem; font-size: .82rem; }
.legend-item { display: flex; align-items: center; gap: .5rem; color: var(--text-secondary); }
.legend-swatch { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* App tooltip (core/tooltip.js): replaces title boxes; placed with fixed coordinates, arrow follows the target. */
.tooltip {
    --tooltip-shift: 4px;
    position: fixed; z-index: 1000; top: 0; left: 0;
    max-width: min(18rem, calc(100vw - 16px)); padding: .38rem .6rem;
    border-radius: 7px; border: 1px solid var(--tooltip-border);
    background: var(--tooltip-bg); color: var(--tooltip-text); box-shadow: var(--tooltip-shadow);
    font-size: .76rem; font-weight: 550; line-height: 1.4; letter-spacing: .005em;
    overflow-wrap: anywhere; pointer-events: none;
    opacity: 0; translate: 0 var(--tooltip-shift); scale: .96;
    transition: opacity 120ms ease, translate 160ms cubic-bezier(.2, .8, .2, 1), scale 160ms cubic-bezier(.2, .8, .2, 1);
}
.tooltip[data-placement="bottom"] { --tooltip-shift: -4px; }
.tooltip[data-placement="left"] { translate: 4px 0; }
.tooltip[data-placement="right"] { translate: -4px 0; }
.tooltip.is-visible { opacity: 1; translate: 0 0; scale: 1; }
.tooltip-arrow {
    position: absolute; width: 8px; height: 8px;
    background: inherit; border: inherit; border-radius: 0 0 2px 0;
    translate: -50% 0; rotate: 45deg;
}
.tooltip[data-placement="top"] .tooltip-arrow { top: calc(100% - 4px); border-width: 0 1px 1px 0; }
.tooltip[data-placement="bottom"] .tooltip-arrow { bottom: calc(100% - 4px); border-width: 1px 0 0 1px; border-radius: 2px 0 0 0; }
.tooltip[data-placement="left"] .tooltip-arrow,
.tooltip[data-placement="right"] .tooltip-arrow { translate: 0 -50%; }
.tooltip[data-placement="left"] .tooltip-arrow { left: calc(100% - 4px); border-width: 1px 1px 0 0; border-radius: 0 2px 0 0; }
.tooltip[data-placement="right"] .tooltip-arrow { right: calc(100% - 4px); border-width: 0 0 1px 1px; border-radius: 0 0 0 2px; }
@media (prefers-reduced-motion: reduce) { .tooltip { transition: opacity 120ms ease; translate: none; scale: none; } }
@media print { .tooltip { display: none !important; } }

/* Chart tooltip (core/chart.js): value first, label second. */
[data-tips], .lc-plot { position: relative; }
.chart-tooltip {
    position: absolute; z-index: 5; top: 0; left: 0;
    display: grid; gap: .05rem; min-width: 7rem; max-width: 16rem; padding: .45rem .65rem;
    background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--radius-sm); box-shadow: var(--shadow-md);
    font-size: .76rem; line-height: 1.35; pointer-events: none;
    transform: translate(-50%, calc(-100% - 8px));
}
.chart-tooltip[data-align="start"] { transform: translate(-12px, calc(-100% - 8px)); }
.chart-tooltip[data-align="end"] { transform: translate(calc(-100% + 12px), calc(-100% - 8px)); }
.chart-tooltip strong { font-size: .9rem; color: var(--text-primary); }
.chart-tooltip span { color: var(--text-secondary); }
.bar-row .bar-track[data-tip-value]:hover .bar-fill, .bar-row .bar-track:focus-visible .bar-fill { filter: brightness(1.12); }
.bar-row .bar-track:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Stacked 100% bar */
.stack-bar { display: flex; gap: 2px; height: 16px; }
.stack-seg { min-width: 3px; flex-basis: 0; transition: filter var(--transition); }
.stack-seg:first-child { border-radius: 4px 0 0 4px; }
.stack-seg:last-child { border-radius: 0 4px 4px 0; }
.stack-seg:only-child { border-radius: 4px; }
.stack-seg:hover, .stack-seg:focus-visible { filter: brightness(1.15); outline: none; }
.stack-legend { display: grid; gap: .45rem; margin: .9rem 0 0; padding: 0; list-style: none; font-size: .84rem; }
.stack-legend li { display: flex; align-items: center; gap: .55rem; }
.stack-legend-label { flex: 1; color: var(--text-secondary); }
.stack-legend strong { color: var(--text-primary); font-variant-numeric: tabular-nums; }
.stack-legend-share { min-width: 3.2rem; text-align: right; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* Line chart: HTML axes around an SVG plot that stretches to the card width. */
.line-chart { margin: 0; padding-top: .9rem; }
.lc-body { display: grid; grid-template-columns: auto 1fr; gap: .6rem; }
.lc-yaxis { position: relative; width: 2.6rem; height: 180px; font-size: .72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.lc-yaxis span { position: absolute; right: 0; transform: translateY(-50%); white-space: nowrap; }
.lc-plot { height: 180px; margin: 0 10px; outline: none; border-radius: 2px; touch-action: pan-y; }
.lc-plot:focus-visible { box-shadow: 0 0 0 2px var(--bg-secondary), 0 0 0 4px var(--primary); }
.lc-plot svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.lc-grid { stroke: var(--border-color); stroke-width: 1; vector-effect: non-scaling-stroke; }
.lc-line { fill: none; stroke: var(--chart-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; vector-effect: non-scaling-stroke; }
.lc-area { fill: var(--chart-1); fill-opacity: .1; stroke: none; }
.lc-dot { position: absolute; width: 10px; height: 10px; border-radius: 50%; background: var(--chart-1); box-shadow: 0 0 0 2px var(--bg-secondary); transform: translate(-50%, -50%); pointer-events: none; }
.lc-hover { width: 12px; height: 12px; }
.lc-crosshair { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--border-strong); pointer-events: none; }
.lc-end-label { position: absolute; transform: translate(-100%, calc(-100% - 8px)); font-size: .78rem; font-weight: 650; color: var(--text-primary); white-space: nowrap; pointer-events: none; }
.lc-plot:hover .lc-end-label, .lc-plot:focus-visible .lc-end-label { opacity: 0; }
.lc-xaxis { position: relative; height: 1.4rem; margin: .45rem 10px 0 calc(3.2rem + 10px); font-size: .72rem; color: var(--text-muted); }
.lc-xaxis span { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.lc-xaxis span:first-child { transform: none; }
.lc-xaxis span:last-child:not(:first-child) { transform: translateX(-100%); }
.chart-table { margin-top: .6rem; font-size: .82rem; }
.chart-table summary { cursor: pointer; color: var(--text-secondary); width: fit-content; }
.chart-table summary:hover { color: var(--text-primary); }
.chart-table .table-wrap { margin-top: .5rem; max-height: 260px; overflow-y: auto; }

/* Dashboard attendance card: headline figure beside the chart. */
.insight-head { display: flex; align-items: flex-end; justify-content: space-between; gap: .5rem 1.5rem; flex-wrap: wrap; margin-bottom: 1.1rem; }
.insight-figure { font-size: 2.4rem; font-weight: 700; line-height: 1; letter-spacing: -.02em; }
.insight-caption { margin-top: .3rem; font-size: .82rem; color: var(--text-secondary); }
.insight-meta { display: grid; gap: .25rem; justify-items: end; font-size: .82rem; color: var(--text-secondary); text-align: right; }
.insight-delta { display: inline-flex; align-items: center; gap: .3rem; font-weight: 650; }
.insight-delta svg.icon { width: 15px; height: 15px; }
.insight-delta.up { color: var(--success); }
.insight-delta.down { color: var(--danger); }
@media (max-width: 520px) { .insight-meta { justify-items: start; text-align: left; } }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; gap: .8rem; align-items: flex-start; padding: .8rem 1.25rem; border-bottom: 1px solid var(--border-color); }
.list-item:last-child { border-bottom: 0; }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 600; color: var(--text-primary); }
.list-item .li-meta { font-size: .78rem; color: var(--text-muted); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.25rem; font-size: .88rem; margin: 0; }
.kv dt { color: var(--text-muted); }
.kv dd { margin: 0; color: var(--text-primary); word-break: break-word; }
/* .kv's margin reset loads after the utilities, so "kv mb-2" needs its own rule: space before what follows the list. */
.kv.mb-2:not(:last-child) { margin-bottom: 1rem; }
/* Keys that are literal identifiers, e.g. environment variable names. */
.kv-env { align-items: center; gap: .6rem 1rem; }
.kv-env dt { font-family: var(--font-mono); font-size: .78rem; }

.unavailable { display: flex; gap: .6rem; align-items: center; padding: .9rem 1.1rem; border: 1px dashed var(--border-strong); border-radius: var(--radius); color: var(--text-secondary); background: var(--bg-inset); font-size: .85rem; }
.unavailable svg { color: var(--warning); }
