/* ─── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #7B2626;
  --primary-light: #9B3333;
  --primary-pale:  #f9efef;
  --accent:        #E8614D;
  --text:          #1a1a2e;
  --text-muted:    #6b7280;
  --bg:            #f7f3f3;
  --surface:       #ffffff;
  --border:        #e2d5d5;
  --radius:        10px;
  --shadow:        0 2px 12px rgba(123, 38, 38, .10);
  --shadow-lg:     0 8px 32px rgba(123, 38, 38, .15);

  --score-high:   #16a34a;
  --score-mid:    #d97706;
  --score-low:    #dc2626;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ─── Header ──────────────────────────────────────────────────────────────── */
.site-header {
  background: linear-gradient(135deg, #6B1E1E 0%, #8B2D2D 100%);
  padding: 16px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 8px rgba(0,0,0,.2);
  position: sticky;
  top: 0;
  z-index: 100;
}
.site-header .logo {
  color: #fff;
  font-size: 1.2rem;
  font-weight: 700;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 10px;
}
.site-header .logo svg { width: 28px; height: 28px; fill: #fff; }
.site-header .tagline { color: rgba(255,255,255,.65); font-size: .8rem; }

/* ─── Layout ──────────────────────────────────────────────────────────────── */
.app-shell {
  flex: 1;
  display: flex;
  gap: 0;
}

.sidebar {
  width: 300px;
  min-width: 260px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-content {
  flex: 1;
  padding: 32px 28px;
  overflow-y: auto;
}

/* ─── Tabs ────────────────────────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  border-bottom: 2px solid var(--border);
  padding: 0 28px;
  background: var(--surface);
}
.tab-btn {
  padding: 14px 20px;
  border: none;
  background: none;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .2s, border-color .2s;
}
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}
.tab-btn:hover:not(.active) { color: var(--text); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ─── Input area ──────────────────────────────────────────────────────────── */
.input-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-bottom: 28px;
}
.input-card h2 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--primary);
}

.url-row {
  display: flex;
  gap: 10px;
}
.url-input {
  flex: 1;
  width: 100%;
  box-sizing: border-box;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
  transition: border-color .2s;
  outline: none;
}
.url-input:focus { border-color: var(--primary); }

.btn {
  padding: 12px 22px;
  border: none;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, transform .1s, box-shadow .2s;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px rgba(232,97,77,.3);
}
.btn-primary:hover { background: #d4503c; box-shadow: 0 4px 14px rgba(232,97,77,.4); }
.btn-primary:active { transform: scale(.97); }
.btn-primary:disabled { background: #9ca3af; box-shadow: none; cursor: not-allowed; }

.btn-outline {
  background: transparent;
  color: var(--primary);
  border: 2px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-pale); }
.btn-outline:disabled { opacity: 0.4; cursor: not-allowed; pointer-events: none; }

.btn-sm { padding: 8px 14px; font-size: .82rem; }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

/* Batch textarea */
.batch-textarea {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: .88rem;
  font-family: 'Courier New', monospace;
  resize: vertical;
  min-height: 120px;
  outline: none;
  transition: border-color .2s;
}
.batch-textarea:focus { border-color: var(--primary); }

/* ─── Progress bar ────────────────────────────────────────────────────────── */
.progress-bar-wrap {
  background: #e5e7eb;
  border-radius: 99px;
  height: 8px;
  overflow: hidden;
  margin: 8px 0;
}
.progress-bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 99px;
  transition: width .4s ease;
}

.batch-url-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  font-size: .88rem;
  border-bottom: 1px solid #f3f4f6;
}
.batch-url-item .url-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-muted);
}
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d1d5db;
  flex-shrink: 0;
}
.status-dot.running { background: #fbbf24; animation: pulse 1s infinite; }
.status-dot.done    { background: var(--score-high); }
.status-dot.error   { background: var(--score-low); }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

/* ─── Score ring ──────────────────────────────────────────────────────────── */
.score-ring-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.score-ring { transform: rotate(-90deg); }
.score-ring-track { fill: none; stroke: #e5e7eb; stroke-width: 8; }
.score-ring-fill  { fill: none; stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset .8s ease; }
.score-number {
  font-size: 2.4rem;
  font-weight: 800;
  line-height: 1;
}
.score-label { font-size: .78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }

/* ─── Results card ────────────────────────────────────────────────────────── */
.result-header {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 24px;
  align-items: start;
}
.result-meta { flex: 1; }
.result-url {
  font-size: .88rem;
  color: var(--primary);
  word-break: break-all;
  margin-bottom: 6px;
}
.result-summary {
  font-size: .92rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 14px;
}

.top-priority-box {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 8px;
  padding: 14px 16px;
  font-size: .88rem;
  margin-bottom: 16px;
}
.top-priority-box strong { color: #92400e; display: block; margin-bottom: 4px; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.top-priority-box span { color: #78350f; line-height: 1.5; }

.action-bar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

/* ─── Dimension grid ──────────────────────────────────────────────────────── */
.dim-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}
.dim-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  border: 1px solid var(--border);
}
.dim-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  cursor: pointer;
  user-select: none;
  gap: 12px;
  transition: background .15s;
}
.dim-card-header:hover { background: var(--primary-pale); }
.dim-card-header.expanded { background: var(--primary-pale); }

.dim-title { font-weight: 600; font-size: .9rem; flex: 1; }
.dim-score-pill {
  font-size: .82rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 99px;
  background: #f3f4f6;
}
.dim-score-pill.high   { background: #dcfce7; color: #166534; }
.dim-score-pill.medium { background: #fef9c3; color: #854d0e; }
.dim-score-pill.low    { background: #fee2e2; color: #991b1b; }

.priority-badge {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
  padding: 2px 8px;
  border-radius: 4px;
}
.priority-badge.high   { background: #fee2e2; color: #991b1b; }
.priority-badge.medium { background: #fef9c3; color: #854d0e; }
.priority-badge.low    { background: #dcfce7; color: #166534; }

.chevron { transition: transform .25s; font-size: 1rem; color: var(--text-muted); }
.expanded .chevron { transform: rotate(180deg); }

.dim-card-body { display: none; padding: 16px; border-top: 1px solid var(--border); }
.dim-card-body.open { display: block; }

.dim-why { margin-bottom: 12px; }
.dim-why summary {
  font-size: .75rem;
  font-weight: 600;
  color: var(--primary);
  cursor: pointer;
  user-select: none;
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.dim-why summary::before { content: '▸'; font-size: .65rem; }
.dim-why[open] summary::before { content: '▾'; }
.dim-why p {
  margin: 8px 0 0;
  font-size: .8rem;
  line-height: 1.6;
  color: var(--text-muted);
  background: #f8fafc;
  border-left: 3px solid var(--primary);
  padding: 8px 12px;
  border-radius: 0 6px 6px 0;
}

.dim-mini-bar {
  height: 4px;
  background: #e5e7eb;
  border-radius: 2px;
  margin: 0 16px 0;
  overflow: hidden;
}
.dim-mini-bar-fill { height: 100%; border-radius: 2px; transition: width .6s ease; }

.findings-list, .fixes-list {
  margin: 0;
  padding-left: 18px;
  font-size: .86rem;
  line-height: 1.7;
  color: var(--text-muted);
}
.fixes-list { color: var(--text); }
.fixes-list li { margin-bottom: 6px; }
.findings-list li { margin-bottom: 4px; }

.section-label {
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin: 12px 0 6px;
}
.section-label:first-child { margin-top: 0; }

/* code blocks inside fixes */
.code-example-label {
  display: block;
  font-size: .7rem;
  font-weight: 700;
  color: #6366f1;
  margin: 8px 0 3px;
}
.fixes-list code {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 2px 5px;
  font-size: .82em;
  font-family: 'Courier New', monospace;
}

/* ─── Sidebar – History ───────────────────────────────────────────────────── */
.profile-panel {
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--border);
  background: #f8fafc;
}
.profile-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-header h3 { font-size: .9rem; font-weight: 700; color: var(--primary); }
.sidebar-list { flex: 1; overflow-y: auto; }

.history-item {
  padding: 12px 18px;
  border-bottom: 1px solid #f3f4f6;
  cursor: pointer;
  transition: background .15s;
  display: flex;
  align-items: center;
  gap: 12px;
}
.history-item:hover { background: var(--primary-pale); }
.history-item .h-score {
  font-weight: 800;
  font-size: 1.1rem;
  min-width: 36px;
  text-align: center;
}
.history-item .h-meta { flex: 1; min-width: 0; }
.history-item .h-url {
  font-size: .78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.history-item .h-date { font-size: .72rem; color: var(--text-muted); }

.sidebar-empty {
  padding: 32px 18px;
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
  line-height: 1.6;
}

/* ─── Email modal ────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 28px;
  width: 440px;
  max-width: 95vw;
  box-shadow: var(--shadow-lg);
}
.modal h3 { font-size: 1rem; font-weight: 700; margin-bottom: 16px; color: var(--primary); }
.modal-row { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; }

/* ─── Loader ──────────────────────────────────────────────────────────────── */
.spinner {
  width: 22px; height: 22px;
  border: 3px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 48px 0;
}
.loading-overlay.visible { display: flex; }
.loading-overlay .message { color: var(--text-muted); font-size: .9rem; }
.loading-spinner-lg {
  width: 52px; height: 52px;
  border: 5px solid var(--primary-pale);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}

/* ─── Toast notification ──────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}
.toast {
  background: #1a1a2e;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: .86rem;
  max-width: 320px;
  animation: slideIn .25s ease;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.toast.success { background: var(--primary); }
.toast.error   { background: #dc2626; }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ─── Score helpers ───────────────────────────────────────────────────────── */
.score-high   { color: var(--score-high); }
.score-medium { color: var(--score-mid); }
.score-low    { color: var(--score-low); }

/* ─── Batch results ───────────────────────────────────────────────────────── */
.batch-result-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .15s;
}
.batch-result-card:hover { border-color: var(--primary); }
.batch-result-card .brc-url { flex: 1; font-size: .88rem; word-break: break-all; color: var(--text); }
.batch-result-card .brc-score { font-size: 1.6rem; font-weight: 800; }
.batch-result-card .brc-badge { font-size: .75rem; color: var(--text-muted); }

/* ─── Monitor ────────────────────────────────────────────────────────────── */
.field-input {
  width: 100%;
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
  transition: border-color .2s;
  outline: none;
  box-sizing: border-box;
}
.field-input:focus { border-color: var(--primary); }

.field-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin-bottom: 6px;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: .9rem;
  cursor: pointer;
}
.checkbox-label input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.monitor-stat {
  text-align: center;
  min-width: 80px;
}
.monitor-stat-num {
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}
.monitor-stat-label {
  font-size: .75rem;
  color: var(--text-muted);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.monitor-result-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  margin-bottom: 12px;
  overflow: hidden;
}
.monitor-result-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: background .15s;
}
.monitor-result-header:hover { background: var(--primary-pale); }
.monitor-result-header.expanded { background: var(--primary-pale); }

.mention-badge {
  font-size: .75rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 99px;
  white-space: nowrap;
  flex-shrink: 0;
}
.mention-badge.yes { background: #dcfce7; color: #166534; }
.mention-badge.no  { background: #fee2e2; color: #991b1b; }

.model-badge {
  font-size: .72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  background: #f3f4f6;
  color: var(--text-muted);
  flex-shrink: 0;
}
.model-badge.claude  { background: #ede9fe; color: #5b21b6; }
.model-badge.openai  { background: #d1fae5; color: #065f46; }
.model-badge.gemini  { background: #fef9c3; color: #854d0e; }

.monitor-query-text {
  flex: 1;
  font-size: .88rem;
  font-weight: 500;
  color: var(--text);
}

.monitor-result-body {
  display: none;
  padding: 16px;
  border-top: 1px solid var(--border);
}
.monitor-result-body.open { display: block; }

.context-box {
  background: #fffbeb;
  border: 1px solid #fcd34d;
  border-radius: 6px;
  padding: 12px 14px;
  font-size: .86rem;
  line-height: 1.6;
  margin-bottom: 12px;
  color: #78350f;
}
.context-box strong {
  display: block;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
  color: #92400e;
}

.position-badge {
  display: inline-block;
  background: var(--primary-pale);
  color: var(--primary);
  font-size: .78rem;
  font-weight: 700;
  padding: 2px 10px;
  border-radius: 99px;
  margin-bottom: 10px;
}

.full-response {
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 12px 14px;
  font-size: .82rem;
  line-height: 1.7;
  color: var(--text);
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.gap-analysis-box {
  background: #fef2f2;
  border: 1px solid #fca5a5;
  border-radius: 6px;
  padding: 12px 14px;
  font-size: .86rem;
  line-height: 1.6;
  margin-bottom: 12px;
  color: #7f1d1d;
}
.gap-analysis-box strong {
  display: block;
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 6px;
  color: #991b1b;
}

.monitor-progress {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 16px;
}

/* ─── AEO Brand Score ────────────────────────────────────────────────────────── */
.aeo-result-header {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 24px;
  align-items: start;
}

.aeo-knowledge-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  font-weight: 700;
  padding: 4px 12px;
  border-radius: 99px;
  margin-bottom: 10px;
}
.aeo-knowledge-badge.none      { background: #fee2e2; color: #991b1b; }
.aeo-knowledge-badge.limited   { background: #fef9c3; color: #854d0e; }
.aeo-knowledge-badge.moderate  { background: #fef3c7; color: #92400e; }
.aeo-knowledge-badge.good      { background: #d1fae5; color: #065f46; }
.aeo-knowledge-badge.excellent { background: #dcfce7; color: #166534; }
.aeo-knowledge-badge.unknown   { background: #f3f4f6; color: var(--text-muted); }

.aeo-dim-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
  margin-bottom: 20px;
}

/* ─── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    max-height: 240px;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-list { flex-direction: row; overflow-x: auto; display: flex; }
  .history-item { min-width: 180px; border-bottom: none; border-right: 1px solid #f3f4f6; }
  .main-content { padding: 20px 16px; }
}

@media (max-width: 600px) {
  .url-row { flex-direction: column; }
  .result-header { grid-template-columns: 1fr; }
  .dim-grid { grid-template-columns: 1fr; }
  .tab-btn { padding: 12px 14px; font-size: .82rem; }
}
