:root {
  --bg: #14161a;
  --panel: #1b1e24;
  --panel-2: #22262e;
  --line: #2c313b;
  --text: #e6e8ec;
  --dim: #8b93a1;
  --accent: #6ea8fe;
  --ok: #4ec98a;
  --no: #f2777a;
  --warn: #e0a24a;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* Явный display в правилах ниже перебил бы атрибут hidden — закрываем это. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

body { display: flex; flex-direction: column; }

/* ─── вход ──────────────────────────────────────────────────────────────── */
.login {
  position: fixed; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: var(--bg);
  padding: 20px;
}
.login-box {
  width: min(340px, 100%);
  display: flex; flex-direction: column; gap: 12px;
}
.login-box h1 { margin: 0 0 8px; font-size: 20px; font-weight: 600; }
.login-box input, .login-box button {
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 16px; /* iOS не зумит поле при фокусе */
}
.login-box button {
  background: var(--accent); color: #10131a;
  font-weight: 600; border: 0; cursor: pointer;
}
.err { color: var(--no); margin: 0; font-size: 14px; }

/* ─── шапка и вкладки ───────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100%; min-height: 0; }

.top {
  display: flex; align-items: center; gap: 6px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  padding: 6px 6px 6px 8px;
  padding-top: max(6px, env(safe-area-inset-top));
  flex: none;
}
.tabs {
  display: flex; gap: 6px; overflow-x: auto; flex: 1;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: none;
  display: flex; align-items: center; gap: 6px;
  padding: 8px 12px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  background: var(--panel-2);
  color: var(--dim);
  cursor: pointer;
  white-space: nowrap;
  font-size: 14px;
}
.tab.active { color: var(--text); border-color: var(--accent); }
.tab .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--dim); flex: none;
}
.tab .dot.working { background: var(--accent); }
.tab .dot.waiting { background: var(--warn); }
.tab .dot.idle    { background: var(--dim); }
.tab .pulse { color: var(--ok); font-size: 12px; }
.tab .badge {
  background: var(--no); color: #fff;
  border-radius: 9px; padding: 0 6px;
  font-size: 11px; font-weight: 700;
}

.ghost {
  flex: none;
  background: transparent; border: 0; color: var(--dim);
  font-size: 22px; line-height: 1; cursor: pointer;
  padding: 4px 10px;
}

.subbar {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  font-size: 12px; color: var(--dim);
  flex: none;
}
.cwd { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.hold { display: flex; align-items: center; gap: 6px; cursor: pointer; flex: none; }
.hold input { accent-color: var(--accent); width: 16px; height: 16px; }

/* ─── лента ─────────────────────────────────────────────────────────────── */
.feed {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 12px;
  display: flex; flex-direction: column; gap: 10px;
  -webkit-overflow-scrolling: touch;
}
.empty { color: var(--dim); text-align: center; margin-top: 40px; }

.msg { max-width: 100%; }
.msg .who { font-size: 11px; color: var(--dim); margin-bottom: 3px; }
.msg .body {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 9px 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user .body { background: #23303f; border-color: #2f4358; }
.msg.assistant .body { background: var(--panel); }

.msg.thinking .body,
.msg.tool_use .body,
.msg.tool_result .body {
  background: transparent;
  border-style: dashed;
  color: var(--dim);
  font-family: ui-monospace, "Cascadia Code", Consolas, monospace;
  font-size: 12.5px;
}
details.fold > summary {
  cursor: pointer; color: var(--dim); font-size: 12px;
  padding: 4px 0; list-style: none;
}
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: "▸ "; }
details.fold[open] > summary::before { content: "▾ "; }
details.fold pre {
  margin: 4px 0 0;
  padding: 8px 10px;
  background: #0f1115;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
  font-size: 12px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 320px;
}

/* ─── карточки разрешений ───────────────────────────────────────────────── */
.perms { flex: none; }
.perm {
  margin: 0 12px 10px;
  border: 1px solid var(--warn);
  border-radius: var(--radius);
  background: #241f16;
  padding: 10px 12px;
}
.perm h3 { margin: 0 0 4px; font-size: 14px; }
.perm .desc { color: var(--dim); font-size: 13px; margin-bottom: 6px; }
.perm pre {
  margin: 0 0 10px;
  background: #0f1115;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  overflow-x: auto;
  font-size: 12px;
  max-height: 220px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.perm .row { display: flex; gap: 8px; }
.perm button {
  flex: 1;
  padding: 11px;
  border: 0; border-radius: 8px;
  font-weight: 600; font-size: 15px; cursor: pointer;
}
.perm .allow { background: var(--ok); color: #0d1a13; }
.perm .deny  { background: var(--no); color: #2a0f10; }

.hint {
  flex: none;
  margin: 0 12px 8px;
  padding: 8px 11px;
  border: 1px solid var(--warn);
  border-radius: 8px;
  background: #241f16;
  color: var(--warn);
  font-size: 13px;
}
.hint button {
  margin-left: 8px;
  background: var(--warn); color: #241f16;
  border: 0; border-radius: 6px; padding: 4px 10px;
  font-weight: 600; cursor: pointer;
}

/* ─── ввод команды ──────────────────────────────────────────────────────── */
.composer {
  flex: none;
  display: flex; gap: 8px; align-items: flex-end;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 10px 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: 16px;
}
.composer button {
  flex: none;
  width: 44px; height: 44px;
  border: 0; border-radius: 50%;
  background: var(--accent); color: #10131a;
  font-size: 20px; font-weight: 700; cursor: pointer;
}
.composer button:disabled { opacity: .4; cursor: default; }

@media (min-width: 800px) {
  .feed { padding: 16px 24px; }
  .perm { margin: 0 24px 12px; }
  .composer { padding-left: 24px; padding-right: 24px; }
}
