:root {
  --bg: #0b1121;
  --surface: #1e293b;
  --text: #e2e8f0;
  --text-secondary: #94a3b8;
  --accent: #38bdf8;
  --accent-hover: #0ea5e9;
  --border: #334155;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
}
[data-theme="light"] {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #0f172a;
  --text-secondary: #475569;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --border: #e2e8f0;
  --shadow: 0 2px 8px rgba(0,0,0,0.06);
}
* { margin:0; padding:0; box-sizing:border-box; }
body { font-family: system-ui, sans-serif; background: var(--bg); color: var(--text); }
.app { height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 2rem; padding: 0.8rem 1.5rem;
  background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.logo { font-size: 1.3rem; font-weight: 700; display: flex; align-items: center; gap: 0.4rem; }
.logo span { color: var(--accent); }
.badge {
  background: var(--accent); color: #000; padding: 0.2rem 0.6rem; border-radius: 20px;
  font-size: 0.7rem; font-weight: 600; text-transform: uppercase; vertical-align: middle;
}
.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); cursor: pointer; font-size: 0.9rem;
}
.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 { font-size: 0.9rem; display: flex; align-items: center; gap: 0.5rem; }
.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);
}
.icon-btn:hover { background: var(--border); }
.primary-btn {
  background: var(--accent); color: #000; border: none; border-radius: var(--radius-sm);
  padding: 0.6rem 1.2rem; font-weight: 600; cursor: pointer;
}
.secondary-btn {
  background: var(--border); color: var(--text); border: none; border-radius: var(--radius-sm);
  padding: 0.6rem 1.2rem; font-weight: 600; cursor: pointer;
}
.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;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 1rem; min-width: 160px; flex: 1;
}
.code-tabs { display: flex; gap: 0.5rem; margin: 1rem 0; }
.tab-btn {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 0.3rem 0.8rem; cursor: pointer; color: var(--text);
}
.tab-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }
.code-block {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 1rem; font-family: 'Fira Code', monospace; white-space: pre-wrap; overflow-x: auto;
}
.chat-layout { display: flex; gap: 1rem; height: calc(100vh - 160px); }
.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;
}
.chat-main {
  flex: 1; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; flex-direction: column; 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: #000; border: none; }
.message .actions { margin-top: 0.4rem; display: flex; gap: 0.3rem; }
.message .actions button { background: transparent; border: none; cursor: pointer; color: inherit; }
.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; background: var(--bg); color: var(--text); font-size: 1rem;
}
.send-btn { background: var(--accent); color: #000; border: none; border-radius: var(--radius-sm); padding: 0.7rem 1.2rem; cursor: pointer; }
.settings-panel { display: flex; gap: 0.8rem; flex-wrap: wrap; margin-top: 0.5rem; }
.settings-panel label { font-size: 0.85rem; }
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: flex; align-items: center; justify-content: center; z-index: 10;
}
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 2rem; width: 100%; max-width: 400px;
}
.modal input { width: 100%; margin-bottom: 1rem; padding: 0.6rem; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); color: var(--text); }
.hidden { display: none !important; }
/* Таблица статистики */
#dailyTable {
  width: 100%;
  border-collapse: collapse;
  margin-top: 1rem;
}
#dailyTable th,
#dailyTable td {
  text-align: left;
  padding: 0.5rem 0.8rem;
  border-bottom: 1px solid var(--border);
}
#dailyTable th {
  background: var(--surface);
  font-weight: 600;
}
#dailyTable tbody tr:hover {
  background: var(--bg);
}

/* Сессии чата */
.session-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  overflow-y: auto;
}
.session {
  padding: 0.5rem 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg);
  font-size: 0.9rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.session:hover,
.session.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}
.session .delete-session {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  opacity: 0.7;
  font-size: 1rem;
}
.session .delete-session:hover {
  opacity: 1;
}

/* Карточки статистики */
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
  min-width: 150px;
  flex: 1 1 0;
  text-align: center;
}
/* Анимация печатания */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0.4rem 0;
}
.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  animation: typing-bounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
.typing-indicator span:nth-child(3) { animation-delay: 0s; }
@keyframes typing-bounce {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1); }
}
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center; z-index: 10;
}
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 2rem;
  width: 100%; max-width: 400px; position: relative;
}
.modal-close {
  position: absolute; top: 0.8rem; right: 1rem;
  background: transparent; border: none; font-size: 1.5rem; cursor: pointer;
  color: var(--text);
}
.hidden { display: none !important; }
