:root {
  --bg: #122018;
  --bg-2: #183024;
  --panel: rgba(236, 240, 230, 0.92);
  --panel-solid: #eef2e6;
  --ink: #142018;
  --muted: #5a6a5e;
  --line: rgba(20, 32, 24, 0.12);
  --accent: #c6a15b;
  --accent-2: #3f8f6b;
  --danger: #b54a3c;
  --tg: #2a7d8f;
  --vk: #4b6fa8;
  --yt: #b85c3a;
  --shadow: 0 18px 50px rgba(8, 16, 12, 0.28);
  --radius: 18px;
  --font: "Sora", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  padding: 28px clamp(16px, 3vw, 40px) 60px;
}

.bg-grid,
.bg-wash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: -1;
}
.bg-grid {
  background-image:
    linear-gradient(rgba(198, 161, 91, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(198, 161, 91, 0.05) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at 30% 10%, black, transparent 70%);
}
.bg-wash {
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(63, 143, 107, 0.35), transparent 60%),
    radial-gradient(700px 420px at 90% 0%, rgba(198, 161, 91, 0.22), transparent 55%),
    linear-gradient(160deg, #0f1c15, #1a3426 55%, #102019);
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: end;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.eyebrow {
  margin: 0 0 8px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--accent);
}
.brand-block h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 56px);
  line-height: 0.95;
  letter-spacing: -0.03em;
  color: #f3f6ec;
}
.sub {
  margin: 10px 0 0;
  color: rgba(238, 242, 230, 0.72);
  font-size: 15px;
}
.top-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
}
.meta-pills {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.pill {
  font-family: var(--mono);
  font-size: 12px;
  padding: 7px 10px;
  border-radius: 999px;
  background: rgba(238, 242, 230, 0.1);
  color: #eef2e6;
  border: 1px solid rgba(238, 242, 230, 0.14);
}

.toolbar,
.stats-row,
.cards,
.list-head {
  position: relative;
  z-index: 1;
}

.toolbar {
  display: grid;
  grid-template-columns: 1.6fr repeat(4, minmax(120px, 0.7fr));
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}
.field.grow { grid-column: span 1; }
.field span,
.form-grid .field span {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
input, select, textarea, button {
  font: inherit;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 11px 12px;
  color: var(--ink);
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: rgba(63, 143, 107, 0.55);
  box-shadow: 0 0 0 3px rgba(63, 143, 107, 0.15);
}
textarea { resize: vertical; }

.btn {
  border: 0;
  border-radius: 12px;
  padding: 11px 16px;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary {
  background: var(--accent);
  color: #1a1408;
}
.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}
.btn.danger {
  background: rgba(181, 74, 60, 0.12);
  color: var(--danger);
}
.icon-btn {
  border: 0;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 22px;
}
.stat-card {
  background: rgba(238, 242, 230, 0.1);
  border: 1px solid rgba(238, 242, 230, 0.12);
  color: #eef2e6;
  border-radius: 16px;
  padding: 16px;
}
.stat-card .label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.7;
}
.stat-card .value {
  margin-top: 8px;
  font-size: 28px;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.list-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  margin: 8px 0 14px;
  color: #eef2e6;
}
.list-head.secondary { margin-top: 28px; }
.list-head h2 {
  margin: 0;
  font-size: 22px;
}
.list-head p {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  opacity: 0.7;
}

.table-wrap {
  overflow: auto;
  border-radius: 18px;
  background: var(--panel-solid);
  box-shadow: var(--shadow);
  margin-bottom: 8px;
}
.links-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}
.links-table th,
.links-table td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.links-table th {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(20, 32, 24, 0.04);
}
.links-table tr:last-child td { border-bottom: 0; }
.links-table tbody tr:hover td {
  background: rgba(63, 143, 107, 0.06);
}
.links-table .title-cell {
  font-weight: 600;
  max-width: 240px;
}
.links-table .link-cell a {
  font-family: var(--mono);
  font-size: 13px;
  color: #1d5f48;
  text-decoration: none;
  word-break: break-all;
}
.links-table .link-cell a:hover { text-decoration: underline; }
.links-table .score-cell {
  font-family: var(--mono);
  font-weight: 500;
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 14px;
}
.card {
  background: var(--panel-solid);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  border: 1px solid rgba(20, 32, 24, 0.06);
  animation: rise 0.35s ease both;
}
@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.card-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: start;
}
.badges { display: flex; flex-wrap: wrap; gap: 6px; }
.badge {
  font-family: var(--mono);
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(20, 32, 24, 0.06);
}
.badge.tg { background: rgba(42, 125, 143, 0.14); color: var(--tg); }
.badge.vk { background: rgba(75, 111, 168, 0.14); color: var(--vk); }
.badge.yt { background: rgba(184, 92, 58, 0.14); color: var(--yt); }
.badge.status-new { background: rgba(63, 143, 107, 0.16); color: var(--accent-2); }
.badge.status-active { background: rgba(198, 161, 91, 0.2); color: #8a6a28; }
.badge.status-watch { background: rgba(20, 32, 24, 0.08); color: var(--muted); }
.badge.status-stale { background: rgba(181, 74, 60, 0.12); color: var(--danger); }
.badge.status-info { background: rgba(75, 111, 168, 0.12); color: var(--vk); }

.score {
  font-family: var(--mono);
  font-weight: 500;
  font-size: 13px;
  min-width: 52px;
  text-align: center;
  padding: 8px 10px;
  border-radius: 12px;
  background: #142018;
  color: #eef2e6;
}
.card h3 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
.handle {
  margin: 4px 0 0;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}
.handle.link-line a {
  color: #1d5f48;
  text-decoration: none;
  word-break: break-all;
}
.handle.link-line a:hover { text-decoration: underline; }
.notes {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.metric {
  background: rgba(20, 32, 24, 0.04);
  border-radius: 12px;
  padding: 10px;
}
.metric .k {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.metric .v {
  margin-top: 4px;
  font-weight: 600;
  font-size: 15px;
}
.card-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
}
.card-actions a,
.card-actions button {
  flex: 1;
  text-align: center;
  text-decoration: none;
  border-radius: 12px;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 14px;
}
.card-actions a {
  background: #142018;
  color: #eef2e6;
}
.card-actions button {
  border: 1px solid var(--line);
  background: #fff;
  cursor: pointer;
}

.empty {
  color: rgba(238, 242, 230, 0.7);
  text-align: center;
  padding: 40px 12px;
}

dialog {
  border: 0;
  border-radius: 20px;
  padding: 0;
  width: min(640px, calc(100vw - 24px));
  background: var(--panel-solid);
  box-shadow: var(--shadow);
}
dialog::backdrop {
  background: rgba(8, 14, 10, 0.62);
  backdrop-filter: blur(4px);
}
dialog form,
.detail {
  padding: 18px;
}
dialog header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
dialog h3 { margin: 0; font-size: 22px; }
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.form-grid .full { grid-column: 1 / -1; }
dialog footer {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.form-hint {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
.footer-actions { display: flex; gap: 8px; }

.detail h3 { margin: 0 0 8px; font-size: 24px; }
.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}
.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin: 14px 0;
}
.detail-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 16px;
}
.detail-actions a,
.detail-actions button { flex: 1; min-width: 120px; }

.tabs {
  display: flex;
  gap: 8px;
  margin: 0 0 18px;
  flex-wrap: wrap;
}
.tab {
  border: 1px solid rgba(238, 242, 230, 0.18);
  background: rgba(238, 242, 230, 0.08);
  color: #eef2e6;
  border-radius: 999px;
  padding: 10px 16px;
  cursor: pointer;
  font-weight: 600;
}
.tab.active {
  background: var(--accent);
  color: #1a1408;
  border-color: transparent;
}
.tab-panel { display: none !important; }
.tab-panel.active { display: block !important; }
.ask-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 16px;
  flex-wrap: wrap;
  color: #eef2e6;
}
.ask-toolbar h2 { margin: 0 0 6px; }

.ai-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 16px;
  flex-wrap: wrap;
  color: #eef2e6;
}
.ai-toolbar h2 { margin: 0 0 6px; }
.muted { margin: 0; opacity: 0.72; font-size: 14px; }

.community-box {
  margin-bottom: 16px;
}
.community-head h3 {
  margin: 0 0 4px;
  color: var(--ink);
}
.community-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-top: 12px;
}
.community-form .field {
  min-width: 160px;
}
.community-form .grow {
  flex: 1;
  min-width: 200px;
}
.community-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 12px;
}
.preview-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 10px;
}
.preview-head h3 { margin: 0; }
.preview-head .community-actions { margin-top: 0; }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}
.post-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}
.post-item {
  text-align: left;
  border: 0;
  border-radius: 14px;
  padding: 12px 14px;
  background: var(--panel-solid);
  cursor: pointer;
  box-shadow: var(--shadow);
}
.post-item:hover { transform: translateY(-1px); }
.post-item .k {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}
.post-item .t {
  font-weight: 600;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.panel-card {
  background: var(--panel-solid);
  border-radius: 18px;
  padding: 16px;
  box-shadow: var(--shadow);
  color: var(--ink);
}
.post-preview pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  font-family: var(--font);
  line-height: 1.5;
  font-size: 14px;
}
.bot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}
.chat-add-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.chat-add-form input {
  flex: 1;
  min-width: 220px;
}
.chat-listen-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.chat-listen-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(20, 32, 24, 0.04);
}
.chat-listen-item .meta {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--muted);
}
.ask-chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 420px;
}
.ask-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 52vh;
  min-height: 280px;
  overflow: auto;
  padding: 4px 2px 8px;
}
.ask-bubble {
  max-width: min(720px, 92%);
  padding: 12px 14px;
  border-radius: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 14px;
}
.ask-bubble.system {
  align-self: stretch;
  max-width: none;
  background: rgba(20, 32, 24, 0.05);
  color: var(--muted);
  font-size: 13px;
}
.ask-bubble.user {
  align-self: flex-end;
  background: #1f3d2a;
  color: #f3f7ef;
}
.ask-bubble.assistant {
  align-self: flex-start;
  background: rgba(20, 32, 24, 0.07);
  color: var(--ink);
}
.ask-bubble.pending {
  opacity: 0.7;
  font-style: italic;
}
.ask-bubble .ask-meta {
  display: block;
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--muted);
  font-style: normal;
}
.ask-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
}
.ask-form textarea {
  width: 100%;
  resize: vertical;
  min-height: 78px;
}
@media (max-width: 640px) {
  .ask-form {
    grid-template-columns: 1fr;
  }
}
@media (max-width: 960px) {
  .split { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  body { padding: 18px 14px 48px; }
  .toolbar { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: 1fr; }
  .form-grid, .detail-grid, .metrics { grid-template-columns: 1fr; }
  .top-actions { align-items: stretch; width: 100%; }
  .meta-pills { justify-content: flex-start; }
}
