:root {
  --bg: #f7f8fb;
  --panel: #fff;
  --text: #18202c;
  --muted: #667085;
  --border: #e4e7ec;
  --primary: #315efb;
  --danger: #c52828;
  --warning: #9b5d00;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans JP", sans-serif;
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
}
a { color: inherit; }

.topbar {
  min-height: 64px;
  padding: 0 28px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand a { text-decoration: none; font-weight: 750; }
.brand span { font-size: 13px; color: var(--muted); font-weight: 500; }
.topbar nav { display: flex; gap: 20px; flex-wrap: wrap; }
.topbar nav a { text-decoration: none; color: var(--muted); font-size: 15px; }
.topbar nav a:hover { color: var(--text); }

.container { width: min(1380px, calc(100% - 32px)); margin: 32px auto 64px; }
.hero { padding: 72px 0; }
.narrow { max-width: 680px; margin: auto; }
.hero h1,
.page-header h1 { font-size: 34px; line-height: 1.25; margin: 8px 0 12px; }
.hero p,
.page-header p { color: var(--muted); line-height: 1.7; }
.eyebrow { font-size: 13px; color: var(--primary); font-weight: 750; letter-spacing: .06em; text-transform: uppercase; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.micro { font-size: 13px; color: var(--muted); margin-top: 5px; line-height: 1.45; }
.url { font-size: 13.5px; color: #667085; display: block; max-width: 680px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 5px; }
.inline-url { max-width: 420px; }
.query-link { font-size: 15.5px; font-weight: 700; text-decoration: none; }
.query-link:hover { text-decoration: underline; }

.button {
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  cursor: pointer;
  font: inherit;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.button.primary { background: var(--primary); color: white; }
.button.secondary { background: #eef2ff; color: #2748b8; }
.button.ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.button.large { padding: 14px 22px; margin-top: 16px; }
.button.small { padding: 8px 11px; font-size: 13px; }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 16px; padding: 22px; margin: 18px 0; }
.callout { background: #eef2ff; border-radius: 12px; padding: 18px; margin: 22px 0; }
.callout p { margin-bottom: 0; }
.page-header { margin-bottom: 22px; }
.page-header.split { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.page-header h1 { margin-bottom: 4px; }
.page-header p { margin: 0; }
.form-panel { max-width: 760px; }
.form-panel label,
.manual-pin label { display: block; margin-bottom: 20px; }
.form-panel label > span,
.manual-pin label > span,
.filter-bar label > span { display: block; font-size: 13px; font-weight: 700; margin-bottom: 7px; }
select,
input[type="text"],
input[type="number"] { width: 100%; border: 1px solid #d0d5dd; border-radius: 10px; padding: 11px 12px; background: #fff; font: inherit; }
.form-actions { display: flex; justify-content: flex-end; }

.flash { border-radius: 10px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; border: 1px solid var(--border); background: #fff; }
.flash.success { background: #ecfdf3; border-color: #abefc6; }
.flash.warning { background: #fffaeb; border-color: #fedf89; }
.flash.danger { background: #fef3f2; border-color: #fecdca; }
.flash.info { background: #eff8ff; border-color: #b2ddff; }

.sync-status,
.period-note { font-size: 13px; color: var(--muted); margin: 8px 0 14px; }
.toolbar { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin: 18px 0 6px; }
.tabs { display: flex; gap: 6px; }
.tab { padding: 9px 13px; border-radius: 9px; text-decoration: none; color: var(--muted); font-size: 14px; }
.tab.active { background: #fff; border: 1px solid var(--border); color: var(--text); font-weight: 700; }
.tab.active.danger-tab { color: var(--danger); }

.filter-bar {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  padding: 14px 16px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  margin: 12px 0 16px;
}
.filter-bar label { min-width: 180px; }
.filter-bar input[type="number"] { width: 150px; }

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 16px 0; }
.metric { background: #fff; border: 1px solid var(--border); border-radius: 14px; padding: 18px; }
.metric span { display: block; color: var(--muted); font-size: 14px; }
.metric strong { display: block; font-size: 30px; margin-top: 4px; }

.table-panel { padding: 0; overflow: hidden; }
.table-header { padding: 20px 22px; border-bottom: 1px solid var(--border); }
.table-header h2,
.section-title h2 { margin: 0; font-size: 20px; }
.table-header p,
.section-title p { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th { background: #fafafa; color: #667085; text-align: left; font-size: 13px; font-weight: 700; padding: 12px 14px; white-space: nowrap; }
td { border-top: 1px solid #f0f1f3; padding: 14px; vertical-align: top; line-height: 1.45; }
tr:hover td { background: #fcfcfd; }
.query-cell { min-width: 340px; }
.arrow { color: #98a2b3; margin: 0 5px; }
.score { display: inline-flex; min-width: 40px; height: 34px; align-items: center; justify-content: center; border-radius: 9px; background: #f2f4f7; font-size: 15px; font-weight: 750; }
.badge { display: inline-flex; border-radius: 999px; padding: 6px 9px; font-size: 12.5px; font-weight: 750; white-space: nowrap; }
.badge.danger { background: #fef3f2; color: #b42318; }
.badge.warning { background: #fffaeb; color: #b54708; }
.badge.attention { background: #fff4ed; color: #b93815; }
.badge.watch { background: #eef4ff; color: #3538cd; }
.badge.info { background: #eff8ff; color: #175cd3; }
.badge.muted { background: #f2f4f7; color: #475467; }
.empty-cell { text-align: center; color: var(--muted); padding: 36px; }
.empty { text-align: center; padding: 48px; }

.chart-box { height: 360px; margin-top: 20px; }
.tracker-chart { height: 420px; }
.bubble-chart-box { height: 600px; }
.pinned { display: flex; gap: 12px; align-items: center; background: #eef2ff; border-radius: 10px; padding: 12px 14px; margin: 16px 0; }
.pinned span { color: var(--muted); font-size: 13px; }
.candidate-list { border-top: 1px solid var(--border); margin-top: 16px; }
.candidate { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.manual-pin { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: end; margin-top: 20px; }
.manual-pin label { margin: 0; }
.unpin-form { margin-top: 10px; }
.compact-table { max-height: 420px; }
.split-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.tracker-header { display: flex; justify-content: space-between; gap: 16px; align-items: center; }
.table-search { max-width: 300px; }
.selected-row td { background: #f5f7ff; }
.note-box { font-size: 13px; color: var(--muted); padding: 12px 14px; border-left: 3px solid #d0d5dd; margin: 12px 0; }

@media (max-width: 900px) {
  .metrics { grid-template-columns: repeat(2, 1fr); }
  .page-header.split { flex-direction: column; }
  .toolbar { align-items: flex-start; flex-direction: column; }
  .topbar { padding: 10px 16px; align-items: flex-start; gap: 10px; flex-direction: column; }
  .topbar nav { gap: 12px; }
  .container { width: min(100% - 20px, 1380px); margin-top: 22px; }
  .hero h1,
  .page-header h1 { font-size: 28px; }
  .manual-pin { grid-template-columns: 1fr; }
  .candidate { align-items: flex-start; flex-direction: column; }
  .split-title,
  .tracker-header { flex-direction: column; align-items: stretch; }
  .table-search { max-width: none; }
  .bubble-chart-box { height: 480px; }
}

/* v0.3: dashboard readability and sticky table headings */
table { font-size: 15.5px; }
th { font-size: 14px; padding: 13px 14px; }
td { padding: 15px 14px; }
.dashboard-table-wrap {
  max-height: calc(100vh - 150px);
  overflow: auto;
}
.dashboard-table-wrap thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: #f8fafc;
  box-shadow: inset 0 -1px 0 var(--border);
}

/* v0.3: visual daily rank tracker */
.tracker-search-form {
  display: flex;
  gap: 8px;
  width: min(430px, 100%);
}
.tracker-search-form input { flex: 1; min-width: 0; }
.tracker-summary {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  color: var(--muted);
  margin: 4px 0 14px;
}
.tracker-summary strong { color: var(--text); }
.tracker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 14px;
}
.rank-card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  min-width: 0;
}
.rank-card:hover { border-color: #c9d2e3; }
.rank-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.rank-card-title-wrap { min-width: 0; }
.rank-card-title {
  display: block;
  color: var(--text);
  text-decoration: none;
  font-weight: 750;
  font-size: 16px;
  line-height: 1.45;
  margin-bottom: 7px;
}
.rank-card-title:hover { text-decoration: underline; }
.rank-now { text-align: right; flex: 0 0 auto; }
.rank-now span { display: block; color: var(--muted); font-size: 12px; }
.rank-now strong { font-size: 25px; line-height: 1.1; }
.spark-link { display: block; margin: 12px 0 8px; text-decoration: none; }
.spark-chart {
  width: 100%;
  height: auto;
  aspect-ratio: 13 / 6;
  border-radius: 8px;
  background: #fbfcfe;
}
.spark-grid-line { stroke: #e7eaf0; stroke-width: 1; vector-effect: non-scaling-stroke; }
.spark-line {
  fill: none;
  stroke: var(--primary);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
}
.spark-label { fill: #98a2b3; font-size: 10px; }
.rank-card-metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 10px 0 12px;
  border-top: 1px solid #f0f1f3;
  border-bottom: 1px solid #f0f1f3;
}
.rank-card-metrics span { display: block; color: var(--muted); font-size: 11.5px; }
.rank-card-metrics strong { display: block; margin-top: 2px; font-size: 14px; }
.rank-card-footer { margin-top: 10px; }
.rank-card-footer .url { max-width: none; }
.card-action {
  display: inline-block;
  margin-top: 9px;
  color: #315efb;
  text-decoration: none;
  font-size: 13px;
  font-weight: 700;
}
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 14px;
  margin: 24px 0;
}
.pagination span { color: var(--muted); }

/* v0.3: bubble chart closer to the Search Central reference */
.bubble-panel { padding-bottom: 12px; }
.bubble-chart-box { height: 720px; }

@media (max-width: 900px) {
  .dashboard-table-wrap { max-height: calc(100vh - 125px); }
  .tracker-search-form { width: 100%; }
  .tracker-grid { grid-template-columns: 1fr; }
  .bubble-chart-box { height: 540px; }
}

/* v0.4: unified change table, visual trends, and sorting */
.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.sort-link {
  color: inherit;
  text-decoration: none;
  font-weight: 750;
}
.sort-link:hover,
.sort-link.active { color: var(--text); }
.metric-change { white-space: nowrap; }
.trend {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-left: 5px;
  font-size: 16px;
  font-weight: 850;
  line-height: 1;
}
.trend.down { color: #d92d20; }
.trend.up { color: #169b62; }
.trend.flat { color: #98a2b3; }
.direction-label {
  margin-top: 7px;
  font-size: 12px;
  font-weight: 750;
}
.direction-label.down { color: #d92d20; }
.direction-label.up { color: #169b62; }

/* v0.4: clearer period labels in tracker cards */
.rank-now span {
  line-height: 1.25;
  font-weight: 650;
}
.rank-card-period-note {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 700;
  margin: 3px 0 4px;
}
.rank-card-metrics span {
  line-height: 1.25;
  min-height: 28px;
}
.previous-rank-metric {
  border-left: 1px solid #eef0f3;
  padding-left: 8px;
}

/* v0.4: explain automatic main-keyword inference */
.candidate-help {
  margin-top: 16px;
  padding: 13px 15px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid var(--border);
  color: #344054;
}
.candidate-help strong { font-size: 15px; color: var(--text); }
.candidate-help p {
  margin: 5px 0 0;
  font-size: 14px;
  line-height: 1.6;
}
.candidate-info { min-width: 0; }
.candidate-query { font-size: 16px; color: var(--text); }
.candidate-score-line {
  margin-top: 7px;
  font-size: 14px;
  color: #475467;
  line-height: 1.5;
}
.candidate-score-line > strong {
  color: #1d2939;
  font-size: 15px;
}
.candidate-breakdown {
  margin-top: 4px;
  color: #667085;
  font-size: 13px;
  line-height: 1.5;
}

/* v0.4: bubble chart opportunity emphasis */
.bubble-summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 12px 0 16px;
}
.bubble-summary > div {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 13px 15px;
}
.bubble-summary span {
  display: block;
  color: var(--muted);
  font-size: 12.5px;
}
.bubble-summary strong {
  display: block;
  margin-top: 3px;
  font-size: 21px;
}
.bubble-summary .opportunity-stat {
  background: #f0fdf4;
  border-color: #bbf7d0;
}
.bubble-summary .opportunity-stat strong { color: #137333; }

@media (max-width: 900px) {
  .table-header { align-items: flex-start; flex-direction: column; }
  .bubble-summary { grid-template-columns: 1fr; }
}


/* v0.5: clearer event semantics and compact explanations */
.metrics-three { grid-template-columns: repeat(3, 1fr); }
.panel-compact {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  margin: 12px 0 16px;
  overflow: hidden;
}
.logic-accordion summary {
  cursor: pointer;
  list-style: none;
  padding: 15px 18px;
  font-weight: 750;
  color: var(--text);
}
.logic-accordion summary::-webkit-details-marker { display: none; }
.logic-accordion summary::after {
  content: '＋';
  float: right;
  color: var(--muted);
}
.logic-accordion[open] summary::after { content: '−'; }
.logic-accordion[open] summary { border-bottom: 1px solid var(--border); }
.logic-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 22px;
  padding: 18px;
}
.logic-grid strong { display: block; margin-bottom: 5px; }
.logic-grid p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.65; }
.event-chip {
  margin-top: 7px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.event-chip.rank-down { color: #d92d20; }
.event-chip.rank-up { color: #169b62; }
.event-chip.click-drop { color: #b54708; }
.event-chip.url-change { color: #175cd3; }
.event-chip.data-missing { color: #667085; }
.candidate-simple-meta {
  margin-top: 5px;
  color: #667085;
  font-size: 13.5px;
}
.detail-data-table { max-height: 360px; }

@media (max-width: 900px) {
  .metrics-three { grid-template-columns: 1fr; }
  .logic-grid { grid-template-columns: 1fr; }
}


/* v0.7: make missing GSC days visible in tracker charts */
.spark-point {
  fill: #315efb;
  stroke: #ffffff;
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
}
.spark-point:hover { r: 3.5px; }
.spark-date-label {
  fill: #98a2b3;
  font-size: 9px;
}
.chart-footnote {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

/* v0.8: tracker period switch and bubble opportunity list */
.tracker-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}
.period-switch {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}
.opportunity-panel { margin-top: 18px; }
.opportunity-table-wrap { overflow-x: auto; }
.opportunity-table { min-width: 920px; }
.opportunity-table th,
.opportunity-table td { vertical-align: top; }
.opportunity-table td:nth-child(n+2),
.opportunity-table th:nth-child(n+2) { white-space: nowrap; }
.opportunity-table strong { color: var(--text); }
@media (max-width: 760px) {
  .tracker-actions { width: 100%; justify-content: stretch; }
  .period-switch { width: 100%; }
  .period-switch .button { flex: 1; text-align: center; }
}

/* v0.9: sticky opportunity headers */
.opportunity-table-wrap {
  max-height: calc(100vh - 150px);
  overflow: auto;
}
.opportunity-table thead th {
  position: sticky;
  top: 0;
  z-index: 4;
  background: #f8fafc;
  box-shadow: inset 0 -1px 0 var(--border);
}

.saved-sites-list { display: grid; gap: 10px; }
.saved-site-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-top: 1px solid var(--border, #e5e7eb); }
.saved-site-row:first-child { border-top: 0; }
.saved-site-row div { min-width: 0; display: grid; gap: 3px; }
.saved-site-row span, .saved-site-row small { color: #667085; }

/* v1.1: sync guidance and low-access checker */
.sync-action {
  min-width: 290px;
  text-align: right;
}
.sync-help {
  max-width: 360px;
  margin: 8px 0 0 auto !important;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.55;
}
.sync-running {
  margin-top: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: #eff8ff;
  color: #175cd3;
  font-size: 13px;
  line-height: 1.5;
}
.button:disabled {
  opacity: .6;
  cursor: wait;
}
.low-access-actions {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.low-access-note { margin-top: 0; }
.low-access-note p { margin: 5px 0 0; }
.low-access-rules { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.warning-box {
  padding: 15px 17px;
  margin: 14px 0;
  border: 1px solid #fedf89;
  border-radius: 12px;
  background: #fffaeb;
}
.warning-box strong { display: block; margin-bottom: 4px; }
.warning-box p { margin: 0; color: #7a2e0e; line-height: 1.55; }
.low-access-filter { justify-content: flex-start; }
.low-access-filter .micro { align-self: center; margin-left: auto; }
.low-url {
  max-width: 520px;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  word-break: break-all;
}
.badge.low-status { background: #f2f4f7; color: #344054; }
.badge.status-削除候補 { background: #fef3f2; color: #b42318; }
.badge.status-noindex { background: #eef4ff; color: #3538cd; }
.badge.status-404整理,
.badge.status-canonical確認,
.badge.status-robots-txt確認,
.badge.status-クロールエラー,
.badge.status-取得エラー { background: #fffaeb; color: #b54708; }

@media (max-width: 900px) {
  .sync-action { text-align: left; min-width: 0; width: 100%; }
  .sync-help { margin-left: 0 !important; }
  .low-access-actions { justify-content: flex-start; width: 100%; }
  .low-access-rules { grid-template-columns: 1fr; }
  .low-access-filter .micro { margin-left: 0; width: 100%; }
}

/* v1.2: compact change table + background low-access jobs */
.dashboard-filter-bar {
  align-items: flex-end;
}

.compact-change-table table {
  min-width: 1320px;
}

.compact-change-table th,
.compact-change-table td {
  padding-top: 8px;
  padding-bottom: 8px;
}

.compact-change-table td {
  vertical-align: middle;
}

.reason-cell {
  min-width: 120px;
  white-space: nowrap;
}

.compact-query-cell {
  min-width: 190px;
  max-width: 260px;
}

.compact-query-cell .query-link {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.compact-url-cell {
  width: 250px;
  max-width: 250px;
}

.compact-url-cell .url {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.delta {
  display: inline-block;
  margin-left: 6px;
  font-size: 12.5px;
  font-weight: 800;
  white-space: nowrap;
}

.delta.up { color: #067647; }
.delta.down { color: #b42318; }
.delta.flat { color: #667085; }

.task-running-box {
  margin-top: 0;
  margin-bottom: 18px;
  border: 1px solid #b2ccff;
  background: #eff4ff;
}

.task-running-box p {
  margin: 5px 0 0;
}

/* v1.3: denser change table that fits a desktop viewport without hiding PV deltas */
.table-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.compact-change-table table {
  min-width: 1160px;
  table-layout: fixed;
}

.compact-change-table .col-judgment { width: 7%; }
.compact-change-table .col-reason { width: 13%; }
.compact-change-table .col-query { width: 20%; }
.compact-change-table .col-url { width: 18%; }
.compact-change-table .col-position { width: 14%; }
.compact-change-table .col-impression { width: 10%; }
.compact-change-table .col-click { width: 8%; }
.compact-change-table .col-pv { width: 10%; }

.compact-change-table th,
.compact-change-table td {
  padding-left: 10px;
  padding-right: 10px;
}

.reason-cell {
  min-width: 0;
  width: auto;
  font-size: 13.5px;
}

.compact-query-cell {
  min-width: 0;
  max-width: none;
}

.compact-url-cell {
  width: auto;
  max-width: none;
}

.compact-url-cell .url {
  max-width: 100%;
}

.compact-change-table .metric-change {
  overflow: visible;
  white-space: nowrap;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.compact-change-table .delta {
  margin-left: 4px;
}

@media (min-width: 1280px) {
  .compact-change-table {
    overflow-x: hidden;
  }
}

@media (max-width: 1279px) {
  .compact-change-table {
    overflow-x: auto;
  }
}
