:root {
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --sidebar-bg: linear-gradient(180deg, #0b2d39 0%, #09222c 100%);
  --primary: #0f5266;
  --primary-hover: #0a3c4b;
  --accent: #f97316;
  --accent-soft: rgba(249, 115, 22, 0.14);
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.06);
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --sidebar-bg: linear-gradient(180deg, #090f1d 0%, #050914 100%);
  --primary: #14b8a6;
  --primary-hover: #0d9488;
  --accent: #fb923c;
  --accent-soft: rgba(251, 146, 60, 0.16);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --border: #1e293b;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Plus Jakarta Sans", "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  transition: background 0.2s ease, color 0.2s ease;
}

.layout { display: flex; height: 100vh; width: 100%; }

/* Sidebar */
.sidebar {
  width: 310px;
  background: var(--sidebar-bg);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  padding: 18px 16px;
  gap: 16px;
  flex-shrink: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(249, 115, 22, 0.35);
}

.sidebar-header h2 { font-size: 1rem; font-weight: 700; color: #fff; }
.sidebar-header p { font-size: 0.74rem; color: #94a3b8; }

.account-card {
  background: rgba(255, 255, 255, 0.07);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.account-top { display: flex; align-items: center; gap: 10px; }

.avatar-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #0ea5e9, #2563eb);
  color: #fff;
  font-weight: 700;
  font-size: 0.9rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.account-name { font-size: 0.87rem; font-weight: 700; color: #fff; }
.account-role { font-size: 0.73rem; color: #bae6fd; }
.account-actions { display: flex; gap: 6px; }

.btn-acc {
  flex: 1;
  background: linear-gradient(135deg, #f97316, #ea580c);
  color: #fff;
  border: none;
  padding: 7px 10px;
  border-radius: 9px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-acc-ghost {
  background: transparent;
  color: #fecaca;
  border: 1px solid rgba(254, 202, 202, 0.4);
  padding: 7px 10px;
  border-radius: 9px;
  font-size: 0.8rem;
  cursor: pointer;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding-right: 4px;
}

.sidebar-scroll::-webkit-scrollbar { width: 5px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.16); border-radius: 99px; }

.sidebar-section h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
  margin-bottom: 8px;
  font-weight: 700;
}

.topic-list, .link-list, .tool-buttons { display: flex; flex-direction: column; gap: 6px; }

.topic-btn, .tool-card-btn {
  text-align: left;
  background: rgba(255, 255, 255, 0.05);
  color: #f1f5f9;
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 8px 11px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.topic-btn:hover, .tool-card-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  transform: translateX(2px);
}

.tool-card-btn {
  background: rgba(249, 115, 22, 0.16);
  border-color: rgba(249, 115, 22, 0.35);
  font-weight: 600;
}

.admin-btn { background: rgba(250, 204, 21, 0.14); border-color: rgba(250, 204, 21, 0.32); }

.link-list a {
  color: #7dd3fc;
  text-decoration: none;
  font-size: 0.82rem;
  padding: 5px 8px;
  border-radius: 8px;
  transition: background 0.15s;
}

.link-list a:hover { background: rgba(255, 255, 255, 0.08); text-decoration: underline; }

/* Main Panel */
.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.btn-icon {
  display: none;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 11px;
  border-radius: 10px;
  font-size: 1rem;
  cursor: pointer;
}

.topbar h1 { font-size: 1.15rem; font-weight: 800; color: var(--primary); letter-spacing: -0.02em; }
.subtitle { font-size: 0.78rem; color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  font-weight: 600;
}
.status-pill .dot { width: 7px; height: 7px; border-radius: 50%; background: #94a3b8; }
.status-pill.ok { background: rgba(16, 185, 129, 0.12); color: #10b981; border-color: rgba(16, 185, 129, 0.3); }
.status-pill.ok .dot { background: #10b981; }
.status-pill.err { background: rgba(239, 68, 68, 0.12); color: #ef4444; border-color: rgba(239, 68, 68, 0.3); }
.status-pill.err .dot { background: #ef4444; }

button { font: inherit; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--primary);
  color: var(--primary);
  padding: 6px 13px;
  border-radius: 9px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-outline:hover { background: rgba(15, 82, 102, 0.08); }

.btn-ghost {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 6px 11px;
  border-radius: 9px;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }

.status-banner { padding: 10px 24px; font-size: 0.85rem; border-bottom: 1px solid var(--border); }
.status-banner.hidden { display: none; }
.status-banner.ok { background: rgba(16, 185, 129, 0.12); color: #059669; }
.status-banner.err { background: rgba(239, 68, 68, 0.12); color: #dc2626; }

/* Chat Area & Welcome Hero */
.chat-box {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.welcome-hero {
  max-width: 760px;
  margin: auto;
  text-align: center;
  padding: 24px 12px;
  animation: fadeIn 0.35s ease;
}

.hero-badge {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 700;
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-bottom: 12px;
}

.welcome-hero h2 { font-size: 1.65rem; font-weight: 800; letter-spacing: -0.03em; margin-bottom: 10px; }
.welcome-hero h2 span { color: var(--primary); }
.welcome-hero p { font-size: 0.94rem; color: var(--muted); line-height: 1.6; max-width: 600px; margin: 0 auto 24px; }

.hero-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  text-align: left;
}

.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px 16px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, border-color 0.15s ease;
}

.hero-card:hover { transform: translateY(-2px); border-color: var(--primary); background: var(--surface); }
.hero-card strong { font-size: 0.9rem; color: var(--text); }
.hero-card span { font-size: 0.79rem; color: var(--muted); }

/* Chat Bubbles */
.msg { display: flex; flex-direction: column; max-width: 82%; animation: fadeIn 0.2s ease; }
.msg.user { align-self: flex-end; }
.msg.ai { align-self: flex-start; }

.bubble {
  padding: 13px 17px;
  border-radius: 16px;
  line-height: 1.6;
  font-size: 0.93rem;
  word-wrap: break-word;
  box-shadow: var(--shadow);
}

.msg.user .bubble {
  background: linear-gradient(135deg, #0f5266, #0b3945);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg.ai .bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble a { color: var(--accent); font-weight: 600; text-decoration: underline; }
.bubble ul { padding-left: 18px; margin: 6px 0; }
.bubble table { border-collapse: collapse; margin: 10px 0; width: 100%; font-size: 0.84rem; border-radius: 8px; overflow: hidden; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 7px 10px; text-align: left; }
.bubble th { background: var(--surface-2); font-weight: 700; }
.bubble code { background: var(--surface-2); padding: 2px 6px; border-radius: 5px; font-size: 0.85em; }

.msg-meta { display: flex; align-items: center; gap: 10px; margin-top: 5px; font-size: 0.74rem; color: var(--muted); }
.copy-btn { background: transparent; border: none; color: var(--primary); cursor: pointer; font-size: 0.74rem; font-weight: 600; }
.copy-btn:hover { text-decoration: underline; }

/* Typing Dots */
.typing-dots { display: inline-flex; gap: 5px; align-items: center; padding: 4px 2px; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--muted);
  animation: bounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: 0.15s; }
.typing-dots span:nth-child(3) { animation-delay: 0.3s; }

/* Input Dock */
.input-dock { padding: 12px 24px 18px; background: transparent; }

.chat-input-bar {
  display: flex;
  gap: 10px;
  padding: 8px 10px 8px 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
  align-items: flex-end;
}

.chat-input-bar textarea {
  flex: 1;
  padding: 8px 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 0.94rem;
  resize: none;
  max-height: 130px;
  outline: none;
}

.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  background: linear-gradient(135deg, #0f5266, #0a3c4b);
  color: #fff;
  border: none;
  padding: 10px 18px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-primary:hover { opacity: 0.92; }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.full-w { width: 100%; }

/* Modals */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}
.hidden { display: none !important; }

.modal-card {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 500px;
  overflow: hidden;
  box-shadow: 0 24px 50px rgba(0, 0, 0, 0.25);
}

.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; border-bottom: 1px solid var(--border); }
.modal-close { background: transparent; border: none; font-size: 1.4rem; cursor: pointer; color: var(--muted); }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 12px; max-height: 75vh; overflow-y: auto; }

.auth-tabs { display: flex; gap: 6px; padding: 4px; background: var(--surface-2); border-radius: 10px; }
.auth-tab { flex: 1; padding: 8px; border: none; background: transparent; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.auth-tab.active { background: var(--surface); color: var(--primary); box-shadow: 0 2px 6px rgba(0,0,0,0.06); }
.auth-form { display: flex; flex-direction: column; gap: 11px; }
.auth-form label { display: flex; flex-direction: column; gap: 5px; font-size: 0.83rem; font-weight: 600; }
.auth-form input, .auth-form select, .course-row input, .course-row select {
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 0.88rem;
}
.auth-error { background: rgba(239, 68, 68, 0.12); color: #ef4444; padding: 9px 11px; border-radius: 9px; font-size: 0.83rem; }
.demo-box { margin-top: 4px; padding-top: 12px; border-top: 1px dashed var(--border); display: flex; flex-direction: column; gap: 7px; font-size: 0.8rem; color: var(--muted); }
.demo-btns { display: flex; gap: 6px; flex-wrap: wrap; }

.course-rows { display: flex; flex-direction: column; gap: 8px; }
.course-row { display: flex; gap: 8px; align-items: center; }
.course-row input[type="text"] { flex: 1; }
.course-row input[type="number"] { width: 70px; }
.ip-result { background: var(--surface-2); border: 1px solid var(--border); padding: 11px 14px; border-radius: 10px; font-size: 0.92rem; }
.checklist-body h4 { font-size: 0.92rem; color: var(--primary); margin-top: 4px; }
.checklist-body label { display: flex; gap: 8px; align-items: flex-start; font-size: 0.86rem; cursor: pointer; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounce { 0%, 80%, 100% { transform: scale(0.7); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

@media (max-width: 860px) {
  .sidebar { position: fixed; left: -320px; top: 0; bottom: 0; z-index: 40; transition: left 0.22s ease; }
  .sidebar.open { left: 0; }
  .btn-icon { display: inline-block; }
  .hero-grid { grid-template-columns: 1fr; }
}
