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

:root {
  --bg: #0d0f14;
  --bg2: #151820;
  --bg3: #1e2130;
  --bg4: #262a3d;
  --border: rgba(255,255,255,0.07);
  --text: #e8eaf6;
  --text2: #8b92b8;
  --text3: #555d8a;
  --accent: #6c63ff;
  --accent2: #8b85ff;
  --accent-glow: rgba(108,99,255,0.3);
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --blue: #3b82f6;
  --card-radius: 16px;
  --nav-h: 64px;
  --header-h: 56px;
  --font: 'Inter', system-ui, sans-serif;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); overflow: hidden; }

#app { height: 100dvh; display: flex; flex-direction: column; position: relative; }

.hidden { display: none !important; }

/* ─── Splash ────────────────────────────────────────────────────────── */
#splash {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; z-index: 999;
}
.splash-icon { font-size: 64px; animation: pulse 1.5s ease infinite; }
#splash h1 { font-size: 28px; font-weight: 800; background: linear-gradient(135deg, var(--accent) 0%, #a78bfa 100%); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
#splash p { color: var(--text2); font-size: 14px; }
.splash-bar { width: 180px; height: 3px; background: var(--bg3); border-radius: 99px; overflow: hidden; margin-top: 8px; }
.splash-bar-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), #a78bfa); border-radius: 99px; animation: fillBar 1.8s ease forwards; }

@keyframes pulse { 0%,100%{transform:scale(1)} 50%{transform:scale(1.08)} }
@keyframes fillBar { 0%{width:0%} 70%{width:80%} 100%{width:100%} }

/* ─── Main Layout ───────────────────────────────────────────────────── */
#main { height: 100dvh; display: flex; flex-direction: column; }

/* ─── Header ────────────────────────────────────────────────────────── */
.app-header {
  height: var(--header-h); padding: 0 16px;
  display: flex; align-items: center; justify-content: space-between;
  background: var(--bg2); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100; flex-shrink: 0;
}
.header-left { display: flex; align-items: center; gap: 8px; }
.site-selector {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 10px; padding: 6px 12px; cursor: pointer;
  font-size: 13px; font-weight: 500; color: var(--text);
  transition: border-color 0.2s, background 0.2s;
}
.site-selector:hover { border-color: var(--accent); background: var(--bg4); }
.site-favicon { font-size: 16px; }
.chevron { color: var(--text2); font-size: 10px; }
.header-right { display: flex; gap: 8px; }
.icon-btn {
  width: 36px; height: 36px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--bg3);
  color: var(--text); font-size: 16px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.icon-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Site Dropdown ─────────────────────────────────────────────────── */
.site-dropdown {
  position: absolute; top: var(--header-h); left: 12px; right: 12px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--card-radius); z-index: 200;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5); overflow: hidden;
}
.dropdown-header { padding: 12px 16px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text3); }
.dropdown-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer; transition: background 0.15s;
}
.dropdown-item:hover { background: var(--bg3); }
.dropdown-item.active { background: rgba(108,99,255,0.15); }
.dropdown-score-badge { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px; margin-left: auto; }
.dropdown-add { padding: 14px 16px; color: var(--accent); font-size: 14px; font-weight: 500; cursor: pointer; border-top: 1px solid var(--border); }
.dropdown-add:hover { background: rgba(108,99,255,0.1); }

/* ─── Page Content ──────────────────────────────────────────────────── */
#pageContent { flex: 1; overflow-y: auto; padding: 16px 16px calc(var(--nav-h) + 16px); }
#pageContent::-webkit-scrollbar { width: 4px; }
#pageContent::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 4px; }

/* ─── Bottom Nav ────────────────────────────────────────────────────── */
.bottom-nav {
  height: var(--nav-h); display: flex; align-items: center;
  background: var(--bg2); border-top: 1px solid var(--border);
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  padding: 0 4px;
}
.nav-btn {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; background: none; border: none; cursor: pointer;
  color: var(--text3); padding: 6px 4px; border-radius: 12px;
  transition: color 0.2s, background 0.2s;
}
.nav-btn:hover, .nav-btn.active { color: var(--accent); }
.nav-btn.active { background: rgba(108,99,255,0.12); }
.nav-icon { font-size: 18px; }
.nav-label { font-size: 10px; font-weight: 500; letter-spacing: 0.02em; }

/* ─── Cards ─────────────────────────────────────────────────────────── */
.card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--card-radius); padding: 16px;
}
.card + .card, .card + .section, .section + .card, .section + .section { margin-top: 12px; }

.section-title { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text3); margin-bottom: 10px; }

/* ─── SEO Score Circle ──────────────────────────────────────────────── */
.score-card { display: flex; align-items: center; gap: 20px; }
.score-ring { position: relative; width: 96px; height: 96px; flex-shrink: 0; }
.score-ring svg { transform: rotate(-90deg); }
.score-ring-track { fill: none; stroke: var(--bg3); stroke-width: 8; }
.score-ring-fill { fill: none; stroke-width: 8; stroke-linecap: round; transition: stroke-dashoffset 1.2s cubic-bezier(.4,0,.2,1); }
.score-number { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; }
.score-value { font-size: 24px; font-weight: 800; line-height: 1; }
.score-max { font-size: 10px; color: var(--text2); font-weight: 500; }
.score-info { flex: 1; }
.score-label { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.score-sublabel { font-size: 13px; color: var(--text2); line-height: 1.5; }
.score-change { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 600; margin-top: 8px; padding: 3px 10px; border-radius: 20px; }
.score-change.up { background: rgba(34,197,94,0.15); color: var(--green); }
.score-change.down { background: rgba(239,68,68,0.15); color: var(--red); }

/* ─── Stats Grid ────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 14px; padding: 14px;
  transition: border-color 0.2s, transform 0.2s;
}
.stat-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.stat-icon { font-size: 20px; margin-bottom: 8px; }
.stat-value { font-size: 22px; font-weight: 800; line-height: 1; }
.stat-label { font-size: 11px; color: var(--text2); margin-top: 4px; font-weight: 500; }
.stat-change { font-size: 11px; font-weight: 600; margin-top: 6px; }
.stat-change.up { color: var(--green); }
.stat-change.down { color: var(--red); }

/* ─── Chart ──────────────────────────────────────────────────────────── */
.chart-container { position: relative; height: 160px; }

/* ─── Issues List ────────────────────────────────────────────────────── */
.issues-list { display: flex; flex-direction: column; gap: 8px; }
.issue-item {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 12px; padding: 12px; cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.issue-item:hover { border-color: var(--accent); background: var(--bg4); }
.issue-sev { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; margin-top: 5px; }
.issue-sev.high { background: var(--red); box-shadow: 0 0 6px var(--red); }
.issue-sev.medium { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.issue-sev.low { background: var(--blue); box-shadow: 0 0 6px var(--blue); }
.issue-body { flex: 1; min-width: 0; }
.issue-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.issue-cat { font-size: 11px; color: var(--text2); }
.issue-badge { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 20px; flex-shrink: 0; text-transform: uppercase; }
.issue-badge.high { background: rgba(239,68,68,0.15); color: var(--red); }
.issue-badge.medium { background: rgba(245,158,11,0.15); color: var(--yellow); }
.issue-badge.low { background: rgba(59,130,246,0.15); color: var(--blue); }

/* Issue detail expand */
.issue-detail { display: none; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.issue-detail.open { display: block; }
.issue-detail p { font-size: 12px; color: var(--text2); line-height: 1.6; margin-bottom: 8px; }
.issue-rec { background: rgba(108,99,255,0.1); border: 1px solid rgba(108,99,255,0.25); border-radius: 8px; padding: 8px 10px; font-size: 12px; color: var(--accent2); line-height: 1.5; }
.issue-rec::before { content: "💡 "; }

/* ─── Filter Tabs ────────────────────────────────────────────────────── */
.filter-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.filter-tabs::-webkit-scrollbar { display: none; }
.filter-tab {
  flex-shrink: 0; padding: 6px 14px; border-radius: 20px;
  font-size: 12px; font-weight: 600; border: 1px solid var(--border);
  background: var(--bg3); color: var(--text2); cursor: pointer;
  transition: all 0.2s;
}
.filter-tab.active, .filter-tab:hover { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ─── Progress Bars ──────────────────────────────────────────────────── */
.progress-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.progress-label { font-size: 12px; color: var(--text2); width: 100px; flex-shrink: 0; }
.progress-bar { flex: 1; height: 6px; background: var(--bg3); border-radius: 99px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 99px; transition: width 1s ease; }
.progress-value { font-size: 12px; font-weight: 600; width: 36px; text-align: right; flex-shrink: 0; }

/* ─── Plan Tasks ─────────────────────────────────────────────────────── */
.plan-week { margin-bottom: 16px; }
.plan-week-header { font-size: 13px; font-weight: 700; margin-bottom: 8px; color: var(--text); display: flex; align-items: center; gap: 8px; }
.plan-week-badge { font-size: 10px; padding: 2px 10px; border-radius: 20px; background: rgba(108,99,255,0.15); color: var(--accent); }
.plan-task {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 10px;
  background: var(--bg3); margin-bottom: 6px; cursor: pointer;
  transition: background 0.15s;
}
.plan-task:hover { background: var(--bg4); }
.plan-task.done { opacity: 0.5; }
.plan-task.done .task-text { text-decoration: line-through; }
.task-check { width: 18px; height: 18px; border-radius: 5px; border: 2px solid var(--border); flex-shrink: 0; display: flex; align-items: center; justify-content: center; font-size: 10px; transition: all 0.2s; }
.plan-task.done .task-check { background: var(--green); border-color: var(--green); color: #fff; }
.task-text { font-size: 13px; flex: 1; }
.task-priority { font-size: 10px; font-weight: 700; padding: 2px 8px; border-radius: 20px; }
.task-priority.high { background: rgba(239,68,68,0.15); color: var(--red); }
.task-priority.medium { background: rgba(245,158,11,0.15); color: var(--yellow); }
.task-priority.low { background: rgba(59,130,246,0.15); color: var(--blue); }

/* ─── Settings ───────────────────────────────────────────────────────── */
.settings-section { margin-bottom: 20px; }
.settings-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid var(--border);
}
.settings-row:last-child { border-bottom: none; }
.settings-row-left { flex: 1; }
.settings-row-label { font-size: 14px; font-weight: 500; }
.settings-row-desc { font-size: 12px; color: var(--text2); margin-top: 2px; }
.toggle { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; inset: 0; background: var(--bg3); border: 1px solid var(--border); border-radius: 99px; cursor: pointer; transition: all 0.25s; }
.toggle-slider::after { content: ''; position: absolute; width: 18px; height: 18px; background: var(--text2); border-radius: 50%; top: 2px; left: 2px; transition: all 0.25s; }
.toggle input:checked + .toggle-slider { background: var(--accent); border-color: var(--accent); }
.toggle input:checked + .toggle-slider::after { transform: translateX(20px); background: #fff; }
.select-input { background: var(--bg3); border: 1px solid var(--border); border-radius: 8px; color: var(--text); padding: 6px 10px; font-size: 13px; font-family: var(--font); cursor: pointer; }
.select-input:focus { outline: none; border-color: var(--accent); }

/* ─── Modal ──────────────────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.7); backdrop-filter: blur(4px); z-index: 500; display: flex; align-items: flex-end; }
.modal { width: 100%; background: var(--bg2); border-radius: 20px 20px 0 0; padding: 20px; border: 1px solid var(--border); animation: slideUp 0.3s ease; }
@keyframes slideUp { from{transform:translateY(100%)} to{transform:translateY(0)} }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.modal-header h3 { font-size: 17px; font-weight: 700; }
.modal-close { background: var(--bg3); border: 1px solid var(--border); color: var(--text2); width: 28px; height: 28px; border-radius: 8px; cursor: pointer; font-size: 13px; }
.modal-body label { display: block; font-size: 12px; font-weight: 600; color: var(--text2); text-transform: uppercase; letter-spacing: 0.06em; margin-bottom: 8px; }
.modal-body input {
  width: 100%; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text); padding: 14px;
  font-size: 14px; font-family: var(--font); margin-bottom: 12px;
  transition: border-color 0.2s;
}
.modal-body input:focus { outline: none; border-color: var(--accent); }
.error-msg { font-size: 12px; color: var(--red); margin-bottom: 12px; margin-top: -8px; }

/* ─── Buttons ────────────────────────────────────────────────────────── */
.btn-primary {
  width: 100%; padding: 14px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  color: #fff; font-size: 15px; font-weight: 700;
  border: none; cursor: pointer; font-family: var(--font);
  transition: opacity 0.2s, transform 0.1s;
}
.btn-primary:hover { opacity: 0.9; }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary {
  padding: 8px 16px; border-radius: 10px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); font-size: 13px; font-weight: 500;
  cursor: pointer; font-family: var(--font); transition: all 0.2s;
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

/* ─── Toast ──────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: calc(var(--nav-h) + 16px); left: 50%; transform: translateX(-50%);
  background: var(--bg4); border: 1px solid var(--border);
  color: var(--text); padding: 10px 20px; border-radius: 12px;
  font-size: 13px; font-weight: 500; z-index: 999; white-space: nowrap;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: fadeInUp 0.3s ease;
}
@keyframes fadeInUp { from{opacity:0;transform:translate(-50%,10px)} to{opacity:1;transform:translate(-50%,0)} }

/* ─── Audit Running ──────────────────────────────────────────────────── */
.audit-running {
  text-align: center; padding: 40px 20px;
}
.audit-spinner { font-size: 48px; animation: spin 1.5s linear infinite; display: inline-block; margin-bottom: 16px; }
@keyframes spin { from{transform:rotate(0deg)} to{transform:rotate(360deg)} }

/* ─── Empty State ────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; }
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.6; }
.empty-title { font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.empty-text { font-size: 13px; color: var(--text2); line-height: 1.6; }

/* ─── AI Chat ─────────────────────────────────────────────────────────── */
.ai-chat-info { margin-bottom: 12px; }

.ai-chat-messages {
  display: flex; flex-direction: column; gap: 12px;
  min-height: 120px; max-height: calc(100dvh - 360px);
  overflow-y: auto; padding: 8px 0; margin-bottom: 12px;
}
.ai-chat-messages::-webkit-scrollbar { width: 3px; }
.ai-chat-messages::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }

.chat-msg { display: flex; gap: 8px; animation: fadeInUp 0.3s ease; }
.chat-msg.user { justify-content: flex-end; }
.chat-msg.ai { justify-content: flex-start; }

.chat-msg-avatar {
  width: 32px; height: 32px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}

.chat-msg-bubble {
  max-width: 85%; border-radius: 16px; padding: 10px 14px;
  font-size: 13px; line-height: 1.6;
}
.chat-msg-bubble.user {
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  color: #fff; border-bottom-right-radius: 4px;
}
.chat-msg-bubble.ai {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-bottom-left-radius: 4px;
}

.chat-voice-badge {
  display: inline-block; font-size: 10px; background: rgba(255,255,255,0.2);
  padding: 2px 8px; border-radius: 10px; margin-bottom: 4px;
}

.chat-transcription {
  font-size: 11px; color: var(--accent2); font-style: italic;
  margin-bottom: 8px; padding-bottom: 6px; border-bottom: 1px solid var(--border);
}

.chat-msg-text { word-break: break-word; }
.chat-msg-time { font-size: 10px; color: var(--text3); margin-top: 4px; text-align: right; }
.chat-msg-bubble.ai .chat-msg-time { text-align: left; }

/* Typing dots */
.typing-dots { display: flex; gap: 4px; padding: 4px 0; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text2); animation: typingBounce 1.4s infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-6px); opacity: 1; }
}

/* Chat input area */
.ai-chat-input-area {
  position: sticky; bottom: 0;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 10px; margin-top: auto;
}
.ai-chat-input-row { display: flex; align-items: center; gap: 8px; }

.ai-chat-text-input {
  flex: 1; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 12px; color: var(--text); padding: 10px 14px;
  font-size: 14px; font-family: var(--font);
  transition: border-color 0.2s;
}
.ai-chat-text-input:focus { outline: none; border-color: var(--accent); }
.ai-chat-text-input::placeholder { color: var(--text3); }

.ai-chat-send-btn {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  border: none; color: #fff; font-size: 18px;
  cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.2s, transform 0.1s;
}
.ai-chat-send-btn:hover { opacity: 0.9; }
.ai-chat-send-btn:active { transform: scale(0.95); }

.ai-chat-mic-btn {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg3); border: 2px solid var(--border);
  font-size: 18px; cursor: pointer; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.3s;
}
.ai-chat-mic-btn:hover { border-color: var(--red); background: rgba(239,68,68,0.1); }
.ai-chat-mic-btn.recording {
  background: rgba(239,68,68,0.2); border-color: var(--red);
  animation: micPulse 1.5s ease infinite;
}
@keyframes micPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.4); }
  50% { box-shadow: 0 0 0 10px rgba(239,68,68,0); }
}

.recording-indicator {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 4px 0; margin-top: 6px;
}
.recording-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--red); animation: blink 1s ease infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }

.ai-chat-stop-btn {
  margin-left: auto; padding: 4px 12px; border-radius: 8px;
  background: rgba(239,68,68,0.15); border: 1px solid rgba(239,68,68,0.3);
  color: var(--red); font-size: 12px; font-weight: 600;
  cursor: pointer; font-family: var(--font);
}
.ai-chat-stop-btn:hover { background: rgba(239,68,68,0.25); }

/* ─── Responsive tweaks ───────────────────────────────────────────────── */
@media (max-width: 360px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-value { font-size: 18px; }
}
