/* ============================================================
   GTS Teacher Portal — Dark Theme
   ============================================================ */

:root {
  --bg: #0a0a0f;
  --surface: #13131e;
  --surface-2: #1a1a2a;
  --surface-3: #202032;
  --border: #252538;
  --border-subtle: #1e1e30;
  --text: #f0f0f8;
  --muted: #8888a8;
  --muted-2: #6060808;
  --accent: #b11226;
  --accent-hover: #d01530;
  --accent-dim: rgba(177, 18, 38, 0.15);
  --green: #22c55e;
  --yellow: #f59e0b;
  --radius: 12px;
  --radius-lg: 18px;
  --sidebar-width: 260px;
  --mobile-header-height: 56px;
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

/* ---- Reset ------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Helvetica, Arial, sans-serif;
  line-height: 1.6;
  display: flex;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
p { margin: 0 0 0.75rem; }
h1, h2, h3 { margin: 0; line-height: 1.2; letter-spacing: -0.02em; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* ---- Sidebar ---------------------------------------------- */
.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  overflow-y: auto;
  z-index: 30;
}

.sidebar-header {
  padding: 1.25rem 1.25rem 0.75rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.sidebar-logo {
  font-size: 1.3rem;
  font-weight: 850;
  color: var(--text);
  letter-spacing: 0.02em;
  flex-shrink: 0;
}

.sidebar-logo:hover {
  color: var(--accent);
}

.sidebar-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 0.2rem 0.5rem;
  background: var(--surface-2);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  width: 100%;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 540;
  cursor: pointer;
  text-align: left;
  transition: background 150ms ease, color 150ms ease;
}

.sidebar-nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.sidebar-nav-item.active {
  background: var(--accent-dim);
  color: var(--text);
  font-weight: 640;
  border: 1px solid rgba(177, 18, 38, 0.25);
}

.nav-icon {
  width: 1.1rem;
  height: 1.1rem;
  flex-shrink: 0;
  opacity: 0.8;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

/* WebSocket status */
.ws-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.ws-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--yellow);
  flex-shrink: 0;
  transition: background 400ms ease;
}

.ws-dot.connected { background: var(--green); }
.ws-dot.disconnected { background: #ef4444; }

.ws-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.sidebar-back-link {
  font-size: 0.8rem;
  color: var(--muted);
  transition: color 150ms;
}

.sidebar-back-link:hover {
  color: var(--text);
}

/* ---- Mobile header ----------------------------------------- */
.mobile-header {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--mobile-header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  align-items: center;
  padding: 0 1rem;
  gap: 0.75rem;
  z-index: 40;
}

.mobile-menu-btn {
  margin-left: auto;
  background: none;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 0.3rem 0.55rem;
  font-size: 1rem;
  cursor: pointer;
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 25;
  backdrop-filter: blur(2px);
}

/* ---- Main content ------------------------------------------ */
.portal-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---- Views ------------------------------------------------- */
.view {
  display: none;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.view.active {
  display: flex;
}

.view-header {
  padding: 2rem 2rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.view-header h1 {
  font-size: 1.6rem;
  font-weight: 750;
}

.view-subtitle {
  color: var(--muted);
  font-size: 0.92rem;
  margin-top: 0.3rem;
}

/* ---- Chat header ------------------------------------------- */
.chat-header {
  padding: 1.1rem 1.5rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.gm-avatar {
  width: 2.6rem;
  height: 2.6rem;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #7a0d18);
  display: grid;
  place-items: center;
  font-size: 0.72rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.04em;
  flex-shrink: 0;
  border: 1px solid rgba(177, 18, 38, 0.4);
}

.chat-title {
  font-size: 1.05rem;
  font-weight: 720;
}

.chat-subtitle {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}

.btn-gen-config {
  padding: 0.5rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent-dim);
  color: var(--text);
  font-size: 0.85rem;
  font-weight: 640;
  cursor: pointer;
  transition: background 150ms ease, border-color 150ms ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.btn-gen-config:hover {
  background: rgba(177, 18, 38, 0.25);
  border-color: var(--accent-hover);
}

/* ---- Chat messages ----------------------------------------- */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

/* Message rows */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 0.65rem;
  max-width: 78%;
}

.msg-row.teacher {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-row.gm {
  align-self: flex-start;
}

/* Avatar in messages */
.msg-avatar {
  width: 1.9rem;
  height: 1.9rem;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #7a0d18);
  display: grid;
  place-items: center;
  font-size: 0.6rem;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

/* Bubble */
.msg-bubble {
  padding: 0.7rem 1rem;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.55;
}

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

.msg-row.teacher .msg-bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-bubble p { margin: 0; }

/* Typing indicator */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 0.6rem 0.85rem;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-5px); opacity: 1; }
}

/* ---- File chips -------------------------------------------- */
.file-chips {
  padding: 0 1.5rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-height: 0;
}

.file-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 0.3rem 0.75rem 0.3rem 0.6rem;
  font-size: 0.8rem;
  color: var(--text);
}

.file-chip-icon {
  font-size: 0.85rem;
}

.file-chip-remove {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0;
  margin-left: 0.15rem;
  display: flex;
  align-items: center;
}

.file-chip-remove:hover {
  color: #ef4444;
}

/* ---- Config card ------------------------------------------- */
.config-card {
  margin: 0.75rem 1.5rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  flex-shrink: 0;
}

.config-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
}

.config-card-title {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--green);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.config-card-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-icon {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.35rem 0.7rem;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface-3);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms, color 150ms, border-color 150ms;
}

.btn-icon svg {
  width: 14px;
  height: 14px;
}

.btn-icon:hover {
  background: var(--surface);
  color: var(--text);
  border-color: var(--muted);
}

.btn-icon-primary {
  background: var(--accent-dim);
  color: var(--text);
  border-color: rgba(177, 18, 38, 0.3);
}

.btn-icon-primary:hover {
  background: rgba(177, 18, 38, 0.25);
  border-color: var(--accent);
  color: var(--text);
}

.config-json {
  margin: 0;
  padding: 1rem;
  font-family: "SFMono-Regular", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.7;
  color: #a8d4a8;
  overflow-x: auto;
  white-space: pre;
  max-height: 260px;
  overflow-y: auto;
}

/* ---- Chat input area --------------------------------------- */
.chat-input-wrap {
  padding: 0.75rem 1.5rem 1rem;
  flex-shrink: 0;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg);
}

.chat-input-bar {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.5rem 0.6rem 0.5rem 0.75rem;
  transition: border-color 150ms ease;
}

.chat-input-bar:focus-within {
  border-color: rgba(177, 18, 38, 0.5);
  box-shadow: 0 0 0 3px rgba(177, 18, 38, 0.08);
}

.attach-btn {
  cursor: pointer;
  color: var(--muted);
  padding: 0.3rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 150ms, background 150ms;
  flex-shrink: 0;
  margin-bottom: 0.15rem;
}

.attach-btn svg {
  width: 1.1rem;
  height: 1.1rem;
}

.attach-btn:hover {
  color: var(--text);
  background: var(--surface-2);
}

.chat-textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  resize: none;
  font: inherit;
  font-size: 0.92rem;
  color: var(--text);
  line-height: 1.55;
  max-height: 140px;
  overflow-y: auto;
  padding: 0.2rem 0;
}

.chat-textarea::placeholder {
  color: var(--muted);
}

.send-btn {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  margin-bottom: 0.05rem;
  transition: background 150ms ease, transform 100ms ease;
}

.send-btn svg {
  width: 0.95rem;
  height: 0.95rem;
  transform: rotate(90deg);
}

.send-btn:hover:not(:disabled) {
  background: var(--accent-hover);
}

.send-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.send-btn:disabled {
  background: var(--surface-3);
  color: var(--muted);
  cursor: not-allowed;
}

.input-hint {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0.45rem 0 0;
  text-align: center;
}

/* ---- Empty / placeholder states ---------------------------- */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 3rem 2rem;
  gap: 0.75rem;
}

.empty-icon {
  font-size: 2.5rem;
  color: var(--border);
  margin-bottom: 0.5rem;
}

.empty-state h2 {
  font-size: 1.25rem;
  color: var(--text);
}

.empty-state p {
  color: var(--muted);
  max-width: 36ch;
  font-size: 0.92rem;
}

.btn-portal-primary {
  margin-top: 0.5rem;
  padding: 0.6rem 1.25rem;
  border-radius: 9px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 0.9rem;
  font-weight: 640;
  cursor: pointer;
  transition: background 150ms;
}

.btn-portal-primary:hover {
  background: var(--accent-hover);
}

/* ---- Settings view ----------------------------------------- */
.settings-section {
  padding: 1.5rem 2rem;
  max-width: 480px;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.settings-label {
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--text);
}

.settings-input {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 0.65rem 0.9rem;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-family: monospace;
  width: 100%;
  transition: border-color 150ms;
}

.settings-input:focus {
  outline: none;
  border-color: rgba(177, 18, 38, 0.5);
}

.settings-hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin: 0;
}

/* ---- Responsive -------------------------------------------- */
@media (max-width: 700px) {
  body {
    flex-direction: column;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    transform: translateX(-100%);
    transition: transform 250ms ease;
    z-index: 35;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-overlay.open {
    display: block;
  }

  .mobile-header {
    display: flex;
  }

  .portal-main {
    margin-top: var(--mobile-header-height);
    height: calc(100vh - var(--mobile-header-height));
  }

  .chat-header {
    padding: 0.85rem 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .chat-messages {
    padding: 1rem;
  }

  .chat-input-wrap {
    padding: 0.6rem 1rem 0.75rem;
  }

  .config-card {
    margin: 0.5rem 1rem;
  }

  .file-chips {
    padding: 0 1rem;
  }

  .msg-row {
    max-width: 92%;
  }

  .settings-section {
    padding: 1.25rem 1rem;
  }
}
