*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.optional-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--gray-100);
  color: var(--gray-600);
  border-radius: 4px;
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: middle;
}

:root {
  --blue: #4f7df3;
  --blue-dark: #3563d4;
  --blue-light: #eef2fd;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-400: #9ca3af;
  --gray-600: #4b5563;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

html { font-size: 15px; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
}

.app { display: flex; flex-direction: column; min-height: 100vh; }

.header {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 24px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 1rem;
  color: var(--gray-900);
}
.badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--blue);
  background: var(--blue-light);
  padding: 3px 10px;
  border-radius: 99px;
}

.main {
  flex: 1;
  max-width: 1100px;
  margin: 0 auto;
  width: 100%;
  padding: 32px 24px 64px;
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 720px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.card-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--gray-900);
  display: flex;
  align-items: center;
  gap: 10px;
}
.step {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
  font-size: .8rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.card-desc {
  font-size: .88rem;
  color: var(--gray-600);
  margin-top: -8px;
}

.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--gray-700, #374151);
}
input[type="text"],
input[type="url"],
input[type="file"] {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-200);
  border-radius: 7px;
  font-size: .9rem;
  color: var(--gray-800);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
input[type="text"]:focus,
input[type="url"]:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(79,125,243,.12);
}
input[type="file"] { padding: 6px 10px; cursor: pointer; }
.hint { font-size: .76rem; color: var(--gray-400); margin-top: 2px; }

.radio-group { display: flex; gap: 18px; }
.radio-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .88rem;
  cursor: pointer;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .88rem;
  cursor: pointer;
}

.btn {
  padding: 10px 20px;
  border-radius: 7px;
  font-size: .9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background .15s, opacity .15s, transform .1s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--blue); color: #fff; }
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }
.btn-small {
  padding: 6px 14px;
  font-size: .82rem;
  background: var(--blue-light);
  color: var(--blue);
  white-space: nowrap;
}
.btn-small:hover { background: #dde8fb; }

.status-box {
  padding: 12px 14px;
  border-radius: 7px;
  font-size: .88rem;
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.5;
}
.status-running { background: var(--blue-light); color: var(--blue-dark); flex-direction: column; align-items: flex-start; }
.status-done { background: #f0fdf4; color: #166534; }
.status-error { background: #fef2f2; color: #991b1b; }
.status-cancelled { background: #fffbeb; color: #92400e; }
.hidden { display: none !important; }

.progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  margin-top: 8px;
}
.progress-bar {
  width: 100%;
  height: 6px;
  background: rgba(79,125,243,.2);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--blue);
  border-radius: 99px;
  transition: width .4s ease;
}
.progress-label {
  font-size: .78rem;
  color: var(--blue-dark);
  opacity: .8;
}

.btn-cancel {
  background: #fff;
  color: var(--gray-600);
  border: 1px solid var(--gray-200);
  border-radius: 7px;
  padding: 8px 16px;
  font-size: .88rem;
  font-weight: 500;
  cursor: pointer;
  margin-left: 8px;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-cancel:hover { background: #fef2f2; border-color: #fca5a5; color: #991b1b; }
.btn-cancel:disabled { opacity: .6; cursor: not-allowed; }

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: .87rem;
  margin-bottom: 20px;
  line-height: 1.5;
}
.alert code { font-family: monospace; font-size: .84rem; }
.alert-warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alert-info { background: var(--blue-light); border: 1px solid #bfdbfe; color: #1e40af; }

.sheet-link {
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
  margin-left: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}

.results {
  border-top: 1px solid var(--gray-200);
  padding-top: 20px;
  margin-top: 4px;
}
.results-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
}
.results-header h3 {
  font-size: .95rem;
  font-weight: 700;
  color: var(--gray-900);
}
.count {
  font-size: .78rem;
  font-weight: 600;
  color: var(--blue);
  background: var(--blue-light);
  padding: 2px 8px;
  border-radius: 99px;
  margin-left: 6px;
}

.rec-list { display: flex; flex-direction: column; gap: 10px; }
.rec-card {
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  overflow: hidden;
}
.rec-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--gray-50);
  gap: 12px;
}
.rec-pages {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  font-size: .8rem;
  overflow: hidden;
}
.rec-source, .rec-target {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rec-source a, .rec-target a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
}
.rec-source a:hover, .rec-target a:hover { text-decoration: underline; }
.rec-arrow { color: var(--gray-400); flex-shrink: 0; }
.rec-score {
  flex-shrink: 0;
  font-size: .78rem;
  font-weight: 700;
  color: var(--gray-600);
  background: var(--gray-200);
  padding: 2px 8px;
  border-radius: 99px;
}
.rec-body { padding: 10px 14px; display: flex; flex-direction: column; gap: 4px; }
.rec-meta { font-size: .82rem; color: var(--gray-600); }
.rec-meta em { color: var(--gray-800); font-style: italic; }
.rec-notes { color: var(--gray-400); font-size: .78rem; }
.rec-label {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--gray-400);
  margin-right: 4px;
}

/* Full-site inbound: group recs by target page */
.rec-group {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 14px 14px 6px;
  margin-bottom: 20px;
  background: #fafafa;
}
.rec-group .already-linking-box {
  margin-bottom: 12px;
}
.rec-group .rec-card {
  margin-bottom: 10px;
}

/* Already-linking summary box */
.already-linking-box {
  background: #f0fdf4;
  border: 1px solid #86efac;
  border-radius: 8px;
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: .85rem;
  color: #166534;
}
.already-linking-summary {
  display: flex;
  align-items: flex-start;
  gap: 7px;
}
.already-linking-toggle {
  margin-left: auto;
  flex-shrink: 0;
  background: none;
  border: 1px solid #86efac;
  border-radius: 5px;
  color: #166534;
  font-size: .75rem;
  font-weight: 600;
  padding: 1px 8px;
  cursor: pointer;
  line-height: 1.6;
}
.already-linking-toggle:hover { background: #dcfce7; }
.already-linking-list {
  margin-top: 8px;
  padding-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.already-linking-list li { font-size: .8rem; }
.already-linking-list a { color: #166534; word-break: break-all; }
.already-linking-list a:hover { text-decoration: underline; }

/* Google connect bar */
.google-connect-bar {
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 20px;
}
.google-connect-bar.connected {
  border-color: #34a853;
  background: #f0fdf4;
}
.google-connect-info {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  font-size: .875rem;
}
.hint-text { color: var(--gray-600); }
.hint-text code { font-size: .8rem; background: var(--gray-100); padding: 1px 5px; border-radius: 4px; }
.btn-google {
  background: #4285f4;
  color: #fff;
  border: none;
}
.btn-google:hover { background: #3070e0; }
.btn-outline {
  background: transparent;
  border: 1px solid var(--gray-200);
  color: var(--gray-600);
}
.btn-outline:hover { background: var(--gray-100); }
.alert-ok {
  background: #f0fdf4;
  border: 1px solid #86efac;
  color: #166534;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: .875rem;
  margin-bottom: 14px;
}

/* Priority rank + score (Part 6B UI) */
.rec-rank {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--blue-light);
  color: var(--blue-dark);
  font-size: .8rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  margin-right: 10px;
}
.rec-score { position: relative; display: inline-flex; align-items: center; gap: 6px; }
.pri-help-btn {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--gray-400);
  background: none;
  color: var(--gray-600);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.pri-help-btn:hover { background: var(--gray-100); }
.pri-tooltip {
  position: absolute;
  top: 130%;
  right: 0;
  z-index: 20;
  width: 280px;
  background: #fff;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 10px 12px;
  font-size: .78rem;
  font-weight: 400;
  color: var(--gray-600);
  text-align: left;
  white-space: normal;
  line-height: 1.5;
}
