/**
 * CAD System - Main Stylesheet
 * Modern, clean design inspired by SnailyCAD
 */

/* ========== Custom Font ========== */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

/* ========== CSS Reset & Variables ========== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: inherit;
}

/* Universal font family - ensures ALL elements use this font */
html, body, input, button, select, textarea, option, optgroup {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

:root {
    --color-primary: #3b82f6;
    --color-secondary: #64748b;
    --color-success: #22c55e;
    --color-warning: #f59e0b;
    --color-danger: #ef4444;
    --color-info: #06b6d4;
    --color-background: #0f172a;
    --color-surface: #1e293b;
    --color-border: #334155;
    --color-text: #f1f5f9;
    --color-text-muted: #94a3b8;
    --portal-civilian: #3b82f6;
    --portal-leo: #ef4444;
    --portal-ems: #22c55e;
    --portal-fire: #f59e0b;
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.4);
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: var(--color-background);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    scrollbar-color: var(--color-border) transparent;
    scrollbar-width: thin;
}

/* ========== Scrollbar ========== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #475569;
}

::-webkit-scrollbar-corner {
    background: transparent;
}

a { color: var(--color-primary); text-decoration: none; transition: color 150ms ease; }
a:hover { color: color-mix(in srgb, var(--color-primary) 80%, white); }
a.btn:hover { color: white; } /* Keep button text white on hover */

/* ========== Layout ========== */
.main-content {
    min-height: calc(100vh - 140px);
    padding: 2rem;
    max-width: 1600px;
    margin: 0 auto;
}

/* ========== Header ========== */
.header {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    position: sticky;
    top: 0;
    z-index: 100;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

.header-container {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 2rem;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
}

.header-lead {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    min-width: 0;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
    text-decoration: none;
    color: var(--color-text);
    flex: none;
}

.header-logo { width: 36px; height: 36px; object-fit: contain; }
.header-title { font-size: 1.125rem; font-weight: 700; letter-spacing: -0.01em; }

.header-nav { display: flex; align-items: center; gap: 0.5rem; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-md);
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 150ms ease;
}

.nav-link:hover { background: rgba(255, 255, 255, 0.05); color: var(--color-text); }
/* Current page. The header already tags the active link with .active
   (layout.php) but nothing styled it, so the active page never lit up. */
.nav-link.active { background: rgba(255, 255, 255, 0.09); color: var(--color-text); font-weight: 600; }

.nav-portal-badge {
    background: color-mix(in srgb, var(--portal-color) 15%, transparent);
    color: var(--portal-color);
}

.nav-portal-badge .portal-dot {
    width: 8px; height: 8px; border-radius: 50%; background: var(--portal-color);
}

.nav-portal-badge .portal-nav-logo {
    width: 20px; height: 20px; border-radius: 4px; object-fit: contain;
}

/* ========== Second-tier module nav (two-tier header) ========== */
/* The identity row (brand + portal) sits above; each portal's own pages live
   on this full-width bar so the header scales to any number of module links
   and stays usable on mobile (it scrolls instead of vanishing). */
.header-subnav {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
}

.header-subnav-inner {
    max-width: 1600px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    align-items: stretch;
    gap: 0.25rem;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}
.header-subnav-inner::-webkit-scrollbar { height: 4px; }
.header-subnav-inner::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 4px; }

.subnav-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.8rem 0.9rem;
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color 150ms ease, border-color 150ms ease;
}
.subnav-link i { font-size: 0.9em; }
.subnav-link:hover { color: var(--color-text); }
/* Current page — underlined in the active portal's colour (falls back to the
   platform accent if a department has no colour set). */
.subnav-link.active {
    color: var(--color-text);
    font-weight: 600;
    border-bottom-color: var(--portal-color, var(--color-primary));
}
.subnav-link:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: -2px;
    border-radius: 4px;
}

/* ========== Admin category dropdowns (second-tier bar) ========== */
/* Shared by System Settings and every other admin page (see includes/admin-subnav.php). */
.header-subnav--custom .header-subnav-inner { overflow: visible; gap: 0.1rem; }
.st-cat { position: relative; }
.st-cat-btn {
    display: inline-flex; align-items: center; gap: 0.5rem;
    padding: 0.8rem 0.9rem; background: transparent; border: 0;
    color: var(--color-text-muted); font-size: 0.875rem; font-weight: 500;
    font-family: inherit; cursor: pointer; white-space: nowrap;
    border-bottom: 2px solid transparent;
}
.st-cat-btn:hover { color: var(--color-text); }
.st-cat-btn.current { color: var(--color-text); font-weight: 600; border-bottom-color: var(--color-primary); }
.st-cat-btn > i:first-child { font-size: 0.85em; opacity: 0.85; }
.st-cat-chev { font-size: 0.62em; opacity: 0.7; transition: transform 0.15s; }
.st-cat-btn.open .st-cat-chev { transform: rotate(180deg); }
.st-cat-menu {
    position: absolute; top: calc(100% + 2px); left: 0; min-width: 212px;
    background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 0.6rem; padding: 0.35rem;
    box-shadow: 0 18px 40px -14px rgba(0,0,0,0.55); display: none; z-index: 60;
}
.st-cat-menu.open { display: block; }
.st-jump {
    display: flex; align-items: center; gap: 0.6rem;
    padding: 0.5rem 0.6rem; border-radius: 0.4rem;
    color: var(--color-text-muted); text-decoration: none; font-size: 0.85rem; white-space: nowrap;
}
.st-jump:hover { background: rgba(255,255,255,0.06); color: var(--color-text); }
.st-jump.active { background: var(--color-primary); color: #fff; }
.st-jump i { width: 1.1rem; text-align: center; font-size: 0.85rem; }

/* Several admin pages embed a legacy left sidebar (.settings-nav). The header
   category nav now replaces it everywhere, so hide any embedded copy and let the
   page content span the full width instead of a 2-column grid. */
.settings-nav { display: none !important; }
.settings-container { display: block !important; }

/* ========== User Dropdown ========== */
.header-user { position: relative; }

.user-dropdown-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.25rem 0.5rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    color: var(--color-text);
    cursor: pointer;
    transition: all 150ms ease;
}

.user-dropdown-toggle:hover,
.user-dropdown-toggle.active {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--color-border);
}

.user-avatar { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.user-name { font-size: 0.875rem; font-weight: 500; }

.user-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 240px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: all 200ms ease;
    z-index: 200;
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 0.8125rem;
}

.user-dropdown.active { opacity: 1; visibility: visible; transform: translateY(0); }

.dropdown-header { display: flex; align-items: center; gap: 0.75rem; padding: 1rem; }
.dropdown-avatar { width: 36px; height: 36px; border-radius: 50%; }
.dropdown-user-info { display: flex; flex-direction: column; }
.dropdown-username { font-weight: 600; font-size: 0.8125rem; color: var(--color-text); }
.dropdown-discord { font-size: 0.6875rem; color: var(--color-text-muted); }
.dropdown-divider { height: 1px; background: var(--color-border); }

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 1rem;
    color: var(--color-text-muted);
    text-decoration: none;
    transition: all 150ms ease;
    font-size: 0.8125rem;
}

.dropdown-item:hover { background: rgba(255, 255, 255, 0.05); color: var(--color-text); }
.dropdown-item-danger:hover { background: color-mix(in srgb, var(--color-danger) 10%, transparent); color: var(--color-danger); }

.dropdown-item-toggle { justify-content: flex-start; }
.dropdown-item-toggle .toggle-indicator {
    margin-left: auto;
    font-size: 0.625rem;
    font-weight: 700;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    background: var(--color-border);
    color: var(--color-text-muted);
}
.dropdown-item-toggle.active .toggle-indicator {
    background: var(--color-warning);
    color: #000;
}
.dropdown-item-toggle.active {
    background: rgba(245, 158, 11, 0.1);
    color: var(--color-warning);
}

/* ========== Footer ========== */
.footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: 1.5rem 2rem;
}

.footer-container {
    max-width: 1600px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.footer-text { font-size: 0.875rem; color: var(--color-text-muted); }

.footer-credits {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.8125rem;
    color: var(--color-text-muted);
}

.footer-version {
    padding: 0.25rem 0.625rem;
    background: rgba(255,255,255,0.05);
    border-radius: 999px;
    font-weight: 500;
    font-size: 0.75rem;
}

.footer-separator {
    opacity: 0.3;
}

.footer-made-by {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    color: inherit;
    text-decoration: none;
}

.footer-made-by:hover {
    opacity: 0.8;
}

.lonex-logo {
    height: 30px;
    width: auto;
    vertical-align: middle;
    margin-left: 4px;
}

/* ========== Flash Messages ========== */
.flash-container {
    position: fixed;
    top: 80px;
    right: 20px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.flash-message {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-md);
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s ease;
    max-width: 400px;
}

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

.flash-success { border-color: var(--color-success); }
.flash-success i { color: var(--color-success); }
.flash-danger { border-color: var(--color-danger); }
.flash-danger i { color: var(--color-danger); }
.flash-warning { border-color: var(--color-warning); }
.flash-warning i { color: var(--color-warning); }
.flash-info { border-color: var(--color-info); }
.flash-info i { color: var(--color-info); }

.flash-close {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    padding: 0.25rem;
    margin-left: auto;
}

.flash-close:hover { color: var(--color-text); }

/* ========== Page Header ========== */
.page-header { margin-bottom: 2rem; }

.breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    color: var(--color-text-muted);
    margin-bottom: 0.5rem;
}

.breadcrumb a { color: var(--color-text-muted); }
.breadcrumb a:hover { color: var(--color-primary); }

.page-title {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--color-text);
    margin: 0 0 0.25rem;
}

.page-subtitle { 
    color: var(--color-text-muted); 
    margin: 0;
    font-size: 1rem;
    font-weight: 400;
}

/* ========== Buttons ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
    transition: all 150ms ease;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: white; }
.btn-primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn-secondary { background: var(--color-secondary); color: white; }
.btn-success { background: var(--color-success); color: white; }
.btn-danger { background: var(--color-danger); color: white; }
.btn-warning { background: var(--color-warning); color: white; }
.btn-ghost { background: transparent; color: var(--color-text); border: 1px solid var(--color-border); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.05); }
.btn-sm { padding: 0.5rem 0.75rem; font-size: 0.75rem; }

/* ========== Cards ========== */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--color-border);
}

.card-icon { color: var(--color-primary); }
.card-title { font-size: 1rem; font-weight: 600; color: var(--color-text); margin: 0; }
.card-actions { margin-left: auto; }
.card-body { padding: 1.25rem; }

/* ========== Forms ========== */
.form-group { margin-bottom: 1.25rem; }

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: 0.5rem;
}

.form-control {
    width: 100%;
    padding: 0.75rem 1rem;
    font-size: 0.875rem;
    color: var(--color-text);
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: border-color 150ms ease;
    font-family: inherit;
}

select.form-control {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239ca3af' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    padding-right: 2.5rem;
    cursor: pointer;
}

select.form-control option {
    background: #1a1a2e;
    color: var(--color-text);
}

.form-control:focus { outline: none; border-color: var(--color-primary); }
.form-control::placeholder { color: var(--color-text-muted); }

/* ========== Dropdowns (native <select>) ==========
   Baseline styling for every select app-wide: dark control, custom caret, and
   dark option list. More specific rules (e.g. plugin themes) still override. */
select {
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    padding: 0.55rem 2.25rem 0.55rem 0.85rem;
    background-color: rgba(0, 0, 0, 0.2);
    color: var(--color-text);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 0.875rem;
    line-height: 1.4;
    cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.8rem center;
    transition: border-color 150ms ease;
}
select:hover { border-color: var(--color-text-muted); }
select:focus { outline: none; border-color: var(--color-primary); }
select:disabled { opacity: 0.6; cursor: not-allowed; }
/* The open list — browsers only honour background/color on options, so at
   minimum keep it dark rather than the OS default white. */
select option { background: var(--color-surface); color: var(--color-text); }
select optgroup { background: var(--color-surface); color: var(--color-text-muted); font-style: normal; }

/* ========== Tables ========== */
.table { width: 100%; border-collapse: collapse; }

.table th, .table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.table th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--color-text-muted);
    background: rgba(0, 0, 0, 0.2);
}

.table tr:hover { background: rgba(255, 255, 255, 0.02); }

/* ========== Badges ========== */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-success { background: color-mix(in srgb, var(--color-success) 20%, transparent); color: var(--color-success); }
.badge-danger { background: color-mix(in srgb, var(--color-danger) 20%, transparent); color: var(--color-danger); }
.badge-warning { background: color-mix(in srgb, var(--color-warning) 20%, transparent); color: var(--color-warning); }
.badge-info { background: color-mix(in srgb, var(--color-info) 20%, transparent); color: var(--color-info); }

/* ========== Utilities ========== */
.text-muted { color: var(--color-text-muted); }
.text-primary { color: var(--color-primary); }
.text-success { color: var(--color-success); }
.text-warning { color: var(--color-warning); }
.text-danger { color: var(--color-danger); }
.text-center { text-align: center; }
.hidden { display: none !important; }

/* ========== Animations ========== */
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.spin { animation: spin 1s linear infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
.pulse { animation: pulse 2s ease-in-out infinite; }

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .main-content { padding: 1rem; }
    .header-container { padding: 0 1rem; }
    /* Keep the identity row compact but present — hide only the wordmark and
       the account name. The second-tier module bar stays and scrolls, so the
       navigation no longer disappears on phones. */
    .header-title, .user-name { display: none; }
    .header-lead { gap: 0.6rem; }
    /* Portals link collapses to its icon; the portal badge keeps its label. */
    .header-nav .nav-link:not(.nav-portal-badge) span { display: none; }
    .header-nav .nav-link:not(.nav-portal-badge) { padding: 0.5rem 0.6rem; }
    .header-subnav-inner { padding: 0 1rem; }
}
