/* Reserve space for bottom nav when present (JS toggles .has-bottom-nav on <body>) */
.has-bottom-nav {
    padding-bottom: calc(var(--bottom-nav-height, 72px) + env(safe-area-inset-bottom, 0px));
}
/* =====================================================
   Navigation System - Interior Dev System
   SRS Compliant Navigation with ALLFIX Branding
   ===================================================== */

/* CSS Variables for Consistent Branding */
:root {
    --allfix-primary: #114B5F;
    --allfix-secondary: #64748b;
    --allfix-accent: #10b981;
    --allfix-warning: #f59e0b;
    --allfix-danger: #ef4444;
    --allfix-background: #ffffff;
    --allfix-surface: #f8fafc;
    --allfix-text-primary: #1e293b;
    --allfix-text-secondary: #64748b;
    --allfix-border: #e2e8f0;
    --allfix-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);

    /* UI helpers used by dropdowns/hover states */
    --allfix-hover: rgba(17, 75, 95, 0.08);
}

/* Dark theme overrides (app-wide) */
html[data-theme="dark"] {
    /* Page background (soft black with subtle green undertone) */
    --allfix-background: #0a0e0d;
    /* Cards, panels, dropdowns, modals, form fields, job context bar */
    --allfix-surface: #141918;
    /* Main text, headings */
    --allfix-text-primary: #e8eae9;
    /* Secondary text, placeholders */
    --allfix-text-secondary: #9ca39f;
    /* Borders for cards/inputs/separators */
    --allfix-border: #252b28;

    /* Accents */
    --allfix-primary: #6b8f71;   /* mossy sage green */
    --allfix-secondary: #7a807d; /* neutral warm gray */
    --allfix-accent: #85a888;    /* brighter sage for emphasis */
    --allfix-warning: #d4a574;   /* muted amber */
    --allfix-danger: #c97066;    /* desaturated red-clay */

    /* Hover bg and elevation */
    --allfix-hover: rgba(107, 143, 113, 0.15);
    --allfix-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.7), 0 1px 3px 0 rgba(0, 0, 0, 0.5);
}

/* Dark-mode accessibility: ensure dark text on white form controls */
html[data-theme="dark"] select.bg-white,
html[data-theme="dark"] input.bg-white,
html[data-theme="dark"] textarea.bg-white {
    color: #0f172a; /* slate-900 for contrast on white */
}
html[data-theme="dark"] select.bg-white option {
    color: #0f172a; /* ensure options stay dark on white */
    background: #ffffff;
}

/* Global mobile scroll safety */
html, body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;           /* prevent horizontal dragging */
    overscroll-behavior: contain; /* reduce rubber-banding on mobile */
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;          /* allow vertical scroll, block horizontal gestures */
    /* Ensure page background and text color always follow theme variables */
    background: var(--allfix-background);
    color: var(--allfix-text-primary);
}

/* =====================================================
   TILE SYSTEM (Reusable, site-wide)
   Matches the look & interactions of QR index tiles
   ===================================================== */

/* Grid container for tiles */
.tile-grid,
.nav-grid,
.tiles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px;
}

/* Individual tile card */
.tile-card,
.nav-card,
.tile {
    background: var(--allfix-background);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    border: 2px solid transparent;
    transition: all 0.3s ease;
    text-decoration: none;
    color: inherit;
    display: block;
    position: relative;
    overflow: hidden;
}

.tile-card::before,
.nav-card::before,
.tile::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: var(--allfix-primary);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.tile-card:hover,
.nav-card:hover,
.tile:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border-color: var(--allfix-primary);
}

.tile-card:hover::before,
.nav-card:hover::before,
.tile:hover::before {
    transform: scaleX(1);
}

/* Titles and descriptions within tiles */
.tile-title,
.nav-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--allfix-text-primary);
    margin-bottom: 8px;
}

.tile-description,
.nav-description,
.tile-subtitle {
    color: var(--allfix-text-secondary);
    line-height: 1.5;
    font-size: 0.95rem;
}

/* Compact adjustment for smaller screens */
@media (max-width: 900px) {
    .tile-card,
    .nav-card,
    .tile { padding: 20px; }
    .tile-title,
    .nav-title { font-size: 1.125rem; }
    .app-header .job-context { display: block; width: 100%; }
}

/* =====================================================
   HEADER STYLES
   ===================================================== */

.app-header {
    background: var(--allfix-background);
    border-bottom: 1px solid var(--allfix-border);
    box-shadow: var(--allfix-shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
    padding: 0.75rem 1rem;
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.allfix-logo {
    display: flex;
    align-items: center;
    text-decoration: none;
}

.allfix-logo:hover {
    text-decoration: none;
}

.logo-image {
    height: 40px;
    width: auto;
    max-width: 200px;
    object-fit: contain;
}

.header-center {
    flex: 1;
    text-align: center;
    margin: 0 2rem;
}

.job-context {
    background: var(--allfix-surface);
    border: 1px solid var(--allfix-border);
    border-radius: 0.5rem;
    padding: 0.5rem 0.75rem;
    display: inline-block;
}

.job-context .job-name {
    font-weight: 600;
    color: var(--allfix-text-primary);
    margin: 0;
}

.job-context .job-code {
    font-size: 0.875rem;
    color: var(--allfix-text-secondary);
    margin: 0;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Icon buttons (mobile-first) */
.icon-btn {
    position: relative;
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--allfix-text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 12px;
    cursor: pointer;
}
.icon-btn svg { width: 24px; height: 24px; }
.icon-btn:focus { outline: 2px solid var(--allfix-primary); outline-offset: 2px; }
.icon-btn:hover { background: var(--allfix-surface); }

.badge {
    position: absolute;
    top: 4px;
    right: 6px;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--allfix-danger);
    color: #fff;
    font-size: 11px;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 0 0 2px var(--allfix-background);
}

.avatar-circle {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--allfix-primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    letter-spacing: 0.5px;
}

/* ==============================
   Profile dropdown menu (avatar)
   ============================== */
.af-menu {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 0.5rem;
    background: var(--allfix-surface);
    color: var(--allfix-text-primary);
    border: 1px solid var(--allfix-border);
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,.12);
    padding: 0.25rem;
    min-width: 240px;
    z-index: 1000;
    overflow-x: hidden; /* prevent horizontal scrollbar in menu */
}
.af-menu.af-hidden { display: none !important; }
.af-menu .af-menu-scroller {
    max-height: 70vh;
    overflow-y: auto;      /* vertical scroll only */
    overflow-x: hidden;    /* no horizontal scroll */
    padding: 0.25rem;
    -webkit-overflow-scrolling: touch;
}
.af-menu .af-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 0.75rem;
    border-radius: 0.5rem;
    text-decoration: none;
    color: inherit;
    background: transparent;
    border: 0;
    width: 100%;
    text-align: left;
    font-size: 0.95rem;
    cursor: pointer;
}
.af-menu .af-item:hover { background: var(--allfix-hover); }
.af-menu .af-divider { height: 1px; margin: 0.25rem 0; background: var(--allfix-border); }
.af-menu .af-logout {
    background: #ef4444;
    color: #fff;
    font-weight: 700;
    justify-content: center;
    padding: 0.75rem;
    border-radius: 0.75rem;
    margin: 0.25rem 0.25rem 0;
}
.af-menu .af-logout:hover { background: #dc2626; }

.af-menu-backdrop {
    position: fixed;
    inset: 0;
    background: transparent;
    z-index: 999;
}
.af-menu-backdrop.af-hidden { display: none !important; }

/* Mobile: present as bottom sheet */
@media (max-width: 640px) {
    .af-menu {
        position: fixed;
        left: 0.75rem;
        right: 0.75rem;
        bottom: 0.75rem;
        top: auto;
        margin: 0;
        border-radius: 16px;
    }
}

/* Logout button as icon variant */
.logout-btn.icon {
    width: 44px;
    height: 44px;
    padding: 0;
    background: var(--allfix-background);
    color: var(--allfix-danger);
    border: 1px solid var(--allfix-border);
    border-radius: 12px;
    box-shadow: 0 1px 0 rgba(0,0,0,0.02);
}
.logout-btn.icon svg { width: 24px; height: 24px; }
.logout-btn.icon:hover { background: var(--allfix-surface); }

/* Logo-only header mode for public token pages */
body.header-logo-only .header-content {
    justify-content: center !important;
}
body.header-logo-only .header-center,
body.header-logo-only .header-right {
    display: none !important;
}

/* =====================================================
   Mobile-first header layout (app):
   On small screens, place job info BELOW the top row,
   left-aligned with the logo. Keep logo left and icons right.
   ===================================================== */
@media (max-width: 900px) {
    body:not(.header-logo-only) .app-header:not(.header-login) .header-content {
        display: grid !important;
        grid-template-columns: auto 1fr;
        grid-template-areas:
          "left right"
          "job job";
        align-items: center;
        gap: 0.5rem 1rem;
    }
    body:not(.header-logo-only) .app-header:not(.header-login) .header-left { grid-area: left; }
    body:not(.header-logo-only) .app-header:not(.header-login) .header-right { grid-area: right; justify-self: end; }
    body:not(.header-logo-only) .app-header:not(.header-login) .header-center {
        grid-area: job;
        width: 100%;
        text-align: left;
        margin: 0; /* override desktop center margin */
        margin-top: 0.25rem; /* small spacing under top row */
    }
    body:not(.header-logo-only) .app-header .job-context { display: block; width: 100%; }
}

/* =====================================================
   DYNAMIC HEADER STATE STYLES
   ===================================================== */

/* Login State - Only logo visible */
.header-login .header-right,
.header-login .header-center {
    display: none !important;
}

.header-login .header-left {
    justify-content: center;
    width: 100%;
}

/* Authenticated State - Logo + User info + Logout */
.header-authenticated .header-right {
    display: flex !important;
}

.header-authenticated .header-center {
    display: none !important;
}

/* Job Selected State - Logo + Job context + User info + Logout */
.header-job-selected .header-right {
    display: flex !important;
}

.header-job-selected .header-center {
    display: block !important;
}

/* Loading State - Show loading indicators */
.header-loading .header-right {
    display: flex !important;
}

.header-loading .user-name::before {
    content: "Loading...";
    color: var(--allfix-text-secondary);
    font-style: italic;
}

/* Hide header-right on login page (legacy support) */
.header-right.hidden {
    display: none !important;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--allfix-text-secondary);
    font-size: 0.875rem;
}

/* Keep legacy logout button styles for desktop contexts if needed */
.logout-btn { display: inline-flex; align-items: center; justify-content: center; }

/* =====================================================
   DYNAMIC BOTTOM NAVIGATION STYLES
   State-aware navigation with SVG icons
   ===================================================== */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--allfix-background);
    border-top: 1px solid var(--allfix-border);
    box-shadow: 0 -1px 3px 0 rgba(0, 0, 0, 0.1);
    z-index: 1000;
    padding: 0.5rem 0;
    transition: all 0.3s ease;
}

/* Bottom Navigation State Classes */
.bottom-nav-loading {
    opacity: 0.7;
}

.bottom-nav-visible {
    display: block;
    opacity: 1;
    transform: translateY(0);
}

.bottom-nav-hidden {
    display: none !important;
    opacity: 0;
    transform: translateY(100%);
}

.bottom-nav-content {
    display: flex;
    justify-content: space-around;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* Bottom nav items: light mode keep secondary tone; dark mode elevate to primary */
.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    color: var(--allfix-text-secondary); /* light mode default */
    transition: all 0.2s ease;
    padding: 0.75rem;
    border-radius: 0.5rem;
    min-width: 4rem;
    min-height: 4rem;
}
html[data-theme="dark"] .nav-item {
    color: #EBB595; /* custom dark mode icon/text color */
}

.nav-item:hover {
    color: var(--allfix-primary);
    background: var(--allfix-surface);
}

.nav-item.active {
    color: var(--allfix-primary);
    background: var(--allfix-surface);
    font-weight: 600;
}
html[data-theme="dark"] .nav-item.active {
    color: #EBB595;
}
/* Dark mode heading accent */
html[data-theme="dark"] h1 {
    color: #EBB595;
}
/* External <img> nav icons need filter since they don't inherit currentColor */
html[data-theme="dark"] .nav-item img.nav-icon-svg {
    /* Approximate #EBB595 using filters (bypass needing inline SVG) */
    filter: brightness(0) saturate(100%) invert(84%) sepia(18%) saturate(743%) hue-rotate(332deg) brightness(94%) contrast(92%);
}

/* Hover/active keep same tint */
html[data-theme="dark"] .nav-item:hover img.nav-icon-svg,
html[data-theme="dark"] .nav-item.active img.nav-icon-svg {
    filter: brightness(0) saturate(100%) invert(84%) sepia(18%) saturate(743%) hue-rotate(332deg) brightness(94%) contrast(92%);
}

.nav-icon-svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    transition: all 0.2s ease;
}

/* Legacy support for emoji icons (if any remain) */
.nav-icon {
    font-size: 1.5rem;
    line-height: 1;
}

/* Icon-only design - no labels */
.nav-label {
    display: none;
}

.nav-badge {
    position: absolute;
    top: 0.25rem;
    right: 0.25rem;
    background: var(--allfix-danger);
    color: white;
    border-radius: 50%;
    width: 1.25rem;
    height: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
}

/* =====================================================
   RESPONSIVE DESIGN
   ===================================================== */

/* Mobile First - Bottom navigation always visible */
@media (max-width: 768px) {
    .header-center {
        display: none; /* Hide job context on mobile to save space */
    }
    
    .header-content {
        padding: 0.5rem;
    }
    
    .allfix-logo {
        font-size: 1.25rem;
    }
    
    .logo-image {
        height: 32px;
        max-width: 150px;
    }
    
    .bottom-nav {
        padding: 0.25rem 0;
    }
    
    .nav-item {
        min-width: 3.5rem;
        min-height: 3.5rem;
        padding: 0.5rem;
    }
    
    .nav-icon-svg {
        width: 20px;
        height: 20px;
    }
    
    .nav-icon {
        font-size: 1.25rem;
    }
}

/* Tablet - Show job context, adjust spacing */
@media (min-width: 769px) and (max-width: 1024px) {
    .header-center {
        margin: 0 1rem;
    }
    
    .job-context {
        padding: 0.375rem 0.75rem;
    }
}

/* Desktop - Full header with job context */
@media (min-width: 1025px) {
    .header-content {
        padding: 1rem 2rem;
    }
    
    .allfix-logo {
        font-size: 1.75rem;
    }
    
    .logo-image {
        height: 48px;
        max-width: 250px;
    }
    
    .job-context {
        padding: 0.75rem 1.5rem;
    }
}

/* =====================================================
   UTILITY CLASSES
   ===================================================== */

/* Add bottom padding to main content to account for fixed bottom nav */
.main-content {
    padding-bottom: 5rem; /* Adjust based on bottom nav height */
}

/* Hide bottom navigation on pages where it's not needed */
.no-bottom-nav .main-content {
    padding-bottom: 1rem;
}

/* =====================================================
   ANIMATIONS AND TRANSITIONS
   ===================================================== */

.nav-item {
    transition: all 0.2s ease-in-out;
}

.nav-item:active {
    transform: scale(0.95);
}

.logout-btn {
    transition: all 0.2s ease-in-out;
}

.logout-btn:active {
    transform: scale(0.98);
}

/* =====================================================
   ACCESSIBILITY
   ===================================================== */

/* Focus indicators for keyboard navigation */
.nav-item:focus,
.logout-btn:focus {
    outline: 2px solid var(--allfix-primary);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .nav-item {
        border: 1px solid var(--allfix-text-primary);
    }
    
    .nav-item.active {
        border-color: var(--allfix-primary);
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .nav-item,
    .logout-btn {
        transition: none;
    }
}

/* =====================================================
   GLOBAL BASE (Typography & Resets for non-Tailwind pages)
   ===================================================== */
html, body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", sans-serif;
    color: var(--allfix-text-primary);
    background: var(--allfix-background);
}

/* Back button style: dark by default, light on hover */
.btn-back {
    background: var(--allfix-primary);
    color: #fff;
    border: 2px solid var(--allfix-primary);
    border-radius: 8px;
    padding: 0.5em 1.25em;
    font-weight: 600;
    transition: all 0.2s ease;
    cursor: pointer;
}
.btn-back:hover, .btn-back:focus {
    background: #fff;
    color: var(--allfix-primary);
    border-color: var(--allfix-primary);
}

/* =====================================================
    Section Header (H1 + Back button)
    Reusable across pages under main-content
    ===================================================== */
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.section-header .title { font-size: 1.5rem; line-height: 2rem; font-weight: 700; color: var(--allfix-text-primary); }
.btn-back { background: var(--allfix-primary); color: #ffffff; border: 2px solid var(--allfix-primary); border-radius: 8px; padding: 0.5em 1.25em; font-weight: 600; transition: all 0.2s ease; }
.btn-back:hover, .btn-back:focus { background: var(--allfix-surface); color: var(--allfix-primary); border-color: var(--allfix-primary); }

/* Primary button style (teal) */
.btn-primary {
    background: var(--allfix-primary);
    color: #fff;
    border: 2px solid var(--allfix-primary);
    border-radius: 8px;
    padding: 0.5em 1.25em;
    font-weight: 600;
    transition: all 0.2s ease;
    cursor: pointer;
}
.btn-primary:hover, .btn-primary:focus {
    background: #0d3b4a; /* slightly darker teal */
    border-color: #0d3b4a;
}

/* Header link styling (avoid default purple underline) */
.app-header a {
    color: var(--allfix-text-secondary);
    text-decoration: none;
}
.app-header a:visited { color: var(--allfix-text-secondary); }
.app-header a:hover { color: var(--allfix-primary); text-decoration: underline; }

/* Icon/button resets for Safari/UA defaults */
.icon-btn { -webkit-appearance: none; appearance: none; }
.logout-btn.icon { border: none; -webkit-appearance: none; appearance: none; }
.logout-btn.icon:focus { outline: 2px solid var(--allfix-primary); outline-offset: 2px; }

/* Job context change link subtle style */
.job-context .job-change-link { color: var(--allfix-text-secondary); text-decoration: underline; }
.job-context .job-change-link:hover { color: var(--allfix-primary); }

/* Common page header strip */
.page-header {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 16px;
    border-bottom: 1px solid var(--allfix-border);
    color: var(--allfix-text-secondary);
}
