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

:root {
    --bg-body: #f4f6fb;
    --bg-sidebar: #111827;
    --bg-sidebar-hover: #1f2937;
    --bg-card: #ffffff;
    --bg-input: #f9fafb;
    --accent: #6366f1;
    --accent-dark: #4f46e5;
    --accent-soft: #eef2ff;
    --success: #10b981;
    --success-soft: #ecfdf5;
    --warning: #f59e0b;
    --warning-soft: #fffbeb;
    --danger: #ef4444;
    --danger-soft: #fef2f2;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --border: #e5e7eb;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow-md: 0 4px 16px rgba(17,24,39,.08);
    --radius: 12px;
    --sidebar-width: 260px;
}

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

html, body {
    height: 100%;
    overflow: hidden;
}

body.login-page,
body.public-page {
    overflow: auto;
    height: auto;
    min-height: 100%;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.icon { width: 20px; height: 20px; flex-shrink: 0; }

/* Login */
.login-page {
    position: relative;
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #0b1026;
    padding: 24px;
    overflow: hidden;
}

.login-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
    background: linear-gradient(135deg, #0b1026 0%, #1e1b4b 35%, #312e81 65%, #4338ca 100%);
    background-size: 400% 400%;
    animation: loginGradientShift 18s ease infinite;
}

.login-grid {
    position: absolute;
    inset: 0;
    background-image:
        linear-gradient(rgba(255,255,255,.04) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,.04) 1px, transparent 1px);
    background-size: 48px 48px;
    mask-image: radial-gradient(ellipse at center, #000 30%, transparent 75%);
    animation: loginGridDrift 24s linear infinite;
}

.login-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(60px);
    opacity: .45;
    animation: loginOrbFloat 14s ease-in-out infinite;
}

.login-orb-1 { width: 320px; height: 320px; background: #6366f1; top: -80px; left: -60px; animation-delay: 0s; }
.login-orb-2 { width: 280px; height: 280px; background: #8b5cf6; bottom: -60px; right: -40px; animation-delay: -4s; }
.login-orb-3 { width: 200px; height: 200px; background: #22d3ee; top: 40%; right: 15%; animation-delay: -8s; opacity: .25; }
.login-orb-4 { width: 160px; height: 160px; background: #f59e0b; bottom: 20%; left: 12%; animation-delay: -2s; opacity: .2; }

.login-particle {
    position: absolute;
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: rgba(255,255,255,.55);
    left: calc((var(--i) * 5.5%) + 2%);
    top: calc((var(--i) * 7%) + 5%);
    animation: loginParticle  calc(8s + (var(--i) * 0.4s)) ease-in-out infinite;
    animation-delay: calc(var(--i) * -0.6s);
    box-shadow: 0 0 8px rgba(255,255,255,.35);
}

@keyframes loginGradientShift {
    0%, 100% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
}

@keyframes loginGridDrift {
    0% { transform: translateY(0); }
    100% { transform: translateY(48px); }
}

@keyframes loginOrbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    33% { transform: translate(30px, -20px) scale(1.05); }
    66% { transform: translate(-20px, 25px) scale(0.95); }
}

@keyframes loginParticle {
    0%, 100% { transform: translateY(0) scale(1); opacity: .2; }
    50% { transform: translateY(-40px) scale(1.4); opacity: .9; }
}

.login-container { position: relative; z-index: 1; width: 100%; max-width: 420px; }

.login-card {
    background: rgba(255,255,255,.97);
    backdrop-filter: blur(12px);
    border-radius: 16px;
    padding: 40px 36px;
    box-shadow: 0 20px 60px rgba(0,0,0,.35);
    border: 1px solid rgba(255,255,255,.15);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 32px;
}

.login-brand-icon {
    width: 48px; height: 48px;
    background: var(--accent-soft);
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    color: var(--accent);
}

.login-brand h1 { font-size: 22px; font-weight: 700; }
.login-brand p { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

.login-note {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 24px;
}

/* Layout */
.admin-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 100;
    height: 100vh;
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}

.brand-logo {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    object-fit: cover;
    flex-shrink: 0;
}

.sidebar-brand strong { display: block; font-size: 15px; font-weight: 700; color: #fff; }
.sidebar-brand small { font-size: 11px; color: #9ca3af; }

.sidebar-nav {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    direction: rtl;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.22) transparent;
}

.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.22);
    border-radius: 999px;
}

.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.35);
}

.sidebar-nav-inner {
    direction: ltr;
    padding: 16px 12px;
}

.sidebar-footer {
    flex-shrink: 0;
    padding: 12px;
    border-top: 1px solid rgba(255,255,255,.08);
    background: var(--bg-sidebar);
    margin-top: auto;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 8px;
    color: #9ca3af;
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    transition: all .15s;
    margin-bottom: 2px;
    border: none;
    background: none;
    width: 100%;
    cursor: pointer;
    font-family: inherit;
}

.nav-item:hover { background: var(--bg-sidebar-hover); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }

.sidebar-nav-divider {
    height: 1px;
    background: rgba(255,255,255,.08);
    margin: 12px 4px;
}

.sidebar-user-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px 12px;
    color: #fff;
}

.sidebar-user-chip strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
}

.sidebar-user-chip small {
    display: block;
    font-size: 11px;
    color: #9ca3af;
}

.nav-item-logout:hover {
    background: rgba(239, 68, 68, .15);
    color: #fca5a5;
}

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    height: 100vh;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
}

.top-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 32px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.top-header h1 { font-size: 20px; font-weight: 700; color: var(--text-primary); }

.header-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.header-profile-btn,
.header-logout-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}

.header-logout-form { margin: 0; }

.header-logout-btn { color: var(--danger); border-color: #fecaca; }
.header-logout-btn:hover { background: var(--danger-soft); color: #991b1b; }

.btn-sm {
    padding: 8px 14px;
    font-size: 13px;
}

.admin-badge {
    display: flex; align-items: center; gap: 8px;
    padding: 6px 12px;
    background: var(--bg-body);
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-secondary);
}

.admin-badge-dot {
    width: 8px; height: 8px;
    background: var(--success);
    border-radius: 50%;
}

.admin-badge-link {
    text-decoration: none;
    transition: background .15s;
}
.admin-badge-link:hover { background: var(--accent-soft); color: var(--accent); }

.user-avatar {
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
    display: inline-block;
}
.user-avatar-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    font-weight: 700;
    border-radius: 50%;
}

.page-content {
    padding: 28px 32px;
    flex: 1;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 24px;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    box-shadow: var(--shadow-sm);
    transition: box-shadow .15s;
}

.stat-card:hover { box-shadow: var(--shadow-md); }

.stat-icon-wrap {
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}

.stat-icon-wrap.purple { background: var(--accent-soft); color: var(--accent); }
.stat-icon-wrap.green  { background: var(--success-soft); color: var(--success); }
.stat-icon-wrap.amber  { background: var(--warning-soft); color: var(--warning); }
.stat-icon-wrap.blue   { background: #eff6ff; color: #3b82f6; }

.stat-value { display: block; font-size: 26px; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 13px; color: var(--text-secondary); margin-top: 2px; }

/* Cards */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    border-bottom: 1px solid var(--border);
}

.card-header h3 { font-size: 15px; font-weight: 600; }
.card-body { padding: 24px; }
.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.charts-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}

.chart-card .card-body { padding-top: 8px; }

.chart-wrap {
    position: relative;
    height: 240px;
}

.chart-wrap-donut {
    height: 260px;
    max-width: 280px;
    margin: 0 auto;
}

/* Forms */
.form-group { margin-bottom: 18px; }
.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

input[type=text], input[type=email], input[type=password],
input[type=number], input[type=url], input[type=search],
select, textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99,102,241,.12);
    background: #fff;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; gap: 12px; margin-top: 8px; padding-top: 8px; }

.toggle-group { display: flex; align-items: center; justify-content: space-between; }
.toggle { position: relative; display: inline-block; width: 44px; height: 24px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; cursor: pointer; inset: 0;
    background: #d1d5db; border-radius: 24px; transition: .2s;
}
.toggle-slider:before {
    content: ''; position: absolute; height: 18px; width: 18px;
    left: 3px; bottom: 3px; background: #fff; border-radius: 50%;
    transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider:before { transform: translateX(20px); }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 9px 18px; border: none; border-radius: 8px;
    font-size: 14px; font-weight: 500; cursor: pointer;
    transition: all .15s; text-decoration: none; font-family: inherit;
    line-height: 1.4;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-outline { background: #fff; color: var(--text-primary); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg-body); border-color: #d1d5db; }
.btn-danger { background: var(--danger-soft); color: var(--danger); border: 1px solid #fecaca; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }

/* Table */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
    text-align: left; padding: 11px 16px;
    color: var(--text-secondary); font-weight: 600;
    border-bottom: 1px solid var(--border);
    font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
    background: var(--bg-body);
}
.data-table td { padding: 14px 16px; border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: #fafafa; }
.text-center { text-align: center; }

/* Quiz question cards */
.questions-list { display: flex; flex-direction: column; gap: 16px; }

.question-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.question-card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 16px 20px;
    background: var(--bg-body);
    border-bottom: 1px solid var(--border);
    gap: 12px;
}

.question-id {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    background: var(--accent-soft);
    padding: 3px 8px;
    border-radius: 4px;
    font-family: monospace;
}

.question-text { font-size: 14px; font-weight: 500; margin-top: 6px; }
.question-text-ar { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

.question-card-body { padding: 16px 20px; }

.options-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.option-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    background: var(--bg-input);
}

.option-item.correct {
    background: var(--success-soft);
    border-color: #6ee7b7;
    color: #065f46;
    font-weight: 500;
}

.option-index {
    width: 22px; height: 22px;
    border-radius: 50%;
    background: var(--border);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px; font-weight: 700;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.option-item.correct .option-index {
    background: var(--success);
    color: #fff;
}

.option-lang { display: block; }
.option-lang-ar { display: block; font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.question-actions { display: flex; gap: 8px; flex-shrink: 0; }

.edit-panel {
    padding: 20px;
    border-top: 1px solid var(--border);
    background: #fafafa;
}

/* Toolbar */
.toolbar {
    display: flex; gap: 12px; align-items: center;
    margin-bottom: 20px; flex-wrap: wrap;
}

/* Badge & status */
.badge {
    display: inline-flex; align-items: center;
    padding: 3px 10px;
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 20px;
    font-size: 12px; font-weight: 600;
}

.status-badge {
    padding: 4px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 600;
}
.status-active  { background: var(--success-soft); color: #065f46; }
.status-waiting { background: var(--warning-soft); color: #92400e; }
.status-finished{ background: #f3f4f6; color: var(--text-secondary); }

/* Alerts */
.alert {
    padding: 12px 16px; border-radius: 8px;
    font-size: 14px; margin-bottom: 20px;
    display: flex; align-items: center; gap: 10px;
}
.alert-success { background: var(--success-soft); color: #065f46; border: 1px solid #6ee7b7; }
.alert-info    { background: var(--accent-soft); color: #3730a3; border: 1px solid #c7d2fe; }
.alert-error   { background: var(--danger-soft); color: #991b1b; border: 1px solid #fecaca; }

.hidden { display: none !important; }

/* Info rows */
.info-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 0; border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.info-row:last-child { border-bottom: none; }
.info-row label { color: var(--text-secondary); font-size: 13px; }
.info-row code {
    font-size: 12px; background: var(--bg-body);
    padding: 4px 10px; border-radius: 6px;
    color: var(--accent); border: 1px solid var(--border);
}

.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; }

.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}
.empty-state .icon { width: 48px; height: 48px; margin: 0 auto 16px; color: var(--text-muted); }

/* Pagination */
.pagination { display: flex; gap: 6px; margin-top: 20px; justify-content: center; }
.pagination a, .pagination span {
    padding: 6px 12px; border-radius: 6px; font-size: 13px;
    border: 1px solid var(--border); text-decoration: none; color: var(--text-primary);
}
.pagination .active { background: var(--accent); color: #fff; border-color: var(--accent); }

@media (max-width: 1100px) {
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .charts-grid { grid-template-columns: 1fr; }
    .card-grid, .options-grid, .form-row { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    html, body { overflow: auto; }
    .admin-layout { height: auto; min-height: 100vh; overflow: visible; }
    .sidebar { transform: translateX(-100%); height: 100vh; }
    .main-content { margin-left: 0; height: auto; min-height: 100vh; overflow: visible; }
    .stats-grid { grid-template-columns: 1fr; }
    .page-content { padding: 16px; }
}

/* Public / legal pages */
.public-page { min-height: 100vh; display: flex; flex-direction: column; background: var(--bg-body); }
.public-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 32px; background: #fff; border-bottom: 1px solid var(--border);
}
.public-brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text-primary); font-weight: 700; }
.public-nav { display: flex; gap: 20px; }
.public-nav a { text-decoration: none; color: var(--text-secondary); font-size: 14px; font-weight: 500; }
.public-nav a:hover { color: var(--accent); }
.public-content { flex: 1; padding: 40px 24px; max-width: 860px; margin: 0 auto; width: 100%; }
.public-footer { text-align: center; padding: 24px; font-size: 13px; color: var(--text-muted); border-top: 1px solid var(--border); background: #fff; }
.public-footer a { color: var(--accent); text-decoration: none; }
.legal-page h1 { font-size: 28px; margin-bottom: 8px; }
.legal-meta { color: var(--text-secondary); font-size: 14px; margin-bottom: 32px; }
.legal-section { margin-bottom: 24px; }
.legal-section h2 { font-size: 18px; margin-bottom: 8px; color: var(--text-primary); }
.legal-section p { color: var(--text-secondary); line-height: 1.7; }
.legal-divider { border: none; border-top: 2px solid var(--border); margin: 48px 0; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
