:root {
  --bg: #f4f1ea;
  --panel: #ffffff;
  --ink: #2b2620;
  --muted: #857c6e;
  --line: #e5ddcd;
  --brand: #2f6f5e;
  --brand-soft: #e4f0eb;
  --accent: #7c5cff;
  --warn: #c9781f;
  --danger: #c0392b;
  --ok: #2f8f4e;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(60, 50, 30, 0.06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Rubik", "Assistant", -apple-system, "Segoe UI", Arial, sans-serif;
  direction: rtl;
  font-size: 16px;
  line-height: 1.55;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font-family: inherit; cursor: pointer; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 22px 18px 80px; }

/* header */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 20px;
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-size: 22px; margin: 0; color: var(--brand); }
.brand .sub { color: var(--muted); font-size: 14px; }
.pill {
  font-size: 12px; padding: 3px 10px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand); white-space: nowrap;
}
.pill.off { background: #f3e6df; color: var(--warn); }

/* buttons */
.btn {
  border: 1px solid var(--brand); background: var(--brand); color: #fff;
  padding: 9px 16px; border-radius: 10px; font-size: 15px; font-weight: 500;
}
.btn:hover { filter: brightness(1.05); }
.btn.ghost { background: #fff; color: var(--brand); }
.btn.subtle { background: #fff; color: var(--ink); border-color: var(--line); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.sm { padding: 5px 12px; font-size: 13px; }

/* cards / panels */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px;
}
.panel h2 { margin: 0 0 6px; font-size: 18px; }
.panel .hint { color: var(--muted); font-size: 13px; margin: 0 0 14px; }

/* new-research form */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px;
  font-size: 15px; background: #fff; color: var(--ink); font-family: inherit;
}
.kind-toggle { display: flex; gap: 8px; }
.kind-toggle button {
  flex: 1; padding: 11px; border: 1px solid var(--line); background: #fff;
  border-radius: 10px; font-size: 15px; color: var(--ink);
}
.kind-toggle button.on { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); font-weight: 600; }

/* project grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px; box-shadow: var(--shadow); cursor: pointer; transition: transform .08s;
  display: flex; flex-direction: column; gap: 7px;
}
.card:hover { transform: translateY(-2px); }
.card .row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card .name { font-weight: 600; font-size: 17px; }
.card .ticker { color: var(--muted); font-size: 13px; }
.card .meta { color: var(--muted); font-size: 12px; }

.badge { font-size: 11px; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.badge.stock { background: #eef3ff; color: #3a5bbf; }
.badge.index { background: #fdf0e6; color: var(--warn); }
.badge.draft { background: #eee9df; color: var(--muted); }
.badge.running { background: #fff5db; color: var(--warn); }
.badge.done { background: #e4f3e9; color: var(--ok); }
.badge.error { background: #fbe6e3; color: var(--danger); }
.badge.level-beginner { background: #e4f3e9; color: #2f8f4e; }
.badge.level-intermediate { background: #fff5db; color: #c9781f; }
.badge.level-advanced { background: #f3edff; color: #7c5cff; }
.badges { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

/* project view layout */
.proj-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.proj-head .title { font-size: 22px; font-weight: 600; }
.proj-head .title small { color: var(--muted); font-size: 15px; font-weight: 400; }
.proj-cols { display: grid; grid-template-columns: 300px 1fr; gap: 18px; align-items: start; }

/* sidebar: agent action log + step list */
.side { position: sticky; top: 14px; display: flex; flex-direction: column; gap: 14px; }
.steplist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.steplist li {
  display: flex; align-items: center; gap: 9px; padding: 8px 9px; border-radius: 8px;
  font-size: 14px; cursor: pointer;
}
.steplist li:hover { background: var(--brand-soft); }
.steplist li.active { background: var(--brand-soft); font-weight: 600; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--line); flex: none; }
.dot.done { background: var(--ok); }
.dot.running { background: var(--warn); animation: pulse 1s infinite; }
.dot.error { background: var(--danger); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.log { max-height: 320px; overflow-y: auto; font-size: 12.5px; display: flex; flex-direction: column; gap: 8px; }
.log .entry { border-inline-start: 3px solid var(--line); padding: 2px 9px; }
.log .entry.ok { border-color: var(--ok); }
.log .entry.warn { border-color: var(--warn); }
.log .entry.error { border-color: var(--danger); }
.log .entry .who { font-weight: 600; }
.log .entry .tool { color: var(--muted); }
.log .entry .out { color: var(--ink); }

/* step cards (main column) */
.steps { display: flex; flex-direction: column; gap: 16px; }
.step { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 17px; }
.step h3 { margin: 0 0 4px; font-size: 17px; display: flex; align-items: center; gap: 8px; }
.step .note { margin: 8px 0; white-space: pre-wrap; }

.datagrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin: 10px 0; }
.stat { background: #faf8f2; border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 17px; font-weight: 600; }

.tag-fact { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 6px; background: #eef3ff; color: #3a5bbf; margin-inline-end: 6px; }
.tag-interp { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 6px; background: #f3edff; color: var(--accent); margin-inline-end: 6px; }

/* learning question — tap-a-chip knowledge check */
.qbox { margin-top: 12px; background: var(--brand-soft); border-radius: 10px; padding: 12px; }
.qbox .q { font-weight: 600; margin-bottom: 9px; }
.qbox .chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: #fff; border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-size: 14px; font-family: inherit; color: var(--ink);
}
.chip:hover:not(:disabled) { border-color: var(--brand); }
.chip:disabled { cursor: default; }
.chip.correct { background: #e4f3e9; border-color: var(--ok); color: var(--ok); font-weight: 600; }
.chip.wrong { background: #fbe6e3; border-color: var(--danger); color: var(--danger); }
.qbox .feedback { margin-top: 9px; font-size: 13px; }
.qbox .feedback.ok { color: var(--ok); }
.qbox .feedback.no { color: var(--danger); }

/* step tools (edit/delete) + add-step */
.step .step-tools { margin-inline-start: auto; display: flex; gap: 6px; }
.step .step-tools button { background: none; border: none; color: var(--muted); font-size: 13px; padding: 2px 4px; }
.step .step-tools button:hover { color: var(--brand); }
.step.custom { border-inline-start: 3px solid var(--accent); }
.add-step-btn { align-self: flex-start; background: #fff; color: var(--brand); border: 1px dashed var(--brand); border-radius: 10px; padding: 9px 16px; font-size: 14px; }
.add-step-btn:hover { background: var(--brand-soft); }

/* per-step prompt: view / edit / rerun */
.step-prompt { margin-top: 10px; }
.step-prompt summary { cursor: pointer; color: var(--accent); font-size: 13px; }
.step-prompt .pfor { margin: 8px 0 4px; font-size: 12px; color: var(--muted); }
.step-prompt .pedit { width: 100%; padding: 10px; background: #2b2620; color: #f2ede2; border: 1px solid #3a332a; border-radius: 9px; font-size: 13px; line-height: 1.6; font-family: inherit; resize: vertical; }
.step-prompt .prow { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }

/* whole-prompt: its own black panel (matches the per-step prompt boxes) */
.fullprompt h2 { font-size: 17px; }
.fullprompt .fp-text {
  width: 100%; padding: 12px; margin-top: 4px; border: 1px solid #3a332a; border-radius: 10px;
  background: #2b2620; color: #f2ede2; font-family: inherit; font-size: 13.5px;
  line-height: 1.7; resize: vertical;
}

.rep-editor { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; font-family: inherit; font-size: 14px; line-height: 1.7; background: #faf8f2; resize: vertical; }

/* schedule control */
.sched { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.sched select { padding: 6px 9px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; }

/* sources */
.sources { margin-top: 10px; font-size: 12px; color: var(--muted); }
.sources a { color: var(--muted); text-decoration: underline; }

/* tables */
table.cmp { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 14px; }
table.cmp th, table.cmp td { border: 1px solid var(--line); padding: 7px 9px; text-align: start; }
table.cmp th { background: #faf8f2; font-weight: 600; }

/* news list */
.news { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.news li { border-inline-start: 3px solid var(--brand-soft); padding: 3px 10px; }
.news .src { color: var(--muted); font-size: 12px; }

/* report modal / section */
.report { margin-top: 20px; }
.report .md h1 { font-size: 22px; }
.report .md h2 { font-size: 18px; margin-top: 18px; }
.report .md { line-height: 1.7; }
.disclaimer { margin-top: 14px; background: #fbf3e6; border: 1px solid #eddcbf; border-radius: 10px; padding: 12px; font-size: 13px; color: #6b5636; }

/* chart */
.chart { width: 100%; height: 170px; margin: 10px 0; }
.chart-empty { color: var(--muted); font-size: 13px; }

/* misc */
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.toast { position: fixed; inset-block-end: 20px; inset-inline-start: 50%; transform: translateX(50%); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; font-size: 14px; box-shadow: var(--shadow); z-index: 50; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- group chat drawer ---- */
#chat-fab {
  position: fixed; bottom: 20px; left: 20px; z-index: 45;
  background: var(--brand); color: #fff; border: none; border-radius: 999px;
  padding: 11px 18px; font-size: 15px; box-shadow: var(--shadow); font-weight: 500;
}
#chat-fab .n { background: #fff; color: var(--brand); border-radius: 999px; padding: 0 7px; margin-inline-start: 6px; font-size: 12px; }

.chat-drawer {
  position: fixed; top: 0; left: 0; height: 100vh; width: 340px; max-width: 90vw;
  background: var(--panel); border-inline-end: 1px solid var(--line);
  box-shadow: 2px 0 16px rgba(60, 50, 30, 0.12); z-index: 46;
  display: flex; flex-direction: column; transform: translateX(-102%);
  transition: transform .2s ease;
}
.chat-drawer.open { transform: translateX(0); }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.chat-head b { color: var(--brand); }
.chat-head .x { background: none; border: none; font-size: 20px; color: var(--muted); line-height: 1; }

.presence { padding: 8px 14px; border-bottom: 1px solid var(--line); display: flex; flex-wrap: wrap; gap: 6px; max-height: 96px; overflow-y: auto; }
.presence .who { display: inline-flex; align-items: center; gap: 5px; font-size: 12.5px; background: #faf8f2; border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; }
.presence .who .sdot { width: 8px; height: 8px; border-radius: 50%; }
.sdot.working { background: var(--ok); }
.sdot.help { background: var(--warn); }
.sdot.idle { background: #bbb; }
.sdot.guide { background: #3a5bbf; }

.messages { flex: 1; overflow-y: auto; padding: 12px 14px; display: flex; flex-direction: column; gap: 10px; }
.messages .empty { padding: 20px 0; }
.msg { display: flex; flex-direction: column; gap: 2px; }
.msg .top { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.msg .top .nm { font-weight: 600; }
.msg .top .t { color: var(--muted); }
.msg .top .del { margin-inline-start: auto; background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; opacity: 0; }
.msg:hover .top .del { opacity: 1; }
.msg .body { background: #faf8f2; border: 1px solid var(--line); border-radius: 9px; padding: 7px 10px; font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.msg.kind-question .body { background: #eef3ff; border-color: #d6e0ff; }
.msg.kind-help .body { background: #fff3df; border-color: #f0dcb5; }
.msg.kind-finding .body { background: #e9f6ee; border-color: #cbe8d5; }
.msg.kind-source .body { background: #f3edff; border-color: #e0d4ff; }
.msg.kind-agent .body { background: #f3edff; border-color: #d9caff; }
.msg.kind-system .body { background: #f0ede6; color: var(--muted); font-size: 13px; text-align: center; }
.msg .ctx { font-size: 11px; color: var(--muted); }
.kbadge { font-size: 11px; padding: 0 6px; border-radius: 6px; background: var(--brand-soft); color: var(--brand); }

.composer { border-top: 1px solid var(--line); padding: 10px 12px; display: flex; flex-direction: column; gap: 7px; }
.composer .rowline { display: flex; gap: 6px; }
.composer select, .composer input[type=text] { padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; font-family: inherit; font-size: 13.5px; background: #fff; }
.composer input[type=text] { flex: 1; }
.composer .send { background: var(--brand); color: #fff; border: none; border-radius: 8px; padding: 0 14px; }
.composer .agent { background: #fff; color: var(--accent); border: 1px solid #d9caff; border-radius: 8px; padding: 7px; font-size: 13px; }
.composer .leave { background: none; border: none; color: var(--muted); font-size: 12px; text-decoration: underline; padding: 2px; align-self: flex-start; }
.composer .leave:hover { color: var(--danger); }
.composer .opts { display: flex; align-items: center; gap: 10px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.name-gate { padding: 22px 16px; text-align: center; }
.name-gate input { width: 100%; padding: 9px; border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; font-family: inherit; }
.typing { font-size: 12px; color: var(--accent); padding: 0 14px 6px; }

@media (max-width: 820px) {
  .proj-cols { grid-template-columns: 1fr; }
  .side { position: static; }
  .form-grid { grid-template-columns: 1fr; }
  .chat-drawer { width: 100%; }
}

/* Card actions (edit / delete) + edit modal */
.card-actions { display: flex; gap: 8px; margin-top: 10px; }
.card-actions .btn { flex: 1; }
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; z-index: 2000;
}
.modal-box {
  width: 100%; max-width: 460px; max-height: calc(100vh - 32px);
  overflow-y: auto; background: #fff;
}
.modal-x {
  background: none; border: none; font-size: 22px; line-height: 1;
  cursor: pointer; color: var(--muted);
}
.modal-x:hover { color: var(--ink); }
