/* ==== StudyHub base styles ==== */
* { box-sizing: border-box; margin: 0; }
:root {
  --bg: #0f172a;
  --bg-panel: #1e293b;
  --bg-hover: #334155;
  --accent: #38bdf8;
  --text: #e2e8f0;
  --text-dim: #94a3b8;
  --danger: #f87171;
  --ok: #4ade80;
  --radius: 10px;
  --sidebar-w: 230px;
}
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }

/* ---- Layout ---- */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  padding: 1rem 0;
  position: sticky; top: 0; height: 100vh;
  flex-shrink: 0;
}
.brand { font-size: 1.3rem; font-weight: 700; padding: 0 1.2rem 1rem; }
.brand span, .login-card h1 span { color: var(--accent); }
.sidebar nav { flex: 1; display: flex; flex-direction: column; }
.sidebar nav a {
  color: var(--text-dim);
  padding: .65rem 1.2rem;
  display: flex; align-items: center; gap: .6rem;
  border-left: 3px solid transparent;
}
.sidebar nav a:hover { background: var(--bg-hover); color: var(--text); }
.sidebar nav a.active { color: var(--text); border-left-color: var(--accent); background: var(--bg-hover); }
.sidebar-footer {
  padding: .8rem 1.2rem; display: flex; justify-content: space-between; align-items: center;
  border-top: 1px solid var(--bg-hover);
}
#idle-indicator { color: var(--ok); font-size: .8rem; }
#idle-indicator.warn { color: var(--danger); }
.logout { color: var(--text-dim); font-size: .9rem; }
.content { flex: 1; padding: 2rem; max-width: 1200px; }
.content h1 { margin-bottom: 1.2rem; }

@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; padding: .5rem 0; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar nav a { border-left: none; border-bottom: 3px solid transparent; padding: .55rem .8rem; }
  .sidebar nav a.active { border-bottom-color: var(--accent); }
  .content { padding: 1rem; }
  .chat-msg { max-width: 95%; }
  .chat-wrap { height: calc(100dvh - 14rem); }  /* dvh: accounts for iOS Safari's collapsing toolbar */
  /* Wide tables scroll horizontally instead of breaking the page */
  table.list { display: block; overflow-x: auto; white-space: nowrap; }
}

/* Comfortable touch targets on any touch device (iPad in landscape is >760px) */
@media (pointer: coarse) {
  button, .mcq-option, .sidebar nav a { min-height: 44px; }
  input, select, textarea { font-size: 16px; }  /* prevents iOS auto-zoom on focus */
}

/* ---- Login ---- */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card {
  background: var(--bg-panel); padding: 2rem; border-radius: var(--radius);
  width: min(360px, 92vw); display: flex; flex-direction: column; gap: 1rem;
}
.login-card h1 { text-align: center; }
.login-card label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; color: var(--text-dim); }

/* ---- Generic UI ---- */
input, select, textarea, button {
  font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--bg-hover);
  border-radius: 6px; padding: .55rem .7rem;
}
button { background: var(--accent); color: #06283d; font-weight: 600; cursor: pointer; border: none; }
button:hover { filter: brightness(1.1); }
button.secondary { background: var(--bg-hover); color: var(--text); }
button.danger { background: var(--danger); color: #3d0606; }
.error  { color: var(--danger); }
.notice { color: var(--accent); }

.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 1rem; }
.stat-card, .panel {
  background: var(--bg-panel); border-radius: var(--radius); padding: 1.2rem;
  display: block; color: var(--text);
}
.stat-card:hover { background: var(--bg-hover); }
.stat-num { font-size: 2.2rem; font-weight: 700; color: var(--accent); }
.stat-label { color: var(--text-dim); }
.panel { margin-bottom: 1rem; }
.toolbar { display: flex; gap: .6rem; flex-wrap: wrap; align-items: center; margin-bottom: 1.2rem; }

table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: .6rem .5rem; border-bottom: 1px solid var(--bg-hover); }
table.list th { color: var(--text-dim); font-weight: 600; font-size: .85rem; }

/* ---- Mind maps ---- */
.mindmap-stage { position: relative; display: inline-block; max-width: 100%; }
.mindmap-stage img { max-width: 100%; display: block; border-radius: var(--radius); user-select: none; }
.hotspot {
  position: absolute; border: 2px dashed rgba(56,189,248,.6);
  border-radius: 4px; cursor: pointer;
}
.hotspot .reveal {
  display: none; position: absolute; left: 50%; top: 100%;
  transform: translateX(-50%); margin-top: 4px; z-index: 5;
  background: var(--bg-panel); color: var(--text);
  padding: .4rem .7rem; border-radius: 6px; white-space: pre-wrap;
  min-width: 120px; max-width: 320px; box-shadow: 0 4px 14px rgba(0,0,0,.5);
  font-size: .9rem; pointer-events: none;
}
.hotspot:hover { background: rgba(56,189,248,.15); }
.hotspot:hover .reveal { display: block; }
/* Touch devices: .show is toggled by tapping the hotspot */
.hotspot.show { background: rgba(56,189,248,.15); }
.hotspot.show .reveal { display: block; }
.mindmap-stage.hide-borders .hotspot { border-color: transparent; }
.mindmap-stage.hide-borders .hotspot:hover { border-color: rgba(56,189,248,.6); }

/* ---- MCQ ---- */
.mcq-option {
  display: block; width: 100%; text-align: left; margin-bottom: .5rem;
  background: var(--bg-panel); color: var(--text); border: 1px solid var(--bg-hover);
}
.mcq-option:hover { background: var(--bg-hover); }
.mcq-option.correct { border-color: var(--ok); background: rgba(74,222,128,.12); }
.mcq-option.wrong   { border-color: var(--danger); background: rgba(248,113,113,.12); }
.mcq-progress { color: var(--text-dim); margin-bottom: .8rem; }

/* ---- Flashcards ---- */
.flashcard {
  background: var(--bg-panel); border-radius: var(--radius);
  padding: 2rem; min-height: 220px; display: grid; place-items: center;
  font-size: 1.2rem; text-align: center; margin-bottom: 1rem;
}
.srs-buttons { display: flex; gap: .6rem; justify-content: center; flex-wrap: wrap; }

/* ---- Chat ---- */
.chat-wrap { display: flex; flex-direction: column; height: calc(100vh - 8rem); }
.chat-log { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .8rem; padding-bottom: 1rem; }
.chat-msg { max-width: 80%; padding: .7rem 1rem; border-radius: var(--radius); white-space: pre-wrap; }
.chat-msg.user { align-self: flex-end; background: var(--accent); color: #06283d; }
.chat-msg.assistant { align-self: flex-start; background: var(--bg-panel); }
.chat-input { display: flex; gap: .6rem; }
.chat-input textarea { flex: 1; resize: none; height: 70px; }

/* ---- Sandbox ---- */
.miniapp-frame { width: 100%; height: calc(100vh - 10rem); border: none; border-radius: var(--radius); background: #fff; }

/* ---- Wiki editor ---- */
#quill-editor { background: #fff; color: #111; min-height: 380px; border-radius: 0 0 6px 6px; }
.ql-toolbar { background: #f1f5f9; border-radius: 6px 6px 0 0; }
.wiki-content { background: var(--bg-panel); padding: 1.5rem; border-radius: var(--radius); line-height: 1.6; }
.wiki-content img { max-width: 100%; }

/* ---- PDF viewer ---- */
.pdf-frame { width: 100%; height: calc(100vh - 10rem); border: none; border-radius: var(--radius); }
