:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #eef2ff;
    --secondary: #0ea5e9;
    --accent: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --dark: #0f172a;
    --dark-hover: #1e293b;
    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-xs: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,.1), 0 4px 6px rgba(0,0,0,.05);
    --transition: all .15s ease;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

/* ── Auth ── */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-light) 0%, #f0f9ff 50%, #ecfdf5 100%);
    padding: 1rem;
}

.auth-card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
}

.auth-header { text-align: center; margin-bottom: 2rem; }
.auth-header h1 { font-size: 1.5rem; margin-top: .75rem; color: var(--gray-900); }
.auth-subtitle { color: var(--gray-500); font-size: .875rem; margin-top: .25rem; }
.auth-logo { display: inline-block; }

.auth-form .form-group { margin-bottom: 1.25rem; }
.auth-form label { display: block; font-size: .875rem; font-weight: 600; color: var(--gray-700); margin-bottom: .375rem; }

.auth-hint {
    font-size: .8125rem;
    color: var(--gray-500);
    margin-bottom: 1.25rem;
    line-height: 1.5;
}
.auth-footer-links { text-align: center; margin-top: 1rem; font-size: .875rem; }
.auth-form-inline { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--gray-200); }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 260px;
    background: #fff;
    border-right: 1px solid var(--gray-200);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar-dark {
    background: var(--dark);
    border-right-color: var(--gray-800);
}
.sidebar-dark .sidebar-title,
.sidebar-dark .sidebar-nav a { color: var(--gray-300); }
.sidebar-dark .sidebar-nav li.active a,
.sidebar-dark .sidebar-nav a:hover { color: #fff; background: var(--dark-hover); }
.sidebar-dark .sidebar-footer { border-top-color: var(--gray-800); }
.sidebar-dark .sidebar-user { color: var(--gray-400); }
.sidebar-dark .sidebar-logout { color: var(--gray-500); }

.sidebar-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1.25rem 1.25rem .75rem;
}
.sidebar-title { font-weight: 700; font-size: 1.05rem; color: var(--gray-900); }

.sidebar-nav { list-style: none; padding: .5rem .75rem; flex: 1; }
.sidebar-nav li { margin-bottom: 2px; }
.sidebar-nav a {
    display: block;
    padding: .625rem 1rem;
    border-radius: var(--radius-sm);
    color: var(--gray-600);
    font-size: .9rem;
    font-weight: 500;
    transition: var(--transition);
}
.sidebar-nav a:hover { background: var(--gray-100); color: var(--gray-900); }
.sidebar-nav li.active a { background: var(--primary-light); color: var(--primary); font-weight: 600; }

.sidebar-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: .825rem;
}
.sidebar-user { color: var(--gray-600); font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 150px; }
.sidebar-logout { color: var(--gray-400); font-size: .8rem; }
.sidebar-logout:hover { color: var(--danger); }

.content { flex: 1; padding: 2rem; max-width: 1200px; }

/* ── Page ── */
.page-header { margin-bottom: 1.5rem; display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; }

/* ── Stats ── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.stats-grid-2 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    box-shadow: var(--shadow);
    border-left: 4px solid var(--gray-300);
}
.stat-card.stat-primary { border-left-color: var(--primary); }
.stat-card.stat-secondary { border-left-color: var(--secondary); }
.stat-card.stat-accent { border-left-color: var(--accent); }

.stat-label { font-size: .8rem; color: var(--gray-500); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat-value { font-size: 1.75rem; font-weight: 700; margin-top: .25rem; color: var(--gray-900); }
.stat-value-sm { font-size: 1rem; }

/* ── Card ── */
.card {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.card h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 1rem; }

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.card-header h2 { margin-bottom: 0; }

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(380px, 1fr));
    gap: 1.5rem;
}
.grid-2 .card { margin-bottom: 0; }

/* ── Table ── */
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table thead th {
    text-align: left;
    padding: .625rem .75rem;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--gray-500);
    border-bottom: 2px solid var(--gray-200);
    font-weight: 600;
}
.table tbody td {
    padding: .625rem .75rem;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--gray-50); }

.clickable-row { cursor: pointer; }
.clickable-row:hover { background: var(--primary-light) !important; }

/* ── Badges ── */
.badge {
    display: inline-block;
    padding: .2em .6em;
    font-size: .75rem;
    font-weight: 600;
    border-radius: 9999px;
    white-space: nowrap;
}
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-blue { background: #dbeafe; color: #1e40af; }

.text-green { color: #16a34a; font-weight: 600; }
.text-red { color: #dc2626; font-weight: 600; }
.text-muted { color: var(--gray-400); }

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: .625rem 1.25rem;
    font-size: .875rem;
    font-weight: 600;
    border-radius: var(--radius-sm);
    border: none;
    cursor: pointer;
    transition: var(--transition);
    gap: .375rem;
    text-decoration: none;
    line-height: 1.4;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }

.btn-dark { background: var(--dark); color: #fff; }
.btn-dark:hover { background: var(--dark-hover); color: #fff; }

.btn-outline { background: transparent; color: var(--gray-600); border: 1px solid var(--gray-300); }
.btn-outline:hover { background: var(--gray-100); color: var(--gray-900); }

.btn-secondary { background: var(--gray-100); color: var(--gray-800); border: 1px solid var(--gray-200); }
.btn-secondary:hover { background: var(--gray-200); color: var(--gray-900); }

.btn-full { width: 100%; }
.btn-sm { padding: .375rem .75rem; font-size: .8rem; }

/* ── Forms ── */
input[type="text"],
input[type="tel"],
input[type="number"],
input[type="password"],
input[type="email"],
select,
textarea {
    width: 100%;
    padding: .625rem .875rem;
    font-size: .9rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--gray-900);
    transition: var(--transition);
    outline: none;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .15);
}

.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: .8rem; font-weight: 600; color: var(--gray-600); margin-bottom: .375rem; }

.inline-form { display: flex; gap: .75rem; align-items: flex-end; flex-wrap: wrap; }
.inline-form .form-group { margin-bottom: 0; flex: 1; min-width: 150px; }

.stacked-form .form-group { margin-bottom: 1rem; }

.search-form { display: flex; gap: .75rem; }
.search-form input { flex: 1; }

.select-sm {
    width: auto;
    padding: .3rem .5rem;
    font-size: .8rem;
    border-radius: var(--radius-xs);
}
.input-sm {
    width: 140px;
    padding: .3rem .5rem;
    font-size: .8rem;
    border-radius: var(--radius-xs);
}

.action-form { display: flex; gap: .375rem; align-items: center; flex-wrap: wrap; }

/* ── Filter ── */
.filter-bar { display: flex; gap: .5rem; flex-wrap: wrap; }

/* ── Info ── */
.info-row {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
    font-size: .9rem;
    color: var(--gray-600);
}

/* ── Alerts ── */
.alert {
    padding: .875rem 1rem;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 500;
    margin-bottom: 1rem;
}
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }

/* ── Misc ── */
.empty-state { color: var(--gray-400); padding: 2rem 0; text-align: center; font-size: .9rem; }

.pagination { display: flex; align-items: center; gap: 1rem; justify-content: center; padding-top: 1rem; }
.page-info { font-size: .875rem; color: var(--gray-500); }

/* ── Responsive ── */
@media (max-width: 768px) {
    .layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: relative;
        flex-direction: row;
        align-items: center;
        border-right: none;
        border-bottom: 1px solid var(--gray-200);
        padding: .5rem;
    }
    .sidebar-header { padding: .5rem; }
    .sidebar-nav { display: flex; gap: .25rem; padding: .25rem; flex: unset; overflow-x: auto; }
    .sidebar-nav li { margin-bottom: 0; }
    .sidebar-footer { display: none; }
    .content { padding: 1rem; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .grid-2 { grid-template-columns: 1fr; }
    .inline-form { flex-direction: column; }
    .table { font-size: .8rem; }
}
