/* WebLab style.css — clean classroom look with a dark editor */

:root {
  --bg: #eef2f7;
  --chrome: #1e293b;
  --chrome-2: #0b1220;
  --accent: #6366f1;
  --accent-dark: #4f46e5;
  --accent-soft: #eef2ff;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --danger: #ef4444;
  --radius: 10px;
  --font-mono: "SF Mono", ui-monospace, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--chrome-2);
  overflow: hidden;
}

button { font-family: inherit; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
  padding: 0 16px;
  background: linear-gradient(180deg, #141d35, var(--chrome-2));
  color: var(--text);
  box-shadow: 0 1px 0 rgba(148, 163, 184, 0.18), 0 4px 18px rgba(2, 6, 23, 0.35);
  position: relative;
  z-index: 10;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.2px;
  white-space: nowrap;
}

.brand .logo {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  box-shadow: 0 2px 10px rgba(99, 102, 241, 0.5);
}

#project-name {
  width: 200px;
  padding: 8px 12px;
  border: 1px solid #334155;
  border-radius: 9px;
  background: rgba(11, 18, 32, 0.8);
  color: var(--text);
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
#project-name::placeholder { color: var(--muted); }
#project-name:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25);
}

.save-status {
  font-size: 12px;
  color: var(--muted);
  min-width: 64px;
  white-space: nowrap;
}

.spacer { flex: 1; }

.btn {
  border: none;
  border-radius: 9px;
  padding: 9px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.15s, transform 0.05s, box-shadow 0.15s, background 0.15s, border-color 0.15s;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  color: #fff;
  box-shadow: 0 2px 12px rgba(99, 102, 241, 0.45);
}
.btn.primary:hover { filter: brightness(1.1); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; box-shadow: none; }
.btn.ghost {
  background: rgba(148, 163, 184, 0.08);
  color: #cbd5e1;
  border: 1px solid #334155;
}
.btn.ghost:hover { background: rgba(148, 163, 184, 0.16); color: #fff; }
.btn.tiny { padding: 5px 12px; font-size: 12px; border-radius: 7px; }

/* ---------------------------------------------------------------- workbench */

.workbench {
  display: flex;
  height: calc(100vh - 56px);
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.pane-left { width: 50%; }
.pane-right { flex: 1; }

.divider {
  width: 8px;
  cursor: col-resize;
  background: #dbe3ee;
  flex: none;
  position: relative;
  transition: background 0.15s;
}
.divider::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 28px;
  transform: translate(-50%, -50%);
  border-radius: 2px;
  background: #94a3b8;
  opacity: 0.6;
  transition: background 0.15s, opacity 0.15s;
}
.divider:hover, .divider.dragging { background: var(--accent); }
.divider:hover::after, .divider.dragging::after { background: #fff; opacity: 0.9; }

/* ------------------------------------------------------------------- tabs */

.tabbar {
  display: flex;
  gap: 4px;
  padding: 8px 10px;
  background: #dee5ef;
  border-bottom: 1px solid #cbd5e1;
  flex: none;
}

.tab {
  border: none;
  background: transparent;
  padding: 7px 13px;
  font-size: 13px;
  font-weight: 600;
  color: #526175;
  border-radius: 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: background 0.12s, color 0.12s, box-shadow 0.12s;
}
.tab:hover { background: #eef2f7; color: #1e293b; }
.tab.active {
  background: #fff;
  color: var(--accent-dark);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.14);
}

#editor-tabs .tab::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}
#editor-tabs .tab[data-tab="html"]::before { background: #f97316; }
#editor-tabs .tab[data-tab="css"]::before { background: #3b82f6; }
#editor-tabs .tab[data-tab="js"]::before { background: #eab308; }

/* ----------------------------------------------------------------- editor */

.editor-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  background: #21252b;
}

/* CodeMirror fills its container */
.editor-wrap .CodeMirror {
  position: absolute;
  inset: 0;
  height: 100%;
  font-size: 14px;
  font-family: var(--font-mono);
}

/* plain-textarea fallback if CodeMirror failed to load */
.editor-wrap textarea.fallback {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  resize: none;
  padding: 12px;
  background: #21252b;
  color: #e5e9f0;
  font-family: var(--font-mono);
  font-size: 14px;
}

/* ------------------------------------------------------------------ views */

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

#preview-frame {
  flex: 1;
  width: 100%;
  border: none;
  background: #fff;
}

.error-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: #fee2e2;
  color: #991b1b;
  font-size: 13px;
  border-top: 2px solid var(--danger);
  flex: none;
}
.error-bar span { flex: 1; word-break: break-word; }
.error-bar button {
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 14px;
  color: #991b1b;
}

/* -------------------------------------------------------------------- chat */

.view-chat { background: #f5f7fc; }

.chat-banner {
  margin: 10px 12px 0;
  padding: 10px 14px;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: var(--radius);
  font-size: 13px;
  color: #78350f;
  flex: none;
}

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-log::-webkit-scrollbar { width: 10px; }
.chat-log::-webkit-scrollbar-track { background: transparent; }
.chat-log::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 8px;
  border: 3px solid #f5f7fc;
}

.msg {
  display: flex;
  gap: 10px;
  max-width: 94%;
}
.msg .avatar {
  width: 32px;
  height: 32px;
  flex: none;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 17px;
}
.msg.user { align-self: flex-end; flex-direction: row-reverse; }
.msg.user .avatar { background: #dbeafe; }
.msg.tutor .avatar {
  background: linear-gradient(135deg, #e0e7ff, #ede9fe);
}

.msg-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.msg .bubble {
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.55;
  word-break: break-word;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
}
.msg.user .bubble {
  background: linear-gradient(135deg, var(--accent), #818cf8);
  color: #fff;
  border-radius: 14px 14px 4px 14px;
}
.msg.tutor .bubble {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 14px 14px 14px 4px;
  color: #1e293b;
}

.msg.tutor .bubble code.inline-code {
  background: var(--accent-soft);
  color: #3730a3;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 13px;
}
.msg.tutor .bubble strong { color: #0f172a; }

/* code blocks inside tutor bubbles: header with language + copy button */
.code-block {
  background: #0f172a;
  border: 1px solid #1e293b;
  border-radius: 10px;
  overflow: hidden;
  margin: 8px 0 4px;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.18);
}
.code-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 5px 8px 5px 12px;
  background: #1e293b;
  color: #94a3b8;
  font-size: 11px;
  font-family: var(--font-mono);
  letter-spacing: 0.3px;
}
.code-copy {
  border: none;
  background: transparent;
  color: #a5b4fc;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 9px;
  border-radius: 6px;
  transition: background 0.12s, color 0.12s;
}
.code-copy:hover { background: rgba(99, 102, 241, 0.25); color: #c7d2fe; }
.code-block pre {
  margin: 0;
  padding: 10px 12px;
  overflow-x: auto;
  color: #e2e8f0;
}
.code-block pre code {
  font-family: var(--font-mono);
  font-size: 12.5px;
  white-space: pre;
}

/* animated "tutor is thinking" dots */
.dots { display: inline-flex; gap: 4px; padding: 5px 0; }
.dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #94a3b8;
  animation: dot-bounce 1.2s infinite ease-in-out;
}
.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.45; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* "applied to your code" card under tutor replies */
.edit-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 10px 12px;
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.08);
  max-width: 380px;
  animation: card-in 0.25s ease-out;
}
@keyframes card-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}
.edit-card-head {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent-dark);
  margin-bottom: 8px;
}
.edit-files { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #dbe3ee;
  background: #f8fafc;
  border-radius: 999px;
  padding: 4px 11px;
  font-size: 12px;
  font-weight: 600;
  color: #334155;
  cursor: pointer;
  font-family: var(--font-mono);
  transition: border-color 0.12s, background 0.12s;
}
.chip:hover { border-color: var(--accent); background: var(--accent-soft); }
.chip-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.chip.html .chip-dot { background: #f97316; }
.chip.css .chip-dot { background: #3b82f6; }
.chip.js .chip-dot { background: #eab308; }
.edit-card-actions { margin-top: 10px; display: flex; gap: 8px; }
.edit-card.undone { border-left-color: #94a3b8; }
.edit-card.undone .edit-card-head { color: #64748b; }

.chat-hint {
  align-self: center;
  text-align: center;
  color: #64748b;
  font-size: 13px;
  background: #fff;
  border: 1px dashed #cbd5e1;
  border-radius: 14px;
  padding: 18px 24px;
  margin: auto 24px;
  line-height: 1.9;
  max-width: 420px;
}

.chat-input {
  display: flex;
  gap: 10px;
  padding: 12px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  flex: none;
}
.chat-input textarea {
  flex: 1;
  resize: none;
  border: 1.5px solid #dbe3ee;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  line-height: 1.4;
  max-height: 140px;
  background: #fbfcfe;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chat-input textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* ------------------------------------------------------------------- toast */

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--chrome-2);
  color: var(--text);
  padding: 12px 22px;
  border-radius: 12px;
  border: 1px solid rgba(148, 163, 184, 0.2);
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.35);
  z-index: 100;
  opacity: 1;
  transition: opacity 0.3s;
}
.toast.hidden { opacity: 0; pointer-events: none; }

.hidden { display: none !important; }

/* ------------------------------------------------------------ small screens */

@media (max-width: 820px) {
  .workbench { flex-direction: column; height: calc(100vh - 100px); }
  .pane-left { width: 100% !important; height: 50%; }
  .pane-right { height: 50%; }
  .divider { display: none; }
  #project-name { width: 120px; }
  .brand > span:last-child { display: none; }
}
