/* Telegram theme variables с фоллбэком */
:root {
  --tg-bg:        var(--tg-theme-bg-color, #ffffff);
  --tg-text:      var(--tg-theme-text-color, #000000);
  --tg-hint:      var(--tg-theme-hint-color, #707579);
  --tg-link:      var(--tg-theme-link-color, #2481cc);
  --tg-btn:       var(--tg-theme-button-color, #2481cc);
  --tg-btn-text:  var(--tg-theme-button-text-color, #ffffff);
  --tg-secondary-bg: var(--tg-theme-secondary-bg-color, #f1f1f1);

  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--tg-bg);
  color: var(--tg-text);
  min-height: 100vh;
  overscroll-behavior: none;
}

/* ── Экраны ───────────────────────────────────────────────── */
.screen {
  display: none;
  flex-direction: column;
  min-height: 100vh;
  padding: 16px;
}
.screen.active { display: flex; }

/* ── Шапка ────────────────────────────────────────────────── */
.header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
}
.header-avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--tg-btn);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}
.header-title { font-size: 18px; font-weight: 700; }
.header-sub   { font-size: 13px; color: var(--tg-hint); }

/* ── Карточка задачи ──────────────────────────────────────── */
.task-card {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  position: relative;
}
.task-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--tg-hint);
  margin-bottom: 8px;
}
.task-text {
  font-size: 16px;
  line-height: 1.5;
  font-weight: 500;
}

/* ── Кнопка «Новая задача» ────────────────────────────────── */
.btn-new-task {
  position: absolute;
  top: 12px; right: 12px;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--tg-hint);
  padding: 4px;
  border-radius: 8px;
  transition: background 0.15s;
}
.btn-new-task:active { background: rgba(0,0,0,0.07); }

/* ── История диалога ──────────────────────────────────────── */
.chat-history {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 12px;
  padding-bottom: 4px;
}

.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
}
.msg-user {
  align-self: flex-end;
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  border-bottom-right-radius: 4px;
}
.msg-assistant {
  align-self: flex-start;
  background: var(--tg-secondary-bg);
  color: var(--tg-text);
  border-bottom-left-radius: 4px;
}
.msg-thinking {
  align-self: flex-start;
  background: var(--tg-secondary-bg);
  color: var(--tg-hint);
  font-style: italic;
  border-bottom-left-radius: 4px;
}

/* ── Блок записи / подтверждения ─────────────────────────── */
.input-area {
  border-top: 1px solid rgba(0,0,0,0.07);
  padding-top: 12px;
}

.voice-confirm-box {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 10px;
  display: none;
}
.voice-confirm-box.visible { display: block; }

.voice-confirm-label {
  font-size: 12px;
  color: var(--tg-hint);
  margin-bottom: 6px;
}

.voice-text-edit {
  width: 100%;
  background: var(--tg-bg);
  border: 1.5px solid var(--tg-btn);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  color: var(--tg-text);
  resize: none;
  min-height: 64px;
  font-family: inherit;
  outline: none;
}

.confirm-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.btn-confirm {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-confirm:active { opacity: 0.75; }

.btn-send    { background: var(--tg-btn); color: var(--tg-btn-text); }
.btn-rerecord { background: var(--tg-secondary-bg); color: var(--tg-text);
                border: 1.5px solid rgba(0,0,0,0.12); }

/* ── Кнопка микрофона ────────────────────────────────────── */
.mic-row {
  display: flex;
  align-items: center;
  gap: 12px;
}
.btn-mic {
  width: 62px; height: 62px;
  border-radius: 50%;
  border: none;
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  font-size: 28px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: var(--shadow);
  transition: transform 0.1s, box-shadow 0.1s;
  position: relative;
  overflow: hidden;
}
.btn-mic:active { transform: scale(0.94); }
.btn-mic.recording {
  background: #e53935;
  animation: pulse 1.2s infinite;
}
.btn-mic.disabled {
  background: var(--tg-hint);
  cursor: not-allowed;
}
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(229,57,53,0.5); }
  70%  { box-shadow: 0 0 0 14px rgba(229,57,53,0); }
  100% { box-shadow: 0 0 0 0 rgba(229,57,53,0); }
}

.mic-hint {
  font-size: 14px;
  color: var(--tg-hint);
  line-height: 1.4;
}

/* ── Экран ввода задачи ──────────────────────────────────── */
#screen-task-input {
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0;
  padding: 24px 20px;
}
.task-input-header {
  margin-bottom: 28px;
}
.task-input-header .big-emoji { font-size: 56px; margin-bottom: 12px; }
.task-input-header h2 { font-size: 22px; font-weight: 700; margin-bottom: 8px; }
.task-input-header p  { font-size: 15px; color: var(--tg-hint); line-height: 1.5; }

.task-input-card {
  width: 100%;
  background: var(--tg-secondary-bg);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 24px;
}

/* Общий блок записи (используется на обоих экранах) */
.record-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.btn-mic-large {
  width: 84px; height: 84px;
  font-size: 36px;
}

.confirm-box {
  width: 100%;
  display: none;
}
.confirm-box.visible { display: block; }

.confirm-box textarea {
  width: 100%;
  background: var(--tg-bg);
  border: 1.5px solid var(--tg-btn);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 15px;
  color: var(--tg-text);
  resize: none;
  min-height: 72px;
  font-family: inherit;
  outline: none;
  margin-bottom: 10px;
}

/* ── Задачи — список ──────────────────────────────────────── */
#screen-tasks {
  gap: 8px;
}
.task-list-item {
  background: var(--tg-secondary-bg);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 12px;
  transition: background 0.1s;
}
.task-list-item:active { background: rgba(0,0,0,0.06); }
.task-list-icon { font-size: 22px; flex-shrink: 0; }
.task-list-text {
  flex: 1;
  font-size: 14px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.task-list-date { font-size: 12px; color: var(--tg-hint); flex-shrink: 0; }

.btn-primary {
  width: 100%;
  padding: 15px;
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  border: none;
  border-radius: var(--radius);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  margin-top: auto;
  transition: opacity 0.15s;
}
.btn-primary:active { opacity: 0.8; }

/* ── Спиннер / лоадер ────────────────────────────────────── */
.loader {
  display: inline-block;
  width: 20px; height: 20px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast уведомление ───────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(60px);
  background: #323232;
  color: #fff;
  padding: 10px 20px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 999;
  transition: transform 0.3s ease;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }

/* ── Пустой список ───────────────────────────────────────── */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  color: var(--tg-hint);
}
.empty-state .big-emoji { font-size: 48px; }
.empty-state p { font-size: 15px; line-height: 1.5; }

/* ── Табы переключения режима ввода ──────────────────────── */
.input-mode-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  width: 100%;
}
.input-mode-tabs-sm {
  margin-bottom: 8px;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  border: 1.5px solid rgba(0,0,0,0.12);
  border-radius: var(--radius-sm);
  background: var(--tg-secondary-bg);
  color: var(--tg-hint);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}
.input-mode-tabs-sm .tab-btn {
  flex: 0 0 auto;
  padding: 8px 16px;
  font-size: 18px;
}
.tab-btn.tab-active {
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  border-color: var(--tg-btn);
}

/* ── Прямой текстовый ввод в карточке задачи ─────────────── */
#task-text-direct {
  width: 100%;
  background: var(--tg-bg);
  border: 1.5px solid var(--tg-btn);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 15px;
  color: var(--tg-text);
  resize: none;
  min-height: 100px;
  font-family: inherit;
  outline: none;
  display: block;
}

/* ── Строка текстового ввода в чате ──────────────────────── */
.text-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-text-area {
  flex: 1;
  background: var(--tg-secondary-bg);
  border: 1.5px solid var(--tg-btn);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 15px;
  color: var(--tg-text);
  resize: none;
  min-height: 48px;
  max-height: 120px;
  font-family: inherit;
  outline: none;
}
.btn-send-text {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: var(--tg-btn);
  color: var(--tg-btn-text);
  font-size: 20px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.15s;
}
.btn-send-text:active { opacity: 0.75; }

/* ── Кнопка «Начать заново» в карточке задачи ───────────── */
.btn-restart {
  display: inline-block;
  margin-top: 10px;
  padding: 6px 12px;
  background: none;
  border: 1px solid rgba(0,0,0,0.15);
  border-radius: 20px;
  font-size: 12px;
  color: var(--tg-hint);
  cursor: pointer;
  transition: all 0.15s;
}
.btn-restart:active {
  background: rgba(0,0,0,0.06);
}
