:root {
  --bg: var(--tg-theme-bg-color, #16191d);
  --text: var(--tg-theme-text-color, #e8ebee);
  --muted: var(--tg-theme-hint-color, #8a93a0);
  --card: var(--tg-theme-secondary-bg-color, #1f242a);
  --accent: var(--tg-theme-button-color, #4a90ff);
  --accent-text: var(--tg-theme-button-text-color, #fff);
  --danger: #ff5a5a;
  --ok: #6dd28a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh; overscroll-behavior: contain; }
main { max-width: 560px; margin: 0 auto; padding: 16px 14px 100px; }
.head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 500; }
.ghost { background: transparent; border: 1px solid rgba(255,255,255,0.08); border-radius: 8px;
  color: var(--text); padding: 6px 10px; cursor: pointer; font-size: 15px; }
.panel { background: var(--card); border-radius: 14px; padding: 14px; margin-bottom: 10px; }
.langs { display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center; }
.lang-row { display: flex; flex-direction: column; gap: 4px; }
.lang-row label, .voice-row label { color: var(--muted); font-size: 12px; }
select { background: rgba(255,255,255,0.05); color: var(--text); border: 0;
  border-radius: 8px; padding: 8px 10px; font-size: 15px; width: 100%; appearance: none; }
.swap { font-size: 18px; width: 40px; height: 40px; align-self: end; }
.voice-row { display: flex; align-items: center; gap: 10px; }
.voice-row select { max-width: 200px; }
.audio-opts { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.check input { accent-color: var(--accent); }

.status-line { display: flex; gap: 8px; align-items: center; padding: 8px 4px; color: var(--muted); font-size: 13px; }
.cost-badge { margin-left: auto; background: rgba(255,255,255,0.06); padding: 3px 8px; border-radius: 6px; font-variant-numeric: tabular-nums; font-size: 12px; }
.stats-btn { padding: 4px 8px; font-size: 14px; }
.stats ul { list-style: none; padding: 0; margin: 0 0 10px; }
.stats li { padding: 4px 0; display: flex; justify-content: space-between; font-size: 14px; }
.stats-note { color: var(--muted); font-size: 11px; line-height: 1.4; margin: 0; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #6a737d; }
.dot.live { background: var(--danger); box-shadow: 0 0 0 0 rgba(255,90,90,0.7); animation: pulse 1.4s infinite; }
.dot.ready { background: var(--ok); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255,90,90,0.7); }
  70% { box-shadow: 0 0 0 12px rgba(255,90,90,0); }
  100% { box-shadow: 0 0 0 0 rgba(255,90,90,0); }
}

.subtitles { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
.sub-block { background: var(--card); border-radius: 14px; padding: 12px 14px; }
.sub-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.sub-text { font-size: 16px; line-height: 1.5; min-height: 80px; max-height: 220px; overflow-y: auto; white-space: pre-wrap; word-break: break-word; }

.mic-wrap { position: fixed; left: 0; right: 0; bottom: 12px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.mic-btn { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 999px;
  padding: 14px 28px; font-size: 16px; font-weight: 600; display: flex; align-items: center; gap: 10px;
  box-shadow: 0 4px 20px rgba(74,144,255,0.4); cursor: pointer; touch-action: manipulation; user-select: none; }
.mic-btn.active { background: var(--danger); box-shadow: 0 4px 24px rgba(255,90,90,0.5); }
.mic-icon { font-size: 22px; }
.mic-hint { color: var(--muted); font-size: 12px; }

.health ul { list-style: none; padding: 0; margin: 0 0 10px; }
.health li { padding: 4px 0; display: flex; justify-content: space-between; gap: 8px; font-size: 14px; }
.health code { background: rgba(255,255,255,0.05); padding: 2px 6px; border-radius: 4px; font-size: 11px; word-break: break-all; max-width: 60%; }
.health button { background: var(--accent); color: var(--accent-text); border: 0; border-radius: 10px;
  padding: 8px 14px; font-size: 14px; cursor: pointer; width: 100%; }
.ok { color: var(--ok); }
.err { color: var(--danger); }
.warn { color: #ffb547; }
.hidden { display: none; }

/* === Tabs === */
.tabs { display: flex; gap: 4px; margin: 8px 0 12px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.tab-btn { flex: 1; background: transparent; border: 0; color: var(--muted); padding: 10px 8px;
  font-size: 14px; cursor: pointer; border-bottom: 2px solid transparent; transition: all 0.2s; }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* === Note input === */
.note-row { padding: 8px; display: flex; gap: 6px; align-items: center; }
.note-row input { flex: 1; background: rgba(255,255,255,0.05); color: var(--text);
  border: 0; border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.note-row button { padding: 8px 12px; font-size: 16px; }

/* === Active session bar === */
.active-session { padding: 8px 12px; display: flex; align-items: center; gap: 8px;
  background: rgba(74,144,255,0.08); border: 1px solid rgba(74,144,255,0.2); }
.active-session-info { flex: 1; font-size: 13px; color: var(--text); }
.active-session-info.empty { color: var(--muted); }

/* === Sessions === */
.sessions-header { display: flex; justify-content: space-between; align-items: center; margin: 6px 0; }
.sessions-header h2 { color: var(--text); font-size: 16px; }
.sessions-list { display: flex; flex-direction: column; gap: 6px; }
.session-card { background: var(--card); padding: 10px 12px; border-radius: 10px; cursor: pointer;
  border: 1px solid transparent; transition: border-color 0.2s; }
.session-card:hover { border-color: var(--accent); }
.session-card .session-name { font-weight: 600; font-size: 15px; }
.session-card .session-sub { color: var(--muted); font-size: 12px; margin-top: 2px;
  display: flex; gap: 8px; flex-wrap: wrap; }
.session-card .audio-badge { color: var(--accent); }

.session-detail { padding: 8px 0; }
.session-detail h2 { font-size: 18px; margin: 8px 0; color: var(--text); }
.session-meta { color: var(--muted); font-size: 12px; margin-bottom: 10px; }
.session-detail audio { width: 100%; margin: 10px 0; }
.session-actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.session-actions .danger { color: var(--danger); border-color: rgba(255,90,90,0.3); }
.session-timeline { display: flex; flex-direction: column; gap: 6px; margin-top: 12px; max-height: 60vh;
  overflow-y: auto; }
.timeline-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tl-col { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.tl-col-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 2px; }
@media (max-width: 540px) {
  .timeline-2col { grid-template-columns: 1fr; }
}
.tl-entry { padding: 8px 10px; border-radius: 8px; font-size: 14px; line-height: 1.4; }
.tl-entry.orig { background: rgba(74,144,255,0.08); border-left: 3px solid var(--accent); }
.tl-entry.trans { background: rgba(109,210,138,0.08); border-left: 3px solid var(--ok); }
.tl-entry.note { background: rgba(255,181,71,0.08); border-left: 3px solid #ffb547; font-style: italic; }
.tl-entry.lang { background: rgba(255,255,255,0.04); color: var(--muted); font-size: 12px; text-align: center; }
.tl-entry .tl-ts { color: var(--muted); font-size: 11px; margin-right: 6px; }
.tl-entry .tl-ts.clickable { color: var(--accent); cursor: pointer; text-decoration: underline; }
.tl-ts-marker { color: var(--accent); font-size: 11px; cursor: pointer; padding: 4px 0 0 2px;
  font-variant-numeric: tabular-nums; user-select: none; }
.tl-ts-marker:hover { color: var(--text); }

/* === Chat === */
.chat-header { margin: 8px 0; }
.chat-header h2 { font-size: 16px; color: var(--text); }
.chat-session-label { color: var(--muted); font-size: 12px; margin-top: 4px; }
.chat-messages { display: flex; flex-direction: column; gap: 8px; max-height: 65vh; overflow-y: auto;
  padding: 8px 0; }
.chat-msg { padding: 10px 14px; border-radius: 14px; font-size: 14px; line-height: 1.5;
  max-width: 85%; white-space: pre-wrap; word-break: break-word; }
.chat-msg.user { align-self: flex-end; background: var(--accent); color: var(--accent-text); }
.chat-msg.assistant { align-self: flex-start; background: var(--card); }
.chat-input-row { display: flex; gap: 6px; padding: 8px 0 12px; position: sticky; bottom: 0; background: var(--bg); }
.chat-input-row input { flex: 1; background: var(--card); color: var(--text); border: 0;
  border-radius: 999px; padding: 10px 16px; font-size: 14px; }
.chat-input-row input:disabled { opacity: 0.5; }
.chat-input-row button { background: var(--accent); color: var(--accent-text); border: 0;
  border-radius: 999px; width: 44px; height: 44px; font-size: 18px; cursor: pointer; }
.chat-input-row button:disabled { opacity: 0.4; cursor: not-allowed; }

/* === Cost chart === */
#cost-chart { width: 100%; max-width: 320px; margin: 8px 0; background: rgba(255,255,255,0.03);
  border-radius: 6px; }

/* === Split view (контент + чат рядом) === */
.split { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.split-col { display: flex; flex-direction: column; min-width: 0; }
.split-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.split .session-timeline { max-height: 40vh; }
.split .chat-messages { max-height: 38vh; }
/* На широком экране — два столбца рядом */
@media (min-width: 720px) {
  .split { flex-direction: row; }
  .split-col { flex: 1; }
  .split .session-timeline { max-height: 65vh; }
  .split .chat-messages { max-height: 55vh; }
}

