/* Оформление под Telegram Mini App: цвета берутся из темы клиента, поэтому
   приложение выглядит светлым в светлой теме и тёмным в тёмной. */

:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --fg: var(--tg-theme-text-color, #f5f5f5);
  --muted: var(--tg-theme-hint-color, #7f8c99);
  --panel: var(--tg-theme-secondary-bg-color, #0e1621);
  --accent: var(--tg-theme-button-color, #40a7e3);
  --accent-fg: var(--tg-theme-button-text-color, #fff);
  --border: rgba(127,127,127,.20);
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── шапка ─────────────────────────────────────────────────────────── */

.top, .panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex: none;
}

.where { flex: 1; min-width: 0; }

button.where {
  background: none;
  border: 0;
  padding: 2px 4px;
  border-radius: 8px;
  text-align: left;
  color: inherit;
  cursor: pointer;
}
button.where:active { background: rgba(127,127,127,.20); }

.title {
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.path {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: rtl;
  text-align: left;
}

.ghost {
  background: none;
  border: 0;
  color: var(--fg);
  font-size: 19px;
  padding: 6px 8px;
  cursor: pointer;
  border-radius: 8px;
}
.ghost:active { background: rgba(127,127,127,.20); }

/* ── строка состояния соединения ───────────────────────────────────── */

.status {
  flex: none;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 12px;
  border-bottom: 1px solid var(--border);
}
.status:empty { display: none; }
.status.bad { color: #e57373; }

/* ── лента ─────────────────────────────────────────────────────────── */

.log {
  flex: 1;
  overflow-y: auto;
  padding: 12px 10px;
  -webkit-overflow-scrolling: touch;
}

.msg { margin-bottom: 12px; max-width: 100%; }

.msg .who {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 3px;
}

.msg .body {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

.msg.user .body {
  background: var(--accent);
  color: var(--accent-fg);
  padding: 9px 12px;
  border-radius: 14px 14px 4px 14px;
  display: inline-block;
  max-width: 88%;
}

.msg.assistant .body {
  background: var(--panel);
  padding: 10px 12px;
  border-radius: 4px 14px 14px 14px;
}

.msg.tool .body {
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 12.5px;
  color: var(--muted);
  background: none;
  padding: 1px 0 1px 10px;
  border-left: 2px solid var(--border);
  white-space: pre-wrap;
  overflow-x: auto;
}

.msg.error .body { color: #e57373; }

.msg code {
  font-family: ui-monospace, "Cascadia Code", Menlo, monospace;
  font-size: 13px;
  background: rgba(127,127,127,.20);
  padding: 1px 4px;
  border-radius: 4px;
}

.msg pre {
  background: rgba(127,127,127,.20);
  padding: 9px 10px;
  border-radius: 8px;
  overflow-x: auto;
}
.msg pre code { background: none; padding: 0; }

.msg a { color: var(--accent); }

/* ── панель файлов ─────────────────────────────────────────────────── */

.panel {
  position: fixed;
  inset: 0;
  top: 8vh;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.hidden { display: none !important; }

.files { flex: 1; overflow-y: auto; padding: 6px 8px; }

.file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 10px;
  border-radius: 10px;
  cursor: pointer;
}
.file:active { background: rgba(127,127,127,.20); }
.file.current { background: rgba(127,127,127,.14); }
.file .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file .size { font-size: 12px; color: var(--muted); flex: none; white-space: nowrap; }
.file .act { flex: none; font-size: 11px; color: var(--accent); }

.panel-foot { flex: none; padding: 10px; border-top: 1px solid var(--border); }

.btn {
  display: inline-block;
  text-align: center;
  padding: 11px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
}
.btn.primary { background: var(--accent); color: var(--accent-fg); width: 100%; }

/* ── поле ввода ────────────────────────────────────────────────────── */

.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 10px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}

.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 10px 12px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  outline: none;
}

.send {
  flex: none;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 17px;
  cursor: pointer;
}
.send.stop { background: #e57373; }
.send:disabled { opacity: 0.45; }