:root {
  --telegram: #3390ec;
  --telegram-dark: #2777bd;
  --shell: #17212b;
  --sidebar: #202b36;
  --sidebar-soft: #293642;
  --chat: #0e1621;
  --bubble: #182533;
  --bubble-user: #2b5278;
  --text: #f5f7fa;
  --muted: #93a4b5;
  --line: rgba(255, 255, 255, 0.09);
  --danger: #ef5b5b;
  --success: #4dcc8e;
  --header-h: 64px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  min-width: 320px;
  overflow: hidden;
  color: var(--text);
  background: var(--shell);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
textarea,
input {
  font: inherit;
}

button {
  color: inherit;
  cursor: pointer;
}

.builder-header {
  position: relative;
  z-index: 20;
  min-height: var(--header-h);
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--line);
  background: #1d2a35;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.24);
}

.back-home {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  width: fit-content;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0.06em;
}

.back-home span {
  color: var(--telegram);
  font-size: 22px;
}

.builder-identity {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 11px;
}

.builder-identity div {
  min-width: 0;
}

.builder-identity strong,
.builder-identity small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.builder-identity small {
  margin-top: 2px;
  color: var(--success);
  font-size: 12px;
}

.bot-avatar {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 50%;
  background: linear-gradient(145deg, #59b7ff, #247bc2);
  color: #fff;
  font-weight: 900;
  box-shadow: 0 7px 20px rgba(51, 144, 236, 0.28);
}

.header-tools {
  display: flex;
  gap: 8px;
}

.header-tools button,
.panel-title button {
  min-height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.045);
  font-size: 13px;
  font-weight: 800;
}

.header-tools button:hover,
.panel-title button:hover {
  background: rgba(255, 255, 255, 0.09);
}

.header-tools .primary-tool {
  border-color: var(--telegram);
  background: var(--telegram);
}

.builder-shell {
  height: calc(100vh - var(--header-h));
  display: grid;
  grid-template-columns: 280px minmax(360px, 1fr) minmax(360px, 42vw);
}

.project-panel,
.preview-panel {
  min-width: 0;
  overflow: auto;
  background: var(--sidebar);
}

.project-panel {
  border-right: 1px solid var(--line);
}

.preview-panel {
  border-left: 1px solid var(--line);
}

.panel-title {
  position: sticky;
  top: 0;
  z-index: 5;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(32, 43, 54, 0.95);
  backdrop-filter: blur(12px);
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.project-card {
  margin: 15px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background:
    radial-gradient(circle at 100% 0, rgba(51, 144, 236, 0.19), transparent 38%),
    var(--sidebar-soft);
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.16);
}

.project-logo {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 18px;
  background: var(--telegram);
  color: #fff;
  font-size: 20px;
  font-weight: 900;
}

.project-logo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.project-card h1 {
  margin: 16px 0 6px;
  overflow-wrap: anywhere;
  font-size: 21px;
  line-height: 1.1;
}

.project-card > p {
  min-height: 38px;
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.project-card dl {
  display: grid;
  gap: 9px;
  margin: 0;
}

.project-card dl div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-top: 9px;
  border-top: 1px solid var(--line);
}

.project-card dt {
  color: var(--muted);
  font-size: 12px;
}

.project-card dd {
  max-width: 145px;
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  font-weight: 800;
}

.quick-nav {
  display: grid;
  gap: 3px;
  padding: 0 8px;
}

.quick-nav button {
  min-height: 47px;
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #d9e3ec;
  text-align: left;
  font-size: 14px;
}

.quick-nav button:hover {
  background: var(--sidebar-soft);
}

.quick-nav span {
  width: 26px;
  color: var(--telegram);
  font-size: 22px;
  text-align: center;
}

.storage-note {
  margin: 18px 20px;
  color: #73879a;
  font-size: 11px;
  line-height: 1.5;
}

.chat-panel {
  position: relative;
  min-width: 0;
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto auto;
  overflow: hidden;
  background: var(--chat);
}

.chat-wallpaper {
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-color: #41556a transparent;
  scrollbar-gutter: stable;
  background:
    linear-gradient(rgba(14, 22, 33, 0.89), rgba(14, 22, 33, 0.89)),
    radial-gradient(circle at 24px 24px, rgba(255, 255, 255, 0.06) 2px, transparent 3px) 0 0 / 48px 48px,
    radial-gradient(circle at 0 0, rgba(51, 144, 236, 0.08), transparent 34%);
}

.messages {
  width: min(760px, calc(100% - 28px));
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  gap: 8px;
  margin: 0 auto;
  padding: 22px 0 18px;
}

.messages::before {
  content: "";
  flex: 1 1 auto;
  min-height: 0;
}

.message {
  position: relative;
  max-width: min(590px, 88%);
  padding: 10px 12px 7px;
  border-radius: 12px;
  background: var(--bubble);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.14);
  animation: bubble-in 180ms ease both;
}

.message.bot {
  align-self: flex-start;
  border-bottom-left-radius: 3px;
}

.message.user {
  align-self: flex-end;
  border-bottom-right-radius: 3px;
  background: var(--bubble-user);
}

.message-text {
  margin: 0;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  font-size: 14px;
  line-height: 1.45;
}

.message-code {
  max-height: 280px;
  overflow: auto;
  margin: 9px 0 2px;
  padding: 10px;
  border-radius: 7px;
  background: rgba(0, 0, 0, 0.28);
  color: #d7e7f4;
  font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}

.message-time {
  display: block;
  margin-top: 4px;
  color: rgba(255, 255, 255, 0.46);
  font-size: 10px;
  text-align: right;
}

.message-actions {
  width: min(590px, 88%);
  align-self: flex-start;
  display: grid;
  gap: 3px;
  margin-top: -5px;
}

.action-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 3px;
}

.message-actions button {
  min-height: 41px;
  padding: 7px 9px;
  border: 0;
  border-radius: 7px;
  background: #25384b;
  color: #65b8ff;
  font-size: 12px;
  font-weight: 850;
}

.message-actions button:hover {
  background: #2d455c;
}

.message-actions button.danger {
  color: #ff8585;
}

.message-actions button.success {
  color: #65e5a7;
}

.message-actions button[disabled] {
  opacity: 0.45;
  cursor: default;
}

.message.typing {
  min-width: 62px;
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}

.message.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-dot 1.15s infinite ease-in-out;
}

.message.typing i:nth-child(2) {
  animation-delay: 140ms;
}

.message.typing i:nth-child(3) {
  animation-delay: 280ms;
}

.scroll-bottom {
  position: absolute;
  z-index: 8;
  right: 18px;
  bottom: 76px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #263747;
  color: #d8e8f7;
  box-shadow: 0 8px 24px #0008;
  font-size: 12px;
  font-weight: 800;
}

.scroll-bottom[hidden] {
  display: none;
}

.scroll-bottom span {
  color: var(--telegram);
  font-size: 18px;
}

.pending-files {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 8px 12px;
  border-top: 1px solid var(--line);
  background: #18232e;
}

.pending-file {
  position: relative;
  width: 62px;
  height: 62px;
  flex: 0 0 62px;
  overflow: hidden;
  border-radius: 8px;
  background: #273747;
}

.pending-file img,
.pending-file video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.pending-file button {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 20px;
  height: 20px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: #000b;
}

.composer {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: end;
  gap: 7px;
  padding: 9px 12px 11px;
  border-top: 1px solid var(--line);
  background: #17212b;
}

.composer textarea {
  width: 100%;
  max-height: 150px;
  resize: none;
  padding: 11px 13px;
  border: 0;
  border-radius: 20px;
  outline: 0;
  background: #242f3d;
  color: var(--text);
  line-height: 1.4;
}

.composer textarea::placeholder {
  color: #7f91a2;
}

.attach-button,
.send-button {
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
}

.attach-button {
  background: transparent;
  color: var(--muted);
  font-size: 28px;
}

.send-button {
  display: grid;
  place-items: center;
  background: var(--telegram);
}

.send-button svg {
  width: 21px;
  fill: none;
  stroke: #fff;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.device-frame {
  width: calc(100% - 24px);
  height: calc(100% - 76px);
  min-height: 500px;
  margin: 10px auto 12px;
  overflow: hidden;
  border: 8px solid #111820;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 22px 55px rgba(0, 0, 0, 0.3);
}

.device-bar {
  height: 31px;
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0 9px;
  border-bottom: 1px solid #d8dde2;
  background: #eef1f4;
  color: #64717c;
  font-size: 10px;
}

.device-bar i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #b7bec5;
}

.device-bar span {
  min-width: 0;
  margin-left: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.device-frame iframe {
  width: 100%;
  height: calc(100% - 31px);
  border: 0;
  background: #fff;
}

.mobile-tabs {
  display: none;
}

.toast {
  position: fixed;
  z-index: 100;
  left: 50%;
  bottom: 18px;
  max-width: calc(100% - 30px);
  padding: 11px 16px;
  border-radius: 9px;
  background: #f5f7fa;
  color: #17212b;
  box-shadow: 0 12px 38px #0007;
  opacity: 0;
  transform: translate(-50%, 18px);
  pointer-events: none;
  transition: 180ms ease;
  font-size: 13px;
  font-weight: 750;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@keyframes bubble-in {
  from {
    opacity: 0;
    transform: translateY(6px) scale(0.98);
  }
}

@keyframes typing-dot {
  0%,
  60%,
  100% {
    opacity: 0.35;
    transform: translateY(0);
  }

  30% {
    opacity: 1;
    transform: translateY(-3px);
  }
}

@media (max-width: 1180px) {
  .builder-header {
    grid-template-columns: 230px 1fr auto;
  }

  .builder-shell {
    grid-template-columns: 230px minmax(360px, 1fr);
  }

  .preview-panel {
    position: fixed;
    inset: var(--header-h) 0 0 230px;
    z-index: 15;
    display: none;
  }

  body[data-panel="preview"] .preview-panel {
    display: block;
  }
}

@media (max-width: 760px) {
  :root {
    --header-h: 58px;
  }

  body {
    padding-bottom: 52px;
  }

  .builder-header {
    grid-template-columns: auto minmax(0, 1fr) auto;
    min-height: var(--header-h);
    padding: 6px 9px;
  }

  .back-home {
    width: 38px;
    font-size: 0;
  }

  .back-home span {
    font-size: 26px;
  }

  .builder-identity .bot-avatar {
    width: 40px;
    height: 40px;
    flex-basis: 40px;
  }

  .header-tools button:first-child {
    display: none;
  }

  .header-tools .primary-tool {
    width: 42px;
    padding: 0;
    overflow: hidden;
    color: transparent;
  }

  .header-tools .primary-tool::after {
    content: "↓";
    color: #fff;
    font-size: 22px;
  }

  .builder-shell {
    height: calc(100vh - var(--header-h) - 52px);
    display: block;
  }

  .chat-panel,
  .project-panel,
  .preview-panel {
    position: fixed;
    inset: var(--header-h) 0 52px;
    display: none;
    border: 0;
  }

  body:not([data-panel]),
  body[data-panel="chat"] {
    overflow: hidden;
  }

  body:not([data-panel]) .chat-panel,
  body[data-panel="chat"] .chat-panel,
  body[data-panel="project"] .project-panel,
  body[data-panel="preview"] .preview-panel {
    display: grid;
  }

  body[data-panel="project"] .project-panel,
  body[data-panel="preview"] .preview-panel {
    overflow: auto;
  }

  .messages {
    width: calc(100% - 18px);
  }

  .message,
  .message-actions {
    max-width: 94%;
    width: auto;
  }

  .device-frame {
    min-height: 0;
    height: calc(100% - 68px);
  }

  .mobile-tabs {
    position: fixed;
    inset: auto 0 0;
    z-index: 30;
    height: 52px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border-top: 1px solid var(--line);
    background: #1d2a35;
  }

  .mobile-tabs button {
    border: 0;
    background: transparent;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
  }

  .mobile-tabs button.active {
    color: var(--telegram);
  }
}
