/* ─────────────── Optimizer / app pages ─────────────── */

.app-shell { padding: 32px 0 80px; }

/* Top stepper bar (always visible, communicates flow) */
.app-stepper {
  display: flex; align-items: center; justify-content: center;
  gap: 8px; flex-wrap: wrap;
  padding: 14px 20px; margin-bottom: 28px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}
.app-stepper .step {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 14px;
  font-size: 13px; font-weight: 600; color: var(--text-muted);
  border-radius: 8px; transition: all .2s ease;
}
.app-stepper .step .num {
  width: 22px; height: 22px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--surface-2); color: var(--text-muted);
  font-size: 11px; font-weight: 700;
}
.app-stepper .step.active { color: var(--text); background: var(--surface-2); }
.app-stepper .step.active .num { background: var(--brand-500); color: #fff; }
.app-stepper .step.done .num {
  background: var(--success-500); color: #fff;
}
.app-stepper .arrow {
  width: 14px; height: 14px;
  color: var(--text-dim);
  flex-shrink: 0;
}

.app-grid {
  display: grid; grid-template-columns: 360px 1fr; gap: 24px; align-items: start;
}
@media (max-width: 980px) {
  .app-grid { grid-template-columns: 1fr; }
  .app-stepper { display: none; }
}

/* Left config panel */
.config-panel { position: sticky; top: 84px; }
.config-panel .card { padding: 22px; }
.config-panel .panel-section + .panel-section { margin-top: 22px; padding-top: 22px; border-top: 1px solid var(--border); }
.panel-title {
  font-size: 11px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 1.5px; color: var(--text-muted); margin-bottom: 12px;
  display: flex; align-items: center; gap: 8px;
}
.panel-title-num {
  display: inline-grid; place-items: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--brand-500); color: #fff;
  font-size: 10px; font-weight: 700; letter-spacing: 0;
}

/* Right work area */
.work-area { display: flex; flex-direction: column; gap: 20px; min-width: 0; }

.editor-card { padding: 0; overflow: hidden; }
.editor-toolbar {
  display: flex; gap: 4px; padding: 10px 14px;
  border-bottom: 1px solid var(--border); background: var(--surface-2);
  flex-wrap: wrap;
}
.tool-btn {
  width: 32px; height: 32px; border-radius: 6px;
  background: transparent; color: var(--text-muted);
  display: grid; place-items: center; font-size: 13px;
  transition: all .12s ease;
}
.tool-btn:hover { background: var(--surface); color: var(--text); }
.tool-btn.active { background: var(--brand-500); color: #fff; }

.editor {
  min-height: 420px; max-height: 65vh; overflow: auto;
  padding: 26px; outline: 0;
  font-size: 15px; line-height: 1.75; color: var(--text);
  background: var(--bg-elev);
}
.editor:empty::before {
  content: attr(data-placeholder); color: var(--text-dim);
  pointer-events: none; display: block;
}
.editor h1, .editor h2, .editor h3, .editor h4 { font-weight: 700; margin: 16px 0 8px; line-height: 1.3; }
.editor h1 { font-size: 26px; }
.editor h2 { font-size: 22px; }
.editor h3 { font-size: 18px; }
.editor p { margin: 8px 0; }
.editor ul, .editor ol { margin: 8px 0 8px 24px; }
.editor blockquote { border-left: 3px solid var(--brand-500); padding-left: 14px; color: var(--text-muted); margin: 12px 0; }
.editor code { background: var(--surface-2); padding: 2px 6px; border-radius: 4px; font-family: var(--font-mono); font-size: 13px; }

.editor-stats {
  display: flex; gap: 18px; padding: 10px 18px;
  border-top: 1px solid var(--border); background: var(--surface-2);
  font-size: 12px; color: var(--text-muted);
}
.stat strong { color: var(--text); font-weight: 600; }

/* Action row */
.action-row {
  display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
}
.usage-pill {
  margin-left: auto; padding: 6px 12px; border-radius: 999px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--text-muted);
}
.usage-pill.warn { color: var(--warn-500); border-color: var(--warn-500); }
.usage-pill.danger { color: var(--danger-500); border-color: var(--danger-500); }
.usage-pill.pro { color: var(--accent-500); border-color: var(--accent-500); background: rgba(6, 214, 160, .08); }

/* Loading state */
.loading-state {
  display: none; padding: 60px 32px; text-align: center;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.loading-state.show { display: block; }
.spinner {
  width: 44px; height: 44px; margin: 0 auto 18px;
  border: 3px solid var(--border); border-top-color: var(--brand-500);
  border-radius: 50%; animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-step { color: var(--text-muted); font-size: 14px; margin-top: 4px; }

/* Results */
.results { display: none; flex-direction: column; gap: 16px; }
.results.show { display: flex; }

.overall-card {
  padding: 28px; display: flex; gap: 24px; align-items: center;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.score-ring { width: 120px; height: 120px; flex-shrink: 0; position: relative; }
.score-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.score-ring .bg { fill: none; stroke: var(--border); stroke-width: 8; }
.score-ring .fg { fill: none; stroke-linecap: round; stroke-width: 8; transition: stroke-dashoffset 1s ease; }
.score-ring-text {
  position: absolute; inset: 0; display: grid; place-items: center;
  flex-direction: column; text-align: center;
}
.score-ring-text { display: flex; }
.score-ring-text .num { font-size: 32px; font-weight: 800; line-height: 1; letter-spacing: -1px; }
.score-ring-text .denom { font-size: 12px; color: var(--text-dim); }
.overall-info h3 { font-size: 18px; margin-bottom: 6px; }
.overall-info p { color: var(--text-muted); font-size: 14px; line-height: 1.6; max-width: 520px; }
.grade-badge {
  display: inline-block; margin-top: 10px;
  padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 700;
  letter-spacing: .4px;
}

/* Section card */
.section-card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-lg);
  overflow: hidden;
}
.section-head {
  padding: 18px 22px; cursor: pointer;
  display: flex; align-items: center; gap: 14px;
}
.section-head:hover { background: var(--surface-2); }
.section-icon {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--surface-2); display: grid; place-items: center; font-size: 18px;
  flex-shrink: 0;
}
.section-title { flex: 1; font-weight: 700; font-size: 15px; }
.section-score {
  font-weight: 800; font-size: 18px; min-width: 50px; text-align: right;
}
.section-toggle { color: var(--text-dim); transition: transform .2s; }
.section-card.open .section-toggle { transform: rotate(180deg); }

.section-body { display: none; padding: 0 22px 22px; }
.section-card.open .section-body { display: block; }

.detail-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.detail {
  padding: 10px 12px; border-radius: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.detail-k { font-size: 11px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .5px; }
.detail-v { font-size: 14px; font-weight: 600; margin-top: 2px; }
.detail-v.good { color: var(--success-500); }
.detail-v.warn { color: var(--warn-500); }
.detail-v.bad  { color: var(--danger-500); }

.suggestions { margin: 12px 0; }
.sug {
  display: flex; gap: 10px; padding: 12px 14px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; margin-bottom: 8px; font-size: 13.5px; line-height: 1.55;
}
.sug-icon { color: var(--brand-500); flex-shrink: 0; }

.fix-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; font-size: 13px; font-weight: 600;
  background: var(--brand-500); color: #fff; transition: all .15s;
}
.fix-btn:hover { filter: brightness(1.1); box-shadow: 0 4px 12px var(--brand-glow); }

/* LLM readiness card */
.llm-readiness { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 14px 0; }
.llm-bar {
  padding: 14px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border);
}
.llm-bar-name { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; display: flex; justify-content: space-between; }
.llm-bar-name b { color: var(--text); }
.llm-bar-track { height: 6px; border-radius: 999px; background: var(--border); overflow: hidden; }
.llm-bar-fill { height: 100%; border-radius: 999px; transition: width .8s ease; }

/* Optimized output panel */
.optimized-panel {
  background: var(--card); border: 1px solid var(--brand-500);
  border-radius: var(--radius-lg); padding: 0; overflow: hidden;
  box-shadow: 0 8px 32px var(--brand-glow);
}
.optimized-head {
  padding: 16px 22px; border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
  background: linear-gradient(135deg, var(--brand-glow), transparent);
}
.optimized-head h3 { font-size: 16px; font-weight: 700; }
.optimized-head .actions { display: flex; gap: 8px; }
.optimized-body {
  padding: 22px; max-height: 60vh; overflow: auto;
  font-size: 15px; line-height: 1.75;
}
.optimized-body h1 { font-size: 26px; margin: 18px 0 10px; }
.optimized-body h2 { font-size: 22px; margin: 18px 0 10px; }
.optimized-body h3 { font-size: 18px; margin: 14px 0 8px; }
.optimized-body p { margin: 10px 0; }
.optimized-body ul, .optimized-body ol { margin: 10px 0 10px 24px; }

/* SERP preview */
.serp {
  padding: 18px; background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: 10px; font-family: var(--font-sans);
}
.serp-url { color: #5f6368; font-size: 13px; margin-bottom: 4px; }
[data-theme='dark'] .serp-url { color: #9aa0a6; }
.serp-title { color: #1a0dab; font-size: 20px; line-height: 1.3; margin-bottom: 4px; }
[data-theme='dark'] .serp-title { color: #8ab4f8; }
.serp-desc { color: #4d5156; font-size: 14px; line-height: 1.55; }
[data-theme='dark'] .serp-desc { color: #bdc1c6; }

/* Profile / history */
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.history-card {
  padding: 18px; border: 1px solid var(--border); border-radius: var(--radius-lg);
  background: var(--card); display: flex; flex-direction: column; gap: 10px;
  transition: transform .15s ease, border-color .15s ease;
}
.history-card:hover { transform: translateY(-2px); border-color: var(--brand-500); cursor: pointer; }
.history-meta { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--text-dim); display: flex; justify-content: space-between; }
.history-title { font-weight: 700; font-size: 14px; line-height: 1.4; }
.history-kw { font-size: 13px; color: var(--text-muted); }
.history-scores { display: flex; gap: 10px; margin-top: auto; }
.score-pill {
  padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--border);
}
.score-pill .label { color: var(--text-dim); margin-right: 4px; font-weight: 500; }

/* Empty state */
.empty {
  padding: 60px 24px; text-align: center; border: 1px dashed var(--border);
  border-radius: var(--radius-lg); color: var(--text-muted);
}
.empty .icon { font-size: 36px; margin-bottom: 12px; opacity: .6; }
.empty h3 { font-size: 18px; margin-bottom: 8px; color: var(--text); font-weight: 700; }

/* Profile header */
.profile-header {
  display: flex; gap: 20px; align-items: center; padding: 28px;
  border-radius: var(--radius-lg); background: var(--card); border: 1px solid var(--border);
  margin-bottom: 28px;
}
.avatar {
  width: 64px; height: 64px; border-radius: 50%;
  background: linear-gradient(135deg, var(--brand-500), var(--accent-500));
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 24px;
  flex-shrink: 0;
}
.profile-info { flex: 1; }
.profile-info h2 { font-size: 22px; font-weight: 700; }
.profile-info .email { color: var(--text-muted); font-size: 14px; }
.plan-badge {
  display: inline-block; padding: 4px 10px; border-radius: 6px;
  font-size: 11px; font-weight: 700; letter-spacing: .5px; margin-top: 8px;
}
.plan-badge.free { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.plan-badge.pro  { background: linear-gradient(135deg, var(--brand-500), var(--accent-500)); color: #fff; }

.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; margin-bottom: 28px; }
.stat-card {
  padding: 18px; border-radius: var(--radius-lg); background: var(--card); border: 1px solid var(--border);
}
.stat-card .label { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .8px; }
.stat-card .value { font-size: 28px; font-weight: 800; letter-spacing: -.5px; margin-top: 4px; }
