:root {
  --bg: #f5f7fb;
  --ink: #121926;
  --muted: #667085;
  --panel: #ffffff;
  --line: #d0d5dd;
  --accent: #0a58ca;
  --danger: #b42318;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Noto Sans JP", "Hiragino Sans", sans-serif;
  color: var(--ink);
  background: linear-gradient(150deg, #e7efff, #f8fafc 45%);
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 20px;
  background: #0b1320;
  color: #fff;
  gap: 12px;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
}

.brand-lockup {
  display: flex;
  align-items: center;
}

.brand-logo {
  height: 30px;
  width: auto;
  display: block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar-nav {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.topbar-nav button {
  padding: 7px 12px;
  border-color: rgba(255,255,255,0.28);
}

.topbar-nav button.active {
  background: #ffffff;
  color: #0b1320;
  border-color: #ffffff;
}

.container {
  max-width: 1100px;
  margin: 18px auto;
  padding: 0 14px 22px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  box-shadow: 0 8px 20px rgba(16, 24, 40, 0.04);
}

.diagnosis-hero {
  border: 1px solid #bfdbfe;
  border-radius: 12px;
  padding: 14px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, #eff6ff, #f8fafc);
}

.diagnosis-result-box {
  margin-top: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #fff;
}

.diag-title {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
}

.diag-text {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

h2 {
  margin: 0 0 10px;
  font-size: 18px;
}

h3 {
  margin: 12px 0 6px;
}

.stack, .grid2, .grid3 {
  display: grid;
  gap: 8px;
}

.grid2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }

label {
  display: grid;
  gap: 4px;
  font-size: 13px;
}

input, select, button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 14px;
}

button {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  cursor: pointer;
}

button.ghost {
  background: transparent;
  border-color: #fff;
}

.inline {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.tabs {
  display: inline-flex;
  margin-bottom: 8px;
  gap: 6px;
}

.tabs button.active {
  background: #111927;
  border-color: #111927;
}

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

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

.chart-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: linear-gradient(180deg, #ffffff, #f8fafc);
}

.chart-summary {
  display: grid;
  gap: 4px;
  margin: 8px 0 10px;
  font-size: 12px;
  color: var(--muted);
}

.compare-good {
  color: #0a58ca;
}

.compare-bad {
  color: #b42318;
}

.compare-neutral {
  color: var(--muted);
}

.ga4-status-card {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  background: linear-gradient(135deg, #eff6ff, #f8fafc);
}

.ga4-kicker {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.ga4-main {
  font-size: 18px;
  font-weight: 700;
  margin-top: 4px;
}

.ga4-sub {
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
}

#ga4-reconnect {
  margin-top: 8px;
  color: var(--accent);
  border-color: #bfdbfe;
  background: #fff;
}

.chart {
  min-height: 220px;
}

.card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #fff;
}

.card .k {
  color: var(--muted);
  font-size: 12px;
}

.card .v {
  font-size: 20px;
  font-weight: 700;
  margin-top: 4px;
}

.action-focus-card {
  margin-top: 12px;
  border-color: #bfdbfe;
  background: linear-gradient(135deg, #eff6ff, #f8fafc);
}

.formula-details {
  margin-bottom: 12px;
}

.formula-details summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  margin-bottom: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 8px;
  border-bottom: 1px solid #e4e7ec;
  font-size: 13px;
  text-align: left;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin-top: 10px;
}

.breakdown-table {
  min-width: 760px;
}

.breakdown-table th:first-child,
.breakdown-table td:first-child {
  min-width: 260px;
  max-width: 360px;
}

.breakdown-dimension {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
}

.table-wrap.landing-mode {
  display: none;
}

.breakdown-cards {
  display: none;
  gap: 10px;
  margin-top: 10px;
}

.breakdown-cards.landing-mode {
  display: grid;
}

.breakdown-row-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: #f8fafc;
}

.breakdown-row-card-compact {
  padding: 8px 10px;
}

.breakdown-row-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 8px;
  word-break: break-word;
}

.breakdown-row-title-inline {
  margin-bottom: 8px;
  display: block;
  min-width: 0;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.breakdown-row-metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 10px;
}

.breakdown-inline-metrics-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  align-items: start;
}

.breakdown-inline-metrics-grid span {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.breakdown-inline-metrics-grid strong {
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
}

.breakdown-inline-metrics-grid em {
  font-style: normal;
  font-size: 12px;
  color: var(--ink);
  white-space: nowrap;
}

.campaign-impact-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.muted { color: var(--muted); }
.tiny { font-size: 12px; margin: 6px 0 8px; }
.locked { color: #b45309; }
.recommendations {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}

.rec-card {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.rec-card img {
  width: 120px;
  height: 90px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid #cbd5e1;
}

.rec-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.chat-log {
  display: grid;
  gap: 10px;
  max-height: 460px;
  overflow: auto;
  padding: 6px 0;
}

.chat-bubble {
  max-width: 88%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
}

.chat-bubble.user {
  margin-left: auto;
  background: #dbeafe;
  border-color: #bfdbfe;
}

.chat-bubble.assistant {
  margin-right: auto;
  background: #f8fafc;
}

.chat-compose {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.chat-compose textarea {
  width: 100%;
  resize: vertical;
}

.suggestion-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

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

.timeline-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.timeline-list {
  display: grid;
  gap: 8px;
}

.timeline-item {
  border: 1px solid #e4e7ec;
  border-radius: 8px;
  padding: 8px;
  background: #f8fafc;
}

.timeline-item.selected {
  border-color: #bfdbfe;
  background: #eff6ff;
}

.timeline-date {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.timeline-body {
  font-size: 13px;
}

.timeline-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
  white-space: pre-wrap;
}

.timeline-badge-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 6px;
}

.timeline-badge {
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #334155;
}

.timeline-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.timeline-actions button {
  padding: 5px 8px;
  font-size: 11px;
}

.validation-metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 10px 0;
}

.validation-detail-stack {
  display: grid;
  gap: 12px;
  margin-top: 10px;
}

.validation-metric-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #f8fafc;
}

.validation-metric-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 8px;
}

.validation-metric-name {
  font-weight: 700;
}

.ghost.active-filter {
  background: #eff6ff;
  color: #0a58ca;
  border-color: #bfdbfe;
}

@media (max-width: 768px) {
  .table-wrap {
    display: none;
  }

  .breakdown-cards {
    display: grid;
  }

  .timeline-grid,
  .chart-grid,
  .validation-metric-grid {
    grid-template-columns: 1fr;
  }

  .breakdown-row-title-inline {
    max-width: 100%;
    white-space: normal;
  }

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

.validation-bar {
  margin-bottom: 10px;
}

.validation-bar-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 4px;
}

.validation-bar-track {
  height: 10px;
  border-radius: 999px;
  background: #e5e7eb;
  overflow: hidden;
  position: relative;
}

.validation-bar-fill-before {
  position: absolute;
  inset: 0 auto 0 0;
  background: #94a3b8;
}

.validation-bar-fill-after {
  position: absolute;
  inset: 0 auto 0 0;
  background: #0a58ca;
  opacity: 0.78;
}

.suggestion-chip {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

.auth-aux {
  width: fit-content;
  color: #0a58ca;
  border-color: #bfdbfe;
  background: #fff;
}

.journey-summary {
  margin: 8px 0 12px;
}

.journey-alert {
  border: 1px solid #bfdbfe;
  border-radius: 10px;
  background: linear-gradient(135deg, #eff6ff, #f8fafc);
  padding: 10px 12px;
  font-size: 13px;
}

.journey-steps {
  display: grid;
  gap: 10px;
}

.journey-step-card {
  border: 1px solid #dbe3ef;
  border-radius: 10px;
  background: #fff;
  padding: 10px;
}

.journey-step-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 7px;
}

.journey-step-name {
  font-weight: 700;
  font-size: 13px;
}

.journey-step-value {
  font-size: 13px;
  font-weight: 700;
}

.journey-step-track {
  height: 11px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}

.journey-step-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #0a58ca, #1d4ed8);
}

.journey-step-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.journey-segments {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.journey-rank {
  display: grid;
  gap: 8px;
}

.journey-rank-row {
  border: 1px solid #e4e7ec;
  border-radius: 8px;
  padding: 8px;
  background: #fff;
}

.journey-rank-title {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 2px;
}

.journey-rank-meta {
  font-size: 12px;
  color: var(--muted);
}

.site-footer {
  display: flex;
  justify-content: center;
  gap: 16px;
  padding: 14px;
  font-size: 13px;
}

.site-footer a {
  color: #0a58ca;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.rec-meta, .rec-summary, .rec-step {
  font-size: 12px;
  color: var(--muted);
}

.hidden { display: none !important; }
.error { color: var(--danger); }

@media (max-width: 840px) {
  .topbar {
    align-items: flex-start;
  }
  .topbar-brand {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .chart-grid { grid-template-columns: 1fr; }
  .timeline-grid { grid-template-columns: 1fr; }
  .grid3, .grid2 { grid-template-columns: 1fr; }
  .rec-card { grid-template-columns: 1fr; }
  .rec-card img { width: 100%; height: 140px; }
  .journey-segments { grid-template-columns: 1fr; }
  .topbar-nav {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 4px;
    flex-wrap: nowrap;
  }
}
