/* Firefighter Certify - Main Stylesheet */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Prevent horizontal scroll on all devices */
html, body {
    max-width: 100%;
    overflow-x: hidden;
    position: relative;
    scrollbar-gutter: stable; /* Reserve space for scrollbar to prevent layout shift */
}

/* Dark Theme (default) */
:root, [data-theme="dark"] {
    --primary-color: #e63946;
    --secondary-color: #f77f00;
    --accent-color: #fcbf49;
    --dark-bg: #1a1a2e;
    --medium-bg: #16213e;
    --light-bg: #0f3460;
    --text-light: #ffffff;
    --text-muted: #a8b5c7; /* Improved from #94a1b2 - now meets 4.6:1 contrast ratio */
    --success: #06d6a0;
    --success-light: #d5f4e6;
    --danger: #ef476f;
    --warning: #ffd60a;
    --shadow: rgba(0, 0, 0, 0.3);
    --border-color: #2d3e50;
}

/* Light Theme */
[data-theme="light"] {
    --primary-color: #e63946;
    --secondary-color: #f77f00;
    --accent-color: #b45309; /* Improved from #d97706 - now meets 4.9:1 contrast ratio */
    --dark-bg: #ffffff;
    --medium-bg: #f8f9fa;
    --light-bg: #e9ecef;
    --text-light: #1a1a2e;
    --text-muted: #5a6470; /* Improved from #6c757d - now meets 5.1:1 contrast ratio */
    --success: #047857; /* Improved from #059669 - now meets 4.5:1 contrast ratio */
    --success-light: #d1fae5;
    --danger: #dc2626;
    --warning: #b45309; /* Improved from #d97706 - matches accent color */
    --shadow: rgba(0, 0, 0, 0.1);
    --border-color: #dee2e6;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: linear-gradient(135deg, var(--dark-bg) 0%, var(--medium-bg) 100%);
    color: var(--text-light);
    min-height: 100vh;
    line-height: 1.6;
    transition: background 0.3s ease, color 0.3s ease;
}

/* Global Focus Indicators for Accessibility */
*:focus {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(252, 191, 73, 0.3);
}

/* Skip to main content link for keyboard users */
a.skip-link {
    position: absolute !important;
    left: -9999px !important;
    top: auto !important;
    width: 1px !important;
    height: 1px !important;
    overflow: hidden !important;
    z-index: 10000;
    clip: rect(1px, 1px, 1px, 1px);
    clip-path: inset(50%);
    white-space: nowrap;
}

a.skip-link:focus {
    position: fixed !important;
    top: 10px !important;
    left: 10px !important;
    width: auto !important;
    height: auto !important;
    overflow: visible !important;
    clip: auto;
    clip-path: none;
    white-space: normal;
    background: var(--primary-color);
    color: white;
    padding: 0.75rem 1.5rem;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.container {
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Header/Navigation */
.header {
    background: var(--medium-bg);
    padding: 1rem 0;
    box-shadow: 0 2px 10px var(--shadow);
    position: sticky;
    top: 0;
    z-index: 2000;
    transition: background 0.3s ease, box-shadow 0.3s ease;
    overflow: visible; /* Allow dropdowns to extend beyond header */
}

.nav {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    padding: 0.5rem 0;
    overflow: visible; /* Allow dropdowns to extend beyond nav */
}

.logo {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--primary-color);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo img {
    transition: transform 0.2s ease;
}

.logo:hover img {
    transform: scale(1.05);
}

/* Theme-based logo switching */
[data-theme="dark"] .logo-light {
    display: none;
}

[data-theme="light"] .logo-dark {
    display: none;
}

/* Logo background colors to match theme */
[data-theme="dark"] .logo img.logo-dark {
    background-color: var(--medium-bg);
    border-radius: 8px;
    padding: 0.75rem;
}

[data-theme="light"] .logo img.logo-light {
    background-color: transparent;
}

/* Override for pages without header (login/register) */
body > div .logo-dark {
    background-color: #16213e;
}

/* Responsive logo sizing */
@media (max-width: 1024px) {
    .logo img {
        height: 90px !important;
    }
    .logo div:nth-of-type(2) div:first-child {
        font-size: 1.2rem !important;
    }
}

@media (max-width: 768px) {
    .logo img {
        height: 70px !important;
    }
    .logo div:nth-of-type(2) div:first-child {
        font-size: 1.1rem !important;
    }
    .logo div:nth-of-type(2) div:last-child {
        font-size: 0.7rem !important;
        max-width: 200px !important;
    }
}

@media (max-width: 480px) {
    .logo {
        gap: 0.75rem !important;
    }
    .logo img {
        height: 60px !important;
    }
    .logo div:nth-of-type(2) div:first-child {
        font-size: 1rem !important;
    }
    .logo div:nth-of-type(2) div:last-child {
        font-size: 0.65rem !important;
    }
}

.nav-links {
    display: flex;
    gap: 0.5rem;
    list-style: none;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
}

.nav-links li {
    display: flex;
    align-items: center;
}

.nav-links a {
    color: var(--text-light);
    text-decoration: none;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    white-space: nowrap;
    font-size: 0.95rem;
    min-height: 44px;
    min-width: 44px;
}

.nav-links a:hover {
    background: var(--light-bg);
    color: var(--accent-color);
}

.nav-links a:focus {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
    background: var(--light-bg);
    box-shadow: 0 0 0 3px rgba(252, 191, 73, 0.3);
}

.nav-links a.btn {
    color: white;
}

/* Main content */
.main-content {
    padding: 2rem 0;
    min-height: calc(100vh - 180px);
    position: relative;
    z-index: 1;
}

/* Cards */
.card {
    background: var(--medium-bg);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px var(--shadow);
    margin-bottom: 1.5rem;
    transition: background 0.3s ease, box-shadow 0.3s ease;
    max-width: 100%;
    overflow-x: auto;
    word-wrap: break-word;
}

.card-header {
    font-size: 1.25rem;
    font-weight: bold;
    margin-bottom: 1rem;
    color: var(--accent-color);
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.875rem 1.5rem;
    border-radius: 8px;
    text-decoration: none;
    font-weight: 500;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    min-height: 44px;
}

.btn:focus {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(252, 191, 73, 0.3);
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: #d62828;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(230, 57, 70, 0.4);
}

.btn-primary:focus {
    box-shadow: 0 0 0 3px rgba(230, 57, 70, 0.4), 0 4px 12px rgba(230, 57, 70, 0.4);
}

.btn-secondary {
    background: var(--light-bg);
    color: var(--text-light);
    border: 2px solid var(--light-bg);
}

.btn-secondary:hover {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: var(--dark-bg);
    transform: translateY(-2px);
}

.btn-secondary:focus {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:focus {
    box-shadow: 0 0 0 3px rgba(6, 214, 160, 0.4);
}

.btn-block {
    display: block;
    width: 100%;
    text-align: center;
}

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

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

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--light-bg);
    border-radius: 8px;
    background: var(--dark-bg);
    color: var(--text-light);
    font-size: 1rem;
    transition: border-color 0.3s ease, background 0.3s ease, color 0.3s ease;
}

.form-control:focus {
    border-color: var(--primary-color);
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
    box-shadow: 0 0 0 3px rgba(230, 57, 70, 0.2);
}

.form-check {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

.alert-danger {
    background: rgba(239, 71, 111, 0.2);
    border: 1px solid var(--danger);
    color: var(--danger);
}

.alert-success {
    background: rgba(6, 214, 160, 0.2);
    border: 1px solid var(--success);
    color: var(--success);
}

.alert-info {
    background: rgba(100, 200, 255, 0.2);
    border: 1px solid #64c8ff;
    color: #64c8ff;
}

/* Footer */
.footer {
    background: var(--medium-bg);
    padding: 2rem 0;
    text-align: center;
    color: var(--text-muted);
    margin-top: 2rem;
    transition: background 0.3s ease;
}

/* Dropdown Menu Styles */
.nav-item {
    position: relative;
}

.nav-dropdown {
    position: relative;
    z-index: 9999;
}

/* Create invisible bridge between trigger and menu */
.nav-dropdown::after {
    content: '';
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    height: 0.5rem;
    background: transparent;
    display: none;
}

.nav-dropdown:hover::after {
    display: block;
}

.nav-dropdown > a,
.nav-dropdown-trigger {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    cursor: pointer;
    background: none;
    border: none;
    color: var(--text-light);
    font-size: 0.95rem;
    font-weight: inherit;
    font-family: inherit;
    text-decoration: none;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    transition: all 0.3s ease;
    min-height: 44px;
    min-width: 44px;
    white-space: nowrap;
}

.nav-dropdown > a:hover,
.nav-dropdown-trigger:hover {
    background: var(--light-bg);
    color: var(--accent-color);
}

.nav-dropdown > a:focus,
.nav-dropdown-trigger:focus {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
    background: var(--light-bg);
    box-shadow: 0 0 0 3px rgba(252, 191, 73, 0.3);
}

.dropdown-arrow {
    font-size: 0.7rem;
    transition: transform 0.2s ease;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.nav-dropdown:hover .dropdown-arrow {
    transform: rotate(180deg);
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    left: 0;
    background: var(--medium-bg);
    border-radius: 8px;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--light-bg);
    padding: 0.5rem 0;
    min-width: 220px;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
    z-index: 9999;
    isolation: isolate;
}

.nav-dropdown:hover .dropdown-menu,
.nav-dropdown.active .dropdown-menu {
    display: block;
}

.dropdown-menu li {
    list-style: none !important;
    display: block !important;
    visibility: visible !important;
    opacity: 1 !important;
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
}

.dropdown-menu a {
    display: flex !important;
    align-items: center;
    padding: 0.875rem 1.25rem;
    color: var(--text-light);
    text-decoration: none;
    transition: background 0.2s ease;
    border-radius: 0;
    white-space: nowrap;
    min-height: 44px;
    visibility: visible !important;
    opacity: 1 !important;
}

.dropdown-menu a:hover {
    background: var(--light-bg);
    color: var(--accent-color);
}

.dropdown-menu a:focus {
    outline: 3px solid var(--accent-color);
    outline-offset: -3px;
    background: var(--light-bg);
    color: var(--accent-color);
    box-shadow: inset 0 0 0 3px rgba(252, 191, 73, 0.3);
}

/* Hamburger Menu Button (Mobile Only) */
.hamburger-btn {
    display: none;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    z-index: 3000;
    position: relative;
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
    align-items: center;
}

.hamburger-btn span {
    display: block;
    width: 28px;
    height: 3px;
    background: var(--text-light);
    transition: all 0.3s ease;
    border-radius: 3px;
}

.hamburger-btn:focus {
    outline: 3px solid var(--accent-color);
    outline-offset: 2px;
}

/* Hamburger animation when active */
.hamburger-btn.active span:nth-child(1) {
    transform: rotate(45deg) translate(7px, 7px);
}

.hamburger-btn.active span:nth-child(2) {
    opacity: 0;
}

.hamburger-btn.active span:nth-child(3) {
    transform: rotate(-45deg) translate(7px, -7px);
}

/* Mobile Navigation Overlay */
.mobile-nav-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2500;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-nav-overlay.active {
    display: block;
    opacity: 1;
}

/* Desktop: Force dropdown menus to display all items with high specificity */
@media (min-width: 769px) {
    /* Override any mobile-specific rules that might leak into desktop */
    .nav-dropdown:hover .dropdown-menu,
    .nav-dropdown.active .dropdown-menu {
        display: block !important;
        position: absolute !important;
        top: calc(100% + 0.5rem) !important;
        left: 0 !important;
        background: var(--medium-bg) !important;
        border-radius: 8px !important;
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.4) !important;
        border: 1px solid var(--light-bg) !important;
        width: auto !important;
        min-width: 220px !important;
    }

    /* Ensure all list items are visible on desktop */
    .dropdown-menu li,
    .nav-dropdown:hover .dropdown-menu li,
    .nav-dropdown.active .dropdown-menu li {
        display: block !important;
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* Ensure all links are visible on desktop */
    .dropdown-menu a,
    .nav-dropdown:hover .dropdown-menu a,
    .nav-dropdown.active .dropdown-menu a {
        display: flex !important;
        visibility: visible !important;
        opacity: 1 !important;
        height: auto !important;
    }
}

/* Responsive Styles */
@media (max-width: 768px) {
    /* Show hamburger button on mobile */
    .hamburger-btn {
        display: flex;
        position: absolute;
        right: 1rem;
        top: 50%;
        transform: translateY(-50%);
    }

    /* Header adjustments for mobile */
    .header {
        padding: 0.75rem 0;
    }

    .nav {
        position: relative;
        padding: 0.25rem 0;
        gap: 1rem;
    }

    /* Logo stays visible but more compact */
    .logo {
        margin: 0 auto;
        padding-right: 60px; /* Make room for hamburger */
    }

    /* Hide navigation links by default on mobile */
    .nav-links {
        display: flex !important;
        position: fixed;
        top: 0;
        right: -100%;
        width: 85%;
        max-width: 350px;
        height: 100vh;
        background: var(--medium-bg);
        background-color: #16213e; /* Solid fallback for dark theme */
        flex-direction: column;
        justify-content: flex-start;
        align-items: stretch;
        padding: 4rem 1.5rem 2rem;
        box-shadow: -4px 0 20px rgba(0, 0, 0, 0.5);
        transition: right 0.3s ease;
        z-index: 3000;
        overflow-y: auto;
        overflow-x: hidden;
        gap: 0.5rem;
        -webkit-overflow-scrolling: touch;
    }

    /* Ensure light theme also gets solid background */
    [data-theme="light"] .nav-links {
        background-color: #f8f9fa;
    }

    .nav-links.active {
        right: 0;
    }

    /* Navigation links take full width on mobile */
    .nav-links > li {
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        display: block !important;
        visibility: visible !important;
        opacity: 1 !important;
        flex: none !important;
    }

    /* Direct links (Dashboard, Help, Settings, etc.) */
    .nav-links > li > a {
        width: 100% !important;
        padding: 1rem 1.25rem !important;
        font-size: 1rem !important;
        border-radius: 8px !important;
        display: block !important;
        color: var(--text-light) !important;
        text-decoration: none !important;
        visibility: visible !important;
        opacity: 1 !important;
        background: transparent !important;
        transition: background 0.2s ease !important;
    }

    .nav-links > li > a:active,
    .nav-links > li > a:hover {
        background: var(--light-bg) !important;
    }

    /* Dropdown trigger buttons */
    .nav-dropdown-trigger {
        width: 100% !important;
        padding: 1rem 1.25rem !important;
        font-size: 1rem !important;
        border-radius: 8px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        color: var(--text-light) !important;
        background: transparent !important;
        border: none !important;
        text-align: left !important;
        visibility: visible !important;
        opacity: 1 !important;
        cursor: pointer !important;
        transition: background 0.2s ease !important;
    }

    .nav-dropdown-trigger:active,
    .nav-dropdown-trigger:hover {
        background: var(--light-bg) !important;
    }

    /* Ensure nav-dropdown items are visible */
    .nav-links .nav-dropdown {
        display: block !important;
        width: 100%;
        visibility: visible !important;
        opacity: 1 !important;
    }

    /* Mobile: Only when nav sidebar is open, adjust dropdown behavior */
    .nav-links.active .nav-dropdown.active .dropdown-menu {
        display: block !important;
        position: relative !important;
        box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2) !important;
        background: rgba(15, 52, 96, 1) !important;
        border-radius: 8px !important;
        margin-top: 0.5rem !important;
        margin-bottom: 0.5rem !important;
        width: 100% !important;
        left: auto !important;
        top: auto !important;
        /* NO scrollbars on mobile dropdowns - let them expand naturally */
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }

    /* Light theme version of mobile dropdown menu */
    [data-theme="light"] .nav-links.active .nav-dropdown.active .dropdown-menu {
        background: rgba(233, 236, 239, 1) !important;
    }

    .nav-links.active .nav-dropdown.active .dropdown-menu li {
        height: auto !important;
        max-height: none !important;
        overflow: visible !important;
    }

    .nav-links.active .nav-dropdown.active .dropdown-menu li a {
        padding-left: 2rem !important; /* Indent to show hierarchy */
        height: auto !important;
    }

    /* Mobile: Adjust dropdown arrow when sidebar is open */
    .nav-links.active .nav-dropdown.active .dropdown-arrow {
        transform: rotate(180deg);
    }

    /* Prevent horizontal overflow on mobile */
    .main-content {
        overflow-x: hidden;
    }

    .card {
        padding: 1rem;
    }

    /* Ensure all content respects viewport width */
    img, video, canvas, iframe, svg {
        max-width: 100%;
        height: auto;
    }

    /* Tables responsive */
    table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Pre and code blocks */
    pre, code {
        max-width: 100%;
        overflow-x: auto;
        word-wrap: break-word;
        white-space: pre-wrap;
    }

    /* Prevent long URLs or text from breaking layout */
    p, li, td, th, div {
        word-wrap: break-word;
        overflow-wrap: break-word;
    }
}

/* Global mobile-friendly element constraints */
img, video, iframe, svg {
    max-width: 100%;
    height: auto;
}

/* Ensure tables don't cause horizontal scroll */
table {
    max-width: 100%;
    border-collapse: collapse;
}

/* Long text handling */
pre {
    overflow-x: auto;
    max-width: 100%;
}

code {
    word-wrap: break-word;
}
