/* Modern Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #0ea5a4;
    --primary-hover: #14b8a6;
    --secondary: #f59e0b;
    --bg-body: #0b1220;
    --bg-card: rgba(18, 28, 44, 0.9);
    --bg-input: rgba(40, 54, 74, 0.9);
    --text-main: #f8fafc;
    --text-muted: #a8b8d1;
    --border: rgba(148, 163, 184, 0.2);
    --radius: 8px;
    --shadow: 0 24px 80px rgba(0, 0, 0, 0.28), 0 1px 0 rgba(255, 255, 255, 0.04) inset;

    /* Typography */
    --font-heading: 'Outfit', 'Segoe UI', sans-serif;
    --font-body: 'Inter', system-ui, -apple-system, sans-serif;
}

/* Light Mode Support (Toggleable class) */
body.light-mode {
    --primary: #0f766e;
    --primary-hover: #0d9488;
    --secondary: #b45309;
    --bg-body: #f7f3ea;
    --bg-card: rgba(255, 255, 255, 0.94);
    --bg-input: #eef2f0;
    --text-main: #172033;
    --text-muted: #64748b;
    --border: rgba(15, 118, 110, 0.16);
}

body {
    background:
        radial-gradient(circle at 12% 8%, rgba(14, 165, 164, 0.18), transparent 28rem),
        radial-gradient(circle at 88% 12%, rgba(245, 158, 11, 0.10), transparent 26rem),
        linear-gradient(135deg, #07101d 0%, #0d1828 44%, #101827 100%);
    color: var(--text-main);
    font-family: var(--font-body);
    line-height: 1.6;
    overflow-x: hidden;
    transition: background-color 0.3s, color 0.3s;
}

body.light-mode {
    background:
        radial-gradient(circle at 12% 8%, rgba(15, 118, 110, 0.12), transparent 28rem),
        radial-gradient(circle at 88% 12%, rgba(180, 83, 9, 0.10), transparent 26rem),
        linear-gradient(135deg, #fbf8f1 0%, #eef6f3 52%, #f8fafc 100%);
}

/* Layout Grid */
.app-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

/* Mobile Sidebar (Hidden by default on mobile) */
@media (max-width: 768px) {
    .app-layout {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: fixed;
        left: -260px;
        top: 0;
        bottom: 0;
        width: 260px;
        z-index: 50;
        transition: left 0.3s ease;
    }

    .sidebar.active {
        left: 0;
    }

    .mobile-header {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 1rem;
        background: var(--bg-card);
        border-bottom: 1px solid var(--border);
    }
}

/* Sidebar Styling */
.sidebar {
    background: linear-gradient(180deg, rgba(20, 33, 54, 0.96), rgba(12, 22, 38, 0.98));
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 1.5rem;
    backdrop-filter: blur(18px);
}

.brand {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 2rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    margin: -0.75rem 0 1.25rem;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-input);
    color: var(--text-main);
    cursor: pointer;
    font-weight: 700;
}

.role-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    width: 100%;
    margin: -0.6rem 0 1rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid rgba(14, 165, 164, 0.22);
    border-radius: var(--radius);
    background: rgba(14, 165, 164, 0.12);
    color: var(--primary);
    font-size: 0.78rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0;
}

.nav-menu {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}

.nav-item a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius);
    transition: all 0.2s;
    font-weight: 500;
}

.nav-item a:hover,
.nav-item a.active {
    background: linear-gradient(135deg, rgba(14, 165, 164, 0.20), rgba(245, 158, 11, 0.08));
    color: var(--primary);
    box-shadow: inset 0 0 0 1px rgba(14, 165, 164, 0.16);
}

/* Main Content */
.main-content {
    padding: 2rem;
    max-width: 1400px;
    width: 100%;
    margin: 0 auto;
}

/* Modern Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    backdrop-filter: blur(16px);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: transform 0.1s;
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: #ffffff;
    box-shadow: 0 10px 24px rgba(14, 165, 164, 0.22);
}

.btn-primary:active {
    transform: scale(0.98);
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.form-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-main);
    font-family: inherit;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Utilities */
.hidden {
    display: none;
}

.text-center {
    text-align: center;
}

.mb-4 {
    margin-bottom: 1rem;
}

.flex {
    display: flex;
}

.justify-between {
    justify-content: space-between;
}

.items-center {
    align-items: center;
}

/* Grid for Dashboard */
.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
}

/* Missing Utilities */
.gap-3 {
    gap: 0.75rem;
}

.gap-4 {
    gap: 1rem;
}

/* Responsive Chart Grid Fix */
@media (max-width: 1024px) {
    .dashboard-grid[style*="grid-template-columns: 2fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
}

/* Mobile Content Padding */
@media (max-width: 768px) {
    .main-content {
        padding: 1rem;
    }

    .card {
        padding: 1rem;
    }
}

/* Overlay for active mobile sidebar */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 40;
}

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

/* ── Utility additions ────────────────────────────── */
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-2 { margin-bottom: 0.5rem; }
.pt-4 { padding-top: 1rem; }
.p-0 { padding: 0; }
.border-t { border-top: 1px solid var(--border); }
.w-full { width: 100%; }

/* ── Button sizes ─────────────────────────────────── */
.btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.8rem;
}

/* ── Form elements: select, textarea ─────────────── */
select.form-input {
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.9rem center;
    padding-right: 2.5rem;
    cursor: pointer;
}

textarea.form-input {
    resize: vertical;
    line-height: 1.6;
}

.form-input:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
}

/* ── Alert / Flash messages ──────────────────────── */
.alert {
    padding: 0.85rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
}
.alert-success {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.4);
    color: #22c55e;
}
.alert-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #ef4444;
}
.alert-warning {
    background: rgba(245, 158, 11, 0.1);
    border: 1px solid rgba(245, 158, 11, 0.4);
    color: #f59e0b;
}
.alert-info {
    background: rgba(96, 165, 250, 0.1);
    border: 1px solid rgba(96, 165, 250, 0.4);
    color: #60a5fa;
}

/* ── Toast notification ──────────────────────────── */
.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem 1.25rem;
    font-size: 0.9rem;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    pointer-events: all;
    animation: toastIn 0.3s ease;
    backdrop-filter: blur(12px);
}
.toast.toast-success { border-left: 3px solid #22c55e; color: #22c55e; }
.toast.toast-error   { border-left: 3px solid #ef4444; color: #ef4444; }
.toast.toast-info    { border-left: 3px solid var(--primary); color: var(--primary); }
@keyframes toastIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Responsive table wrapper ────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ── Badge / pill variants ───────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 1rem;
    font-size: 0.75rem;
    font-weight: 600;
}
.badge-primary  { background: rgba(14, 165, 164, 0.15); color: var(--primary); }
.badge-success  { background: rgba(34, 197, 94, 0.15);  color: #22c55e; }
.badge-warning  { background: rgba(245, 158, 11, 0.15); color: #f59e0b; }
.badge-danger   { background: rgba(239, 68, 68, 0.15);  color: #ef4444; }
.badge-blue     { background: rgba(96, 165, 250, 0.15); color: #60a5fa; }
.badge-pink     { background: rgba(244, 114, 182, 0.15);color: #f472b6; }

/* ── Button loading state ────────────────────────── */
.btn.loading {
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
    position: relative;
}
.btn.loading::after {
    content: '';
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-left: 0.5rem;
    display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Link button without decoration ─────────────── */
.btn-link {
    background: none;
    border: none;
    padding: 0;
    color: var(--primary);
    cursor: pointer;
    text-decoration: underline;
    font-size: inherit;
    font-weight: 500;
}

/* ── Logout nav item ─────────────────────────────── */
.nav-item a.nav-logout {
    color: #ef4444;
}
.nav-item a.nav-logout:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

/* ── Theme toggle in sidebar ─────────────────────── */
.sidebar-theme-toggle {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.75rem 1rem;
    margin-top: 0.5rem;
    border: none;
    border-radius: var(--radius);
    background: linear-gradient(135deg, #0ea5a4 0%, #087b7a 100%);
    color: #ffffff;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 700;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 4px 12px rgba(14, 165, 164, 0.25);
    text-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.sidebar-theme-toggle i {
    font-size: 1.1rem;
    color: #facc15;
}
.sidebar-theme-toggle:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(14, 165, 164, 0.35);
    background: linear-gradient(135deg, #0faeac 0%, #098b8a 100%);
}
.sidebar-theme-toggle:active {
    transform: translateY(0);
}

/* ── Mobile responsive fixes ─────────────────────── */
@media (max-width: 640px) {
    .dashboard-grid[style*="repeat(5"] {
        grid-template-columns: repeat(3, 1fr) !important;
    }
    .dashboard-grid[style*="repeat(4"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
    .dashboard-grid[style*="repeat(3"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}

/* ── Page fade-in ────────────────────────────────── */
.main-content {
    animation: fadeIn 0.25s ease;
}
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Empty state ─────────────────────────────────── */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    text-align: center;
    color: var(--text-muted);
}
.empty-state i { font-size: 4rem; margin-bottom: 1rem; opacity: 0.4; }
.empty-state h3 { margin-bottom: 0.5rem; color: var(--text-muted); }
.empty-state p  { margin-bottom: 1.5rem; font-size: 0.9rem; }
