/* ИИ-Бот — мини-приложение MAX. Тёмная тема по умолчанию, светлая — по системной. */

:root {
  --bg: #0f1020;
  --bg-2: #171a30;
  --bg-3: #1f2340;
  --line: #2b3054;
  --text: #eef0f8;
  --muted: #9099bd;
  --accent: #6e7bff;
  --accent-2: #a06bff;
  --ok: #3ddc97;
  --warn: #ffcc4d;
  --radius: 16px;
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fc;
    --bg-2: #ffffff;
    --bg-3: #eceef8;
    --line: #dfe2f0;
    --text: #14162b;
    --muted: #6b7290;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

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

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(60% 40% at 15% 0%, rgba(110,123,255,.18), transparent 70%),
    radial-gradient(50% 35% at 90% 10%, rgba(160,107,255,.14), transparent 70%);
  pointer-events: none;
}

#app { position: relative; height: 100%; }

/* ── экраны ─────────────────────────────────────────────────── */

.screen {
  position: absolute;
  inset: 0 0 var(--tabbar-h) 0;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.screen[hidden] { display: none; }

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 14px calc(18px + env(safe-area-inset-bottom));
}

/* ── топбар ─────────────────────────────────────────────────── */

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
}
.topbar--title { justify-content: space-between; }
.topbar h2 { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: -.2px; }

.model-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--text);
  font-size: 14px;
  font-weight: 550;
  cursor: pointer;
}
.model-pill__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); }
.model-pill__chev { color: var(--muted); font-size: 11px; }

.icon-btn {
  margin-left: auto;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg-2);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}
.icon-btn--ghost { margin: 0; border-color: transparent; background: transparent; }

/* ── чат ────────────────────────────────────────────────────── */

.messages {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty { margin: auto; text-align: center; padding: 20px 6px; }
.empty__logo {
  width: 56px; height: 56px; margin: 0 auto 14px;
  display: grid; place-items: center;
  font-size: 26px;
  border-radius: 18px;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff;
}
.empty__title { margin: 0 0 6px; font-size: 21px; font-weight: 650; letter-spacing: -.3px; }
.empty__sub { margin: 0 0 18px; color: var(--muted); font-size: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.chip {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-2);
  color: var(--text);
  font-size: 13.5px;
  cursor: pointer;
}

.msg {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  animation: pop .16s ease-out;
}
.msg--me {
  align-self: flex-end;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff;
  border-bottom-right-radius: 6px;
}
.msg--bot {
  align-self: flex-start;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-bottom-left-radius: 6px;
}
.msg__model { display: block; margin-bottom: 4px; font-size: 11px; color: var(--muted); }
.msg--typing { color: var(--muted); }

@keyframes pop { from { opacity: 0; transform: translateY(6px); } }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}
.composer textarea {
  flex: 1;
  max-height: 110px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  resize: none;
  outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.send-btn {
  width: 40px; height: 40px;
  flex: 0 0 40px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 15px;
  cursor: pointer;
}

/* ── плитки инструментов ────────────────────────────────────── */

.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 15px 13px;
  min-height: 108px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
  color: var(--text);
  cursor: pointer;
}
.tile:active { transform: scale(.985); }
.tile__ico { font-size: 22px; margin-bottom: 4px; }
.tile__name { font-weight: 600; }
.tile__hint { color: var(--muted); font-size: 12px; }

/* ── список чатов ───────────────────────────────────────────── */

.list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.list__item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
  cursor: pointer;
}
.list__ico { width: 36px; height: 36px; flex: 0 0 36px; display: grid; place-items: center; border-radius: 11px; background: var(--bg-3); }
.list__body { min-width: 0; flex: 1; }
.list__title { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list__sub { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list__del { border: 0; background: transparent; color: var(--muted); font-size: 15px; cursor: pointer; }
.list__empty { color: var(--muted); text-align: center; padding: 40px 10px; }

/* ── профиль ────────────────────────────────────────────────── */

.user-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
}
.avatar {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff;
  font-weight: 650;
  font-size: 18px;
  background-size: cover;
  background-position: center;
}
.user-card__info { flex: 1; min-width: 0; }
.user-card__name { font-weight: 600; }
.user-card__id { color: var(--muted); font-size: 12.5px; }
.badge {
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg-3);
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.badge--premium { background: linear-gradient(140deg, var(--accent), var(--accent-2)); color: #fff; }

.limit-card {
  margin-top: 10px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-2);
}
.limit-card__row { display: flex; justify-content: space-between; font-size: 14px; }
.limit-card__reset { margin-top: 9px; color: var(--muted); font-size: 12.5px; }
.progress { height: 7px; margin-top: 10px; border-radius: 99px; background: var(--bg-3); overflow: hidden; }
.progress__bar { height: 100%; width: 0; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .25s; }

.cta {
  width: 100%;
  margin-top: 12px;
  padding: 14px;
  border: 0;
  border-radius: var(--radius);
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}

.section-title { margin: 22px 0 8px; font-size: 12.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }

.settings { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg-2); overflow: hidden; }
.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 13px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row__label { flex: 1; }
.row__chev { color: var(--muted); }
.row__value {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px 10px;
  background: var(--bg-3);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}
.row input[type=checkbox] { position: absolute; opacity: 0; pointer-events: none; }
.switch { width: 44px; height: 26px; border-radius: 99px; background: var(--bg-3); position: relative; transition: background .18s; flex: 0 0 44px; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .18s; }
.row input:checked ~ .switch { background: var(--accent); }
.row input:checked ~ .switch::after { transform: translateX(18px); }

.version { margin: 20px 0 0; text-align: center; color: var(--muted); font-size: 12px; }

/* ── таббар ─────────────────────────────────────────────────── */

.tabbar {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
}
.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
}
.tab span { font-size: 19px; filter: grayscale(1); opacity: .75; }
.tab.is-active { color: var(--accent); }
.tab.is-active span { filter: none; opacity: 1; }

/* ── шторки ─────────────────────────────────────────────────── */

.sheet { position: absolute; inset: 0; z-index: 20; }
.sheet[hidden] { display: none; }
.sheet__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.55); animation: fade .18s; }
.sheet__panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-height: 86%;
  overflow-y: auto;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom));
  border-radius: 22px 22px 0 0;
  background: var(--bg);
  border-top: 1px solid var(--line);
  animation: slide .22s ease-out;
}
.sheet__handle { width: 38px; height: 4px; margin: 4px auto 12px; border-radius: 99px; background: var(--line); }
.sheet__title { margin: 0 0 6px; font-size: 17px; font-weight: 650; }
.sheet__note { margin: 0 0 14px; color: var(--muted); font-size: 13px; }

@keyframes fade { from { opacity: 0; } }
@keyframes slide { from { transform: translateY(100%); } }

.models { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.model {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--bg-2);
  color: var(--text);
  text-align: left;
  font: inherit;
  cursor: pointer;
}
.model__name { font-weight: 550; font-size: 14px; }
.model__tag { color: var(--muted); font-size: 11.5px; }
.model.is-active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--bg-2)); }
.model.is-locked { opacity: .62; }

.form { display: flex; flex-direction: column; gap: 10px; }
.form textarea {
  width: 100%;
  min-height: 92px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  resize: vertical;
  outline: none;
}
.form textarea:focus { border-color: var(--accent); }
.note { color: var(--muted); font-size: 13px; line-height: 1.5; }
.note code { background: var(--bg-3); padding: 1px 5px; border-radius: 5px; font-size: 12px; }

.plans { display: flex; flex-direction: column; gap: 9px; margin-bottom: 12px; }
.plan {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--bg-2);
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}
.plan.is-best { border-color: var(--accent); }
.plan__body { flex: 1; }
.plan__name { font-weight: 600; }
.plan__desc { color: var(--muted); font-size: 12.5px; }
.plan__price { font-weight: 650; white-space: nowrap; }

.toast {
  position: absolute;
  left: 50%;
  bottom: calc(var(--tabbar-h) + 18px);
  transform: translateX(-50%);
  z-index: 30;
  max-width: 84%;
  padding: 11px 16px;
  border-radius: 13px;
  background: #000c;
  color: #fff;
  font-size: 13.5px;
  text-align: center;
  backdrop-filter: blur(8px);
  animation: pop .16s;
}
.toast[hidden] { display: none; }

.msg__img {
  display: block;
  width: 100%;
  max-width: 320px;
  border-radius: 12px;
  margin: 2px 0 6px;
}

.tile { position: relative; }
.tile--soon { opacity: .55; }
.tile__soon {
  position: absolute;
  top: 10px; right: 10px;
  padding: 3px 8px;
  border-radius: 99px;
  background: var(--bg-3);
  color: var(--muted);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .4px;
}

/* ── голосовой ввод ─────────────────────────────────────────── */

.icon-btn--mic {
  margin: 0;
  flex: 0 0 34px;
  border-color: var(--line);
  background: var(--bg-2);
}
.icon-btn--mic.is-rec {
  border-color: transparent;
  background: #ff4d6d;
  animation: pulse 1.1s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,77,109,.45); }
  50%      { box-shadow: 0 0 0 8px rgba(255,77,109,0); }
}

.rec-bar {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 9px 14px;
  border-top: 1px solid var(--line);
  background: var(--bg-2);
  font-size: 13px;
}
.rec-bar[hidden] { display: none; }
.rec-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: #ff4d6d;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { 50% { opacity: .25; } }
.rec-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.rec-hint { color: var(--muted); flex: 1; }
.rec-cancel {
  border: 0;
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  cursor: pointer;
}
