/* ==========================================================================
   Tactical90South / TARS — design system
   Palette taken from the TARS logo: navy ink #282E69, signal blue #427BD2,
   abyss #000732, slate #6D7A89, mist #D6D7E2. Type: Barlow (self-hosted).
   Light + dark themes driven by CSS custom properties.
   Theme resolution: <html data-theme="light|dark"> (explicit user choice)
   wins; without it, the OS preference (prefers-color-scheme) applies.
   Page templates must only use these tokens — never hard-coded colors —
   so both themes work everywhere.
   ========================================================================== */

@font-face { font-family: "Barlow"; font-style: normal; font-weight: 400; font-display: swap; src: url("../fonts/barlow/barlow-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-style: normal; font-weight: 500; font-display: swap; src: url("../fonts/barlow/barlow-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/barlow/barlow-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/barlow/barlow-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-style: normal; font-weight: 600; font-display: swap; src: url("../fonts/barlow/barlow-semi-condensed-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "Barlow Semi Condensed"; font-style: normal; font-weight: 700; font-display: swap; src: url("../fonts/barlow/barlow-semi-condensed-latin-700-normal.woff2") format("woff2"); }

:root {
    color-scheme: light;

    /* surfaces */
    --bg: #f2f3f8;
    --surface: #ffffff;
    --surface-2: #f0f1f7;         /* subtle fills: table heads, inputs, chips */
    --surface-3: #e5e7f0;         /* hover / pressed */
    --overlay: rgba(0, 7, 50, 0.5);

    /* lines */
    --border: #dcdee9;
    --border-strong: #c7cbdb;

    /* text */
    --text: #1b1f45;
    --text-muted: #586379;
    --text-faint: #8890a6;

    /* brand / accent */
    --accent: #3566be;
    --accent-hover: #2a539f;
    --accent-contrast: #ffffff;
    --accent-soft: rgba(53, 102, 190, 0.10);
    --accent-ring: rgba(53, 102, 190, 0.38);

    /* semantic */
    --ok: #157a3d;
    --ok-strong: #1f9a50;
    --ok-soft: rgba(31, 154, 80, 0.12);
    --warn: #a35a06;
    --warn-strong: #d9921a;
    --warn-soft: rgba(217, 146, 26, 0.14);
    --danger: #c21f2f;
    --danger-strong: #d8434d;
    --danger-soft: rgba(216, 67, 77, 0.11);
    --info: #0b6f86;
    --info-strong: #1592a8;
    --info-soft: rgba(21, 146, 168, 0.12);
    --violet: #5b3cc4;
    --violet-soft: rgba(91, 60, 196, 0.09);

    /* data series (charts, bars) — readable on both themes */
    --series-incidents: #e5484d;
    --series-commands: #2e9e66;
    --series-connections: #3566be;
    --series-debug: #d9921a;
    --chart-1: #3566be;
    --chart-2: #2e9e66;
    --chart-3: #d9921a;
    --chart-4: #d8434d;
    --chart-5: #7b4fd1;
    --chart-6: #1592a8;
    --chart-7: #c2408e;
    --chart-8: #6d7a89;
    --chart-grid: rgba(27, 31, 69, 0.08);

    /* navigation bar: TARS abyss navy in both themes (brand identity) */
    --nav-bg: #000732;
    --nav-border: #121a4a;
    --nav-text: #b9c1dd;
    --nav-text-active: #ffffff;
    --nav-hover: rgba(255, 255, 255, 0.07);
    --nav-active: rgba(111, 157, 232, 0.18);

    /* elevation: borders carry structure, shadows stay faint */
    --shadow-sm: 0 1px 1px rgba(27, 31, 69, 0.04);
    --shadow: 0 1px 2px rgba(27, 31, 69, 0.05);
    --shadow-lg: 0 16px 40px rgba(0, 7, 50, 0.18), 0 2px 6px rgba(0, 7, 50, 0.08);

    /* shape & type */
    --radius-sm: 5px;
    --radius: 7px;
    --radius-lg: 12px;
    --font: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --font-display: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;
    --font-mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", Menlo, Consolas, monospace;
    --nav-h: 60px;
}

/* dark tokens — applied by OS preference unless the user forced light,
   and always when the user forced dark */
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #070b22;
        --surface: #0e1433;
        --surface-2: #151c42;
        --surface-3: #1e2754;
        --overlay: rgba(2, 4, 18, 0.72);
        --border: #232b57;
        --border-strong: #323b6e;
        --text: #e3e6f4;
        --text-muted: #9aa2c2;
        --text-faint: #6a7299;
        --accent: #6f9de8;
        --accent-hover: #93b6f0;
        --accent-contrast: #050a24;
        --accent-soft: rgba(111, 157, 232, 0.15);
        --accent-ring: rgba(111, 157, 232, 0.5);
        --ok: #4acb75;
        --ok-strong: #3fbf69;
        --ok-soft: rgba(74, 203, 117, 0.15);
        --warn: #e8b54a;
        --warn-strong: #dba237;
        --warn-soft: rgba(232, 181, 74, 0.16);
        --danger: #ff7a72;
        --danger-strong: #f65a51;
        --danger-soft: rgba(255, 122, 114, 0.15);
        --info: #56cfe0;
        --info-strong: #3cbcd0;
        --info-soft: rgba(86, 207, 224, 0.14);
        --violet: #b39cf5;
        --violet-soft: rgba(179, 156, 245, 0.15);
        --series-incidents: #ff6b70;
        --series-commands: #3dd68c;
        --series-connections: #6f9de8;
        --series-debug: #f2bf4d;
        --chart-1: #6f9de8;
        --chart-2: #3dd68c;
        --chart-3: #f2bf4d;
        --chart-4: #ff6b70;
        --chart-5: #b39cf5;
        --chart-6: #4fc9da;
        --chart-7: #f07ac0;
        --chart-8: #98a2b8;
        --chart-grid: rgba(227, 230, 244, 0.08);
        --nav-bg: #04081f;
        --nav-border: #18204a;
        --shadow-sm: none;
        --shadow: none;
        --shadow-lg: 0 18px 48px rgba(0, 2, 14, 0.6);
    }
}
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #070b22;
    --surface: #0e1433;
    --surface-2: #151c42;
    --surface-3: #1e2754;
    --overlay: rgba(2, 4, 18, 0.72);
    --border: #232b57;
    --border-strong: #323b6e;
    --text: #e3e6f4;
    --text-muted: #9aa2c2;
    --text-faint: #6a7299;
    --accent: #6f9de8;
    --accent-hover: #93b6f0;
    --accent-contrast: #050a24;
    --accent-soft: rgba(111, 157, 232, 0.15);
    --accent-ring: rgba(111, 157, 232, 0.5);
    --ok: #4acb75;
    --ok-strong: #3fbf69;
    --ok-soft: rgba(74, 203, 117, 0.15);
    --warn: #e8b54a;
    --warn-strong: #dba237;
    --warn-soft: rgba(232, 181, 74, 0.16);
    --danger: #ff7a72;
    --danger-strong: #f65a51;
    --danger-soft: rgba(255, 122, 114, 0.15);
    --info: #56cfe0;
    --info-strong: #3cbcd0;
    --info-soft: rgba(86, 207, 224, 0.14);
    --violet: #b39cf5;
    --violet-soft: rgba(179, 156, 245, 0.15);
    --series-incidents: #ff6b70;
    --series-commands: #3dd68c;
    --series-connections: #6f9de8;
    --series-debug: #f2bf4d;
    --chart-1: #6f9de8;
    --chart-2: #3dd68c;
    --chart-3: #f2bf4d;
    --chart-4: #ff6b70;
    --chart-5: #b39cf5;
    --chart-6: #4fc9da;
    --chart-7: #f07ac0;
    --chart-8: #98a2b8;
    --chart-grid: rgba(227, 230, 244, 0.08);
    --nav-bg: #04081f;
    --nav-border: #18204a;
    --shadow-sm: none;
    --shadow: none;
    --shadow-lg: 0 18px 48px rgba(0, 2, 14, 0.6);
}

/* ----------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    font-feature-settings: "tnum" 0;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

h1, h2, h3, h4, h5, h6 { color: var(--text); font-family: var(--font-display); font-weight: 600; letter-spacing: 0; }
a { color: var(--accent); }
a:hover { color: var(--accent-hover); }
code, kbd, pre, samp { font-family: var(--font-mono); }
code { color: var(--text); background: var(--surface-2); border-radius: 4px; padding: 0.1em 0.35em; font-size: 0.88em; }
hr { border-color: var(--border); }
::selection { background: var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent-ring); outline-offset: 2px; }
img { max-width: 100%; }

/* scrollbars that don't glare in dark mode */
* { scrollbar-color: var(--border-strong) transparent; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------- Bootstrap 4 theme bridging */
/* Bootstrap ships light-only colors; map the pieces we use onto tokens. */
.table { color: var(--text); background: transparent; }
.table th, .table td { border-color: var(--border); }
.table thead th { border-bottom-color: var(--border); }
.table-striped tbody tr:nth-of-type(odd) { background: var(--surface-2); }
.table-hover tbody tr:hover { background: var(--surface-2); color: var(--text); }
.form-control, .custom-select {
    background-color: var(--surface);
    border-color: var(--border-strong);
    color: var(--text);
}
.form-control:focus, .custom-select:focus {
    background-color: var(--surface);
    border-color: var(--accent);
    color: var(--text);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-control::placeholder { color: var(--text-faint); }
.form-control:disabled, .form-control[readonly] { background: var(--surface-2); }
.input-group-text { background: var(--surface-2); border-color: var(--border-strong); color: var(--text-muted); }
.card, .modal-content, .dropdown-menu, .list-group-item, .popover {
    background: var(--surface);
    border-color: var(--border);
    color: var(--text);
}
.dropdown-item { color: var(--text); }
.dropdown-item:hover, .dropdown-item:focus { background: var(--surface-2); color: var(--text); }
.close { color: var(--text); text-shadow: none; }
.text-muted { color: var(--text-muted) !important; }
.bg-light { background-color: var(--surface-2) !important; }
.bg-white { background-color: var(--surface) !important; }
.border, .border-top, .border-bottom { border-color: var(--border) !important; }
.alert { border-radius: var(--radius); }

/* tempusdominus date picker (connections / commands) */
.bootstrap-datetimepicker-widget.dropdown-menu { background: var(--surface); border-color: var(--border); box-shadow: var(--shadow-lg); }
.bootstrap-datetimepicker-widget table td, .bootstrap-datetimepicker-widget table th { color: var(--text); }
.bootstrap-datetimepicker-widget table td.day:hover,
.bootstrap-datetimepicker-widget table td.hour:hover,
.bootstrap-datetimepicker-widget table td.minute:hover,
.bootstrap-datetimepicker-widget table td span:hover { background: var(--surface-3); }
.bootstrap-datetimepicker-widget table td.old,
.bootstrap-datetimepicker-widget table td.new { color: var(--text-faint); }
.bootstrap-datetimepicker-widget table td.active,
.bootstrap-datetimepicker-widget table td span.active { background: var(--accent); color: var(--accent-contrast); }

/* ------------------------------------------------------------ app nav */
.app-nav {
    position: sticky;
    top: 0;
    z-index: 1030;
    height: var(--nav-h);
    background: var(--nav-bg);
    border-bottom: 1px solid var(--nav-border);
}
.app-nav-inner {
    height: 100%;
    max-width: 1440px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    gap: 16px;
}
.app-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--nav-text-active);
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 17px;
    letter-spacing: 0.01em;
    text-decoration: none;
    white-space: nowrap;
}
.app-brand:hover { color: var(--nav-text-active); text-decoration: none; }
/* full TARS logo (light recolor: the bar is abyss navy in both themes) */
.app-brand-logo { display: block; height: 36px; width: auto; flex: none; }
.app-brand-sep { width: 1px; height: 24px; background: var(--nav-border); flex: none; }
.app-brand-name { color: var(--nav-text); font-family: var(--font); font-weight: 600; font-size: 14px; letter-spacing: 0.02em; }
.app-brand:hover .app-brand-name { color: var(--nav-text-active); }
.app-links { display: flex; align-items: center; gap: 2px; margin-left: 12px; }
.app-links a {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 34px;
    padding: 0 12px;
    border-radius: 8px;
    color: var(--nav-text);
    font-weight: 500;
    font-size: 15px;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}
.app-links a:hover { background: var(--nav-hover); color: var(--nav-text-active); }
.app-links a.active { background: var(--nav-active); color: var(--nav-text-active); }
.app-links svg { width: 16px; height: 16px; opacity: 0.85; }
.app-nav-right { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.app-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: transparent;
    color: var(--nav-text);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.app-icon-btn:hover { background: var(--nav-hover); color: var(--nav-text-active); }
.app-icon-btn svg { width: 18px; height: 18px; }
.app-user {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--nav-text);
    font-size: 13px;
    padding: 0 6px 0 10px;
    border-left: 1px solid var(--nav-border);
    margin-left: 4px;
    white-space: nowrap;
}
.app-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(96, 165, 250, 0.22);
    color: #dbeafe;
    font-weight: 700;
    font-size: 12px;
    text-transform: uppercase;
}
.app-menu-btn { display: none; }

/* theme toggle shows the icon of the theme you would switch to */
.theme-icon-sun { display: none; }
:root[data-theme-resolved="dark"] .theme-icon-sun { display: block; }
:root[data-theme-resolved="dark"] .theme-icon-moon { display: none; }

@media (max-width: 860px) {
    .app-menu-btn { display: inline-flex; }
    .app-links {
        display: none;
        position: absolute;
        top: var(--nav-h);
        left: 0;
        right: 0;
        margin: 0;
        padding: 8px 12px 14px;
        flex-direction: column;
        align-items: stretch;
        background: var(--nav-bg);
        border-bottom: 1px solid var(--nav-border);
        box-shadow: var(--shadow-lg);
    }
    .app-nav.open .app-links { display: flex; }
    .app-links a { height: 42px; font-size: 15px; }
    .app-user-name { display: none; }
}
@media (max-width: 480px) {
    .app-nav-inner { padding: 0 10px; gap: 8px; }
    .app-brand { gap: 8px; }
    .app-brand-logo { height: 28px; }
    .app-brand-sep, .app-brand-name { display: none; }
    .app-nav-right { gap: 2px; }
    .app-user { border-left: none; padding: 0 4px; margin-left: 0; }
}

/* --------------------------------------------------------- page layout */
.page {
    max-width: 1440px;
    margin: 0 auto;
    padding: 24px 20px 48px;
}
.page-narrow { max-width: 1040px; }
.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px 20px;
    margin-bottom: 20px;
}
.page-title { margin: 0; font-family: var(--font-display); font-size: 27px; font-weight: 700; line-height: 1.15; letter-spacing: 0.005em; }
.page-subtitle { margin: 4px 0 0; color: var(--text-muted); font-size: 15px; max-width: 72ch; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

@media (max-width: 600px) {
    .page { padding: 16px 16px 40px; }
    .page-title { font-size: 23px; }
}

/* ---------------------------------------------------------- components */
.ui-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}
.ui-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}
.ui-card-title { margin: 0; font-family: var(--font-display); font-size: 17px; font-weight: 600; letter-spacing: 0.005em; }
.ui-card-body { padding: 18px; }

.ui-section-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
}

.ui-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 34px;
    padding: 0 14px;
    border-radius: 8px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
}
.ui-btn:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.ui-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.ui-btn-sm { height: 28px; padding: 0 10px; font-size: 13px; border-radius: var(--radius-sm); }
.ui-btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.ui-btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-contrast); }
.ui-btn-danger { background: transparent; border-color: var(--danger-soft); color: var(--danger); }
.ui-btn-danger:hover { background: var(--danger-soft); color: var(--danger); }
.ui-btn-success { background: transparent; border-color: var(--ok-soft); color: var(--ok); }
.ui-btn-success:hover { background: var(--ok-soft); color: var(--ok); }
.ui-btn-ghost { border-color: transparent; background: transparent; }

.ui-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
    background: var(--surface-2);
    color: var(--text-muted);
}
.ui-badge-ok { background: var(--ok-soft); color: var(--ok); }
.ui-badge-warn { background: var(--warn-soft); color: var(--warn); }
.ui-badge-danger { background: var(--danger-soft); color: var(--danger); }
.ui-badge-info { background: var(--info-soft); color: var(--info); }
.ui-badge-accent { background: var(--accent-soft); color: var(--accent); }
.ui-badge-violet { background: var(--violet-soft); color: var(--violet); }
.ui-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

.ui-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.ui-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14.5px; }
.ui-table th {
    position: sticky;
    top: 0;
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    text-align: left;
    white-space: nowrap;
    padding: 9px 14px;
    border-bottom: 1px solid var(--border);
}
.ui-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.ui-table tbody tr:last-child td { border-bottom: none; }
.ui-table tbody tr:hover td { background: var(--surface-2); }
.ui-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.ui-table th.num { text-align: right; }

.ui-input, .ui-select, .ui-textarea {
    width: 100%;
    height: 36px;
    padding: 0 11px;
    border-radius: 8px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14.5px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.ui-textarea { height: auto; padding: 10px 11px; font-family: var(--font-mono); font-size: 12.5px; }
.ui-input::placeholder, .ui-textarea::placeholder { color: var(--text-faint); }
.ui-input:focus, .ui-select:focus, .ui-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}
.ui-label { display: block; margin-bottom: 6px; font-size: 13.5px; font-weight: 600; color: var(--text-muted); }

.ui-alert {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 11px 14px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-size: 13.5px;
}
.ui-alert-info { background: var(--info-soft); color: var(--text); border-color: var(--info-soft); }
.ui-alert-warn { background: var(--warn-soft); color: var(--text); border-color: var(--warn-soft); }
.ui-alert-danger { background: var(--danger-soft); color: var(--text); border-color: var(--danger-soft); }
.ui-alert-ok { background: var(--ok-soft); color: var(--text); border-color: var(--ok-soft); }

/* KPI tile */
.ui-stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}
.ui-stat-label { display: flex; align-items: center; gap: 7px; font-size: 13.5px; font-weight: 600; color: var(--text-muted); }
.ui-stat-value { font-family: var(--font-display); font-size: 32px; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; color: var(--text); }
.ui-stat-foot { font-size: 13px; color: var(--text-faint); }

/* segmented control / filter chips */
.ui-segment {
    display: inline-flex;
    padding: 3px;
    gap: 2px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 9px;
}
.ui-segment a, .ui-segment button {
    display: inline-flex;
    align-items: center;
    height: 28px;
    padding: 0 12px;
    border-radius: 7px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}
.ui-segment a:hover, .ui-segment button:hover { color: var(--text); text-decoration: none; }
.ui-segment .active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }

/* iframe modal (agent policy, connections, commands, incident detail) */
.modal-overlay {
    display: none;
    position: fixed; inset: 0; z-index: 2000;
    background: var(--overlay);
    backdrop-filter: blur(3px);
    padding: 4vh 16px;
    overflow-y: auto;
}
.modal-content-custom {
    max-width: 1100px; margin: 0 auto;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
}
.modal-header-custom {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.modal-header-custom h5 { margin: 0; font-size: 14.5px; }
.modal-close { width: 32px; height: 32px; border-radius: 8px; border: none; background: transparent; color: var(--text-muted); font-size: 22px; line-height: 1; cursor: pointer; }
.modal-close:hover { background: var(--surface-2); color: var(--text); }
#modalIframe { display: block; width: 100%; height: 82vh; border: 0; background: var(--bg); }
@media (max-width: 760px) {
    .modal-overlay { padding: 0; }
    .modal-content-custom { border-radius: 0; min-height: 100%; }
    #modalIframe { height: calc(100vh - 57px); }
}

.ui-empty { padding: 40px 20px; text-align: center; color: var(--text-muted); font-size: 15px; }

.mono { font-family: var(--font-mono); font-size: 0.92em; }
.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.tabular { font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------- finishing touches */
/* Tactical grid: page background only (cards paint their own surface) */
:root { --grid-line: rgba(27, 31, 69, 0.035); --card-glow: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) { --grid-line: rgba(111, 157, 232, 0.05); --card-glow: inset 0 1px 0 rgba(255, 255, 255, 0.05); }
}
:root[data-theme="dark"] { --grid-line: rgba(111, 157, 232, 0.05); --card-glow: inset 0 1px 0 rgba(255, 255, 255, 0.05); }

body {
    background-color: var(--bg);
    background-image:
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: 32px 32px;
    background-position: -1px -1px;
    background-attachment: fixed;
}

/* depth: a faint top highlight on dark surfaces, a soft lift on light ones */
.ui-card, .ui-stat, .stat-card, .radar-card {
    box-shadow: var(--card-glow), var(--shadow);
}
:root:not([data-theme-resolved="dark"]) .ui-card,
:root:not([data-theme-resolved="dark"]) .stat-card,
:root:not([data-theme-resolved="dark"]) .radar-card {
    box-shadow: 0 1px 2px rgba(27, 31, 69, 0.05), 0 6px 18px rgba(27, 31, 69, 0.045);
}
:root[data-theme-resolved="dark"] .ui-card,
:root[data-theme-resolved="dark"] .stat-card,
:root[data-theme-resolved="dark"] .radar-card {
    box-shadow: var(--card-glow), 0 10px 28px rgba(0, 2, 14, 0.35);
}

/* tab switch (index Overview ↔ Manage agents) */
.index-panel.is-entering { animation: panel-in 0.22s ease-out; }
@keyframes panel-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: none; }
}

/* an agent dropping offline / getting disarmed */
tr.row-alert-danger > td { animation: row-alert-danger 2s ease-out; }
tr.row-alert-warn > td { animation: row-alert-warn 2s ease-out; }
@keyframes row-alert-danger { 0%, 30% { background-color: var(--danger-soft); } 100% { background-color: transparent; } }
@keyframes row-alert-warn { 0%, 30% { background-color: var(--warn-soft); } 100% { background-color: transparent; } }

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

/* ------------------------------------------------------ SIEM forwarding */
.siem-dest { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.siem-dest + .siem-dest { margin-top: 10px; }
.siem-dest-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.siem-dest-id { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.siem-dest-name { font-weight: 600; }
.siem-dest-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.siem-dest-actions form { margin: 0; }
.siem-dest-meta { display: flex; flex-wrap: wrap; gap: 4px 18px; color: var(--text-muted); font-size: 13.5px; }
.siem-dest-meta code { word-break: break-all; }
.siem-dest-error { font-size: 13.5px; padding: 8px 10px; word-break: break-word; }
.siem-edit > summary, .siem-add > summary, .siem-tls > summary { cursor: pointer; color: var(--accent); font-weight: 600; font-size: 14px; }
.siem-edit[open] > summary, .siem-add[open] > summary { margin-bottom: 12px; }
.siem-form { display: flex; flex-direction: column; gap: 14px; }
.siem-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.siem-grid .span-2 { grid-column: span 2; }
.siem-types { border: 0; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
.siem-types legend { margin-bottom: 6px; }
.siem-check { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; color: var(--text); cursor: pointer; }
.siem-tls { border: 1px dashed var(--border-strong); border-radius: var(--radius); padding: 10px 12px; }
.siem-tls[open] { display: flex; flex-direction: column; gap: 8px; }
.siem-tls p { margin: 0; font-size: 13.5px; }
.siem-form-foot { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.siem-health { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.siem-empty { padding: 18px; }
.siem-sub { margin: 18px 0 10px; font-size: 15px; font-weight: 600; font-family: var(--font-display); }
.siem-mono { font-family: var(--font-mono); font-size: 13px; background: var(--surface-2); border-radius: var(--radius-sm); padding: 8px 10px; overflow-x: auto; white-space: pre; }
@media (max-width: 900px) { .siem-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 520px) { .siem-grid { grid-template-columns: 1fr; } .siem-grid .span-2 { grid-column: auto; } }

[hidden] { display: none !important; }

/* ── Office (back office for sales) ─────────────────────────────── */
.office-msgs { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.office-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 18px; }
.office-toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; flex-wrap: wrap; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.office-toolbar form { display: flex; gap: 8px; margin: 0; }
.office-toolbar .ui-input { width: 260px; max-width: 100%; }
.office-table td { vertical-align: middle; }
.office-name { font-weight: 600; color: var(--text); text-decoration: none; }
.office-name:hover { text-decoration: underline; }
.office-sub { display: block; color: var(--text-faint); font-size: 13px; }
.office-badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.usage { display: flex; align-items: center; gap: 10px; min-width: 170px; }
.usage-bar { flex: 1; height: 8px; border-radius: 6px; background: var(--surface-2); overflow: hidden; }
.usage-bar span { display: block; height: 100%; border-radius: 6px; background: var(--ok-strong); }
.usage-bar span.warn { background: var(--warn-strong); }
.usage-bar span.full { background: var(--danger-strong); }
.usage-num { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.office-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); gap: 18px; align-items: start; }
.office-col { display: flex; flex-direction: column; gap: 18px; min-width: 0; }
.office-form { display: flex; flex-direction: column; gap: 12px; }
.office-form .field { display: flex; flex-direction: column; }
.office-steps { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; align-items: start; }
.office-step-num { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft, var(--surface-2)); color: var(--accent, var(--text)); font-weight: 700; font-size: 13px; margin-right: 8px; }
.office-hint { margin: 0; color: var(--text-faint); font-size: 13px; }
.lic-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.lic-fields .field { display: flex; flex-direction: column; }
.lic-fields .field[hidden] { display: none; }
.lic-preview { grid-column: 1 / -1; margin: 0; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); color: var(--text-muted); font-size: 13.5px; }
.office-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.office-actions form { margin: 0; }
.cred-grid { display: grid; grid-template-columns: 240px minmax(0, 1fr); gap: 24px; align-items: start; }
.cred-list { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 8px 14px; margin: 0; }
.cred-list dt { color: var(--text-faint); font-size: 13px; padding-top: 6px; }
.cred-list dd { margin: 0; }
.cred-value { font-family: var(--font-mono); font-size: 15px; background: var(--surface-2); border-radius: var(--radius-sm); padding: 6px 10px; display: inline-block; word-break: break-all; }
.qr-box { background: #ffffff; border-radius: var(--radius); padding: 12px; border: 1px solid var(--border); }
.qr-box svg { display: block; width: 100%; height: auto; }
@media (max-width: 1100px) {
    .office-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .office-layout, .office-steps { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
    .office-table thead { display: none; }
    .office-table, .office-table tbody { display: block; }
    .office-table tr { display: grid; gap: 8px; padding: 14px; border-bottom: 1px solid var(--border); }
    .office-table td { display: block; padding: 0; border: none; }
    .office-actions { justify-content: flex-start; }
    .cred-grid, .lic-fields { grid-template-columns: 1fr; }
    .qr-box { max-width: 260px; }
}
@media print {
    .app-nav, .no-print { display: none !important; }
    body { background: #fff; }
}
.access-choice { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.access-choice label { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; color: var(--text); cursor: pointer; }
.access-choice input { margin-top: 3px; }
.access-choice .access-mail { padding-left: 22px; color: var(--text-muted); }
.invite-link { display: flex; gap: 8px; align-items: stretch; }
.invite-link .ui-input { flex: 1; font-family: var(--font-mono); font-size: 13px; }
