:root {
    /* Palette - Cobalt & Forest */
    --primary: #0047AB;
    --primary-dark: #003380;
    --accent: #2ECC71;
    /* Emerald Success */
    --bg: #F8F9FA;
    --card-bg: #FFFFFF;
    --text-main: #2D3436;
    --text-muted: #636E72;
    --danger: #D63031;
    --warning: #FDCB6E;

    /* Metrics */
    --sidebar-w: 260px;
    --header-h: 65px;
    --radius: 12px;
    --shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Base Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg);
    color: var(--text-main);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Layout Engine */
.app-shell {
    display: flex;
    min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
    width: var(--sidebar-w);
    background: var(--primary);
    color: white;
    display: flex;
    flex-direction: column;
    height: 100vh;
    position: sticky;
    top: 0;
    z-index: 1100;
    /* Higher than overlay */
    transition: var(--transition);
}

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

.sidebar-logo {
    height: 40px;
    filter: brightness(0) invert(1);
}

.nav-group {
    padding: 20px 15px;
    flex: 1;
    overflow-y: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 15px;
    margin-bottom: 6px;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.2s;
    font-weight: 500;
    font-size: 0.95rem;
}

.nav-item:hover,
.nav-item.active {
    background: rgba(255, 255, 255, 0.15);
}

.nav-item .icon {
    font-size: 1.25rem;
    width: 24px;
    text-align: center;
}

/* MAIN CONTENT */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    /* Prevents overflow-x */
}

.top-bar {
    height: var(--header-h);
    background: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 25px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    position: sticky;
    top: 0;
    z-index: 900;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.page-title {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.view-port {
    padding: 25px;
    max-width: 1400px;
    margin: 0 auto;
    width: 100%;
}

/* DASHBOARD & GRIDS */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    padding: 20px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 15px;
}

.stat-icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    background: rgba(0, 71, 171, 0.1);
    color: var(--primary);
}

.action-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 15px;
}

.action-tile {
    background: white;
    padding: 25px 15px;
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: transform 0.2s, box-shadow 0.2s;
    border: 1px solid #f0f0f0;
}

.action-tile:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.action-tile .icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
}

.action-tile span {
    font-weight: 600;
    font-size: 0.9rem;
}

/* FORMS */
.card-form {
    background: white;
    padding: 30px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    max-width: 800px;
    margin: 0 auto;
}

.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

.field {
    margin-bottom: 15px;
}

.field label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 12px 15px;
    border: 1px solid #D1D5DB;
    border-radius: 8px;
    font-size: 1rem;
    background: #F9FAFB;
}

.field input:focus {
    border-color: var(--primary);
    outline: none;
    box-shadow: 0 0 0 3px rgba(0, 71, 171, 0.1);
}

/* BUTTONS */
.btn {
    padding: 12px 20px;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: 0.2s;
}

.btn-full {
    width: 100%;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-ghost {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
}

/* RESPONSIVE LOGIC */

/* Mobile (< 768px) */
@media (max-width: 767px) {
    .sidebar {
        position: fixed;
        left: -100%;
        height: 100vh;
        width: 280px;
    }

    .sidebar.active {
        left: 0;
    }

    .view-port {
        padding: 15px;
    }

    .input-row {
        grid-template-columns: 1fr;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }
}

/* Tablet (768px - 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
    :root {
        --sidebar-w: 200px;
    }

    .nav-item span:not(.icon) {
        display: none;
        /* Icon-only sidebar on medium screens */
    }

    .sidebar-header {
        justify-content: center;
    }

    .sidebar-logo {
        height: 30px;
    }
}

/* Desktop (> 1024px) */
@media (min-width: 1025px) {
    .sidebar-toggle {
        display: none !important;
    }
}

/* Utility */
.hidden {
    display: none !important;
}

.overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    /* Safari Support */
    z-index: 1000;
    /* Behind active sidebar */
}

.role-operator .role-admin-only,
.role-operator .role-office-only {
    display: none !important;
}

/* TABS & MODULAR VIEWS */
.tabs-control {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    overflow-x: auto;
    padding-bottom: 5px;
    -webkit-overflow-scrolling: touch;
}

.tab-btn,
.btn-ghost.btn-sm {
    padding: 8px 16px;
    border-radius: 20px;
    border: 1px solid var(--primary);
    background: transparent;
    color: var(--primary);
    cursor: pointer;
    white-space: nowrap;
    font-size: 0.85rem;
    font-weight: 600;
    transition: 0.2s;
}

.tab-btn.active,
.btn-ghost.btn-sm.active {
    background: var(--primary);
    color: white;
}

.tab-content.hidden {
    display: none !important;
}

.grid-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-card {
    background: white;
    border-radius: 8px;
    padding: 15px;
    border: 1px solid #eee;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.role-item {
    display: block;
    /* Default to show if no role class on body */
}

.role-operator .role-item:not(.operator) {
    display: none !important;
}

.role-office .role-item:not(.office) {
    display: none !important;
}