/* ============================================
   1. VARIABLES & THEME
   ============================================ */
:root {
    /* Brand Colors */
    --primary-color: #326193;
    --primary-dark: #030C4D;
    --secondary-color: #64748b;
    --accent-color: #38bdf8;
    
    /* Functional Colors */
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --info-color: #3b82f6;

    /* Surface Colors */
    --bg-body: #f1f5f9;
    --bg-surface: #ffffff;
    --bg-sidebar: linear-gradient(135deg, #326193 0%, #030C4D 100%);
    
    /* Typography */
    --font-primary: "Aleo", serif;
    --font-system: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --text-main: #334155;
    --text-light: #64748b;
    --text-white: #ffffff;

    /* Spacing & Layout */
    --header-height: 64px;
    --sidebar-width: 260px;
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1);
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* ============================================
   2. RESET & BASE
   ============================================ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-system);
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, h5, h6 {
    font-family: var(--font-primary);
    font-weight: 600;
    color: var(--primary-dark);
    line-height: 1.2;
    margin-bottom: 0.75rem;
}

a {
    color: var(--primary-color);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover:not(.btn) {
    color: var(--primary-dark);
}

ul {
    list-style: none;
}

img {
    max-width: 100%;
    display: block;
}

/* ============================================
   3. LAYOUT & GRID
   ============================================ */
/* App Shell Grid */
.app-shell {
    display: grid;
    grid-template-areas: 
        "header header"
        "sidebar main";
    grid-template-columns: var(--sidebar-width) 1fr;
    grid-template-rows: var(--header-height) 1fr;
    min-height: 100vh;
}

/* Header */
.top-nav {
    grid-area: header;
    background-color: var(--bg-surface);
    border-bottom: 1px solid #e2e8f0;
    padding: 0 2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.nav-brand h2 {
    font-size: 1.25rem;
    margin: 0;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.nav-actions {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.nav-user {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-light);
}

/* Sidebar */
.sidebar {
    grid-area: sidebar;
    background: var(--bg-sidebar);
    color: var(--text-white);
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
    overflow-y: auto;
    padding: 1.5rem 0;
    box-shadow: 4px 0 24px rgba(0,0,0,0.1);
}

.sidebar-nav ul {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 0 1rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: rgba(255, 255, 255, 0.7);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.sidebar-link:hover {
    color: var(--text-white);
    background-color: rgba(255, 255, 255, 0.1);
}

.sidebar-link.active {
    color: var(--text-white);
    background-color: rgba(255, 255, 255, 0.2);
    font-weight: 600;
    box-shadow: var(--shadow-sm);
}

/* Main Content */
.main-content {
    grid-area: main;
    padding: 2rem;
    overflow-x: hidden;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

/* ============================================
   4. COMPONENTS
   ============================================ */

/* Cards */
.card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid #e2e8f0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    line-height: 1.5;
}

.btn:disabled, .btn[disabled] {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background-color: var(--primary-color);
    color: white;
}
.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-dark);
    box-shadow: 0 4px 6px -1px rgba(50, 97, 147, 0.3);
    color: white;
}

/* Ensure anchor tags styled as buttons keep their color on hover */
a.btn-primary,
a.btn-primary:hover,
a.btn-primary:visited,
a.btn-primary:active {
    color: white !important;
}

a.btn-secondary,
a.btn-secondary:hover,
a.btn-secondary:visited,
a.btn-secondary:active {
    color: var(--text-main) !important;
}

a.btn-danger,
a.btn-danger:hover,
a.btn-danger:visited,
a.btn-danger:active {
    color: white !important;
}

.btn-secondary {
    background-color: white;
    border-color: #cbd5e1;
    color: var(--text-main);
}
.btn-secondary:hover:not(:disabled) {
    background-color: #f8fafc;
    border-color: #94a3b8;
}

.btn-danger {
    background-color: var(--danger-color);
    color: white;
}
.btn-danger:hover:not(:disabled) {
    background-color: #dc2626;
}

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
}

.btn-block {
    width: 100%;
}

/* Forms */
.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 0.875rem;
    line-height: 1.5;
    color: var(--text-main);
    background-color: #fff;
    border: 1px solid #cbd5e1;
    border-radius: var(--radius-sm);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(50, 97, 147, 0.1);
}

.form-control.error {
    border-color: var(--danger-color);
}

.form-help {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--text-light);
}

.error-message {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    color: var(--danger-color);
}

/* Tables */
.table-container {
    background: var(--bg-surface);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    border: 1px solid #e2e8f0;
}

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

.data-table th {
    background-color: #f8fafc;
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: var(--text-light);
    letter-spacing: 0.05em;
    border-bottom: 1px solid #e2e8f0;
}

.data-table td {
    padding: 1rem;
    border-bottom: 1px solid #e2e8f0;
    font-size: 0.875rem;
    color: var(--text-main);
}

.data-table tbody tr:last-child td {
    border-bottom: none;
}

.data-table tbody tr:hover {
    background-color: #f8fafc;
}

/* Badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
    line-height: 1;
}

.badge-success { background-color: #dcfce7; color: #166534; }
.badge-warning { background-color: #fef3c7; color: #92400e; }
.badge-danger  { background-color: #fee2e2; color: #991b1b; }
.badge-info    { background-color: #dbeafe; color: #1e40af; }
.badge-secondary { background-color: #f1f5f9; color: #475569; }

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
}

.alert-success { background-color: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.alert-error   { background-color: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-info    { background-color: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }

/* ============================================
   5. UTILITIES (Alpine & JS States)
   ============================================ */
.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }
.mr-2 { margin-right: 0.5rem; }
.text-center { text-align: center; }

/* Dimensions */
.h-5 { height: 1.25rem; }
.w-5 { width: 1.25rem; }
.flex-grow { flex-grow: 1; }
.flex-col { flex-direction: column; }
.flex-wrap { flex-wrap: wrap; }
.items-end { align-items: flex-end; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }

/* Positioning */
.relative { position: relative; }
.absolute { position: absolute; }
.left-3 { left: 0.75rem; }
.top-1\/2 { top: 50%; }
.-translate-y-1\/2 { transform: translateY(-50%); }

/* Typography Strings */
.text-2xl { font-size: 1.5rem; line-height: 2rem; }
.text-sm { font-size: 0.875rem; }
.text-xs { font-size: 0.75rem; }
.font-bold { font-weight: 700; }
.font-semibold { font-weight: 600; }
.uppercase { text-transform: uppercase; }
.tracking-wider { letter-spacing: 0.05em; }
.block { display: block; }
.text-gray-400 { color: #94a3b8; }
.text-gray-500 { color: #64748b; }
.text-gray-800 { color: #1e293b; }

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(2px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

.spinner {
    width: 2.5rem;
    height: 2.5rem;
    border: 3px solid #e2e8f0;
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    min-width: 300px;
    background: white;
    padding: 1rem 1.25rem;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--primary-color);
    animation: slideIn 0.3s ease forwards;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.875rem;
}

.toast[data-type="success"] { border-left-color: var(--success-color); }
.toast[data-type="error"]   { border-left-color: var(--danger-color); }
.toast[data-type="info"]    { border-left-color: var(--info-color); }

@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ============================================
   6. RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .app-shell {
        grid-template-areas: 
            "header"
            "main";
        grid-template-columns: 1fr;
        grid-template-rows: var(--header-height) 1fr;
    }

    .top-nav {
        padding: 0 1rem;
    }

    .nav-left {
        display: flex;
        align-items: center;
        gap: 0.75rem;
    }

    .mobile-menu-toggle {
        display: flex;
        align-items: center;
        justify-content: center;
        background: transparent;
        border: none;
        color: var(--primary-dark);
        cursor: pointer;
        padding: 5px;
        border-radius: var(--radius-sm);
    }

    .mobile-menu-toggle:hover {
        background-color: #f1f5f9;
    }

    .nav-user-desktop {
        display: none;
    }

    .sidebar {
        grid-area: unset;
        display: block;
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 1000;
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
        height: 100vh;
        padding-top: 1.5rem;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }

    .mobile-sidebar-overlay {
        position: fixed;
        inset: 0;
        background-color: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(4px);
        z-index: 999;
    }

    .mobile-menu-open {
        overflow: hidden;
    }
    
    .nav-actions {
        gap: 0.5rem;
    }

    .brand-text {
        display: none;
    }
    
    .nav-brand h2 {
        font-size: 1rem;
    }

    .main-content {
        padding: 1.5rem 1rem;
    }
}

@media (max-width: 480px) {
    .nav-brand h2 img {
        height: 28px !important;
    }
}

.nav-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.mobile-menu-toggle {
    display: none;
}
