/* ── Reset & Variables ─────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg:           #0f1a0f;
  --bg2:          #1a2e1a;
  --bg3:          #1e3a1e;
  --accent:       #4caf50;
  --accent-dark:  #388e3c;
  --accent-light: #81c784;
  --text:         #e8f5e9;
  --text-muted:   #5a8a5a;
  --border:       #2e5a2e;
  --shadow:       rgba(0,0,0,0.5);
  --radius:       12px;
  --sidebar-w:    240px;
  --user-bubble:  #2e7d32;
  --bot-bubble:   #1e3a1e;
}

html, body {
  height: 100%;
  height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  overflow: hidden;
  position: fixed;
  width: 100%;
}

/* ── Auth Page ─────────────────────────────────────────────────────────────── */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-container {
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.auth-logo {
  margin-bottom: 32px;
}

.logo-icon {
  font-size: 56px;
  display: block;
  margin-bottom: 12px;
}

.auth-logo h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent-light);
}

.auth-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-top: 4px;
}

.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  margin-bottom: 20px;
}

.auth-desc {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 24px;
  line-height: 1.6;
}

.btn-yandex {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: #FC3F1D;
  color: #fff;
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 24px;
  border-radius: 8px;
  transition: background 0.2s;
  width: 100%;
  justify-content: center;
}

.btn-yandex:hover {
  background: #e0361a;
}

.auth-footer {
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.6;
}

.auth-footer a {
  color: var(--accent-light);
}

/* ── Cabinet Layout ────────────────────────────────────────────────────────── */

.cabinet-page {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  transition: transform 0.25s;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo { font-size: 24px; }

.sidebar-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--accent-light);
  flex: 1;
}

.sidebar-close {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
}

.user-block {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--border);
}

.user-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg3);
  border: 2px solid var(--border);
  flex-shrink: 0;
}

.user-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-email {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}

.nav-btn:hover {
  background: var(--bg3);
  color: var(--text);
}

.nav-btn.active {
  background: rgba(76, 175, 80, 0.15);
  color: var(--accent-light);
}

.nav-icon { font-size: 16px; }

.btn-logout {
  margin: 12px;
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  padding: 9px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-logout:hover {
  background: rgba(255,50,50,0.1);
  color: #ef9a9a;
  border-color: #c62828;
}

/* Main content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  flex-shrink: 0;
}

.hamburger {
  display: none;
  background: none;
  border: none;
  color: var(--text);
  font-size: 22px;
  cursor: pointer;
  padding: 4px;
}

.page-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--accent-light);
  flex: 1;
}

.status-indicator {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
  animation: pulse 2.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Tab content */
.tab-content {
  display: none;
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.tab-content.active {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Cards */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--accent-light);
  margin-bottom: 16px;
}

.card-desc {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 20px;
}

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus {
  border-color: var(--accent);
}

.form-group input.readonly {
  color: var(--text-muted);
  cursor: default;
}

.form-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 4px;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 22px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover { background: var(--accent-dark); }

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-secondary:hover { background: var(--bg3); }

.save-status {
  font-size: 13px;
  color: var(--accent-light);
}

/* Channel items */
.channel-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}

.channel-item:last-child { border-bottom: none; }

.channel-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.channel-icon { font-size: 24px; }

.channel-name {
  font-weight: 600;
  font-size: 14px;
}

.channel-status {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.channel-status.linked { color: var(--accent-light); }

.channel-actions {
  display: flex;
  gap: 8px;
}

.btn-link {
  background: rgba(76, 175, 80, 0.15);
  color: var(--accent-light);
  border: 1px solid var(--accent-dark);
  border-radius: 7px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-link:hover { background: rgba(76, 175, 80, 0.28); }

.btn-unlink {
  background: rgba(255, 100, 100, 0.1);
  color: #ef9a9a;
  border: 1px solid #c62828;
  border-radius: 7px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-unlink:hover { background: rgba(255, 100, 100, 0.2); }

.hidden { display: none !important; }

/* ── Chat ──────────────────────────────────────────────────────────────────── */

#tab-chat {
  padding: 0;
}

#tab-chat.active {
  gap: 0;
}

.chat-wrapper {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Welcome screen inside chat */
.chat-welcome {
  margin: auto;
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 40px 20px;
}

.chat-welcome-icon { font-size: 48px; }

.chat-welcome-title {
  font-size: 18px;
  color: var(--accent-light);
  font-weight: 600;
}

.chat-welcome-text {
  font-size: 14px;
  max-width: 300px;
}

/* Message rows */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  animation: msgFadeIn 0.2s ease;
}

@keyframes msgFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.msg-row.user { justify-content: flex-end; }
.msg-row.bot  { justify-content: flex-start; }

.msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  background: var(--bg2);
}

.msg-bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 14.5px;
  line-height: 1.55;
  overflow-wrap: break-word;
  word-break: normal;
  min-width: 60px;
}

.msg-row.user .msg-bubble {
  background: var(--user-bubble);
  color: #e8f5e9;
  border-bottom-right-radius: 5px;
}

.msg-row.bot .msg-bubble {
  background: var(--bot-bubble);
  color: #c8e6c9;
  border-bottom-left-radius: 5px;
  border: 1px solid var(--border);
}

/* Markdown content inside bubble */
.msg-bubble strong { color: var(--accent-light); font-weight: 700; }
.msg-bubble em { font-style: italic; }
.msg-bubble ul, .msg-bubble ol { padding-left: 18px; margin: 6px 0; }
.msg-bubble li { margin: 2px 0; }
.msg-bubble code {
  background: rgba(0,0,0,0.3);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 13px;
  color: #a5d6a7;
}
.msg-bubble pre {
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  padding: 10px;
  margin: 8px 0;
  overflow-x: auto;
  font-size: 13px;
}
.msg-bubble pre code { background: none; padding: 0; }
.msg-bubble p { margin: 4px 0; }
.msg-bubble hr { border: none; border-top: 1px solid var(--border); margin: 8px 0; }

.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.msg-row.user .msg-meta { justify-content: flex-end; }

.channel-badge {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 10px;
  color: var(--text-muted);
}

/* Thinking animation */
.msg-row.thinking .msg-bubble {
  padding: 12px 16px;
}

.thinking-dots {
  display: flex;
  gap: 5px;
  align-items: center;
}

.thinking-dots span {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  animation: dotBounce 1.2s infinite;
}

.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes dotBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
  30% { transform: translateY(-5px); opacity: 1; }
}

.thinking-text {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: 6px;
}

/* Chat input bar */
.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input-wrap {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 8px 14px;
  display: flex;
  align-items: flex-end;
  transition: border-color 0.2s;
}

.chat-input-wrap:focus-within {
  border-color: var(--accent);
}

.chat-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  resize: none;
  max-height: 120px;
  min-height: 22px;
  overflow-y: auto;
  font-family: inherit;
}

.chat-input::placeholder { color: var(--text-muted); }

.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: none;
  background: var(--accent-dark);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.1s;
}

.chat-send-btn:hover { background: var(--accent); }
.chat-send-btn:active { transform: scale(0.92); }
.chat-send-btn:disabled { background: var(--bg2); opacity: 0.5; cursor: not-allowed; }

/* ── Modal ─────────────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  text-align: center;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-light);
  margin-bottom: 12px;
}

.modal-desc {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.link-code {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 0.18em;
  color: var(--accent-light);
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
  font-family: monospace;
}

/* Link code container */
.link-code-container {
  background: var(--bg);
  border: 1px solid var(--accent-dark);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.link-code-label {
  font-size: 13px;
  color: var(--text-muted);
}

.btn-copy-code {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--accent-light);
  font-size: 13px;
  padding: 7px 16px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-copy-code:hover {
  border-color: var(--accent);
  background: var(--bg3);
}

.btn-copy-code.copied {
  background: var(--accent-dark);
  border-color: var(--accent);
  color: #fff;
}

/* Steps */
.link-steps {
  background: var(--bg);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 16px;
  text-align: left;
}

.link-steps-title {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-weight: 600;
  margin-bottom: 10px;
}

.link-step-item {
  font-size: 13px;
  color: #c8e6c9;
  padding: 4px 0;
  display: flex;
  gap: 8px;
  line-height: 1.5;
}

.link-step-num {
  color: var(--accent);
  font-weight: 700;
  flex-shrink: 0;
}

.btn-open-bot {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--accent-dark);
  color: #fff;
  text-decoration: none;
  font-size: 15px;
  font-weight: 600;
  padding: 12px 24px;
  border-radius: 12px;
  margin-bottom: 14px;
  transition: background 0.15s;
  width: 100%;
  justify-content: center;
}

.btn-open-bot:hover { background: var(--accent); }

/* Waiting spinner */
.link-waiting {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  color: var(--text-muted);
  font-size: 12px;
  margin-bottom: 14px;
}

.link-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.modal-feedback {
  margin-top: 14px;
  font-size: 13px;
  min-height: 20px;
}

/* ── Sidebar overlay (mobile) ──────────────────────────────────────────────── */

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ── Scrollbar ─────────────────────────────────────────────────────────────── */

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Responsive ────────────────────────────────────────────────────────────── */

@media (max-width: 680px) {
  html, body {
    position: fixed;
    overflow: hidden;
    width: 100%;
    height: 100%;
    height: 100dvh;
  }

  .cabinet-page {
    height: 100dvh;
  }

  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
  }

  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay.open { display: block; }

  .sidebar-close { display: block; }

  .hamburger { display: flex; }

  .main-content {
    overflow: hidden;
  }

  .tab-content { padding: 16px; }
  #tab-chat { padding: 0; }

  .form-grid { grid-template-columns: 1fr; }

  .chat-messages { padding: 12px 14px; }

  .chat-input-bar {
    position: sticky;
    bottom: 0;
    z-index: 10;
  }
}
