:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #6d7785;
  --line: #dfe4ea;
  --accent: #2674e8;
  --accent-ink: #ffffff;
  --good: #16825d;
  --bad: #b42318;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: auto minmax(220px, 360px) 1fr auto;
  gap: 16px;
  align-items: center;
  min-height: 64px;
  padding: 0 28px;
  background: rgba(255, 255, 255, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand { font-size: 18px; font-weight: 800; }
.project-switch select, input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
  color: var(--ink);
}
.project-create, .project-menu { position: relative; }
.project-create summary, .project-menu summary {
  display: grid;
  place-items: center;
  min-width: 40px;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  list-style: none;
}
.project-create form, .project-menu form {
  position: absolute;
  top: 46px;
  right: 0;
  z-index: 30;
  display: grid;
  gap: 8px;
  width: 260px;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(24,32,42,.12);
}

.nav { display: flex; gap: 6px; }
.nav a, .mobile-nav a, .filters button, .text-button {
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--muted);
}
.nav a.active, .mobile-nav a.active, .filters button.active {
  background: #e9f1ff;
  color: var(--accent);
}
.text-button.active {
  background: #e9f1ff;
  color: var(--accent);
}
.inline-link {
  display: inline-flex;
  margin: 8px 0;
}

.icon-button, button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 14px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}
.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.vk-connect-button {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 0 18px 0 10px;
  border-radius: 8px;
  background: #0077ff;
  color: #fff;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(0, 119, 255, 0.24);
}
.vk-connect-button:hover { background: #096fe0; }
.vk-connect-mark {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.18);
  font-size: 12px;
  letter-spacing: 0;
}
.ghost { color: var(--bad); }
.logout-button { color: var(--bad); border-color: var(--bad); white-space: nowrap; }

.shell {
  width: min(1220px, calc(100% - 40px));
  margin: 24px auto 88px;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: end;
  gap: 18px;
  margin-bottom: 18px;
}
h1, h2, p { margin: 0; }
h1 { font-size: 28px; letter-spacing: 0; }
h2 { font-size: 18px; letter-spacing: 0; }
p, small { color: var(--muted); }

.filters, .search, .inline-form, .bulk-bar { display: flex; gap: 8px; align-items: center; }
.filters button { background: #fff; }
.search { width: min(520px, 100%); }

.empty-state, .notice {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  margin-bottom: 14px;
}
.notice { padding: 12px 16px; color: var(--good); }
.notice.warn { color: #8a5a00; background: #fff8e6; }
.button-link { display: inline-flex; align-items: center; min-height: 40px; border-radius: 8px; padding: 0 14px; margin-top: 16px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.kpi-grid article, .panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}
.kpi-grid span { display: block; color: var(--muted); font-size: 13px; }
.kpi-grid strong { display: block; margin-top: 8px; font-size: 28px; letter-spacing: 0; }
.kpi-grid small { display: block; margin-top: 4px; }

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}
.leaders-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}
.efficiency-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.efficiency-grid article {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}
.efficiency-grid h3 {
  margin: 0 0 8px;
  font-size: 14px;
  letter-spacing: 0;
}
.leader-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.leader-row:first-of-type { border-top: 0; }
.panel.wide { min-height: 260px; }
.panel.compact { margin-bottom: 14px; }
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}
.chart {
  display: flex;
  align-items: end;
  gap: 5px;
  height: 190px;
  margin-top: 22px;
  border-bottom: 1px solid var(--line);
}
.bar {
  flex: 1;
  min-width: 5px;
  border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, #2674e8, #1b9a8a);
}
.bar.growth { background: linear-gradient(180deg, #1b9a8a, #62b87f); }
.bar.views { background: linear-gradient(180deg, #2674e8, #6b8ff0); }
.chart.stacked { align-items: stretch; }
.stack-col {
  flex: 1;
  min-width: 8px;
  display: flex;
  align-items: end;
  gap: 2px;
}
.stack-col span {
  flex: 1;
  display: block;
  min-height: 4px;
  border-radius: 4px 4px 0 0;
}
.stack-col .posts { background: #2674e8; }
.stack-col .clips { background: #1b9a8a; }
.split-metric {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}
.split-metric:last-child { border-bottom: 0; }

.chart-panel { position: relative; }
.line-chart {
  position: relative;
  min-height: 300px;
  margin-top: 14px;
}
.line-chart svg {
  display: block;
  width: 100%;
  height: 260px;
  overflow: visible;
}
.line-chart line {
  stroke: #e7ebf0;
  stroke-width: 1;
}
.line-chart line.zero { stroke: #aeb7c2; stroke-dasharray: 4 4; }
.line-chart text {
  fill: var(--muted);
  font-size: 11px;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.chart-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
}
.chart-tooltip {
  position: absolute;
  z-index: 5;
  max-width: 260px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(24,32,42,.16);
  color: var(--ink);
  font-size: 12px;
  pointer-events: none;
}
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f7f9;
}
.segmented button {
  min-height: 32px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  padding: 0 10px;
}
.segmented button.active {
  background: #fff;
  color: var(--accent);
  box-shadow: 0 1px 4px rgba(24,32,42,.12);
}
.empty-chart {
  display: grid;
  place-items: center;
  min-height: 260px;
  color: var(--muted);
}

.compare-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
}
.settings-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  max-width: 720px;
}
.settings-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
}
.settings-form .toggle-row {
  grid-template-columns: auto 1fr;
  align-items: center;
  color: var(--ink);
}
.settings-form .toggle-row input { width: auto; min-height: auto; }
.settings-form button { justify-self: start; }

.topbar-actions { display: flex; align-items: center; gap: 14px; }
.expert-toggle .toggle-row { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.expert-toggle .toggle-row input { width: auto; min-height: auto; }
.expert-toggle .toggle-row:has(input:checked) { color: var(--accent); font-weight: 600; }
.compare-drawer { margin-bottom: 14px; }
.compare-drawer summary {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  list-style: none;
  font-weight: 700;
}
.compare-drawer summary::-webkit-details-marker { display: none; }
.compare-drawer summary::after {
  content: "+";
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
}
.compare-drawer[open] summary {
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}
.compare-drawer[open] summary::after { content: "-"; }
.compare-drawer summary small {
  margin-left: auto;
  font-weight: 400;
}
.compare-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  width: 100%;
}
.compare-list label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fafb;
}
.compare-list span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table { display: grid; gap: 0; overflow-x: auto; }
a.tr { cursor: pointer; transition: background-color .12s ease; border-radius: 6px; }
a.tr:hover { background-color: rgba(38, 116, 232, 0.06); }
a.tr:hover span:nth-child(2) { color: var(--accent); text-decoration: underline; }
a.tr[target="_blank"] span:nth-child(2)::after { content: " \2197"; color: var(--muted); font-size: 12px; }
.tr {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) 140px 110px 110px 130px;
  gap: 12px;
  align-items: center;
  min-width: 760px;
  padding: 13px 4px;
  border-top: 1px solid var(--line);
  font-size: 14px;
  line-height: 1.45;
}
.tr.th {
  border-top: 0;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding-top: 0;
  padding-bottom: 10px;
}
.tr small { display: block; margin-top: 3px; overflow-wrap: anywhere; color: var(--muted); font-size: 12.5px; }
.groups-table .tr { grid-template-columns: 36px minmax(220px, 1fr) 210px 120px 120px 170px 150px; }
.team-table .tr { grid-template-columns: minmax(240px, 1fr) 110px 150px 170px; }
.admin-users-table .tr {
  grid-template-columns: minmax(240px, 1fr) 100px 85px 85px 100px 170px 160px 260px;
  min-width: 1350px;
}
.admin-projects-table .tr {
  grid-template-columns: minmax(240px, 1fr) minmax(220px, 1fr) 120px 110px 110px;
  min-width: 820px;
}
.provider-events-table .tr {
  grid-template-columns: 190px 180px 90px minmax(320px, 1fr);
  min-width: 840px;
}
.analytics-table .tr {
  grid-template-columns: 44px minmax(260px, 1fr) 120px 100px 90px 90px 110px 130px 105px 105px 105px 110px 125px 110px 150px;
  min-width: 1680px;
}
.clips-table .tr {
  grid-template-columns: 150px minmax(280px, 1fr) 100px 120px 90px 100px 90px 100px;
  min-width: 1030px;
}
.top-clips-table .tr {
  grid-template-columns: 170px 145px minmax(260px, 1fr) 115px 75px 95px 85px 70px 100px 95px;
  min-width: 1280px;
}
.top-posts-table .tr {
  grid-template-columns: 170px 145px minmax(300px, 1fr) 115px 75px 95px 85px 70px 95px;
  min-width: 1250px;
}
.content-growth-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0 22px;
}
.metric-note { margin-top: 12px; }
.pagination { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
.heatmap { display: flex; flex-direction: column; gap: 2px; margin: 14px 0; overflow-x: auto; }
.heatmap-row { display: grid; grid-template-columns: 30px repeat(24, minmax(16px, 1fr)); gap: 2px; align-items: center; min-width: 640px; }
.heatmap-head { color: var(--muted); font-size: 10px; }
.heatmap-day { font-size: 11px; color: var(--muted); text-align: right; padding-right: 4px; }
.heatmap-hourlabel { text-align: center; font-size: 10px; color: var(--muted); }
.heatmap-cell { height: 18px; border-radius: 3px; background: var(--bg); border: 1px solid var(--line); }
button.heatmap-cell { width: 100%; padding: 0; margin: 0; font: inherit; cursor: pointer; transition: outline-color .1s ease; }
button.heatmap-cell:hover, button.heatmap-cell:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
button.heatmap-cell.selected { outline: 2px solid var(--ink); outline-offset: 1px; }
.best-time-summary { margin: 10px 0; }
.best-time-detail { min-height: 1.2em; }
.heatmap-legend { display: flex; align-items: center; gap: 10px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.heatmap-legend-scale { display: inline-block; width: 140px; height: 10px; border-radius: 5px; border: 1px solid var(--line); background: linear-gradient(90deg, #ffffff 0%, #ffffff 35%, rgb(36,62,214) 100%); }
.compare-table { margin-top: 18px; }
.compare-table .tr {
  grid-template-columns: minmax(220px, 1fr) 110px 110px 100px 90px 80px 80px 130px 120px 105px 105px 110px 125px;
  min-width: 1480px;
}
.compare-table > .tr.th:not(.compare-efficiency-head) { display: none; }
.filter-search { flex-basis: 260px; max-width: 360px; }

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-panel {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
}
.auth-panel h1 { margin-bottom: 8px; }
.auth-panel p { margin-bottom: 22px; }
.auth-panel.wide { width: min(560px, 100%); }
.topic-picker {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 16px;
  margin-bottom: 4px;
}
.topic-picker-label { display: block; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.topic-picker .toggle-row { display: flex; align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
.topic-picker .toggle-row input { width: auto; min-height: auto; }
.topic-picker-more { margin-bottom: 16px; }
.topic-picker-more summary { color: var(--accent); cursor: pointer; margin-bottom: 10px; }
.topic-picker-more .topic-picker { max-height: 260px; overflow-y: auto; }
@media (max-width: 640px) {
  .topic-picker { grid-template-columns: 1fr; }
}
.goal-picker { display: grid; gap: 10px; margin-bottom: 4px; }
.goal-card {
  display: grid;
  gap: 4px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.goal-card input { position: absolute; opacity: 0; width: 0; height: 0; }
.goal-card-title { font-weight: 700; color: var(--ink); }
.goal-card-desc { color: var(--muted); font-size: 13px; }
.goal-card:has(input:checked) { border-color: var(--accent); background: #eef4fe; }
.goal-card:has(input:checked) .goal-card-title { color: var(--accent); }
.stack { display: grid; gap: 14px; margin-bottom: 16px; }
.stack label { display: grid; gap: 6px; color: var(--muted); }
.alert {
  margin-bottom: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fff1f0;
  color: var(--bad);
}
.ok { color: var(--good); margin-top: 10px; }
.mt { margin-top: 16px; }
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 999px;
  background: #eaf1fd;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}
.badge.muted { background: var(--bg); color: var(--muted); }
.badge.stage-emerging { background: var(--bg); color: var(--muted); }
.badge.stage-rising { background: #eaf1fd; color: var(--accent); }
.badge.stage-hot { background: #fff1f0; color: var(--bad); }
.badge.stage-cooling { background: #fff4e5; color: #b56a00; }
.badge.stage-faded { background: var(--bg); color: var(--muted); opacity: 0.7; }
.badge.type-topic { background: #f1eafd; color: #6b3fd6; }
.badge.type-hashtag { background: #e6f7f3; color: #0f8a6a; }
.badge.type-tag { background: #fff4d6; color: #8a5a00; }
.badge.type-phrase { background: #eaf1fd; color: #315bb8; }
.signal-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.badge.confidence-ready { background: #e9f7f1; color: var(--good); }
.badge.confidence-limited { background: #fff8e6; color: #8a5a00; }
.badge.confidence-insufficient { background: var(--bg); color: var(--muted); }
.confidence-wrap { display: inline-flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.confidence-sample { color: var(--muted); font-size: 12px; }
.topic-cell { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; max-width: 100%; }
.topic-cell .inline-form.compact,
.row-actions .inline-form.compact {
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}
.topic-cell select {
  font-size: 12px;
  padding: 3px 6px;
  min-height: 26px;
  width: auto;
  max-width: 150px;
}
.topic-cell .inline-form.compact button,
.row-actions .inline-form.compact button {
  min-height: 26px;
  padding: 0 8px;
  font-size: 12px;
  white-space: nowrap;
}
.row-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.code-box {
  width: max-content;
  margin-top: 18px;
  padding: 12px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f6f7f9;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0;
}

.mobile-nav { display: none; }

@media (max-width: 820px) {
  .topbar {
    grid-template-columns: 1fr auto;
    padding: 10px 14px;
  }
  .project-switch { grid-column: 1 / -1; }
  .nav { display: none; }
  .expert-toggle .toggle-row span { display: none; }
  .shell { width: min(100% - 24px, 640px); margin-top: 16px; }
  .toolbar { align-items: stretch; flex-direction: column; }
  .filters, .search, .inline-form, .bulk-bar { align-items: stretch; flex-direction: column; }
  .settings-form { grid-template-columns: 1fr; }
  .kpi-grid, .dashboard-grid, .leaders-grid, .efficiency-grid, .content-growth-grid { grid-template-columns: 1fr; }
  .compare-list { grid-template-columns: 1fr; }
  .project-create form, .project-menu form { left: 0; right: auto; width: min(300px, calc(100vw - 28px)); }
  .kpi-grid strong { font-size: 25px; }
  .mobile-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 20;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(62px, 1fr));
    gap: 6px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.96);
    border-top: 1px solid var(--line);
  }
  .mobile-nav a { text-align: center; }
  .analytics-table .tr span:nth-child(2) {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--panel);
  }
}
