/*
 * Палитра целиком берётся из темы Telegram: клиент подставляет свои цвета,
 * а запасные значения нужны только для открытия в обычном браузере.
 */
:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #8b9398);
  --subtitle: var(--tg-theme-subtitle-text-color, var(--hint));
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-secondary-bg-color, #232e3c));
  --section-head: var(--tg-theme-section-header-text-color, var(--hint));
  --accent: var(--tg-theme-button-color, #3390ec);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --link: var(--tg-theme-link-color, #6ab3f3);
  --danger: var(--tg-theme-destructive-text-color, #e0564f);
  --ok: #4dab5b;
  --warn: #d8a13a;
  --radius: 14px;
  --gap: 10px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior-y: contain;
}

button,
input,
textarea,
select {
  font: inherit;
  color: inherit;
}

.muted { color: var(--hint); }
.small { font-size: 13px; }
.mono { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }

/* ── выбор проекта ──────────────────────────────────────── */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 6px;
  margin-bottom: 12px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  border: 1px solid transparent;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}
.chip[data-active="1"] {
  border-color: var(--accent);
  color: var(--accent);
}
.chip.add {
  font-weight: 600;
  color: var(--link);
  padding-inline: 13px;
}

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: var(--hint);
}
.dot.busy { background: var(--warn); animation: pulse 1.4s infinite; }
.dot.up { background: var(--ok); }
.dot.off { background: var(--hint); opacity: .5; }
@keyframes pulse { 50% { opacity: .3; } }

/* ── карточки ───────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: var(--gap);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.section-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--section-head);
  margin: 16px 4px 8px;
  font-weight: 600;
}

.status { display: flex; align-items: center; gap: 8px; font-size: 14px; }

.prompt-line {
  margin-top: 8px;
  font-size: 14px;
  color: var(--subtitle);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tools { margin-top: 10px; display: flex; flex-direction: column; gap: 5px; }
.tool { display: flex; gap: 8px; align-items: baseline; font-size: 13px; min-width: 0; }
.tool .mark { color: var(--ok); width: 12px; flex: 0 0 auto; }
.tool.now .mark { color: var(--warn); }
.tool .name { font-weight: 600; flex: 0 0 auto; }
.tool .sum {
  color: var(--hint);
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── ввод задачи ────────────────────────────────────────── */
textarea {
  width: 100%;
  min-height: 78px;
  resize: vertical;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px;
  font-size: 15px;
}
input[type="text"] {
  width: 100%;
  background: var(--bg);
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px;
  font-size: 15px;
}
textarea:focus,
input:focus { outline: none; border-color: var(--accent); }

.field { margin-bottom: 10px; }
.field label {
  display: block;
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 5px;
}
.field .hint { font-size: 12px; color: var(--hint); margin-top: 4px; }

.buttons { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

button {
  flex: 1 1 auto;
  padding: 11px 14px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
}
button.ghost { background: var(--bg); color: var(--text); font-weight: 500; }
button.danger { background: transparent; color: var(--danger); font-weight: 600; }
button:disabled { opacity: .4; }

/* ── переключатели модели и усилий ──────────────────────── */
.pills { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.pill {
  padding: 6px 11px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--hint);
  font-size: 13px;
  cursor: pointer;
  border: 1px solid transparent;
}
.pill[data-active="1"] {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

/* ── вкладки ────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; margin: 14px 0 10px; }
.tab {
  flex: 1;
  text-align: center;
  padding: 8px 4px;
  border-radius: 9px;
  background: transparent;
  color: var(--hint);
  font-size: 13px;
  cursor: pointer;
}
.tab[data-active="1"] { background: var(--card); color: var(--text); font-weight: 600; }

/* ── логи ───────────────────────────────────────────────── */
.log-wrap { position: relative; }
pre.logs {
  margin: 0;
  padding: 10px;
  background: var(--card);
  border-radius: var(--radius);
  font: 12px/1.5 ui-monospace, "SF Mono", Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 52vh;
  overflow-y: auto;
}
.logs .err { color: var(--danger); }
.logs .sys { color: var(--hint); font-style: italic; }

.to-bottom {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: auto;
  flex: 0 0 auto;
  padding: 6px 12px;
  font-size: 12px;
  border-radius: 999px;
  opacity: .92;
}

/* ── история ────────────────────────────────────────────── */
.hist {
  display: flex;
  gap: 8px;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid var(--bg);
  cursor: pointer;
}
.hist:last-child { border-bottom: 0; }
.hist .txt {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

/* ── расход ─────────────────────────────────────────────── */
.stat { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.stat .val { font-variant-numeric: tabular-nums; }
.bar { height: 4px; border-radius: 2px; background: var(--accent); margin-top: 5px; opacity: .8; }

/* ── шторка ─────────────────────────────────────────────── */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, .45);
  display: flex;
  align-items: flex-end;
  z-index: 10;
}
.sheet {
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 14px 14px calc(18px + env(safe-area-inset-bottom));
  animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(18px); opacity: .6; } }

.sheet h2 { margin: 2px 0 14px; font-size: 17px; }
.sheet .grabber {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--hint);
  opacity: .4;
  margin: 0 auto 10px;
}

.result-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
  max-height: 40vh;
  overflow-y: auto;
}

.empty { text-align: center; color: var(--hint); padding: 30px 12px; font-size: 14px; }
.error-box {
  background: var(--danger);
  color: #fff;
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 10px;
  font-size: 14px;
}
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--card);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .3);
  z-index: 20;
}
