:root {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273449;
  --primary: #6366f1;
  --primary-light: #818cf8;
  --text: #f1f5f9;
  --text-dim: #94a3b8;
  --border: #334155;
  --ai-bg: #1e3a8a22;
  --ai-border: #60a5fa;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  font-family: 'Sarabun', 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: flex; gap: 0.8rem; align-items: center; }
.brand .logo { font-size: 2rem; }
.brand h1 { margin: 0; font-size: 1.3rem; }
.brand .subtitle { margin: 0; font-size: 0.85rem; color: var(--text-dim); }

nav.persona-switch { display: flex; gap: 0.5rem; }
nav.persona-switch button {
  padding: 0.5rem 1rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.95rem;
}
nav.persona-switch button.active {
  background: var(--primary);
  border-color: var(--primary-light);
}

/* AI backend selector — 3 modes per Kiat 2026-06-10 16:15 */
.model-switch {
  display: flex; align-items: center; gap: 0.4rem;
  margin-left: auto; margin-right: 1rem;
  padding: 0.3rem 0.6rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.model-switch-label {
  font-size: 0.85rem; color: var(--muted, #8b949e);
  white-space: nowrap;
}
.model-btn {
  padding: 0.35rem 0.7rem;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}
.model-btn:hover { background: var(--surface, #161b22); }
.model-btn.active {
  background: var(--primary);
  border-color: var(--primary-light);
  font-weight: 600;
}

/* 🛡️ Auto-Cut PDPA button — golden shield to stand out */
.model-btn.pdpa-btn {
  background: linear-gradient(135deg, #6f4e1f, #9c7b3a);
  color: #fff7e0;
  border-color: #c2a04a;
}
.model-btn.pdpa-btn:hover {
  background: linear-gradient(135deg, #8a6324, #b88f47);
}
.model-btn.pdpa-btn.active {
  background: linear-gradient(135deg, #b88f47, #e0b85a);
  color: #2a1f0a;
  font-weight: 700;
  border-color: #f1cf73;
  box-shadow: 0 0 0 2px rgba(241, 207, 115, .25);
}

/* PDPA badge — appears in chat when Auto-Cut PDPA is active */
.pdpa-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.35rem 0.75rem;
  margin: 0.5rem 0;
  background: linear-gradient(135deg, rgba(184,143,71,.2), rgba(224,184,90,.15));
  border: 1px solid rgba(241,207,115,.5);
  border-radius: 8px;
  font-size: 0.85rem;
  color: #f1cf73;
}
.pdpa-badge .label { font-weight: 600; }
.pdpa-badge .counts { color: #fff7e0; opacity: 0.9; }
.pdpa-badge .layers {
  font-size: 0.75rem; color: #c9a35a; opacity: 0.85;
  margin-left: 0.4rem;
}

main.view {
  display: none;
  padding: 1.5rem 2rem;
  gap: 1.5rem;
}
main.view.active { display: grid; grid-template-columns: 280px 1fr; }
main.view .content.single { display: block; }
main.view#view-paths.active { display: block; }

.sidebar {
  background: var(--surface);
  border-radius: 12px;
  padding: 1rem;
  height: fit-content;
  position: sticky;
  top: 100px;
}
.sidebar h3 { margin: 0.5rem 0 0.5rem; font-size: 0.95rem; color: var(--text-dim); }

.vlist { display: flex; flex-direction: column; gap: 0.4rem; max-height: 60vh; overflow-y: auto; }
.vlist button {
  text-align: left;
  padding: 0.6rem 0.8rem;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.92rem;
}
.vlist button:hover { border-color: var(--primary); }
.vlist button.active { background: var(--primary); border-color: var(--primary-light); }
.vlist .small { font-size: 0.8rem; color: var(--text-dim); margin-top: 0.2rem; }

.content { display: flex; flex-direction: column; gap: 1.5rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
}
.card h3 { margin: 0 0 1rem; font-size: 1.1rem; }
.hidden { display: none !important; }

.hint { color: var(--text-dim); font-style: italic; padding: 0.5rem 0; }

.ai-box {
  background: var(--ai-bg);
  border-left: 3px solid var(--ai-border);
  padding: 1rem;
  border-radius: 6px;
  white-space: pre-wrap;
  font-size: 0.95rem;
}

.course-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}
.course-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.course-card h4 { margin: 0; font-size: 1rem; }
.course-card .meta { font-size: 0.85rem; color: var(--text-dim); }
.course-card .desc { font-size: 0.85rem; }
.tag { display: inline-block; padding: 0.15rem 0.5rem; background: var(--primary); border-radius: 4px; font-size: 0.75rem; margin-right: 0.3rem; }
.tag.level-beginner { background: var(--success); }
.tag.level-intermediate { background: var(--warning); color: #000; }
.tag.level-advanced { background: var(--danger); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
th { color: var(--text-dim); font-weight: 600; }
tr:hover { background: var(--surface-2); cursor: pointer; }
tr.active { background: var(--primary); color: white; }

.chat-log {
  background: var(--surface-2);
  border-radius: 6px;
  padding: 1rem;
  min-height: 240px;
  max-height: 50vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1rem;
}
.bubble {
  max-width: 75%;
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  white-space: pre-wrap;
  font-size: 0.95rem;
}
.bubble.user { background: var(--primary); align-self: flex-end; }
.bubble.assistant { background: var(--surface); align-self: flex-start; border: 1px solid var(--border); }
.bubble.assistant.thinking { font-style: italic; color: var(--text-dim); }

#chat-form { display: flex; gap: 0.5rem; }
#chat-form input { flex: 1; padding: 0.7rem 1rem; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; }
#chat-form button { padding: 0.7rem 1.5rem; background: var(--primary); color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 1rem; }

.form { display: grid; gap: 1rem; }
.form label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.9rem; color: var(--text-dim); }
.form input { padding: 0.6rem 0.8rem; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); border-radius: 6px; font-size: 1rem; }
.form button { padding: 0.7rem 1.5rem; background: var(--primary); color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 1rem; align-self: flex-start; }
button:hover { filter: brightness(1.1); }

.metric-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.8rem; margin-bottom: 1rem; }
.metric {
  background: var(--surface-2);
  padding: 0.7rem 1rem;
  border-radius: 6px;
  display: flex;
  flex-direction: column;
}
.metric .label { font-size: 0.8rem; color: var(--text-dim); }
.metric .value { font-size: 1.3rem; font-weight: 600; margin-top: 0.2rem; }

.review-list { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.5rem; }
.review-item { padding: 0.6rem 0.8rem; background: var(--surface-2); border-left: 3px solid var(--border); border-radius: 4px; font-size: 0.88rem; }
.review-item.positive { border-left-color: var(--success); }
.review-item.negative { border-left-color: var(--danger); }
.review-item.neutral { border-left-color: var(--warning); }
.review-item .meta { font-size: 0.78rem; color: var(--text-dim); }

#run-insights { padding: 0.7rem 1.2rem; background: var(--primary); color: white; border: none; border-radius: 6px; cursor: pointer; font-size: 0.95rem; }

@media (max-width: 800px) {
  main.view.active { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}

/* ── Chart containers — enforce fixed heights ────────────────── */
.chart-box {
  position: relative;
  width: 100%;
  height: 240px;
  max-height: 280px;
  overflow: hidden;
}
.chart-box.tall { height: 320px; max-height: 360px; }
.chart-box.short { height: 180px; max-height: 220px; }
.chart-box canvas {
  max-width: 100% !important;
  max-height: 100% !important;
  display: block;
}
