:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-secondary: #475569;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --border: #e2e8f0;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.15s ease;
}
[data-theme="dark"] {
  --bg: #0b1121;
  --surface: #1e293b;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --border: #334155;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Аутентификация (модалка) */
.modal-overlay {
  background: var(--bg);
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2.5rem;
  max-width: 400px;
  width: 90%;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}
.modal h2 { margin-bottom: 1.5rem; }
.modal input {
  width: 100%;
  padding: 0.75rem;
  margin-bottom: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
.modal p { margin: 1rem 0; font-size: 0.9rem; }
.modal a { color: var(--accent); text-decoration: none; }

/* Главный интерфейс */
.app {
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Верхняя панель */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
}
.logo {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.badge {
  background: var(--accent);
  color: #fff;
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
}
.topbar-nav {
  display: flex;
  gap: 0.3rem;
}
.nav-item {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover, .nav-item.active {
  background: var(--border);
  color: var(--text);
}
.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.user-info {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
}
.quota-badge {
  background: var(--bg);
  padding: 0.2rem 0.6rem;
  border-radius: 20px;
  font-size: 0.8rem;
  border: 1px solid var(--border);
}
.icon-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 0.3rem;
  transition: background var(--transition);
}
.icon-btn:hover { background: var(--border); }

/* Основной контент */
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 2rem;
}
.tab-content { display: none; }
.tab-content.active { display: block; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  margin-bottom: 1.5rem;
}
.card h2, .card h3 { margin-bottom: 0.75rem; }

/* Кнопки */
.primary-btn, .secondary-btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.7rem 1.5rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.primary-btn { background: var(--accent); color: #fff; }
.primary-btn:hover { opacity: 0.9; }
.secondary-btn { background: var(--border); color: var(--text); }
.secondary-btn:hover { background: var(--accent); color: #fff; }

/* Блоки кода */
.code-block {
  background: var(--bg);
  padding: 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  overflow-x: auto;
  font-family: 'Fira Code', monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
  margin: 1rem 0;
}
.code-tabs { display: flex; gap: 0.5rem; margin-bottom: 0.5rem; }
.tab-btn {
  padding: 0.3rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  cursor: pointer;
  color: var(--text);
  font-size: 0.85rem;
  transition: all var(--transition);
}
.tab-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Чат */
.chat-layout {
  display: flex;
  height: calc(100vh - 160px);
  gap: 1rem;
}
.chat-sidebar {
  width: 260px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow-y: auto;
}
.session-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}
.session {
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg);
}
.session:hover, .session.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.session .delete-session { background: none; border: none; color: inherit; cursor: pointer; opacity: 0.7; }
.session .delete-session:hover { opacity: 1; }

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}
.message {
  max-width: 80%;
  padding: 0.7rem 1rem;
  border-radius: var(--radius-sm);
  white-space: pre-wrap;
  border: 1px solid var(--border);
  background: var(--bg);
}
.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border: none;
}
.message .actions { display: flex; gap: 0.3rem; margin-top: 0.4rem; font-size: 0.8rem; opacity: 0.7; }
.message .actions button { background: transparent; border: none; color: inherit; cursor: pointer; }

.chat-input-area {
  padding: 1rem;
  border-top: 1px solid var(--border);
}
.input-row { display: flex; gap: 0.5rem; align-items: flex-end; }
.input-row textarea {
  flex: 1;
  resize: none;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  padding: 0.6rem;
  font-size: 1rem;
  background: var(--bg);
  color: var(--text);
}
.input-row textarea:focus { border-color: var(--accent); outline: none; }
.send-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.7rem 1.2rem;
  cursor: pointer;
  font-weight: 600;
}
.settings-panel {
  display: flex;
  gap: 0.8rem;
  margin-top: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
  font-size: 0.85rem;
}
.settings-panel label { display: flex; align-items: center; gap: 0.2rem; }
.settings-panel input[type="range"] { width: 80px; }
.settings-panel input[type="text"], .settings-panel input[type="number"] {
  width: 120px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }
@media (max-width: 800px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .topbar-right { margin-left: 0; width: 100%; justify-content: space-between; }
  .chat-layout { flex-direction: column; }
  .chat-sidebar { width: 100%; max-height: 150px; }
}
