@import url("https://fonts.googleapis.com/css2?family=Inter:wght@100..900&display=swap");

:root {
  --bg-page: #fff;
  --bg-sidebar: #f7f7f8;
  --bg-chat: #ffffff;
  --bg-chat-alt: #f3f4f6;
  --border-subtle: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #000;
  --accent-soft: rgb(0, 168, 126);
  --text-primary: #0d0d0d;
  --text-secondary: #8f8f8f;
  --text-muted: #9ca3af;
  --danger: #ef4444;
  --shadow-soft: 0 8px 24px rgba(15, 23, 42, 0.1);
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 999px;

  --sidebar-w: 260px;
  --sidebar-w-collapsed: 72px;
}

/* base */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: "Inter", sans-serif;
  background: var(--bg-page);
  color: var(--text-primary);
}

.page {
  min-height: 100vh;
}

/* layout */

.app {
  display: flex;
  height: 100svh;
}

/* SIDEBAR */

.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  transition: width 0.18s ease, min-width 0.18s ease;
}
.sidebar-inner {
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
}

.sidebar-logo {
  border: 0;
  background: transparent;
  padding: 4px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.sidebar-logo:hover {
  background: #ececec;
}

.logo-mark {
  display: block;
}
.expand-mark {
  display: none;
}

.sidebar-hide {
  border: none;
  background: transparent;
  font-size: 16px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  border-radius: 8px;
}
.sidebar-hide:hover {
  background: #ececec;
}

.sidebar-section {
  width: 100%;
  margin-top: 12px;
}

.sidebar-new-chat {
  border: none;
  border-radius: var(--radius-md);
  background: transparent;
  padding: 7px 12px;
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}
.sidebar-new-chat:hover {
  background: #e5e7eb;
}
.sidebar-new-chat .icon {
  flex: 0 0 20px;
}
.sidebar-new-chat span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Футер сайдбара + плашка юзера */
.sidebar-footer {
  margin-top: auto;
  font-size: 11px;
  color: var(--text-muted);
  display: grid;
  gap: 8px;
}
.user-badge {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background: #fff;
}
.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  background: #7c3aed;
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.02em;
}
.user-meta {
  display: grid;
  gap: 2px;
}
.user-name {
  text-wrap: nowrap;
  font-size: 13px;
  color: #111827;
}
.user-plan {
  font-size: 12px;
  color: var(--text-muted);
}
.user-menu {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  color: #6b7280;
  padding: 0 4px;
}

/* MAIN PANEL (RIGHT) */

.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100svh;
  overflow: hidden;
}

/* header */

.main-header {
  border-bottom: 1px solid var(--border-subtle);
}
.main-header-inner {
  padding: 8px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.main-header-title {
  font-size: 18px;
  font-weight: 300;
}
.main-header-subtitle {
  color: var(--text-secondary);
  margin-left: 4px;
}

.main-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.header-action-btn {
  border: none;
  border-radius: var(--radius-full);
  background: none;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
  color: var(--text-primary);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}
.header-action-btn:hover {
  background: #f3f4f6;
}

.header-mobile-newchat-btn {
  display: none;
  width: 30px;
  height: 30px;
  border-radius: 12px;
  border: none;
  background: transparent;
  font-size: 20px;
  line-height: 1;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-primary);
}
.header-mobile-newchat-btn:hover {
  background: #00000012;
}

.header-mobile-logo {
  display: none;
  width: 24px;
  height: 24px;
  margin-right: 8px;
}

@media (max-width: 768px) {
  .header-mobile-logo {
    display: inline-block;
  }
  .main-header-inner {
    gap: 10px;
  }
}

/* chat layout */

.chat-layout {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: stretch;
  overflow: hidden;
  min-height: 0;
}
.chat-shell {
  height: 100%;
  width: 100%;
  max-width: 960px;
  margin: 8px 20px 16px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* MESSAGES */

.chat-messages {
  flex: 1;
  padding: 16px 18px;
  overflow-y: auto;
  scroll-behavior: smooth;
}
.chat-messages::-webkit-scrollbar {
  width: 6px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 999px;
}

/* message bubble */

.message {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
  font-size: 14px;
}
.message:last-child {
  margin-bottom: 0;
}
.message-bubble {
  border-radius: 12px;
  padding: 12px 16px;
  background: var(--bg-chat-alt);
}
.message-text {
  white-space: normal;
  line-height: 1.5;
}
.message--user .message-text {
  white-space: pre-wrap;
}

.message-text p {
  margin: 0 0 8px;
}
.message-text p:last-child {
  margin-bottom: 0;
}
.message-text .message-heading {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 10px;
}
.message-text ul.message-list {
  margin: 0 0 8px 1.1em;
  padding-left: 1em;
}
.message-text ul.message-list li {
  margin-bottom: 4px;
}
.message-text ul.message-list li:last-child {
  margin-bottom: 0;
}
.message-text ul.message-list li.is-empty {
  list-style-type: none;
}

.message--bot .message-bubble {
  background: transparent;
}
.message--user {
  justify-content: flex-end;
}
.message--user .message-main {
  text-align: right;
}
.message--user .message-bubble {
  background: #e9e9e980;
}

/* typing indicator */
.message--typing .message-bubble {
  display: inline-flex;
  align-items: center;
}
.typing-indicator {
  display: inline-flex;
  gap: 4px;
}
.typing-indicator span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: #9ca3af;
  opacity: 0.4;
  animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-indicator span:nth-child(2) {
  animation-delay: 0.18s;
}
.typing-indicator span:nth-child(3) {
  animation-delay: 0.36s;
}
@keyframes typingBounce {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  40% {
    transform: translateY(-2px);
    opacity: 1;
  }
}

/* SUGGESTIONS */
.chat-suggestions {
  padding: 8px 18px 10px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  flex-shrink: 0;
  background: #fff;
}
.chat-suggestions.chat-suggestions--hidden {
   display: none;
}
.chat-suggestions.chat-suggestions--typing-hidden {
  display: none;
}
.chat-suggestions.chat-suggestions--consumed {
  display: none;
}
.chat-suggestions.chat-suggestions--template {
  display: none;
}
.chat-suggestion {
  font-size: 12px;
  padding: 6px 10px;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-subtle);
  background: #ffffff;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: normal;
  max-width: 100%;
}
.chat-suggestion:hover {
  background: #f3f4f6;
}
.chat-suggestion--primary {
  border-color: rgba(16, 163, 127, 0.8);
  background: var(--accent-soft);
  color: #fff;
  font-weight: 500;
  font-size: 13px;
}
.chat-suggestion--primary:hover {
  filter: brightness(1.05);
  background: var(--accent-soft);
}
.chat-suggestion:disabled {
  opacity: 0.6;
  cursor: default;
}
.message--suggestions {
  margin-top: -2px;
}
.chat-inline-cta {
  width: 100%;
  min-width: 220px;
}

/* INPUT */
.chat-input-area {
  padding: 10px 18px calc(14px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
  background: #fff;
  border-top: 1px solid var(--border-subtle);
}
.chat-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: var(--radius-full);
  background: #ffffff;
  border: 1px solid var(--border-subtle);
  padding: 7px 8px 7px 12px;
}
.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  overflow: hidden;
  color: var(--text-primary);
  font: inherit;
  font-size: 14px;
  max-height: 140px;
}
.chat-input::placeholder {
  color: var(--text-muted);
}

.chat-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  color: #fff;
  opacity: 0.5;
  transition: opacity 0.12s ease;
}
.chat-send-btn:not(:disabled) {
  opacity: 1;
}
.chat-send-btn:hover {
  filter: brightness(1.05);
}
.chat-send-btn:disabled {
  cursor: default;
  box-shadow: none;
}
.chat-send-icon {
  width: 20px;
  height: 20px;
  fill: #fff;
}

.chat-input-hint {
  text-align: center;
  margin: 0;
  font-size: 11px;
  color: var(--text-muted);
}

/* lead form inside message */
.lead-form-wrapper {
  display: flex;
  flex-direction: column;
  gap: 6px;
  white-space: normal;
}
.lead-form-wrapper * {
  white-space: normal;
}
.lead-form-title {
  margin: 0 0 4px;
  font-size: 13px;
  color: var(--text-primary);
}
.lead-form-note {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.lead-form {
  display: grid;
  gap: 6px;
}
.lead-form-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.lead-form-row label {
  font-size: 11px;
  color: var(--text-muted);
}
.lead-form-row input {
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  background: #f9fafb;
  color: var(--text-primary);
  padding: 7px 9px;
  font-size: 13px;
}
.lead-form-row input::placeholder {
  color: #9ca3af;
}
.lead-form-row input:focus {
  outline: 1px solid rgba(16, 163, 127, 0.7);
  border-color: rgba(16, 163, 127, 0.7);
  background: #ffffff;
}
.lead-form-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}
.lead-form-submit {
  display: flex;
  border-radius: var(--radius-full);
  border: none;
  padding: 12px 16px;
  font-size: 14px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  font-weight: 500;
}
.lead-form-submit:hover {
  filter: brightness(1.05);
}
.lead-form-caption {
  font-size: 11px;
  color: var(--text-muted);
}
.lead-form.is-submitted {
  opacity: 0.7;
}

#leadFormParking {
  display: none;
}

/* welcome stats table */
.welcome-stats-title {
  margin: 0 0 8px;
  font-weight: 600;
  font-size: inherit;
  line-height: inherit;
}
.welcome-stats-subtitle {
  margin: 0 0 8px;
  color: inherit;
  font-size: inherit;
  line-height: inherit;
}
.welcome-stats-table {
  width: 100%;
  border-collapse: collapse;
  font-size: inherit;
  margin: 0 0 8px;
}
.welcome-stats-table th,
.welcome-stats-table td {
  border: 1px solid var(--border-subtle);
  padding: 7px 6px;
  text-align: left;
  vertical-align: top;
}
.welcome-stats-table th {
  background: #f9fafb;
  font-weight: 600;
}
.welcome-stats-note {
  margin: 8px 0;
  font-size: inherit;
}
.welcome-stats-summary-title {
  margin: 0 0 4px;
  font-weight: 600;
  font-size: inherit;
}
.welcome-stats-summary {
  margin: 0;
  font-size: inherit;
}

/* TOASTS */
.toast-container {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  top: 16px;
  display: grid;
  gap: 8px;
  z-index: 50;
  width: min(560px, calc(100vw - 24px));
}
.toast {
  border: 1px solid var(--border-subtle);
  background: #fff;
  color: #111827;
  font-size: 13px;
  border-radius: 10px;
  box-shadow: var(--shadow-soft);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  opacity: 0;
  transform: translateY(-6px);
  transition: opacity 0.16s ease, transform 0.16s ease;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}

/* RESPONSIVE */

@media (max-width: 960px) {
  .chat-shell {
    margin: 8px 12px 16px;
  }
  .main-header-inner {
    padding-inline: 12px;
  }
}

@media (max-width: 768px) {
  .sidebar {
    display: none;
  }
  .main-header-actions {
    display: none;
  }
  .header-mobile-newchat-btn {
    display: inline-flex;
  }
  .chat-shell {
    border-radius: 0;
    border-left: none;
    border-right: none;
    max-width: 100%;
    margin: 0 12px calc(12px + env(safe-area-inset-bottom));
    height: 100%;
    min-height: 0;
  }
}

@media (max-width: 480px) {
  .chat-messages {
    padding-inline: 12px;
  }
  .message--bot .message-main {
    width: 100%;
  }
  .chat-suggestions {
    flex-direction: column;
    align-items: stretch;
    flex-wrap: nowrap;
  }
  .chat-suggestion {
    width: 100%;
    white-space: normal;
    font-size: 16px;
    padding: 10px 14px;
  }
  .chat-inline-cta {
    font-size: 17px;
    padding: 12px 16px;
  }

  .chat-input {
    font-size: 16px;
  }
  /* font sized responsive */
  .main-header-title {
    font-size: 18px;
  }
  .header-action-btn {
    font-size: 12px;
    padding: 8px 10px;
  }
  .message {
    font-size: 16px;
  }
  .welcome-stats-title {
    font-size: inherit;
  }
  .welcome-stats-subtitle,
  .welcome-stats-note,
  .welcome-stats-summary {
    font-size: inherit;
  }
  .welcome-stats-table {
    display: block;
    border: none;
  }
  .welcome-stats-table thead {
    display: none;
  }
  .welcome-stats-table tbody {
    display: grid;
    gap: 8px;
  }
  .welcome-stats-table tr {
    display: grid;
    gap: 4px;
    border: 1px solid var(--border-subtle);
    border-radius: 10px;
    padding: 8px;
    background: #f9fafb;
  }
  .welcome-stats-table td {
    border: none;
    border-bottom: 1px dashed #e5e7eb;
    padding: 2px 0 4px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 2px;
    font-size: inherit;
  }
  .welcome-stats-table td:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }
  .welcome-stats-table td::before {
    content: attr(data-label);
    font-size: 12px;
    color: #6b7280;
    font-weight: 600;
  }
}

@media (max-width: 768px) {
  .chat-suggestions {
    border-top: 0;
    padding: 6px 0 10px;
  }
}

/* --- СВЁРНУТЫЙ САЙДБАР --- */
.sidebar.is-collapsed {
  width: var(--sidebar-w-collapsed);
  min-width: var(--sidebar-w-collapsed);
}
.sidebar.is-collapsed .sidebar-new-chat span,
.sidebar.is-collapsed .sidebar-section-title,
.sidebar.is-collapsed .sidebar-small,
.sidebar.is-collapsed .user-meta,
.sidebar.is-collapsed .user-menu,
.sidebar.is-collapsed .sidebar-hide {
  display: none;
}
.sidebar.is-collapsed .sidebar-footer {
  gap: 0;
}
.sidebar.is-collapsed .user-badge {
  grid-template-columns: 36px;
  justify-items: center;
  padding: 6px;
}
.sidebar.is-collapsed .sidebar-inner {
  padding-left: 10px;
  padding-right: 10px;
}
.sidebar.is-collapsed .sidebar-logo .logo-mark {
  display: block;
}
.sidebar.is-collapsed .sidebar-logo:hover .logo-mark {
  display: none;
}
.sidebar.is-collapsed .sidebar-logo:hover .expand-mark {
  display: block;
}
