/* ===================== Design tokens ===================== */
:root {
    color-scheme: dark;
    --bg: #0a0e17;
    --bg-elevated: #10151f;
    --card: #141a26;
    --card-hover: #1a2130;
    --border: #232b3d;
    --text: #e6e9f0;
    --text-muted: #8a93a8;
    --accent: #6366f1;
    --accent-2: #22d3ee;
    --accent-grad: linear-gradient(135deg, #6366f1 0%, #8b5cf6 50%, #22d3ee 100%);
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #f43f5e;
    --info: #38bdf8;
    --sidebar-w: 264px;
    --radius: 14px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, Arial, sans-serif;
    letter-spacing: 0.1px;
}

h1, h2, h3, h4, h5, h6, .stat-value, .brand-text, .topbar-title {
    font-weight: 700;
}

a { text-decoration: none; }

::selection { background: var(--accent); color: #fff; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ===================== App shell ===================== */
.app { display: flex; min-height: 100vh; }
[dir="rtl"] .app { flex-direction: row-reverse; }

.app-sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--bg-elevated);
    border-inline-end: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 1040;
    transition: transform 0.3s ease;
}

.app-main {
    flex: 1;
    min-width: 0;
    margin-inline-start: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 1.35rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand .logo-badge {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--accent-grad);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.12);
}

.sidebar-brand .brand-text {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: 0.2px;
}

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 0.85rem;
}

.sidebar-nav .nav-section-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    padding: 0.6rem 0.75rem 0.4rem;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 0.85rem;
    border-radius: 10px;
    color: var(--text-muted);
    font-weight: 500;
    margin-bottom: 2px;
    position: relative;
    transition: background 0.2s ease, color 0.2s ease, transform 0.15s ease;
}

.sidebar-link i { font-size: 1.1rem; width: 1.3rem; text-align: center; }

.sidebar-link:hover {
    background: rgba(99, 102, 241, 0.1);
    color: var(--text);
    transform: translateX(2px);
}
[dir="rtl"] .sidebar-link:hover { transform: translateX(-2px); }

.sidebar-link.active {
    background: rgba(99, 102, 241, 0.16);
    color: #fff;
}

.sidebar-link.active::before {
    content: '';
    position: absolute;
    inset-inline-start: -0.85rem;
    top: 10%;
    height: 80%;
    width: 3px;
    border-radius: 4px;
    background: var(--accent-grad);
}

.sidebar-footer {
    border-top: 1px solid var(--border);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.avatar-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent-grad);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.sidebar-footer .user-name {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer .logout-btn {
    margin-inline-start: auto;
    color: var(--text-muted);
    font-size: 1.15rem;
    transition: color 0.2s ease;
}
.sidebar-footer .logout-btn:hover { color: var(--danger); }

/* ===================== Topbar ===================== */
.app-topbar {
    position: sticky;
    top: 0;
    z-index: 1020;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.9rem 1.5rem;
    background: rgba(10, 14, 23, 0.75);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    position: relative;
}

.app-topbar::after {
    content: '';
    position: absolute;
    inset-inline: 0;
    bottom: -1px;
    height: 1px;
    background: var(--accent-grad);
    opacity: 0.5;
}

.sidebar-toggle-btn {
    display: none;
    background: var(--card);
    border: 1px solid var(--border);
    color: var(--text);
    width: 38px;
    height: 38px;
    border-radius: 10px;
    align-items: center;
    justify-content: center;
}

.topbar-title {
    font-weight: 700;
    font-size: 1.1rem;
}

.lang-switch {
    margin-inline-start: auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.lang-switch a {
    color: var(--text-muted);
    border: 1px solid var(--border);
    padding: 0.35rem 0.85rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
}

.lang-switch a:hover {
    color: #fff;
    border-color: var(--accent);
    background: rgba(99, 102, 241, 0.12);
}

.app-content {
    padding: 1.5rem;
    flex: 1;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 1030;
}

/* ===================== Components ===================== */
.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    color: var(--text);
    position: relative;
    transition: border-color 0.2s ease;
}

.card:hover { border-color: rgba(99, 102, 241, 0.35); }

.card::before {
    content: '';
    position: absolute;
    inset-inline: 1px;
    top: 1px;
    height: 2px;
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--accent-grad);
    opacity: 0;
    transition: opacity 0.2s ease;
}
.card:hover::before { opacity: 0.9; }

.table {
    color: var(--text);
    --bs-table-bg: transparent;
    --bs-table-color: var(--text);
    --bs-table-striped-color: var(--text);
    --bs-table-hover-color: var(--text);
    --bs-table-hover-bg: rgba(99, 102, 241, 0.08);
    --bs-table-border-color: var(--border);
    vertical-align: middle;
}

.table thead.table-light th,
.table > :not(caption) > * > th {
    background: var(--bg-elevated) !important;
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-color: var(--border) !important;
    box-shadow: none;
}

.table a { color: var(--text); font-weight: 600; }
.table a:hover { color: var(--accent-2); }

.form-control, .form-select {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text);
}
.form-control:focus, .form-select:focus {
    background: var(--bg-elevated);
    color: var(--text);
    border-color: var(--accent);
    box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.2);
}
.form-control::placeholder { color: var(--text-muted); }
.form-label { color: var(--text-muted); font-weight: 600; font-size: 0.85rem; }
.form-check-input { background-color: var(--bg-elevated); border-color: var(--border); }
.form-check-input:checked { background-color: var(--accent); border-color: var(--accent); }
.form-text { color: var(--text-muted); }

.btn-primary {
    background: var(--accent-grad);
    border: none;
    font-weight: 600;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.35);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(99, 102, 241, 0.45); }

.btn-outline-secondary, .btn-outline-primary, .btn-outline-danger, .btn-outline-success {
    color: var(--text);
    border-color: var(--border);
}
.btn-outline-secondary:hover, .btn-outline-primary:hover { background: var(--card-hover); color: #fff; }

.badge { font-weight: 600; letter-spacing: 0.02em; padding: 0.4em 0.75em; border-radius: 8px; }

.badge-tag {
    display: inline-flex;
    align-items: center;
    font-weight: 600;
    font-size: 0.78rem;
    letter-spacing: 0.02em;
    padding: 0.35em 0.75em;
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.14);
    color: #c7d2fe;
    border: 1px solid rgba(99, 102, 241, 0.3);
    margin-inline-end: 0.35rem;
    margin-bottom: 0.25rem;
}
.badge.bg-primary { animation: none; }
.badge.bg-danger { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.5); animation: pulse-danger 2s infinite; }

.badge.bg-waiting {
    background: linear-gradient(135deg, #8b5cf6, #d946ef) !important;
    color: #fff;
    box-shadow: 0 0 0 0 rgba(217, 70, 239, 0.5);
    animation: pulse-waiting 2s infinite;
}

@keyframes pulse-waiting {
    0% { box-shadow: 0 0 0 0 rgba(217, 70, 239, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(217, 70, 239, 0); }
    100% { box-shadow: 0 0 0 0 rgba(217, 70, 239, 0); }
}

@keyframes pulse-danger {
    0% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.4); }
    70% { box-shadow: 0 0 0 6px rgba(244, 63, 94, 0); }
    100% { box-shadow: 0 0 0 0 rgba(244, 63, 94, 0); }
}

.alert {
    border: 1px solid var(--border);
    background: var(--card);
    color: var(--text);
    border-radius: 12px;
}
.alert-success { border-color: rgba(34, 197, 94, 0.4); }
.alert-danger { border-color: rgba(244, 63, 94, 0.4); }
.alert-warning { border-color: rgba(245, 158, 11, 0.4); }
.alert-info { border-color: rgba(56, 189, 248, 0.4); }

.list-group-item {
    background: var(--card);
    border-color: var(--border);
    color: var(--text);
}

/* ===================== Stat cards ===================== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
    transition: transform 0.2s ease, border-color 0.2s ease;
}
.stat-card:hover { transform: translateY(-3px); border-color: rgba(99, 102, 241, 0.4); }

.stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    color: #fff;
    flex-shrink: 0;
}
.stat-icon.grad-1 { background: linear-gradient(135deg, #6366f1, #8b5cf6); box-shadow: 0 6px 16px rgba(99, 102, 241, 0.35); }
.stat-icon.grad-2 { background: linear-gradient(135deg, #22d3ee, #0ea5e9); box-shadow: 0 6px 16px rgba(34, 211, 238, 0.3); }
.stat-icon.grad-3 { background: linear-gradient(135deg, #f59e0b, #f97316); box-shadow: 0 6px 16px rgba(245, 158, 11, 0.3); }
.stat-icon.grad-4 { background: linear-gradient(135deg, #f43f5e, #ec4899); box-shadow: 0 6px 16px rgba(244, 63, 94, 0.3); }

.stat-value { font-size: 1.6rem; font-weight: 800; line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); margin-top: 0.25rem; }

/* ===================== Login page ===================== */
.auth-wrapper {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.18), transparent 45%),
                radial-gradient(circle at 80% 80%, rgba(34, 211, 238, 0.15), transparent 45%),
                var(--bg);
}

/* ===================== Animations ===================== */
@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(14px); }
    to { opacity: 1; transform: translateY(0); }
}

.fade-in-up {
    animation: fadeInUp 0.5s ease both;
}

.app-content > * { animation: fadeInUp 0.45s ease both; }
.app-content > *:nth-child(2) { animation-delay: 0.05s; }
.app-content > *:nth-child(3) { animation-delay: 0.1s; }
.app-content > *:nth-child(4) { animation-delay: 0.15s; }

/* ===================== Responsive ===================== */
@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-105%);
    }
    [dir="rtl"] .app-sidebar { transform: translateX(105%); }
    .app-sidebar.open { transform: translateX(0); }

    .app-main { margin-inline-start: 0; }
    .sidebar-toggle-btn { display: inline-flex; }
    .sidebar-overlay.show { display: block; }
    .app-content { padding: 1rem; }
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
}

@media (max-width: 575.98px) {
    .app-content { padding: 0.75rem; }
    .card-body { padding: 1rem; }
}
