:root {
  color-scheme: dark;
  --bg: #091218;
  --surface: #111d26;
  --surface-2: #172631;
  --surface-3: #1d303d;
  --line: rgba(173, 214, 197, .11);
  --line-strong: rgba(101, 232, 165, .24);
  --text: #eef8f3;
  --muted: #91a5ae;
  --accent: #45e18e;
  --accent-strong: #20bd6b;
  --me: #176747;
  --danger: #ff7d86;
  --shadow: 0 20px 55px rgba(0, 0, 0, .48);
  --header-height: calc(68px + env(safe-area-inset-top));
  --composer-height: calc(76px + env(safe-area-inset-bottom));
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

body { min-height: 100dvh; }
button, input { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }

.phone {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 12% -6%, rgba(69, 225, 142, .14), transparent 24rem),
    radial-gradient(circle at 105% 70%, rgba(35, 124, 100, .08), transparent 26rem),
    linear-gradient(145deg, rgba(255, 255, 255, .018) 25%, transparent 25%) 0 0 / 34px 34px,
    var(--bg);
}

.tg-head {
  position: fixed;
  inset: 0 0 auto 0;
  z-index: 50;
  min-height: var(--header-height);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: rgba(15, 26, 34, .92);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 7px 24px rgba(0, 0, 0, .18);
  backdrop-filter: blur(18px);
}

.avatar {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 15px;
  object-fit: cover;
  background: #071b18;
  border: 1px solid rgba(221, 180, 80, .32);
  box-shadow: inset 0 1px rgba(255, 255, 255, .08), 0 7px 18px rgba(0, 0, 0, .24);
}

.head-main { flex: 1; min-width: 0; }
.site-back { color:#dcc48e; text-decoration:none; font-size:12px; white-space:nowrap; padding:10px 8px; border:1px solid #dcc48e40; border-radius:8px; }
button:focus-visible, a:focus-visible, input:focus-visible { outline:2px solid #dcc48e; outline-offset:3px; }
.title { font-size: 17px; font-weight: 780; letter-spacing: -.2px; line-height: 1.15; }
.status { margin-top: 4px; color: var(--muted); font-size: 12px; line-height: 1; }

.chat {
  min-height: 100dvh;
  padding: calc(var(--header-height) + 14px) 12px calc(var(--composer-height) + 16px);
  display: flex;
  flex-direction: column;
  gap: 10px;
  overflow-x: hidden;
}

.row { display: flex; width: 100%; }
.row.me { justify-content: flex-end; }
.row.bot { justify-content: flex-start; }
.row.service { justify-content: center; }

.bubble {
  position: relative;
  max-width: min(91%, 620px);
  padding: 12px 13px 10px;
  border-radius: 18px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  line-height: 1.42;
  box-shadow: 0 5px 18px rgba(0, 0, 0, .2);
}

.me .bubble {
  max-width: min(82%, 520px);
  padding: 9px 13px 8px;
  border-top-right-radius: 6px;
  background: linear-gradient(145deg, #1b7752, var(--me));
  border: 1px solid rgba(114, 255, 178, .1);
}

.bot .bubble {
  border-top-left-radius: 6px;
  background: linear-gradient(145deg, rgba(24, 40, 51, .99), rgba(19, 32, 42, .99));
  border: 1px solid rgba(255, 255, 255, .035);
}

.service .bubble {
  max-width: min(86%, 520px);
  padding: 8px 14px;
  border: 1px solid rgba(121, 176, 157, .08);
  border-radius: 999px;
  background: rgba(20, 40, 48, .7);
  color: var(--muted);
  text-align: center;
  font-size: 12px;
  line-height: 1.35;
  box-shadow: none;
}

.msg-text { white-space: pre-wrap; }
.bot .msg-text { font-size: 15.5px; }

.time {
  display: inline-block;
  margin-left: 7px;
  color: rgba(214, 231, 224, .4);
  font-size: 10.5px;
  white-space: nowrap;
}

.message-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}

.copy-mini {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  padding: 6px 11px;
  background: rgba(69, 225, 142, .075);
  color: #82f8b6;
  font-size: 12.5px;
  font-weight: 650;
  transition: background .16s ease, transform .16s ease, color .16s ease;
}

.copy-mini:active { transform: scale(.98); }
.copy-mini.copied { color: #d8ffea; background: rgba(69, 225, 142, .18); }

.kb {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.kb-row {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 8px;
}

.inline-btn {
  min-height: 45px;
  border: 1px solid rgba(102, 211, 160, .16);
  border-radius: 13px;
  padding: 9px 10px;
  background: linear-gradient(145deg, #213746, #1c303d);
  color: #e6f7ed;
  font-size: 14.5px;
  line-height: 1.16;
  box-shadow: inset 0 1px rgba(255, 255, 255, .025);
  transition: transform .14s ease, border-color .14s ease, background .14s ease;
}

.inline-btn:active {
  transform: scale(.98);
  border-color: rgba(102, 232, 171, .32);
  background: #294252;
}

.composer {
  position: fixed;
  inset: auto 0 0 0;
  z-index: 70;
  min-height: var(--composer-height);
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr) 50px;
  gap: 10px;
  align-items: center;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(14, 25, 33, .95);
  box-shadow: 0 -10px 30px rgba(0, 0, 0, .22);
  backdrop-filter: blur(18px);
}

.composer input {
  width: 100%;
  min-width: 0;
  height: 50px;
  border: 1px solid rgba(255, 255, 255, .035);
  outline: none;
  border-radius: 17px;
  padding: 0 16px;
  color: var(--text);
  background: var(--surface-2);
  font-size: 16px;
  line-height: 50px;
  box-shadow: inset 0 1px 5px rgba(0, 0, 0, .18);
}

.composer input::placeholder { color: #71858f; opacity: 1; }
.composer input:focus { border-color: rgba(69, 225, 142, .3); }

.round,
.send {
  width: 50px;
  height: 50px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 16px;
}

.round {
  gap: 4px;
  align-content: center;
  background: var(--surface-2);
  border: 1px solid rgba(255, 255, 255, .035);
}

.round > span {
  display: block;
  width: 19px;
  height: 2px;
  border-radius: 2px;
  background: #d7e6df;
  transition: transform .18s ease, opacity .18s ease;
}

.round.active > span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.round.active > span:nth-child(2) { opacity: 0; }
.round.active > span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

.send {
  background: linear-gradient(145deg, #50e798, #1cb665);
  color: #03140c;
  box-shadow: 0 8px 20px rgba(24, 190, 101, .25), inset 0 1px rgba(255, 255, 255, .25);
}

.send:active { transform: scale(.96); }
.send svg { width: 23px; height: 23px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

.hidden { display: none !important; }

.command-backdrop {
  position: fixed;
  inset: 0;
  z-index: 58;
  border: 0;
  background: rgba(2, 8, 11, .48);
  backdrop-filter: blur(2px);
}

.command-menu {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--composer-height) + 10px);
  z-index: 65;
  max-width: 516px;
  margin: 0 auto;
  padding: 14px;
  border: 1px solid rgba(104, 225, 166, .17);
  border-radius: 22px;
  background: rgba(16, 29, 38, .985);
  box-shadow: var(--shadow);
  animation: command-in .18s ease-out;
}

@keyframes command-in {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.command-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 1px 2px 12px;
}

.command-menu-head strong { display: block; font-size: 15px; }
.command-menu-head span { display: block; margin-top: 3px; color: var(--muted); font-size: 11.5px; }

.command-close {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 11px;
  background: rgba(255, 255, 255, .05);
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.command-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.command-grid > button {
  min-height: 66px;
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid rgba(112, 199, 158, .12);
  border-radius: 15px;
  padding: 10px;
  color: var(--text);
  text-align: left;
  background: linear-gradient(145deg, var(--surface-3), var(--surface-2));
}

.command-grid > button:active { transform: scale(.985); background: #29404d; }
.command-grid > .command-author { grid-column: 1 / -1; min-height: 58px; border-color: rgba(226, 185, 92, .18); }
.command-grid > .command-clear { grid-column: 1 / -1; min-height: 58px; border-color: rgba(255, 125, 134, .15); }

.command-icon {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: rgba(69, 225, 142, .09);
  color: #7cf3af;
  font-size: 18px;
  font-weight: 750;
}

.command-clear .command-icon { background: rgba(255, 125, 134, .09); color: var(--danger); }
.command-author .command-icon { background: rgba(226, 185, 92, .1); color: #e8c56d; }
.command-grid strong { display: block; font-size: 13.5px; }
.command-grid small { display: block; margin-top: 3px; color: var(--muted); font-size: 10.5px; font-weight: 450; }

@media (max-width: 370px) {
  .tg-head { padding-left: 12px; padding-right: 12px; }
  .chat { padding-left: 8px; padding-right: 8px; }
  .bubble { max-width: 95%; }
  .composer { padding-left: 8px; padding-right: 8px; grid-template-columns: 46px minmax(0, 1fr) 46px; gap: 7px; }
  .round, .send { width: 46px; height: 46px; }
  .composer input { height: 46px; padding: 0 12px; line-height: 46px; }
  .inline-btn { padding-left: 6px; padding-right: 6px; font-size: 13.5px; }
}

@media (min-width: 680px) {
  .phone {
    width: 540px;
    margin: 0 auto;
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }

  .tg-head,
  .composer {
    left: 50%;
    width: 540px;
    transform: translateX(-50%);
  }
}

.storage-notice {
  position: fixed;
  z-index: 90;
  right: max(12px, env(safe-area-inset-right));
  bottom: max(76px, calc(env(safe-area-inset-bottom) + 68px));
  display: flex;
  align-items: center;
  gap: 10px;
  width: min(430px, calc(100vw - 24px));
  box-sizing: border-box;
  padding: 11px 12px;
  border: 1px solid rgba(226, 185, 92, .38);
  border-radius: 12px;
  background: rgba(16, 26, 34, .97);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .55);
  color: var(--text);
  font-size: 12px;
  line-height: 1.4;
  pointer-events: none;
}
.storage-notice.hidden { display: none; }
.storage-notice p { margin: 0; }
.storage-notice a { color: #e8c56d; pointer-events: auto; }
.storage-notice button { flex: 0 0 auto; min-height: 34px; padding: 0 12px; border: 0; border-radius: 8px; background: #e8c56d; color: #101a22; font-weight: 750; pointer-events: auto; }
@media (max-width: 460px) { .storage-notice { align-items: stretch; flex-direction: column; } }
