:root {
  --ground: #F6F5F1; --panel: #FFFFFF; --ink: #1C1D1A; --muted: #5E6059; --line: #E3E1DA;
  --accent: #0F6E66; --accent-ink: #FFFFFF; --accent-soft: #E3F0EE; --thumb: #D9E7E4; --danger: #B3261E;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #141513; --panel: #1E201D; --ink: #ECEBE6; --muted: #A3A49D; --line: #33352F;
    --accent: #13857B; --accent-soft: #243A37; --thumb: #2B403D; --danger: #F2B8B5;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--ground); color: var(--ink);
  font-family: 'IBM Plex Sans Arabic', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  font-size: 16px; line-height: 1.6; -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--accent); }
svg.icon { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
svg.icon .fill { fill: currentColor; stroke: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; color: var(--ink);
}
.icon-btn:hover { background: var(--accent-soft); }
.icon-btn.round { border-radius: 22px; border: 1px solid var(--line); background: var(--ground); }
.icon-btn.primary { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 22px; }
.icon-btn.primary:disabled { opacity: .45; cursor: default; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 32px 24px; }
.login-box { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 28px; }
.login-head { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.logo { width: 64px; height: 64px; border-radius: 20px; background: var(--accent); color: var(--accent-ink); display: flex; align-items: center; justify-content: center; }
.logo svg.icon { width: 30px; height: 30px; }
.login h1 { margin: 0; font-size: 26px; font-weight: 600; }
.login p { margin: 0; color: var(--muted); }
.login form { display: flex; flex-direction: column; gap: 12px; }
.login label { font-weight: 500; }
.login input { height: 52px; padding: 0 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.login .error { color: var(--danger); font-size: 14px; }
.btn-primary { height: 52px; border: 0; border-radius: 14px; background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.btn-primary:disabled { opacity: .6; }
.login .hint { text-align: center; font-size: 13px; color: var(--muted); }

/* ---------- shell ---------- */
.shell { height: 100dvh; display: flex; }
.sidebar { width: 340px; flex-shrink: 0; border-inline-end: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; min-height: 0; }
@media (max-width: 899px) {
  .sidebar { width: 100%; border: 0; background: var(--ground); }
  .shell.in-chat .sidebar { display: none; }
  .shell:not(.in-chat) .chat { display: none; }
}

.side-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; gap: 8px; }
.side-head h1 { margin: 0; font-size: 22px; font-weight: 600; }
.btn-new { min-height: 40px; padding: 0 14px; border-radius: 12px; border: 0; background: var(--accent); color: var(--accent-ink); font-size: 14px; font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.btn-new svg.icon { width: 16px; height: 16px; }
.search { padding: 0 16px 12px; }
.search input { width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--ground); font-size: 14px; }
.conv-list { flex: 1; overflow-y: auto; margin: 0; padding: 0; list-style: none; }
.conv-list a { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.conv-list a[aria-current="page"] { background: var(--accent-soft); }
.avatar { width: 44px; height: 44px; border-radius: 22px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 14px; flex-shrink: 0; }
.conv-main { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; }
.conv-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.conv-last { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }
.side-foot { padding: 12px 16px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; font-size: 14px; color: var(--muted); }
.link-btn { border: 0; background: transparent; color: var(--muted); padding: 8px; font-size: 14px; }
.fab { display: none; }
@media (max-width: 899px) {
  .side-head .btn-new { display: none; }
  .side-foot { padding-bottom: calc(92px + env(safe-area-inset-bottom)); }
  .fab { display: inline-flex; position: fixed; bottom: calc(24px + env(safe-area-inset-bottom)); left: 16px; height: 56px; padding: 0 20px; border-radius: 28px; border: 0; background: var(--accent); color: var(--accent-ink); align-items: center; gap: 8px; font-weight: 600; box-shadow: 0 6px 18px rgba(15,110,102,.3); }
}

/* ---------- chat ---------- */
.chat-head { display: flex; align-items: center; gap: 12px; padding: 10px 12px; padding-top: calc(10px + env(safe-area-inset-top)); border-bottom: 1px solid var(--line); background: var(--panel); }
.chat-head .who { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.chat-head .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-head .sub { font-size: 13px; color: var(--muted); }
.back { display: none; }
@media (max-width: 899px) { .back { display: inline-flex; } }
.menu { position: relative; }
.menu-pop { position: absolute; top: 48px; left: 0; z-index: 10; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px; min-width: 160px; display: flex; flex-direction: column; }
.menu-pop[hidden] { display: none; }
.menu-pop button { border: 0; background: transparent; text-align: start; padding: 10px 12px; border-radius: 8px; min-height: 44px; }
.menu-pop button:hover { background: var(--accent-soft); }
.menu-pop .danger { color: var(--danger); }

.messages { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.messages-inner { width: 100%; max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }
.welcome { margin: auto; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 24px; }
.welcome .avatar { width: 56px; height: 56px; border-radius: 28px; font-size: 18px; }
.welcome strong { color: var(--ink); font-size: 18px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 18px; overflow-wrap: anywhere; }
.msg.user { align-self: flex-start; background: var(--accent); color: var(--accent-ink); border-start-end-radius: 4px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-end; background: var(--panel); border: 1px solid var(--line); border-end-start-radius: 4px; max-width: 90%; }
.msg.error .body { color: var(--danger); }
.msg .meta { display: flex; align-items: center; gap: 12px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.msg.user .meta { color: inherit; opacity: .85; }
.msg .meta button { border: 0; background: transparent; color: inherit; padding: 6px 4px; display: inline-flex; align-items: center; gap: 4px; font-size: 12px; }
.msg .meta svg.icon { width: 14px; height: 14px; }
.cursor { display: inline-block; width: 8px; height: 16px; background: var(--accent); vertical-align: middle; margin-inline-start: 2px; border-radius: 1px; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.typing { font-size: 12px; color: var(--muted); }
.body > :first-child { margin-top: 0; }
.body > :last-child { margin-bottom: 0; }
.body p { margin: 0 0 8px; }
.body ul, .body ol { margin: 0 0 8px; padding-inline-start: 22px; }
.body pre { direction: ltr; text-align: left; background: var(--ground); border: 1px solid var(--line); border-radius: 10px; padding: 10px; overflow-x: auto; font-size: 13px; }
.body code { font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace; font-size: .9em; }
.body :not(pre) > code { background: var(--ground); padding: 1px 5px; border-radius: 5px; }
.body .table-wrap { overflow-x: auto; margin: 0 0 8px; }
.body table { border-collapse: collapse; font-size: 14px; }
.body th, .body td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: start; }
.body blockquote { margin: 0 0 8px; padding-inline-start: 12px; border-inline-start: 3px solid var(--line); color: var(--muted); }

.att-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 6px; }
.att-img { display: block; max-width: 240px; max-height: 240px; border-radius: 14px; background: var(--thumb); }
.att-img img { display: block; max-width: 240px; max-height: 240px; border-radius: 14px; object-fit: cover; }
.att-file { display: flex; align-items: center; gap: 8px; background: rgba(255,255,255,.14); border-radius: 12px; padding: 8px 10px; font-size: 13px; color: inherit; text-decoration: none; }
.att-file.plain { background: var(--ground); }
.att-file .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-file svg.icon { width: 18px; height: 18px; }

.composer { border-top: 1px solid var(--line); background: var(--panel); padding: 10px 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
.composer-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.composer.dragging { background: var(--accent-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips:empty { display: none; }
.chip { display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 12px; padding: 4px 4px 4px 10px; background: var(--ground); font-size: 13px; max-width: 100%; }
.chip .thumb { width: 32px; height: 32px; border-radius: 8px; background: var(--thumb); color: var(--accent); display: flex; align-items: center; justify-content: center; overflow: hidden; flex-shrink: 0; }
.chip .thumb img { width: 100%; height: 100%; object-fit: cover; }
.chip .thumb svg.icon { width: 16px; height: 16px; }
.chip .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chip.uploading { opacity: .6; }
.chip.failed { border-color: var(--danger); color: var(--danger); }
.chip .icon-btn { width: 32px; height: 32px; border-radius: 8px; }
.chip .icon-btn svg.icon { width: 14px; height: 14px; }
.row { display: flex; align-items: flex-end; gap: 8px; }
.row textarea { flex: 1; resize: none; min-height: 44px; max-height: 40dvh; padding: 10px 14px; border: 1px solid var(--line); border-radius: 22px; background: var(--ground); font-size: 16px; line-height: 1.5; }
.hint-line { font-size: 12px; color: var(--muted); }
@media (max-width: 899px) { .hint-line { display: none; } }
.toast { position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--ground); padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 50; max-width: calc(100% - 32px); }

/* ---------- agents: picker, task bar, needs you ---------- */
.needs-link { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); color: var(--ink); text-decoration: none; font-weight: 500; }
.needs-link[aria-current="page"] { background: var(--accent-soft); }
.badge { margin-inline-start: auto; min-width: 24px; height: 24px; padding: 0 8px; border-radius: 12px; background: var(--danger); color: #fff; font-size: 13px; font-weight: 600; display: inline-flex; align-items: center; justify-content: center; }
@media (prefers-color-scheme: dark) { .badge { color: #1E201D; } }
.pill { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 12px; background: var(--accent-soft); color: var(--accent); font-size: 13px; font-weight: 500; white-space: nowrap; }
.pill.warn, .pill.status-blocked { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.pill.status-done { background: var(--thumb); color: var(--ink); }
.picker { width: 100%; max-width: 760px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 20px; }
.picker h2 { margin: 0 0 8px; font-size: 14px; font-weight: 600; color: var(--muted); }
.picker ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.agent-card { width: 100%; display: flex; align-items: center; gap: 12px; padding: 12px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); text-align: start; }
.agent-card:hover { border-color: var(--accent); }
.agent-main { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.agent-name { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.agent-desc { color: var(--muted); font-size: 14px; }
.task-bar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel); font-size: 14px; }
.task-bar[hidden] { display: none; }
.task-note { color: var(--muted); flex: 1; min-width: 200px; }
.msg.waiting { background: transparent; border: 1px dashed var(--line); }
.needs { width: 100%; max-width: 760px; margin: 0 auto; padding: 16px; }
.needs ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.needs .error { color: var(--danger); }
.need { background: var(--panel); border: 1px solid var(--line); border-inline-start: 4px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.need.sev-critical, .need.sev-high { border-inline-start-color: var(--danger); }
.need.sev-medium { border-inline-start-color: var(--accent); }
.need-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.need-top .conv-time { margin-inline-start: auto; }
.need-agent { color: var(--muted); font-size: 14px; }
.need-title { font-weight: 600; }
.need-issue, .need-why { color: var(--muted); font-size: 14px; }
.need-excerpt { font-size: 15px; white-space: pre-wrap; overflow-wrap: anywhere; }
.need-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.need-actions .btn-primary { height: 44px; padding: 0 20px; }
.btn-ghost { height: 44px; padding: 0 16px; border: 1px solid var(--line); border-radius: 14px; background: transparent; color: var(--ink); display: inline-flex; align-items: center; text-decoration: none; font-weight: 500; }
.btn-ghost.danger { color: var(--danger); }
.btn-ghost:disabled, .btn-primary:disabled { opacity: .5; }
