/* lightgallertytg — тёмная тема в духе Telegram Web Dark */
:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-2: #1c2835;
  --border: #1f2d3d;
  --text: #e4eaef;
  --text-dim: #8a9aab;
  --accent: #3390ec;
  --accent-hover: #4aa0ff;
  --danger: #e56565;
  --radius: 8px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

button, input, select, textarea {
  font: inherit;
  color: var(--text);
}

/* Тонкие скроллбары */
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #2a3a4d; border-radius: 4px; }
*::-webkit-scrollbar-thumb:hover { background: #3a4d64; }

/* ── Header ─────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
header h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
header .stats {
  color: var(--text-dim);
  font-size: 12px;
  flex: 1;
}
header button#sync-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius);
  cursor: pointer;
}
header button#sync-btn:hover { background: var(--accent-hover); }
header button#sync-btn:disabled { opacity: 0.6; cursor: wait; }

/* ── Layout ─────────────────────────────── */
main {
  display: grid;
  grid-template-columns: 240px 1fr 360px;
  gap: 12px;
  padding: 12px;
  height: calc(100vh - 53px);
  overflow: hidden;
}

.filters, .feed, .ai-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-y: auto;
  padding: 12px;
}

/* ── Filters ────────────────────────────── */
.search-box input {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  outline: none;
}
.search-box input:focus { border-color: var(--accent); }

.filter-group { margin-top: 14px; }
.filter-group h3 {
  margin: 0 0 6px;
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-dim);
  letter-spacing: 0.5px;
}
.filter-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.filter-group ul {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 240px;
  overflow-y: auto;
}
.filter-group li {
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--text);
}
.filter-group li:hover { background: var(--panel-2); }
.filter-group li.active { background: var(--accent); color: #fff; }
.filter-group li .count { color: var(--text-dim); font-size: 12px; }
.filter-group li.active .count { color: #d5e7ff; }

/* ── Feed ───────────────────────────────── */
.feed { display: flex; flex-direction: column; }
#messages { display: flex; flex-direction: column; gap: 10px; }

.msg {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.msg-head {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.msg-head .author { color: var(--accent); font-weight: 600; }
.msg-text {
  white-space: pre-wrap;
  word-wrap: break-word;
}
.msg-media {
  margin-top: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.msg-media a { display: block; }
.msg-media img {
  max-width: 200px;
  max-height: 200px;
  border-radius: 6px;
  object-fit: cover;
  cursor: zoom-in;
  display: block;
}

#load-more { text-align: center; margin: 12px 0; }
#load-more button {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 18px;
  border-radius: var(--radius);
  cursor: pointer;
}
#load-more button:hover { border-color: var(--accent); }

#empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin: 20px auto;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── AI panel ───────────────────────────── */
.ai-panel { display: flex; flex-direction: column; }
.ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.ai-header h2 { margin: 0; font-size: 14px; }
.ai-actions { display: flex; align-items: center; gap: 4px; }
.ai-actions button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
.ai-actions button:hover { background: var(--panel-2); }
.ai-header select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
}
.ai-hint {
  color: var(--text-dim);
  font-size: 12px;
  margin-bottom: 8px;
}
.ai-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 8px;
  min-height: 100px;
}
.ai-msg {
  padding: 8px 10px;
  border-radius: var(--radius);
  white-space: pre-wrap;
  word-wrap: break-word;
}
.ai-msg.user {
  background: var(--accent);
  color: #fff;
  align-self: flex-end;
  max-width: 90%;
}
.ai-msg.assistant {
  background: var(--panel-2);
  border: 1px solid var(--border);
  align-self: flex-start;
  max-width: 100%;
}
.ai-msg.error {
  background: #3a1e1e;
  border: 1px solid var(--danger);
  color: var(--danger);
}

#ai-form { display: flex; flex-direction: column; gap: 6px; }
#ai-form textarea {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 10px;
  resize: vertical;
  outline: none;
}
#ai-form textarea:focus { border-color: var(--accent); }
#ai-form button {
  background: var(--accent);
  border: none;
  color: #fff;
  padding: 8px;
  border-radius: var(--radius);
  cursor: pointer;
}
#ai-form button:hover { background: var(--accent-hover); }
#ai-form button:disabled { opacity: 0.6; cursor: wait; }

/* ── Mobile tabs ─────────────────────────── */
.mobile-tabs { display: none; }

@media (max-width: 900px) {
  main {
    grid-template-columns: 1fr;
    height: calc(100vh - 53px - 48px);
  }
  .filters, .feed, .ai-panel { display: none; }
  .filters.active, .feed.active, .ai-panel.active { display: flex; flex-direction: column; }
  .feed.active { display: block; }

  .mobile-tabs {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 48px;
    background: var(--panel);
    border-top: 1px solid var(--border);
    z-index: 20;
  }
  .mobile-tabs button {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-dim);
    cursor: pointer;
  }
  .mobile-tabs button.active { color: var(--accent); }
}
