:root {
  --bg: #d1d7db;
  --panel: #ffffff;
  --head: #f0f2f5;
  --hover: #f5f6f6;
  --active: #e9edef;
  --border: #e9edef;
  --text: #111b21;
  --muted: #54656f;
  --accent: #008069;
  --accent-text: #ffffff;
  --chat-bg: #efeae2;
  --out: #d9fdd3;
  --in: #ffffff;
  --system: #ffeecd;
  --danger: #c62828;
  --warn: #8a5300;
  --focus: #027eb5;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1317;
    --panel: #111b21;
    --head: #202c33;
    --hover: #202c33;
    --active: #2a3942;
    --border: #222d34;
    --text: #e9edef;
    --muted: #8696a0;
    --accent: #00a884;
    --accent-text: #111b21;
    --chat-bg: #0b141a;
    --out: #005c4b;
    --in: #202c33;
    --system: #182229;
    --danger: #f15c6d;
    --warn: #ffd279;
    --focus: #53bdeb;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, "Segoe UI", "Noto Sans Hebrew", Arial, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
h1, h2, h3 { margin: 0; }
.boot { padding: 24px; text-align: center; }

/* ---------- buttons & form controls */
button {
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 20px;
  padding: 7px 16px;
  cursor: pointer;
  min-height: 36px;
}
button:hover { background: var(--hover); }
button:disabled { opacity: .6; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.danger { color: var(--danger); }
button.small { padding: 3px 12px; min-height: 30px; font-size: 13px; }
button.wide { width: 100%; }
button.icon { border: none; background: none; border-radius: 50%; width: 40px; height: 40px; padding: 0; font-size: 20px; color: var(--muted); }
button.icon:hover { background: var(--active); }
button.link { border: none; background: none; padding: 0 6px; min-height: 0; color: var(--accent); text-decoration: underline; }
button.link.danger { color: var(--danger); }
input:not([type=checkbox]), select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 8px;
  padding: 8px 10px;
}
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; flex: none; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.label { font-size: 13px; color: var(--muted); }
.hint { font-size: 13px; color: var(--muted); margin: 4px 0; }
.check { display: flex; gap: 10px; align-items: center; padding: 4px 0; }
.err { color: var(--danger); min-height: 1.4em; margin: 4px 0; }

/* ---------- login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%);
  background: var(--panel);
  border-radius: 12px;
  padding: 32px 24px;
  display: flex; flex-direction: column; gap: 12px;
  text-align: center;
  box-shadow: 0 2px 12px rgba(0, 0, 0, .12);
}
.login-card .field { text-align: start; }
.logo { align-self: center; border-radius: 18px; }

/* ---------- layout */
.shell {
  display: grid;
  grid-template-columns: minmax(320px, 32%) 1fr;
  height: 100dvh;
  max-width: 1600px;
  margin: 0 auto;
  background: var(--panel);
}
.sidebar { display: flex; flex-direction: column; min-height: 0; min-width: 0; border-inline-end: 1px solid var(--border); }
.side-head {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--head); padding: 8px 16px; min-height: 60px;
}
.side-head h1 { font-size: 19px; }
.head-actions { display: flex; gap: 4px; }
.tabs { display: flex; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); }
.tab { border-radius: 16px; min-height: 32px; padding: 4px 14px; background: var(--head); border-color: transparent; color: var(--muted); }
.tab[aria-selected=true] { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.list { overflow-y: auto; flex: 1; }
.empty { padding: 24px 20px; color: var(--muted); text-align: center; }

.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 14px;
  color: inherit; text-decoration: none;
  border: none; border-bottom: 1px solid var(--border); border-radius: 0;
  width: 100%; background: none; text-align: start;
}
.row:hover { background: var(--hover); }
.row.active { background: var(--active); }
.row-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.row-top { display: flex; justify-content: space-between; gap: 8px; }
.name { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.time { font-size: 12px; color: var(--muted); flex: none; }
.row-sub { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar {
  flex: none; width: 46px; height: 46px; border-radius: 50%;
  display: grid; place-items: center;
  background: #6b7c85; color: #fff; font-size: 20px; font-weight: 600;
}
.avatar.group { background: #3d7a8a; font-size: 22px; }
.avatar.plus { background: var(--accent); color: var(--accent-text); font-size: 26px; }

/* ---------- chat */
.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--chat-bg); }
.placeholder { margin: auto; text-align: center; color: var(--muted); padding: 24px; }
.placeholder h2 { color: var(--text); font-weight: 400; font-size: 28px; margin: 12px 0; }
.chat-head { display: flex; align-items: center; gap: 4px; background: var(--head); padding: 6px 12px; min-height: 60px; }
.head-info {
  display: flex; align-items: center; gap: 12px; flex: 1; min-width: 0;
  border: none; background: none; border-radius: 8px; padding: 4px; text-align: start;
}
.head-info:hover { background: none; }
.head-info .avatar { width: 40px; height: 40px; font-size: 17px; }
.ws-btn { border: 1px solid var(--line, rgba(255,255,255,.18)); background: none; border-radius: 16px; padding: 4px 10px; font-size: 13px; color: var(--muted); white-space: nowrap; }
.ws-btn:hover { background: var(--active); }
.ws-note { font-size: 12px; color: var(--muted); white-space: nowrap; }
.head-text { display: flex; flex-direction: column; min-width: 0; }
.head-text .title { font-size: 16px; font-weight: 600; }
.head-text .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 12px 7%; display: flex; flex-direction: column; gap: 3px; }
.msg {
  max-width: min(78%, 620px);
  padding: 6px 9px 4px;
  border-radius: 8px;
  box-shadow: 0 1px .5px rgba(11, 20, 26, .13);
  margin-top: 2px;
}
.msg.out { align-self: flex-end; background: var(--out); }
.msg.in { align-self: flex-start; background: var(--in); }
.msg.pending.sending { opacity: .75; }
.text { white-space: pre-wrap; overflow-wrap: anywhere; }
.meta { font-size: 11px; color: var(--muted); text-align: end; margin-top: 1px; }
.tick { color: #53bdeb; }
.who { font-size: 13px; font-weight: 600; margin-bottom: 1px; }
.who.c0 { color: #1f7aa8; } .who.c1 { color: #a4468f; } .who.c2 { color: #b35c00; }
.who.c3 { color: #2e7d32; } .who.c4 { color: #6a4fc0; } .who.c5 { color: #c2185b; }
@media (prefers-color-scheme: dark) {
  .who.c0 { color: #53bdeb; } .who.c1 { color: #e26ab6; } .who.c2 { color: #ffb74d; }
  .who.c3 { color: #7bd88f; } .who.c4 { color: #a78bfa; } .who.c5 { color: #f48fb1; }
}
.day, .system, .run {
  align-self: center;
  background: var(--system);
  color: var(--muted);
  border-radius: 8px;
  padding: 4px 12px;
  margin: 6px 0;
  font-size: 13px;
  text-align: center;
  max-width: 90%;
}
.day { background: var(--panel); text-transform: none; }
.run.failed { color: var(--danger); }
.run.blocked { color: var(--warn); }
.dots { display: inline-block; animation: blink 1.2s infinite; }
@keyframes blink { 50% { opacity: .2; } }
@media (prefers-reduced-motion: reduce) { .dots { animation: none; } }
.older { align-self: center; margin: 4px 0 8px; }

.suggestions {
  display: flex; flex-direction: column; gap: 8px;
  padding: 6px 12px 0; max-height: 40vh; overflow-y: auto;
}
.suggestions:empty { display: none; }
.suggestion { background: var(--system); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.suggestion-head { font-weight: 600; font-size: 14px; }
.suggestion-text { white-space: pre-wrap; overflow-wrap: anywhere; }
.suggestion-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.composer { display: flex; align-items: flex-end; gap: 8px; padding: 8px 12px; background: var(--head); }
.composer textarea { resize: none; border-radius: 20px; padding: 9px 14px; max-height: 140px; border-color: transparent; }
.send {
  flex: none; width: 44px; height: 44px; border-radius: 50%; padding: 0;
  background: var(--accent); border: none; color: var(--accent-text); font-size: 18px;
  transform: scaleX(-1); /* RTL: the arrow points toward the reading direction */
}
.send:hover { background: var(--accent); filter: brightness(1.08); }

/* ---------- dialogs */
dialog.dlg {
  border: none; border-radius: 12px; padding: 0;
  width: min(520px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  background: var(--panel); color: var(--text);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .3);
}
dialog::backdrop { background: rgba(11, 20, 26, .55); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--head); position: sticky; top: 0; z-index: 1; }
.dlg-head h2 { font-size: 18px; }
.dlg-body { padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.dlg-body section { display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); padding-top: 12px; }
.dlg-body section:first-child { border-top: none; padding-top: 0; }
.dlg-body section > button { align-self: flex-start; }
.dlg-body section.warn { background: var(--system); border-radius: 8px; padding: 12px; }
.dlg-body h3 { font-size: 15px; color: var(--accent); }
.inline { display: flex; gap: 8px; align-items: flex-end; }
.inline > input, .inline > select { flex: 1; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.picks { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin: 0; }
.picks legend { font-size: 13px; color: var(--muted); padding: 0 4px; }
ul.plain { list-style: none; margin: 0; padding: 0; }
ul.plain li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); }
ul.plain li.done label { text-decoration: line-through; color: var(--muted); }
.badge { font-size: 12px; background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 1px 10px; flex: none; }

#toast {
  position: fixed; bottom: 88px; left: 50%; transform: translateX(-50%);
  background: #323739; color: #fff; padding: 10px 18px; border-radius: 8px;
  max-width: calc(100vw - 32px); z-index: 10;
  opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }

/* ---------- phone */
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .shell[data-view=chat] .sidebar { display: none; }
  .shell[data-view=list] .chat { display: none; }
  .back { display: inline-block; }
  .messages { padding: 10px 12px; }
  .msg { max-width: 88%; }
  .inline { flex-wrap: wrap; }
  .row { padding: 10px 12px; }
}

/* ---------------------------------------------------------------- agent builder */
.badge.ok { background: var(--accent); }
.badge.warn { background: var(--warn); color: var(--panel); }
.badge.bad { background: var(--danger); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 12px; background: var(--active); color: var(--text); border-radius: 10px; padding: 2px 10px; }
.cap-list { display: flex; flex-direction: column; gap: 6px; max-height: 260px; overflow-y: auto; }
.cap-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 0; border-bottom: 1px solid var(--border); }
.cap-row .check { padding: 0; }
.cap-id { font-size: 13px; flex: 1; min-width: 150px; word-break: break-all; }
.resp-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 2px 12px; }
.lesson-agent { display: flex; flex-direction: column; gap: 6px; padding: 6px 0; }
ul.lessons li { flex-wrap: wrap; }
ul.lessons li span[dir] { flex: 1; min-width: 180px; font-size: 13px; }

/* ---------- V3: the Claude-led Builder conversation (reuses .msg/.system/.who/.dots/.chips above) */
.bld-thread {
  display: flex; flex-direction: column; gap: 4px; padding: 10px;
  min-height: 140px; max-height: 42vh; overflow-y: auto;
  background: var(--chat-bg); border-radius: 8px;
}
.bld-thread .msg { max-width: 92%; }
.bld-q { font-weight: 600; margin-top: 4px; }
.bld-composer { display: flex; align-items: flex-end; gap: 8px; }
.bld-composer textarea { flex: 1; resize: none; max-height: 140px; }
.perm-row { display: flex; flex-direction: column; gap: 6px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.perm-row .actions { gap: 6px; }
.perm-result { white-space: pre-wrap; overflow-wrap: anywhere; background: var(--active); border-radius: 8px; padding: 8px 10px; }
