:root {
  --bg: #0c0d12;
  --bg-elev: #14161e;
  --bg-elev-2: #1c1f2a;
  --border: #2a2e3c;
  --text: #e7e9ee;
  --text-muted: #8b91a3;
  --accent: #6f8bff;
  --accent-2: #a577ff;
  --green: #4dd6a3;
  --red: #ff6b81;
  --yellow: #ffc94d;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html {
  margin: 0;
  padding: 0;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  font-family: 'DM Sans', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.45;
}
img, svg, video { max-width: 100%; height: auto; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em; background: rgba(255,255,255,0.06); padding: 2px 6px; border-radius: 4px; }

.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.error { color: var(--red); margin-top: 8px; }
.alert { background: rgba(255,201,77,0.12); border: 1px solid rgba(255,201,77,0.4); padding: 12px; border-radius: var(--radius-sm); }

/* ------- AUTH PAGE ------- */
.page-auth {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  position: relative;
  padding: 32px 16px;
  overflow-x: hidden;
}
.bg-glow {
  position: fixed; inset: 0;
  background: radial-gradient(60% 50% at 30% 30%, rgba(111,139,255,0.18), transparent 60%),
              radial-gradient(60% 50% at 70% 70%, rgba(165,119,255,0.15), transparent 60%);
  z-index: -1;
  pointer-events: none;
}
.shell {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(320px, 460px);
  gap: 48px;
  max-width: 1100px;
  width: 100%;
  align-items: center;
}
.brand .logo { font-size: 38px; font-weight: 700; }
.brand .logo span { color: var(--accent); }
.brand .tagline { color: var(--text-muted); margin: 16px 0 24px; }
.brand .features { padding: 0; list-style: none; }
.brand .features li { padding: 8px 0; border-top: 1px solid var(--border); }
.brand .features li:first-child { border-top: 0; }

.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: var(--shadow);
}
.card h1 { margin: 0 0 8px; }
.tg-widget { margin-top: 16px; min-height: 50px; }
.tg-fallback-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  padding: 12px 20px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, #2aabee 0%, #229ed9 100%);
  color: #fff;
  font: 600 15px/1 'DM Sans', system-ui, sans-serif;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(34,158,217,.25);
  transition: transform .1s ease, box-shadow .15s ease, filter .15s ease;
}
.tg-fallback-btn:hover { filter: brightness(1.05); box-shadow: 0 8px 22px rgba(34,158,217,.35); }
.tg-fallback-btn:active { transform: translateY(1px); }
.tg-fallback-btn .tg-icon { display: inline-flex; align-items: center; justify-content: center; }
.tg-fallback-btn--secondary {
  background: var(--bg-elev-2);
  color: var(--text);
  box-shadow: none;
  border: 1px solid var(--border);
}
.tg-fallback-btn--secondary:hover { filter: none; background: var(--bg-elev); }
.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0 12px;
  color: var(--text-muted);
  font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}
.otp-input {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 14px 16px;
  font: 600 22px/1 'DM Sans', system-ui, sans-serif;
  letter-spacing: 0.12em;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
}
.otp-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(111,139,255,0.25);
}
.btn-link {
  display: block;
  width: 100%;
  margin-top: 12px;
  padding: 8px;
  background: none;
  border: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  text-align: center;
}
.btn-link:hover { color: var(--accent); }

@media (max-width: 800px) {
  .page-auth { padding: 24px 14px; place-items: start center; }
  .shell { grid-template-columns: 1fr; gap: 24px; }
  .brand .logo { font-size: 30px; }
  .brand .tagline { margin: 12px 0 16px; }
  .card { padding: 22px; }
  .card h1 { font-size: 22px; }
}

/* ------- APP LAYOUT ------- */
.page-app {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
}
.brand-mini { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; }
.logo-dot { width: 10px; height: 10px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-radius: 50%; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  color: var(--text);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
}
.nav a:hover { background: var(--bg-elev-2); text-decoration: none; }
.nav a.active { background: var(--bg-elev-2); color: var(--accent); }

.nav-group { display: flex; flex-direction: column; gap: 2px; margin: 8px 0; }
.nav-group__label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  padding: 6px 10px 4px;
}
.nav-group__item { padding-left: 18px !important; font-size: 13px; }

.proposals-list { display: flex; flex-direction: column; gap: 16px; margin-top: 16px; }
.proposal-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.proposal-card h3 { margin: 0 0 8px; font-size: 16px; }
.proposal-card p { margin: 0 0 8px; }
.proposal-products { margin: 10px 0 14px; }
.proposal-products-label { font-size: 13px; font-weight: 600; margin-bottom: 8px; }
.proposal-product-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.proposal-product-chip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 12px;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.proposal-product-chip--ok { border-color: var(--accent, #3d7a5c); }
.proposal-product-badge {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}
.proposal-product-chip--ok .proposal-product-badge { color: var(--accent, #3d7a5c); }
.proposal-products-warn { color: #b45309; }
.proposal-draft-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 6px;
  font-size: 13px;
  font-weight: 600;
}
.proposal-draft {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  max-height: 420px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.55;
}
.proposal-draft p { margin: 0 0 10px; }
.proposal-draft p:last-child { margin-bottom: 0; }
.proposal-draft-meta { font-weight: 400; color: var(--muted); font-size: 12px; }
.me { font-size: 13px; }
.me-name { font-weight: 600; }
.me-role { text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }
.me .btn { width: 100%; margin-top: 8px; }

.content {
  padding: 24px 32px 64px;
  min-width: 0;
  min-height: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  overscroll-behavior: contain;
}
.page { min-width: 0; max-width: 100%; width: 100%; }
.page-inner--center {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
}
.page-inner--wide { width: 100%; max-width: none; }

.catalog-layout {
  display: grid;
  grid-template-columns: minmax(200px, 280px) 1fr;
  gap: 20px;
  align-items: start;
}
.catalog-sidebar {
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 120px);
  overflow: auto;
}
.catalog-tree {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  font-size: 13px;
}
.catalog-tree a {
  display: block;
  padding: 4px 8px;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
}
.catalog-tree a:hover,
.catalog-tree a.active {
  background: var(--surface-2);
}
.catalog-tree__branch {
  margin-top: 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  list-style: none;
  padding: 4px 8px 0;
}
.catalog-main .pager {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}
@media (max-width: 900px) {
  .catalog-layout { grid-template-columns: 1fr; }
  .catalog-sidebar { position: static; max-height: none; }
}

.nav-toggle {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 120;
  width: 44px;
  height: 44px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elev);
  cursor: pointer;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
}
.nav-toggle span {
  display: block;
  height: 2px;
  background: var(--text);
  border-radius: 1px;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0, 0, 0, 0.55);
}
body.nav-open .sidebar-backdrop { display: block; }
.badge-list { display: flex; flex-wrap: wrap; gap: 6px; }
.badge-list .badge { margin: 0; }

/* Источники — карточки на всю ширину */
.sources-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}
.source-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  width: 100%;
  box-sizing: border-box;
}
.source-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}
.source-card-head h3 { margin: 0; font-size: 16px; }
.source-card-feed {
  font-family: ui-monospace, monospace;
  font-size: 12px;
  color: var(--text-muted);
  word-break: break-all;
  margin: 0 0 8px;
  line-height: 1.4;
}
.source-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 10px;
}
.source-card-actions { display: flex; flex-wrap: wrap; gap: 6px; }

.suggestions-panel {
  margin-bottom: 20px;
  padding: 16px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.suggestions-panel .panel-title { margin: 0 0 12px; font-size: 15px; }
.suggestions-list { display: flex; flex-direction: column; gap: 10px; }
.suggestion-card {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}
.suggestion-card__actions { margin-top: 8px; display: flex; gap: 8px; }
.story-key { font-size: 11px; color: var(--text-muted); font-family: ui-monospace, monospace; }

.articles-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
  width: 100%;
  min-width: 0;
}
.articles-topbar__actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.articles-topbar__filters {
  flex: 1 1 360px;
  min-width: 0;
}
.articles-topbar__filters select {
  flex: 0 1 auto;
  min-width: 7rem;
  max-width: 11rem;
}
.articles-topbar__filters input[type="search"] {
  flex: 1 1 140px;
  min-width: 8rem;
  max-width: 280px;
}
.articles-topbar__filters .btn[type="submit"] {
  flex: 0 0 auto;
}
.topbar-actions:has(.articles-topbar) {
  flex: 1 1 100%;
  align-items: center;
}
.topbar:has(.articles-topbar) {
  align-items: center;
}
.topbar:has(.articles-topbar) .page-title {
  flex: 0 0 auto;
}
.topbar .articles-topbar .filters {
  flex: 1 1 auto;
  max-width: none;
}

/* ------- Catalog topbar (поиск + YML) ------- */
.catalog-topbar {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
}
.catalog-topbar__search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
  max-width: none;
  margin-right: 0;
}
.catalog-topbar__search input[type="search"] {
  flex: 1 1 12rem;
  min-width: 8rem;
  max-width: 320px;
}
.catalog-topbar__search .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}
.catalog-topbar__actions {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.catalog-topbar__actions .btn {
  white-space: nowrap;
}
.topbar-actions:has(.catalog-topbar) {
  flex: 1 1 100%;
  align-items: center;
  justify-content: flex-end;
}
.topbar:has(.catalog-topbar) {
  align-items: center;
}
.topbar:has(.catalog-topbar) .page-title {
  flex: 0 0 auto;
}

.catalog-proposals-list { display: flex; flex-direction: column; gap: 10px; }
.proposal-remove { border-color: #c44; }
.proposal-add { border-color: var(--accent, #3b82f6); }
.tr.row-muted td { opacity: 0.65; }
.warn { color: #c44; font-size: 12px; }
.btn.danger { background: #b91c1c; color: #fff; border-color: #b91c1c; }
.btn.danger:hover { filter: brightness(1.08); }

select.multi-select {
  min-height: 140px;
  width: 100%;
}
select.multi-select option { padding: 4px 6px; }
.field-hint { font-size: 12px; color: var(--text-muted); margin: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}
.page-title { margin: 0; font-size: 24px; flex: 1 1 auto; min-width: 0; }
.topbar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
}
.topbar .filters {
  flex: 1 1 100%;
  max-width: 100%;
}
.topbar-actions-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.table-wrap--center { width: 100%; }

/* ------- BUTTONS / FORMS ------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  background: var(--bg-elev-2);
  color: var(--text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  font-size: 14px;
  transition: background 120ms, border-color 120ms;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: white; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.active { background: var(--bg-elev-2); border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.form { display: flex; flex-direction: column; gap: 12px; min-width: min(360px, 100%); }
.form .field { display: flex; flex-direction: column; gap: 4px; }
.form .field span { color: var(--text-muted); font-size: 12px; }
.form .field input, .form .field select, .form .field textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  font-family: inherit;
  font-size: 14px;
  resize: vertical;
}
.form .field input:focus, .form .field select:focus, .form .field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; align-items: center; gap: 8px; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 4px; }

.filters {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
  max-width: 100%;
}
.filters select, .filters input[type="search"] {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 13px;
  max-width: 100%;
  min-width: 0;
}
.filters input[type="search"] { flex: 1 1 140px; min-width: 0; }
.filters select { flex: 1 1 120px; min-width: 0; }
.filters .btn { flex: 0 0 auto; }

/* ------- CARDS / STATS ------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 24px; }
.stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
}
.stat-num { font-size: 28px; font-weight: 700; line-height: 1.1; }
.stat-label { color: var(--text-muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; margin-bottom: 16px; }
.card-block {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}
.card-block h2 { margin: 0 0 12px; font-size: 16px; }
.list { padding-left: 20px; margin: 0; }
.list li { padding: 4px 0; }
.list li .num { color: var(--text-muted); font-size: 12px; margin-left: 6px; }

/* ------- TABLES ------- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--text-muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; background: var(--bg-elev-2); }
.table tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }
.table td.actions { white-space: nowrap; text-align: right; }
.table .feed { font-family: ui-monospace, monospace; font-size: 12px; color: var(--text-muted); word-break: break-all; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; line-height: 1.6; border: 1px solid var(--border); }
.badge.on { color: var(--green); border-color: rgba(77,214,163,0.4); }
.badge.off { color: var(--text-muted); }
.badge.role-admin { color: var(--accent); border-color: rgba(111,139,255,0.4); }
.badge.role-member { color: var(--text-muted); }
.badge.status-blocked { color: var(--red); border-color: rgba(255,107,129,0.4); }
.badge--muted { color: var(--text-muted); font-size: 10px; vertical-align: middle; }
tr.segment-group-row td { background: var(--surface-2, rgba(255,255,255,0.04)); padding-top: 14px; padding-bottom: 6px; border-bottom: none; }
tr.segment-group-row + tr td { border-top: none; }

/* ------- ARTICLES ------- */
.articles { display: flex; flex-direction: column; gap: 8px; }
.article {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
}
.article h3 { margin: 0 0 4px; font-size: 15px; }
.article h3 a { color: var(--text); }
.article h3 a:hover { color: var(--accent); }
.article .meta { color: var(--text-muted); font-size: 12px; display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.article .meta .seg { color: var(--accent); }
.article p { margin: 0; color: var(--text-muted); font-size: 13px; word-break: break-word; overflow-wrap: anywhere; }
.article h3 a { word-break: break-word; }

.pagination { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; }

/* ------- TRENDS ------- */
.trends-meta { margin-bottom: 12px; }

.dashboard-actions { flex-wrap: wrap; }
.enrichment-panel { margin: 0 0 20px; }
.enrichment-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px 28px;
}
.enrichment-grid--single {
  grid-template-columns: 1fr;
  max-width: 480px;
}
.enrichment-subtitle { font-size: 14px; font-weight: 600; margin: 0 0 8px; color: var(--text); }
.enrichment-line { margin: 0; font-size: 15px; line-height: 1.5; }
.enrichment-line b { font-weight: 600; }
.dashboard-last-collect { margin: 0 0 20px; }
.dashboard-trends-grid { margin-top: 0; }
.trend-panel-meta { margin: 0 0 10px; min-height: 1.2em; }
.trend-panel-loading,
.trend-panel-empty { margin: 0 0 8px; }
.trends--panel {
  max-height: min(72vh, 720px);
  overflow-y: auto;
  padding-right: 4px;
}
.trend--compact {
  padding: 12px 14px;
}
.trend--compact .trend-head h3 { font-size: 14px; }
.trend--compact p { font-size: 12px; margin: 6px 0 4px; }
.trend--compact .src-list li { font-size: 12px; }
.trend--rich .trend-summary { line-height: 1.5; }
.trend-points { margin: 8px 0 8px 1.1rem; padding: 0; font-size: 13px; color: var(--text); }
.trend--compact .trend-points { font-size: 12px; margin: 6px 0 6px 1rem; }
.trend-points li { margin: 4px 0; }
.trend-label { font-weight: 600; color: var(--text-muted); }
.trend-why, .trend-outlook { font-size: 13px; margin: 8px 0; line-height: 1.45; color: var(--text-muted); }
.trend--compact .trend-why { font-size: 12px; }
.trend-cats { margin: 8px 0 6px; font-size: 12px; }
.trend-cats__label { color: var(--text-muted); font-weight: 600; }
.trend-cats__list { margin: 4px 0 0 1.1rem; padding: 0; }
.trend-cats__list li { margin: 3px 0; color: var(--text-muted); }
.trend-notes { margin-top: 12px; }
.trend-notes h4 { margin: 0 0 6px; font-size: 13px; }
.trend-raw {
  font-size: 11px;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

.job-log-panel { margin-top: 8px; }
.job-log-list { max-height: 280px; overflow-y: auto; font-size: 13px; }
.job-log-list li { padding: 6px 0; border-bottom: 1px solid var(--border); line-height: 1.4; }
.job-log-time { color: var(--text-muted); margin-right: 8px; white-space: nowrap; }
.job-log-ev { font-weight: 500; margin-right: 6px; }
.job-log-st { color: var(--accent); margin-right: 6px; }
.period-toggle { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 2px; gap: 2px; background: var(--bg-elev); }
.period-toggle .btn { border: 0; padding: 6px 12px; font-size: 13px; background: transparent; }
.period-toggle .btn.active { background: var(--bg-elev-2); color: var(--accent); }

.trends { display: flex; flex-direction: column; gap: 12px; }
.trend {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.trend-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.trend-head h3 { margin: 0; font-size: 16px; }
.trend-scores { display: flex; gap: 10px; color: var(--text-muted); font-size: 12px; }
.trend-scores .hot { color: var(--yellow); }
.trend-scores .rel { color: var(--accent); }
.trend p { margin: 8px 0 6px; }
.trend .cats { color: var(--text-muted); font-size: 12px; margin-bottom: 6px; }
.trend .src-list { padding-left: 18px; margin: 0; }
.trend .src-list li { font-size: 13px; padding: 2px 0; word-break: break-word; }
.trend-head h3 { word-break: break-word; min-width: 0; }

/* ------- MODAL / TOAST ------- */
.modal {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--text);
  padding: 24px;
  max-width: min(520px, calc(100vw - 24px));
  width: calc(100vw - 24px);
  margin: auto;
  max-height: calc(100dvh - 24px);
  overflow-y: auto;
  box-sizing: border-box;
}
.table-wrap {
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.modal::backdrop { background: rgba(0,0,0,0.6); }
.modal h2 { margin: 0 0 12px; }

.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 10;
}
.toast.error { border-color: rgba(255,107,129,0.5); color: var(--red); }
.toast.ok { border-color: rgba(77,214,163,0.5); color: var(--green); }

/* ------- RESPONSIVE: APP LAYOUT ON MOBILE ------- */
@media (max-width: 900px) {
  .page-app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: visible;
  }
  .nav-toggle { display: flex; }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 110;
    width: min(280px, 86vw);
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  .content {
    padding: 68px 12px 48px;
    max-width: 100%;
    height: auto;
    overflow: visible;
  }
  .topbar {
    flex-direction: column;
    align-items: stretch;
    margin-bottom: 16px;
  }
  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
  }
  .page-title { font-size: 20px; }
  .filters {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }
  .filters select,
  .filters input[type="search"],
  .filters .btn {
    width: 100%;
    flex: none;
  }
  .catalog-topbar {
    flex-wrap: wrap;
  }
  .catalog-topbar__search {
    flex: 1 1 100%;
    max-width: none;
  }
  .catalog-topbar__search input[type="search"] {
    max-width: none;
  }
  .catalog-topbar__actions {
    flex: 1 1 100%;
    flex-wrap: wrap;
  }
  .catalog-topbar__actions .btn {
    flex: 1 1 auto;
  }
  .articles-topbar {
    flex-direction: column;
    align-items: stretch;
  }
  .articles-topbar__actions {
    flex-wrap: wrap;
    width: 100%;
  }
  .articles-topbar__actions .btn {
    flex: 1 1 auto;
  }
  .articles-topbar__filters {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
    flex-wrap: wrap;
  }
  .articles-topbar__filters select,
  .articles-topbar__filters input[type="search"] {
    width: 100%;
    max-width: none;
    min-width: 0;
  }
  .period-toggle { flex-wrap: wrap; max-width: 100%; }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
  .table { font-size: 13px; min-width: 520px; }
  .table th, .table td { padding: 8px; }
  .table td.actions {
    white-space: normal;
  }
  .table td.actions .btn {
    display: inline-block;
    margin: 2px 0;
  }
  .modal { padding: 18px; width: calc(100vw - 20px); }
  .form { min-width: 0; width: 100%; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .btn { flex: 1 1 calc(50% - 4px); min-width: 0; }
  .toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    max-width: none;
  }
}

@media (max-width: 400px) {
  .cards { grid-template-columns: 1fr; }
}

/* ------- COMPANY STRUCTURE ------- */
.company-layout {
  display: grid;
  grid-template-columns: minmax(260px, 340px) 1fr;
  gap: 20px;
  align-items: start;
}
.company-tree-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  max-height: calc(100vh - 160px);
  overflow: auto;
  background: var(--surface);
}
.company-tree__item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  font-size: 13px;
}
.company-tree__item--active .company-tree__label {
  color: var(--accent);
  font-weight: 600;
}
.company-tree__toggle,
.company-tree__spacer {
  width: 18px;
  flex-shrink: 0;
  border: none;
  background: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
}
.company-tree-legend {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 8px 0 10px;
}
.company-tree__trends {
  display: inline-block;
  width: 14px;
  text-align: center;
  font-size: 11px;
  flex-shrink: 0;
}
.company-tree__trends--yes { color: var(--green, #3d9a5c); }
.company-tree__trends--no { color: var(--text-muted); opacity: 0.55; }
.company-tree__item--has-trends .company-tree__label { font-weight: 500; }
.trend-err { color: #e85d5d; }
.company-tree__type { font-size: 10px; min-width: 52px; }
.company-tree__label {
  border: none;
  background: none;
  text-align: left;
  cursor: pointer;
  color: inherit;
  padding: 0;
  flex: 1;
}
.company-detail {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  background: var(--surface);
  min-height: 320px;
}
.company-trends-block { margin-top: 20px; }
.company-trends-actions { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
.company-trends-out { margin-bottom: 16px; }
.company-descendants { margin: 8px 0 16px; max-height: 200px; overflow-y: auto; }
button.linklike {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  cursor: pointer;
  font: inherit;
  text-align: left;
}
button.linklike:hover { text-decoration: underline; }
.story-dup {
  font-size: 11px;
  color: var(--yellow);
  font-weight: 600;
  margin-left: 6px;
}
.cluster-urls { margin: 6px 0 0 0; padding-left: 18px; }
.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
}
@media (max-width: 900px) {
  .company-layout { grid-template-columns: 1fr; }
}
