/* ==========================================================================
   CSS RESET & GLOBAL
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    background-color: #f8fafc;
    color: #1e293b;
    min-height: 100vh;
    display: flex;
    overflow-x: hidden;
}

ul, ol {
    margin: 0;
    padding: 0;
    list-style: none;
}

button, input, textarea, select {
    font: inherit;
}

a { text-decoration: none; }

/* Custom Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ==========================================================================
   VARIABLES
   ========================================================================== */
:root {
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --sidebar-bg: #ffffff;
    --sidebar-width: 260px;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --text-main: #0f172a;
    --text-muted: #64748b;
    
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

/* ==========================================================================
   LOGIN SCREEN
   ========================================================================== */
.login-screen {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(248, 250, 252, 0.9); backdrop-filter: blur(8px);
    display: flex; justify-content: center; align-items: center; z-index: 9999;
}
.login-card {
    background: var(--card-bg); padding: 2.5rem; border-radius: 16px;
    border: 1px solid var(--border); box-shadow: var(--shadow-md);
    width: 100%; max-width: 400px; text-align: center;
}
.login-logo { font-size: 1.5rem; font-weight: 700; color: var(--primary); margin-bottom: 0.5rem; }
.login-title { color: var(--text-muted); margin-bottom: 2rem; font-size: 0.95rem; }
.admin-input, .admin-select, .admin-textarea {
    width: 100%; padding: 0.75rem 1rem; border-radius: 8px;
    border: 1px solid var(--border); background: #fff;
    color: var(--text-main); transition: border-color 0.2s, box-shadow 0.2s;
}
.admin-input:focus, .admin-select:focus, .admin-textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* ==========================================================================
   LAYOUT: SIDEBAR
   ========================================================================== */
.admin-sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    position: fixed; top: 0; left: 0; height: 100vh;
    padding: 1.5rem 1rem; z-index: 100;
}
.sidebar-brand {
    font-size: 1.25rem; font-weight: 700; color: var(--text-main);
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0 0.5rem; margin-bottom: 2rem;
}
.sidebar-menu {
    display: flex; flex-direction: column; gap: 0.25rem; flex: 1;
}
.menu-item a {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.75rem 1rem; border-radius: 8px;
    color: var(--text-muted); font-weight: 500;
    transition: all 0.2s;
}
.menu-item a:hover {
    background: #f1f5f9; color: var(--text-main);
}
.menu-item.active a {
    background: #eff6ff; color: var(--primary); font-weight: 600;
}
.sidebar-footer {
    margin-top: auto; padding-top: 1rem;
}
.sidebar-footer a {
    display: flex; justify-content: center; align-items: center; width: 100%;
}

/* ==========================================================================
   LAYOUT: MAIN CONTENT
   ========================================================================== */
.admin-main {
    margin-left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    padding: 40px 48px;
}

/* Header */
.admin-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 32px;
}
.page-title {
    font-size: 1.8rem; font-weight: 700; color: var(--text-main); margin: 0 0 0.25rem 0;
}
.admin-header p {
    color: var(--text-muted); margin: 0; font-size: 0.95rem;
}

/* User Badge */
.user-badge {
    display: flex; flex-direction: column; align-items: flex-end;
    background: #fff; padding: 0.75rem 1.25rem; border-radius: 12px;
    border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.user-name { font-weight: 600; color: var(--text-main); font-size: 0.9rem; margin-bottom: 0.2rem; }
.user-badge > div > div:last-child {
    font-size: 0.75rem; color: var(--success); font-weight: 500;
    display: flex; align-items: center; gap: 4px;
}

/* ==========================================================================
   DASHBOARD COMPONENTS
   ========================================================================== */
section { margin-bottom: 32px; }

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 24px;
    margin-bottom: 32px;
}
.stat-card {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: 16px; padding: 1.5rem;
    display: flex; align-items: center; gap: 1rem;
    box-shadow: var(--shadow-sm);
    height: 100%; /* Equal height */
}
.stat-icon {
    width: 48px; height: 48px; border-radius: 12px;
    display: flex; justify-content: center; align-items: center;
    font-size: 1.25rem; flex-shrink: 0;
}
.stat-icon.blue { background: #eff6ff; color: var(--primary); }
.stat-icon.purple { background: #f5f3ff; color: #8b5cf6; }
.stat-icon.green { background: #ecfdf5; color: var(--success); }
.stat-icon.amber { background: #fffbeb; color: var(--warning); }
.stat-info { display: flex; flex-direction: column; justify-content: center; }
.stat-info h3 { margin: 0 0 0.25rem 0; font-size: 0.85rem; color: var(--text-muted); font-weight: 500; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--text-main); }

/* Content Cards & AI Box */
.content-card, .ai-box {
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: 16px; padding: 24px; margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}
.card-header, .ai-box-header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 1.2rem; font-weight: 700; color: var(--text-main); margin: 0; }
.ai-box-header { font-size: 1.1rem; font-weight: 600; color: var(--text-main); margin-bottom: 1rem; }

/* ==========================================================================
   TABLES
   ========================================================================== */
.table-responsive {
    width: 100%; overflow-x: auto;
    border-radius: 8px; /* For clean scroll area */
}
.admin-table {
    width: 100%; min-width: 700px;
    border-collapse: collapse; text-align: left;
}
.admin-table th {
    padding: 1rem; font-size: 0.8rem; text-transform: uppercase;
    color: var(--text-muted); font-weight: 600;
    border-bottom: 2px solid var(--border);
    background: #f8fafc;
}
.admin-table td {
    padding: 1rem; border-bottom: 1px solid var(--border);
    font-size: 0.9rem; color: var(--text-main); vertical-align: middle;
}
.admin-table tr:hover td { background: #f1f5f9; }

/* Buttons */
.btn-admin {
    padding: 0.6rem 1.2rem; border: none; border-radius: 8px; cursor: pointer;
    font-weight: 600; transition: all 0.2s;
    display: inline-flex; align-items: center; gap: 8px; font-size: 0.9rem;
    justify-content: center;
}
.btn-admin-primary { background: var(--primary); color: #fff; }
.btn-admin-primary:hover { background: var(--primary-hover); }
.btn-admin-success { background: var(--success); color: #fff; }
.btn-admin-success:hover { background: #059669; }
.btn-admin-danger { background: #fee2e2; color: var(--danger); }
.btn-admin-danger:hover { background: #fecaca; }

/* Forms */
.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; margin-bottom: 0.5rem; font-size: 0.85rem; font-weight: 600; color: var(--text-main); }

/* Badges */
.status-badge {
    padding: 0.25rem 0.75rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 600; display: inline-block;
}
.badge-new { background: #dbeafe; color: #1e40af; }
.badge-processing { background: #fef3c7; color: #92400e; }
.badge-completed { background: #d1fae5; color: #065f46; }

/* Utility */
.hidden { display: none !important; }
.tab-content { display: none; animation: fadeIn 0.3s ease; }
.tab-content.active { display: block; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

/* Tablet (Under 1200px) */
@media (max-width: 1199px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .admin-main { padding: 30px; }
}

/* Mobile (Under 768px) */
@media (max-width: 767px) {
    body { flex-direction: column; }
    
    /* Sidebar becomes horizontal scroll or stack */
    .admin-sidebar {
        width: 100%; height: auto; position: relative;
        padding: 1rem; border-right: none; border-bottom: 1px solid var(--border);
        flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between;
    }
    .sidebar-brand { margin-bottom: 0; padding: 0; }
    .sidebar-menu {
        flex-direction: row; overflow-x: auto; flex: 1 1 100%;
        margin-top: 1rem; gap: 0.5rem; padding-bottom: 0.5rem;
    }
    .menu-item a { white-space: nowrap; }
    .sidebar-footer { margin-top: 1rem; padding-top: 0; width: 100%; border-top: none; }
    
    /* Main Content */
    .admin-main { width: 100%; margin-left: 0; padding: 20px; }
    .admin-header { flex-direction: column; align-items: flex-start; gap: 1rem; }
    .user-badge { width: 100%; align-items: flex-start; }
    
    /* Stats */
    .stats-grid { grid-template-columns: 1fr; }
    
    /* Hide some table columns on very small screens if necessary, but horizontal scroll handles it */
}
