:root {
  color-scheme: light;
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --sidebar: #0b1f33;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;
  --text: #142234;
  --muted: #65758b;
  --primary: #087f8c;
  --primary-dark: #07636e;
  --primary-soft: #e8f7f7;
  --blue: #2563eb;
  --violet: #7c3aed;
  --amber: #d97706;
  --rose: #dc2626;
  --green: #15803d;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 12px rgba(15, 23, 42, .04);
  --radius: 16px;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  direction: rtl;
  font-family: Tahoma, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.65;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 4px; font-size: clamp(24px, 3vw, 34px); line-height: 1.25; letter-spacing: -.6px; }
h2 { margin-bottom: 4px; font-size: 17px; line-height: 1.45; }
p { color: var(--muted); }

.admin-shell { display: grid; grid-template-columns: 272px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 22px 16px 18px;
  overflow-y: auto;
  color: #e7f1f7;
  background: var(--sidebar);
  border-left: 1px solid rgba(255,255,255,.06);
}
.brand { display: flex; align-items: center; gap: 12px; padding: 2px 7px 22px; margin-bottom: 12px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand strong { display: block; color: #fff; font-size: 18px; }
.brand small { display: block; margin-top: 1px; color: #8ea6bb; font-size: 11px; }
.brand-mark { position: relative; flex: 0 0 44px; width: 44px; height: 44px; border-radius: 14px; background: linear-gradient(145deg, #2dd4bf, #0e7490); box-shadow: 0 12px 28px rgba(45, 212, 191, .2); }
.brand-mark i { position: absolute; inset: 20px 11px auto; height: 4px; border-radius: 5px; background: #fff; }
.brand-mark i:last-child { inset: 11px 20px auto; width: 4px; height: 22px; }
.tabs { display: grid; gap: 15px; }
.nav-group { display: grid; gap: 3px; }
.nav-group > span { padding: 0 11px 5px; color: #718aa1; font-size: 10px; font-weight: 700; letter-spacing: .5px; }
.tab { display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 8px 11px; color: #c7d5e1; border-radius: 11px; font-size: 13px; transition: background .18s ease, color .18s ease, transform .18s ease; }
.tab:hover { color: #fff; background: rgba(255,255,255,.07); transform: translateX(-2px); }
.tab.active { color: #fff; background: linear-gradient(90deg, rgba(20,184,166,.28), rgba(8,127,140,.18)); box-shadow: inset -3px 0 #2dd4bf; }
.nav-indicator { width: 7px; height: 7px; border: 1.5px solid #7890a5; border-radius: 50%; }
.tab.active .nav-indicator { border-color: #5eead4; background: #5eead4; box-shadow: 0 0 0 4px rgba(94,234,212,.1); }
.sidebar-footer { margin-top: auto; padding-top: 18px; }
.utility-link { display: block; padding: 10px 11px; color: #9eb1c2; border-top: 1px solid rgba(255,255,255,.08); }
.sidebar-footer form { margin: 8px 0 0; }
.logout-button { width: 100%; color: #fecaca; background: rgba(220,38,38,.13); box-shadow: none; }

.content { min-width: 0; padding: 28px clamp(18px, 3vw, 42px) 48px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; max-width: 1500px; margin: 0 auto 25px; }
.eyebrow { margin-bottom: 2px; color: var(--primary); font-size: 11px; font-weight: 800; letter-spacing: .4px; }
.page-date { margin-bottom: 0; font-size: 12px; }
.system-live { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; color: #166534; background: #ecfdf3; border: 1px solid #bbf7d0; border-radius: 999px; white-space: nowrap; font-size: 12px; font-weight: 700; }
.system-live span { width: 8px; height: 8px; background: #22c55e; border-radius: 50%; box-shadow: 0 0 0 4px rgba(34,197,94,.13); }

.panel, .metric, .login-card, .triage-card, .data-form, .table-scroll { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.panel { min-width: 0; padding: 21px; }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; margin-bottom: 18px; }
.panel-head p { margin: 2px 0 0; font-size: 12px; }
.demo-callout { display: flex; align-items: center; justify-content: space-between; gap: 18px; max-width: 1500px; padding: 14px 17px; margin: 0 auto 18px; color: #6b4f16; background: #fffbeb; border: 1px solid #fde68a; border-radius: 14px; }
.demo-callout strong { display: block; }
.demo-callout p { margin: 2px 0 0; color: #8a6820; font-size: 12px; }
.demo-callout.compact { margin: 14px 0; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 14px; max-width: 1500px; margin: 0 auto 18px; }
.metric-grid-six { grid-template-columns: repeat(6, minmax(150px, 1fr)); }
.metric { display: flex; align-items: center; gap: 14px; min-height: 116px; padding: 18px; overflow: hidden; }
.metric-icon { display: grid; flex: 0 0 42px; width: 42px; height: 42px; place-items: center; border-radius: 13px; background: var(--primary-soft); color: var(--primary); }
.metric-icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.metric span { display: block; color: var(--muted); font-size: 11px; }
.metric strong { display: block; margin: 1px 0; font-size: 26px; line-height: 1.2; }
.metric small { color: #8a98aa; font-size: 10px; }
.metric-blue .metric-icon { color: var(--blue); background: #eff6ff; }
.metric-teal .metric-icon { color: var(--primary); background: var(--primary-soft); }
.metric-violet .metric-icon { color: var(--violet); background: #f5f3ff; }
.metric-amber .metric-icon { color: var(--amber); background: #fffbeb; }
.metric-rose .metric-icon, .metric-emergency .metric-icon { color: var(--rose); background: #fef2f2; }
.metric-green .metric-icon { color: var(--green); background: #f0fdf4; }

.dashboard-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; max-width: 1500px; margin: auto; }
.span-2 { grid-column: 1 / -1; }
.chart-wrap { width: 100%; overflow-x: auto; }
.bar-chart { display: block; width: 100%; min-width: 620px; height: 240px; }
.chart-bar { fill: #0d9488; opacity: .88; }
.chart-bar:hover { fill: #0f766e; opacity: 1; }
.chart-axis { stroke: #d8e1ea; stroke-width: 1; }
.chart-label { fill: #748398; font-size: 9px; text-anchor: middle; }
.chart-value { fill: #344358; font-size: 9px; text-anchor: middle; font-weight: 700; }
.progress-list { display: grid; gap: 16px; }
.progress-row > div { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 7px; }
.progress-row strong { font-size: 12px; }
.progress-row span { color: var(--muted); font-size: 11px; }
.progress-row svg { display: block; width: 100%; height: 8px; }
.progress-track { fill: #eef2f6; }
.progress-fill { fill: var(--primary); }
.progress-fill.success { fill: #22a65a; }
.progress-fill.warning { fill: #e8a21a; }
.progress-fill.danger { fill: #e55252; }
.progress-fill.violet { fill: #8b5cf6; }
.activity-list, .conversation-list { display: grid; }
.activity-item { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; color: var(--text); border-bottom: 1px solid var(--line); }
.activity-item:last-child { border: 0; }
.activity-item p { max-width: 560px; margin: 1px 0 0; font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.activity-item > div:last-child { display: flex; gap: 5px; }

.status-badge { display: inline-flex; align-items: center; justify-content: center; padding: 4px 8px; color: #475569; background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 999px; white-space: nowrap; font-size: 10px; font-weight: 700; }
.status-badge.success, .status-badge.reviewed, .status-badge.resolved { color: #166534; background: #f0fdf4; border-color: #bbf7d0; }
.status-badge.demo { color: #7c5207; background: #fffbeb; border-color: #fde68a; }
.status-badge.primary, .status-badge.new, .status-badge.routine { color: #1d4ed8; background: #eff6ff; border-color: #bfdbfe; }
.status-badge.soon { color: #6d28d9; background: #f5f3ff; border-color: #ddd6fe; }
.status-badge.warning, .status-badge.urgent, .status-badge.escalated { color: #92400e; background: #fffbeb; border-color: #fde68a; }
.status-badge.danger, .status-badge.emergency { color: #b91c1c; background: #fef2f2; border-color: #fecaca; }
.badge-stack { display: flex; align-items: center; justify-content: flex-end; gap: 5px; flex-wrap: wrap; }

.content > .data-form, .content > .table-scroll { max-width: 1500px; margin: 0 auto 18px; }
.data-form { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); align-items: end; gap: 15px; padding: 21px; margin-bottom: 18px; }
.data-form > input[type="hidden"] { display: none; }
.data-form > button { justify-self: start; min-width: 120px; }
.grid { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 14px; }
.actions, .row-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
label { display: block; color: #536275; font-size: 11px; font-weight: 700; }
input, select, textarea { display: block; width: 100%; min-height: 42px; padding: 9px 11px; margin-top: 6px; color: var(--text); background: #fff; border: 1px solid var(--line-strong); border-radius: 10px; outline: none; font: inherit; font-size: 13px; transition: border-color .15s ease, box-shadow .15s ease, background .15s ease; }
textarea { min-height: 92px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: #2aa7a8; box-shadow: 0 0 0 3px rgba(42,167,168,.12); background: #fcffff; }
input[type="file"] { height: auto; padding: 7px; }
button, .button { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 9px 15px; color: #fff; background: var(--primary); border: 0; border-radius: 10px; box-shadow: 0 7px 16px rgba(8,127,140,.14); cursor: pointer; font: inherit; font-size: 12px; font-weight: 700; transition: transform .15s ease, background .15s ease, box-shadow .15s ease; }
button:hover, .button:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 9px 20px rgba(8,127,140,.2); }
.secondary { background: var(--amber); }
.danger { background: var(--rose); }
.ghost { color: var(--text); background: #eef2f6; box-shadow: none; }

.table-scroll { padding: 0; overflow: auto; }
table { width: 100%; min-width: 850px; border-collapse: separate; border-spacing: 0; background: #fff; }
th, td { padding: 13px 15px; text-align: right; vertical-align: middle; border-bottom: 1px solid var(--line); font-size: 12px; }
th { position: sticky; top: 0; z-index: 2; color: #536275; background: #f8fafc; font-size: 10px; font-weight: 800; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfdfd; }
.compact-table { border: 0; border-radius: 0; box-shadow: none; }
.compact-table table { min-width: 620px; }
.table-note { display: block; margin-top: 2px; color: var(--muted); }
.table-scroll .data-form { display: grid; grid-template-columns: 1fr; gap: 7px; min-width: 240px; padding: 0; margin: 0 0 8px; border: 0; border-radius: 0; box-shadow: none; }
.table-scroll form:not(.data-form) { display: grid; gap: 7px; min-width: 220px; margin: 7px 0; }
.table-scroll button { min-height: 34px; padding: 6px 10px; }
.avatar { width: 48px; height: 48px; object-fit: cover; border: 1px solid var(--line); border-radius: 12px; }
.empty-state { padding: 34px 18px; color: var(--muted); text-align: center; background: var(--surface-soft); border: 1px dashed var(--line-strong); border-radius: 12px; }

.triage-summary { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 14px; max-width: 1500px; margin: 0 auto 18px; }
.triage-list { display: grid; gap: 16px; max-width: 1500px; margin: auto; }
.triage-card { padding: 21px; }
.triage-card > header { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding-bottom: 15px; border-bottom: 1px solid var(--line); }
.triage-card h2 { margin: 2px 0; }
.triage-card header p { margin: 0; font-size: 11px; }
.case-id { color: var(--primary); font-size: 10px; font-weight: 800; }
.triage-details { display: grid; grid-template-columns: 1.4fr 1fr .6fr 1.4fr; gap: 10px; margin: 16px 0; }
.triage-details > div { padding: 12px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 11px; }
.triage-details span, .recommendation > span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 10px; }
.triage-details strong { font-size: 12px; font-weight: 600; }
.recommendation { padding: 14px 16px; margin-bottom: 15px; background: #f0fdfa; border-right: 3px solid #14b8a6; border-radius: 11px; }
.recommendation p { margin: 0 0 5px; color: #25434a; white-space: pre-line; }
.recommendation small { color: #5e7680; }
.review-form { display: grid; grid-template-columns: minmax(250px, 2fr) minmax(160px, .7fr) auto; align-items: end; gap: 12px; }

.search-bar { display: grid; grid-template-columns: minmax(220px, 480px) auto; gap: 8px; max-width: 1500px; margin: 0 auto 17px; }
.search-bar input { margin: 0; }
.conversation-row { display: grid; grid-template-columns: 42px minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 12px 4px; color: var(--text); border-bottom: 1px solid var(--line); }
.conversation-row:last-child { border: 0; }
.conversation-row:hover { background: #fbfdfd; }
.conversation-avatar { display: grid; width: 42px; height: 42px; place-items: center; color: #0f766e; background: #ccfbf1; border-radius: 13px; font-weight: 800; }
.conversation-row p { max-width: 650px; margin: 1px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11px; }
.conversation-row > div:last-child { display: grid; justify-items: end; color: var(--muted); font-size: 10px; }
.conversation-header { display: flex; align-items: center; justify-content: space-between; max-width: 900px; margin: 0 auto 14px; }
.conversation-header > div { display: flex; align-items: center; gap: 9px; }
.conversation-header h2 { margin: 0; }
.back-link { display: inline-flex; margin-bottom: 10px; font-weight: 700; }
.chat-thread { display: flex; flex-direction: column; gap: 9px; max-width: 900px; min-height: 300px; max-height: 65vh; padding: 18px; margin: auto; overflow-y: auto; background: #eaf0f4; border: 1px solid #dbe3ea; border-radius: 18px; }
.chat-bubble { align-self: flex-start; width: min(75%, 620px); padding: 11px 13px; background: #fff; border-radius: 14px 14px 14px 4px; box-shadow: 0 2px 8px rgba(15,23,42,.07); }
.chat-bubble.inbound { align-self: flex-end; background: #dcfce7; border-radius: 14px 14px 4px 14px; }
.chat-bubble.admin { background: #e0f2fe; }
.chat-bubble > span { display: block; color: var(--primary); font-size: 9px; font-weight: 800; }
.chat-bubble p { margin: 3px 0; color: var(--text); white-space: pre-line; }
.chat-bubble small { color: var(--muted); font-size: 9px; }
.reply-box { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 10px; max-width: 900px; padding: 14px; margin: 12px auto 0; background: #fff; border: 1px solid var(--line); border-radius: 15px; }
.reply-box textarea { min-height: 62px; margin: 0; }

.notice { max-width: 1500px; padding: 12px 14px; margin: 0 auto 14px; color: #166534; background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 11px; }
.error { color: #b91c1c; background: #fef2f2; border-color: #fecaca; }
.badge { display: inline-block; padding: 4px 8px; color: #334155; background: #e2e8f0; border-radius: 999px; }
.badge.error, .badge.critical { color: var(--rose); background: #fee2e2; }
.badge.warning { color: #92400e; background: #fef3c7; }
.badge.info { color: #1d4ed8; background: #dbeafe; }
.badge.debug { color: #475569; background: #f1f5f9; }
audio { width: min(360px, 100%); }
pre { max-width: 520px; max-height: 280px; margin: 0; overflow: auto; white-space: pre-wrap; direction: ltr; text-align: left; font: 11px Consolas, monospace; }

.login-shell { display: grid; min-height: 100vh; padding: 22px; place-items: center; background: radial-gradient(circle at 80% 15%, rgba(45,212,191,.16), transparent 30%), var(--sidebar); }
.login-card { width: min(430px, 100%); padding: 34px; border-color: rgba(255,255,255,.08); box-shadow: 0 30px 80px rgba(0,0,0,.24); }
.login-card::before { content: "+"; display: grid; width: 46px; height: 46px; margin-bottom: 18px; place-items: center; color: #fff; background: var(--primary); border-radius: 14px; font-size: 28px; font-weight: 800; }
.login-card h1 { margin-bottom: 18px; font-size: 24px; }
.login-card label { margin-top: 12px; }
.login-card button { width: 100%; margin-top: 18px; }

@media (max-width: 1350px) { .metric-grid-six { grid-template-columns: repeat(3, minmax(160px, 1fr)); } }
@media (max-width: 1050px) {
  .admin-shell { grid-template-columns: 1fr; }
  .sidebar { position: relative; height: auto; padding: 16px; }
  .brand { padding-bottom: 14px; }
  .tabs { grid-template-columns: repeat(3, minmax(180px, 1fr)); align-items: start; }
  .sidebar-footer { display: flex; gap: 12px; align-items: center; }
  .sidebar-footer form { flex: 1; margin: 0; }
  .utility-link { flex: 1; border: 0; }
  .triage-details { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .content { padding: 20px 13px 38px; }
  .topbar { align-items: flex-start; }
  .system-live { display: none; }
  .tabs { display: flex; padding-bottom: 4px; overflow-x: auto; }
  .nav-group { display: flex; gap: 5px; }
  .nav-group > span { display: none; }
  .tab { min-width: max-content; background: rgba(255,255,255,.05); }
  .sidebar-footer { margin-top: 14px; }
  .metric-grid, .metric-grid-six, .triage-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .data-form, .review-form { grid-template-columns: 1fr; }
  .triage-card > header, .demo-callout { align-items: flex-start; flex-direction: column; }
  .triage-details { grid-template-columns: 1fr; }
  .conversation-row { grid-template-columns: 42px minmax(0, 1fr); }
  .conversation-row > div:last-child { grid-column: 2; justify-items: start; }
  .chat-bubble { width: 90%; }
  .reply-box, .search-bar { grid-template-columns: 1fr; }
}
@media (max-width: 460px) {
  .metric-grid, .metric-grid-six, .triage-summary { grid-template-columns: 1fr; }
  .metric { min-height: 96px; }
  .sidebar-footer { display: grid; }
  .login-card { padding: 25px; }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }
