/* ============================================================
   Tactical Command — Base Design System
   Dark Room Analytics aesthetic for cybersecurity professionals
   ============================================================ */

/* Google Fonts are loaded via base.html <link> tag */

/* ── CSS Variables ────────────────────────────────────────── */
:root {
    /* Surface layers — no borders, depth through bg shifts */
    --surface-lowest:    #0f0f0f;
    --surface:           #141414;
    --surface-low:       #181818;
    --surface-container: #202020;
    --surface-high:      #282828;
    --surface-highest:   #2e2e2e;
    --surface-bright:    #3a3a3a;

    /* Primary — Bootstrap Blue */
    --accent:          #0d6efd;
    --accent-container:#0b5ed7;
    --on-accent:       #ffffff;

    /* Text scale */
    --text-primary:    #f8fafc;
    --text-secondary:  #94a3b8;
    --text-muted:      #64748b;
    --text-subtle:     rgba(148,163,184,0.4);

    /* Compatibility aliases (used by page-specific CSS) */
    --bg-primary:           var(--surface-lowest);
    --bg-secondary:         var(--surface-low);
    --bg-tertiary:          var(--surface-container);
    --bg-card:              var(--surface-high);
    --border-color:         rgba(255,255,255,0.1);
    --border-color-light:   rgba(255,255,255,0.06);

    /* Buttons */
    --btn-primary-bg:            var(--accent);
    --btn-primary-hover:         #3d8bfd;
    --btn-secondary-bg:          transparent;
    --btn-secondary-text:        var(--text-secondary);
    --btn-secondary-border:      rgba(255,255,255,0.1);
    --btn-secondary-hover-bg:    var(--surface-high);
    --btn-secondary-active-bg:   var(--accent);
    --btn-secondary-active-text: var(--on-accent);

    /* Semantic flash colours */
    --success-bg:     rgba(27,67,50,0.85);
    --success-text:   #95d5b2;
    --success-border: rgba(45,106,79,0.4);
    --error-bg:       rgba(147,0,10,0.2);
    --error-text:     #ffdad6;
    --error-border:   rgba(147,0,10,0.35);
    --info-bg:        rgba(26,47,74,0.8);
    --info-text:      #90b8f8;
    --info-border:    rgba(45,74,112,0.4);
    --warning-bg:     rgba(74,63,26,0.8);
    --warning-text:   #ffd966;
    --warning-border: rgba(102,82,0,0.4);

    /* Fonts */
    --font-display: 'Space Grotesk', system-ui, sans-serif;
    --font-body:    'Inter', system-ui, sans-serif;

    /* Sidebar */
    --sidebar-width: 260px;
    --topbar-height: 64px;
}

/* Dark theme — identical to :root (always dark) */
[data-theme="dark"] {
    --bg-primary:         var(--surface-lowest);
    --bg-secondary:       var(--surface-low);
    --bg-tertiary:        var(--surface-container);
    --text-primary:       #f8fafc;
    --text-secondary:     #94a3b8;
    --text-muted:         #64748b;
    --border-color:       rgba(255,255,255,0.1);
    --border-color-light: rgba(255,255,255,0.06);
    --btn-primary-bg:     var(--accent);
    --btn-primary-hover:  #3d8bfd;
    --btn-secondary-bg:   transparent;
    --btn-secondary-text: #94a3b8;
    --btn-secondary-border: rgba(255,255,255,0.1);
    --btn-secondary-hover-bg: var(--surface-high);
    --btn-secondary-active-bg:   var(--accent);
    --btn-secondary-active-text: var(--on-accent);
    --success-bg:     rgba(27,67,50,0.85);
    --success-text:   #95d5b2;
    --success-border: rgba(45,106,79,0.4);
    --error-bg:       rgba(147,0,10,0.2);
    --error-text:     #ffdad6;
    --error-border:   rgba(147,0,10,0.35);
    --info-bg:        rgba(26,47,74,0.8);
    --info-text:      #90b8f8;
    --info-border:    rgba(45,74,112,0.4);
    --warning-bg:     rgba(74,63,26,0.8);
    --warning-text:   #ffd966;
    --warning-border: rgba(102,82,0,0.4);
}

/* Light theme */
[data-theme="light"] {
    /* Surface layers */
    --surface-lowest:    #f0f2f5;
    --surface:           #f5f6f8;
    --surface-low:       #ffffff;
    --surface-container: #f0f2f5;
    --surface-high:      #e8eaed;
    --surface-highest:   #dde0e4;
    --surface-bright:    #d0d4d9;

    /* Accent stays the same */
    --accent:          #0d6efd;
    --accent-container:#0b5ed7;
    --on-accent:       #ffffff;

    /* Text */
    --text-primary:    #0f1117;
    --text-secondary:  #4b5563;
    --text-muted:      #9ca3af;
    --text-subtle:     rgba(75,85,99,0.4);

    /* Compatibility aliases */
    --bg-primary:           var(--surface-lowest);
    --bg-secondary:         var(--surface-low);
    --bg-tertiary:          var(--surface-container);
    --bg-card:              var(--surface-high);
    --border-color:         rgba(0,0,0,0.1);
    --border-color-light:   rgba(0,0,0,0.06);

    /* Buttons */
    --btn-primary-bg:            var(--accent);
    --btn-primary-hover:         #0b5ed7;
    --btn-secondary-bg:          transparent;
    --btn-secondary-text:        #4b5563;
    --btn-secondary-border:      rgba(0,0,0,0.12);
    --btn-secondary-hover-bg:    var(--surface-high);
    --btn-secondary-active-bg:   var(--accent);
    --btn-secondary-active-text: var(--on-accent);

    /* Semantic flash colours */
    --success-bg:     rgba(220,252,231,0.9);
    --success-text:   #166534;
    --success-border: rgba(22,101,52,0.25);
    --error-bg:       rgba(254,226,226,0.9);
    --error-text:     #991b1b;
    --error-border:   rgba(153,27,27,0.25);
    --info-bg:        rgba(219,234,254,0.9);
    --info-text:      #1e40af;
    --info-border:    rgba(30,64,175,0.25);
    --warning-bg:     rgba(254,243,199,0.9);
    --warning-text:   #92400e;
    --warning-border: rgba(146,64,14,0.25);
}

/* ── Material Symbols ─────────────────────────────────────── */
.material-symbols-outlined {
    font-family: 'Material Symbols Outlined', sans-serif;
    font-weight: normal;
    font-style: normal;
    font-size: 20px;
    line-height: 1;
    letter-spacing: normal;
    text-transform: none;
    display: inline-block;
    white-space: nowrap;
    word-wrap: normal;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
    font-feature-settings: 'liga';
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    user-select: none;
    vertical-align: middle;
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    color-scheme: dark;
}

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

body {
    font-family: var(--font-body);
    background: var(--surface-lowest);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* ── App Layout ───────────────────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-width);
    background: var(--surface-lowest);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 1000;
    transition: transform 0.3s ease;
    /* subtle right-edge depth */
    box-shadow: 1px 0 0 0 rgba(255,255,255,0.06);
}

.sidebar-header {
    height: var(--topbar-height);
    padding: 0 24px;
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-logo {
    width: 28px;
    height: 28px;
    filter: brightness(0) invert(1);
    flex-shrink: 0;
}

.sidebar-title {
    font-family: var(--font-display);
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.03em;
    margin: 0;
    line-height: 1.1;
}

.sidebar-manager-label {
    font-size: 10px;
    color: rgba(229,226,225,0.35);
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    margin-top: 1px;
}

/* ── Sidebar Navigation ───────────────────────────────────── */
.sidebar-nav {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
    scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar {
    display: none;
}

.nav-section {
    margin-bottom: 28px;
}

.nav-section-title {
    display: block;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: rgba(148,163,184,0.4);
    padding: 0 24px;
    margin-bottom: 4px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 11px 24px;
    color: var(--text-secondary);
    text-decoration: none;
    font-family: var(--font-display);
    font-size: 14px;
    font-weight: 600;
    letter-spacing: -0.01em;
    border-left: 3px solid transparent;
    transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
    position: relative;
}

.sidebar-link svg {
    stroke: var(--text-muted);
    width: 19px;
    height: 19px;
    flex-shrink: 0;
    transition: stroke 0.15s ease;
}

.sidebar-link:hover {
    background: var(--surface-low);
    color: var(--text-primary);
    border-left-color: rgba(13,110,253,0.3);
}

.sidebar-link:hover svg {
    stroke: var(--text-secondary);
}

.sidebar-link.active {
    background: var(--surface-high);
    color: #ffffff;
    border-left-color: #0d6efd;
}

.sidebar-link.active svg {
    stroke: #0d6efd;
}

.sidebar-menu-logo {
    width: 19px;
    height: 19px;
    filter: brightness(0) invert(0.6);
    flex-shrink: 0;
    transition: filter 0.15s ease;
}

.sidebar-link:hover .sidebar-menu-logo {
    filter: brightness(0) invert(0.8);
}

.sidebar-link.active .sidebar-menu-logo {
    filter: brightness(0) saturate(100%) invert(40%) sepia(100%) saturate(2000%) hue-rotate(213deg) brightness(110%) contrast(100%);
}

/* ── Main Content ─────────────────────────────────────────── */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: block;
    background: var(--surface-lowest);
}

/* ── Top Bar ──────────────────────────────────────────────── */
.top-bar {
    height: var(--topbar-height);
    background: rgba(15,15,15,0.75);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(255,255,255,0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 4px 24px rgba(13,110,253,0.04);
}

.top-bar-left,
.top-bar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.sidebar-toggle-desktop {
    display: none;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
}

.sidebar-toggle-desktop svg {
    stroke: var(--text-secondary);
}

/* ── Breadcrumbs ──────────────────────────────────────────── */
.breadcrumb-container {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
}

.breadcrumb-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.breadcrumb-separator {
    color: rgba(171,137,135,0.35);
    font-size: 11px;
}

.breadcrumb-link {
    color: var(--text-muted);
    text-decoration: none;
    transition: color 0.15s;
}

.breadcrumb-link:hover {
    color: var(--text-secondary);
}

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

/* ── Top Bar Actions ──────────────────────────────────────── */
.top-bar-action-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.top-bar-action-btn:hover {
    background: var(--surface-high);
    color: var(--accent);
}

.top-bar-action-btn .moon-icon,
.top-bar-action-btn .sun-icon {
    stroke: currentColor;
}

/* ── Top Bar User ─────────────────────────────────────────── */
.user-profile-dropdown {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-left: 16px;
    border-left: 1px solid rgba(255,255,255,0.08);
}

.top-bar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-primary);
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: rgba(13,110,253,0.15);
    border: 1px solid rgba(13,110,253,0.2);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 13px;
    color: var(--accent);
}

.user-info {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.user-role {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

.top-bar-logout {
    color: var(--text-muted);
    transition: color 0.15s;
    display: flex;
    padding: 6px;
    border-radius: 4px;
}

.top-bar-logout:hover {
    color: #ffdad6;
    background: rgba(147,0,10,0.15);
}

.top-bar-logout svg {
    stroke: currentColor;
}

/* ── Flash Messages ───────────────────────────────────────── */
.flash-messages {
    padding: 20px 32px 0;
}

.flash-message {
    padding: 14px 18px;
    border-radius: 4px;
    margin-bottom: 12px;
    font-size: 13px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border: 1px solid;
}

.flash-text { flex: 1; }

.flash-close {
    background: none;
    border: none;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    opacity: 0.5;
    color: inherit;
    transition: opacity 0.15s;
}

.flash-close:hover { opacity: 1; }

.flash-success {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: var(--success-border);
}

.flash-error {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: var(--error-border);
}

.flash-info {
    background: var(--info-bg);
    color: var(--info-text);
    border-color: var(--info-border);
}

.flash-warning {
    background: var(--warning-bg);
    color: var(--warning-text);
    border-color: var(--warning-border);
}

/* ── Buttons (global) ─────────────────────────────────────── */
.btn {
    padding: 9px 18px;
    background: var(--btn-primary-bg);
    color: var(--on-accent);
    text-decoration: none;
    border-radius: 4px;
    font-family: var(--font-display);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: -0.01em;
    transition: filter 0.15s, background 0.15s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: none;
    cursor: pointer;
    white-space: nowrap;
}

.btn:hover {
    filter: brightness(1.08);
    color: var(--on-accent);
}

.btn-secondary {
    background: var(--surface-high);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: var(--surface-highest);
    color: var(--text-primary);
    filter: none;
}

.btn-secondary.active {
    background: var(--accent);
    color: var(--on-accent);
    border-color: var(--accent);
}

/* ── No Sidebar Layout ────────────────────────────────────── */
.no-sidebar-layout {
    width: 100%;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--surface-lowest);
}

/* ── Mobile Sidebar Toggle ────────────────────────────────── */
.sidebar-toggle {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1001;
    width: 40px;
    height: 40px;
    background: var(--surface-low);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

.sidebar-toggle svg {
    stroke: var(--text-secondary);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    z-index: 999;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 1024px) {
    :root { --sidebar-width: 240px; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .sidebar-overlay.open {
        display: block;
    }

    .sidebar-toggle {
        display: flex;
    }

    .main-content {
        margin-left: 0;
        padding-top: 60px;
    }

    .flash-messages {
        padding: 12px 16px 0;
    }

    .top-bar {
        padding: 0 16px;
    }

    .user-info {
        display: none;
    }

    .sidebar-toggle-desktop {
        display: flex;
    }
}

@media (max-width: 480px) {
    .sidebar { width: 100%; }
    .flash-messages { padding: 10px 12px 0; }
}

/* ── Light theme chrome overrides ────────────────────────── */
[data-theme="light"] .sidebar-manager-label {
    color: rgba(75,85,99,0.5);
}

[data-theme="light"] .sidebar {
    background: #ffffff;
    box-shadow: 1px 0 0 0 rgba(0,0,0,0.08), 4px 0 16px rgba(0,0,0,0.04);
}

[data-theme="light"] .sidebar-header {
    border-bottom-color: rgba(0,0,0,0.07);
}

[data-theme="light"] .sidebar-logo {
    filter: none;
}

[data-theme="light"] .nav-section-title {
    color: rgba(75,85,99,0.5);
}

[data-theme="light"] .sidebar-link {
    color: #4b5563;
}

[data-theme="light"] .sidebar-link svg {
    stroke: #9ca3af;
}

[data-theme="light"] .sidebar-link:hover {
    background: #f0f2f5;
    color: #0f1117;
    border-left-color: rgba(13,110,253,0.3);
}

[data-theme="light"] .sidebar-link:hover svg {
    stroke: #4b5563;
}

[data-theme="light"] .sidebar-link.active {
    background: rgba(13,110,253,0.08);
    color: #0d6efd;
    border-left-color: #0d6efd;
}

[data-theme="light"] .sidebar-link.active svg {
    stroke: #0d6efd;
}

[data-theme="light"] .sidebar-link .sidebar-menu-logo {
    filter: brightness(0) invert(0.5);
}

[data-theme="light"] .sidebar-link:hover .sidebar-menu-logo {
    filter: brightness(0) invert(0.3);
}

[data-theme="light"] .top-bar {
    background: rgba(255,255,255,0.85);
    border-bottom-color: rgba(0,0,0,0.07);
    box-shadow: 0 1px 0 rgba(0,0,0,0.06);
}

[data-theme="light"] .top-bar-action-btn:hover {
    background: #e8eaed;
}

[data-theme="light"] .top-bar-user:hover .user-avatar {
    background: rgba(13,110,253,0.15);
}

[data-theme="light"] .top-bar-logout svg {
    stroke: #9ca3af;
}

[data-theme="light"] .top-bar-logout:hover svg {
    stroke: #ef4444;
}

[data-theme="light"] .user-avatar {
    background: rgba(13,110,253,0.1);
}

[data-theme="light"] .user-avatar .user-initial {
    color: #0d6efd;
}

[data-theme="light"] .sidebar-overlay {
    background: rgba(0,0,0,0.3);
}

[data-theme="light"] .flash-message {
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
