:root {
    /* Brand Colors */
    --primary-color: #e53e3e;
    /* Fire engine red */
    --primary-hover: #c53030;
    --secondary-color: #2b6cb0;

    /* Status Colors */
    --success-color: #38a169;
    --success-bg: #c6f6d5;
    --danger-color: #e53e3e;
    --danger-bg: #fed7d7;
    --warning-color: #dd6b20;

    /* Neutrals */
    --text-main: #2d3748;
    --text-muted: #718096;
    --bg-page: #f7fafc;
    --bg-card: #ffffff;
    --border-color: #e2e8f0;

    /* Spacing & Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --border-radius: 8px;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-page);
    color: var(--text-main);
    line-height: 1.5;
}

a {
    color: var(--secondary-color);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Typography */
h1,
h2,
h3,
h4 {
    color: var(--text-main);
    font-weight: 600;
    margin-bottom: 1rem;
}

/* Layout Core */
.app-container {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    flex: 0 0 250px;
    width: 250px;
    background-color: white;
    border-right: 1px solid var(--border-color);
    padding: 1.5rem 0;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 0 1.5rem 1.5rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    text-transform: uppercase;
    font-weight: 700;
    letter-spacing: 0.05em;
    color: var(--text-muted);
}

.sidebar-nav {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    padding: 1rem 0;
}

.nav-item {
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-main);
    font-weight: 500;
}

.nav-item:hover,
.nav-item.active {
    background-color: #edf2f7;
    color: var(--primary-color);
    text-decoration: none;
}

.main-content {
    flex: 1 1 auto;
    padding: 2rem;
    overflow-y: auto;
    min-width: 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all 0.2s;
    font-size: 0.875rem;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--primary-hover);
    color: white;
    text-decoration: none;
}

.btn-outline {
    background-color: transparent;
    border-color: var(--border-color);
    color: var(--text-main);
}

.btn-outline:hover {
    background-color: #f7fafc;
    text-decoration: none;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}

.btn-danger-outline {
    color: var(--danger-color);
    border-color: var(--danger-color);
    background-color: white;
}

.btn-danger-outline:hover {
    background-color: var(--danger-bg);
}


/* Cards */
.card {
    background-color: var(--bg-card);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

th {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.05em;
    background-color: #f7fafc;
}

tr:hover {
    background-color: #fcfcfc;
}

/* Badges */
.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-valid {
    background-color: var(--success-bg);
    color: var(--success-color);
}

.badge-overdue {
    background-color: var(--danger-bg);
    color: var(--danger-color);
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 0.6rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-family: inherit;
    font-size: 1rem;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.1);
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
}

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background-color: var(--bg-page);
}

.login-card {
    width: 100%;
    max-width: 400px;
}

.login-header {
    text-align: center;
    margin-bottom: 2rem;
}

.login-header svg {
    color: var(--primary-color);
    margin-bottom: 1rem;
}

/* Utilities */
.text-center {
    text-align: center;
}

.mt-4 {
    margin-top: 1rem;
}

.mb-4 {
    margin-bottom: 1rem;
}

.flex-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Mobile Passport View */
.mobile-view {
    max-width: 480px;
    margin: 0 auto;
    background-color: white;
    min-height: 100vh;
    box-shadow: var(--shadow-md);
}

.passport-header {
    background-color: var(--primary-color);
    color: white;
    padding: 1.5rem;
    text-align: center;
}

.passport-content {
    padding: 1.5rem;
}

.data-row {
    display: flex;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

.data-label {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.data-value {
    font-weight: 500;
    text-align: right;
}

.system-verified {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--success-color);
    background-color: var(--success-bg);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    margin-bottom: 1.5rem;
    font-weight: 600;
}

/* ============================================================ */
/* MOBILE SIDEBAR TOGGLE BUTTON                                  */
/* Hidden on desktop, shown only when viewport <= 768px          */
/* ============================================================ */
.sidebar-toggle {
    display: none;              /* Hidden by default on desktop screens */
    background: var(--bg-card); /* White background to match admin theme */
    border: 1px solid var(--border-color); /* Subtle border for visibility */
    border-radius: var(--border-radius);   /* Rounded corners matching system design */
    padding: 0.5rem 0.75rem;   /* Comfortable tap target size */
    cursor: pointer;            /* Pointer cursor to indicate clickability */
    margin-bottom: 1rem;       /* Space between toggle and page content below */
    color: var(--text-main);   /* Dark text color for the icon */
    box-shadow: var(--shadow-sm); /* Subtle shadow for depth perception */
    transition: background-color 0.2s; /* Smooth hover feedback */
}

/* Darken background on hover to give tactile feedback */
.sidebar-toggle:hover {
    background-color: #edf2f7; /* Light grey hover state matches nav-item hover */
}

/* ============================================================ */
/* SIDEBAR OVERLAY BACKDROP                                      */
/* Translucent dark layer behind the sidebar on mobile           */
/* ============================================================ */
.sidebar-overlay {
    display: none;              /* Hidden by default, shown only when sidebar is open */
    position: fixed;            /* Covers the entire viewport regardless of scroll */
    top: 0;                     /* Anchored to top-left corner of the screen */
    left: 0;
    width: 100%;                /* Full viewport width */
    height: 100%;               /* Full viewport height */
    background: rgba(0, 0, 0, 0.5); /* Semi-transparent black for dimming effect */
    z-index: 999;               /* Just below the sidebar (z-index 1000) but above content */
    transition: opacity 0.3s ease; /* Smooth fade in/out animation */
}

/* When the overlay has the 'open' class, make it visible */
.sidebar-overlay.open {
    display: block;             /* Show the overlay backdrop */
}

/* ============================================================ */
/* RESPONSIVE BREAKPOINT: TABLET & PHONE (max-width: 768px)     */
/* Core layout changes: collapsible sidebar, single-column grids */
/* ============================================================ */
@media (max-width: 768px) {

    /* --- Sidebar: Off-canvas slide-in panel --- */
    .sidebar {
        position: fixed;            /* Remove from document flow, overlay on top of content */
        top: 0;                     /* Anchored to top-left of screen */
        left: -280px;               /* Hidden off-screen to the left by default */
        width: 280px;               /* Slightly wider than desktop for better touch targets */
        height: 100vh;              /* Full viewport height */
        z-index: 1000;              /* Highest z-index to appear above all content */
        transition: left 0.3s ease; /* Smooth slide-in animation */
        box-shadow: var(--shadow-md); /* Drop shadow for floating panel effect */
        background-color: white;    /* Solid white background */
    }

    /* When sidebar has the 'open' class, slide it into view */
    .sidebar.open {
        left: 0;                    /* Move sidebar to its visible position */
    }

    /* --- Show the hamburger menu button on mobile --- */
    .sidebar-toggle {
        display: inline-flex;       /* Make the toggle button visible */
        align-items: center;        /* Center the icon vertically */
        gap: 0.5rem;                /* Space between icon and any text */
    }

    /* --- Main content: full width without sidebar space --- */
    .main-content {
        padding: 1rem;              /* Reduced padding for smaller screens */
        width: 100%;                /* Use full viewport width */
    }

    /* --- App container: stack vertically instead of side-by-side --- */
    .app-container {
        flex-direction: column;     /* Stack sidebar and content vertically */
    }

    /* --- Grid layouts: single column on mobile --- */
    .grid-2 {
        grid-template-columns: 1fr; /* One column instead of two on small screens */
        gap: 1rem;                   /* Slightly less gap than desktop */
    }

    /* --- Flex-between headers: stack vertically --- */
    .flex-between {
        flex-direction: column;      /* Stack title and buttons vertically */
        align-items: flex-start;     /* Left-align all stacked items */
        gap: 0.75rem;                /* Vertical spacing between stacked items */
    }

    /* --- KPI cards grid: single column on mobile --- */
    .kpi-grid {
        grid-template-columns: 1fr; /* One KPI card per row for readability */
    }

    /* --- Tables: reduce cell padding to fit more data --- */
    th, td {
        padding: 0.6rem 0.5rem;     /* Compact padding for narrow viewports */
        font-size: 0.85rem;         /* Slightly smaller text for table cells */
    }

    /* --- Buttons: full width for better mobile tap targets --- */
    .btn {
        width: 100%;                /* Stretch buttons to full container width */
        justify-content: center;    /* Center button text and icon */
    }

    /* --- Action buttons in tables: stay compact, don't stretch --- */
    td .btn {
        width: auto;                /* Override full-width for inline table action buttons */
    }

    /* --- Print Labels page: stack preview panes vertically --- */
    .preview-split {
        flex-direction: column;     /* Stack extinguisher and unit previews */
    }

    /* --- Preview panes: remove min-width constraint for mobile --- */
    .preview-pane {
        min-width: 0 !important;    /* Allow panes to shrink below 400px on mobile */
        width: 100%;                /* Use full available width */
    }

    /* --- Login card: use more screen width on mobile --- */
    .login-card {
        max-width: 90%;             /* Use 90% of screen instead of fixed 400px */
        margin: 0 auto;             /* Center the card horizontally */
    }
}

/* ============================================================ */
/* RESPONSIVE BREAKPOINT: SMALL PHONE (max-width: 480px)        */
/* Further refinements for narrow screens like iPhone SE         */
/* ============================================================ */
@media (max-width: 480px) {

    /* --- Even more compact main content padding --- */
    .main-content {
        padding: 0.75rem;           /* Minimum padding for very small screens */
    }

    /* --- KPI values: smaller font to avoid overflow --- */
    .kpi-value {
        font-size: 1.8rem;          /* Reduce from 2.5rem to prevent line wrapping */
    }

    /* --- Tables: further reduce padding on tiny screens --- */
    th, td {
        padding: 0.4rem 0.35rem;    /* Minimal padding for very narrow viewports */
        font-size: 0.8rem;          /* Smaller text to fit more columns */
    }

    /* --- Cards: reduce internal padding --- */
    .card {
        padding: 1rem;              /* Less padding than desktop 1.5rem */
    }

    /* --- Page headings: slightly smaller for mobile --- */
    h2 {
        font-size: 1.25rem;         /* Smaller heading to save vertical space */
    }

    /* --- Login card: nearly full width on small phones --- */
    .login-card {
        max-width: 95%;             /* Almost full width on very small screens */
    }
}