:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --border: #dfe3dd;
  --text: #17201b;
  --muted: #5d6a62;
  --accent: #0f7a5c;
  --accent-hover: #0b6249;
  --accent-soft: #e3f3ec;
  --on-accent: #ffffff;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --warn: #8a5a00;
  --warn-soft: #fff4d6;
  --bubble-user: #d9f6e5;
  --bubble-bot: #ffffff;
  --chat-bg: #eef1ec;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 20, 0.06), 0 4px 16px rgba(16, 24, 20, 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1412;
    --surface: #171e1b;
    --surface-2: #1e2723;
    --border: #2c3732;
    --text: #e7ede9;
    --muted: #9aa8a0;
    --accent: #34b98a;
    --accent-hover: #4fcb9e;
    --accent-soft: #163329;
    --on-accent: #06140e;
    --danger: #f2877d;
    --danger-soft: #3a1d1a;
    --warn: #f1c25b;
    --warn-soft: #352a12;
    --bubble-user: #1d4434;
    --bubble-bot: #222c28;
    --chat-bg: #121815;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Hebrew", sans-serif;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-weight: 650;
}

.topbar .logo {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--on-accent);
  display: grid;
  place-items: center;
}

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 16px 64px;
}

main.narrow { max-width: 680px; }

h1 { font-size: 1.75rem; line-height: 1.25; margin: 0 0 8px; letter-spacing: -0.01em; }
h2 { font-size: 1.15rem; margin: 0 0 12px; }
p { margin: 0 0 12px; }
.lead { color: var(--muted); font-size: 1.05rem; margin-bottom: 24px; }
.muted { color: var(--muted); }
.small { font-size: 0.875rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

/* ---- Stepper ---- */
.steps {
  display: flex;
  gap: 8px;
  list-style: none;
  padding: 0;
  margin: 0 0 28px;
  flex-wrap: wrap;
}
.steps li {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 550;
}
.steps li:not(:last-child)::after {
  content: "";
  width: 28px;
  height: 1px;
  background: var(--border);
  margin-left: 4px;
}
.steps .num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  display: grid;
  place-items: center;
  font-size: 0.8rem;
}
.steps li.active { color: var(--text); }
.steps li.active .num { border-color: var(--accent); color: var(--accent); }
.steps li.done .num { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ---- Lists & choices ---- */
.checklist { list-style: none; padding: 0; margin: 0; display: grid; gap: 10px; }
.checklist li { display: flex; gap: 10px; }
.checklist li::before { content: "✓"; color: var(--accent); font-weight: 700; }

.choices { display: grid; gap: 12px; margin: 4px 0 20px; }
.choice {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 16px;
  border: 1.5px solid var(--border);
  border-radius: 12px;
  cursor: pointer;
  background: var(--surface);
}
.choice:hover { border-color: var(--muted); }
.choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice input { margin-top: 4px; accent-color: var(--accent); width: 18px; height: 18px; flex: none; }
.choice strong { display: block; margin-bottom: 2px; }
.choice span { color: var(--muted); font-size: 0.925rem; }

/* ---- Buttons & inputs ---- */
button, .button {
  font: inherit;
  font-weight: 600;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 11px 18px;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
}
button:disabled { opacity: 0.55; cursor: not-allowed; }
.primary { background: var(--accent); color: var(--on-accent); }
.primary:hover:not(:disabled) { background: var(--accent-hover); }
.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.secondary:hover:not(:disabled) { background: var(--surface-2); }
.ghost { background: transparent; color: var(--muted); padding: 6px 10px; min-height: 32px; font-weight: 550; }
.ghost:hover { color: var(--text); }
.danger { background: var(--danger-soft); color: var(--danger); }
.fb { background: #1877f2; color: #fff; }
.fb:hover:not(:disabled) { background: #0f63d1; }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

textarea, input[type="text"] {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}
textarea:focus, input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
textarea.prompt {
  min-height: 460px;
  resize: vertical;
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 0.9rem;
  line-height: 1.6;
}
label.field { display: block; font-weight: 600; margin-bottom: 6px; }

.copy-row { display: flex; gap: 8px; }
.copy-row input { font-family: ui-monospace, Consolas, monospace; font-size: 0.85rem; min-width: 0; }

/* ---- Notices ---- */
.notice { border-radius: 10px; padding: 12px 14px; margin: 12px 0; font-size: 0.95rem; }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.ok { background: var(--accent-soft); color: var(--accent); }
.notice:empty { display: none; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}
.badge.on { background: var(--accent-soft); color: var(--accent); }
.badge.on::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* ---- Editor + chat layout ---- */
.editor-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 860px) { .editor-grid { grid-template-columns: 1fr; } textarea.prompt { min-height: 360px; } }

.chat {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 16px;
}
.chat header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.chat header strong { display: block; font-size: 0.95rem; }
.chat header span { font-size: 0.8rem; color: var(--muted); }
.chat .log {
  background: var(--chat-bg);
  height: 380px;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat .empty { margin: auto; text-align: center; color: var(--muted); font-size: 0.9rem; max-width: 240px; }
.bubble {
  max-width: 85%;
  padding: 8px 12px;
  border-radius: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 0.95rem;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}
.bubble.user { align-self: flex-end; background: var(--bubble-user); border-bottom-right-radius: 4px; }
.bubble.assistant { align-self: flex-start; background: var(--bubble-bot); border-bottom-left-radius: 4px; }
.bubble.error { align-self: center; background: var(--danger-soft); color: var(--danger); font-size: 0.85rem; }
.bubble.typing { color: var(--muted); font-style: italic; }
.chat form { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--border); }
.chat form input { padding: 10px 12px; }
.chat form button { padding: 10px 14px; }

/* ---- Misc ---- */
.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  animation: spin 0.9s linear infinite;
  margin: 8px auto 16px;
}
@keyframes spin { to { transform: rotate(360deg); } }
.center { text-align: center; }
.hidden { display: none !important; }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 600; }
.switch input { appearance: none; width: 46px; height: 26px; border-radius: 999px; background: var(--border); position: relative; cursor: pointer; transition: background 0.15s; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: 0 1px 2px rgba(0,0,0,0.2); }
.switch input:checked { background: var(--accent); }
.switch input:checked::after { transform: translateX(20px); }

.stats { display: flex; gap: 28px; flex-wrap: wrap; margin-top: 16px; }
.stats div { display: flex; flex-direction: column; }
.stats strong { font-size: 1.35rem; }
.stats span { color: var(--muted); font-size: 0.85rem; }

.tenant-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }

.narrow-section { max-width: 680px; }

/* ---- Message templates ---- */
.badge.bad { background: var(--danger-soft); color: var(--danger); }
.template { border-top: 1px solid var(--border); padding: 14px 0; }
.template-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.template-head .spacer { flex: 1; }
.template-body { margin: 8px 0 0; white-space: pre-wrap; color: var(--muted); font-size: 0.925rem; }
.send-form { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.send-form input { flex: 1 1 200px; width: auto; }
details.create { margin-top: 16px; }
details.create summary { list-style: none; width: fit-content; }
details.create summary::-webkit-details-marker { display: none; }
.template-form { margin-top: 16px; display: grid; gap: 8px; }
.template-form .field { margin: 8px 0 0; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 600px) { .form-row { grid-template-columns: 1fr; } }
select {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
}
.examples { display: grid; gap: 8px; }
