:root {
  --bg: #f0f4f9;
  --surface: #ffffff;
  --surface2: #f8faff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-ring: #93c5fd;
  --accent-light: #eff6ff;
  --success: #059669;
  --success-light: #ecfdf5;
  --warn: #d97706;
  --warn-light: #fffbeb;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --radius: 12px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 24px rgba(0, 0, 0, 0.08);
  --font: "Inter", "SF Pro", "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", Consolas, monospace;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ===== HEADER ===== */
header {
  background: linear-gradient(135deg, #1e40af 0%, #2563eb 50%, #3b82f6 100%);
  color: white;
  padding: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-md);
}

header .header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
}

header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

header h1::before {
  content: "⚡";
  font-size: 1.2rem;
}

header .header-meta {
  font-size: 0.8rem;
  opacity: 0.75;
  margin-top: 0.1rem;
}

header .nav-links {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

header .nav-links a {
  color: rgba(255, 255, 255, 0.9);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.35rem 0.85rem;
  border-radius: 8px;
  transition: background var(--transition);
}

header .nav-links a:hover {
  background: rgba(255, 255, 255, 0.15);
  color: white;
}

header .header-name {
  font-size: 0.82rem;
  opacity: 0.7;
  padding: 0.35rem 0.65rem;
  border-left: 1px solid rgba(255, 255, 255, 0.2);
}

/* ===== LAYOUT ===== */
main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 4rem;
  display: grid;
  gap: 1.25rem;
}

/* ===== SECTION HEADER ===== */
.section-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}

.section-header .num {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  font-size: 0.8rem;
  font-weight: 700;
  flex-shrink: 0;
}

.section-header h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text);
  margin: 0;
}

/* ===== CARDS ===== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
  transition: box-shadow var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.card-header .icon {
  font-size: 1.2rem;
}

.card h2 {
  font-size: 1rem;
  font-weight: 700;
  margin: 0;
  color: var(--text);
}

/* ===== FORMS ===== */
label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

input[type="text"], input[type="url"], textarea, input[type="email"], input[type="password"], select {
  width: 100%;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.6rem 0.8rem;
  font-family: inherit;
  font-size: 0.9rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-ring);
}

textarea {
  min-height: 180px;
  resize: vertical;
  line-height: 1.6;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  margin-bottom: 1rem;
}

@media (max-width: 640px) {
  .form-row { grid-template-columns: 1fr; }
  main { padding: 1rem 1rem 3rem; }
}

/* ===== BUTTONS ===== */
button {
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.3rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background var(--transition), transform 0.1s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

button:hover { background: var(--accent-hover); }
button:active { transform: scale(0.97); }
button:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-success {
  background: var(--success);
}
.btn-success:hover { background: #047857; }

.btn-secondary {
  background: var(--surface2);
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-secondary:hover { background: var(--border); }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.btn-outline:hover { background: var(--accent-light); }

/* ===== HOW-IT-WORKS ===== */
.how-to { background: linear-gradient(135deg, var(--accent-light) 0%, white 100%); border-color: var(--accent-ring); }
.how-to ol { margin-left: 1.25rem; font-size: 0.9rem; line-height: 1.8; }
.how-to li { margin-bottom: 0.15rem; }
.how-to li strong { color: var(--accent); }

/* ===== SCORE DISPLAY ===== */
.score-ring {
  display: flex;
  align-items: center;
  gap: 2rem;
  flex-wrap: wrap;
  padding: 1.25rem;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 1rem;
}

.score-item { text-align: center; }

.score-item .meta {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.25rem;
}

.score-value {
  font-size: 2.5rem;
  font-weight: 800;
  line-height: 1;
  color: var(--accent);
}

.score-value.good { color: var(--success); }
.score-value.mid { color: var(--warn); }
.score-value.low { color: var(--danger); }

.score-value.target {
  font-size: 1.2rem;
  color: var(--success);
}

/* ===== CHIPS ===== */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
}

.chip {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface2);
  color: var(--muted);
  font-weight: 500;
}

.chip.match { 
  border-color: #a7f3d0; 
  background: var(--success-light); 
  color: #065f46;
  font-weight: 600;
}

.chip.miss { 
  border-color: #fecaca; 
  background: var(--danger-light); 
  color: #991b1b;
  font-weight: 500;
}

.chip.partial { 
  border-color: #fde68a; 
  background: var(--warn-light); 
  color: #92400e;
  font-weight: 500;
}

.subhead {
  font-size: 0.75rem;
  font-weight: 700;
  margin-bottom: 0.4rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ===== SUGGESTIONS ===== */
.suggestion {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.1rem;
  margin-bottom: 0.75rem;
  background: var(--surface);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.suggestion:hover {
  box-shadow: var(--shadow-sm);
}

.suggestion.accepted {
  border-color: var(--success);
  background: #f0fdf4;
}

.suggestion-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
}

.suggestion-header strong {
  font-size: 0.8rem;
  color: var(--accent);
}

.suggestion-header .company-tag {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 500;
}

.suggestion .original {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
  padding-left: 0.5rem;
  border-left: 2px solid var(--border);
  line-height: 1.5;
}

.suggestion textarea {
  min-height: 55px;
  margin-bottom: 0.5rem;
  background: var(--surface);
  font-size: 0.88rem;
}

.status-badge {
  font-size: 0.7rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-weight: 600;
  white-space: nowrap;
}

.status-badge.pending { 
  background: var(--accent-light); 
  color: var(--accent); 
}

.status-badge.accepted { 
  background: var(--success-light); 
  color: var(--success); 
}

.review-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 1.25rem 0 0.75rem;
  flex-wrap: wrap;
}

/* ===== RESCORE COMPARE ===== */
.score-compare {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-wrap: wrap;
  padding: 1rem;
  background: var(--bg);
  border-radius: 10px;
  border: 1px solid var(--border);
  margin: 1rem 0;
}

.score-compare .arrow {
  font-size: 1.3rem;
  color: var(--muted);
}

.delta {
  font-size: 1.3rem;
  font-weight: 700;
}
.delta.positive { color: var(--success); }
.delta.negative { color: var(--danger); }

.target-message {
  margin-top: 0.75rem;
  padding: 0.7rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.4;
}

.target-message.on_target {
  background: var(--success-light);
  border: 1px solid var(--success);
  color: #065f46;
}

.target-message.close {
  background: var(--warn-light);
  border: 1px solid var(--warn);
  color: #92400e;
}

.target-message.below {
  background: var(--danger-light);
  border: 1px solid var(--danger);
  color: #991b1b;
}

/* ===== DRAFT PREVIEW ===== */
.draft-preview {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
  font-size: 0.82rem;
  line-height: 1.6;
  white-space: pre-wrap;
  max-height: 500px;
  overflow-y: auto;
  font-family: var(--font);
}

/* ===== EXPORT ===== */
.export-gate {
  padding: 1rem;
  border-radius: 8px;
  background: var(--warn-light);
  border: 1.5px dashed var(--warn);
  color: #92400e;
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.export-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin: 1rem 0;
}

.download-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1rem;
}

.download-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  background: var(--accent);
  color: white;
  text-decoration: none;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  transition: background var(--transition);
}

.download-link:hover { 
  background: var(--accent-hover); 
  color: white;
}

/* ===== LOADING ===== */
.loading {
  display: none;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 0.6rem;
  padding-left: 0.25rem;
  animation: pulse 1.5s ease-in-out infinite;
}

.loading.visible { display: block; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ===== GRID ===== */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.25rem;
}

@media (max-width: 800px) {
  .grid-2 { grid-template-columns: 1fr; }
}

/* ===== IMPORT ROW ===== */
.import-row {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: center;
}

.import-row input[type="url"] {
  flex: 1 1 320px;
  min-width: 0;
}

/* ===== TRACKER SPECIFIC ===== */
.tracker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 1rem;
}

.stat-card {
  text-align: center;
  padding: 1.25rem 1rem;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  transition: box-shadow var(--transition);
}

.stat-card:hover {
  box-shadow: var(--shadow-sm);
}

.stat-card .stat-value {
  font-size: 1.8rem;
  font-weight: 800;
  line-height: 1;
}

.stat-card .stat-label {
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-top: 0.4rem;
  font-weight: 600;
}

.action-bar {
  display: flex;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.action-bar button, .action-bar select {
  font-size: 0.72rem;
  padding: 0.2rem 0.45rem;
}

.status-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  padding: 0.2rem 0.45rem;
  font-size: 0.75rem;
  font-family: inherit;
}

.history-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.83rem;
}

.history-table th {
  text-align: left;
  padding: 0.6rem 0.7rem;
  border-bottom: 2px solid var(--border);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.history-table td {
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.history-table tr:hover td { background: var(--bg); }

.email-scan-result {
  background: var(--surface2);
  padding: 1rem;
  border-radius: 8px;
  font-size: 0.78rem;
  white-space: pre-wrap;
  min-height: 48px;
  border: 1px solid var(--border);
  margin-top: 0.75rem;
  line-height: 1.5;
  font-family: var(--font-mono);
  color: var(--muted);
}

.detail-panel { display: none; }
.detail-panel.visible { display: block; }

/* ===== MODAL ===== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(2px);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal-overlay.visible { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  max-width: 560px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal h2 { margin-bottom: 1rem; font-size: 1rem; }
.modal textarea { min-height: 80px; }
.modal .form-row { margin-bottom: 0.75rem; }

/* ==========================================================================
   In-page help system — click-to-open panels + desktop hover tooltips
   Added 2026-09-23. Purely additive; nothing below overrides existing rules.
   ========================================================================== */

.help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px; height: 20px;
  margin-left: .45rem;
  border-radius: 50%;
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  vertical-align: middle;
  flex: 0 0 auto;
  transition: background .12s ease, transform .08s ease;
}
.help-btn:hover { background: #dbeafe; }
.help-btn:active { transform: scale(.94); }
.help-btn:focus-visible { outline: 2px solid #1d4ed8; outline-offset: 2px; }

/* Click-to-open panel (works on touch + desktop) */
.help-panel {
  display: none;
  margin: .5rem 0 .75rem;
  padding: .85rem 1rem;
  background: #f8fbff;
  border: 1px solid #cfe3ff;
  border-left: 4px solid #3b82f6;
  border-radius: 0 8px 8px 0;
  font-size: .85rem;
  line-height: 1.55;
  color: #1f2937;
}
.help-panel.open { display: block; }
.help-panel h4 {
  margin: 0 0 .4rem;
  font-size: .88rem;
  color: #1e40af;
}
.help-panel ul, .help-panel ol { margin: .35rem 0 .35rem 1.1rem; padding: 0; }
.help-panel li { margin: .2rem 0; }
.help-panel .example {
  margin-top: .5rem;
  padding: .5rem .65rem;
  background: #fff;
  border: 1px dashed #cfe3ff;
  border-radius: 6px;
  font-size: .8rem;
  color: #475569;
}
.help-panel .example strong { color: #1e40af; }
.help-panel .close-help {
  float: right;
  border: none;
  background: transparent;
  color: #64748b;
  font-size: 15px;
  cursor: pointer;
  line-height: 1;
  padding: 0 0 0 .5rem;
}
.help-panel .close-help:hover { color: #1e293b; }

/* Desktop-only hover tooltip on the ? button */
@media (hover: hover) and (pointer: fine) {
  .help-btn[data-tip]:hover::after {
    content: attr(data-tip);
    position: absolute;
    z-index: 60;
    margin-top: 28px;
    margin-left: -6px;
    max-width: 280px;
    padding: .55rem .7rem;
    background: #1e293b;
    color: #f1f5f9;
    font-size: .75rem;
    font-weight: 400;
    line-height: 1.45;
    border-radius: 6px;
    box-shadow: 0 4px 14px rgba(0,0,0,.22);
    white-space: normal;
    text-align: left;
  }
}

/* Keep section headers tidy with the help button inline */
.section-header h2 { display: inline-flex; align-items: center; }
