/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --bg-panel: #1a1d27;
  --bg-card: #222633;
  --bg-input: #2a2e3d;
  --text: #e8eaed;
  --text-dim: #9aa0ac;
  --text-muted: #6b7280;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --green: #22c55e;
  --yellow: #eab308;
  --red: #ef4444;
  --orange: #f97316;
  --blue: #3b82f6;
  --border: #2d3148;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }

#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* === LOADING === */
#loading-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.5s ease;
}
#loading-overlay.hidden { opacity: 0; pointer-events: none; }
.loader-content { text-align: center; }
.loader-content h2 { margin: 1rem 0 0.5rem; font-size: 1.6rem; }
.loader-content p { color: var(--text-dim); margin-bottom: 1rem; }
.spinner {
  width: 48px; height: 48px; margin: 0 auto;
  border: 4px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.progress-bar {
  width: 300px; height: 6px; margin: 0 auto;
  background: var(--border); border-radius: 3px; overflow: hidden;
}
.progress-fill {
  height: 100%; width: 0%; background: var(--accent);
  border-radius: 3px; transition: width 0.3s ease;
}

/* === HEADER === */
header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--bg-panel); border-bottom: 1px solid var(--border);
}
header h1 { font-size: 1.2rem; font-weight: 700; }
.badge {
  display: inline-block; margin-left: 0.75rem;
  padding: 0.2rem 0.6rem; font-size: 0.7rem; font-weight: 500;
  background: rgba(99,102,241,0.15); color: var(--accent-light);
  border-radius: 20px; border: 1px solid rgba(99,102,241,0.3);
}
.header-left { display: flex; align-items: center; }
.status-chip {
  padding: 0.3rem 0.8rem; border-radius: 20px; font-size: 0.75rem; font-weight: 500;
}
.status-chip.online { background: rgba(34,197,94,0.15); color: var(--green); border: 1px solid rgba(34,197,94,0.3); }
.status-chip.offline { background: rgba(234,179,8,0.15); color: var(--yellow); border: 1px solid rgba(234,179,8,0.3); }
.status-chip.error { background: rgba(239,68,68,0.15); color: var(--red); border: 1px solid rgba(239,68,68,0.3); }

/* === MAIN LAYOUT === */
main {
  flex: 1; display: grid;
  grid-template-columns: 320px 1fr 380px;
  gap: 0; overflow: hidden;
}

/* === PANELS === */
.panel {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.panel:last-child { border-right: none; }
.panel-header {
  padding: 0.75rem 1rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5;
}
.panel-header h2 { font-size: 0.95rem; font-weight: 600; }

/* === TABS === */
.tabs {
  display: flex; background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1; padding: 0.6rem; font-size: 0.75rem; font-weight: 500;
  background: none; border: none; color: var(--text-dim);
  cursor: pointer; border-bottom: 2px solid transparent;
  transition: all 0.2s;
}
.tab:hover { color: var(--text); background: var(--bg-card); }
.tab.active { color: var(--accent-light); border-bottom-color: var(--accent); }
.tab-content { display: none; padding: 1rem; flex: 1; overflow-y: auto; }
.tab-content.active { display: flex; flex-direction: column; gap: 0.75rem; }

/* === FORM ELEMENTS === */
.hint { color: var(--text-dim); font-size: 0.8rem; line-height: 1.4; }
.input-row { display: flex; flex-direction: column; gap: 0.3rem; }
.input-row label { font-size: 0.75rem; color: var(--text-dim); font-weight: 500; }
select, input[type="text"], input[type="number"], textarea {
  width: 100%; padding: 0.5rem 0.7rem; font-size: 0.85rem;
  background: var(--bg-input); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  outline: none; transition: border-color 0.2s;
  font-family: inherit;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; }
input[type="range"] { accent-color: var(--accent); }

/* === BUTTONS === */
.btn-primary, .btn-secondary {
  padding: 0.6rem 1rem; font-size: 0.85rem; font-weight: 600;
  border: none; border-radius: var(--radius-sm); cursor: pointer;
  transition: all 0.2s; font-family: inherit;
}
.btn-primary {
  background: var(--accent); color: white;
}
.btn-primary:hover { background: var(--accent-light); transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.btn-secondary {
  background: var(--bg-card); color: var(--text); border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-input); }

/* === MISCONCEPTION CHECKLIST === */
#misconception-checklist {
  display: flex; flex-direction: column; gap: 0.4rem;
  max-height: 300px; overflow-y: auto;
  padding-right: 0.3rem;
}
.misconception-item {
  display: flex; align-items: flex-start; gap: 0.5rem;
  padding: 0.5rem; background: var(--bg-card);
  border-radius: var(--radius-sm); cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s;
}
.misconception-item:hover { border-color: var(--border); }
.misconception-item.checked { border-color: var(--red); background: rgba(239,68,68,0.08); }
.misconception-item input[type="checkbox"] { margin-top: 0.15rem; accent-color: var(--red); }
.misconception-item .mc-label { font-size: 0.8rem; line-height: 1.35; }
.misconception-item .mc-concept { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.15rem; }

/* === RADAR === */
.panel-radar { background: var(--bg); }
#radar-container {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  position: relative; padding: 1rem;
}
#radar-canvas { max-width: 100%; height: auto; }
.legend {
  display: flex; gap: 0.75rem; font-size: 0.7rem; margin-top: 0.3rem;
}
.legend-item { display: flex; align-items: center; gap: 0.3rem; color: var(--text-dim); }

#cluster-summary {
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--border);
  font-size: 0.8rem;
  max-height: 200px; overflow-y: auto;
}
.cluster-card {
  padding: 0.6rem; margin-bottom: 0.5rem;
  background: var(--bg-card); border-radius: var(--radius-sm);
  border-left: 3px solid var(--border);
}
.cluster-card.danger { border-left-color: var(--red); }
.cluster-card.warning { border-left-color: var(--yellow); }
.cluster-card.safe { border-left-color: var(--green); }
.cluster-card h4 { font-size: 0.85rem; margin-bottom: 0.3rem; }
.cluster-card p { font-size: 0.75rem; color: var(--text-dim); line-height: 1.4; }
.cluster-card .risk-score { font-weight: 700; }

/* === AI RESPONSE === */
.panel-response { background: var(--bg); }
#ai-response {
  flex: 1; padding: 1rem; overflow-y: auto;
  font-size: 0.85rem; line-height: 1.6;
}
#ai-response h3 { color: var(--accent-light); margin: 0.75rem 0 0.3rem; font-size: 1rem; }
#ai-response h4 { color: var(--text); margin: 0.5rem 0 0.2rem; font-size: 0.9rem; }
#ai-response ul, #ai-response ol { padding-left: 1.2rem; margin: 0.3rem 0; }
#ai-response li { margin-bottom: 0.3rem; }
#ai-response code {
  background: var(--bg-input); padding: 0.1rem 0.3rem;
  border-radius: 3px; font-size: 0.8rem;
}
#ai-response pre {
  background: var(--bg-input); padding: 0.75rem;
  border-radius: var(--radius-sm); overflow-x: auto;
  margin: 0.5rem 0;
}
#ai-response .remediation {
  background: rgba(99,102,241,0.08); border: 1px solid rgba(99,102,241,0.2);
  border-radius: var(--radius-sm); padding: 0.75rem; margin: 0.5rem 0;
}
#ai-response .remediation h4 { color: var(--accent-light); }

.welcome-msg { padding: 0.5rem; }
.welcome-msg h3 { font-size: 1.1rem; margin-bottom: 0.5rem; }
.welcome-msg ol { margin: 0.5rem 0 0.5rem 1.2rem; }
.welcome-msg li { margin-bottom: 0.4rem; }
.privacy-note {
  margin-top: 0.75rem; padding: 0.6rem;
  background: rgba(34,197,94,0.08); border: 1px solid rgba(34,197,94,0.2);
  border-radius: var(--radius-sm); font-size: 0.8rem;
}

/* Typing indicator */
#ai-typing {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem 1rem; border-top: 1px solid var(--border);
  font-size: 0.8rem; color: var(--text-dim);
}
#ai-typing.hidden { display: none; }
.typing-indicator span {
  display: inline-block; width: 6px; height: 6px;
  background: var(--accent); border-radius: 50%;
  animation: bounce 1.2s infinite;
}
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); }
  40% { transform: translateY(-6px); }
}

/* === GENERATED QUESTIONS === */
#generated-questions {
  display: flex; flex-direction: column; gap: 0.5rem;
}
.question-card {
  padding: 0.6rem; background: var(--bg-card);
  border-radius: var(--radius-sm); border-left: 3px solid var(--accent);
}
.question-card .q-level { font-size: 0.7rem; color: var(--accent-light); font-weight: 600; }
.question-card .q-text { font-size: 0.8rem; margin-top: 0.2rem; }

/* === INDEX STATUS === */
#index-status {
  font-size: 0.8rem; padding: 0.3rem 0;
}
#index-status.success { color: var(--green); }
#index-status.error { color: var(--red); }

/* === TOOLTIP === */
.tooltip {
  position: absolute; display: none;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 0.5rem 0.7rem;
  font-size: 0.75rem; box-shadow: var(--shadow);
  pointer-events: none; z-index: 10; max-width: 250px;
}
.tooltip.visible { display: block; }
.tooltip .tt-title { font-weight: 600; margin-bottom: 0.2rem; }
.tooltip .tt-risk { font-size: 0.7rem; }

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === RESPONSIVE === */
@media (max-width: 1100px) {
  main { grid-template-columns: 1fr; grid-template-rows: auto 1fr auto; }
  .panel { border-right: none; border-bottom: 1px solid var(--border); }
  .panel-radar { min-height: 400px; }
  .panel-response { min-height: 300px; }
}
