/* TG Claude IDE — мобайл-first. Тема живёт в --tg-* (заполняется app.js). */

:root {
  --tg-bg: #17212b;
  --tg-text: #f5f5f5;
  --tg-hint: #7d8b99;
  --tg-link: #64baf0;
  --tg-btn: #5288c1;
  --tg-btn-text: #ffffff;
  --tg-secondary-bg: #232e3c;
  --tg-header-bg: #17212b;
  --tg-destructive: #ec3942;
  --tg-accent: #64baf0;
  --tg-subtitle: #7d8b99;

  --border: rgba(255, 255, 255, 0.08);
  --tabbar-h: 60px;
  --topbar-h: 48px;
  --radius: 10px;
  --gap: 10px;
  --touch: 44px;

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

[data-theme="light"] {
  --border: rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.4;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

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

pre, code, kbd, samp {
  font-family: var(--font-mono);
  font-size: 13px;
}

a { color: var(--tg-link); text-decoration: none; }
a:active { opacity: 0.7; }

/* --- Каркас приложения --------------------------------------------------- */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  height: var(--topbar-h);
  padding: 0 14px;
  background: var(--tg-header-bg);
  border-bottom: 1px solid var(--border);
  padding-top: env(safe-area-inset-top, 0);
  height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
}

.topbar-title {
  font-weight: 600;
  font-size: 16px;
  letter-spacing: 0.2px;
}

.topbar-status {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--tg-hint);
}

.topbar-status.status-warn {
  color: var(--tg-destructive);
}

.tabs {
  flex: 1 1 auto;
  position: relative;
  overflow: hidden;
}

.tab-panel {
  display: none;
  height: 100%;
  overflow: auto;
  padding: 12px 12px calc(76px + env(safe-area-inset-bottom, 0px)) 12px;   /* место под FAB'ы */
  -webkit-overflow-scrolling: touch;
}

.tab-panel.tab-active {
  display: block;
}

.tab-placeholder {
  padding: 24px 12px;
  text-align: center;
  color: var(--tg-hint);
  font-size: 14px;
}

/* --- FAB'ы + бургер-меню разделов ---------------------------------------- */

.fab {
  position: fixed;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 30;
  width: 52px;
  height: 52px;
  border: none;
  border-radius: 50%;
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  font-size: 22px;
  line-height: 1;
  box-shadow: 0 3px 12px rgba(0,0,0,0.4);
  cursor: pointer;
}
.fab-left { left: 16px; }
.fab-right { right: 16px; }

/* Кнопка «вниз чата» — полупрозрачная, с блюром, плавно появляется */
.fab-right {
  background: color-mix(in srgb, var(--tg-btn) 55%, transparent);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: opacity 0.18s ease;
}
.fab-right[hidden] { display: none; }
.fab:active { opacity: 0.7; }

/* Всплывающее меню разделов над бургером */
.tab-menu {
  position: fixed;
  left: 16px;
  bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  z-index: 30;
  display: flex;
  flex-direction: column;
  min-width: 160px;
  padding: 6px;
  gap: 2px;
  background: var(--tg-header-bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.45);
}
.tab-menu[hidden] { display: none; }

.tab-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 14px;
  background: transparent;
  border: 0;
  border-radius: 10px;
  color: var(--tg-text);
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.tab-btn:active { opacity: 0.7; }
.tab-btn.tab-active { background: var(--tg-secondary-bg); color: var(--tg-accent); }

.tab-ico { font-size: 18px; line-height: 1; width: 20px; text-align: center; }
.tab-lbl { font-size: 15px; }

/* --- Универсальные контролы --------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--touch);
  padding: 10px 16px;
  border: 0;
  border-radius: var(--radius);
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.12s ease;
}
.btn:active { opacity: 0.75; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-ghost {
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
}

.btn-danger {
  background: var(--tg-destructive);
  color: #fff;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
  border-radius: 8px;
}

.input, .textarea, .select {
  width: 100%;
  min-height: var(--touch);
  padding: 10px 12px;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}

.textarea {
  min-height: 96px;
  resize: vertical;
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
}

.input:focus, .textarea:focus, .select:focus {
  border-color: var(--tg-accent);
}

.select {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--tg-hint) 50%),
                    linear-gradient(135deg, var(--tg-hint) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 34px;
}

.label {
  display: block;
  font-size: 12px;
  color: var(--tg-hint);
  margin: 8px 0 4px;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: var(--tg-secondary-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
}

.hint {
  color: var(--tg-hint);
  font-size: 12px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--tg-secondary-bg);
  color: var(--tg-hint);
  border: 1px solid var(--border);
}

.badge-ok { background: rgba(64, 180, 120, 0.18); color: #58c39a; border-color: transparent; }
.badge-run { background: rgba(100, 186, 240, 0.18); color: var(--tg-accent); border-color: transparent; }
.badge-err { background: rgba(236, 57, 66, 0.2); color: var(--tg-destructive); border-color: transparent; }

pre.code, .code-block {
  background: var(--tg-secondary-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  overflow-x: auto;
  white-space: pre;
  font-family: var(--font-mono);
  font-size: 13px;
}

code.inline {
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--tg-secondary-bg);
  font-family: var(--font-mono);
  font-size: 0.92em;
}

/* --- Экран «не ты» ------------------------------------------------------- */

.not-you {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 24px;
  text-align: center;
}
.not-you h2 { margin: 0; font-size: 22px; }
.not-you p { margin: 0; color: var(--tg-hint); max-width: 320px; }

/* --- Спиннер ------------------------------------------------------------- */

.spinner {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  background: color-mix(in srgb, var(--tg-bg) 85%, transparent);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
}

.spinner.spin-on {
  opacity: 1;
  pointer-events: auto;
}

.spinner-ring {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border);
  border-top-color: var(--tg-accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.spinner-label {
  color: var(--tg-hint);
  font-size: 13px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Тосты --------------------------------------------------------------- */

.toast-box {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: min(92vw, 480px);
  pointer-events: none;
}

.toast {
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  border: 1px solid var(--border);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
  font-size: 13px;
  opacity: 0;
  transform: translateY(-6px);
  animation: toast-in 0.18s ease forwards;
  pointer-events: auto;
}
.toast-err { border-color: var(--tg-destructive); color: var(--tg-destructive); }
.toast-ok { border-color: #58c39a; color: #58c39a; }
.toast-out { animation: toast-out 0.6s ease forwards; }

@keyframes toast-in {
  to { opacity: 1; transform: translateY(0); }
}
@keyframes toast-out {
  to { opacity: 0; transform: translateY(-6px); }
}

/* --- Оверлей (для файлового дека и модалок из S9) ----------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  flex-direction: column;
  background: var(--tg-bg);
}

.overlay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 10px);
  border-bottom: 1px solid var(--border);
  background: var(--tg-header-bg);
}

.overlay-body {
  flex: 1 1 auto;
  overflow: auto;
  padding: 12px;
}

.overlay-close {
  min-width: var(--touch);
  min-height: var(--touch);
  border: 0;
  background: transparent;
  color: var(--tg-text);
  font-size: 22px;
  cursor: pointer;
}

/* --- Утилиты ------------------------------------------------------------- */

.hidden { display: none !important; }
.grow { flex: 1 1 auto; }
.mono { font-family: var(--font-mono); }
.mt-8 { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.dim { color: var(--tg-hint); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --- Формы UI-модулей (S8/S9 используют свои классы — стилизуем голые элементы,
       чтобы нативные белые контролы не слепли в тёмной теме) ------------------ */
.tab-panel select,
.tab-panel input:not([type="checkbox"]):not([type="radio"]),
.tab-panel textarea {
  min-height: 40px;
  padding: 8px 12px;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  max-width: 100%;
}
.tab-panel textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  line-height: 1.5;
}
.tab-panel select:focus,
.tab-panel input:focus,
.tab-panel textarea:focus { border-color: var(--tg-accent); }
.tab-panel select {
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--tg-hint) 50%),
                    linear-gradient(135deg, var(--tg-hint) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-right: 30px;
}
.tab-panel button {
  min-height: 40px;
  padding: 8px 16px;
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
}
.tab-panel button:disabled { opacity: 0.45; }
.tab-panel button:active { opacity: 0.8; }

/* Шапка чата: ряды выбора сессии/проекта/модели — флекс с переносом, метки-подсказки */
.chat-header { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.chat-header-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.chat-meta-label { color: var(--tg-hint); font-size: 13px; }
.chat-session-select { flex: 1 1 160px; min-width: 120px; }
.chat-project-select { flex: 1 1 130px; min-width: 110px; }
.chat-model-select, .chat-effort-select { flex: 0 1 auto; min-width: 86px; }
.chat-new-btn { flex: 0 0 auto; width: 40px; padding: 8px 0; }

/* Композер внизу вкладки чата */
.chat-composer { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--border); }
.chat-composer-row { display: flex; gap: 8px; align-items: flex-end; }
.chat-input { flex: 1; }
.chat-list { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
.chat-ultra-lbl { color: var(--tg-hint); font-size: 13px; margin-left: 2px; }
.chat-composer-row input[type="checkbox"] { min-height: auto; width: 18px; height: 18px; accent-color: var(--tg-accent); }
.chat-file-chip { display: inline-flex; align-items: center; gap: 6px; margin: 6px 8px 0 0;
  padding: 6px 12px; min-height: 34px; font-size: 13px; font-weight: 500;
  background: var(--tg-secondary-bg); color: var(--tg-link); border: 1px solid var(--border); border-radius: 17px; }
.chat-file-chip:active { opacity: 0.7; }

/* --- Облачка сообщений: user справа (акцент), assistant слева (нейтрально) --- */
.chat-msg { max-width: 85%; padding: 9px 13px; border-radius: 16px; line-height: 1.5;
  word-wrap: break-word; overflow-wrap: anywhere; }
.chat-msg-user { align-self: flex-end; background: var(--tg-btn); color: var(--tg-btn-text);
  border-bottom-right-radius: 5px; }
.chat-msg-assistant { align-self: flex-start; background: var(--tg-secondary-bg); color: var(--tg-text);
  border: 1px solid var(--border); border-bottom-left-radius: 5px; }
.chat-msg-user a { color: var(--tg-btn-text); text-decoration: underline; }
.chat-msg-body pre { background: rgba(0,0,0,0.25); padding: 8px 10px; border-radius: 8px;
  overflow-x: auto; font-family: var(--font-mono); font-size: 12.5px; }
.chat-msg-body code { font-family: var(--font-mono); font-size: 12.5px; }
.chat-msg-body p:first-child { margin-top: 0; }
.chat-msg-body p:last-child { margin-bottom: 0; }
