/* Blue Mar UI foundation
 * Shared visual tokens and low-level primitives for authenticated and guest views.
 * Feature-specific selectors should use the bm- prefix when migrated.
 */
:root {
    --bm-color-ink: #001738;
    --bm-color-ink-soft: #334a66;
    --bm-color-muted: #66788c;
    --bm-color-primary: #0bb5dd;
    --bm-color-primary-classic: #00aeef;
    --bm-color-primary-hover: #0497bb;
    --bm-color-primary-soft: #e7f8fc;
    --bm-color-deep: #005c9b;
    --bm-color-deep-classic: #00569d;
    --bm-color-deep-hover: #004b7f;
    --bm-color-surface: #ffffff;
    --bm-color-surface-muted: #f5f8fa;
    --bm-color-border: #d8e2ea;
    --bm-color-border-strong: #bac9d5;
    --bm-color-text-neutral: #333333;
    --bm-color-border-neutral: #eaeaea;
    --bm-color-border-dropdown-classic: #e2e8f0;
    --bm-color-success: #2e7d32;
    --bm-color-success-soft: #eaf6ec;
    --bm-color-warning: #b86b00;
    --bm-color-warning-soft: #fff5df;
    --bm-color-danger: #c62828;
    --bm-color-danger-soft: #fdecec;
    --bm-color-info: #1565c0;
    --bm-color-info-soft: #eaf3fd;

    --bm-font-body: "proxima-nova", "Nunito Sans", sans-serif;
    --bm-font-display: "Nunito Sans", "proxima-nova", sans-serif;
    --bm-font-performance: "Nunito Sans", sans-serif;
    --bm-font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

    --bm-text-xs: 0.75rem;
    --bm-text-sm: 0.875rem;
    --bm-text-md: 1rem;
    --bm-text-lg: 1.125rem;
    --bm-text-xl: 1.375rem;
    --bm-text-2xl: clamp(1.75rem, 3vw, 2.5rem);
    --bm-text-display: clamp(2.25rem, 5vw, 3.25rem);

    --bm-space-1: 0.25rem;
    --bm-space-2: 0.5rem;
    --bm-space-3: 0.75rem;
    --bm-space-4: 1rem;
    --bm-space-5: 1.25rem;
    --bm-space-6: 1.5rem;
    --bm-space-8: 2rem;
    --bm-space-10: 2.5rem;
    --bm-space-12: 3rem;

    --bm-radius-sm: 4px;
    --bm-radius-md: 8px;
    --bm-radius-lg: 12px;
    --bm-radius-pill: 999px;
    --bm-radius-card-classic: 4px;
    --bm-radius-dropdown-classic: 0.375rem;
    --bm-shadow-sm: 0 1px 3px rgba(0, 23, 56, 0.1);
    --bm-shadow-md: 0 8px 24px rgba(0, 23, 56, 0.1);
    --bm-shadow-lg: 0 18px 48px rgba(0, 23, 56, 0.14);
    --bm-shadow-card-classic: 0 2px 4px rgba(0, 0, 0, 0.1);
    --bm-focus-ring: 0 0 0 3px rgba(11, 181, 221, 0.24);

    --bm-content-compact: 960px;
    --bm-content-standard: 1200px;
    --bm-content-wide: 1400px;
    --bm-control-height: 42px;
    --bm-transition: 160ms ease;

    /* Temporary compatibility aliases for views still using the original names. */
    --primary-blue: var(--bm-color-primary);
    --dark-blue: var(--bm-color-deep);
    --dark-text: var(--bm-color-ink);
    --light-background: var(--bm-color-surface-muted);
}

html {
    color: var(--bm-color-ink);
    font-family: var(--bm-font-body);
}

body.app-shell,
body.guest-shell {
    color: var(--bm-color-ink);
    font-family: var(--bm-font-body);
    font-size: var(--bm-text-md);
    line-height: 1.5;
}

body.app-shell :where(button, input, select, textarea),
body.guest-shell :where(button, input, select, textarea) {
    font-family: inherit;
}

body.app-shell :where(h1, h2, h3, .system-title, .performance-header h2) {
    color: var(--bm-color-ink);
    font-family: var(--bm-font-display);
    letter-spacing: -0.025em;
}

body.app-shell main {
    color: var(--bm-color-ink);
}

/* Standard page widths */
.bm-page,
body.app-shell :where(.performance-container, .container-fluid, .container-medium, .container-wide) {
    width: min(100%, var(--bm-content-standard));
    margin-inline: auto;
}

.bm-page--compact,
body.app-shell .container-medium {
    max-width: var(--bm-content-compact);
}

.bm-page--wide,
body.app-shell .container-wide {
    max-width: var(--bm-content-wide);
}

/* Page title/header */
.bm-page-header,
body.app-shell .performance-header {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-wrap: wrap;
    gap: var(--bm-space-4);
    margin: var(--bm-space-8) 0 var(--bm-space-10);
    text-align: center;
}

.bm-page-header__title,
body.app-shell .bm-page-header__title,
body.app-shell .performance-header h2 {
    margin: 0;
    color: var(--bm-color-text-neutral);
    font-family: var(--bm-font-body);
    font-size: var(--bm-text-display);
    font-weight: 300;
    letter-spacing: normal;
    line-height: 1.2;
}

.bm-page-header__context,
body.app-shell .section-title .location-label {
    border-radius: var(--bm-radius-sm);
    background: var(--bm-color-deep);
    color: #fff;
    font-size: var(--bm-text-lg);
    font-weight: 700;
    letter-spacing: 0.02em;
}

.header-controls {
    display: flex;
    align-items: center;
    gap: var(--bm-space-3);
}

.performance-header.admin-settings-header {
    width: 100%;
    justify-content: space-between;
    flex-wrap: nowrap;
}

.performance-header.admin-settings-header h2 {
    min-width: 0;
}

.admin-home-header-button {
    min-height: 36px;
    white-space: nowrap;
    text-transform: uppercase;
}

.admin-home-header-button i {
    font-size: 18px;
}

.snapshot-mode-banner {
    display: flex;
    align-items: center;
    gap: var(--bm-space-3);
    margin-bottom: var(--bm-space-4);
    border: 1px solid #f3c96a;
    border-radius: var(--bm-radius-md);
    background: var(--bm-color-warning-soft);
    color: #7a4800;
    padding: var(--bm-space-3) var(--bm-space-5);
    font-size: var(--bm-text-sm);
}

.snapshot-mode-banner .snapshot-icon,
.snapshot-label {
    display: flex;
    align-items: center;
}

.snapshot-exit-link {
    margin-left: auto;
    color: var(--bm-color-warning);
    font-weight: 600;
    text-decoration: underline;
}

.snapshot-selector {
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--bm-space-2);
    border: 1px solid var(--bm-color-border);
    border-radius: var(--bm-radius-md);
    background: var(--bm-color-surface-muted);
    color: var(--bm-color-ink-soft);
    padding: 0.5rem 0.875rem;
    font-size: var(--bm-text-sm);
    cursor: pointer;
    transition: background-color var(--bm-transition), border-color var(--bm-transition);
}

.snapshot-selector:hover {
    border-color: var(--bm-color-border-strong);
    background: var(--bm-color-primary-soft);
}

.snapshot-label {
    gap: 0.375rem;
}

.snapshot-active-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--bm-color-warning);
    animation: bm-pulse 2s infinite;
}

@keyframes bm-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.45; }
}

.snapshot-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + var(--bm-space-2));
    right: 0;
    z-index: 1000;
    min-width: 280px;
    overflow: hidden;
    border: 1px solid var(--bm-color-border);
    border-radius: var(--bm-radius-lg);
    background: var(--bm-color-surface);
    box-shadow: var(--bm-shadow-md);
}

.snapshot-selector.snapshot-selector--floating {
    position: fixed;
    right: max(24px, env(safe-area-inset-right));
    bottom: max(24px, env(safe-area-inset-bottom));
    z-index: 1300;
    width: max-content;
    max-width: calc(100vw - 32px);
    border-color: var(--bm-color-border-strong);
    background: var(--bm-color-surface);
    box-shadow: var(--bm-shadow-lg);
}

.snapshot-selector--floating:focus-visible {
    outline: none;
    box-shadow: var(--bm-shadow-lg), var(--bm-focus-ring);
}

.snapshot-selector--floating > .dropdown-arrow {
    transform: rotate(180deg);
    transition: transform var(--bm-transition);
}

.snapshot-selector--floating.is-open > .dropdown-arrow {
    transform: rotate(0deg);
}

.snapshot-selector--floating .snapshot-dropdown {
    top: auto;
    right: 0;
    bottom: calc(100% + var(--bm-space-2));
    left: auto;
    width: min(340px, calc(100vw - 32px));
    min-width: 280px;
    max-height: min(60vh, 420px);
    overflow-x: hidden;
    overflow-y: auto;
}

.snapshot-option {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: var(--bm-space-3) var(--bm-space-4);
    cursor: pointer;
}

.snapshot-option:hover,
.snapshot-option.active {
    background: var(--bm-color-primary-soft);
}

.snapshot-option.active {
    border-left: 3px solid var(--bm-color-primary);
}

.snapshot-date {
    color: var(--bm-color-ink);
    font-weight: 600;
}

.snapshot-meta,
.snapshot-section-title {
    color: var(--bm-color-muted);
    font-size: var(--bm-text-xs);
}

.snapshot-divider {
    height: 1px;
    margin: var(--bm-space-1) 0;
    background: var(--bm-color-border);
}

.snapshot-section-title {
    padding: var(--bm-space-2) var(--bm-space-4) var(--bm-space-1);
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

/* Surfaces and cards */
.bm-surface,
body.app-shell :where(.card, .metric-card, .filters-section, .filter-section, .stats-card, .chart-card) {
    border: 1px solid var(--bm-filter-panel-border, var(--bm-color-border));
    border-radius: var(--bm-radius-md);
    background: var(--bm-filter-panel-section-bg, var(--bm-color-surface));
    box-shadow: var(--bm-shadow-sm);
}

.bm-surface {
    padding: var(--bm-space-6);
}

.bm-surface--flat {
    box-shadow: none;
}

.bm-surface--raised {
    box-shadow: var(--bm-shadow-md);
}

.bm-surface--classic {
    border-radius: var(--bm-radius-card-classic);
    box-shadow: var(--bm-shadow-card-classic);
}

/* Disclosure tables
 * Accordion-style tables use the lighter, compact treatment from the original
 * operational views. They are intentionally distinct from alt-header tables.
 */
.bm-disclosure-table {
    overflow: hidden;
    border: 0;
    border-radius: var(--bm-radius-sm);
    background: var(--bm-color-surface);
    padding: 0;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12);
}

.bm-disclosure-table .module-header {
    border-bottom-color: #e0e0e0;
}

.bm-disclosure-table .module-header h3 {
    color: var(--bm-color-primary);
    font-family: var(--bm-font-body);
    letter-spacing: normal;
    line-height: normal;
}

.bm-disclosure-table .bm-table-wrap {
    border: 0;
    border-radius: 0;
}

body.app-shell :where(.card-header, .panel-header, .table-header) {
    border-bottom: 1px solid var(--bm-color-border);
    background: var(--bm-color-surface-muted);
    color: var(--bm-color-ink);
}

/* Buttons and button-like links */
.bm-button,
body.app-shell :where(.btn-primary, .btn-submit, .filter-btn, .apply-date-range-button, .btn-save) {
    min-height: var(--bm-control-height);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--bm-space-2);
    border: 1px solid transparent;
    border-radius: var(--bm-radius-sm);
    background: var(--bm-color-deep);
    color: #fff;
    padding: 0.65rem 1.1rem;
    font-size: var(--bm-text-sm);
    font-weight: 700;
    line-height: 1.1;
    text-decoration: none;
    cursor: pointer;
    transition: background-color var(--bm-transition), border-color var(--bm-transition), box-shadow var(--bm-transition), transform var(--bm-transition);
}

.bm-button:hover,
body.app-shell :where(.btn-primary, .btn-submit, .filter-btn, .apply-date-range-button, .btn-save):hover:not(:disabled) {
    background: var(--bm-color-deep-hover);
    color: #fff;
}

.bm-button:focus-visible,
body.app-shell :where(button, a, input, select, textarea):focus-visible {
    outline: 2px solid transparent;
    box-shadow: var(--bm-focus-ring);
}

.bm-button--secondary,
body.app-shell :where(.clear-btn, .btn-cancel) {
    border-color: var(--bm-color-border-strong);
    background: var(--bm-color-surface);
    color: var(--bm-color-ink-soft);
}

.bm-button--danger {
    background: var(--bm-color-danger);
}

.bm-button--compact {
    min-height: 0;
    border: 0;
    padding: 4px 12px;
    white-space: nowrap;
}

.bm-button:disabled,
body.app-shell button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

/* Fields and filters */
.bm-field,
body.app-shell :where(.filter-select, .filter-input, input[type="text"], input[type="email"], input[type="date"], input[type="time"], input[type="number"], select, textarea) {
    min-height: var(--bm-filter-panel-control-height, var(--bm-control-height));
    border: 1px solid var(--bm-filter-panel-control-border, var(--bm-color-border-strong));
    border-radius: var(--bm-radius-sm);
    background-color: var(--bm-color-surface);
    color: var(--bm-color-ink);
    padding: var(--bm-filter-panel-control-padding, 0.6rem 0.75rem);
    font-size: var(--bm-filter-panel-control-font-size, inherit);
    transition: border-color var(--bm-transition), box-shadow var(--bm-transition), background-color var(--bm-transition);
}

body.app-shell :where(.filter-select, .filter-input, input, select, textarea):focus {
    border-color: var(--bm-color-primary);
    outline: none;
    box-shadow: var(--bm-focus-ring);
}

body.app-shell :where(input[type="checkbox"], input[type="radio"]),
body.guest-shell :where(input[type="checkbox"], input[type="radio"]) {
    accent-color: var(--bm-color-primary);
}

.bm-field--readonly {
    background: var(--bm-color-surface-muted) !important;
    color: var(--bm-color-muted);
}

.bm-form-errors {
    margin: 0 0 var(--bm-space-4);
    border: 1px solid #efb7b7;
    border-radius: var(--bm-radius-md);
    background: var(--bm-color-danger-soft);
    color: var(--bm-color-danger);
    padding: var(--bm-space-3) var(--bm-space-4);
    list-style: none;
}

.bm-field-error {
    display: block;
    margin-top: var(--bm-space-1);
    color: var(--bm-color-danger);
    font-size: var(--bm-text-xs);
    font-weight: 600;
}

body.app-shell :where(label, .filter-group label) {
    color: var(--bm-filter-panel-label-color, var(--bm-color-ink-soft));
    font-size: var(--bm-filter-panel-label-font-size, var(--bm-text-sm));
    font-weight: var(--bm-filter-panel-label-font-weight, 600);
}

.bm-filter-panel,
body.app-shell :where(.filters-section, .filter-section) {
    padding: var(--bm-filter-panel-section-padding, var(--bm-space-5));
}

.bm-filter-panel--alt {
    --bm-filter-panel-accent: #1976d2;
    --bm-filter-panel-border: #d8e2ea;
    --bm-filter-panel-control-border: #d8e2ea;
    --bm-filter-panel-label-color: var(--bm-color-ink);
    --bm-filter-panel-label-font-size: var(--bm-text-xs);
    --bm-filter-panel-label-font-weight: 400;
    --bm-filter-panel-section-bg: #f7f9fb;
    --bm-filter-panel-section-padding: var(--bm-space-3);
    --bm-filter-panel-toggle-hover-bg: var(--bm-color-surface-muted);
    --bm-filter-panel-control-height: 34px;
    --bm-filter-panel-control-padding: 0.45rem 0.625rem;
    --bm-filter-panel-control-font-size: var(--bm-text-xs);
    padding: 0;
}

.bm-filter-panel__section--flush {
    --bm-filter-panel-section-padding: 0;
}

body.app-shell .bm-filter-panel > .filter-section {
    padding: 0;
}

/* Tables */
.bm-table-wrap,
body.app-shell .table-responsive {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--bm-color-border);
    border-radius: var(--bm-radius-md);
    background: var(--bm-color-surface);
}

.bm-table,
body.app-shell :where(.table-responsive table, table.data-table) {
    width: 100%;
    border-collapse: collapse;
    color: var(--bm-color-ink);
}

.bm-table--alt-header {
    --bm-table-header-bg: #1976d2;
    --bm-table-header-border: rgba(255, 255, 255, 0.7);
    --bm-table-header-color: #fff;
    --bm-table-header-font-size: var(--bm-text-md);
    --bm-table-header-font-weight: 500;
    --bm-table-header-hover-bg: #1565c0;
    --bm-table-header-letter-spacing: 0;
}

.bm-table--disclosure {
    --bm-table-header-bg: var(--bm-color-surface);
    --bm-table-header-border: #e0e0e0;
    --bm-table-header-color: var(--bm-color-primary);
    --bm-table-header-font-size: var(--bm-text-md);
    --bm-table-header-font-weight: 500;
    --bm-table-header-hover-bg: var(--bm-color-primary-soft);
    --bm-table-header-letter-spacing: 0;
}

.bm-table th,
body.app-shell :where(.table-responsive table, table.data-table) th {
    border-bottom: 1px solid var(--bm-table-header-border, var(--bm-color-border-strong));
    background: var(--bm-table-header-bg, var(--bm-color-surface-muted));
    color: var(--bm-table-header-color, var(--bm-color-ink-soft));
    font-size: var(--bm-table-header-font-size, var(--bm-text-xs));
    font-weight: var(--bm-table-header-font-weight, 700);
    letter-spacing: var(--bm-table-header-letter-spacing, 0.04em);
    text-transform: uppercase;
}

.bm-table :where(th, td),
body.app-shell :where(.table-responsive table, table.data-table) :where(th, td) {
    padding: 0.8rem 0.9rem;
    text-align: left;
    vertical-align: middle;
}

.bm-table td,
body.app-shell :where(.table-responsive table, table.data-table) td {
    border-bottom: 1px solid var(--bm-color-border);
}

.bm-table tbody tr:hover,
body.app-shell :where(.table-responsive table, table.data-table) tbody tr:hover {
    background: var(--bm-color-primary-soft);
}

.bm-table.bm-table--disclosure :where(th, td) {
    border: 1px solid #e0e0e0;
    background: var(--bm-color-surface);
    padding: 0.75rem 1rem;
    line-height: 1.2;
}

.bm-table.bm-table--disclosure th {
    color: var(--bm-color-primary);
    font-weight: 500;
}

.bm-table.bm-table--disclosure td {
    color: var(--bm-color-ink);
    font-weight: 700;
}

.bm-table.bm-table--disclosure th.sortable:hover {
    background: var(--bm-color-primary-soft);
}

.bm-disclosure-table .bm-button--compact {
    background: #2563a5;
    font-size: var(--bm-text-md);
    font-weight: 600;
    letter-spacing: 1px;
    line-height: 1.2;
}

.bm-disclosure-table .bm-button--compact:hover {
    background: #1f548d;
}

.bm-table--fixed-columns {
    table-layout: fixed;
}

.bm-table--fixed-columns :where(th, td) {
    min-width: 0;
    overflow-wrap: anywhere;
}

/* Badges and statuses */
.bm-badge,
body.app-shell :where(.status-badge, .badge) {
    display: inline-flex;
    align-items: center;
    gap: var(--bm-space-1);
    min-height: 24px;
    border-radius: var(--bm-radius-pill);
    padding: 0.2rem 0.65rem;
    background: var(--bm-color-info-soft);
    color: var(--bm-color-info);
    font-size: var(--bm-text-xs);
    font-weight: 700;
    line-height: 1;
}

.bm-badge--success,
body.app-shell :where(.status-completed, .status-active, .badge-success) {
    background: var(--bm-color-success-soft);
    color: var(--bm-color-success);
}

.bm-badge--warning,
body.app-shell :where(.status-pending, .status-warning, .badge-warning) {
    background: var(--bm-color-warning-soft);
    color: var(--bm-color-warning);
}

.bm-badge--danger,
body.app-shell :where(.status-overdue, .status-critical, .badge-danger) {
    background: var(--bm-color-danger-soft);
    color: var(--bm-color-danger);
}

/* Empty states */
.bm-empty-state,
body.app-shell :where(.empty-state, .tenant-empty-state, .tenant-home-empty, .tenant-error-panel) {
    width: 100%;
    border: 1px dashed var(--bm-color-border-strong);
    border-radius: var(--bm-radius-md);
    background: rgba(255, 255, 255, 0.86);
    color: var(--bm-color-muted);
    padding: var(--bm-space-10) var(--bm-space-6);
    text-align: center;
}

body.app-shell :where(.empty-state, .tenant-empty-state, .tenant-home-empty, .tenant-error-panel) h3 {
    margin: 0 0 var(--bm-space-2);
    color: var(--bm-color-ink);
}

.bm-empty-state > .material-icons {
    margin-bottom: var(--bm-space-2);
    color: var(--bm-color-deep);
    font-size: 2rem;
}

.bm-empty-state__body :where(p, ul) {
    margin: 0;
}

.bm-empty-state__actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: var(--bm-space-3);
    margin-top: var(--bm-space-5);
}

/* Dialogs */
.bm-dialog-backdrop,
body.app-shell :where(.modal, .modal-overlay) {
    background: rgba(0, 23, 56, 0.48);
    backdrop-filter: blur(2px);
}

.bm-dialog,
body.app-shell :where(.modal-content, .modal-container) {
    border: 1px solid var(--bm-color-border);
    border-radius: var(--bm-radius-lg);
    background: var(--bm-color-surface);
    box-shadow: var(--bm-shadow-lg);
}

/* Shared responsive behavior */
@media (max-width: 992px) {
    .bm-page,
    body.app-shell :where(.performance-container, .container-fluid, .container-medium, .container-wide) {
        width: 100%;
        max-width: none;
    }

    .bm-page-header,
    body.app-shell .performance-header {
        margin-block: var(--bm-space-4) var(--bm-space-6);
    }

    .snapshot-mode-banner {
        flex-wrap: wrap;
        align-items: flex-start;
    }

    .snapshot-exit-link {
        width: 100%;
        margin-left: 0;
    }
}

@media (max-width: 600px) {
    body.app-shell {
        font-size: 0.9375rem;
    }

    .bm-page-header__title,
    body.app-shell .performance-header h2 {
        font-size: clamp(1.9rem, 10vw, 2.5rem);
    }

    .bm-surface {
        padding: var(--bm-space-4);
    }

    .header-controls,
    .performance-header.admin-settings-header {
        width: 100%;
        flex-direction: column;
        align-items: stretch;
    }

    .admin-home-header-button,
    .snapshot-selector,
    .header-location-selector {
        width: 100%;
        margin-left: 0;
        justify-content: space-between;
    }

    .snapshot-label,
    .header-location-label {
        flex: 1;
        min-width: 0;
    }

    .snapshot-dropdown,
    .header-location-dropdown {
        left: 0;
        right: auto;
        width: min(100%, 340px);
        min-width: 0;
        max-width: calc(100vw - 32px);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}
