:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #17202a;
  --muted: #5d6b7a;
  --line: #e1e5ea;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --warn: #b45309;
  --warn-soft: #fef3c7;
  --danger: #b91c1c;
  --danger-soft: #fee2e2;
  --ok: #15803d;
  --ok-soft: #dcfce7;
  --user-bubble: #e0f2fe;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Hebrew", "Arial Hebrew", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1117;
    --surface: #121a23;
    --surface-2: #18222d;
    --text: #e6edf3;
    --muted: #93a1b0;
    --line: #233140;
    --accent: #5eead4;
    --accent-soft: #123a37;
    --warn: #fbbf24;
    --warn-soft: #3a2c0b;
    --danger: #f87171;
    --danger-soft: #3b1313;
    --ok: #4ade80;
    --ok-soft: #12321e;
    --user-bubble: #13304a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--accent); }
button, input, textarea, select { font: inherit; color: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; text-decoration: none; color: var(--text); white-space: nowrap; }
.nav { display: flex; gap: 4px; overflow-x: auto; }
.nav a {
  padding: 6px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--muted);
  white-space: nowrap;
}
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.view { max-width: 860px; margin: 0 auto; padding: 16px; padding-bottom: 80px; }

h1 { font-size: 1.35rem; margin: 4px 0 12px; line-height: 1.3; }
h2 { font-size: 1.1rem; margin: 20px 0 8px; }
h3 { font-size: 1rem; margin: 14px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.spacer { flex: 1; }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-bottom: 10px;
}
a.card { display: block; color: inherit; text-decoration: none; }
a.card:active { transform: scale(0.995); }
.card-title { font-weight: 600; margin-bottom: 6px; overflow-wrap: anywhere; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  white-space: nowrap;
}
.chip.warn { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.dot.running { background: var(--ok); animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

.filters { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.filters button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 999px;
  padding: 5px 12px;
  white-space: nowrap;
  cursor: pointer;
}
.filters button.active { background: var(--text); color: var(--surface); border-color: var(--text); }

.btn {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 10px;
  padding: 9px 14px;
  cursor: pointer;
  min-height: 42px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
@media (prefers-color-scheme: dark) { .btn.primary { color: #062320; } }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: 0.55; cursor: default; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-group .btn { flex: 1 1 120px; }

textarea, input[type="text"], input[type="password"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  padding: 10px 12px;
  min-height: 44px;
}
textarea { resize: vertical; min-height: 90px; }
textarea.code { font-family: var(--mono); font-size: 0.85rem; min-height: 55vh; direction: ltr; text-align: left; }
label { display: block; font-size: 0.9rem; color: var(--muted); margin: 10px 0 4px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 10px 0 14px; overflow-x: auto; }
.tabs button {
  border: none;
  background: none;
  padding: 9px 12px;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

.plan .summary { font-size: 1.02rem; }
.plan ol, .plan ul { padding-inline-start: 22px; margin: 6px 0; }
.plan li { margin: 4px 0; }
.tier { font-size: 0.75rem; padding: 1px 7px; border-radius: 6px; margin-inline-start: 6px; white-space: nowrap; }
.tier-0 { background: var(--surface-2); color: var(--muted); }
.tier-1 { background: var(--ok-soft); color: var(--ok); }
.tier-2 { background: var(--warn-soft); color: var(--warn); }
.tier-3 { background: var(--danger-soft); color: var(--danger); }
.owner { font-size: 0.75rem; color: var(--muted); margin-inline-start: 6px; }
details.past { margin-bottom: 8px; }
details.past summary { cursor: pointer; padding: 8px 0; }

.chat { display: flex; flex-direction: column; gap: 8px; }
.msg {
  max-width: 92%;
  padding: 10px 12px;
  border-radius: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.msg.user { align-self: flex-start; background: var(--user-bubble); border-color: transparent; }
.msg.agent { align-self: flex-end; }
.msg .meta { font-size: 0.75rem; color: var(--muted); margin-top: 4px; }
.msg p { margin: 0 0 6px; }
.msg p:last-child { margin-bottom: 0; }
.msg ul, .msg ol { margin: 4px 0; padding-inline-start: 20px; }
.msg code, .mono { font-family: var(--mono); font-size: 0.85em; background: var(--surface-2); padding: 0 4px; border-radius: 4px; }
.msg.system-like { white-space: pre-wrap; font-size: 0.88rem; }
details.tools { align-self: stretch; font-size: 0.85rem; color: var(--muted); }
details.tools summary { cursor: pointer; padding: 2px 0; }
.toolline { font-family: var(--mono); font-size: 0.78rem; direction: ltr; text-align: left; padding: 3px 8px; border-inline-start: 2px solid var(--line); margin: 2px 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.toolline.err { border-color: var(--danger); color: var(--danger); }
.statusline { align-self: center; font-size: 0.78rem; color: var(--muted); }
.working { align-self: center; font-size: 0.85rem; color: var(--ok); display: flex; align-items: center; gap: 8px; }

.composer {
  position: sticky;
  bottom: 0;
  background: var(--bg);
  padding: 10px 0 max(10px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.composer textarea { min-height: 46px; max-height: 40vh; }

.list-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.list-item:last-child { border-bottom: none; }
.list { padding: 0; overflow: hidden; }
.path { font-family: var(--mono); font-size: 0.88rem; direction: ltr; overflow-wrap: anywhere; }

.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; font-size: 0.9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.login { max-width: 360px; margin: 12vh auto 0; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.error-box { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 10px 12px; margin: 10px 0; }

.toast {
  position: fixed;
  bottom: max(18px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--surface);
  padding: 10px 16px;
  border-radius: 10px;
  z-index: 50;
  max-width: calc(100% - 32px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}

.mt-0 { margin-top: 0; }
.mt-4 { margin-top: 4px; }
.mt-10 { margin-top: 10px; }
.mt-12 { margin-top: 12px; }
.w-100 { width: 100%; }
.list-item.block { display: block; }
.pre { white-space: pre-wrap; }

/* long links and ids must wrap instead of widening the page */
.card, .plan, .msg, .error-box { overflow-wrap: anywhere; }
.plan a, .msg a, .kv dd { word-break: break-all; }
html, body { max-width: 100%; overflow-x: hidden; }

details.past > summary { list-style: none; display: flex; align-items: center; gap: 8px; }
details.past > summary::-webkit-details-marker { display: none; }
details.past > summary::before { content: "▸"; color: var(--muted); transition: transform 0.15s; }
details.past[open] > summary::before { transform: rotate(90deg); }
details.past > summary .row { flex: 1; }
details.tools > summary { list-style: none; }
details.tools > summary::-webkit-details-marker { display: none; }
details.tools > summary::before { content: "▸ "; }
details.tools[open] > summary::before { content: "▾ "; }

.path { unicode-bidi: isolate; }
.switch .btn { white-space: nowrap; flex-shrink: 0; }
.msg.system-like .meta { direction: rtl; text-align: right; }
