/* SmartFusion Diagnostics — identity: deep navy + bright blue, white cards, Arabic RTL */
:root {
  --navy-900: #0b1a45;
  --navy-800: #0f2a6b;
  --navy-700: #163a8c;
  --blue: #2563eb;
  --blue-600: #1d4ed8;
  --blue-50: #eff6ff;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --green: #16a34a;
  --teal: #0d9488;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, system-ui, sans-serif;
  font-size: 15px; line-height: 1.7;
}
a { color: var(--blue-600); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0 0 .6em; line-height: 1.35; }
h2 { font-size: 1.2rem; } h3 { font-size: 1.05rem; }
code { background: #f1f5f9; padding: 1px 6px; border-radius: 6px; font-size: .9em; }
.muted { color: var(--muted); } .small { font-size: .85rem; } .nowrap { white-space: nowrap; }

/* ---------- Layout ---------- */
body.has-nav { padding-right: 260px; }
.sidebar {
  position: fixed; inset: 0 0 0 auto; width: 260px; z-index: 30;
  background: linear-gradient(180deg, var(--navy-900), var(--navy-800));
  color: #fff; display: flex; flex-direction: column; padding: 18px 14px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 18px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand b { display: block; font-size: 1rem; } .brand small { color: #9fb3e6; font-size: .78rem; }
.logo {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 11px;
  background: #fff; color: var(--navy-800); font-weight: 700; letter-spacing: .5px; flex: none;
  box-shadow: inset 0 0 0 3px var(--blue);
}
.logo.big { width: 64px; height: 64px; border-radius: 16px; font-size: 1.4rem; }
.sidebar nav { flex: 1; overflow-y: auto; padding: 12px 0; display: flex; flex-direction: column; gap: 3px; }
.sidebar nav a {
  display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-radius: 10px;
  color: #dbe5ff; font-weight: 500;
}
.sidebar nav a:hover { background: rgba(255,255,255,.08); text-decoration: none; }
.sidebar nav a.on { background: var(--blue); color: #fff; box-shadow: 0 4px 14px rgba(37,99,235,.45); }
.nav-sec { color: #7f93c7; font-size: .75rem; padding: 14px 12px 4px; }
.me-box { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.1); }
.me-box b { display: block; font-size: .9rem; } .me-box small { color: #9fb3e6; font-size: .75rem; }
.me-box .btn { color: #fff; border-color: rgba(255,255,255,.25); }
.topbar { display: none; }
.main { max-width: 1180px; margin: 0 auto; padding: 24px; }

/* ---------- Components ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card.narrow { max-width: 480px; margin-inline: auto; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr)); gap: 18px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 14px; }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }
.grid-2 + *, .grid-3 + * { margin-top: 18px; }
label { display: block; font-weight: 500; font-size: .9rem; margin-bottom: 12px; }
input, select, textarea {
  display: block; width: 100%; margin-top: 5px; padding: 10px 12px; font: inherit;
  border: 1px solid #cbd5e1; border-radius: 10px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 3px solid rgba(37,99,235,.18); border-color: var(--blue); }
select:disabled { background: #f8fafc; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: center; }
label.check input { width: auto; margin: 0; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 10px 18px;
  border-radius: 10px; border: 1px solid transparent; font: inherit; font-weight: 600; cursor: pointer;
  background: #e2e8f0; color: var(--text); text-decoration: none !important;
}
.btn.primary { background: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-600); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.ghost:hover { background: #f8fafc; }
.btn.danger { color: var(--red); }
.btn.sm { padding: 5px 11px; font-size: .82rem; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .55; cursor: wait; }
.flash { padding: 11px 14px; border-radius: 10px; margin-bottom: 16px; font-weight: 500; }
.flash.ok { background: #ecfdf5; color: #065f46; border: 1px solid #a7f3d0; }
.flash.err { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.badge.blue { background: var(--blue-50); color: var(--blue-600); }
.badge.green { background: #dcfce7; color: #166534; }
.badge.teal { background: #ccfbf1; color: #115e59; }
.badge.gray { background: #f1f5f9; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  direction: ltr; font-family: ui-monospace, Consolas, monospace; font-size: .8rem; font-weight: 600;
  background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; padding: 1px 8px; border-radius: 7px;
}
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: right; color: var(--muted); font-weight: 600; border-bottom: 2px solid var(--line); padding: 8px; }
.tbl td { border-bottom: 1px solid var(--line); padding: 8px; vertical-align: top; }
tr.off, .off { opacity: .5; }
form.inline { display: inline; }
.row-btns { display: flex; gap: 10px; flex-wrap: wrap; }
.link { display: inline-block; margin-top: 10px; font-weight: 600; }

/* ---------- Login ---------- */
body.bare { background: radial-gradient(circle at 70% 10%, var(--navy-700), var(--navy-900) 65%); min-height: 100vh; }
.login-wrap { max-width: 400px; margin: 8vh auto 0; }
.login-head { text-align: center; color: #fff; margin-bottom: 18px; }
.login-head h1 { margin: 12px 0 0; font-size: 1.5rem; }
.login-head p { margin: 0; color: #b8c7ef; }
.login-card { padding: 26px; }

/* ---------- New case ---------- */
.steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); gap: 12px; }
.step { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; background: var(--blue); color: #fff; font-size: .75rem; margin-left: 4px; }
details.more { margin: 4px 0 14px; border: 1px dashed var(--line); border-radius: 10px; padding: 8px 12px; }
details.more summary { cursor: pointer; color: var(--blue-600); font-weight: 500; font-size: .9rem; }
details.more[open] summary { margin-bottom: 10px; }

/* ---------- Lists ---------- */
.list { display: flex; flex-direction: column; gap: 8px; }
.row-card { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); }
.row-card:hover { border-color: var(--blue); background: var(--blue-50); text-decoration: none; }
.rc-main small { display: block; color: var(--muted); }
.rc-side { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; flex: none; }
.rc-side small { color: var(--muted); font-size: .75rem; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { width: auto; flex: 1 1 180px; margin: 0; }

/* ---------- Case / chat ---------- */
.case-head { display: flex; justify-content: space-between; gap: 12px; }
.case-head h2 { margin-bottom: 2px; }
.case-head p { margin: 0 0 6px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: .85rem; color: var(--muted); }
.chat { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.empty-chat { text-align: center; padding: 40px 20px; border: 2px dashed #cbd5e1; border-radius: var(--radius); color: var(--muted); }
.empty-chat b { display: block; color: var(--text); margin-bottom: 6px; }
.msg { border-radius: var(--radius); padding: 14px 18px; border: 1px solid var(--line); background: #fff; box-shadow: var(--shadow); max-width: 100%; overflow-wrap: anywhere; }
.msg.me { background: var(--blue-50); border-color: #bfdbfe; margin-inline-start: 12%; }
.msg.ai { margin-inline-end: 4%; border-top: 3px solid var(--blue); }
.msg-head { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.msg-head small { color: var(--muted); font-size: .75rem; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin: 6px 0; }
.thumbs img { width: 120px; height: 90px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); }
.md h2 { font-size: 1.05rem; color: var(--navy-800); margin: 1.1em 0 .4em; padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.md h3 { font-size: .98rem; margin: 1em 0 .3em; }
.md h2:first-child, .md h3:first-child { margin-top: 0; }
.md p { margin: .4em 0; }
.md ul, .md ol { margin: .3em 0; padding-inline-start: 1.4em; }
.md li { margin: .15em 0; }
.md blockquote { margin: .6em 0; padding: 8px 12px; border-inline-start: 4px solid var(--amber); background: #fffbeb; border-radius: 6px; }
.md table { width: 100%; border-collapse: collapse; margin: .6em 0; font-size: .88rem; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 8px; text-align: right; }
.md th { background: #f8fafc; }
.md code { direction: ltr; unicode-bidi: embed; }
.rate { display: flex; align-items: center; gap: 6px; margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); }
.rate small { color: var(--muted); }
.rate button { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 2px 10px; cursor: pointer; font-size: 1rem; }
.rate button.on { background: var(--blue-50); border-color: var(--blue); }
.composer { position: sticky; bottom: 10px; z-index: 5; padding: 12px; }
.composer textarea { margin: 0 0 8px; resize: vertical; min-height: 54px; }
.composer-bar { display: flex; align-items: center; gap: 10px; justify-content: space-between; }
.composer-bar .muted { flex: 1; }
.file-btn { cursor: pointer; margin: 0; }
.previews { display: flex; gap: 8px; flex-wrap: wrap; }
.previews:not(:empty) { margin-bottom: 8px; }
.preview { position: relative; }
.preview img { width: 84px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.preview button { position: absolute; top: -6px; left: -6px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: var(--red); color: #fff; cursor: pointer; font-size: .8rem; line-height: 1; }
.thinking { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.dots span { display: inline-block; width: 8px; height: 8px; margin: 0 2px; border-radius: 50%; background: var(--blue); animation: blink 1.2s infinite; }
.dots span:nth-child(2) { animation-delay: .2s; } .dots span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
.resolve summary { cursor: pointer; font-weight: 600; color: var(--green); }
.resolve[open] summary { margin-bottom: 12px; }
.resolved-box { border-top: 3px solid var(--green); }

/* ---------- Admin ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 170px), 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { margin: 0; }
.stat small { display: block; color: var(--muted); }
.stat b { font-size: 1.5rem; color: var(--navy-800); }
.review textarea { min-height: 80px; }
.make-list { display: flex; flex-wrap: wrap; gap: 6px; max-height: 420px; overflow-y: auto; margin-bottom: 14px; }
.make-list a { border: 1px solid var(--line); border-radius: 9px; padding: 4px 10px; font-size: .88rem; color: var(--text); }
.make-list a.on { background: var(--blue); border-color: var(--blue); color: #fff; }
.make-list a small { color: inherit; opacity: .7; }
.form-inline { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.form-inline input { width: auto; flex: 1 1 140px; margin: 0; }
.temp-pass { border: 2px solid var(--amber); background: #fffbeb; }
.temp-pass code.big { display: inline-block; font-size: 1.3rem; padding: 6px 14px; margin: 8px 0; background: #fff; }
.code-card { padding: 12px 0; border-bottom: 1px solid var(--line); }
.code-card:last-child { border-bottom: 0; }
.code-card h3 { font-family: ui-monospace, Consolas, monospace; color: #9a3412; text-align: right; }

/* ---------- Mobile ---------- */
@media (max-width: 900px) {
  body.has-nav { padding-right: 0; }
  .sidebar { transform: translateX(100%); transition: transform .2s; box-shadow: -10px 0 30px rgba(0,0,0,.3); }
  body.nav-open .sidebar { transform: none; }
  .topbar {
    display: flex; position: sticky; top: 0; z-index: 20; align-items: center; justify-content: space-between; gap: 10px;
    padding: 10px 16px; background: var(--navy-800); color: #fff;
  }
  .menu-btn { background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }
  .main { padding: 16px; }
  .grid-2, .grid-3, .steps { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
  .msg.me { margin-inline-start: 0; } .msg.ai { margin-inline-end: 0; }
  .case-head { flex-direction: column; }
  .row-card { flex-direction: column; }
  .rc-side { align-items: flex-start; flex-direction: row; flex-wrap: wrap; gap: 8px; }
  .tbl { display: block; overflow-x: auto; }
  .composer { bottom: 0; border-radius: var(--radius) var(--radius) 0 0; margin-inline: -16px; margin-bottom: 0; }
}
