:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #1d2733;
  --muted: #657386;
  --line: #dce2ea;
  --blue: #0051f9;
  --green: #1f9d63;
  --red: #d84f45;
  --amber: #c68a10;
  --radius: 8px;
  font-family: Inter, Segoe UI, Roboto, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

#app {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px 1fr;
}

.sidebar {
  background: #111827;
  color: #fff;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 32px;
}

.brand-logo {
  width: 104px;
  height: auto;
  display: block;
  background: #fff;
  border-radius: 6px;
  padding: 7px 8px;
}

.brand span,
.sidebar nav button {
  color: #aeb8c4;
}

.brand strong,
.brand span {
  display: block;
}

.sidebar nav {
  display: grid;
  gap: 8px;
}

.sidebar-section {
  display: grid;
  gap: 8px;
}

.sidebar-section > span {
  color: #aeb8c4;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
  padding: 0 14px 4px;
}

.period-toggle {
  display: none;
}

.sidebar nav button {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius);
}

.sidebar nav button.active,
.sidebar nav button:hover {
  background: var(--blue);
  color: #fff;
}

main {
  padding: 32px;
  display: grid;
  gap: 22px;
  align-content: start;
}

.auth-page {
  grid-column: 1 / -1;
  width: 100%;
  min-height: 100vh;
  display: grid;
  place-items: center;
  align-content: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  width: min(440px, 100%);
  display: grid;
  gap: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 30px;
  box-shadow: 0 18px 50px rgba(17, 24, 39, 0.08);
}

.auth-logo {
  width: 150px;
  display: block;
}

.auth-card p {
  color: var(--muted);
  margin-top: 8px;
}

.auth-form {
  display: grid;
  gap: 14px;
}

.auth-error {
  color: var(--red);
  background: #fdecea;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  font-weight: 700;
}

.inline-warning {
  color: #8a5b00;
  background: #fff3d7;
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 13px;
  font-weight: 700;
}

.inline-success {
  color: var(--green);
  background: #e9f7ef;
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-top: 14px;
  font-size: 13px;
  font-weight: 700;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: rgba(17, 24, 39, 0.5);
  padding: 24px;
}

.modal {
  width: min(760px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  background: #fff;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: 0 24px 70px rgba(17, 24, 39, 0.26);
  padding: 22px;
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 18px;
}

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.project-form {
  display: grid;
  gap: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 24px;
}

.admin-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.eyebrow {
  color: var(--blue);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 12px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 34px;
  line-height: 1.1;
  margin-top: 6px;
}

h2 {
  font-size: 18px;
}

.page-head p,
.panel-head span,
.source-grid span {
  color: var(--muted);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

select,
input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  padding: 8px 11px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(120px, 1fr));
  gap: 14px;
}

.metric-card,
.panel,
.text-block {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric-card {
  padding: 16px;
  display: grid;
  gap: 8px;
}

.metric-card span {
  color: var(--muted);
  font-size: 13px;
}

.metric-card strong {
  font-size: 28px;
  line-height: 1;
}

.trend {
  display: inline-flex;
  width: fit-content;
  align-items: center;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
}

.trend.up {
  color: var(--green);
  background: #e9f7ef;
}

.trend.down {
  color: var(--red);
  background: #fdecea;
}

.content-grid {
  display: grid;
  gap: 18px;
}

.content-grid.two {
  grid-template-columns: 1fr 1fr;
}

.panel {
  padding: 18px;
  min-width: 0;
}

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

.channel-table td {
  white-space: nowrap;
}

.channel-name {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  white-space: normal;
}

.channel-name i {
  width: 10px;
  height: 10px;
  flex: 0 0 auto;
  border-radius: 999px;
}

.share-badge {
  display: inline-flex;
  min-width: 54px;
  justify-content: center;
  border-radius: 999px;
  background: #edf3ff;
  color: var(--blue);
  font-weight: 800;
  padding: 5px 9px;
}

.traffic-chart-panel {
  width: 100%;
}

.traffic-chart-wrap {
  width: 100%;
  overflow-x: auto;
  position: relative;
}

.traffic-chart {
  display: block;
  width: 100%;
  min-width: 760px;
  height: auto;
}

.chart-grid {
  stroke: #e3e8ef;
  stroke-width: 1;
}

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

.chart-line {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-dot {
  stroke: #fff;
  stroke-width: 2;
  cursor: pointer;
  transition: r 0.15s ease, stroke-width 0.15s ease;
}

.chart-dot:hover {
  r: 7;
  stroke-width: 3;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  margin-top: 12px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.chart-legend i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.chart-tooltip {
  position: absolute;
  z-index: 5;
  min-width: 170px;
  pointer-events: none;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
  background: #111827;
  color: #fff;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 12px 30px rgba(17, 24, 39, 0.22);
}

.chart-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

.chart-tooltip strong,
.chart-tooltip span,
.chart-tooltip b {
  display: block;
}

.chart-tooltip strong {
  font-size: 13px;
  margin-bottom: 4px;
}

.chart-tooltip span {
  color: #cbd5e1;
  font-size: 12px;
  margin-bottom: 6px;
}

.chart-tooltip b {
  font-size: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 700;
  font-size: 12px;
}

.seo-head {
  display: grid;
  grid-template-columns: 1fr auto;
}

.seo-range {
  display: inline-flex;
  background: #edf1f5;
  border-radius: var(--radius);
  padding: 3px;
}

.seo-range button {
  border: 0;
  background: transparent;
  border-radius: 6px;
  color: var(--muted);
  font-weight: 700;
  padding: 8px 11px;
  white-space: nowrap;
}

.seo-range button.active {
  background: #fff;
  color: var(--blue);
  box-shadow: 0 1px 2px rgba(20, 31, 44, 0.1);
}

.seo-tables {
  display: grid;
  gap: 22px;
}

.seo-tables article {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.seo-table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin: 0;
  padding: 14px 16px;
  background: #f7f9fb;
  border-bottom: 1px solid var(--line);
}

.seo-table-head h3 {
  margin: 0;
  font-size: 16px;
}

.seo-table-head select {
  min-width: 190px;
  background: #fff;
}

.seo-tables table th:first-child,
.seo-tables table td:first-child {
  padding-left: 16px;
}

.seo-tables table th:last-child,
.seo-tables table td:last-child {
  padding-right: 16px;
}

.seo-scroll {
  max-width: 100%;
  overflow-x: auto;
}

.show-more {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-top: 1px solid var(--line);
  background: #f7f9fb;
  color: var(--blue);
  font-weight: 800;
}

.show-more:hover {
  background: #edf3ff;
}

.seo-matrix {
  min-width: 1120px;
  table-layout: fixed;
  border-collapse: separate;
  border-spacing: 0;
}

.seo-matrix th,
.seo-matrix td {
  border-right: 1px solid #aeb9c7;
  border-bottom: 1px solid #aeb9c7;
}

.seo-matrix th {
  background: #f2f4f7;
  color: #1d2733;
  font-size: 14px;
}

.seo-matrix .query-col {
  width: 320px;
}

.seo-matrix .freq-col {
  width: 92px;
  text-align: center;
}

.seo-matrix .date-col {
  width: 72px;
  text-align: center;
}

.seo-matrix th.date-col span,
.seo-matrix th.date-col small {
  display: block;
}

.seo-matrix th.date-col small {
  color: #8a96a3;
  font-size: 13px;
  font-weight: 700;
  margin-top: 5px;
}

.seo-matrix .query-col,
.seo-matrix .freq-col {
  position: sticky;
  z-index: 2;
}

.seo-matrix .query-col {
  left: 0;
}

.seo-matrix .freq-col {
  left: 320px;
}

.seo-matrix th.query-col,
.seo-matrix th.freq-col {
  z-index: 3;
}

.seo-matrix th.query-col,
.seo-matrix td.query-col,
.seo-matrix th.freq-col,
.seo-matrix td.freq-col {
  background: #fff;
}

.seo-matrix th.query-col,
.seo-matrix th.freq-col {
  background: #f2f4f7;
}

.seo-matrix td.query-col {
  text-align: left;
}

.seo-matrix td.query-col span,
.seo-matrix td.query-col small {
  display: block;
}

.seo-matrix td.query-col small {
  color: var(--muted);
  margin-top: 3px;
}

.seo-matrix td.date-col {
  font-size: 18px;
  color: #17324d;
  padding: 9px 8px;
}

.seo-matrix td.date-col sup {
  font-size: 12px;
  margin-left: 3px;
  vertical-align: super;
}

.seo-matrix td.date-col sup.up {
  color: #18a763;
}

.seo-matrix td.date-col sup.down {
  color: #ff2c2c;
}

.seo-pos-top3 {
  background: #b4d9f1;
}

.seo-pos-top10 {
  background: #8fe2b3;
}

.seo-pos-other,
.seo-pos-empty {
  background: #ffffff;
}

.url {
  color: var(--muted);
  font-size: 13px;
}

.position {
  min-width: 44px;
  display: inline-flex;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-weight: 800;
}

.pos-top {
  color: #0d6b3d;
  background: #cceedd;
}

.pos-ten {
  color: #18734b;
  background: #e2f6e9;
}

.pos-thirty {
  color: #846000;
  background: #fff0bf;
}

.pos-fifty {
  color: #9a5400;
  background: #ffe1c2;
}

.pos-low {
  color: #a2352f;
  background: #ffd8d5;
}

.pos-none {
  color: #6e7782;
  background: #edf0f3;
}

.text-block {
  padding: 18px;
}

.text-block > span {
  display: block;
  color: var(--blue);
  font-weight: 800;
  margin-bottom: 8px;
}

.text-block p {
  line-height: 1.55;
}

.report-notes h2 {
  margin: 0 0 18px;
}

.report-notes h3 {
  color: var(--blue);
  font-size: 15px;
  margin: 18px 0 8px;
}

.report-notes h3:first-of-type {
  margin-top: 0;
}

.admin-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 18px;
}

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

.project-list button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: var(--radius);
  padding: 13px;
  text-align: left;
  display: grid;
  gap: 4px;
}

.project-list button.active {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(0, 81, 249, 0.12);
}

.project-list span,
.project-list i {
  color: var(--muted);
  font-style: normal;
  font-size: 13px;
}

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

.form-grid.single {
  grid-template-columns: 1fr;
  margin-bottom: 14px;
}

.project-edit-form {
  display: grid;
  gap: 14px;
}

.period-create-form,
.period-edit-form {
  display: grid;
  gap: 14px;
  margin-bottom: 16px;
}

.period-create-form {
  align-items: end;
  grid-template-columns: minmax(180px, 240px) minmax(180px, 240px) auto;
}

.wide-field {
  display: grid;
  gap: 7px;
}

textarea {
  resize: vertical;
  min-height: 96px;
}

.integration-summary {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
}

.integration-summary div {
  display: grid;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.integration-summary span {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.field-note {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: -4px 0 14px;
}

.primary,
.secondary,
.table-action {
  border-radius: var(--radius);
  border: 1px solid transparent;
  min-height: 40px;
  padding: 8px 13px;
  font-weight: 700;
}

.primary {
  background: var(--blue);
  color: #fff;
}

.secondary,
.table-action {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.chips span {
  background: #edf3ff;
  color: #285dbf;
  border-radius: 999px;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 700;
}

.source-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 14px;
  margin-bottom: 14px;
}

.source-grid div {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
}

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

.status {
  display: inline-flex;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}

.status.ok {
  background: #e9f7ef;
  color: var(--green);
}

.status.warn {
  background: #fff3d7;
  color: var(--amber);
}

.status.bad {
  background: #ffe8e8;
  color: #c92a2a;
}

@media (max-width: 1100px) {
  #app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .metrics-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .content-grid.two,
  .admin-layout {
    grid-template-columns: 1fr;
  }

  .period-create-form {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  main {
    padding: 20px;
  }

  .page-head,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 28px;
  }

  .metrics-grid,
  .form-grid,
  .source-grid {
    grid-template-columns: 1fr;
  }

  .seo-head {
    grid-template-columns: 1fr;
  }

  .seo-table-head {
    align-items: stretch;
    flex-direction: column;
  }

  .sidebar-section:not(.show-all) .period-extra {
    display: none;
  }

  .period-toggle {
    display: block;
    color: #fff;
    border: 1px solid rgba(255, 255, 255, 0.18);
    background: rgba(255, 255, 255, 0.08);
  }

  table {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
  }
}
