/*
 * ESN Admin Portal - Premium Shadcn & Tailwind Aesthetic
 * Globally upgrades all admin pages to modern web standards.
 */

/* ========== FONTS ========== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ========== CSS VARIABLES (Shadcn Config) ========== */
:root {
    /* Shadcn Slate Theme Colors */
    --bg-primary: #ffffff;
    /* Background */
    --bg-secondary: #f8fafc;
    /* Muted/slate-50 */
    --bg-tertiary: #f1f5f9;
    /* slate-100 */
    --bg-card: #ffffff;
    /* Card */
    --bg-hover: #f1f5f9;
    /* slate-100 hover */

    --text-primary: #0f172a;
    /* slate-900 */
    --text-secondary: #334155;
    /* slate-700 */
    --text-muted: #64748b;
    /* slate-500 */

    /* Shadcn Brand/Primary */
    --accent: #0f172a;
    /* Primary - Dark */
    --accent-hover: #1e293b;
    /* Primary Hover */
    --accent-light: rgba(15, 23, 42, 0.05);

    /* Status Colors */
    --success: #10b981;
    /* emerald-500 */
    --success-bg: #ecfdf5;
    /* emerald-50 */
    --warning: #f59e0b;
    /* amber-500 */
    --warning-bg: #fffbeb;
    /* amber-50 */
    --danger: #ef4444;
    /* red-500 */
    --danger-bg: #fef2f2;
    /* red-50 */
    --info: #3b82f6;
    /* blue-500 */
    --info-bg: #eff6ff;
    /* blue-50 */

    /* Borders */
    --border: #e2e8f0;
    /* slate-200 */
    --border-light: #f1f5f9;

    /* Spacing */
    --sidebar-width: 260px;
    --header-height: 64px;

    /* Tailwind Shadows */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

    /* Shadcn Border Radius */
    --radius-sm: 0.25rem;
    /* 4px  */
    --radius-md: 0.375rem;
    /* 6px  */
    --radius-lg: 0.5rem;
    /* 8px  */
    --radius-xl: 0.75rem;
    /* 12px */
    --radius-full: 9999px;
}

/* ========== RESET ========== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', ui-sans-serif, system-ui, -apple-system, sans-serif;
    font-weight: 400;
    background: var(--bg-secondary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: inherit;
    text-decoration: none;
}

/* ========== TYPOGRAPHY (Tailwind/Shadcn style) ========== */
h1,
h2,
h3,
h4,
h5,
h6 {
    font-weight: 600;
    line-height: normal;
    letter-spacing: -0.025em;
    color: var(--text-primary);
}

h1 {
    font-size: 1.875rem;
}

/* text-3xl */
h2 {
    font-size: 1.5rem;
}

/* text-2xl */
h3 {
    font-size: 1.25rem;
}

/* text-xl */
h4 {
    font-size: 1.125rem;
}

/* text-lg */

p {
    font-weight: 400;
}

.text-muted {
    color: var(--text-muted);
}

.text-secondary {
    color: var(--text-secondary);
}

.text-success {
    color: var(--success);
}

.text-warning {
    color: var(--warning);
}

.text-danger {
    color: var(--danger);
}

/* ========== LOGIN PAGE ========== */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg-secondary);
    padding: 20px;
}

.login-container {
    width: 100%;
    max-width: 400px;
}

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 40px 32px;
    box-shadow: var(--shadow-sm);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo img {
    height: 48px;
    margin-bottom: 16px;
}

.login-logo h1 {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.login-logo p {
    font-size: 0.875rem;
    color: var(--text-muted);
}

/* ========== FORMS (Shadcn Input) ========== */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.form-control {
    display: flex;
    height: 2.5rem;
    width: 100%;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--bg-primary);
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: var(--text-primary);
    font-family: inherit;
    transition: all 0.15s ease;
    box-shadow: var(--shadow-sm);
}

.form-control:focus {
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: 0 0 0 2px #cbd5e1;
    /* slate-300 ring */
    border-color: #94a3b8;
}

.form-control::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

textarea.form-control {
    height: auto;
    min-height: 80px;
}

/* ========== BUTTONS (Shadcn Button) ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: inherit;
    border: none;
    height: 2.5rem;
    padding: 0 1rem;
    cursor: pointer;
    transition: all 0.15s ease;
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: var(--bg-primary);
}

.btn-primary:hover {
    background: var(--accent-hover);
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-sm {
    height: 2rem;
    padding: 0 0.75rem;
    font-size: 0.75rem;
}

.btn-block {
    width: 100%;
}

.btn-icon {
    width: 2.5rem;
    height: 2.5rem;
    padding: 0;
}

/* ========== LAYOUT ========== */
.admin-layout {
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    z-index: 100;
}

.sidebar-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-logo img {
    height: 1.5rem;
}

.sidebar-logo span {
    font-weight: 600;
    font-size: 1rem;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 1.5rem;
}

.nav-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.25rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s ease;
    margin-bottom: 0.125rem;
}

.nav-item:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-item.active {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 600;
}

.nav-item i {
    width: 1rem;
    height: 1rem;
    opacity: 0.8;
}

.nav-item .badge {
    margin-left: auto;
    background: var(--text-primary);
    color: var(--bg-primary);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.125rem 0.5rem;
    border-radius: var(--radius-full);
}

.sidebar-footer {
    padding: 1rem 0.75rem;
    border-top: 1px solid var(--border);
}

/* User Menu inside Sidebar Footer */
.user-menu {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    transition: background 0.15s ease;
}

.user-menu:hover {
    background: var(--bg-hover);
}

.user-avatar {
    width: 2rem;
    height: 2rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-primary);
}

.user-info {
    flex: 1;
}

.user-name {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
}

.user-role {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* Main Content */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    background: var(--bg-secondary);
}

.main-header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.page-title {
    font-size: 1.125rem;
    font-weight: 600;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.main-body {
    padding: 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

/* ========== CARDS (Shadcn Card) ========== */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-sm);
    margin-bottom: 1.5rem;
}

.card-header {
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.card-title {
    font-size: 1.125rem;
    font-weight: 600;
    letter-spacing: -0.025em;
}

.card-body {
    padding: 1.5rem;
}

/* ========== STATS CARDS ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    box-shadow: var(--shadow-sm);
}

.stat-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    color: var(--text-muted);
}

.stat-icon.purple {
    color: #8b5cf6;
    background: rgba(139, 92, 246, 0.1);
}

.stat-icon.green {
    color: #10b981;
    background: rgba(16, 185, 129, 0.1);
}

.stat-icon.blue {
    color: #3b82f6;
    background: rgba(59, 130, 246, 0.1);
}

.stat-icon.orange {
    color: #f59e0b;
    background: rgba(245, 158, 11, 0.1);
}

.stat-icon.red {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.stat-content {
    flex: 1;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1;
    margin-bottom: 0.25rem;
    color: var(--text-primary);
}

.stat-label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
}

/* ========== TABLES (Shadcn Table) ========== */
.table-container {
    overflow-x: auto;
    width: 100%;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

.table th,
.table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.table th {
    font-weight: 500;
    color: var(--text-muted);
    background: var(--bg-card);
}

.table tbody tr:hover {
    background: var(--bg-hover);
}

.table td {
    color: var(--text-primary);
}

/* ========== BADGES (Shadcn Badge) ========== */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.625rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: var(--radius-full);
    text-transform: capitalize;
    border: 1px solid transparent;
}

.badge-pending {
    border-color: #fcd34d;
    background: var(--warning-bg);
    color: #d97706;
}

.badge-approved,
.badge-new {
    border-color: #bfdbfe;
    background: var(--info-bg);
    color: #2563eb;
}

.badge-delivered,
.badge-completed {
    border-color: #a7f3d0;
    background: var(--success-bg);
    color: #059669;
}

.badge-rejected,
.badge-cancelled {
    border-color: #fecaca;
    background: var(--danger-bg);
    color: #dc2626;
}

.badge-contacted,
.badge-warning {
    border-color: #fcd34d;
    background: var(--warning-bg);
    color: #d97706;
}

/* General badges spanning specific classes from old logic */
.badge-admin {
    background: var(--text-primary);
    color: var(--bg-primary);
}

/* ========== ALERTS (Shadcn Alert) ========== */
.alert {
    padding: 1rem;
    border-radius: var(--radius-xl);
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid var(--border);
}

.alert-error {
    background: var(--danger-bg);
    color: #991b1b;
    border-color: #fecaca;
}

.alert-success {
    background: var(--success-bg);
    color: #065f46;
    border-color: #a7f3d0;
}

/* ========== TABS ========== */
.tabs {
    display: inline-flex;
    height: 2.5rem;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    background-color: var(--bg-tertiary);
    padding: 0.25rem;
    margin-bottom: 1.5rem;
}

.tab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
    border-radius: 0.25rem;
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
}

/* ========== KPI DASHBOARD ========== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    margin-bottom: 2rem;
}

.kpi-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 1.5rem;
    box-shadow: var(--shadow-sm);
}

.kpi-header {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.kpi-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
}

.kpi-icon {
    float: right;
    width: 2rem;
    height: 2rem;
    color: var(--text-muted);
}

/* ========== RESPONSIVE ========== */
@media (max-width: 1200px) {
    .kpi-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .charts-row {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 1024px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .main-content {
        margin-left: 0;
    }
}

@media (max-width: 640px) {
    .main-body {
        padding: 1rem;
    }

    .stats-grid,
    .kpi-grid {
        grid-template-columns: 1fr;
    }
}

/* Tooltip and generic fix */
.dashboard-card-hover {
    transition: all 0.2s ease;
}

.dashboard-card-hover:hover {
    border-color: #94a3b8;
    box-shadow: var(--shadow-md);
}