/**
 * Базовые стили, шрифты, reset
 * Mobile-first (vision.md: базовые стили БЕЗ media queries)
 */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px; /* vision.md: минимум 16px, iOS не зумит input */
  line-height: 1.5;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App layout — mobile: один экран, desktop: sidebar + chat */
.app {
  display: flex;
  height: 100%;
  width: 100%;
  overflow: hidden;
}

/* Sidebar — скрываемая панель */
.sidebar {
  width: 0;
  height: 100%;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar.open {
  width: 300px;
}

/* Main area — tabs + chat */
.main-area {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow: hidden;
}

/* Chat area */
.chat-area {
  display: none;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  height: 100%;
  background: var(--bg-tertiary);
  overflow: hidden;
}

/* Tabs bar */
.tabs-bar {
  display: flex;
  align-items: center;
  height: 40px;
  background: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  padding: 0 4px;
  gap: 2px;
  overflow: hidden;
}

.tabs-toggle-sidebar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  min-height: 32px;
  border-radius: 6px;
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

.tabs-toggle-sidebar:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.tabs-toggle-sidebar svg {
  width: 18px;
  height: 18px;
}

.sidebar.open ~ .main-area .tabs-toggle-sidebar {
  color: var(--accent);
}

/* Tabs container */
.tabs-container {
  display: flex;
  flex: 1;
  overflow-x: auto;
  gap: 2px;
  min-width: 0;
  scrollbar-width: none;
}

.tabs-container::-webkit-scrollbar { display: none; }

/* Tab item */
.tab {
  height: 32px;
  min-height: 32px;
  min-width: 0;
  max-width: 180px;
  padding: 0 8px;
  border-radius: 6px;
  border: none;
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, color 0.15s;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  flex-shrink: 0;
}

.tab:hover {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.tab.active {
  background: var(--accent-light, #e6f0ff);
  color: var(--accent);
}

.tab-name {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.tab-close {
  width: 16px;
  height: 16px;
  min-width: 16px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  color: inherit;
}

.tab:hover .tab-close {
  opacity: 0.6;
}

.tab-close:hover {
  opacity: 1 !important;
  background: rgba(0, 0, 0, 0.1);
}

/* Tab status dot */
.tab-dot {
  width: 7px;
  height: 7px;
  min-width: 7px;
  border-radius: 50%;
  background: var(--text-secondary);
  opacity: 0.3;
  flex-shrink: 0;
}

.tab-dot.online {
  background: #00875A;
  opacity: 1;
}

/* Tab activity indicators */
.tab-typing .tab-name {
  font-style: italic;
  opacity: 0.8;
}

.tab-typing::after {
  content: '';
  width: 6px;
  height: 6px;
  min-width: 6px;
  border-radius: 50%;
  background: var(--accent, #0066ff);
  animation: tab-pulse 1s ease-in-out infinite;
  margin-left: -2px;
}

.tab-new-msg {
  color: var(--text-primary);
  font-weight: 600;
}

.tab-new-msg .tab-dot {
  background: var(--accent, #0066ff);
  opacity: 1;
  animation: tab-pulse 1.5s ease-in-out infinite;
}

@keyframes tab-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

/* Tab drag & drop */
.tab-dragging {
  opacity: 0.4;
}

.tab-drop-before {
  box-shadow: -2px 0 0 0 var(--accent, #0066ff);
}

.tab-drop-after {
  box-shadow: 2px 0 0 0 var(--accent, #0066ff);
}

/* Chat area — всегда flex на десктопе, скрыт на мобильном */
@media (min-width: 768px) {
  .chat-area {
    display: flex;
  }
}

/* Mobile layout */
@media (max-width: 767px) {
  /* На мобиле sidebar — полный экран по умолчанию */
  .sidebar {
    width: 100%;
    transition: none;
  }

  /* main-area скрыт пока не выбран чат */
  .main-area {
    display: none;
  }

  /* При выборе чата: sidebar прячется, main показывается */
  .app.chat-open .sidebar {
    width: 0;
    display: none;
  }

  .app.chat-open .main-area {
    display: flex;
  }

  .app.chat-open .chat-area {
    display: flex;
  }

  /* Tabs на мобиле: убрать скрытие табов, показать кнопку назад */
  .tabs-toggle-sidebar svg {
    transform: rotate(180deg);
  }

  .tabs-bar {
    height: 44px;
    padding: 0 4px;
  }

  .tab {
    max-width: 140px;
    font-size: 12px;
  }
}

/* Десктоп 1024px+ */
@media (min-width: 1024px) {
  .sidebar.open {
    width: 340px;
  }
}

/* Кнопки — минимум 44x44 touch target (vision.md) */
button, .btn {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  font-size: inherit;
  min-height: 44px;
  min-width: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:disabled {
  opacity: 0.5;
  cursor: default;
}

/* Скроллбар */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-secondary); }

/* ====== LOGIN SCREEN (4.1) ====== */
.login-screen {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  z-index: 9999;
}

.login-card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 32px;
  max-width: 380px;
  width: 90%;
  text-align: center;
  box-shadow: 0 2px 8px var(--shadow);
}

.login-logo {
  margin-bottom: 16px;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 32px;
}

.login-step {
  margin-bottom: 20px;
}

.login-bot-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 12px 20px;
  background: #0088cc;
  color: #fff;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
  min-height: 48px;
}
.login-bot-btn:hover { background: #006fa8; }
.login-bot-btn svg { flex-shrink: 0; stroke: #fff; }

/* Ожидание подтверждения от бота */
.login-waiting {
  padding: 24px 0 16px;
}

.login-spinner {
  width: 40px;
  height: 40px;
  margin: 0 auto 16px;
  border: 3px solid var(--border);
  border-top-color: #0088cc;
  border-radius: 50%;
  animation: login-spin 0.8s linear infinite;
}

@keyframes login-spin {
  to { transform: rotate(360deg); }
}

.login-waiting-text {
  font-size: 15px;
  color: var(--text-primary);
  line-height: 1.5;
  margin-bottom: 8px;
}

.login-waiting-hint {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.login-back-btn {
  display: block;
  width: 100%;
  margin-top: 8px;
  padding: 10px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  min-height: 44px;
}
.login-back-btn:hover { color: var(--text-primary); }

.login-error {
  display: none;
  color: var(--danger);
  font-size: 14px;
  padding: 10px 12px;
  background: rgba(222, 53, 11, 0.08);
  border-radius: 8px;
  margin-bottom: 16px;
  text-align: center;
}

.login-hint {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
}

/* Утилиты */
.hidden { display: none !important; }

/* Dim overlay для модалов */
.dim {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: none;
}
.dim.active { display: block; }
