/* ==========================================================================
   CSS Variables (Design Tokens) - Light & Dark Mode
   ========================================================================== */
:root {
    /* Light Mode (Default) */
    --color-bg: #f3f4f6; /* Lighter background for the app feel */
    --color-surface: #ffffff;
    --color-text: #1f2937;
    --color-text-muted: #6b7280;
    
    /* Orange / Brand (#EE741E base) */
    --color-primary: #ea580c; /* close to #ee741e but slightly higher contrast */
    --color-primary-hover: #c2410c;
    --color-primary-light: #ffedd5;
    
    --color-danger: #ef4444;
    --color-danger-hover: #dc2626;
    
    --color-success: #10b981;
    --color-success-hover: #059669;

    --color-warning: #f59e0b;
    --color-warning-hover: #d97706;

    --border-color: #e5e7eb;
    --border-radius: 12px;
    --border-radius-lg: 20px;
    
    /* Premium Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.05), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.05), 0 4px 6px -4px rgb(0 0 0 / 0.05);
    
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    
    /* Spacing */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 1rem;
    --space-4: 1.5rem;
    --space-5: 2rem;

    /* Layout Variables */
    --sidebar-width: 90px;
}

[data-theme="dark"] {
    --color-bg: #111827;
    --color-surface: #1f2937;
    --color-text: #f9fafb;
    --color-text-muted: #9ca3af;
    
    --color-primary: #f97316;
    --color-primary-hover: #fb923c;
    --color-primary-light: #431407;
    
    --color-danger: #f87171;
    --color-danger-hover: #fca5a5;

    --border-color: #374151;
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.5);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.5);
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-family: var(--font-sans);
    line-height: 1.5;
    background-color: var(--color-bg);
    color: var(--color-text);
    transition: background-color 0.3s, color 0.3s;
}

body {
    min-height: 100vh;
    overflow-x: hidden;
}

img, svg { max-width: 100%; height: auto; display: block; }

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color 0.2s;
}
a:hover { color: var(--color-primary-hover); text-decoration: underline; }

/* Accessibility */
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border-width: 0;
}
.skip-link {
    position: absolute; top: -40px; left: 0; background: var(--color-primary); color: white;
    padding: 8px; z-index: 9999; transition: top 0.2s;
}
.skip-link:focus { top: 0; }

/* ==========================================================================
   App Layout (Sidebar & Main Content)
   ========================================================================== */
.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: #1e293b; /* Dark Navy */
    color: white;
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: transform 0.3s ease;
    z-index: 1000;
}

.sidebar-header {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 var(--space-2);
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.sidebar-header .brand {
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    text-decoration: none;
}

.mobile-close-btn {
    display: none;
    background: none; border: none; color: white; font-size: 1.5rem; cursor: pointer;
}

.sidebar-nav {
    flex: 1;
    padding: var(--space-3) 0;
    overflow-y: auto;
}

.sidebar-nav ul { list-style: none; }
.sidebar-nav li { margin-bottom: 0.25rem; }

.sidebar-nav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
    padding: 1rem 0.5rem;
    color: rgba(255,255,255,0.6);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.75rem;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover, .sidebar-nav a:focus {
    color: white;
    background: rgba(255,255,255,0.05);
}

.sidebar-nav a[aria-current="page"] {
    color: var(--color-primary);
    background: rgba(255,255,255,0.02);
    font-weight: 600;
    border-left: 3px solid var(--color-primary);
}

.sidebar-footer {
    padding: var(--space-3) 0;
    border-top: 1px solid rgba(255,255,255,0.05);
}

.logout-link {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    color: rgba(255,255,255,0.6);
    text-decoration: none;
}
.logout-link:hover { color: white; text-decoration: none; }

/* Main Content Wrapper */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0; /* fixes flexbox overflow issues */
}

/* Top Header */
.top-header {
    height: 70px;
    background-color: var(--color-surface);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-4);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
    z-index: 50;
}

.top-header-left {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex: 1;
}

.hamburger-btn {
    display: none;
    background: none; border: none; color: var(--color-text); font-size: 1.5rem; cursor: pointer;
}

.global-search-container {
    display: flex;
    align-items: center;
    background: var(--color-bg);
    border-radius: 9999px;
    padding: 0.25rem 1rem;
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border-color);
}
.global-search-container:focus-within {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}
.global-search-container input {
    border: none; background: transparent; padding: 0.5rem; box-shadow: none; width: 100%;
}
.global-search-container input:focus { box-shadow: none; }

.top-header-right {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.theme-toggle {
    background: none; border: none; color: var(--color-text); font-size: 1.25rem; cursor: pointer;
    width: 40px; height: 40px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { background: var(--color-bg); }
.theme-toggle::after { content: "🌙"; }
[data-theme="dark"] .theme-toggle::after { content: "☀️"; }

.user-profile .avatar {
    width: 40px; height: 40px; border-radius: 50%; background: var(--color-primary-light);
    color: var(--color-primary); display: flex; align-items: center; justify-content: center; font-weight: bold;
}

/* Content Area */
.content-area {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
}
@media (min-width: 1024px) {
    .content-area { padding: var(--space-5); }
}

/* Mobile Layout Overrides */
@media (max-width: 767px) {
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; transform: translateX(-100%);
    }
    .sidebar.open { transform: translateX(0); }
    .hamburger-btn { display: block; }
    .mobile-close-btn { display: block; }
    .global-search-container { max-width: 200px; }
}

/* Auth Layout (Login) */
.auth-layout {
    display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--color-bg);
}
.auth-layout .container { width: 100%; max-width: 400px; padding: var(--space-3); }

/* ==========================================================================
   Components (Forms, Buttons, Cards)
   ========================================================================== */
.card {
    background-color: var(--color-surface);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: var(--space-4);
    margin-bottom: var(--space-3);
    box-shadow: var(--shadow-sm);
}

.modern-card {
    border-radius: var(--border-radius-lg);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}
.modern-card:hover {
    box-shadow: var(--shadow-lg);
    border-color: var(--color-primary);
    transform: translateY(-2px);
}

/* Forms */
.form-group { margin-bottom: var(--space-3); }
label { display: block; margin-bottom: var(--space-1); font-weight: 600; font-size: 0.875rem; }

input[type="text"], input[type="email"], input[type="password"], input[type="search"],
input[type="date"], input[type="datetime-local"], textarea, select {
    width: 100%; padding: 0.75rem 1rem; border: 1px solid var(--border-color);
    border-radius: var(--border-radius); background-color: var(--color-bg);
    color: var(--color-text); font-family: inherit; font-size: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
}
input:focus, textarea:focus, select:focus {
    outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-light);
}
input[aria-invalid="true"] { border-color: var(--color-danger); }
.error-message { color: var(--color-danger); font-size: 0.875rem; margin-top: var(--space-1); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 0.6rem 1.2rem; border: none; border-radius: var(--border-radius);
    font-family: inherit; font-size: 1rem; font-weight: 600; cursor: pointer;
    transition: all 0.2s; text-decoration: none;
}
.btn:focus { outline: none; box-shadow: 0 0 0 3px var(--color-primary-light); }

.btn-primary { background-color: var(--color-primary); color: white; }
.btn-primary:hover, .btn-primary:focus { background-color: var(--color-primary-hover); color: white; text-decoration: none; }

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

.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; }

/* Dashboard / Grid */
.dashboard-grid { display: grid; grid-template-columns: 1fr; gap: var(--space-4); }
@media (min-width: 1024px) { .dashboard-grid { grid-template-columns: 1fr 1fr; } }

.overdue { border-left: 4px solid var(--color-danger); }

/* Utilities */
.alert { padding: var(--space-3); border-radius: var(--border-radius); margin-bottom: var(--space-3); font-weight: 500; }
.alert-info { background-color: var(--color-primary-light); color: var(--color-primary-hover); }

.badge { display: inline-flex; align-items: center; padding: 0.2rem 0.6rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 700; }
.badge-danger { background-color: var(--color-danger); color: white; }

.pill { background-color: var(--border-color); color: var(--color-text); padding: 0.15rem 0.6rem; border-radius: 12px; font-size: 0.75rem; font-weight: 500;}

/* ==========================================================================
   Print Styles (PDF Export)
   ========================================================================== */
@media print {
    body { background-color: white; color: black; }
    .sidebar, .top-header, .btn, .skip-link { display: none !important; }
    .main-wrapper { margin: 0; padding: 0; }
    .content-area { padding: 0; }
    .card { box-shadow: none; border: 1px solid #ccc; page-break-inside: avoid; }
    a { text-decoration: none; color: black; }
}
