/* =========================================================
 * ALevelGenie — clean, modern, education-focused theme
 * ========================================================= */
:root {
  --bg: #f6f8fb;
  --surface: #ffffff;
  --ink: #1c2536;
  --ink-soft: #5b6a77;
  --muted: #64748b;
  --line: #e4e9f1;
  --primary: #3d5afe;
  --primary-dark: #2c44d8;
  --primary-soft: #eef1ff;
  --accent: #0ea5a4;
  --danger: #e11d48;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(16, 30, 60, .06), 0 8px 24px rgba(16, 30, 60, .05);
  --font: 'Inter', system-ui, sans-serif;
  --mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  display: flex;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ============ SIDEBAR ============ */
#sidebar {
  width: 280px;
  min-width: 280px;
  background: #10182b;
  color: #dbe2f0;
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  gap: 1rem;
}
.logo {
  font-size: 1.3rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -.02em;
}
.logo i { color: #7c93ff; margin-right: .35rem; }
.logo span { color: #7c93ff; }
.tagline { font-size: .74rem; color: #8b98b4; margin-top: .3rem; }

#chat-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .25rem; }
.chat-item {
  display: flex;
  align-items: center;
  border-radius: 10px;
  transition: background .15s;
}
.chat-item:hover, .chat-item.active { background: rgba(124, 147, 255, .14); }
.chat-item.active { outline: 1px solid rgba(124,147,255,.4); }
.chat-open {
  flex: 1;
  display: flex;
  align-items: center;
  gap: .55rem;
  background: none;
  border: none;
  color: #cfd8ea;
  font: 500 .85rem var(--font);
  padding: .6rem .7rem;
  cursor: pointer;
  text-align: left;
  overflow: hidden;
}
.chat-open span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-del {
  background: none;
  border: none;
  color: #5d6a85;
  cursor: pointer;
  padding: .5rem .6rem;
  border-radius: 8px;
}
.chat-del:hover { color: #ff7d94; }

.sidebar-footer { display: flex; flex-direction: column; gap: .6rem; }
.ai-status { display: flex; align-items: center; gap: .5rem; font-size: .76rem; color: #8b98b4; padding: 0 .25rem; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #64748b; }
.dot.on { background: #34d399; box-shadow: 0 0 8px rgba(52, 211, 153, .8); }

.empty-hint { color: #7d8aa5; font-size: .8rem; text-align: center; padding: 1rem .5rem; line-height: 1.5; }

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  border: none;
  border-radius: 10px;
  font: 600 .875rem var(--font);
  padding: .65rem 1.1rem;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: rgba(255,255,255,.07); color: #cfd8ea; }
.btn-ghost:hover { background: rgba(255,255,255,.14); }
.btn-outline { background: var(--surface); color: var(--primary); border: 1.5px solid var(--primary); }
.btn-outline:hover { background: var(--primary-soft); }
.btn-sm { font-size: .78rem; padding: .45rem .8rem; }

.icon-btn {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  padding: .45rem;
  border-radius: 8px;
  font-size: .95rem;
}
.icon-btn:hover { background: #fef2f2; color: var(--danger); }

/* ============ MAIN & TABS ============ */
#main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tabs {
  display: flex;
  gap: .25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: .5rem 1.25rem 0;
}
.tab {
  display: flex;
  align-items: center;
  gap: .5rem;
  background: none;
  border: none;
  border-bottom: 2.5px solid transparent;
  color: var(--muted);
  font: 600 .875rem var(--font);
  padding: .7rem 1rem;
  cursor: pointer;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.badge {
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 20px;
  font-size: .7rem;
  padding: .1rem .5rem;
  font-weight: 700;
}

.tab-panel { display: none; flex: 1; min-height: 0; flex-direction: column; }
.tab-panel.active { display: flex; }

.panel-inner {
  max-width: 780px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
  overflow-y: auto;
}
.panel-inner h2 { font-size: 1.25rem; margin-bottom: .4rem; }
.panel-inner h2 i { color: var(--primary); margin-right: .4rem; }
.panel-desc { color: var(--muted); font-size: .9rem; line-height: 1.55; margin-bottom: 1.25rem; }
.panel-desc a { color: var(--primary); }

/* ============ GENERATOR / CHAT ============ */
#chat-area {
  flex: 1;
  overflow-y: auto;
  padding: 1.75rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
#welcome-card {
  max-width: 640px;
  margin: 8vh auto 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2.25rem 2.5rem;
  text-align: center;
}
.welcome-icon { font-size: 2rem; color: var(--primary); margin-bottom: 1rem; }
#welcome-card h1 { font-size: 1.45rem; letter-spacing: -.02em; margin-bottom: .75rem; }
#welcome-card p { color: var(--muted); font-size: .92rem; line-height: 1.6; }
.welcome-tips {
  list-style: none;
  margin-top: 1.25rem;
  text-align: left;
  display: flex;
  flex-direction: column;
  gap: .55rem;
}
.welcome-tips li { font-size: .85rem; color: var(--ink); }
.welcome-tips i { color: var(--accent); width: 1.4rem; }

.msg {
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.4rem 1.25rem;
}
.msg-user { border-left: 4px solid var(--accent); }
.msg-ai { border-left: 4px solid var(--primary); }
.msg-head {
  font-size: .74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  margin-bottom: .6rem;
}
.msg-user .msg-head i { color: var(--accent); }
.msg-ai .msg-head i { color: var(--primary); }

.msg-body { font-size: .93rem; line-height: 1.65; overflow-x: auto; }
.msg-body h2 { font-size: 1.05rem; margin: 1.1rem 0 .5rem; color: var(--primary-dark); }
.msg-body h3 { font-size: .95rem; margin: .9rem 0 .4rem; }
.msg-body p { margin: .45rem 0; }
.msg-body ul, .msg-body ol { margin: .45rem 0 .45rem 1.4rem; }
.msg-body blockquote {
  border-left: 3px solid var(--line);
  padding-left: .9rem;
  color: var(--muted);
  margin: .5rem 0;
}
.msg-body table { border-collapse: collapse; margin: .6rem 0; font-size: .86rem; }
.msg-body th, .msg-body td { border: 1px solid var(--line); padding: .4rem .7rem; text-align: left; }
.msg-body th { background: var(--primary-soft); }
.msg-body pre {
  background: #10182b;
  color: #d8e2f6;
  font-family: var(--mono);
  font-size: .8rem;
  padding: 1rem;
  border-radius: 10px;
  overflow-x: auto;
  margin: .6rem 0;
}
.msg-body code { font-family: var(--mono); font-size: .84em; }
.msg-body :not(pre) > code { background: var(--primary-soft); padding: .1em .35em; border-radius: 5px; }

.answer-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-top: 1rem;
  padding-top: .9rem;
  border-top: 1px dashed var(--line);
}

.thinking {
  max-width: 860px;
  width: 100%;
  margin: 0 auto;
  color: var(--muted);
  font-size: .85rem;
  padding: .4rem .2rem;
}
.thinking i { color: var(--primary); margin-right: .4rem; }

/* ============ COMPOSER ============ */
#composer {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: .85rem 1.5rem 1.1rem;
}
.composer-options {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: .65rem;
  max-width: 860px;
  margin-left: auto;
  margin-right: auto;
}
.opt { display: flex; align-items: center; gap: .5rem; font-size: .8rem; color: var(--muted); font-weight: 600; }
.opt i { color: var(--primary); }
.opt select {
  font: 500 .82rem var(--font);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: .35rem .5rem;
  background: var(--bg);
  color: var(--ink);
  max-width: 230px;
}
.opt-check { cursor: pointer; }
.opt-check input { accent-color: var(--primary); width: 15px; height: 15px; }

#diagram-desc-wrap { max-width: 860px; margin: 0 auto .6rem; }
#diagram-desc-wrap textarea,
.composer-input textarea {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 12px;
  font: 400 .92rem var(--font);
  padding: .75rem .9rem;
  resize: vertical;
  background: var(--bg);
  color: var(--ink);
}
.composer-input textarea:focus, #diagram-desc-wrap textarea:focus, .opt select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
  border-color: transparent;
}
.composer-input {
  display: flex;
  gap: .75rem;
  align-items: flex-end;
  max-width: 860px;
  margin: 0 auto;
}
#generate-btn { white-space: nowrap; height: 46px; }

/* ============ CARDS (resources & commands) ============ */
.card-list { display: flex; flex-direction: column; gap: .7rem; margin-top: 1.25rem; }
.card {
  display: flex;
  align-items: center;
  gap: .9rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: .9rem 1.1rem;
}
.card.inactive { opacity: .55; }
.card-text { flex: 1; font-size: .9rem; line-height: 1.45; display: flex; flex-direction: column; gap: .15rem; }
.card-text small { color: var(--muted); font-size: .78rem; }
.res-summary { font-style: italic; }
.res-icon { color: #e11d48; font-size: 1.4rem; }

.inline-form { display: flex; gap: .6rem; }
.inline-form input {
  flex: 1;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font: 400 .9rem var(--font);
  padding: .65rem .9rem;
  background: var(--surface);
}
.inline-form input:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* toggle switch */
.switch { position: relative; width: 40px; height: 22px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 22px;
  cursor: pointer;
  transition: background .2s;
}
.slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s;
}
.switch input:checked + .slider { background: var(--primary); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* ============ DROP ZONE ============ */
#drop-zone {
  border: 2px dashed #b9c4d8;
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  padding: 2.25rem 1rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  color: var(--muted);
}
#drop-zone:hover, #drop-zone.drag { border-color: var(--primary); background: var(--primary-soft); }
#drop-zone i { font-size: 1.8rem; color: var(--primary); margin-bottom: .5rem; }
#upload-progress { margin-top: .9rem; color: var(--primary); font-size: .87rem; font-weight: 600; }

/* ============ MODAL & TOAST ============ */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(13, 20, 38, .55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: 1rem;
}
.modal-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 24px 64px rgba(0,0,0,.25);
  max-width: 460px;
  width: 100%;
  padding: 1.6rem 1.8rem;
}
.modal-card h3 { margin-bottom: .6rem; }
.modal-card h3 i { color: var(--primary); margin-right: .3rem; }
.field-label { display: block; font-size: .8rem; font-weight: 600; color: var(--muted); margin: .9rem 0 .3rem; }
.modal-card input, .modal-card select {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  font: 400 .9rem var(--font);
  padding: .6rem .8rem;
}
.modal-actions { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.4rem; }
.modal-actions .btn-ghost { background: var(--bg); color: var(--ink); }

#toast {
  position: fixed;
  bottom: 1.4rem;
  left: 50%;
  transform: translateX(-50%);
  background: #10182b;
  color: #fff;
  font-size: .86rem;
  padding: .7rem 1.3rem;
  border-radius: 30px;
  box-shadow: 0 8px 24px rgba(0,0,0,.25);
  z-index: 80;
  max-width: 90vw;
}
#toast.error { background: var(--danger); }

/* ============ RESPONSIVE ============ */
@media (max-width: 860px) {
  body { flex-direction: column; }
  #sidebar { width: 100%; min-width: 0; max-height: 40vh; }
  .composer-options { gap: .6rem; }
  #welcome-card { margin-top: 1rem; padding: 1.5rem; }
}
