:root {
  --bg: #F5F6FA;
  --surface: #FFFFFF;
  --surface-2: #EEF0F6;
  --ink: #1B2230;
  --ink-muted: #5B6472;
  --ink-faint: #8A93A3;
  --border: #E2E5EC;
  --accent: #4A55D9;
  --accent-ink: #FFFFFF;
  --accent-soft: #E8E9FB;
  --accent-soft-ink: #3A44B8;
  --success: #1E9E6B;
  --success-soft: #E3F6EC;
  --warning: #C97F0A;
  --warning-soft: #FBF0DD;
  --critical: #D64545;
  --critical-soft: #FBE7E7;
  --radius-s: 8px;
  --radius-m: 12px;
  --radius-l: 18px;
  --shadow-1: 0 1px 2px rgba(20,24,40,0.07), 0 1px 1px rgba(20,24,40,0.04);
  --shadow-2: 0 10px 28px rgba(20,24,40,0.12);
  --font-body: "SF Arabic", "Dubai", "Segoe UI", Tahoma, "Noto Sans Arabic", system-ui, -apple-system, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg:#12141C; --surface:#1A1D27; --surface-2:#20232F; --ink:#EDEFF4; --ink-muted:#9AA2B4; --ink-faint:#6E7688; --border:#2B2F3D;
    --accent:#8489FF; --accent-ink:#12141C; --accent-soft:#262B47; --accent-soft-ink:#B7BBFF;
    --success:#34C98A; --success-soft:#16332A; --warning:#E2A03D; --warning-soft:#332711; --critical:#F16565; --critical-soft:#3A1E20;
    --shadow-1: 0 1px 2px rgba(0,0,0,0.4); --shadow-2: 0 10px 28px rgba(0,0,0,0.55);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button, input { font-family: inherit; }
::selection { background: var(--accent-soft); color: var(--accent-soft-ink); }

.app-root { min-height: 100vh; display: flex; flex-direction: column; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 30; flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 28px; height: 28px; flex-shrink: 0; }
.brand-mark img { display: block; width: 100%; height: 100%; }
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-name { font-size: 19px; font-weight: 800; letter-spacing: 0.2px; }
.brand-tagline { font-size: 11.5px; color: var(--ink-muted); }

.user-chip { display: flex; align-items: center; gap: 12px; }
.lang-switch { display: flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.lang-switch a { padding: 5px 10px; font-size: 11px; font-weight: 700; color: var(--ink-muted); }
.lang-switch a.active { background: var(--accent); color: var(--accent-ink); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-soft-ink); display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 12.5px; flex-shrink: 0; }
.avatar-img { object-fit: cover; }
.user-link { display: flex; align-items: center; gap: 10px; }
.user-link:hover .user-name { color: var(--accent); }
.user-meta { display: flex; flex-direction: column; line-height: 1.25; }
.user-name { font-size: 13px; font-weight: 700; }
.user-role { font-size: 11px; color: var(--ink-muted); }
.logout-btn { border: 1px solid var(--border); background: var(--surface); color: var(--ink-muted); padding: 7px 14px; border-radius: 10px; font-size: 12.5px; font-weight: 700; cursor: pointer; }
.logout-btn:hover { color: var(--critical); border-color: var(--critical-soft); }

.shell { flex: 1; display: flex; min-height: 0; }
.sidebar { width: 300px; flex-shrink: 0; border-inline-start: 1px solid var(--border); background: var(--surface); display: flex; flex-direction: column; }
.sidebar-head { padding: 14px 14px 6px; }
.sidebar-title { font-size: 12.5px; font-weight: 700; color: var(--ink-muted); }
.sidebar-cta { padding: 4px 14px 12px; }
.sidebar-search { padding: 8px 14px 10px; display: flex; gap: 6px; }
.sidebar-search input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--ink); font-size: 13px; }
.search-btn { border: 1px solid var(--border); background: var(--surface-2); color: var(--ink-muted); padding: 0 12px; border-radius: 10px; font-size: 12px; font-weight: 700; cursor: pointer; }
.stage-filters { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 14px 12px; border-bottom: 1px solid var(--border); }
.chip { border: 1px solid var(--border); background: var(--surface); padding: 5px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; color: var(--ink-muted); cursor: pointer; display: inline-block; }
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

.case-list { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 3px; }
.case-item { display: flex; flex-direction: column; gap: 6px; padding: 10px 12px; border-radius: 12px; cursor: pointer; border: 1px solid transparent; background: transparent; text-align: start; width: 100%; }
.case-item:hover { background: var(--surface-2); }
.case-item.active { background: var(--accent-soft); border-color: var(--accent); }
.case-item-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.case-name { font-size: 13.5px; font-weight: 700; color: var(--ink); }
.case-updated { font-size: 10.5px; color: var(--ink-faint); white-space: nowrap; }
.stage-pill { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 999px; width: fit-content; }
.stage-pill.neutral { background: var(--surface-2); color: var(--ink-muted); }
.stage-pill.warning { background: var(--warning-soft); color: var(--warning); }
.stage-pill.accent { background: var(--accent-soft); color: var(--accent-soft-ink); }
.stage-pill.success { background: var(--success-soft); color: var(--success); }
.empty-list-note { padding: 24px 16px; text-align: center; color: var(--ink-faint); font-size: 12.5px; }

.content { flex: 1; min-width: 0; overflow-y: auto; padding: 28px 32px 60px; }
.content-inner { max-width: 920px; }

.kpi-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 30px; }
.kpi-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); padding: 16px 18px; cursor: pointer; display: flex; flex-direction: column; gap: 6px; box-shadow: var(--shadow-1); text-align: start; }
.kpi-card:hover { border-color: var(--accent); }
.kpi-value { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.kpi-label { font-size: 12px; color: var(--ink-muted); font-weight: 600; }

.section-title { font-size: 15px; font-weight: 800; margin: 0 0 14px; }

.patient-list { display: flex; flex-direction: column; gap: 8px; }
.patient-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-m); background: var(--surface); box-shadow: var(--shadow-1); flex-wrap: wrap; }
.patient-row:hover { border-color: var(--accent); }
.patient-row-main { display: flex; flex-direction: column; gap: 3px; }
.patient-row-name { font-size: 14px; font-weight: 700; }
.patient-row-meta { font-size: 12px; color: var(--ink-muted); font-variant-numeric: tabular-nums; }
.patient-row-side { display: flex; align-items: center; gap: 12px; }
.patient-row-updated { font-size: 11.5px; color: var(--ink-faint); white-space: nowrap; }
.empty-state { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 70px 20px; color: var(--ink-muted); text-align: center; border: 1px dashed var(--border); border-radius: var(--radius-l); }
.empty-state-icon { font-size: 34px; }

.back-link { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 700; color: var(--ink-muted); margin-bottom: 16px; }
.back-link:hover { color: var(--accent); }

.case-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 24px; flex-wrap: wrap; }
.case-header h1 { font-size: 22px; margin: 0 0 6px; font-weight: 800; text-wrap: balance; }
.case-sub { font-size: 12.5px; color: var(--ink-muted); display: flex; gap: 14px; flex-wrap: wrap; }
.case-sub b { color: var(--ink); font-weight: 700; }

.stepper-wrap { overflow-x: auto; padding-bottom: 8px; margin-bottom: 28px; }
.stepper { display: flex; align-items: flex-start; min-width: 760px; }
.step { display: flex; flex-direction: column; align-items: center; gap: 8px; width: 96px; flex-shrink: 0; }
.step-circle { width: 34px; height: 34px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 800; border: 2px solid var(--border); background: var(--surface); color: var(--ink-faint); }
.step.completed .step-circle { background: var(--success); border-color: var(--success); color: #fff; }
.step.current .step-circle { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); box-shadow: 0 0 0 4px var(--accent-soft); }
.step-label { font-size: 11px; text-align: center; color: var(--ink-faint); font-weight: 600; }
.step.current .step-label, .step.completed .step-label { color: var(--ink); }
.connector { flex: 1 1 24px; height: 2px; background: var(--border); margin-top: 17px; min-width: 16px; }
.connector.completed { background: var(--success); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 22px; overflow-x: auto; }
.tab-btn { padding: 10px 4px; margin-inline-end: 20px; font-size: 13.5px; font-weight: 700; color: var(--ink-muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; display: inline-block; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-m); padding: 18px; box-shadow: var(--shadow-1); }
.card h3 { margin: 0 0 8px; font-size: 13.5px; font-weight: 700; }
.card p { margin: 0; font-size: 13px; color: var(--ink-muted); }
.card .big { font-size: 22px; font-weight: 800; font-variant-numeric: tabular-nums; margin-bottom: 2px; }
.card-full { grid-column: 1 / -1; }

.stage-action-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 14px; flex-wrap: wrap; }
.btn { border: 0; background: var(--accent); color: var(--accent-ink); padding: 10px 18px; border-radius: 10px; font-size: 13px; font-weight: 700; cursor: pointer; }
.btn:hover { filter: brightness(1.06); }
.btn.secondary { background: var(--accent-soft); color: var(--accent-soft-ink); }
.btn.btn-block { display: block; width: 100%; text-align: center; text-decoration: none; box-sizing: border-box; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.waiting-note { font-size: 12.5px; color: var(--ink-faint); }

.progress-row { display: flex; align-items: center; gap: 12px; margin-top: 6px; }
.progress-track { flex: 1; height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.progress-fill { height: 100%; background: var(--accent); border-radius: 999px; }
.progress-text { font-size: 12px; font-weight: 700; color: var(--ink-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 14px; }
.photo-card { border-radius: var(--radius-m); overflow: hidden; border: 1px solid var(--border); background: var(--surface); }
.photo-thumb { height: 120px; display: flex; align-items: center; justify-content: center; font-size: 30px; }
.photo-thumb-img { padding: 0; overflow: hidden; background: var(--surface-2); }
.photo-thumb-img img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-meta { padding: 10px 12px; }
.photo-meta .label { font-size: 12.5px; font-weight: 700; }
.photo-meta .date { font-size: 11px; color: var(--ink-faint); }

.photo-upload-form { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--border); }
.photo-upload-form input[type="text"] { flex: 1; min-width: 180px; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--ink); font-size: 13px; }
.photo-upload-form input[type="file"] { flex: 1; min-width: 200px; font-size: 12.5px; color: var(--ink-muted); }

.chat-panel { display: flex; flex-direction: column; height: min(520px, 60vh); border: 1px solid var(--border); border-radius: var(--radius-m); background: var(--surface); overflow: hidden; }
.chat-list { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 72%; padding: 10px 14px; border-radius: 14px; font-size: 13.5px; line-height: 1.6; }
.msg .msg-text { margin: 0; }
.msg .msg-time { display: block; font-size: 10px; margin-top: 4px; opacity: .75; }
.msg.self { align-self: flex-start; background: var(--accent); color: var(--accent-ink); border-end-end-radius: 4px; }
.msg.other { align-self: flex-end; background: var(--surface-2); color: var(--ink); border-end-start-radius: 4px; }
.msg-sender { display: block; font-size: 10.5px; font-weight: 700; margin-bottom: 3px; opacity: .85; }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--border); }
.chat-form input { flex: 1; padding: 10px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--ink); font-size: 13px; }
.chat-form button { border: 0; background: var(--accent); color: var(--accent-ink); padding: 0 18px; border-radius: 10px; font-weight: 700; font-size: 13px; cursor: pointer; }

.history-list { display: flex; flex-direction: column; gap: 4px; }
.history-item { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.history-item:last-child { border-bottom: 0; }
.history-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); margin-top: 6px; flex-shrink: 0; }
.history-title { margin: 0 0 3px; font-size: 13.5px; font-weight: 700; }
.history-meta { margin: 0; font-size: 11.5px; color: var(--ink-faint); }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-l); padding: 32px 28px; box-shadow: var(--shadow-2); }
.login-brand { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 24px; text-align: center; }
.login-brand .brand-mark { width: 56px; height: 56px; }
.login-brand .brand-name { font-size: 22px; font-weight: 800; }
.login-brand .brand-tagline { font-size: 12.5px; color: var(--ink-muted); }
.field-hint { font-size: 12px; color: var(--ink-muted); margin: -6px 0 12px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--ink-muted); }
.field input, .field select, .field textarea { padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border); background: var(--bg); color: var(--ink); font-size: 14px; font-family: inherit; }
.field textarea { resize: vertical; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-submit { width: 100%; padding: 12px; border: 0; border-radius: 10px; background: var(--accent); color: var(--accent-ink); font-weight: 800; font-size: 14px; cursor: pointer; margin-top: 6px; }
.flash-error { background: var(--critical-soft); color: var(--critical); padding: 10px 14px; border-radius: 10px; font-size: 12.5px; margin-bottom: 16px; }
.flash-success { background: var(--success-soft); color: var(--success); padding: 10px 14px; border-radius: 10px; font-size: 12.5px; margin-bottom: 16px; font-weight: 600; }
.login-links { display: flex; flex-direction: column; gap: 8px; align-items: center; margin-top: 16px; }
.login-links a { font-size: 12.5px; color: var(--accent); font-weight: 600; }
.request-code { text-align: center; font-size: 34px; font-weight: 800; letter-spacing: 4px; direction: ltr; color: var(--accent); background: var(--surface-2); border-radius: var(--radius-l); padding: 18px; margin: 4px 0 20px; }

a.role-btn, button.role-btn { border: 0; background: transparent; }

*:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (max-width: 760px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; max-height: 280px; overflow-y: auto; border-inline-start: 0; border-bottom: 1px solid var(--border); }
  .sidebar .case-list { overflow-y: visible; }
  .content { padding: 20px; }
}
