:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-strong: #ffffff;
  --ink: #17202a;
  --muted: #667085;
  --line: #d9e1ec;
  --accent: #0f766e;
  --accent-strong: #1d4ed8;
  --danger: #b42318;
  --danger-soft: #fee4e2;
  --warn: #b54708;
  --warn-soft: #fef0c7;
  --ok: #067647;
  --ok-soft: #dcfae6;
  --shadow: 0 8px 22px rgba(16, 24, 40, 0.08);
  --radius-xl: 8px;
  --radius-lg: 8px;
  --radius-md: 8px;
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow-x: hidden;
}

button, select, input, textarea, a { font: inherit; }

.app-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(29, 78, 216, 0.06), transparent 260px);
}

.app-shell {
  position: relative;
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 28px;
  overflow-x: hidden;
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 20px;
  align-items: end;
  margin-bottom: 24px;
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--muted);
}

h1, h2, h3, h4, p { margin: 0; }

h1 {
  font-size: 36px;
  line-height: 1.08;
  letter-spacing: 0;
}

.topbar-actions,
.filters-row,
.detail-header-actions,
.status-line {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.topbar-actions {
  align-items: end;
}

.custom-range-controls {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}

.custom-range-controls[hidden] {
  display: none;
}

.toolbar-field {
  display: grid;
  gap: 8px;
}

.custom-range-controls .toolbar-field input {
  width: 160px;
}

.toolbar-field span,
.meta,
.subtle,
.panel-header p,
.site-main span,
.metric-stack span,
.reason-cell span {
  color: var(--muted);
  font-size: 14px;
}

select,
input,
textarea,
.ghost-button,
.chip-button {
  min-height: 48px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface-strong);
  padding: 0 18px;
  color: var(--ink);
}

textarea {
  width: 100%;
  min-height: 180px;
  padding: 14px 16px;
  line-height: 1.45;
  resize: vertical;
}

.ghost-button,
.chip-button {
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.ghost-button:hover,
.chip-button:hover,
.site-row:hover,
.site-card:hover,
.module-nav a:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.chip-button.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

button:disabled {
  cursor: wait;
  opacity: 0.62;
  transform: none;
  box-shadow: none;
}

.page-grid { display: grid; gap: 18px; min-width: 0; }

.page-grid > * { min-width: 0; }

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow);
  padding: 22px;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-bottom: 16px;
}

.compact-header { align-items: start; }

.hero-panel { padding-bottom: 18px; }

.hero-header { margin-bottom: 18px; }

.filters-row-wide > * { flex: 1 1 180px; }

.filter-actions {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  margin-top: 14px;
}

.filter-button-group {
  display: flex;
  gap: 10px;
}

.context-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.compact-field {
  min-width: 0;
}

.metric-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.metric-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.72);
  padding: 10px 14px;
  cursor: pointer;
}

.metric-chip.selected {
  border-color: var(--accent);
  background: rgba(15, 92, 82, 0.08);
}

.metric-chip input {
  margin: 0;
}

.kpi-grid {
  display: grid;
  gap: 16px;
}

.kpi-grid-five { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.kpi-grid-six { grid-template-columns: repeat(6, minmax(0, 1fr)); }

.empty-state-block {
  border: 1px dashed var(--line);
  border-radius: var(--radius-md);
  background: #f8fafc;
  color: var(--muted);
  padding: 18px;
}

.wide-empty-state {
  grid-column: 1 / -1;
}

.kpi-card,
.mini-metric,
.ops-item,
.alert-item,
.workspace-nav,
.detail-card,
.site-row,
.site-card {
  border-radius: var(--radius-lg);
  border: 1px solid rgba(28, 23, 20, 0.08);
  background: rgba(255,255,255,0.86);
}

.kpi-card {
  display: block;
  padding: 22px;
  background: var(--surface);
  color: inherit;
  text-decoration: none;
}

.kpi-card span,
.mini-metric span {
  display:block;
  font-size:13px;
  color: var(--muted);
  margin-bottom: 10px;
}

.kpi-card strong { font-size: 30px; letter-spacing: -0.04em; }

.mini-metric-value {
  display: block;
}

.kpi-value-line {
  display: flex;
  align-items: baseline;
  gap: 10px;
  flex-wrap: wrap;
}

.kpi-delta {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 700;
}

.kpi-card .kpi-delta,
.table-metric .kpi-delta,
.mini-metric .kpi-delta {
  display: inline-flex;
  margin: 0;
  font-size: 12px;
}

.kpi-delta-up {
  background: var(--ok-soft);
  color: var(--ok);
}

.kpi-card .kpi-delta-up,
.table-metric .kpi-delta-up,
.mini-metric .kpi-delta-up {
  color: var(--ok);
}

.kpi-delta-down {
  background: var(--danger-soft);
  color: var(--danger);
}

.kpi-card .kpi-delta-down,
.table-metric .kpi-delta-down,
.mini-metric .kpi-delta-down {
  color: var(--danger);
}

.kpi-delta-flat {
  background: #eef2f6;
  color: var(--muted);
}

.kpi-card .kpi-delta-flat,
.table-metric .kpi-delta-flat,
.mini-metric .kpi-delta-flat {
  color: var(--muted);
}

.mini-metric .kpi-delta {
  width: fit-content;
  margin-top: 12px;
}

.ops-kpi-card {
  cursor: pointer;
}

.ops-kpi-card em {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  font-style: normal;
}

.status-text-ok { color: var(--ok); }
.status-text-watch { color: var(--warn); }
.status-text-action { color: var(--danger); }

.overview-stack,
.detail-module-grid {
  display: grid;
  gap: 18px;
}

.site-table,
.alert-list,
.ops-list { display: grid; gap: 12px; }

.portfolio-table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
}

.portfolio-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  background: var(--surface);
}

.portfolio-table th,
.portfolio-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.portfolio-table th {
  background: #f8fafc;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.table-sort-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  padding: 0;
  cursor: pointer;
  text-align: left;
  text-transform: inherit;
  letter-spacing: inherit;
  font-size: inherit;
  font-weight: inherit;
}

.table-sort-button small {
  min-width: 10px;
  color: var(--accent);
  font-size: 12px;
  line-height: 1;
}

.portfolio-table tr:last-child td {
  border-bottom: 0;
}

.portfolio-table td strong,
.portfolio-table td span {
  display: block;
}

.portfolio-table td span,
.site-link span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 4px;
}

.table-metric {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.site-link {
  color: inherit;
  text-decoration: none;
}

.site-link:hover strong {
  color: var(--accent-strong);
}

.site-row {
  display: grid;
  gap: 12px;
  padding: 16px 18px;
  align-items: start;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  text-align: left;
}

.priority-header-row,
.priority-row {
  grid-template-columns: 1.1fr 0.7fr 0.7fr 0.9fr 0.8fr 0.7fr 0.8fr 1.6fr;
}

.site-row.header {
  background: #f8fafc;
  border-style: solid;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  cursor: default;
  box-shadow: none;
}

.site-main strong,
.reason-cell strong,
.metric-stack strong { display:block; }

.site-main strong,
.reason-cell strong { font-size: 16px; }

.metric-stack strong { font-size: 18px; }

.delta {
  font-weight: 700;
}

.delta-up {
  color: var(--danger);
}

.delta-down {
  color: var(--ok);
}

.delta-flat {
  color: var(--muted);
}

.reason-cell { display: grid; gap: 4px; }

.hero-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 12px;
}

.status-pill,
.severity-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.status-ok, .tone-ok { background: var(--ok-soft); color: var(--ok); }
.status-watch, .tone-watch { background: var(--warn-soft); color: var(--warn); }
.status-action, .tone-action { background: var(--danger-soft); color: var(--danger); }

.alert-item,
.ops-item,
.mini-metric { padding: 16px; }

.alert-item h4,
.ops-item h4 { font-size: 18px; margin-bottom: 6px; }

.site-workspace {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 16px;
}

.workspace-nav {
  position: sticky;
  top: 28px;
  align-self: start;
}

.module-nav {
  display: grid;
  gap: 8px;
  margin-top: 16px;
}

.module-nav a {
  display: block;
  padding: 11px 13px;
  text-decoration: none;
  color: var(--ink);
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: var(--surface);
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
}

.module-nav a.active {
  border-color: var(--accent);
  background: rgba(15, 118, 110, 0.08);
  color: var(--accent-strong);
  font-weight: 700;
}

.platform-links {
  display: grid;
  gap: 8px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.platform-links .eyebrow {
  margin-bottom: 2px;
}

.platform-links a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--soft);
  color: var(--ink);
  text-decoration: none;
  font-weight: 650;
}

.platform-link-action {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.order-product-links {
  display: grid;
  gap: 5px;
}

.order-product-links span,
.order-product-links a {
  min-width: 0;
}

.workspace-main { min-width: 0; }

.detail-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.detail-header h2 { font-size: clamp(28px, 3vw, 44px); }

.headline {
  margin-top: 12px;
  max-width: 760px;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.55;
}

.detail-kpis {
  display: grid;
  gap: 16px;
}

.detail-kpis-five { grid-template-columns: repeat(5, minmax(0, 1fr)); }

.secondary-kpis { margin-top: -4px; }

.mini-metric strong { font-size: 24px; letter-spacing: -0.03em; }

.detail-module-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.serp-layout-grid {
  grid-template-columns: 1fr 1fr;
}

.serp-featured-card,
.serp-history-card,
.serp-snapshot-card {
  min-width: 0;
}

.serp-snapshot-card {
  grid-column: 1 / -1;
}

.matched-result-card {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.matched-rank-block {
  border-radius: var(--radius-lg);
  background: #ecfdf3;
  border: 1px solid #abefc6;
  padding: 18px;
}

.matched-rank-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 8px;
}

.matched-rank-block strong {
  font-size: 42px;
  letter-spacing: -0.04em;
}

.matched-result-meta {
  display: grid;
  gap: 8px;
}

.matched-result-meta h4 {
  font-size: 22px;
}

.result-link {
  word-break: break-all;
  color: var(--accent);
  text-decoration: none;
}

.result-link:hover {
  text-decoration: underline;
}

.neighbors-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.neighbor-card-primary {
  border-color: rgba(15, 92, 82, 0.18);
  background: rgba(15, 92, 82, 0.06);
}

.serp-five-row {
  grid-template-columns: 0.6fr 1.4fr 1.1fr 1.5fr 0.7fr;
}

.serp-snapshot-table {
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid rgba(28, 23, 20, 0.08);
}

.target-row {
  background: rgba(143, 45, 45, 0.06);
}

.serp-rank-chart {
  height: 190px;
}

.serp-table-page {
  overflow: hidden;
}

.serp-master-table {
  border-radius: var(--radius-md);
  overflow: auto;
  border: 1px solid rgba(28, 23, 20, 0.08);
}

.serp-master-row {
  min-width: 1800px;
  grid-template-columns: 1.1fr 0.45fr 0.55fr 0.65fr 0.65fr 1.15fr 1.15fr 1.15fr 1.15fr 1.05fr 1.35fr;
}

.serp-master-data-row {
  align-items: start;
}

.serp-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.serp-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.serp-toolbar-filters,
.serp-toolbar-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.keyword-drawer {
  position: fixed;
  top: 24px;
  right: 24px;
  width: min(520px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  z-index: 20;
}

.keyword-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.keyword-target-row {
  grid-column: 1 / -1;
}

.drawer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.drawer-actions-bottom {
  padding-top: 12px;
  border-top: 1px solid rgba(28, 23, 20, 0.08);
}

.keyword-list-block {
  margin-top: 18px;
}

.keyword-list-block h4 {
  margin-bottom: 12px;
}

.keyword-list-grid {
  display: grid;
  gap: 10px;
}

.keyword-list-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 14px;
}

.overview-trend-panel {
  padding-top: 18px;
}

.trend-legend {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 14px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  display: inline-block;
  margin-right: 8px;
}

.legend-visitors { background: #8f2d2d; }
.legend-visits { background: #0f5c52; }
.legend-views { background: #8d5b16; }

.overview-sparkline {
  width: 100%;
  height: 320px;
  display: block;
  border-radius: 14px;
  background: #f8fafc;
  border: 1px solid var(--line);
}

.trend-grid-line {
  stroke: #e6edf5;
  stroke-width: 1;
}

.trend-axis-line,
.trend-tick-line {
  stroke: #cdd9ea;
  stroke-width: 1;
}

.trend-axis-label {
  fill: var(--muted);
  font-size: 12px;
}

.trend-line {
  vector-effect: non-scaling-stroke;
}

.trend-point {
  stroke: #ffffff;
  stroke-width: 1.5;
  vector-effect: non-scaling-stroke;
}

.trend-hover-zone {
  fill: transparent;
  cursor: crosshair;
}

.trend-hover-overlay {
  fill: transparent;
  pointer-events: all;
  cursor: crosshair;
}

.trend-hover-line {
  stroke: #8a98b7;
  stroke-width: 1;
  stroke-dasharray: 4 4;
  opacity: 0;
}

.trend-tooltip {
  opacity: 0;
  pointer-events: none;
}

.trend-tooltip-bg {
  fill: rgba(255, 255, 255, 0.96);
  stroke: #d7e0ec;
}

.trend-tooltip-title {
  fill: var(--ink);
  font-size: 13px;
  font-weight: 600;
}

.trend-tooltip-label,
.trend-tooltip-value {
  fill: var(--ink);
  font-size: 12px;
}

.trend-tooltip-swatch {
  stroke-width: 4;
  stroke-linecap: round;
}

.trend-hover-group:hover .trend-hover-line,
.trend-hover-group:hover .trend-tooltip,
.trend-hover-group[data-active="true"] .trend-hover-line,
.trend-hover-group[data-active="true"] .trend-tooltip {
  opacity: 1;
}

.detail-card { padding: 20px; }

.warning-note {
  margin-top: 12px;
  padding: 10px 12px;
  border: 1px solid #fde68a;
  background: #fffbeb;
  color: #8a4b0b;
  border-radius: 8px;
  font-size: 13px;
}

.funnel-user-row {
  grid-template-columns: 144px 112px 78px 144px 190px 230px 70px 112px 78px;
  min-width: 1258px;
  gap: 10px;
  padding: 11px 12px;
  font-size: 14px;
}

.funnel-user-row-no-product {
  grid-template-columns: 144px 112px 78px 144px 230px 70px 112px 78px;
  min-width: 1030px;
}

.funnel-user-row > div,
.funnel-user-row > button {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.funnel-user-row span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.funnel-user-row strong {
  font-size: 14px;
}

.table-link {
  color: #1d4ed8;
  font-weight: 700;
  text-decoration: none;
}

.button-link {
  border: 0;
  background: transparent;
  padding: 0;
  cursor: pointer;
  font: inherit;
}

.table-sort-button {
  border: 0;
  background: transparent;
  padding: 0;
  color: inherit;
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  text-align: left;
  text-transform: inherit;
  letter-spacing: inherit;
}

.table-sort-button:hover {
  color: var(--accent-strong);
}

.table-link:hover {
  text-decoration: underline;
}

.funnel-table-scroll {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 8px;
  -webkit-overflow-scrolling: touch;
  scrollbar-color: #94a3b8 #e5edf7;
  scrollbar-width: thin;
}

.funnel-table-scroll::-webkit-scrollbar {
  height: 12px;
}

.funnel-table-scroll::-webkit-scrollbar-track {
  background: #e5edf7;
  border-radius: 999px;
}

.funnel-table-scroll::-webkit-scrollbar-thumb {
  background: #94a3b8;
  border: 3px solid #e5edf7;
  border-radius: 999px;
}

.funnel-user-table {
  min-width: 1258px;
  width: 1258px;
  max-width: none;
  overflow: hidden;
}

.funnel-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.funnel-pagination > div {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.activity-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.46);
}

.serp-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 22;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.46);
}

.activity-modal {
  width: min(920px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 22px;
}

.serp-modal {
  width: min(1040px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 22px;
}

.serp-modal-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.serp-modal-summary div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
  padding: 10px;
}

.serp-modal-summary span,
.serp-modal-summary strong {
  display: block;
}

.serp-modal-summary span {
  color: var(--muted);
  font-size: 12px;
}

.serp-rank-modal-chart {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #fbfdff;
  margin-bottom: 14px;
}

.serp-rank-modal-chart svg {
  display: block;
  min-width: 720px;
  width: 100%;
}

.serp-rank-line {
  fill: none;
  stroke: var(--accent-strong);
  stroke-width: 3;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.serp-rank-point {
  fill: var(--surface);
  stroke: var(--accent-strong);
  stroke-width: 2;
}

.serp-history-row {
  grid-template-columns: 0.7fr 0.5fr minmax(0, 2fr);
}

.serp-keyword-link {
  text-align: left;
}

.activity-summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.activity-summary-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #fbfdff;
}

.activity-summary-grid span,
.activity-summary-grid strong {
  display: block;
}

.activity-summary-grid span {
  color: var(--muted);
  font-size: 12px;
}

.activity-path-list {
  display: grid;
  gap: 0;
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.activity-path-item {
  display: grid;
  grid-template-columns: 16px minmax(120px, 180px) minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.activity-path-dot {
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: #1d4ed8;
  margin-top: 7px;
}

.activity-path-item strong,
.activity-path-item span,
.activity-path-item p {
  display: block;
  margin: 0;
}

.activity-path-item span {
  color: var(--muted);
  font-size: 12px;
}

.activity-path-item p {
  overflow-wrap: anywhere;
}

.activity-session-block {
  display: grid;
  gap: 10px;
  padding: 12px 0 16px;
  border-bottom: 1px solid var(--line);
}

.activity-session-block:last-child {
  border-bottom: 0;
}

.activity-session-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.activity-session-header div {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.activity-session-header strong,
.activity-session-header span {
  overflow-wrap: anywhere;
}

.activity-session-header span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.module-action {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
}

.section-metrics {
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
}

.section-metrics-tight { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.traffic-explorer-intro { padding-bottom: 18px; }

.detail-module-grid.traffic-breakdown-grid {
  align-items: start;
  grid-template-columns: minmax(0, 1fr);
}

.traffic-breakdown-panel {
  display: grid;
  gap: 16px;
  min-width: 0;
}

.traffic-breakdown-wide {
  grid-column: auto;
}

.traffic-tab-row {
  display: flex;
  align-items: center;
  gap: 22px;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}

.traffic-tab {
  appearance: none;
  border: 0;
  border-bottom: 3px solid transparent;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-weight: 650;
  padding: 0 0 12px;
}

.traffic-tab.active {
  border-bottom-color: var(--accent);
  color: var(--ink);
}

.traffic-subtabs {
  gap: 28px;
  border-bottom-color: rgba(28, 23, 20, 0.08);
  margin-top: -2px;
}

.traffic-breakdown-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
}

.traffic-breakdown-header h3 {
  margin: 0;
}

.traffic-breakdown-header p {
  margin: 4px 0 0;
  color: var(--muted);
}

.traffic-list {
  display: grid;
  gap: 0;
  min-width: 0;
  overflow-x: auto;
}

.traffic-list-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(90px, 120px) minmax(72px, 96px) minmax(66px, 82px);
  gap: 18px;
  align-items: center;
  min-height: 48px;
  padding: 9px 12px;
  border-radius: 8px;
}

.traffic-list-row:hover:not(.traffic-list-head) {
  background: rgba(15, 92, 82, 0.05);
}

.traffic-list-head {
  min-height: auto;
  padding-top: 0;
  padding-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.traffic-list-head > div {
  min-width: 0;
}

.traffic-list-head .table-sort-button {
  display: block;
  width: 100%;
  text-align: left;
}

.traffic-list-head > div:not(:first-child) {
  text-align: right;
}

.traffic-list-head > div:not(:first-child) .table-sort-button {
  width: 100%;
  text-align: right;
}

.traffic-dimension {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.traffic-dimension strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.traffic-dimension span,
.traffic-value span {
  color: var(--muted);
  font-size: 14px;
}

.traffic-value {
  display: grid;
  grid-template-columns: minmax(52px, 1fr) minmax(56px, auto) 58px;
  gap: 12px;
  align-items: baseline;
  justify-items: end;
}

.traffic-list-number,
.traffic-list-delta,
.traffic-list-share {
  min-width: 0;
  text-align: right;
}

.traffic-list-number strong {
  font-size: 17px;
}

.traffic-list-share span {
  color: var(--muted);
  font-size: 14px;
}

.traffic-change {
  font-style: normal;
  font-weight: 750;
  font-size: 14px;
}

.traffic-change-up { color: #087443; }
.traffic-change-down { color: #b42318; }
.traffic-change-flat { color: var(--muted); }

.traffic-value span {
  justify-self: start;
  border-left: 1px solid var(--line);
  padding-left: 14px;
}

.traffic-search-list {
  overflow-x: auto;
}

.traffic-search-movement {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.traffic-search-movement-item {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: 9px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.68);
}

.traffic-search-movement-item span,
.traffic-search-movement-item em {
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
}

.traffic-search-movement-item strong {
  font-size: 18px;
}

.traffic-search-movement-item em {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.traffic-search-row {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(8, minmax(92px, 0.38fr));
  gap: 14px;
  align-items: center;
  min-width: 1180px;
  min-height: 58px;
  padding: 11px 12px;
  border-radius: 8px;
}

.traffic-search-row:hover {
  background: rgba(15, 92, 82, 0.05);
}

.traffic-search-row > div:not(:first-child) {
  justify-self: stretch;
  text-align: right;
}

.traffic-search-row > div {
  min-width: 0;
}

.traffic-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.traffic-pagination > div {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.traffic-search-head {
  min-height: auto;
  padding-top: 0;
  padding-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.traffic-search-head:hover {
  background: transparent;
}

.traffic-search-head > div {
  display: flex;
  align-items: center;
}

.traffic-search-head > div:first-child {
  justify-content: flex-start;
}

.traffic-search-head > div:not(:first-child) {
  justify-content: flex-end;
}

.traffic-search-head .table-sort-button {
  display: block;
  width: 100%;
  white-space: nowrap;
}

.traffic-search-head > div:not(:first-child) .table-sort-button {
  width: 100%;
  text-align: right;
}

.traffic-search-metric {
  display: grid;
  gap: 4px;
  justify-items: end;
  line-height: 1.1;
  text-align: right;
}

.traffic-search-delta {
  display: grid;
  justify-items: end;
  text-align: right;
}

.traffic-search-metric strong {
  font-size: 17px;
}

.traffic-search-metric .traffic-change,
.traffic-search-delta .traffic-change {
  font-size: 12px;
  font-weight: 750;
}

.behavior-breakdown-grid {
  align-items: start;
}

.behavior-page-grid {
  grid-template-columns: 1fr;
}

.detail-module-grid.behavior-page-grid {
  grid-template-columns: 1fr;
}

.behavior-breakdown-panel {
  box-shadow: none;
}

.behavior-breakdown-embedded {
  min-width: 0;
}

.behavior-table {
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.behavior-row {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) 0.58fr 0.62fr 0.72fr 0.62fr;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.behavior-row:last-child { border-bottom: 0; }

.behavior-head {
  background: #eef4ff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.site-search-table {
  display: grid;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.site-search-row {
  display: grid;
  grid-template-columns: minmax(0, 1.55fr) 0.55fr 0.55fr 0.65fr 0.75fr 0.5fr;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.site-search-row:last-child { border-bottom: 0; }

.site-search-head {
  background: #eef4ff;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.site-search-head > div:not(:first-child) {
  text-align: right;
}

.table-like {
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 1px solid rgba(28, 23, 20, 0.08);
}

.table-row {
  display: grid;
  gap: 12px;
  padding: 13px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.table-row:last-child { border-bottom: 0; }

.table-row.four { grid-template-columns: 1.4fr 0.8fr 0.8fr 1fr; }
.table-row.three { grid-template-columns: 1.5fr 0.8fr 0.8fr; }

.table-row.header {
  background: #eef4ff;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
}

.breakdown-row {
  grid-template-columns: minmax(0, 1.8fr) 0.8fr 0.9fr 0.8fr;
}

.search-breakdown-row {
  grid-template-columns: minmax(0, 1.8fr) 0.8fr 0.8fr 0.8fr;
}

.order-breakdown-row {
  grid-template-columns: minmax(0, 1.4fr) 0.8fr 0.9fr 0.9fr 0.9fr;
}

.serp-master-row {
  grid-template-columns: minmax(0, 1.9fr) 0.6fr 0.7fr 1fr 1fr;
}

.serp-detail-row {
  min-width: 1800px;
  grid-template-columns: 1.1fr 0.45fr 0.55fr 0.65fr 0.65fr 1.15fr 1.15fr 1.15fr 1.15fr 1.05fr 1.35fr;
}

.keyword-bulk-field,
.serp-keyword-notice {
  margin-top: 12px;
}

.ai-assistant {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  display: grid;
  justify-items: end;
  gap: 14px;
  pointer-events: none;
}

.ai-fab,
.ai-chat-panel {
  pointer-events: auto;
}

.ai-fab {
  width: 66px;
  height: 66px;
  border: 0;
  border-radius: 999px;
  background: #3348f4;
  color: #fff;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.28);
  cursor: pointer;
  font-weight: 850;
  letter-spacing: 0;
}

.ai-fab:hover {
  transform: translateY(-2px);
}

.ai-fab span {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
}

.ai-chat-panel {
  width: min(560px, calc(100vw - 40px));
  max-height: min(820px, calc(100vh - 96px));
  display: grid;
  grid-template-rows: auto auto minmax(280px, 1fr) auto auto;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  background: var(--surface);
  box-shadow: 0 24px 72px rgba(15, 23, 42, 0.22);
}

.ai-chat-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.ai-chat-header h3 {
  font-size: 18px;
}

.ai-model-row {
  display: grid;
  gap: 6px;
  padding: 8px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.ai-model-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: start;
}

.ai-model-toolbar select,
.ai-model-toolbar input,
.ai-model-row input {
  width: 100%;
  min-height: 34px;
  padding: 0 10px;
  font-size: 14px;
}

.ai-provider-settings {
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 0;
  background: #fbfdff;
}

.ai-model-settings[open] {
  grid-column: 1 / -1;
}

.ai-provider-settings summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  min-height: 34px;
  display: flex;
  align-items: center;
  padding: 0 10px;
}

.ai-load-models-button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: #eef4ff;
  color: var(--ink);
  cursor: pointer;
  font-size: 13px;
  font-weight: 800;
}

.ai-provider-grid {
  display: grid;
  gap: 8px;
  padding: 8px 10px 10px;
  min-width: min(420px, calc(100vw - 86px));
}

.ai-model-filter-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.ai-optional-field {
  display: none;
}

.ai-icon-button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--ink);
  cursor: pointer;
  font-weight: 850;
}

.ai-chat-messages {
  display: grid;
  align-content: start;
  gap: 10px;
  overflow: auto;
  padding: 16px 20px;
  background: #f8fafc;
}

.ai-chat-message {
  display: flex;
}

.ai-chat-message div {
  max-width: 88%;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 11px 13px;
  background: var(--surface);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.ai-chat-message-user {
  justify-content: flex-end;
}

.ai-chat-message-user div {
  border-color: #3348f4;
  background: #3348f4;
  color: #fff;
}

.ai-chat-empty {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.ai-prompt-grid {
  display: grid;
  gap: 8px;
  padding: 0 18px 14px;
  background: #f8fafc;
}

.ai-prompt-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 8px 10px;
  text-align: left;
  font-size: 14px;
}

.ai-prompt-button:hover {
  border-color: #3348f4;
}

.ai-chat-error {
  padding: 0 18px 10px;
  color: var(--danger);
  font-size: 13px;
}

.ai-chat-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.ai-chat-form textarea {
  min-height: 96px;
  padding: 12px;
  resize: none;
}

.ai-send-button {
  min-height: 44px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--ink);
  color: #fff;
  cursor: pointer;
  padding: 0 16px;
  font-weight: 800;
}

[hidden] { display: none !important; }

@media (max-width: 1280px) {
  .kpi-grid-five,
  .kpi-grid-six,
  .detail-kpis-five,
  .detail-module-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .priority-header-row,
  .priority-row { grid-template-columns: 1fr 1fr 1fr 1fr; }
  .priority-row > :nth-child(n+5) { display: block; }
  .context-grid,
  .neighbors-grid,
  .serp-layout-grid {
    grid-template-columns: 1fr;
  }
  .keyword-form-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 900px) {
  .app-shell { padding: 18px; max-width: 100vw; }
  .site-workspace { grid-template-columns: 1fr; }
  .workspace-nav { position: static; }
  .page-grid,
  .panel,
  .hero-panel { max-width: calc(100vw - 36px); overflow-x: hidden; }
  h2 { font-size: 24px; line-height: 1.2; overflow-wrap: anywhere; }
  .topbar,
  .detail-header { flex-direction: column; align-items: start; }
  .panel-header { flex-direction: column; align-items: start; }
  .hero-actions { justify-content: flex-start; width: 100%; }
  .hero-actions .module-action { max-width: 100%; }
  .filters-row > * { width: 100%; flex-basis: 100%; }
  .filter-actions { flex-direction: column; align-items: stretch; }
  .filter-button-group { flex-wrap: wrap; }
  .kpi-grid-five,
  .kpi-grid-six,
  .detail-kpis-five,
  .detail-module-grid,
  .section-metrics-tight { grid-template-columns: 1fr; }
  .activity-summary-grid,
  .serp-modal-summary,
  .activity-path-item { grid-template-columns: 1fr; }
  .activity-path-dot { display: none; }
  .traffic-breakdown-header { align-items: start; flex-direction: column; }
  .traffic-list-row { min-width: 560px; }
  .traffic-search-movement,
  .traffic-search-movement-item { grid-template-columns: 1fr; }
  .traffic-tab-row { gap: 16px; }
  .behavior-page-grid,
  .behavior-row { grid-template-columns: 1fr; }
  .matched-result-card,
  .serp-five-row,
  .context-grid,
  .neighbors-grid,
  .serp-layout-grid { grid-template-columns: 1fr; }
  .serp-toolbar,
  .serp-toolbar-filters,
  .serp-toolbar-actions,
  .serp-header-actions,
  .keyword-list-item { flex-direction: column; align-items: stretch; }
  .priority-header-row,
  .priority-row,
  .table-row.four,
  .table-row.three { grid-template-columns: 1fr; }
  .site-row.header { display: none; }
  .ai-assistant {
    right: 16px;
    bottom: 16px;
  }
  .ai-chat-panel {
    width: calc(100vw - 32px);
    max-height: calc(100vh - 98px);
    grid-template-rows: auto auto minmax(220px, 1fr) auto auto;
  }
  .ai-model-toolbar {
    grid-template-columns: 1fr;
  }
  .ai-provider-grid {
    min-width: 0;
  }
  .ai-model-filter-row {
    grid-template-columns: 1fr;
  }
}
