:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --sep: #e5e5ea;
  --sep-soft: #f0f0f2;
  --stroke: #d2d2d7;
  --blue: #0071e3;
  --blue-vivid: #0a84ff;
  --green: #34c759;
  --red: #ff3b30;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.04), 0 8px 24px rgba(0, 0, 0, 0.05);
  --shadow-float: 0 12px 48px rgba(0, 0, 0, 0.18);
  --sans: -apple-system, BlinkMacSystemFont, "SF Pro JP", "SF Pro Display", "Helvetica Neue", "Hiragino Sans", "Yu Gothic UI", Meiryo, sans-serif;
  --mono: ui-monospace, "SF Mono", "SFMono-Regular", Menlo, monospace;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea { font: inherit; }

button { color: inherit; }

button:focus-visible,
input:focus-visible,
textarea:focus-visible {
  outline: 3px solid rgba(0, 125, 250, 0.5);
  outline-offset: 2px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 274px minmax(0, 1fr);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 274px;
  display: flex;
  flex-direction: column;
  padding: 28px 18px 22px;
  overflow-y: auto;
  background: rgba(246, 246, 248, 0.92);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  color: var(--text);
  border-right: 1px solid rgba(0, 0, 0, 0.07);
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 2px 6px 24px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.07);
}

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  padding: 10px 9px;
  background: linear-gradient(160deg, #45a1ff 0%, #0a6cff 55%, #0353d6 100%);
  border-radius: 11px;
  box-shadow: 0 2px 8px rgba(10, 108, 255, 0.35);
}

.brand-mark i {
  width: 5px;
  display: block;
  background: #fff;
  border-radius: 3px;
}

.brand-mark i:nth-child(1) { height: 10px; opacity: 0.65; }
.brand-mark i:nth-child(2) { height: 22px; }
.brand-mark i:nth-child(3) { height: 15px; opacity: 0.82; }

.brand-kicker,
.eyebrow,
.panel-kicker,
.modal-kicker {
  margin: 0 0 5px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.brand-kicker { font-size: 10px; }

.brand-name {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sidebar-section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 8px 8px;
  color: var(--text-3);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.count-badge {
  min-width: 24px;
  padding: 2px 8px;
  text-align: center;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-2);
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.site-list { display: grid; gap: 3px; }

.site-item {
  width: 100%;
  display: grid;
  grid-template-columns: 9px minmax(0, 1fr);
  gap: 11px;
  align-items: center;
  padding: 10px 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text);
  text-align: left;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.site-item:hover { background: rgba(0, 0, 0, 0.05); }

.site-item.is-active {
  background: var(--blue);
  color: #fff;
}

.site-item-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
}

.site-item.is-active .site-item-status { background: #fff; }
.site-item-status.is-paused { background: #aeaeb2; }

.site-item strong,
.site-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.site-item strong { font-size: 13px; font-weight: 600; letter-spacing: -0.01em; }
.site-item small { margin-top: 2px; color: var(--text-3); font-size: 11px; }
.site-item.is-active small { color: rgba(255, 255, 255, 0.75); }

.add-site-button {
  width: 100%;
  margin-top: 14px;
  padding: 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--blue);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 140ms ease;
}

.add-site-button:hover { background: rgba(0, 113, 227, 0.08); }

.sidebar-footer {
  display: flex;
  align-items: center;
  gap: 11px;
  margin-top: auto;
  padding: 16px 8px 0;
  border-top: 1px solid rgba(0, 0, 0, 0.07);
}

.sidebar-footer strong,
.sidebar-footer span { display: block; }
.sidebar-footer strong { font-size: 12px; font-weight: 600; }
.sidebar-footer span:not(.status-dot) { margin-top: 2px; color: var(--text-3); font-size: 10px; }

.status-dot,
.live-pulse {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--green);
}

.main-content {
  grid-column: 2;
  min-width: 0;
  padding: 34px clamp(24px, 3.6vw, 60px) 52px;
}

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

.topbar h1 {
  margin: 0;
  max-width: 640px;
  font-size: clamp(28px, 3vw, 40px);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.022em;
}

.current-domain {
  margin: 8px 0 0;
  color: var(--text-3);
  font-size: 13px;
}

.topbar-actions {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.date-control { display: grid; gap: 5px; }
.date-control span { color: var(--text-3); font-size: 11px; font-weight: 600; }
.date-control input {
  width: 140px;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

.date-separator { margin-bottom: 11px; color: var(--text-3); }

.icon-button,
.secondary-button,
.rail-action {
  min-height: 40px;
  padding: 0 17px;
  border: 1px solid var(--stroke);
  border-radius: 999px;
  background: var(--card);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease;
}

.icon-button { width: 40px; padding: 0; font-size: 16px; }
.key-button { font-size: 12px; }
.secondary-button:hover,
.icon-button:hover,
.rail-action:hover { background: #f5f5f7; }

.primary-button {
  min-height: 44px;
  padding: 0 22px;
  border: 0;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 140ms ease;
}

.primary-button:hover { background: #0077ed; }
.full-width { width: 100%; }
button:disabled { opacity: 0.4; cursor: not-allowed; }

.notice {
  margin-bottom: 18px;
  padding: 13px 18px;
  border-radius: 12px;
  background: #eaf2ff;
  color: #0058b0;
  font-size: 13px;
}

.notice.is-error { background: #ffefee; color: #d70015; }

.signal-rail {
  display: grid;
  grid-template-columns: auto auto minmax(24px, 1fr) auto minmax(24px, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
  padding: 14px 20px;
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--shadow-card);
}

.signal-label { display: flex; align-items: center; gap: 8px; margin-right: 10px; font-size: 12px; font-weight: 600; }
.signal-step span,
.signal-step small { display: block; }
.signal-step span { font-size: 12px; font-weight: 600; letter-spacing: -0.01em; }
.signal-step small { margin-top: 2px; color: var(--text-3); font-size: 10px; }
.signal-step:not(.is-active) { opacity: 0.4; }
.signal-line { height: 1px; background: var(--sep); }
.rail-actions { display: flex; gap: 8px; margin-left: 10px; }
.rail-action { font-size: 12px; white-space: nowrap; }
.pause-action { color: var(--red); }

.metric-grid {
  display: grid;
  grid-template-columns: 1.2fr 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.metric-card,
.panel {
  border: 0;
  border-radius: 16px;
  background: var(--card);
  box-shadow: var(--shadow-card);
}

.metric-card { position: relative; padding: 20px 22px 18px; }

.metric-primary {
  background: linear-gradient(150deg, #3395ff 0%, #0a6cff 55%, #0353d6 100%);
  color: #fff;
}

.metric-heading {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.metric-code { color: #c7c7cc; font-family: var(--mono); font-size: 9px; letter-spacing: 0.12em; }
.metric-primary .metric-code { color: rgba(255, 255, 255, 0.5); }

.metric-number {
  margin: 20px 0 8px;
  font-size: clamp(40px, 4.6vw, 62px);
  font-weight: 700;
  line-height: 0.95;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.metric-note { margin: 0; color: var(--text-3); font-size: 11px; }
.metric-primary .metric-note { color: rgba(255, 255, 255, 0.72); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.65fr) minmax(260px, 0.75fr); gap: 16px; margin-bottom: 16px; }
.panel { padding: 24px; }
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}
.panel-header h2 { margin: 0; font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.panel-kicker { margin-bottom: 4px; }
.chart-legend { display: flex; gap: 14px; color: var(--text-2); font-size: 11px; }
.chart-legend span { display: flex; align-items: center; gap: 6px; }
.chart-legend i { width: 8px; height: 8px; display: inline-block; border-radius: 50%; }
.legend-visits { background: var(--blue-vivid); }
.legend-goals { background: var(--green); }

.trend-chart { min-height: 252px; display: grid; align-items: center; }
.trend-chart svg { width: 100%; height: auto; overflow: visible; }
.chart-grid-line { stroke: var(--sep-soft); stroke-width: 1; }
.chart-axis-label { fill: #aeaeb2; font-family: var(--mono); font-size: 8px; }
.chart-area { fill: url(#visitArea); }
#visitArea stop:first-child { stop-color: var(--blue-vivid); stop-opacity: 0.16; }
#visitArea stop:last-child { stop-color: var(--blue-vivid); stop-opacity: 0; }
.chart-line { fill: none; stroke: var(--blue-vivid); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-goals { fill: none; stroke: var(--green); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.chart-dot { fill: #fff; stroke: var(--blue-vivid); stroke-width: 2; }

.conversion-list { display: grid; gap: 14px; }
.compact-header { margin-bottom: 12px; }
.panel-divider { height: 1px; margin: 22px 0; background: var(--sep); }
.source-list { display: grid; }
.source-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 12px 2px;
  border-bottom: 1px solid var(--sep-soft);
}
.source-row:last-child { border-bottom: 0; }
.source-row span,
.source-row small { display: block; }
.source-row strong { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.source-row span small { margin-top: 2px; color: var(--text-3); font-size: 11px; }
.source-row output { font-size: 20px; font-weight: 700; text-align: right; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.source-row output small { color: var(--text-3); font-size: 10px; font-weight: 500; }
.conversion-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 12px; align-items: center; }
.conversion-row strong { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conversion-row output { color: var(--text); font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.conversion-track { grid-column: 1 / -1; height: 6px; overflow: hidden; border-radius: 999px; background: var(--sep); }
.conversion-track i { height: 100%; display: block; border-radius: inherit; background: var(--green); }

.landing-panel { margin-bottom: 14px; }
.landing-header { align-items: flex-end; }
.landing-header p { max-width: 430px; margin: 0; color: var(--text-3); font-size: 12px; line-height: 1.7; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 13px 12px; text-align: right; }
th { color: var(--text-3); border-bottom: 1px solid var(--sep); font-size: 11px; font-weight: 600; }
td { border-top: 1px solid var(--sep-soft); font-variant-numeric: tabular-nums; }
tbody tr:first-child td { border-top: 0; }
th:first-child, td:first-child { width: 64%; text-align: left; }
td:first-child { font-family: var(--mono); font-size: 12px; color: var(--text-2); }
.empty-cell { padding: 32px; text-align: center !important; color: var(--text-3); font-family: var(--sans) !important; }

.empty-state { color: var(--text-3); text-align: center; line-height: 1.7; }
.empty-state.compact { padding: 34px 15px; font-size: 12px; }
.measurement-note { max-width: 860px; margin: 0; color: var(--text-3); font-size: 11px; line-height: 1.7; }

.modal {
  width: min(620px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  padding: 0;
  border: 0;
  border-radius: 18px;
  background: var(--card);
  color: var(--text);
  box-shadow: var(--shadow-float);
  overflow: auto;
}

.modal::backdrop { background: rgba(0, 0, 0, 0.32); backdrop-filter: blur(6px); }
.modal > form,
.modal > div { position: relative; padding: 40px; overflow: hidden; }
.small-modal { width: min(430px, calc(100vw - 32px)); }
.modal-number { display: none; }
.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.06);
  color: var(--text-2);
  font-size: 14px;
  cursor: pointer;
  z-index: 1;
  transition: background 140ms ease;
}
.modal-close:hover { background: rgba(0, 0, 0, 0.1); }
.modal h2 { position: relative; margin: 0 0 8px; font-size: 26px; font-weight: 700; letter-spacing: -0.02em; }
.modal-description { position: relative; margin: 0 0 26px; color: var(--text-2); font-size: 13px; line-height: 1.7; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 17px; margin-bottom: 24px; }
.field { display: grid; gap: 7px; margin-bottom: 20px; }
.form-grid .field { margin-bottom: 0; }
.field-wide { grid-column: 1 / -1; }
.field span,
.code-field span { font-size: 12px; font-weight: 600; }
.field input,
.code-field textarea {
  width: 100%;
  border: 1px solid var(--stroke);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
}
.field input { height: 44px; padding: 0 13px; }
.field small { color: var(--text-3); font-size: 10px; line-height: 1.6; }
.code-field { display: grid; gap: 8px; }
.code-field textarea { min-height: 108px; padding: 14px; resize: vertical; background: #f5f5f7; border-color: transparent; font-family: var(--mono); font-size: 11px; line-height: 1.6; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.install-help { margin-top: 25px; padding: 17px 18px; border-radius: 12px; background: #f5f5f7; }
.install-help strong { font-size: 12px; }
.install-help p { margin: 6px 0 0; color: var(--text-2); font-size: 11px; line-height: 1.7; }
.install-help code { padding: 2px 6px; background: #fff; border-radius: 5px; font-family: var(--mono); font-size: 10px; }

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  max-width: min(390px, calc(100vw - 48px));
  padding: 13px 18px;
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  color: var(--text);
  border: 1px solid rgba(0, 0, 0, 0.06);
  box-shadow: 0 10px 36px rgba(0, 0, 0, 0.16);
  font-size: 13px;
  font-weight: 500;
}

@media (max-width: 1080px) {
  .app-shell { grid-template-columns: 222px minmax(0, 1fr); }
  .sidebar { width: 222px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .topbar-actions { justify-content: flex-start; }
  .signal-rail { grid-template-columns: auto auto 1fr auto 1fr auto; }
  .signal-label { grid-column: 1 / -1; }
  .rail-actions { grid-column: 1 / -1; margin-left: 0; }
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; max-height: none; padding: 20px 16px; }
  .brand { padding-bottom: 18px; }
  .site-list { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .sidebar-footer { display: none; }
  .main-content { padding: 24px 16px 40px; }
  .topbar-actions { width: 100%; }
  .date-control { flex: 1; }
  .date-control input { width: 100%; }
  .secondary-button { flex: 1; }
  .signal-rail { grid-template-columns: 1fr; gap: 10px; }
  .signal-line { width: 1px; height: 14px; margin-left: 8px; background: var(--sep); }
  .rail-actions { flex-direction: column; }
  .metric-grid { grid-template-columns: 1fr; }
  .metric-card { min-height: 150px; }
  .landing-header { align-items: flex-start; flex-direction: column; }
  .modal > form,
  .modal > div { padding: 32px 22px; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: auto; }
  .modal-actions { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
