:root {
    --primary: #2d6a4f;
    --primary-dark: #1b4332;
    --primary-light: #52b788;
    --danger: #dc3545;
    --warning: #fd7e14;
    --success: #28a745;
    --gray-100: #f8f9fa;
    --gray-200: #e9ecef;
    --gray-300: #dee2e6;
    --gray-500: #adb5bd;
    --gray-700: #495057;
    --gray-900: #212529;
    --sidebar-width: 250px;
    --radius: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--gray-900);
    background: var(--gray-100);
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
hr { border: none; border-top: 1px solid var(--gray-200); margin: 1rem 0; }

/* ============================================
   LAYOUT - Desktop
   ============================================ */
.app-wrapper {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--primary-dark);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: fixed;
    height: 100vh;
    overflow-y: auto;
    z-index: 1000;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-header h2 { font-size: 1.3rem; }
.sidebar-header small { opacity: .7; }

/* Hamburger / close button - hidden on desktop */
.menu-toggle,
.sidebar-close {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    z-index: 1001;
}

.menu-toggle span,
.sidebar-close span {
    font-size: 1.5rem;
}

.nav-menu {
    list-style: none;
    padding: .5rem 0;
    flex: 1;
}

.nav-menu li a {
    display: block;
    padding: .7rem 1.5rem;
    color: rgba(255,255,255,.8);
    transition: .2s;
}

.nav-menu li a:hover,
.nav-menu li a.active {
    background: rgba(255,255,255,.1);
    color: #fff;
    text-decoration: none;
}

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,.1);
}

.sidebar-footer .user-info { margin-bottom: .5rem; }
.sidebar-footer .btn { margin-right: .3rem; margin-top: .3rem; }

/* Overlay for mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 999;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 2rem;
    max-width: calc(100vw - var(--sidebar-width));
}

/* Mobile top bar - hidden on desktop */
.mobile-header {
    display: none;
    background: var(--primary-dark);
    color: #fff;
    padding: 0.75rem 1rem;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 998;
}

.mobile-header h2 {
    font-size: 1.1rem;
    margin: 0;
}

.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.5rem;
    color: var(--primary-dark);
}

/* ============================================
   CARDS
   ============================================ */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
    margin-bottom: 1rem;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
    flex-wrap: wrap;
    gap: 0.5rem;
}

.card-header h3 { margin: 0; font-size: 1.1rem; }
.card-body { padding: 1.5rem; }
.card-highlight { border-left: 4px solid var(--primary); }

/* ============================================
   STATS
   ============================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
}

.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    color: var(--gray-700);
    margin-top: .3rem;
    font-size: 0.85rem;
}

.stat-warning .stat-number { color: var(--warning); }
.stat-danger .stat-number { color: var(--danger); }

/* ============================================
   TABLE
   ============================================ */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
}

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

.table th {
    font-weight: 600;
    color: var(--gray-700);
    font-size: .85rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    white-space: nowrap;
}

.table tr:hover { background: var(--gray-100); }
.row-overdue { background: #fff5f5 !important; }

/* ============================================
   FORMS
   ============================================ */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    margin-bottom: .3rem;
    font-weight: 500;
    color: var(--gray-700);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="tel"],
select,
textarea {
    width: 100%;
    padding: .6rem .8rem;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 1rem;
    transition: .2s;
    -webkit-appearance: none;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(45,106,79,.1);
}

textarea { resize: vertical; }

.filter-form {
    display: flex;
    gap: .5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-form input, .filter-form select { width: auto; }

.inline-form {
    display: flex;
    gap: .5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: .5rem;
}

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    display: inline-block;
    padding: .5rem 1rem;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    background: #fff;
    color: var(--gray-700);
    cursor: pointer;
    font-size: .9rem;
    transition: .2s;
    text-decoration: none;
    touch-action: manipulation;
}

.btn:hover { background: var(--gray-100); text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn-full { width: 100%; }

/* ============================================
   BADGES, ALERTS, MISC
   ============================================ */
.badge {
    display: inline-block;
    padding: .2rem .6rem;
    border-radius: 50px;
    font-size: .8rem;
    font-weight: 500;
}
.badge-success { background: var(--success); color: #fff; }
.badge-warning { background: var(--warning); color: #fff; }
.badge-danger { background: var(--danger); color: #fff; }

.alert {
    padding: .75rem 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
}
.alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
.alert-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
.alert-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeaa7; }

/* ============================================
   CHECKLIST
   ============================================ */
.checklist-item {
    padding: 1rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    margin-bottom: .75rem;
}
.checklist-header { margin-bottom: .5rem; }
.checklist-header strong { display: block; }
.checklist-header small { color: var(--gray-500); }
.checklist-controls { display: flex; gap: 1rem; margin-bottom: .5rem; flex-wrap: wrap; }
.radio-label { display: flex; align-items: center; gap: .3rem; cursor: pointer; }

/* ============================================
   LIST, PHOTO, LETTER
   ============================================ */
.list-item {
    padding: .75rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: .5rem;
}
.list-item:last-child { border-bottom: none; }

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    gap: .5rem;
}
.photo-thumb {
    width: 100%;
    height: 120px;
    object-fit: cover;
    border-radius: 4px;
    cursor: pointer;
}
.photo-upload { margin-top: .5rem; }

.description-box { background: var(--gray-100); padding: 1rem; border-radius: 4px; }
.letter-body { white-space: pre-wrap; background: var(--gray-100); padding: 1.5rem; border-radius: 4px; }

/* ============================================
   GRID & SPACING
   ============================================ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.mt-1 { margin-top: .5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.text-muted { color: var(--gray-500); }

/* ============================================
   LOGIN PAGE
   ============================================ */
.login-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-dark), var(--primary-light));
    padding: 1rem;
}

.login-card {
    background: #fff;
    padding: 2.5rem;
    border-radius: var(--radius);
    box-shadow: 0 10px 40px rgba(0,0,0,.2);
    width: 100%;
    max-width: 400px;
    text-align: center;
}

.login-card h1 { font-size: 1.8rem; color: var(--primary-dark); margin-bottom: .3rem; }
.login-card p { color: var(--gray-500); margin-bottom: 1.5rem; }
.login-card .form-group { text-align: left; }

/* ============================================
   ERROR PAGE
   ============================================ */
.error-page { display: flex; justify-content: center; align-items: center; min-height: 100vh; }
.error-container { text-align: center; }
.error-container h1 { font-size: 5rem; color: var(--gray-300); }

/* ============================================
   MOBILE RESPONSIVE (max 768px)
   ============================================ */
@media (max-width: 768px) {
    /* Show mobile header with hamburger */
    .mobile-header {
        display: flex;
    }

    .menu-toggle {
        display: block;
        color: #fff;
    }

    .sidebar-close {
        display: block;
        color: #fff;
    }

    /* Sidebar: hidden off-screen by default */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100vh;
        transform: translateX(-100%);
    }

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

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

    /* Main content: full width */
    .main-content {
        margin-left: 0;
        max-width: 100%;
        padding: 1rem;
    }

    .page-header h1 {
        font-size: 1.25rem;
    }

    /* Stats grid: 2 columns on mobile */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }

    .stat-card {
        padding: 1rem;
    }

    .stat-number {
        font-size: 1.5rem;
    }

    .stat-label {
        font-size: 0.75rem;
    }

    /* Grid: stack on mobile */
    .grid-2 {
        grid-template-columns: 1fr;
    }

    /* Cards: tighter padding */
    .card-body {
        padding: 1rem;
    }

    .card-header {
        padding: 0.75rem 1rem;
    }

    /* Table: scrollable */
    .table th, .table td {
        padding: .5rem;
        font-size: .85rem;
    }

    /* Forms: full width filters */
    .filter-form {
        flex-direction: column;
    }

    .filter-form input,
    .filter-form select {
        width: 100%;
    }

    /* Buttons: slightly larger touch targets */
    .btn {
        padding: .6rem 1rem;
        font-size: .9rem;
    }

    /* Photo grid: smaller */
    .photo-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    }

    .photo-thumb {
        height: 100px;
    }

    /* Login card */
    .login-card {
        padding: 1.5rem;
    }

    .login-card h1 {
        font-size: 1.5rem;
    }

    /* Nav menu: vertical on mobile */
    .nav-menu li a {
        padding: .75rem 1.5rem;
        font-size: 1rem;
    }

    /* Inline forms stack */
    .inline-form {
        flex-direction: column;
        align-items: stretch;
    }
}

/* Small phones */
@media (max-width: 400px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .main-content {
        padding: 0.75rem;
    }

    .checklist-controls {
        flex-direction: column;
        gap: .5rem;
    }
}

/* ============================================
   EXTRA CLASSES (fix8)
   ============================================ */
.stat-success .stat-number { color: var(--success); }
.stat-active { outline: 3px solid var(--primary); outline-offset: -3px; }
h4 { font-size: 1rem; margin-bottom: .5rem; }
.scenario-section .card { margin-top: .5rem; }
