/* ==========================================================================
   TooManyPictures - Customer Portal Stylesheet
   Clean, high-performance, accessible, professional enterprise styling.
   ========================================================================== */

:root {
    /* Lets the browser render native control internals (time/date pickers, scrollbars) in the active theme. */
    color-scheme: light;

    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --transition: var(--transition-fast);

    /* Light Theme (Default) */
    --bg-primary: #faf9f7;
    --bg-surface: #ffffff;
    --bg-surface-elevated: #ffffff;
    --bg-secondary: #f4f1ed;
    --bg-tertiary: #e5dfd7;

    --text-primary: #282425;
    --text-secondary: #554f4b;
    --text-muted: #746b65;
    --text-inverse: #ffffff;

    --primary: #d99000;
    --primary-hover: #b87800;
    --primary-light: #fff3d9;
    --primary-border: #f3c86d;

    --secondary: #554f4b;
    --secondary-hover: #393433;

    --success: #16a34a;
    --success-bg: #f0fdf4;
    --success-border: #bbf7d0;

    --warning: #d97706;
    --warning-bg: #fffbeb;
    --warning-border: #fde68a;

    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --danger-border: #fecaca;

    --border-color: #e5dfd7;
    --border-focus: #d99000;

    --nav-background: #ffffff;
    --nav-border: #e5dfd7;
    --nav-status-background: #f4f1ed;
    --nav-status-border: #e5dfd7;
    --nav-text: #554f4b;
    --nav-button-border: #c9c0b7;
    --nav-button-hover: #f4f1ed;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;

    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

[data-theme="dark"] {
    color-scheme: dark;

    --bg-primary: #242021;
    --bg-surface: #302b2c;
    --bg-surface-elevated: #403939;
    --bg-secondary: #302b2c;
    --bg-tertiary: #403939;

    --text-primary: #faf7f2;
    --text-secondary: #dfd7ce;
    --text-muted: #b8aea5;
    --text-inverse: #282425;

    --primary: #ffad0b;
    --primary-hover: #ffc14c;
    --primary-light: #513b0c;
    --primary-border: #9f6a00;

    --border-color: #514948;
    --border-focus: #ffad0b;

    --nav-background: #231f20;
    --nav-border: #443d3e;
    --nav-status-background: #302b2c;
    --nav-status-border: #514948;
    --nav-text: #dfd7ce;
    --nav-button-border: #62595a;
    --nav-button-hover: #3a3334;

    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.6);
}

/* Base resets & box-sizing */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Utility Helpers */
.hidden {
    display: none !important;
}

.text-muted {
    color: var(--text-muted);
}

.mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.admin-modal-window {
    max-width: 720px;
}

.admin-modal-window:has(#userEditForm) {
    max-width: 640px;
}

#userEditForm .form-actions {
    justify-content: flex-end;
}

.admin-modal-body {
    padding: 1.25rem;
    overflow-y: auto;
}

.admin-modal-body .form-card,
.admin-modal-body #membershipPanel {
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    background: transparent;
}

.admin-modal-body .form-card > h4,
.admin-modal-body #membershipPanel > h4 {
    display: none;
}

#jobsPlansPanel > .section-toolbar,
#jobsPlansPanel > .section-toolbar .toolbar-actions {
    flex-wrap: wrap;
}

#jobsPlansPanel > .section-toolbar > div:first-child {
    max-width: 44rem;
}

.job-plan-view-switch,
.job-plan-sort {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .5rem;
    margin-bottom: 1rem;
}

.job-plan-view-switch [aria-pressed="true"] {
    color: var(--primary);
    background: var(--primary-light);
    border-color: var(--primary-border);
}

.job-plan-sort {
    gap: .25rem .75rem;
    color: var(--text-muted);
    font-size: .8rem;
}

.job-plan-sort .table-sort-button {
    padding: .35rem .25rem;
}

.job-plan-position {
    margin-bottom: 1.75rem;
}

.job-plan-position-header {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: .75rem;
    padding: .85rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
    list-style: none;
    cursor: pointer;
}

.job-plan-position-header::-webkit-details-marker {
    display: none;
}

.job-plan-position-header::before {
    content: '▸';
    color: var(--text-muted);
}

.job-plan-position[open] > .job-plan-position-header {
    margin-bottom: 1rem;
}

.job-plan-position[open] > .job-plan-position-header::before {
    transform: rotate(90deg);
}

.job-plan-position-header:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 3px;
}

.job-plan-position-title {
    flex: 1 1 180px;
    min-width: 0;
    overflow-wrap: anywhere;
}

.job-plan-position-title p,
.job-plan-position-header > span {
    color: var(--text-muted);
    font-size: .8rem;
}

.job-plan-position-title h4 {
    margin: .15rem 0 0;
    font-size: 1rem;
}

.job-plan-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 390px), 1fr));
    gap: 1.25rem;
}

.job-plan-card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow-wrap: anywhere;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    background: var(--bg-surface);
    box-shadow: var(--shadow-sm);
}

.job-plan-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid var(--border-color);
}

.job-plan-card-header p {
    margin-bottom: .2rem;
    color: var(--text-muted);
    font-size: .8rem;
}

.job-plan-card-header h4 {
    margin: 0;
    font-size: 1.1rem;
}

.job-plan-card-header .badge {
    flex-shrink: 0;
}

.job-plan-card-settings {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.1rem 1.25rem;
    padding: 1.25rem;
}

.job-plan-card-settings dt,
.job-plan-card-schedule > span {
    margin-bottom: .3rem;
    color: var(--text-muted);
    font-size: .75rem;
    font-weight: 500;
}

.job-plan-card-settings dd {
    margin: 0;
    font-size: .875rem;
    font-weight: 600;
}

.job-plan-card-settings small,
.job-plan-card-schedule small {
    display: block;
    margin-top: .3rem;
    color: var(--text-secondary);
    font-size: .75rem;
    font-weight: 400;
}

.job-plan-card-format,
.job-plan-card-selection {
    grid-column: 1 / -1;
}

.job-plan-card-schedule {
    margin: auto 1.25rem 0;
    padding: .85rem 1rem;
    border-left: 3px solid var(--primary-border);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
}

.job-plan-card-schedule > span,
.job-plan-card-schedule strong {
    display: block;
}

.job-plan-card-schedule strong {
    font-size: .85rem;
    font-variant-numeric: tabular-nums;
}

.job-plan-card-activity {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: .75rem;
    padding: 1rem 1.25rem .5rem;
    color: var(--text-muted);
    font-size: .75rem;
}

.job-plan-card-activity strong {
    display: block;
    color: var(--text-secondary);
    font-weight: 500;
}

.job-plan-card-id {
    padding: 0 1.25rem .75rem;
    color: var(--text-muted);
    font-size: .7rem;
}

.job-plan-card-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: .5rem;
    padding: .85rem 1.25rem;
    border-top: 1px solid var(--border-color);
}

.job-plan-variants {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border-color);
}

.job-plan-variants > summary {
    margin-bottom: 1.25rem;
    cursor: pointer;
    font-weight: 600;
}

.job-plan-variants > summary span {
    display: inline-block;
    margin-left: .5rem;
    font-size: .8rem;
    font-weight: 400;
}

@media (max-width: 480px) {
    .navbar {
        flex-wrap: wrap;
        gap: .5rem;
    }

    .navbar .nav-actions {
        flex-wrap: wrap;
        min-width: 0;
    }

    .navbar .user-profile {
        min-width: 0;
    }

    .navbar .user-email {
        overflow-wrap: anywhere;
    }

    .job-plan-card-settings {
        grid-template-columns: 1fr;
    }
}

.job-plan-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    margin-bottom: 1.25rem;
}

.job-plan-progress {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .5rem;
    margin: 0 0 .75rem;
    padding: 0;
    list-style: none;
    counter-reset: job-plan-step;
}

.job-plan-progress li {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-secondary);
    color: var(--text-muted);
    font-size: .75rem;
}

.job-plan-progress li::before {
    display: grid;
    place-items: center;
    flex: 0 0 1.4rem;
    width: 1.4rem;
    height: 1.4rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    content: counter(job-plan-step);
    counter-increment: job-plan-step;
}

.job-plan-progress [aria-current="step"] {
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}

.job-plan-progress [aria-current="step"]::before {
    border-color: var(--primary);
    background-color: var(--primary);
    color: var(--text-inverse);
}

.job-plan-step {
    display: grid;
    gap: 1.25rem;
}

.job-plan-step-label,
.job-plan-step-hint {
    margin: 0 0 1rem;
    color: var(--text-muted);
    font-size: .875rem;
}

.job-plan-review-source {
    margin: 0 0 1rem;
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

@media (max-width: 480px) {
    .job-plan-progress {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.job-plan-derived-time {
    display: block;
    min-height: 42px;
    padding: .6rem .75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: .875rem;
    font-variant-numeric: tabular-nums;
}

.job-plan-preview {
    margin-top: 1.25rem;
    padding: .85rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    font-size: .875rem;
    line-height: 1.6;
    white-space: pre-line;
}

.auth-notice[tabindex="-1"]:focus {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.job-plan-tabs [aria-selected="true"] {
    background: var(--primary);
    border-color: var(--primary);
    color: var(--text-inverse);
}

.job-plan-help {
    display: grid;
    gap: 1.25rem;
    font-size: .875rem;
    line-height: 1.6;
}

.job-plan-help h5,
.job-plan-help h6 {
    font-size: .95rem;
    margin: 0 0 .5rem;
}

.job-plan-help p {
    margin: 0;
}

.job-plan-help-intro p + p {
    margin-top: .75rem;
}

.job-plan-help dl {
    margin: 0;
}

.job-plan-help dt {
    font-weight: 600;
}

.job-plan-help dd {
    margin: 0 0 .5rem;
    color: var(--text-muted);
}

.job-plan-examples {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 250px), 1fr));
    gap: 1rem;
}

.job-plan-example {
    padding: 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-secondary);
}

.job-plan-example dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: .25rem .75rem;
    margin: .75rem 0;
}

.job-plan-example dd {
    margin: 0;
}

.job-processing-counts {
    margin-bottom: 1rem;
    font-weight: 600;
}

.job-processing-filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    align-items: end;
    gap: .75rem;
    margin-bottom: 1rem;
}

.job-processing-filters .form-group {
    margin: 0;
    min-width: 0;
}

.job-processing-details dd {
    margin: .25rem 0 1rem;
    overflow-wrap: anywhere;
    white-space: pre-wrap;
}

.mt-1 {
    margin-top: 0.25rem;
}

.mt-2 {
    margin-top: 0.5rem;
}

.mt-3 {
    margin-top: 1rem;
}

.mb-2 {
    margin-bottom: 0.5rem;
}

.mb-3 {
    margin-bottom: 1rem;
}

/* Layout Structure */
.app-container {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1.5rem;
    background-color: var(--nav-background);
    border-bottom: 1px solid var(--nav-border);
    box-shadow: var(--shadow-sm);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    display: flex;
    align-items: center;
}

.nav-brand-link {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.brand-logo {
    display: block;
    width: 150px;
    height: auto;
}

.brand-logo-dark {
    display: none;
}

[data-theme="dark"] .brand-logo-light {
    display: none;
}

[data-theme="dark"] .brand-logo-dark {
    display: block;
}

.navbar .status-badge {
    background-color: var(--nav-status-background);
    border-color: var(--nav-status-border);
    color: var(--nav-text);
}

.navbar .badge-label,
.navbar .user-email {
    color: var(--nav-text);
}

.navbar .btn-outline,
.navbar .btn-icon {
    border-color: var(--nav-button-border);
    color: var(--nav-text);
}

.navbar .btn-outline:hover:not(:disabled),
.navbar .btn-icon:hover {
    background-color: var(--nav-button-hover);
    border-color: var(--primary);
}

.nav-status {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.75rem;
    background-color: var(--bg-secondary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    font-size: 0.8rem;
}

.badge-label {
    color: var(--text-muted);
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.user-email {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: background-color var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast), transform 50ms ease;
    text-decoration: none;
    line-height: 1.25;
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background-color: var(--primary);
    color: var(--text-inverse);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--secondary);
    color: var(--text-inverse);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--secondary-hover);
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--text-primary);
}

.btn-outline:hover:not(:disabled) {
    background-color: var(--bg-secondary);
    border-color: var(--border-focus);
}

.btn-text {
    background-color: transparent;
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
}

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

.btn-sm {
    padding: 0.35rem 0.65rem;
    font-size: 0.8rem;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-md);
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    cursor: pointer;
    transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

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

.btn-icon.active {
    background-color: var(--primary);
    color: var(--text-inverse);
    border-color: var(--primary);
}

.btn-icon.btn-sm {
    width: 28px;
    height: 28px;
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 1rem;
}

.auth-switch {
    display: block;
    margin: 0.75rem auto 0;
}

.auth-notice {
    margin-top: 1rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
}

.auth-notice.success {
    background-color: var(--success-bg);
    border-color: var(--success-border);
    color: var(--success);
}

.auth-notice.error {
    background-color: var(--danger-bg);
    border-color: var(--danger-border);
    color: var(--danger);
}

label {
    display: block;
    margin-bottom: 0.35rem;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

input:not([type]),
input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="search"],
input[type="tel"],
input[type="number"],
input[type="time"],
input[type="date"],
input[type="datetime-local"],
select {
    width: 100%;
    padding: 0.6rem 0.75rem;
    font-size: 0.875rem;
    font-family: inherit;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    background-color: var(--bg-surface);
    color: var(--text-primary);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

input[type="number"],
input[type="time"],
input[type="date"],
input[type="datetime-local"] {
    min-height: 42px;
    appearance: none;
    -webkit-appearance: none;
}

input[type="number"] {
    -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    appearance: none;
    -webkit-appearance: none;
    margin: 0;
}

input[type="time"]::-webkit-calendar-picker-indicator,
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    cursor: pointer;
    opacity: 0.7;
}

[data-theme="dark"] input[type="time"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="date"]::-webkit-calendar-picker-indicator,
[data-theme="dark"] input[type="datetime-local"]::-webkit-calendar-picker-indicator {
    filter: invert(1);
}

select {
    min-height: 42px;
    cursor: pointer;
}

.input-sm {
    padding: 0.4rem 0.6rem !important;
    font-size: 0.8rem !important;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

input.is-invalid, select.is-invalid {
    border-color: var(--danger) !important;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15) !important;
}

/* Auth Card */
.auth-section {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex-grow: 1;
    padding: 2rem 1rem;
}

.auth-card {
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    padding: 2.25rem;
}

.auth-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-header h2 {
    font-size: 1.5rem;
    margin-bottom: 0.5rem;
}

.access-notice-card {
    text-align: center;
}

.access-notice-text {
    margin: 0 0 1.5rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.account-modal-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.account-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.account-form + .account-form {
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
}

.account-form h4 {
    margin: 0;
    color: var(--text-primary);
}

.account-form-hint {
    margin: -0.25rem 0 0;
    color: var(--text-muted);
    font-size: 0.8125rem;
    line-height: 1.4;
}

.subtitle {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* Dashboard Layout */
.dashboard-section {
    display: grid;
    grid-template-columns: 340px 1fr;
    flex-grow: 1;
    min-height: calc(100vh - 65px);
}

.sidebar {
    background-color: var(--bg-surface);
    border-right: 1px solid var(--border-color);
    padding: 1.25rem;
    position: sticky;
    top: 84px;
    align-self: start;
    height: calc(100vh - 84px);
    overflow-y: visible;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.sidebar-header h3 {
    font-size: 1.05rem;
    font-weight: 600;
}

.position-search-box {
    margin-bottom: 0.75rem;
}

/* Positions List / Table */
.positions-container {
    max-height: 220px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-secondary);
    padding: 0.25rem;
}

.positions-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.position-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.position-item:hover {
    border-color: var(--primary-border);
    background-color: var(--primary-light);
}

.position-item.active {
    border-color: var(--primary);
    background-color: var(--primary-light);
    box-shadow: 0 0 0 1px var(--primary);
}

.position-item-main {
    overflow: hidden;
    margin-right: 0.5rem;
}

.position-item-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.position-item-project {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.status-pill {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 0.15rem 0.4rem;
    border-radius: var(--radius-full);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-active {
    background-color: var(--success-bg);
    color: var(--success);
    border: 1px solid var(--success-border);
}

.status-inactive {
    background-color: var(--bg-tertiary);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
}

.selected-position-badge {
    padding: 0.5rem 0.75rem;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    font-size: 0.85rem;
}

.divider {
    border: 0;
    height: 1px;
    background-color: var(--border-color);
    margin: 1.25rem 0;
}

.label-xs {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: block;
    margin-bottom: 0.2rem;
}

.filter-container h4, .quick-tools h4 {
    font-size: 0.95rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
}

.filter-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

.filter-error-hint {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    color: var(--danger);
    background-color: var(--danger-bg);
    border: 1px solid var(--danger-border);
    padding: 0.45rem 0.65rem;
    border-radius: var(--radius-sm);
    font-size: 0.775rem;
    font-weight: 500;
    margin-top: -0.25rem;
    margin-bottom: 0.75rem;
}

.live-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ef4444;
    margin-right: 0.4rem;
}

/* Content Body */
.content-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.25rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.gallery-summary h2 {
    font-size: 1.4rem;
    margin-bottom: 0.25rem;
}

.gallery-toolbar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.view-toggle {
    display: flex;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background-color: var(--bg-surface);
    overflow: hidden;
}

.view-toggle .btn-icon {
    border-radius: 0;
    border: none;
}

/* Banner */
.banner {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1.25rem;
    font-size: 0.875rem;
}

.banner-info {
    background-color: var(--primary-light);
    border: 1px solid var(--primary-border);
    color: var(--primary);
}

.banner-icon {
    display: inline-flex;
    align-items: center;
}

/* Pictures Grid */
.pictures-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.pictures-grid.list-mode {
    grid-template-columns: 1fr;
}

.picture-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: transform var(--transition-fast), box-shadow var(--transition-fast), border-color var(--transition-fast);
}

.picture-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: var(--border-focus);
}

.picture-thumbnail-wrapper {
    position: relative;
    width: 100%;
    aspect-ratio: 16 / 9;
    background-color: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.picture-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    opacity: 0;
    transform: scale(1.04);
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
    will-change: opacity, transform;
}

.picture-thumb.loaded {
    opacity: 1;
    transform: scale(1);
}

.thumb-loader {
    position: absolute;
    z-index: 1;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.thumb-loader.fade-out {
    opacity: 0;
    transform: scale(0.85);
}

.thumb-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    color: var(--text-muted);
    opacity: 0.6;
}

.picture-card-info {
    padding: 0.6rem 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
}

.picture-card-time {
    color: var(--text-primary);
    font-weight: 500;
}

.picture-card-seq {
    color: var(--text-muted);
}

.pictures-grid.list-mode .picture-card {
    display: flex;
    align-items: center;
    height: 70px;
}

.pictures-grid.list-mode .picture-thumbnail-wrapper {
    width: 110px;
    height: 100%;
    aspect-ratio: auto;
}

.pictures-grid.list-mode .picture-card-info {
    flex-grow: 1;
    padding: 0 1rem;
    font-size: 0.85rem;
}

/* States */
.empty-state, .loading-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-muted);
    background-color: var(--bg-surface);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-lg);
    margin: 1rem 0;
}

.empty-icon {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 1rem;
    color: var(--text-muted);
}

.loading-state-sm, .empty-state-sm {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 1rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* Spinners */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 0.75rem auto;
}

.spinner-sm {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.gallery-load-more-sentinel {
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.65rem;
    margin-top: 0.75rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.gallery-load-more-sentinel .spinner-sm {
    width: 24px;
    height: 24px;
    border-width: 3px;
}

.gallery-load-more-label {
    padding: 0.5rem 0.85rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    background-color: var(--bg-surface);
    box-shadow: var(--shadow-sm);
}

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

/* Keep the full-screen scrim unfiltered while live tables update behind it. */
.modal-backdrop {
    position: absolute;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.7);
}

.modal-window {
    position: relative;
    background-color: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 1100px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    z-index: 10;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
}

.modal-title-group h3 {
    font-size: 1.15rem;
}

.modal-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.modal-header-actions {
    display: flex;
    gap: 0.5rem;
}

.modal-body {
    display: grid;
    grid-template-columns: 1fr 300px;
    flex-grow: 1;
    overflow: hidden;
}

.modal-image-container {
    background-color: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.modal-image {
    max-width: 100%;
    max-height: calc(90vh - 70px);
    object-fit: contain;
    opacity: 0;
    transform: scale(0.97);
    transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1), transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-image.loaded {
    opacity: 1;
    transform: scale(1);
}

.modal-sidebar {
    padding: 1.25rem;
    background-color: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
}

.modal-sidebar h4 {
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.meta-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.35rem 0.75rem;
    font-size: 0.8rem;
}

.meta-list dt {
    color: var(--text-muted);
}

.meta-list dd {
    color: var(--text-primary);
    font-weight: 500;
    word-break: break-all;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.4rem;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
}

.badge-active {
    background-color: var(--success-bg);
    color: var(--success);
}

.assets-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.asset-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    transition: var(--transition);
}

.asset-item.active {
    border-color: var(--primary);
    background-color: var(--bg-surface);
    box-shadow: 0 0 0 1px var(--primary);
}

.asset-info {
    display: flex;
    flex-direction: column;
}

/* Timelapse Modal */
.timelapse-window {
    max-width: 900px;
}

.timelapse-body {
    display: flex;
    flex-direction: column;
}

.timelapse-canvas-wrapper {
    background-color: #000;
    aspect-ratio: 16 / 9;
    display: flex;
    align-items: center;
    justify-content: center;
}

.timelapse-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.timelapse-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-color);
}

.timelapse-scrubber {
    flex-grow: 1;
    cursor: pointer;
}

.speed-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
}

.speed-selector select {
    width: auto;
    padding: 0.3rem 0.5rem;
}

/* Toast Container */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 2000;
}

.toast {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    border-radius: var(--radius-md);
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    font-size: 0.875rem;
    color: var(--text-primary);
    border-left: 4px solid var(--primary);
    min-width: 260px;
    max-width: 380px;
}

.toast-success {
    border-left-color: var(--success);
}

.toast-error {
    border-left-color: var(--danger);
}

.toast-info {
    border-left-color: var(--primary);
}

/* Tenant Selector & Switcher Modal */
.nav-tenant-select {
    background-color: transparent;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 0.15rem 0.4rem;
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition-fast);
}

.nav-tenant-select:focus {
    border-color: var(--border-focus);
}

.modal-sm {
    max-width: 540px;
}

.modal-body-simple {
    padding: 1.25rem;
    overflow-y: auto;
    max-height: calc(85vh - 70px);
}

.tenant-cards-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.tenant-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 1rem;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-fast), background-color var(--transition-fast);
}

.tenant-card:hover {
    border-color: var(--border-focus);
}

.tenant-card.active {
    border-color: var(--primary);
    background-color: var(--primary-light);
}

.tenant-card-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex-grow: 1;
}

.tenant-card-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.tenant-card-title {
    font-size: 0.95rem;
    color: var(--text-primary);
}

.badge-role {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: var(--radius-sm);
    background-color: var(--bg-secondary);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.badge-active {
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: var(--radius-sm);
    background-color: var(--success);
    color: #ffffff;
}

.tenant-card-meta {
    font-size: 0.75rem;
}

.text-xs {
    font-size: 0.75rem;
}

/* Responsive Breakpoints */
@media (max-width: 860px) {
    .dashboard-section {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
    }

    .modal-body {
        grid-template-columns: 1fr;
    }

    .modal-sidebar {
        border-left: none;
        border-top: 1px solid var(--border-color);
    }
}

/* Sidebar Footer & Auth Footer */
.sidebar-footer {
    margin-top: auto;
    padding-top: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
}

.sidebar-footer-links {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
}

.sidebar-footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.sidebar-footer-links a:hover {
    color: var(--primary);
    text-decoration: underline;
}

.sidebar-footer-version {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    letter-spacing: 0.02em;
}

.auth-footer-links {
    margin-top: 1.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-size: 0.775rem;
    color: var(--text-muted);
}

.auth-footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.auth-footer-links a:hover {
    color: var(--primary);
    text-decoration: underline;
}

.auth-footer-version {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.75rem;
}

.footer-separator {
    color: var(--border-color);
    user-select: none;
}

/* Legal Pages (Impressum / Datenschutz) & Modals */
.legal-modal-window {
    max-width: 820px;
    width: 95%;
    max-height: 85vh;
}

.legal-modal-body {
    padding: 1.5rem 2rem 2rem;
    overflow-y: auto;
    max-height: calc(85vh - 70px);
}

.legal-modal-body .legal-section:last-of-type {
    margin-bottom: 1rem;
}

.legal-modal-body .legal-footer {
    margin-top: 1.5rem;
}

.legal-page-container {
    max-width: 860px;
    margin: 2rem auto;
    padding: 0 1.25rem 3rem;
    flex-grow: 1;
    width: 100%;
}

.legal-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 2.5rem;
}

.legal-header {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1.25rem;
    margin-bottom: 1.75rem;
}

.legal-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.legal-section {
    margin-bottom: 1.75rem;
}

.legal-section h2 {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-top: 1.5rem;
    margin-bottom: 0.75rem;
}

.legal-section h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 1rem;
    margin-bottom: 0.5rem;
}

.legal-section p {
    color: var(--text-secondary);
    font-size: 0.925rem;
    line-height: 1.65;
    margin-bottom: 0.75rem;
}

.legal-section ul {
    margin: 0.5rem 0 1rem 1.5rem;
    color: var(--text-secondary);
    font-size: 0.925rem;
    line-height: 1.65;
}

.legal-section li {
    margin-bottom: 0.35rem;
}

.legal-section a {
    color: var(--primary);
    text-decoration: none;
}

.legal-section a:hover {
    text-decoration: underline;
}

.legal-section code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    background-color: var(--bg-secondary);
    padding: 0.15rem 0.4rem;
    border-radius: var(--radius-sm);
    font-size: 0.85em;
    border: 1px solid var(--border-color);
}

.legal-footer {
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
    margin-top: 2.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    font-size: 0.825rem;
    color: var(--text-muted);
}

.legal-footer-links {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.legal-footer-links a {
    color: var(--text-muted);
    text-decoration: none;
    transition: color var(--transition-fast);
}

.legal-footer-links a:hover {
    color: var(--primary);
    text-decoration: underline;
}

.legal-footer-version {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.75rem;
}

@media (max-width: 640px) {
    .legal-card {
        padding: 1.5rem;
    }
}

/* Administration views reuse the customer portal design system above. */
.list-search {
    display: flex;
    flex-wrap: wrap;
    gap: .75rem;
    margin-bottom: 1rem;
}

.list-search input {
    flex: 1 1 200px;
    max-width: 420px;
}

.list-footer {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    margin: -.25rem 0 1.5rem;
}

.list-footer [role="status"] {
    font-size: .85rem;
}

.admin-section {
    display: grid;
    grid-template-columns: 250px minmax(0, 1fr);
    min-height: calc(100vh - 65px);
}

.admin-section .sidebar {
    display: block;
    min-height: 100%;
    padding: 1.5rem 1rem;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
}

.admin-navigation {
    display: grid;
    gap: .3rem;
}

.nav-item {
    width: 100%;
    padding: .7rem .8rem;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    background: transparent;
    text-align: left;
    font-weight: 500;
}

.nav-item:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.nav-item.active {
    color: var(--primary);
    background: var(--primary-light);
    border-color: var(--primary-border);
}

.admin-content {
    padding: 2rem;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

.section-toolbar, .toolbar-actions, .form-row, .form-actions {
    display: flex;
    align-items: center;
    gap: .75rem;
}

.section-toolbar {
    justify-content: space-between;
    margin-bottom: 1rem;
}

.section-toolbar h3 {
    margin: 0;
}

.form-card, .table-card {
    margin: 0 0 1rem;
}

.form-card h4 {
    margin: 0 0 1rem;
}

.form-row {
    flex-wrap: wrap;
    align-items: flex-end;
}

.form-row .form-group {
    flex: 1 1 180px;
    margin: 0;
}

.form-actions {
    margin-top: 1rem;
}

.checkbox {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    min-height: 42px;
    margin: 0;
    color: var(--text-secondary);
    font-size: .875rem;
    cursor: pointer;
}

.checkbox input {
    width: auto;
}

.search-box {
    max-width: 420px;
    margin: 0 0 1rem;
}

.checkbox input[type="checkbox"] {
    flex: none;
    display: grid;
    place-content: center;
    width: 1.1rem;
    height: 1.1rem;
    margin: 0;
    padding: 0;
    min-height: 0;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-surface);
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
    transition: background-color var(--transition-fast), border-color var(--transition-fast);
}

.checkbox input[type="checkbox"]::before {
    content: "";
    width: .6rem;
    height: .6rem;
    transform: scale(0);
    transition: transform var(--transition-fast);
    background: var(--text-inverse);
    clip-path: polygon(14% 44%, 0 65%, 50% 100%, 100% 16%, 80% 0%, 43% 62%);
}

.checkbox input[type="checkbox"]:checked {
    background: var(--primary);
    border-color: var(--primary);
}

.checkbox input[type="checkbox"]:checked::before {
    transform: scale(1);
}

.checkbox input[type="checkbox"]:focus-visible {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.form-sections {
    display: grid;
    gap: 1.25rem;
}

.form-section {
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
}

.form-section:first-child {
    padding-top: 0;
    border-top: 0;
}

.form-section > h5 {
    margin: 0 0 .85rem;
    color: var(--text-muted);
    font-size: .75rem;
    font-weight: 700;
    letter-spacing: .06em;
    text-transform: uppercase;
}

.form-section-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem .9rem;
    align-items: start;
}

.form-section-grid .form-group {
    margin: 0;
}

.form-section-grid .span-2 {
    grid-column: 1 / -1;
}

.form-section-grid small {
    display: block;
    margin-top: .4rem;
    font-size: .78rem;
    line-height: 1.45;
}

.label-optional {
    display: inline-block;
    margin-left: .35rem;
    padding: .05rem .4rem;
    border-radius: var(--radius-full);
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: .66rem;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    vertical-align: middle;
}

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

.data-table th, .data-table td {
    padding: .8rem;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    vertical-align: middle;
}

.data-table th {
    color: var(--text-muted);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
}

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

.badge {
    display: inline-flex;
    padding: .2rem .55rem;
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    font-size: .75rem;
    font-weight: 600;
}

.badge.ok {
    color: var(--success);
    background: var(--success-bg);
}

.badge.wait {
    color: var(--warning);
    background: var(--warning-bg);
}

.badge.error {
    color: var(--danger);
    background: var(--danger-bg);
}

.badge.access {
    min-width: 2.25rem;
    justify-content: center;
    color: var(--primary);
    background: var(--primary-light);
    border: 1px solid var(--primary-border);
    text-transform: uppercase;
}

.refresh-meta {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    color: var(--text-muted);
    font-size: .78rem;
}

.panel-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .75rem;
    margin: -.5rem 0 1rem;
}

.panel-meta .btn {
    margin-left: auto;
}

.danger {
    color: var(--danger);
    border-color: var(--danger-border);
}

.empty-state-sm {
    margin: 0;
    padding: 1rem;
    color: var(--text-muted);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.toast {
    padding: .8rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-surface-elevated);
    box-shadow: var(--shadow-lg);
}

.toast-success {
    color: var(--success);
    border-color: var(--success-border);
}

.toast-error {
    color: var(--danger);
    border-color: var(--danger-border);
}

#keySecret {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: .75rem;
    margin-bottom: 1rem;
    padding: .9rem 1rem;
    overflow-wrap: anywhere;
}

#keySecret code {
    padding: .45rem;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
}

.key-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem .9rem;
    align-items: end;
}

.key-form-grid .form-group {
    margin: 0;
}

.key-form-grid .key-position-group {
    grid-column: 1 / -1;
}

.form-card select[multiple] {
    min-height: 10.5rem;
    padding: .35rem;
    background: var(--bg-secondary);
}

.form-card select[multiple] option {
    padding: .5rem .6rem;
    border-radius: var(--radius-sm);
}

.form-card select[multiple] option:checked {
    color: var(--text-inverse);
    background: var(--primary);
}

.key-position-group small {
    display: block;
    margin-top: .4rem;
    font-size: .78rem;
}

.key-active {
    align-self: end;
    padding-bottom: .55rem;
}

.key-id {
    max-width: 14rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.key-positions {
    min-width: 14rem;
    color: var(--text-secondary);
    font-size: .825rem;
    line-height: 1.55;
}

.camera-form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem .9rem;
    align-items: end;
}

.camera-form-grid .form-group {
    margin: 0;
}

.camera-form-grid small {
    display: block;
    margin-top: .4rem;
    font-size: .78rem;
}

.camera-actions {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
}

.camera-address {
    font-size: .825rem;
    color: var(--text-secondary);
}

.device-operations, .device-detail {
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.device-operations h4, .device-detail h4 {
    margin: 0 0 .75rem;
}

.device-secret {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    overflow-wrap: anywhere;
}

.device-secret code {
    display: block;
    padding: .65rem;
    background: var(--primary-light);
    border-radius: var(--radius-sm);
}

.device-health-heading {
    margin: 1rem 0;
}

.device-public-key {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    padding: .8rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    font-size: .8rem;
}

.device-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .85rem 1.25rem;
}

.device-facts dt {
    font-size: .8rem;
    color: var(--text-muted);
}

.device-facts dd {
    margin: .3rem 0 0;
    overflow-wrap: anywhere;
}

.device-action-form {
    margin: 1.5rem 0;
    padding: 1rem 0;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
}

#deviceList .mono, #deviceAttemptList .mono {
    font-size: .72rem;
    overflow-wrap: anywhere;
}

@media (max-width: 800px) {
    .device-facts {
        grid-template-columns: 1fr;
    }

    .device-secret {
        flex-direction: column;
    }
}

@media (max-width: 800px) {
    .admin-section {
        display: block;
    }

    .admin-section .sidebar {
        min-height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border-color);
    }

    .admin-navigation {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .admin-content {
        padding: 1.25rem;
    }

    .section-toolbar {
        align-items: flex-start;
        flex-direction: column;
    }

    .data-table {
        display: block;
        overflow-x: auto;
    }

    #keySecret {
        grid-template-columns: 1fr;
    }

    .key-form-grid, .camera-form-grid, .form-section-grid {
        grid-template-columns: 1fr;
    }

    .key-form-grid .key-position-group {
        grid-column: auto;
    }

    .key-active {
        padding-bottom: 0;
    }
}

.table-sort-button {
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
    text-align: left;
    cursor: pointer;
}

.table-sort-button:hover {
    color: var(--primary);
}

.table-sort-button:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 4px;
}

.table-sort-hint {
    margin: .5rem 0;
    font-size: .8rem;
}

/* Global plain-text email templates reuse the portal's form and theme components. */
.email-template-card {
    max-width: 960px;
    padding: 1.5rem;
}

.email-template-card textarea {
    width: 100%;
    min-height: 18rem;
    resize: vertical;
    font: inherit;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem;
}

.email-template-card textarea:focus {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

.email-template-section, .email-template-preview {
    margin-top: 1.5rem;
    padding-top: 1.25rem;
    border-top: 1px solid var(--border-color);
}

.email-template-preview pre {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    font: inherit;
    line-height: 1.6;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.email-template-preview-subject {
    font-weight: 600;
    overflow-wrap: anywhere;
}

.email-template-card .form-row > .form-group {
    flex: 1;
    min-width: 0;
}
