:root {
    --brand-primary: #0F2A44;
    --brand-primary-dark: #0A1F33;
    --brand-primary-hover: #16385A;
    --brand-accent: #D4A24C;
    --brand-bg: #F4F6F8;
    --brand-surface: #FFFFFF;
    --brand-border: #E1E5EA;
    --brand-text: #1A2533;
    --brand-text-muted: #5C6E7E;
    --brand-muted-on-dark: #9CA8B5;
    --brand-danger: #B3261E;
    --brand-success: #198754;
    --sidebar-width: 248px;
    --topbar-height: 64px;
    /* Configurable work-order colors (overridden per-org by App.razor from stored settings). */
    --wo-priority-high: #dc3545;
    --wo-priority-high-text: #ffffff;
    --wo-priority-medium: #ffc107;
    --wo-priority-medium-text: #000000;
    --wo-priority-low: #6c757d;
    --wo-priority-low-text: #ffffff;
    --wo-today: #0d6efd;
    --wo-today-text: #ffffff;
}

.wo-prio-high { background-color: var(--wo-priority-high); color: var(--wo-priority-high-text); }
.wo-prio-medium { background-color: var(--wo-priority-medium); color: var(--wo-priority-medium-text); }
.wo-prio-low { background-color: var(--wo-priority-low); color: var(--wo-priority-low-text); }
.wo-today-bg { background-color: var(--wo-today) !important; color: var(--wo-today-text) !important; }

html, body {
    height: 100%;
}

body {
    margin: 0;
    background-color: var(--brand-bg);
    color: var(--brand-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

/* Brand button overrides so Bootstrap primary matches the navy palette. */
.btn-primary {
    --bs-btn-bg: var(--brand-primary);
    --bs-btn-border-color: var(--brand-primary);
    --bs-btn-hover-bg: var(--brand-primary-hover);
    --bs-btn-hover-border-color: var(--brand-primary-hover);
    --bs-btn-active-bg: var(--brand-primary-dark);
    --bs-btn-active-border-color: var(--brand-primary-dark);
}

.btn-link {
    --bs-btn-color: var(--brand-primary);
    --bs-btn-hover-color: var(--brand-primary-hover);
    text-decoration: none;
}

.btn-outline-primary {
    --bs-btn-color: var(--brand-primary);
    --bs-btn-border-color: var(--brand-primary);
    --bs-btn-hover-bg: var(--brand-primary);
    --bs-btn-hover-border-color: var(--brand-primary);
    --bs-btn-hover-color: #fff;
    --bs-btn-active-bg: var(--brand-primary-dark);
    --bs-btn-active-border-color: var(--brand-primary-dark);
    --bs-btn-active-color: #fff;
}

.text-primary { color: var(--brand-primary) !important; }

.app-splash {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--brand-primary-dark);
}

/* ---- App shell -------------------------------------------------------- */
.app-shell {
    display: flex;
    flex-direction: row;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background-color: var(--brand-primary-dark);
    border-right: 1px solid #091828;
    display: flex;
    flex-direction: column;
    padding: 16px 12px;
    position: relative;
}

.sidebar-brand {
    padding: 12px 8px;
    margin-bottom: 16px;
    text-align: center;
}

.sidebar-logo {
    width: 100%;
    height: 56px;
    object-fit: contain;
    background-color: #fff;
    border-radius: 8px;
    padding: 8px;
}

/* Pin / unpin toggle anchored in the menu's top-right corner. A single button whose icon
   swaps: a filled pin when pinned (expanded) and an outline pin when unpinned (collapsed). */
.sidebar-pin {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.6);
    font-size: 16px;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 6px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
}
.sidebar-pin:hover { background-color: rgba(255, 255, 255, 0.12); color: #fff; }
.sidebar-pin .pin-icon-unpinned { display: none; }
.app-shell.nav-toggled .sidebar-pin .pin-icon-pinned { display: none; }
.app-shell.nav-toggled .sidebar-pin .pin-icon-unpinned { display: inline-flex; }
/* On mobile the rail is a drawer driven by the hamburger/backdrop, so hide the pin. */
@media (max-width: 900px) { .sidebar-pin { display: none; } }

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.nav-section + .nav-section {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #091828;
}

.nav-section-label {
    color: var(--brand-muted-on-dark);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    padding: 0 12px 4px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--brand-muted-on-dark);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
}

.nav-item:hover {
    background-color: #162C44;
    color: #fff;
}

.nav-item-active {
    background-color: var(--brand-primary);
    color: #fff;
    border-left: 3px solid var(--brand-accent);
    padding-left: 9px;
}

.nav-item-active i { color: var(--brand-accent); }

.nav-item-disabled {
    opacity: 0.55;
    cursor: default;
}

/* AI Settings tabs — outlined "real tab" look. The generic .nav-item rules above
   are the dark sidebar nav; reset them here so Bootstrap's <li class="nav-item">
   tab wrappers don't pick up the dark hover fill. */
.ai-tabs.nav-tabs, .app-tabs.nav-tabs {
    border-bottom: 1px solid #000;
    gap: 4px;
}
.ai-tabs .nav-item, .app-tabs .nav-item {
    display: block;
    padding: 0;
    border-radius: 0;
    background-color: transparent;
    color: inherit;
}
.ai-tabs .nav-item:hover, .app-tabs .nav-item:hover {
    background-color: transparent;
    color: inherit;
}
.ai-tabs .nav-link, .app-tabs .nav-link {
    margin-bottom: -1px;
    padding: 8px 16px;
    border: 1px solid #000;            /* hairline black outline around each tab */
    border-radius: 6px 6px 0 0;
    background-color: #fff;
    color: var(--brand-text);
    font-weight: 500;
}
.ai-tabs .nav-link:hover, .app-tabs .nav-link:hover {
    background-color: var(--brand-surface, #f1f3f5);
    color: var(--brand-text);
    border-color: #000;
}
.ai-tabs .nav-link.active, .app-tabs .nav-link.active {
    background-color: #fff;
    color: var(--brand-primary);
    font-weight: 600;
    border-color: #000;
    border-bottom-color: #fff;         /* merge the active tab into the content area */
}

.sidebar-footer {
    padding: 16px 12px 0;
    border-top: 1px solid #091828;
}

.sidebar-footer-text {
    color: #fff;
    font-size: 13px;
    font-weight: 600;
}

.sidebar-footer-muted {
    color: var(--brand-muted-on-dark);
    font-size: 11px;
    margin-top: 2px;
}

.app-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.topbar {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 24px;
    background-color: var(--brand-surface);
    border-bottom: 1px solid var(--brand-border);
}

.topbar-title-wrap { flex: 1; }

.topbar-title {
    color: var(--brand-text);
    font-weight: 600;
    font-size: 16px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-user { text-align: right; line-height: 1.2; }
.topbar-user-name { display: block; color: var(--brand-text); font-size: 13px; font-weight: 600; }
.topbar-user-email { display: block; color: var(--brand-text-muted); font-size: 11px; }

.topbar-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--brand-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
}

.topbar-logout {
    padding: 8px;
    border-radius: 8px;
    color: var(--brand-text-muted);
    display: inline-flex;
}

.topbar-logout:hover { background-color: var(--brand-bg); color: var(--brand-text); }

.app-content {
    flex: 1;
    background-color: var(--brand-bg);
    overflow-y: auto;
}

.page-inner {
    /* Fill the available width (rail + this content area); no centered max-width cap. */
    width: 100%;
    margin: 0 auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.page-title { color: var(--brand-text); font-weight: 700; font-size: 24px; margin: 0; }
.page-subtitle { color: var(--brand-text-muted); margin: 4px 0 0; }
.page-header { margin-bottom: 8px; }
.welcome { margin-bottom: 8px; }

/* ---- Cards / dashboard ------------------------------------------------ */
.card {
    background-color: var(--brand-surface);
    border: 1px solid var(--brand-border);
    border-radius: 12px;
}

.kpi-row, .card-split {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
}

.kpi-card { flex: 1 1 200px; }
.kpi-link {
    text-decoration: none;
    color: inherit;
    transition: transform 0.1s ease, box-shadow 0.1s ease;
}
.kpi-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.1);
    color: inherit;
}
.kpi-link:focus-visible {
    outline: 2px solid var(--brand-primary, #1565d8);
    outline-offset: 2px;
}
.kpi-label { color: var(--brand-text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-value { color: var(--brand-text); font-size: 32px; font-weight: 700; margin-top: 4px; }
.kpi-trend { color: var(--brand-text-muted); font-size: 12px; margin-top: 4px; }
.kpi-trend-success { color: var(--brand-success); }
.kpi-trend-warn { color: var(--brand-accent); }

.panel-card { flex: 1 1 320px; }
.panel-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.panel-title { font-size: 16px; font-weight: 600; margin: 0; color: var(--brand-text); }
.panel-muted { color: var(--brand-text-muted); margin-bottom: 12px; }

/* ---- Settings tiles --------------------------------------------------- */
.tile-grid { display: flex; flex-wrap: wrap; gap: 16px; }

.tile-card {
    width: 280px;
    background-color: var(--brand-surface);
    border: 1px solid var(--brand-border);
    border-radius: 12px;
    padding: 16px;
    text-decoration: none;
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 6px;
    transition: transform 0.1s ease;
}

.tile-card:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(15, 42, 68, 0.08); }

.tile-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background-color: var(--brand-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 4px;
    color: var(--brand-primary);
    font-size: 22px;
}

.tile-label { color: var(--brand-text); font-weight: 700; }
.tile-description { color: var(--brand-text-muted); font-size: 13px; line-height: 18px; }
.tile-footer { display: flex; align-items: center; gap: 4px; margin-top: 8px; color: var(--brand-primary); font-size: 13px; font-weight: 600; }

/* ---- Auth (login / register) ----------------------------------------- */
.auth-shell { display: flex; min-height: 100vh; background-color: var(--brand-bg); }

.auth-form-side {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.auth-form-col { width: 100%; max-width: 420px; }

.auth-brand { text-align: center; margin-bottom: 16px; }
.auth-logo { width: 220px; max-width: 100%; height: 56px; object-fit: contain; background-color: #fff; border-radius: 6px; }

.auth-form { width: 100%; }
.auth-title { color: var(--brand-text); font-weight: 700; font-size: 24px; margin: 0; }
.auth-subtitle { color: var(--brand-text-muted); margin: 4px 0 16px; }
.auth-submit { margin-top: 8px; padding: 10px; border-radius: 6px; }
.auth-link { margin-top: 8px; }
.auth-field-error { color: var(--brand-danger); font-size: 13px; margin-top: 4px; }
.auth-form-error {
    color: var(--brand-danger);
    background-color: rgba(179, 38, 30, 0.08);
    border: 1px solid rgba(179, 38, 30, 0.25);
    border-radius: 6px;
    padding: 8px 12px;
    font-size: 14px;
    margin-bottom: 8px;
}

.auth-hero-side {
    flex: 1;
    background-size: cover;
    background-position: center;
    display: none;
}

.auth-hero-overlay {
    height: 100%;
    background-color: rgba(15, 42, 68, 0.65);
    display: flex;
    align-items: flex-end;
    padding: 40px;
}

.auth-hero-content { max-width: 480px; }
.auth-hero-eyebrow { color: var(--brand-accent); font-size: 12px; letter-spacing: 1.5px; text-transform: uppercase; font-weight: 600; margin: 0 0 8px; }
.auth-hero-title { color: #fff; font-size: 28px; font-weight: 700; line-height: 36px; margin: 0 0 8px; }
.auth-hero-subtitle { color: var(--brand-muted-on-dark); font-size: 14px; margin: 0; }

@media (min-width: 900px) {
    .auth-hero-side { display: block; }
}

/* ---- Users manage page ------------------------------------------------ */
.users-header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.users-header-text { flex: 1; }

.users-toolbar { display: flex; }
.users-search { max-width: 420px; }
.users-search .input-group-text { background-color: var(--brand-surface); }

.users-card { overflow: hidden; }
.users-state { padding: 32px; display: flex; flex-direction: column; align-items: center; gap: 8px; }

.wo-link {
    text-decoration: none;
    color: var(--brand-text);
    font-weight: 600;
}
.wo-link:hover,
.wo-link:focus-visible {
    text-decoration: none;
    color: var(--brand-primary, #1565d8);
}

.users-table { margin: 0; }
.users-table thead th { color: var(--brand-text-muted); font-weight: 600; font-size: 13px; border-bottom: 1px solid var(--brand-border); }
.users-table td { vertical-align: middle; color: var(--brand-text); }
.users-empty { color: var(--brand-text-muted); padding: 16px; text-align: center; }
.users-actions { white-space: nowrap; }

.btn-icon {
    background: transparent;
    border: none;
    color: var(--brand-text-muted);
    padding: 4px 8px;
    border-radius: 6px;
}
.btn-icon:hover:not(:disabled) { background-color: var(--brand-bg); color: var(--brand-text); }
.btn-icon:disabled { opacity: 0.4; }
.btn-icon.text-danger { color: var(--brand-danger); }

.role-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
}
.role-chip-user { background-color: var(--brand-bg); color: var(--brand-text); }
.role-chip-admin { background-color: #FEF1D6; color: #7A5A12; }

.users-pagination { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--brand-border); }
.users-pagination-label { color: var(--brand-text-muted); font-size: 13px; }

.role-toggle .btn { --bs-btn-active-bg: var(--brand-primary); }

/* ---- Modals / dialogs ------------------------------------------------- */
.modal-backdrop-custom {
    position: fixed;
    inset: 0;
    background-color: rgba(10, 31, 51, 0.45);
    z-index: 1040;
}

.modal-card {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: var(--brand-surface);
    border-radius: 12px;
    padding: 24px;
    /* Roomy by default so multi-field forms don't cramp/wrap; caps at the viewport on small screens. */
    width: min(560px, calc(100vw - 32px));
    z-index: 1050;
    box-shadow: 0 12px 40px rgba(10, 31, 51, 0.25);
    max-height: 90vh;
    overflow-y: auto;
}

/* Wider variant for form-heavy dialogs (multiple side-by-side fields, e.g. Project). */
.modal-card-wide { width: min(860px, calc(100vw - 32px)); }

.modal-title { font-size: 20px; font-weight: 700; margin: 0 0 16px; color: var(--brand-text); }

.confirm-card { max-width: 420px; text-align: center; }
.confirm-icon { color: var(--brand-danger); font-size: 32px; margin-bottom: 8px; }
.confirm-title { font-size: 20px; font-weight: 700; margin: 0 0 12px; }
.confirm-body { color: var(--brand-text); margin-bottom: 8px; }
.confirm-note { color: var(--brand-text-muted); font-size: 13px; margin-bottom: 16px; }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }

/* ---- Snackbar --------------------------------------------------------- */
.snackbar {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translateX(-50%);
    background-color: var(--brand-text);
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 1060;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

/* ---- Health / diagnostics -------------------------------------------- */
.health-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; }
.health-status { font-size: 32px; font-weight: 600; color: var(--brand-success); margin: 0; }
.health-service { margin-top: 8px; font-size: 14px; color: var(--brand-text-muted); }

/* ---- API status page -------------------------------------------------- */
.status-root { max-width: 920px; margin: 24px auto; padding: 0 16px; display: flex; flex-direction: column; gap: 16px; }
.status-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.status-h1 { font-size: 24px; font-weight: 700; margin: 0; color: var(--brand-text); }
.status-sub { color: var(--brand-text-muted); margin: 0; }
.status-h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; color: var(--brand-text); }
.status-card { }
.status-loading { padding: 24px; display: flex; justify-content: center; }

.status-meta th { width: 38%; color: var(--brand-text-muted); font-weight: 600; font-size: 13px; vertical-align: top; }
.status-meta td { color: var(--brand-text); word-break: break-all; }
.status-meta code, .probe-url code, .status-foot code { font-size: 13px; }

.status-pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill-ok { background-color: #E3F4EA; color: var(--brand-success); }
.pill-fail { background-color: #FBE3E1; color: var(--brand-danger); }
.pill-muted { background-color: var(--brand-bg); color: var(--brand-text-muted); }

.probe { border: 1px solid var(--brand-border); border-radius: 10px; padding: 12px 16px; margin-bottom: 12px; }
.probe:last-child { margin-bottom: 0; }
.probe-ok { border-left: 4px solid var(--brand-success); }
.probe-fail { border-left: 4px solid var(--brand-danger); }
.probe-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.probe-icon { font-size: 18px; }
.probe-ok .probe-icon { color: var(--brand-success); }
.probe-fail .probe-icon { color: var(--brand-danger); }
.probe-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.probe-name { font-weight: 600; color: var(--brand-text); }
.probe-url { color: var(--brand-text-muted); font-size: 12px; word-break: break-all; }
.probe-stat { display: flex; align-items: center; gap: 8px; }
.probe-ms { color: var(--brand-text-muted); font-size: 12px; }
.probe-error { color: var(--brand-danger); font-size: 13px; margin-top: 8px; }
.probe-note { color: var(--brand-text-muted); font-size: 13px; margin-top: 8px; }
.probe-section-label { color: var(--brand-text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-top: 10px; }
.probe-body {
    background-color: var(--brand-bg);
    border-radius: 6px;
    padding: 10px 12px;
    margin: 4px 0 0;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-all;
    max-height: 240px;
    overflow: auto;
}
.status-foot { color: var(--brand-text-muted); font-size: 13px; margin: 0; }

/* ---- Kanban board drag-and-drop -------------------------------------- */
.kanban-card { cursor: grab; }
.kanban-card:active { cursor: grabbing; }
.kanban-card.kanban-dragging { opacity: 0.5; }
/* Roomy cells so the High/Med/Low vertical drop zones have space, and a hover hint. */
.kanban-cell { min-height: 7rem; transition: background-color 0.1s ease; }
.kanban-board td.kanban-cell:hover { background-color: #eef2f6 !important; }

/* Flex-column board views (Operations, Op status). */
.kanban-col { width: 20rem; }
.kanban-col-narrow { width: 18rem; }

/* Touch devices can't fire HTML5 drag events — cards are tap-to-act (buttons/links),
   so drop the grab cursor that implies dragging. */
@media (pointer: coarse) {
    .kanban-card, .kanban-card:active { cursor: default; }
}

/* Phones: columns shrink to ~viewport width so you swipe one column at a time
   instead of scrolling a tiny sliver. */
@media (max-width: 768px) {
    .kanban-col, .kanban-col-narrow { width: 85vw; max-width: 22rem; }
}

/* ---- Collapsible left rail ------------------------------------------- */
/* Hamburger toggle in the top bar (always visible). */
.topbar-toggle {
    background: transparent;
    border: none;
    color: var(--brand-text-muted);
    font-size: 22px;
    line-height: 1;
    padding: 8px 10px;
    margin-right: 8px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
}
.topbar-toggle:hover { background-color: var(--brand-bg); color: var(--brand-text); }

/* Smooth the rail width change on desktop collapse. */
.sidebar { transition: transform 0.2s ease; }

/* Backdrop behind the mobile drawer; hidden unless the drawer is open on a narrow screen. */
.sidebar-backdrop { display: none; }

/* Desktop: rail shows by default; collapse it when toggled. */
@media (min-width: 901px) {
    /* Collapsed: pull the rail off-canvas so content fills the width, but keep it as a hover
       flyout — hovering the hamburger (or the rail itself) slides it in so you can click an
       item without re-expanding the layout. */
    .app-shell.nav-toggled .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
        z-index: 1045;
    }
    .app-shell.nav-toggled:has(.topbar-toggle:hover) .sidebar,
    .app-shell.nav-toggled .sidebar:hover {
        transform: translateX(0);
        box-shadow: 0 0 40px rgba(10, 31, 51, 0.35);
    }
}

/* ---- Responsive ------------------------------------------------------- */
@media (max-width: 900px) {
    /* The rail becomes an off-canvas drawer: hidden by default, slid in when toggled. */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100%;
        transform: translateX(-100%);
        z-index: 1045;
    }
    .app-shell.nav-toggled .sidebar {
        transform: translateX(0);
        box-shadow: 0 0 40px rgba(10, 31, 51, 0.45);
    }
    .app-shell.nav-toggled .sidebar-backdrop {
        display: block;
        position: fixed;
        inset: 0;
        background-color: rgba(10, 31, 51, 0.45);
        z-index: 1044;
    }
}

/* ---- Mobile: reclaim horizontal space -------------------------------------
   Fixed 24px page padding costs 48px on a ~375px phone; tighten it below the
   phone breakpoint so content (especially cards and tables) gets the width. */
@media (max-width: 768px) {
    .page-inner { padding: 12px; gap: 12px; }
    .page-title { font-size: 20px; }
}

/* ---- Mobile: stack data tables into cards ---------------------------------
   Auto-adapts by viewport width — no device toggle. Add class "table-cards" to
   a .table and a data-label to each <td>. Below the phone breakpoint the header
   row is hidden and each row renders as a bordered card of "Label: value" pairs.
   Special per-cell classes:
     .table-cards-primary  → full-width heading row (e.g. the work order number)
     .table-cards-hide     → dropped on mobile (redundant spacer/icon cells)
     .users-actions        → buttons row, left-aligned with a top divider
   Cells with no data-label (and none of the classes above) render value-only. */
@media (max-width: 768px) {
    .table-cards thead { display: none; }
    .table-cards,
    .table-cards tbody,
    .table-cards tr,
    .table-cards td { display: block; width: 100%; }

    .table-cards tr {
        border: 1px solid var(--brand-border);
        border-radius: 10px;
        padding: 10px 12px;
        margin-bottom: 12px;
        background-color: var(--brand-surface);
        box-shadow: 0 1px 2px rgba(10, 31, 51, 0.06);
    }
    .table-cards tr:last-child { margin-bottom: 0; }

    .table-cards td {
        display: flex;
        justify-content: space-between;
        align-items: baseline;
        gap: 1rem;
        text-align: right;
        padding: 4px 0;
        border: 0;
    }
    .table-cards td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 12px;
        color: var(--brand-text-muted);
        text-align: left;
        white-space: nowrap;
    }
    /* Value-only cells: no pseudo-label. */
    .table-cards td:not([data-label])::before { content: none; }

    .table-cards td.table-cards-primary {
        justify-content: flex-start;
        text-align: left;
        font-size: 18px;
        font-weight: 700;
        padding-bottom: 8px;
    }

    .table-cards td.table-cards-hide { display: none; }

    .table-cards td.users-actions {
        justify-content: flex-start;
        gap: 0.5rem;
        margin-top: 8px;
        padding-top: 8px;
        border-top: 1px solid var(--brand-border);
        white-space: normal;
        flex-wrap: wrap;
    }

    /* Comfortable touch targets inside stacked cards. */
    .table-cards .btn-sm { padding: 0.375rem 0.75rem; }
    .table-cards .btn-icon { padding: 8px 12px; }
}

/* ---- Mobile: stack EDITING tables into form cards -------------------------
   Like .table-cards, but each cell renders label-above-full-width-input (better
   for inputs/selects than the read-only "label: value" row). Use class
   "table-cards-form" + a data-label per <td>. Add .tc-inline to a checkbox cell
   to keep its label and box on one line. */
@media (max-width: 768px) {
    .table-cards-form thead { display: none; }
    .table-cards-form,
    .table-cards-form tbody,
    .table-cards-form tr,
    .table-cards-form td { display: block; width: 100%; }

    .table-cards-form tr {
        border: 1px solid var(--brand-border);
        border-radius: 10px;
        padding: 10px 12px;
        margin-bottom: 12px;
        background-color: var(--brand-surface);
        box-shadow: 0 1px 2px rgba(10, 31, 51, 0.06);
    }
    .table-cards-form tr:last-child { margin-bottom: 0; }

    .table-cards-form td {
        padding: 4px 0;
        border: 0;
        text-align: left !important;
    }
    .table-cards-form td::before {
        content: attr(data-label);
        display: block;
        font-weight: 600;
        font-size: 12px;
        color: var(--brand-text-muted);
        margin-bottom: 2px;
    }
    .table-cards-form td:not([data-label])::before { content: none; }

    /* Inputs fill the card width, overriding any fixed inline widths. */
    .table-cards-form td .form-control,
    .table-cards-form td .form-select {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
    }

    /* Checkbox cells: label and box on one line. */
    .table-cards-form td.tc-inline { display: flex; align-items: center; gap: 0.5rem; }
    .table-cards-form td.tc-inline::before { margin-bottom: 0; }
}

/* ---- PersonPicker ----------------------------------------------------- */
.person-picker-menu { z-index: 1056; max-height: 16rem; overflow-y: auto; }
.person-picker-item { cursor: pointer; }

/* A read-only field that should read as disabled (e.g. email mirrored from a linked login). */
.form-control-locked {
    background-color: var(--bs-secondary-bg, #e9ecef);
    opacity: 1;
}

/* ---- Work order "traveler" grid (mirrors the printed DES WORK ORDER form) ---- */
.wo-traveler { border: 1px solid #1a2533; overflow: hidden; }
.wo-traveler-head {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 12px; background-color: var(--brand-primary); color: #fff;
}
.wo-traveler-name { font-weight: 700; letter-spacing: 1px; font-size: 15px; }

/* Navy section header that matches the traveler's blue bar. Breaks out of the card's
   p-3 padding to span full width; .users-card has overflow:hidden so the top corners clip clean. */
.wo-section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin: -1rem -1rem 1rem;
    padding: 8px 16px;
    background-color: var(--brand-primary);
    color: #fff;
}
.wo-section-title { margin: 0; color: #fff; font-weight: 700; font-size: 15px; letter-spacing: 0.5px; }
.wo-traveler-no { font-size: 14px; }
.wo-grid { width: 100%; border-collapse: collapse; table-layout: fixed; margin: 0; }
.wo-grid th.wo-label {
    width: 8%; background-color: #eef1f4; border: 1px solid #c8ced3;
    padding: 4px 6px; font-size: 11px; font-weight: 700; text-transform: uppercase;
    color: #41505f; vertical-align: middle; white-space: normal; word-break: break-word;
}
.wo-grid td.wo-cell { width: 17%; border: 1px solid #c8ced3; padding: 0; overflow: hidden; }
.wo-grid .wo-field {
    width: 100%; max-width: 100%; box-sizing: border-box; border: 0; padding: 6px 8px;
    background-color: transparent; font-size: 14px; color: var(--brand-text);
}
.wo-grid .wo-field:focus { outline: 2px solid var(--brand-primary); outline-offset: -2px; }
.wo-grid .wo-field.is-invalid { background-color: #fdecea; box-shadow: inset 0 0 0 1px var(--bs-danger, #dc3545); }
.wo-cell-error { padding: 2px 8px 4px; font-size: 12px; color: var(--bs-danger, #dc3545); }
.wo-req { color: var(--bs-danger, #dc3545); margin-left: 2px; font-weight: 700; }
.wo-traveler-errors { padding: 6px 12px; font-size: 13px; }

/* Work order quick-filter facet chips */
.wo-facets { display: flex; flex-wrap: wrap; gap: 0.5rem 1.5rem; margin: 0 0 1rem; }
.wo-facet-group { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem; }
.wo-facet-label {
    font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em;
    color: #6c757d; margin-right: 0.15rem;
}
.wo-chip {
    border: 1px solid var(--bs-border-color, #dee2e6); background: #fff;
    color: var(--brand-text, #1f2d3d); border-radius: 999px; padding: 0.2rem 0.65rem;
    font-size: 0.8rem; line-height: 1.4; cursor: pointer; transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.wo-chip:hover { background: #f1f4f8; }
.wo-chip:focus-visible { outline: 2px solid var(--brand-primary, #0F2A44); outline-offset: 1px; }
.wo-chip.active { background: var(--brand-primary, #0F2A44); border-color: var(--brand-primary, #0F2A44); color: #fff; }
.wo-chip-count { font-weight: 700; margin-left: 0.3rem; opacity: 0.7; }
.wo-chip-clear { color: #b02a37; border-color: #f1c2c7; }
.wo-chip-clear:hover { background: #fbe9eb; }
@media (max-width: 768px) {
    .wo-grid, .wo-grid tbody, .wo-grid tr { display: block; }
    .wo-grid th.wo-label, .wo-grid td.wo-cell { display: block; width: 100%; }
}
