/* Colors come from the Telegram theme when opened as a Mini App, with light/dark fallbacks for a normal browser. */
:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg-2: var(--tg-theme-secondary-bg-color, #f1f2f6);
  --text: var(--tg-theme-text-color, #111418);
  --hint: var(--tg-theme-hint-color, #8a9099);
  --link: var(--tg-theme-link-color, #2a7de1);
  --accent: var(--tg-theme-button-color, #2a7de1);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --header: var(--tg-theme-header-bg-color, var(--bg));
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --bubble-client: var(--bg);
  --bubble-ai: color-mix(in srgb, var(--hint) 16%, var(--bg));
  --bubble-manager: var(--accent);
  --wait: #f08c2e;
  --ok: #3cb46e;
  --danger: #e2483d;
  --radius: 16px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-bg-color, #17191d);
    --bg-2: var(--tg-theme-secondary-bg-color, #0f1013);
    --text: var(--tg-theme-text-color, #eef0f3);
    --hint: var(--tg-theme-hint-color, #8b919a);
    --link: var(--tg-theme-link-color, #5ea2f0);
    --accent: var(--tg-theme-button-color, #3b8be6);
  }
}
:root[data-theme="dark"] {
  --bg: var(--tg-theme-bg-color, #17191d);
  --bg-2: var(--tg-theme-secondary-bg-color, #0f1013);
  --text: var(--tg-theme-text-color, #eef0f3);
  --hint: var(--tg-theme-hint-color, #8b919a);
  --link: var(--tg-theme-link-color, #5ea2f0);
  --accent: var(--tg-theme-button-color, #3b8be6);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg-2);
  color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
a { color: var(--link); }

.app { height: var(--tg-viewport-stable-height, 100dvh); display: flex; }
.pane { height: 100%; display: flex; flex-direction: column; min-width: 0; }
.list-pane { width: 100%; background: var(--bg); }
.chat-pane { display: none; width: 100%; }
.app.chat-open .list-pane { display: none; }
.app.chat-open .chat-pane { display: flex; }

@media (min-width: 860px) {
  .list-pane { width: 360px; flex: none; border-right: 1px solid var(--sep); display: flex !important; }
  .chat-pane { display: flex; flex: 1; }
  .back-btn { display: none !important; }
}

/* ---------- list ---------- */
.list-header { padding: 14px 16px 8px; background: var(--header); position: sticky; top: 0; }
.list-title-row { display: flex; align-items: center; justify-content: space-between; }
h1 { font-size: 22px; margin: 0 0 10px; letter-spacing: -0.01em; }
.conn { font-size: 12px; color: var(--hint); transition: color .2s; }
.conn.on { color: var(--ok); }
.search {
  width: 100%; border: 0; outline: 0; border-radius: 10px; padding: 9px 12px;
  background: var(--bg-2); color: var(--text); font: inherit;
}
.tabs { display: flex; gap: 6px; margin-top: 10px; }
.tab {
  flex: 1; padding: 7px 4px; border-radius: 9px; font-size: 14px; font-weight: 500; color: var(--hint);
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.tab.active { background: var(--bg-2); color: var(--text); }
.tab-badge {
  background: var(--wait); color: #fff; border-radius: 10px; font-size: 11px; font-weight: 600;
  min-width: 18px; height: 18px; padding: 0 5px; display: inline-grid; place-items: center;
}

.chat-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.chat-list:empty { display: none; }
.chat-item {
  display: flex; gap: 12px; align-items: center; padding: 10px 16px; cursor: pointer;
  border-bottom: 1px solid var(--sep);
}
.chat-item:active, .chat-item.selected { background: var(--bg-2); }
.chat-item-main { flex: 1; min-width: 0; }
.chat-item-top, .chat-item-bottom { display: flex; align-items: center; gap: 8px; }
.chat-item-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-item-time { font-size: 12px; color: var(--hint); flex: none; }
.chat-item-preview {
  flex: 1; min-width: 0; color: var(--hint); font-size: 14px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-item-preview b { color: var(--text); font-weight: 500; }
.unread {
  background: var(--accent); color: var(--accent-text); border-radius: 11px; font-size: 12px; font-weight: 600;
  min-width: 22px; height: 22px; padding: 0 7px; display: grid; place-items: center; flex: none;
}
.pill { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 6px; flex: none; }
.pill.wait { background: color-mix(in srgb, var(--wait) 18%, transparent); color: var(--wait); }
.pill.manager { background: color-mix(in srgb, var(--ok) 18%, transparent); color: var(--ok); }
.pill.ai { background: var(--bg-2); color: var(--hint); }

.avatar {
  width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center;
  color: #fff; font-weight: 600; font-size: 17px;
}
.avatar.small { width: 38px; height: 38px; font-size: 15px; }

.empty, .placeholder { color: var(--hint); text-align: center; padding: 40px 16px; }
.placeholder { margin: auto; }

/* ---------- chat ---------- */
.chat-body { display: flex; flex-direction: column; height: 100%; width: 100%; }
.chat-header {
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--header);
  border-bottom: 1px solid var(--sep);
}
.icon-btn { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 50%; color: var(--hint); flex: none; }
.back-btn { color: var(--link); margin-left: -6px; }
.chat-head-text { flex: 1; min-width: 0; }
.chat-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-sub { font-size: 13px; color: var(--hint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.action-btn {
  font-size: 13px; font-weight: 600; padding: 7px 12px; border-radius: 9px; flex: none;
  background: var(--accent); color: var(--accent-text);
}
.action-btn.close { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.action-btn:disabled { opacity: .5; }

.summary { background: var(--bg); border-bottom: 1px solid var(--sep); padding: 0 16px; }
.summary > summary { padding: 10px 0; font-size: 14px; font-weight: 600; color: var(--link); cursor: pointer; list-style: none; }
.summary > summary::-webkit-details-marker { display: none; }
.summary > summary::after { content: " ▾"; }
.summary[open] > summary::after { content: " ▴"; }
.summary-text { white-space: pre-wrap; font-size: 14px; padding-bottom: 8px; }
.flights { display: grid; gap: 6px; padding-bottom: 12px; max-height: 40vh; overflow-y: auto; }
.flight {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 8px 10px;
  border-radius: 10px; background: var(--bg-2); font-size: 13px; color: var(--text); text-decoration: none;
}
.flight-route { font-weight: 600; }
.flight-price { font-weight: 700; text-align: right; }
.flight-meta { color: var(--hint); grid-column: 1 / -1; }

.messages { flex: 1; overflow-y: auto; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 4px; }
.day { align-self: center; font-size: 12px; color: var(--hint); background: var(--bg); border-radius: 10px; padding: 3px 10px; margin: 8px 0; }
.msg { max-width: min(78%, 520px); padding: 7px 11px 6px; border-radius: var(--radius); position: relative; word-wrap: break-word; }
.msg-text { white-space: pre-wrap; }
.msg-meta { font-size: 11px; opacity: .65; text-align: right; margin-top: 2px; }
.msg-label { font-size: 12px; font-weight: 600; margin-bottom: 2px; opacity: .8; }
.msg.user { align-self: flex-start; background: var(--bubble-client); border-bottom-left-radius: 6px; }
.msg.ai { align-self: flex-end; background: var(--bubble-ai); border-bottom-right-radius: 6px; }
.msg.manager { align-self: flex-end; background: var(--bubble-manager); color: var(--accent-text); border-bottom-right-radius: 6px; }
.msg.manager a { color: inherit; }
.msg.system {
  align-self: center; max-width: 90%; background: none; text-align: center; font-size: 13px;
  color: var(--hint); padding: 4px 8px;
}
.msg.pending { opacity: .6; }
.msg img { display: block; max-width: 100%; max-height: 320px; border-radius: 10px; margin: 2px 0 4px; }
.msg audio, .msg video { max-width: 100%; display: block; margin: 2px 0 4px; }
.file-link { display: inline-flex; gap: 6px; align-items: center; font-weight: 500; }

.mode-hint { font-size: 12px; color: var(--hint); text-align: center; padding: 6px 16px 0; background: var(--bg); }
.composer {
  display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--sep);
}
.input-wrap { flex: 1; min-width: 0; background: var(--bg-2); border-radius: 19px; padding: 0 12px; }
.composer textarea {
  width: 100%; border: 0; outline: 0; resize: none; background: transparent; color: var(--text);
  font: inherit; padding: 9px 0; max-height: 140px; display: block;
}
.send { color: var(--accent); }
.send:disabled { opacity: .4; }
.attach { cursor: pointer; }
.file-chip {
  display: flex; align-items: center; gap: 6px; font-size: 13px; padding-top: 7px; color: var(--link);
}
.file-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-chip button { color: var(--hint); font-size: 18px; line-height: 1; }

.auth-error { position: fixed; inset: 0; display: grid; place-items: center; text-align: center; background: var(--bg); padding: 24px; }
.auth-error p { color: var(--hint); }
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%); max-width: calc(100% - 32px);
  background: rgba(20, 22, 26, .92); color: #fff; padding: 9px 14px; border-radius: 10px; font-size: 14px; z-index: 10;
}
