:root {
  --bg: #ffffff;
  --panel: #ffffff;
  --ink: #111111;
  --muted: #6b7280;
  --line: #e5e7eb;
  --accent: #9b1c2c;
  --accent-hover: #7f1624;
  --danger: #b42318;
  --chip: #f3f4f6;
  --radius: 4px;
  font-family: "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { max-width: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.hidden { display: none !important; }
.view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}
.brand {
  margin: 0;
  font-weight: 700;
  font-size: 15px;
}
.product {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.session-email {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.site-footer {
  margin-top: auto;
  padding: 20px 16px 28px;
  text-align: center;
  border-top: 1px solid var(--line);
}
.site-footer p {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.login-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.login-card {
  width: min(420px, 100%);
}
.login-card h1 {
  margin: 0 0 8px;
  font-size: 28px;
}
.login-card .muted { margin: 0 0 24px; }
.login-card label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 6px;
}
.login-card input {
  width: 100%;
  margin-bottom: 16px;
}
.login-card button { width: 100%; }

.tabs {
  display: flex;
  justify-content: center;
  align-items: stretch;
  gap: 0;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}
.tab {
  position: relative;
  flex: 0 0 8.5rem;
  width: 8.5rem;
  background: transparent;
  color: var(--muted);
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 12px 8px;
  font-weight: 600;
  font-size: 14px;
  text-align: center;
  white-space: nowrap;
}
.tab:not(:first-child)::before {
  content: "｜";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translate(-50%, -50%);
  color: var(--muted);
  font-weight: 400;
  font-size: 13px;
  pointer-events: none;
}
.tab:hover { background: #fafafa; color: var(--ink); }
.tab.active {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.layout {
  width: min(1100px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
  flex: 1;
}
.tab-panel h1 { margin: 0 0 8px; font-size: 24px; }
.tab-panel h2 { margin: 24px 0 8px; font-size: 18px; }
.tab-panel h3 { margin: 20px 0 8px; font-size: 15px; }
.tab-panel h4 { margin: 16px 0 8px; font-size: 13px; color: var(--muted); }

.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 1.2em; }

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 6px;
}

input[type="password"],
input[type="email"],
input[type="url"],
input[type="text"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  font: inherit;
  color: var(--ink);
  background: #fff;
}
textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

button {
  border: 0;
  border-radius: var(--radius);
  padding: 12px 16px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 600;
}
button.ghost:hover { background: #fafafa; }
button.primary { margin-top: 12px; }
.status-actions { margin-top: 12px; }
.status-actions .primary { margin-top: 0; }

.seg {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.seg-btn {
  background: #fff;
  color: var(--ink);
  border: 0;
  border-radius: 0;
  font-weight: 600;
  padding: 10px 14px;
}
.seg-btn + .seg-btn { border-left: 1px solid var(--line); }
.seg-btn:hover { background: #fafafa; }
.seg-btn.active {
  background: var(--accent);
  color: #fff;
}
.seg-btn.active:hover { background: var(--accent-hover); }
.seg-equal .seg-btn {
  flex: 1 1 0;
  min-width: 4.5rem;
  text-align: center;
}

.kw-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 16px 0;
}
.kw-card-list { display: grid; gap: 14px; margin-top: 12px; }
.kw-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  background: #fff;
  break-inside: avoid;
}
.kw-card h2 { margin: 0 0 8px; font-size: 16px; }
.kw-card .kw-meta { margin: 0 0 10px; font-size: 13px; color: var(--muted); }
.kw-card dl {
  display: grid;
  grid-template-columns: 7.5rem minmax(0, 1fr);
  gap: 6px 10px;
  margin: 0 0 12px;
  font-size: 13px;
}
.kw-card dt { color: var(--muted); font-weight: 600; }
.kw-card dd { margin: 0; }
.kw-print-header { display: none; }

@media print {
  body.printing-kw .site-header,
  body.printing-kw .tabs,
  body.printing-kw .site-footer,
  body.printing-kw .kw-toolbar,
  body.printing-kw .progress-overlay,
  body.printing-kw .status-actions {
    display: none !important;
  }
  body.printing-kw .tab-panel { display: none !important; }
  body.printing-kw #tab-keywords.tab-panel {
    display: block !important;
  }
  body.printing-kw #kw-empty { display: none !important; }
  body.printing-kw .kw-print-header {
    display: block !important;
    margin-bottom: 16px;
  }
  body.printing-kw .kw-card .kw-actions { display: none !important; }
  body.printing-kw .layout {
    width: auto;
    margin: 0;
    padding: 0;
  }
}

.eyebrow {
  letter-spacing: 0.04em;
  font-size: 12px;
  color: var(--accent);
  margin: 0 0 8px;
  font-weight: 700;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 20px 22px;
  margin-top: 16px;
  overflow-wrap: anywhere;
}

.row { display: flex; gap: 10px; align-items: center; min-width: 0; }
.row input { flex: 1; min-width: 0; }
.row.tight { gap: 8px; flex-wrap: wrap; }
.row-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.scores {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 16px 0;
}
.scores-4 { grid-template-columns: repeat(4, 1fr); }
.scores-6 { grid-template-columns: repeat(3, 1fr); }
@media (min-width: 900px) {
  .scores-6 { grid-template-columns: repeat(6, 1fr); }
}
.score-card {
  background: var(--chip);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  text-align: center;
}
.score-card span { display: block; color: var(--muted); font-size: 12px; }
.score-card strong { font-size: 28px; }
.score-card strong.sm { font-size: 18px; }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.table-wrap { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  border-bottom: 1px solid var(--line);
  padding: 6px 8px;
  text-align: left;
}
th { color: var(--muted); font-weight: 600; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.aio-score-secondary { margin-top: 8px; }
.aio-toolbar {
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.aio-asof {
  margin: 0 0 0 auto;
  font-size: 18px;
  font-weight: 700;
  color: var(--ink);
}
.aio-subnav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 0 0 16px;
  padding: 10px 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.aio-subnav a {
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
}
.aio-subnav a:hover { color: var(--ink); }
.aio-sec-title {
  scroll-margin-top: 48px;
  margin: 20px 0 10px;
  font-size: 18px;
}
.aio-kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 8px 0 12px;
}
@media (max-width: 720px) {
  .aio-kpi-grid { grid-template-columns: 1fr; }
}
.aio-kpi-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
  background: var(--chip);
}
.aio-kpi-panel h2,
.aio-kpi-panel h3 {
  margin: 0 0 10px;
  font-size: 15px;
}
.aio-kpi-overview { border-top: 3px solid var(--accent); }
.aio-kpi-mode { border-top: 3px solid #2563eb; }
.aio-kpi-main-label {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}
.aio-kpi-main {
  margin: 2px 0 4px;
  font-size: 32px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}
.aio-delta {
  margin: 0 0 12px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}
.aio-delta.sm {
  margin: 2px 0 0;
  font-size: 12px;
}
.aio-delta.up { color: #1a7f4b; }
.aio-delta.down { color: #9a3412; }
.aio-delta.flat { color: var(--muted); }
.aio-kpi-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.aio-kpi-row span {
  display: block;
  font-size: 12px;
  color: var(--muted);
}
.aio-kpi-row strong {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}
.aio-kpi-totals {
  margin: 8px 0 12px;
  font-size: 13px;
}
.aio-kpi-totals strong {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
.aio-count {
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
.aio-other-pf,
.aio-monthly-details {
  margin: 16px 0 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 14px;
  background: var(--chip);
}
.aio-other-pf summary,
.aio-monthly-details summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
}
.aio-chart-title {
  margin: 16px 0 6px;
  font-size: 14px;
  font-weight: 600;
}
.aio-chart {
  margin: 0 0 16px;
  min-height: 120px;
}
.aio-line-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: baseline;
  margin-bottom: 8px;
  font-size: 12px;
}
.aio-leg-latest {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}
.aio-leg::before {
  content: "";
  display: inline-block;
  width: 14px;
  height: 3px;
  margin-right: 6px;
  vertical-align: middle;
  border-radius: 1px;
}
.aio-leg-overview::before { background: var(--accent); }
.aio-leg-mode::before { background: #2563eb; }
.aio-line-svg {
  width: 100%;
  height: auto;
  display: block;
}
.aio-line {
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}
.aio-line-overview { stroke: var(--accent); }
.aio-line-mode { stroke: #2563eb; }
.aio-dot { stroke: #fff; stroke-width: 1.5; }
.aio-dot-overview { fill: var(--accent); }
.aio-dot-mode { fill: #2563eb; }
.aio-grid {
  stroke: var(--line);
  stroke-width: 1;
}
.aio-axis {
  fill: var(--muted);
  font-size: 11px;
}
.aio-axis-x-sub {
  font-size: 9px;
  fill: var(--muted);
}
.aio-val-label {
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}
.aio-val-overview { fill: var(--accent); }
.aio-val-mode { fill: #2563eb; }
.aio-val-label-latest {
  font-size: 11px;
  font-weight: 700;
}
.aio-url-cell {
  font-size: 12px;
  max-width: 220px;
}
.aio-short-url {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  word-break: break-all;
}
.aio-pf-chip {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}
.aio-pf-chip.overview {
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: color-mix(in srgb, var(--accent) 75%, #000);
}
.aio-pf-chip.mode {
  background: color-mix(in srgb, #2563eb 14%, transparent);
  color: #1e40af;
}
.aio-pf-chip.other {
  background: color-mix(in srgb, var(--muted) 18%, transparent);
  color: var(--muted);
}
.aio-rewrite-btn {
  font-size: 12px;
  padding: 4px 8px;
  white-space: nowrap;
}
.aio-serp-note {
  margin: -4px 0 10px;
  font-size: 12px;
}

.meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.meta-grid p { margin: 0; font-size: 14px; line-height: 1.5; }

.bullets { margin: 0; padding-left: 18px; }
.bullets li { margin: 6px 0; font-size: 14px; }

.proposal-list { display: grid; gap: 10px; }
.proposal {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: start;
}
.proposal.high { border-color: #e8b4b8; background: #fff8f8; }
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--accent);
  margin-right: 6px;
  font-weight: 700;
}
.proposal .summary { font-weight: 700; margin: 0 0 8px; line-height: 1.45; }
.proposal .field-label {
  display: inline-block;
  min-width: 2.5em;
  margin-right: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.04em;
}
.proposal .proposal-problem,
.proposal .proposal-fix,
.proposal .rationale {
  margin: 0 0 6px;
  font-size: 13px;
  line-height: 1.55;
  color: var(--text);
}
.proposal .proposal-problem { color: #6b3a3d; }
.proposal .proposal-fix { color: #1f4d36; }
.proposal .rationale { color: var(--muted); }
.proposal-change {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 8px 0 6px;
}
.proposal-change .change-col {
  background: #f7f5f2;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}
.proposal-change .change-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  margin-bottom: 4px;
}
.proposal-change p {
  margin: 0;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}
.proposal .apply-note { margin: 6px 0 0; font-size: 12px; }
.proposal.manual { opacity: 0.92; border-style: dashed; }
.apply-legend { margin: 0 0 12px; font-size: 13px; line-height: 1.6; }
.badge.apply-body { background: #fde8ea; color: var(--accent); }
.badge.apply-cms { background: #e8eef8; color: #2f5f9e; }
.badge.apply-manual { background: #f5efe6; color: #8a5a12; }

body.preview-open {
  overflow: hidden !important;
}
.preview-actions { margin: 16px 0 4px; }
.preview-note { margin: 0 0 16px; font-size: 13px; }

.preview-overlay {
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  right: 0 !important;
  bottom: 0 !important;
  width: 100vw !important;
  height: 100vh !important;
  height: 100dvh !important;
  z-index: 2000;
  display: flex !important;
  flex-direction: column;
  background: #fff;
  margin: 0;
  padding: 0;
}
.preview-overlay.hidden {
  display: none !important;
}
.preview-overlay-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  flex: 0 0 auto;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--panel, #fff);
}
.preview-overlay-bar h2 {
  margin: 0;
  font-size: 16px;
}
.article-preview-frame {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

@media (max-width: 720px) {
  .proposal-change { grid-template-columns: 1fr; }
}

.steps { font-size: 14px; color: var(--muted); padding-left: 20px; }

code {
  background: var(--chip);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  overflow-wrap: anywhere;
  word-break: break-word;
}

a { color: var(--accent); }

.users-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: end;
  margin: 16px 0;
}
.users-form button { height: 44px; }
.account-form {
  max-width: 420px;
  margin: 16px 0;
}
.account-form label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 6px;
}
.account-form input {
  width: 100%;
  margin-bottom: 16px;
}
.account-form button { width: 100%; }
.users-table-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.users-table-actions button { padding: 8px 12px; font-size: 12px; }

.history-list {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}
.history-list.tall { max-height: none; }
.history-admin-tools {
  display: grid;
  gap: 12px;
  margin: 12px 0 4px;
}
.history-member-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
}
.history-member-filter label { margin: 0; }
.history-member-filter select { width: auto; min-width: 16rem; padding: 8px 12px; }
#history-member-summary tbody tr { cursor: pointer; }
#history-member-summary tbody tr:hover { background: #fafafa; }
#history-member-summary tbody tr.active { background: #f8eef0; }
.history-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}
.history-item:hover { background: #fafafa; }
.history-item.active { border-color: var(--accent); }
.history-item .history-open {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px 12px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 8px 10px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.history-item .history-title { margin: 0; font-size: 14px; font-weight: 700; }
.history-item .history-meta {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
}
.history-item .stage-badge {
  justify-self: end;
  font-size: 11px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--accent);
  white-space: nowrap;
}
.history-item-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}
.history-item .history-reanalyze,
.history-item .history-delete {
  padding: 8px 12px;
  font-size: 12px;
  white-space: nowrap;
}
.history-item .history-delete {
  color: var(--danger);
  border-color: #f0c9c5;
}
.work-header-actions { margin-top: 12px; }
.history-item .stage-badge.applied {
  background: var(--accent);
  color: #fff;
}

.progress-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(17, 17, 17, 0.4);
}
.progress-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px 24px;
  text-align: center;
}
.progress-title { margin: 0 0 16px; font-size: 18px; font-weight: 700; }
.progress-track {
  position: relative;
  height: 8px;
  border-radius: 999px;
  background: #f3f4f6;
  overflow: hidden;
  margin-bottom: 14px;
}
.progress-bar-indeterminate {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 40%;
  border-radius: 999px;
  background: var(--accent);
  animation: progress-slide 1.2s ease-in-out infinite;
}
@keyframes progress-slide {
  0% { transform: translateX(-120%); }
  100% { transform: translateX(320%); }
}
.progress-phase { margin: 0 0 6px; color: var(--muted); font-size: 14px; }
.progress-elapsed { margin: 0; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

@media (max-width: 720px) {
  .site-header, .tabs { padding-left: 16px; padding-right: 16px; }
  .layout { width: 100%; padding: 20px 16px 32px; }
  .scores, .meta-grid, .split, .scores-4, .scores-6 { grid-template-columns: 1fr; }
  .row { flex-direction: column; align-items: stretch; }
  .users-form { grid-template-columns: 1fr; }
  .history-item { grid-template-columns: 1fr; }
  .history-item .history-open { grid-template-columns: 1fr; }
}
