@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800;900&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

/* ==========================================================================
   FACTIONOS OPERATIONAL DESIGN SYSTEM (v3.0)
   FactionOS — Tactical Operating System & Torn Utility Platform
   ========================================================================== */

:root {
    /* Base Surface Palette (Layered Obsidian & Slate) */
    --bg-canvas: #07090e;
    --bg-surface: #0c1017;
    --bg-elevated: #121824;
    --bg-overlay: #182030;
    --bg-hover: #1b2436;
    --bg-subtle: rgba(255, 255, 255, 0.03);
    
    /* Legacy aliases */
    --bg: var(--bg-canvas);
    --card: var(--bg-surface);
    --item: var(--bg-elevated);

    /* Hairline Tactical Borders */
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-default: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --border: var(--border-default);

    /* Typography Colors */
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-tertiary: #64748b;
    --text-main: var(--text-primary);
    --text-dim: var(--text-secondary);

    /* Tactical Accent System (Restrained Spider-Verse) */
    --accent-crimson: #e63946;
    --accent-crimson-dim: rgba(230, 57, 70, 0.12);
    --accent-crimson-glow: rgba(230, 57, 70, 0.25);
    --accent-crimson-border: rgba(230, 57, 70, 0.35);

    --accent-cobalt: #3b82f6;
    --accent-cobalt-dim: rgba(59, 130, 246, 0.12);
    --accent-cobalt-glow: rgba(59, 130, 246, 0.25);
    --accent-cobalt-border: rgba(59, 130, 246, 0.35);

    --accent-emerald: #10b981;
    --accent-emerald-dim: rgba(16, 185, 129, 0.12);
    --accent-emerald-glow: rgba(16, 185, 129, 0.25);
    --accent-emerald-border: rgba(16, 185, 129, 0.35);

    --accent-amber: #f59e0b;
    --accent-amber-dim: rgba(245, 158, 11, 0.12);
    --accent-amber-glow: rgba(245, 158, 11, 0.25);
    --accent-amber-border: rgba(245, 158, 11, 0.35);

    --accent-cyan: #06b6d4;
    --accent-cyan-dim: rgba(6, 182, 212, 0.12);
    --accent-cyan-glow: rgba(6, 182, 212, 0.25);
    --accent-cyan-border: rgba(6, 182, 212, 0.35);

    --accent-purple: #8b5cf6;
    --accent-purple-dim: rgba(139, 92, 246, 0.12);

    /* Color Aliases */
    --red: var(--accent-crimson);
    --blue: var(--accent-cobalt);
    --green: var(--accent-emerald);
    --gold: var(--accent-amber);
    --teal: var(--accent-cyan);
    --purple: var(--accent-purple);

    /* Font Families */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', ui-monospace, SFMono-Regular, monospace;

    /* Metrics & Transitions */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --radius-full: 9999px;
    --transition-fast: 0.15s cubic-bezier(0.16, 1, 0.3, 1);
    --transition-normal: 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    --sidebar-width: 250px;
    --sidebar-collapsed-width: 72px;
    --topbar-height: 54px;
}

/* Light Mode Overrides */
body.light-mode {
    --bg-canvas: #f1f5f9;
    --bg-surface: #ffffff;
    --bg-elevated: #f8fafc;
    --bg-overlay: #ffffff;
    --bg-hover: #e2e8f0;
    --bg-subtle: rgba(0, 0, 0, 0.02);
    --border-subtle: rgba(0, 0, 0, 0.06);
    --border-default: rgba(0, 0, 0, 0.12);
    --border-strong: rgba(0, 0, 0, 0.20);
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-tertiary: #94a3b8;
    --text-main: var(--text-primary);
    --text-dim: var(--text-secondary);
}

/* Base Reset & Core Setup */
*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    background-color: var(--bg-canvas);
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
}

body {
    display: flex;
    overflow: hidden;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.12);
    border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.22);
}

/* Tabular Numerics Utility */
.font-mono, .text-mono, [data-mono] {
    font-family: var(--font-mono) !important;
    font-feature-settings: "tnum" 1, "zero" 1;
    font-variant-numeric: tabular-nums;
}

/* ==========================================================================
   SIDEBAR NAVIGATION SYSTEM
   ========================================================================== */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-surface);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    height: 100vh;
    z-index: 100;
    transition: width var(--transition-normal);
    user-select: none;
    box-shadow: 2px 0 12px rgba(0, 0, 0, 0.25);
}

.sidebar.collapsed {
    width: var(--sidebar-collapsed-width);
}

/* Sidebar Header */
.sidebar-header {
    height: var(--topbar-height);
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-surface);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85em;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    flex-shrink: 0;
}

.sidebar-logo .brand-icon {
    font-size: 1.25em;
    color: var(--accent-crimson);
    filter: drop-shadow(0 0 8px var(--accent-crimson-glow));
    transition: transform var(--transition-fast);
    flex-shrink: 0;
}

.sidebar-logo .brand-text {
    background: linear-gradient(135deg, #ffffff 40%, var(--accent-crimson) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-weight: 900;
    white-space: nowrap;
    flex-shrink: 0;
}

.sidebar.collapsed .brand-text {
    display: none;
}

.sidebar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.toggle-btn, .theme-toggle {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1em;
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.toggle-btn:hover, .theme-toggle:hover {
    background: var(--bg-elevated);
    border-color: var(--border-subtle);
    color: var(--text-primary);
}

/* Navigation Items & Groups */
.nav-items {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 10px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-section-title {
    font-size: 0.65em;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-tertiary);
    padding: 14px 10px 6px;
    white-space: nowrap;
}

.sidebar.collapsed .nav-section-title {
    text-align: center;
    padding: 12px 0 4px;
    font-size: 0.55em;
}

.nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.86em;
    font-weight: 600;
    padding: 9px 12px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
    white-space: nowrap;
    position: relative;
    border: 1px solid transparent;
}

.nav-link:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
    border-color: var(--border-subtle);
}

.nav-link.active {
    background: var(--accent-cobalt-dim);
    color: var(--accent-cobalt);
    border-color: var(--accent-cobalt-border);
    font-weight: 700;
}

.nav-link.active::before {
    content: '';
    position: absolute;
    left: 0;
    top: 6px;
    bottom: 6px;
    width: 3px;
    background: var(--accent-cobalt);
    border-radius: 0 4px 4px 0;
    box-shadow: 0 0 10px var(--accent-cobalt);
}

.nav-link .nav-icon {
    font-size: 1.15em;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.nav-text {
    transition: opacity var(--transition-fast);
}

.sidebar.collapsed .nav-text {
    display: none;
}

.nav-badge-dev {
    margin-left: auto;
    font-size: 0.60rem;
    font-weight: 700;
    letter-spacing: 0.4px;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: var(--radius-sm, 4px);
    background: rgba(239, 68, 68, 0.14);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.32);
    line-height: 1.2;
    white-space: nowrap;
    flex-shrink: 0;
}

.sidebar.collapsed .nav-badge-dev {
    display: none;
}

/* Sidebar Footer (User & Settings) */
.sidebar-footer {
    padding: 10px 10px 14px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 6px;
    background: var(--bg-surface);
}

.sidebar-user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-size: 0.8em;
    color: var(--text-primary);
    overflow: hidden;
}

.sidebar-user-avatar {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-full);
    background: var(--accent-cobalt);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.85em;
    color: #fff;
    flex-shrink: 0;
}

.sidebar-user-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.sidebar-user-name {
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-faction {
    font-size: 0.85em;
    color: var(--text-tertiary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar.collapsed .sidebar-user-info {
    display: none;
}

/* Alternate Format B Sidebar Support */
.sidebar-brand {
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-subtle);
    height: var(--topbar-height);
    box-sizing: border-box;
}

.brand-badge {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-avatar {
    font-size: 1.3em;
    filter: drop-shadow(0 0 8px var(--accent-crimson-glow));
}

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

.brand-title {
    font-weight: 900;
    font-size: 0.88em;
    letter-spacing: 1.5px;
    background: linear-gradient(135deg, #ffffff 40%, var(--accent-crimson) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.brand-subtitle {
    font-size: 0.68em;
    color: var(--text-tertiary);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 700;
}

.sidebar.collapsed .brand-info {
    display: none;
}

.sidebar-toggle-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1em;
    padding: 4px 6px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.sidebar-toggle-btn:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.nav-scroller {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 12px 10px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
}

.nav-section-label {
    font-size: 0.65em;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-tertiary);
    padding: 14px 10px 6px;
    white-space: nowrap;
}

.sidebar.collapsed .nav-section-label {
    text-align: center;
    padding: 12px 0 4px;
    font-size: 0.55em;
}

/* ==========================================================================
   APP CONTENT CONTAINER & UNIVERSAL TOPBAR
   ========================================================================== */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    height: 100vh;
    overflow: hidden;
    position: relative;
    width: calc(100vw - var(--sidebar-width));
}

.sidebar.collapsed ~ .main-wrapper {
    width: calc(100vw - var(--sidebar-collapsed-width));
}

.app-topbar {
    height: var(--topbar-height);
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    flex-shrink: 0;
    z-index: 40;
    width: 100%;
    box-sizing: border-box;
    position: relative;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
    min-width: 0;
}

.topbar-crumb {
    font-size: 0.78em;
    color: var(--text-tertiary);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}

.topbar-crumb span {
    color: var(--text-secondary);
}

.page-breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    white-space: nowrap;
}

.breadcrumb-sub {
    color: var(--text-tertiary);
}

.breadcrumb-sep {
    color: var(--border-strong);
}

.breadcrumb-current {
    color: var(--text-primary);
    font-weight: 700;
}

.topbar-title {
    font-size: 1.15em;
    font-weight: 800;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    flex-shrink: 0;
}

/* Secondary Topbar Component Tokens */
.topbar-clock {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.8em;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
}

.topbar-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75em;
    font-weight: 700;
    font-family: var(--font-mono);
    border: 1px solid var(--accent-emerald-border);
    background: var(--accent-emerald-dim);
    color: var(--accent-emerald);
    white-space: nowrap;
}

.pill-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 8px currentColor;
    animation: pulseDot 1.8s infinite;
}

.topbar-user {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-size: 0.8em;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}

.user-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent-emerald);
    box-shadow: 0 0 6px var(--accent-emerald);
}

.user-name-label {
    color: var(--text-primary);
    font-weight: 700;
}

.topbar-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    border-radius: var(--radius-sm);
    padding: 5px 9px;
    cursor: pointer;
    font-size: 0.9em;
    transition: all var(--transition-fast);
    font-family: inherit;
}

.topbar-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-strong);
}

/* Telemetry Badge (Live WS / Polling) */
.telemetry-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75em;
    font-weight: 700;
    font-family: var(--font-mono);
    border: 1px solid var(--border-subtle);
    background: var(--bg-elevated);
    color: var(--text-secondary);
}

.telemetry-chip.live-ws {
    border-color: var(--accent-emerald-border);
    background: var(--accent-emerald-dim);
    color: var(--accent-emerald);
}

.telemetry-chip.polling {
    border-color: var(--accent-cyan-border);
    background: var(--accent-cyan-dim);
    color: var(--accent-cyan);
}

.pulse-indicator {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 8px currentColor;
    animation: pulseDot 1.8s infinite;
}

@keyframes pulseDot {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.5; }
}

/* TCT Clock Pill */
.tct-clock-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.8em;
    font-weight: 700;
    color: var(--text-primary);
}

.tct-clock-chip .tct-label {
    color: var(--text-tertiary);
    font-size: 0.85em;
    text-transform: uppercase;
}

/* Main Content Area */
.main-content {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 24px 28px 48px;
    position: relative;
    box-sizing: border-box;
}

/* ==========================================================================
   STANDARDIZED PAGE HEADERS & METRICS
   ========================================================================== */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 22px;
    gap: 16px;
    flex-wrap: wrap;
}

.page-title {
    font-size: 1.45em;
    font-weight: 900;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 0;
    letter-spacing: -0.3px;
}

.page-title .title-accent {
    color: var(--accent-cobalt);
}

.page-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

/* Refresh Progress Bar */
#refresh-bar-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: transparent;
    z-index: 50;
    pointer-events: none;
}

#refresh-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-crimson), var(--accent-cobalt));
    box-shadow: 0 0 10px var(--accent-crimson);
    transition: width 0.1s linear;
}

/* ==========================================================================
   KPI STRIP & STAT CARDS
   ========================================================================== */
.kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.kpi-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 16px 18px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    transition: transform var(--transition-fast), border-color var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.kpi-card:hover {
    border-color: var(--border-strong);
    transform: translateY(-1px);
    background: var(--bg-elevated);
}

.kpi-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--border-strong);
    transition: background var(--transition-fast);
}

.kpi-card.kpi-crimson::before { background: var(--accent-crimson); }
.kpi-card.kpi-cobalt::before { background: var(--accent-cobalt); }
.kpi-card.kpi-emerald::before { background: var(--accent-emerald); }
.kpi-card.kpi-amber::before { background: var(--accent-amber); }
.kpi-card.kpi-cyan::before { background: var(--accent-cyan); }

.kpi-icon {
    font-size: 1.6em;
    flex-shrink: 0;
    opacity: 0.9;
}

.kpi-content {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}

.kpi-label {
    font-size: 0.72em;
    color: var(--text-tertiary);
    text-transform: uppercase;
    font-weight: 800;
    letter-spacing: 0.8px;
}

.kpi-value {
    font-size: 1.55em;
    font-weight: 900;
    color: var(--text-primary);
    margin-top: 2px;
    line-height: 1.1;
    font-family: var(--font-mono);
    font-feature-settings: "tnum" 1;
}

.kpi-sub {
    font-size: 0.74em;
    color: var(--text-secondary);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ==========================================================================
   CARDS & CONTAINERS
   ========================================================================== */
.card, .dash-card {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 20px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: border-color var(--transition-fast);
}

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

.card-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.01);
}

.card-title {
    font-size: 0.88em;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    color: var(--text-primary);
}

.card-title-icon {
    color: var(--accent-cobalt);
}

.card-body {
    padding: 20px;
}

.card-body.no-pad {
    padding: 0;
}

.card-body.scrollable {
    overflow-y: auto;
    padding: 0;
    max-height: 480px;
}

/* Layout Grids */
.dash-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.dash-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

.dash-grid-wide {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.span-full {
    grid-column: 1 / -1;
}

/* ==========================================================================
   TACTICAL DATA TABLES
   ========================================================================== */
.table-wrap {
    width: 100%;
    overflow-x: auto;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    position: relative;
}

table, .c-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88em;
    text-align: left;
}

thead th {
    background: var(--bg-elevated);
    padding: 12px 18px;
    font-size: 0.72em;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-default);
    position: sticky;
    top: 0;
    z-index: 10;
    white-space: nowrap;
}

tbody td {
    padding: 12px 18px;
    border-bottom: 1px solid var(--border-subtle);
    color: var(--text-primary);
    transition: background var(--transition-fast);
}

tbody tr:hover td {
    background: var(--bg-elevated);
}

tbody tr:last-child td {
    border-bottom: none;
}

.col-right {
    text-align: right;
}

.col-center {
    text-align: center;
}

.col-mono {
    font-family: var(--font-mono);
    font-feature-settings: "tnum" 1;
}

/* ==========================================================================
   STATUS PILLS & TELEMETRY BADGES
   ========================================================================== */
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 0.74em;
    font-weight: 800;
    padding: 3px 9px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border: 1px solid transparent;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
}

.status-pill.online {
    background: var(--accent-emerald-dim);
    color: var(--accent-emerald);
    border-color: var(--accent-emerald-border);
}

.status-pill.idle {
    background: var(--accent-amber-dim);
    color: var(--accent-amber);
    border-color: var(--accent-amber-border);
}

.status-pill.offline {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-tertiary);
    border-color: var(--border-subtle);
}

.status-pill.hospital {
    background: var(--accent-crimson-dim);
    color: var(--accent-crimson);
    border-color: var(--accent-crimson-border);
}

.status-pill.traveling {
    background: var(--accent-cobalt-dim);
    color: var(--accent-cobalt);
    border-color: var(--accent-cobalt-border);
}

/* Badges for Claims, SOS, Intel */
.intel-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--accent-amber-dim);
    color: var(--accent-amber);
    border: 1px solid var(--accent-amber-border);
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    font-size: 0.72em;
    font-weight: 800;
    font-family: var(--font-mono);
}

.active-claim {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--accent-emerald-dim);
    color: var(--accent-emerald);
    border: 1px solid var(--accent-emerald-border);
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    font-size: 0.72em;
    font-weight: 800;
}

.active-sos {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: var(--accent-crimson-dim);
    color: var(--accent-crimson);
    border: 1px solid var(--accent-crimson-border);
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    font-size: 0.72em;
    font-weight: 800;
    animation: pulseDot 1.5s infinite;
}

/* ==========================================================================
   BUTTONS & ACTIONS
   ========================================================================== */
.btn, .c-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.84em;
    font-weight: 700;
    letter-spacing: 0.3px;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-decoration: none;
    font-family: inherit;
    border: 1px solid transparent;
    user-select: none;
}

.btn-primary {
    background: var(--accent-cobalt);
    color: #ffffff;
    box-shadow: 0 2px 10px var(--accent-cobalt-glow);
}
.btn-primary:hover {
    background: #4f94fc;
    box-shadow: 0 4px 16px var(--accent-cobalt-glow);
    transform: translateY(-1px);
}

.btn-secondary {
    background: var(--bg-elevated);
    border-color: var(--border-default);
    color: var(--text-primary);
}
.btn-secondary:hover {
    background: var(--bg-hover);
    border-color: var(--border-strong);
    color: #ffffff;
}

.btn-danger {
    background: var(--accent-crimson);
    color: #ffffff;
    box-shadow: 0 2px 10px var(--accent-crimson-glow);
}
.btn-danger:hover {
    background: #f04856;
    transform: translateY(-1px);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: transparent;
}
.btn-ghost:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.76em;
}

/* Tactical Attack Button */
.btn-attack {
    background: linear-gradient(135deg, #e63946, #d90429);
    color: #ffffff;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.8em;
    font-weight: 800;
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.15);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 2px 12px var(--accent-crimson-glow);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-family: inherit;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.btn-attack:hover {
    background: linear-gradient(135deg, #f04856, #ef233c);
    box-shadow: 0 4px 18px rgba(230, 57, 70, 0.5);
    transform: translateY(-1px) scale(1.02);
}

.btn-action {
    background: var(--bg-elevated);
    color: var(--text-secondary);
    border: 1px solid var(--border-subtle);
    padding: 5px 11px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.76em;
    font-weight: 700;
    transition: all var(--transition-fast);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-family: inherit;
}
.btn-action:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-default);
}
.btn-action.claim {
    background: var(--accent-emerald-dim);
    color: var(--accent-emerald);
    border-color: var(--accent-emerald-border);
}
.btn-action.claim:hover {
    background: var(--accent-emerald);
    color: #000;
}
.btn-action.sos {
    background: var(--accent-crimson-dim);
    color: var(--accent-crimson);
    border-color: var(--accent-crimson-border);
}
.btn-action.sos:hover {
    background: var(--accent-crimson);
    color: #fff;
}
.btn-action.inspect {
    background: var(--accent-cobalt-dim);
    color: var(--accent-cobalt);
    border-color: var(--accent-cobalt-border);
}
.btn-action.inspect:hover {
    background: var(--accent-cobalt);
    color: #fff;
}

/* ==========================================================================
   SEGMENTED CONTROL & FILTER CHIPS
   ========================================================================== */
.segmented-control, .filter-group {
    display: inline-flex;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 3px;
    gap: 4px;
    flex-wrap: wrap;
}

.filter-chip, .btn-filter {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid transparent;
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.78em;
    font-weight: 700;
    letter-spacing: 0.4px;
    transition: all var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: inherit;
}

.filter-chip:hover, .btn-filter:hover {
    background: var(--bg-elevated);
    color: var(--text-primary);
}

.filter-chip.active, .btn-filter.active {
    background: var(--accent-cobalt-dim);
    border-color: var(--accent-cobalt-border);
    color: var(--accent-cobalt);
}

.filter-badge {
    background: rgba(255, 255, 255, 0.08);
    color: currentColor;
    font-size: 0.85em;
    padding: 1px 6px;
    border-radius: var(--radius-full);
    font-family: var(--font-mono);
}

/* ==========================================================================
   FORM CONTROLS & INPUTS
   ========================================================================== */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 16px;
}

.form-group label {
    font-size: 0.74em;
    color: var(--text-tertiary);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.8px;
}

input[type="text"], input[type="password"], input[type="number"], select, textarea {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-default);
    background: var(--bg-elevated);
    color: var(--text-primary);
    font-size: 0.92em;
    width: 100%;
    box-sizing: border-box;
    transition: all var(--transition-fast);
    font-family: inherit;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent-cobalt);
    box-shadow: 0 0 0 3px var(--accent-cobalt-dim);
    background: var(--bg-surface);
}

.btn-save {
    background: var(--accent-cobalt);
    color: #ffffff;
    border: none;
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-weight: 800;
    font-size: 0.92em;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    transition: all var(--transition-fast);
    width: 100%;
    font-family: inherit;
}
.btn-save:hover {
    background: #4f94fc;
    box-shadow: 0 4px 16px var(--accent-cobalt-glow);
}

/* Switch Toggle */
.switch { position: relative; display: inline-block; width: 44px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--bg-elevated); border: 1px solid var(--border-default); transition: .3s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 2px; bottom: 2px; background-color: white; transition: .3s; border-radius: 50%; }
input:checked + .slider { background-color: var(--accent-emerald); border-color: var(--accent-emerald); }
input:checked + .slider:before { transform: translateX(22px); }

/* ==========================================================================
   SKELETON LOADERS & EMPTY STATES
   ========================================================================== */
.empty-state {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-tertiary);
    font-size: 0.9em;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.empty-state-icon {
    font-size: 2.4em;
    opacity: 0.5;
}

.loading-shimmer, .c-skeleton {
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.03) 25%, rgba(255, 255, 255, 0.08) 50%, rgba(255, 255, 255, 0.03) 75%);
    background-size: 200% 100%;
    animation: shimmerAnim 1.6s infinite ease-in-out;
    border-radius: var(--radius-sm);
    height: 18px;
}

@keyframes shimmerAnim {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ==========================================================================
   MODALS & DIALOGS
   ========================================================================== */
.modal-overlay {
    display: none !important;
    position: fixed !important;
    inset: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: rgba(7, 9, 14, 0.88) !important;
    backdrop-filter: blur(8px) !important;
    -webkit-backdrop-filter: blur(8px) !important;
    z-index: 99999 !important;
    justify-content: center !important;
    align-items: center !important;
    padding: 20px !important;
    box-sizing: border-box !important;
}

.modal-overlay.active,
.modal-overlay.open,
.modal-overlay[style*="display: flex"],
.modal-overlay[style*="display: flex;"],
.modal-overlay[style*="display: block"],
.modal-overlay[style*="display: block;"],
.modal-overlay[style*="display:flex"],
.modal-overlay[style*="display:block"] {
    display: flex !important;
}

.modal-content {
    background: var(--bg-surface);
    border: 1px solid var(--border-default);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 480px;
    max-width: 95vw;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 40px rgba(0, 0, 0, 0.5);
    animation: modalScaleIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-content.wide {
    width: 780px;
    max-width: 96vw;
}

@keyframes modalScaleIn {
    from { opacity: 0; transform: scale(0.96) translateY(-8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-title {
    margin: 0 0 16px;
    font-size: 1.15em;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    border-bottom: 1px solid var(--border-subtle);
    padding-bottom: 14px;
    color: var(--text-primary);
}

.close-btn {
    position: absolute;
    right: 20px;
    top: 20px;
    color: var(--text-tertiary);
    cursor: pointer;
    font-size: 1.4em;
    line-height: 1;
    background: transparent;
    border: none;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.close-btn:hover {
    color: var(--text-primary);
    background: var(--bg-elevated);
}

/* ==========================================================================
   TOAST NOTIFICATIONS
   ========================================================================== */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    pointer-events: none;
}

.toast {
    background: var(--bg-elevated);
    border: 1px solid var(--border-default);
    border-left: 4px solid var(--accent-crimson);
    color: var(--text-primary);
    padding: 14px 20px;
    border-radius: var(--radius-md);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    font-weight: 700;
    font-size: 0.9em;
    pointer-events: auto;
    animation: toastSlideIn 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.toast.online, .toast.okay {
    border-left-color: var(--accent-emerald);
}

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

@keyframes toastSlideIn {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ==========================================================================
   RESPONSIVE DESIGN (MOBILE & TABLET)
   ========================================================================== */
@media (max-width: 960px) {
    html, body {
        width: 100% !important;
        max-width: 100vw !important;
        overflow-x: hidden !important;
    }

    body {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .sidebar {
        width: 100% !important;
        max-width: 100vw !important;
        height: auto !important;
        position: sticky !important;
        top: 0 !important;
        z-index: 1000 !important;
        border-right: none !important;
        border-bottom: 1px solid var(--border-subtle) !important;
        box-sizing: border-box !important;
    }

    .sidebar-header {
        height: 50px !important;
        padding: 0 12px !important;
        width: 100% !important;
        max-width: 100vw !important;
        box-sizing: border-box !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        gap: 8px !important;
    }

    .sidebar-logo {
        flex-shrink: 0 !important;
        overflow: visible !important;
    }

    .sidebar-logo .brand-text {
        font-size: 0.9em !important;
        overflow: visible !important;
        white-space: nowrap !important;
    }

    .sidebar-actions {
        flex-shrink: 0 !important;
        gap: 6px !important;
    }

    .nav-items {
        display: none !important;
        max-height: 75vh !important;
        padding: 12px 14px 24px !important;
        background: var(--bg-surface) !important;
        border-top: 1px solid var(--border-subtle) !important;
    }

    .nav-items.mobile-open {
        display: flex !important;
        animation: mobileSlide 0.2s ease-out;
    }

    @keyframes mobileSlide {
        from { opacity: 0; transform: translateY(-8px); }
        to { opacity: 1; transform: translateY(0); }
    }

    .sidebar-footer {
        display: none !important;
    }

    .main-wrapper,
    .sidebar.collapsed ~ .main-wrapper {
        width: 100% !important;
        max-width: 100vw !important;
        min-width: 0 !important;
        height: auto !important;
        overflow-x: hidden !important;
        overflow-y: visible !important;
        box-sizing: border-box !important;
    }

    .app-topbar {
        padding: 0 12px !important;
        height: 46px !important;
        width: 100% !important;
        max-width: 100vw !important;
        box-sizing: border-box !important;
    }

    .main-content {
        padding: 14px 12px 60px !important;
        width: 100% !important;
        max-width: 100vw !important;
        box-sizing: border-box !important;
        height: auto !important;
        overflow-x: hidden !important;
        overflow-y: visible !important;
    }

    .dash-grid, .dash-grid-3, .dash-grid-wide {
        grid-template-columns: 1fr !important;
        gap: 14px !important;
    }

    .kpi-row {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 10px !important;
    }

    .page-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 12px !important;
    }

    .page-actions, .filter-strip, .filter-row {
        flex-wrap: wrap !important;
        gap: 6px !important;
    }

    .table-wrap, .table-container, .table-responsive {
        width: 100% !important;
        max-width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
        box-sizing: border-box !important;
    }

    /* Prevent iOS auto-zoom on form inputs */
    input, select, textarea {
        font-size: 16px !important;
    }
}

@media (max-width: 520px) {
    .kpi-row {
        grid-template-columns: 1fr 1fr !important;
        gap: 8px !important;
    }

    .kpi-card {
        padding: 12px 14px !important;
    }

    .kpi-value {
        font-size: 1.25em !important;
    }

    .topbar-crumb {
        display: none !important;
    }

    .page-title {
        font-size: 1.2em !important;
    }

    .page-actions {
        width: 100% !important;
        justify-content: flex-start !important;
    }
}

/* Live Indicator & Utility Elements */
.live-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent-emerald);
    box-shadow: 0 0 10px var(--accent-emerald);
    animation: pulseDot 1.6s infinite;
    display: inline-block;
    flex-shrink: 0;
}

.chart-wrap {
    position: relative;
    width: 100%;
}

.credits-bar {
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 12px 18px;
    margin-top: 20px;
    font-size: 0.85em;
    color: var(--text-secondary);
}

.credits-bar summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--text-secondary);
}

.credits-bar-body {
    padding-top: 10px;
    border-top: 1px solid var(--border-subtle);
    margin-top: 10px;
}
