:root {
    --bg: linear-gradient(135deg, #eef2ff, #f8fafc);
    --surface: #ffffff;
    --surface2: #f8fafc;
    --text: #111827;
    --muted: #6b7280;
    --primary: #1e3a8a;
    --primary-hover: #2563eb;
    --border: #e5e7eb;
    --danger: #dc2626;
    --success: #059669;
    --shadow: 0 18px 45px rgba(15,23,42,0.12);
    --sidebar-w: 240px;
    --radius: 18px;
}

[data-theme="dark"] {
    --bg: linear-gradient(135deg, #0f172a, #1e293b);
    --surface: #1e293b;
    --surface2: #334155;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --border: #475569;
    --shadow: 0 18px 45px rgba(0,0,0,0.35);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Segoe UI', Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    transition: background .2s, color .2s;
}

.hidden { display: none !important; }
.loading-msg { color: var(--muted); }

/* RTL */
[dir="rtl"] body { text-align: right; }
[dir="rtl"] .sidebar { border-inline-end: none; border-inline-start: 1px solid var(--border); }
[dir="rtl"] .main { margin-inline-start: 0; margin-inline-end: var(--sidebar-w); }
[dir="rtl"] .nav-btn { text-align: end; }
[dir="rtl"] .topbar { flex-direction: row-reverse; }
[dir="rtl"] .topbar-start, [dir="rtl"] .topbar-actions { flex-direction: row-reverse; }
[dir="rtl"] th, [dir="rtl"] td { text-align: end; }
[dir="rtl"] .filter-row { flex-direction: row-reverse; }
[dir="rtl"] .lang-row { flex-direction: row-reverse; }
[dir="rtl"] .form-grid { direction: rtl; }
[dir="rtl"] .theme-toggle, [dir="rtl"] .theme-toggle-inline { flex-direction: row-reverse; }
[dir="rtl"] .upload-progress { flex-direction: row-reverse; }
[dir="rtl"] input[type="email"], [dir="rtl"] input[type="tel"] { direction: ltr; text-align: end; }
[dir="rtl"] .topbar-start { justify-content: flex-end; }

/* Login */
.login-wrap {
    max-width: 420px;
    margin: 60px auto;
    background: var(--surface);
    padding: 40px;
    border-radius: 24px;
    box-shadow: var(--shadow);
    text-align: center;
}
.login-logo { width: 72px; height: 72px; margin-bottom: 12px; }
.brand { color: var(--primary); font-size: 28px; font-weight: 700; margin: 0; }
.subtitle { color: var(--muted); margin: 8px 0 24px; font-size: 14px; }
.auth-links { margin-top: 16px; font-size: 14px; }
.auth-links a { color: var(--primary); text-decoration: none; }
.auth-links a:hover { text-decoration: underline; }
.user-role { color: var(--muted); font-size: 13px; font-weight: 400; }
.empty-state { text-align: center; padding: 24px 12px; color: var(--muted); }
.empty-state p { margin: 0 0 16px; }
.field-error { color: var(--danger); font-size: 13px; margin: 6px 0 12px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.actions-cell { white-space: nowrap; }
.actions-cell .btn { margin-inline-end: 6px; }
.error-card { border-inline-start: 4px solid var(--danger); background: color-mix(in srgb, var(--danger) 8%, var(--surface)); }
.success-card { border-inline-start: 4px solid var(--success); }
.analysis-report p { text-align: start; margin: 8px 0; line-height: 1.5; }
.analysis-report .analysis-title { font-size: 16px; margin-bottom: 12px; }
.analysis-report .analysis-disclaimer { margin-top: 16px; }
.survey-question { margin: 16px 0; text-align: start; }
.survey-question h4 { margin: 0 0 12px; text-align: start; }
.survey-audio-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.risk-badge { display: inline-block; padding: 4px 10px; border-radius: 8px; font-size: 13px; font-weight: 600; }
.risk-LOW { background: color-mix(in srgb, var(--success) 15%, var(--surface)); color: var(--success); }
.risk-MEDIUM { background: color-mix(in srgb, #d97706 15%, var(--surface)); color: #d97706; }
.risk-HIGH { background: color-mix(in srgb, var(--danger) 15%, var(--surface)); color: var(--danger); }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-inline-end: 1px solid var(--border);
    padding: 20px 16px;
    position: fixed;
    top: 0; bottom: 0;
    inset-inline-start: 0;
    z-index: 20;
    transition: transform .25s;
    overflow-y: auto;
}
.sidebar-logo { width: 48px; height: 48px; display: block; margin-bottom: 16px; }
.nav-btn {
    display: block; width: 100%; text-align: start;
    background: transparent; color: var(--text);
    border: none; padding: 12px 14px; border-radius: 12px;
    margin-bottom: 6px; cursor: pointer; font-size: 14px;
    transition: background .15s;
}
.nav-btn.active, .nav-btn:hover { background: var(--surface2); color: var(--primary); }
.main {
    flex: 1;
    margin-inline-start: var(--sidebar-w);
    padding: 24px;
    max-width: 1200px;
    width: 100%;
}
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 24px; flex-wrap: wrap; gap: 12px;
}
.topbar-start, .topbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    transition: background .2s, border-color .2s;
}
.card h2, .card h3 { margin-top: 0; font-size: 18px; }
.success-card { border-color: var(--success); }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
}
.stat-box {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    text-align: center;
}
.stat-box .num { font-size: 28px; font-weight: 700; color: var(--primary); }
.stat-box .lbl { font-size: 13px; color: var(--muted); }

input, select, textarea, button.btn {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text);
    font-size: 14px;
    margin-bottom: 10px;
}
[data-theme="dark"] input, [data-theme="dark"] select, [data-theme="dark"] textarea {
    background: var(--surface2);
}
button.btn-primary {
    background: var(--primary);
    color: #fff;
    border: none;
    cursor: pointer;
    font-weight: 600;
}
button.btn-primary:hover { background: var(--primary-hover); }
button.btn-danger { background: var(--danger); color: #fff; border: none; }
button.btn-sm { width: auto; padding: 8px 14px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.filter-row { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.filter-row input, .filter-row select { flex: 1; min-width: 140px; margin: 0; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: start; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; }
td:last-child { white-space: normal; }

.badge {
    display: inline-block; padding: 4px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600; background: var(--surface2);
}
.lang-btn, .icon-btn {
    width: auto; padding: 8px 12px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--surface);
    cursor: pointer; color: var(--text);
}
.lang-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.lang-row { display: flex; gap: 8px; flex-wrap: wrap; }
.lang-row-center { justify-content: center; margin-top: 16px; }

.theme-toggle, .theme-toggle-inline {
    display: flex; align-items: center; gap: 10px; cursor: pointer; margin-top: 20px;
}
.theme-toggle-inline { margin-top: 0; }
.theme-toggle input, .theme-toggle-inline input { width: auto; margin: 0; }

.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 20px; }
.chart-box { height: 280px; position: relative; }
.chart-box canvas { max-height: 220px; }

/* Upload */
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 32px 20px;
    text-align: center;
    cursor: pointer;
    margin: 12px 0;
    transition: border-color .2s, background .2s;
}
.drop-zone:hover, .drop-zone.drag-over {
    border-color: var(--primary);
    background: var(--surface2);
}
.selected-file { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.upload-progress {
    display: flex; align-items: center; gap: 12px;
    margin: 12px 0; color: var(--muted);
}
.spinner {
    width: 20px; height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.menu-toggle { display: none; }

@media (max-width: 900px) {
    .form-grid, .chart-row { grid-template-columns: 1fr; }
    .form-grid .full { grid-column: 1; }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(calc(-100% - 8px));
        box-shadow: var(--shadow);
    }
    [dir="rtl"] .sidebar { transform: translateX(calc(100% + 8px)); }
    .sidebar.open { transform: translateX(0); }
    .main, [dir="rtl"] .main { margin-inline-start: 0; margin-inline-end: 0; padding: 16px; }
    .menu-toggle { display: inline-block; }
    .topbar-actions .lang-btn { padding: 6px 8px; font-size: 12px; }
    .login-wrap { margin: 24px 16px; padding: 28px 20px; }
    .card { padding: 16px; }
    th, td { padding: 8px; font-size: 13px; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .topbar-actions { width: 100%; justify-content: flex-end; }
}
