/*
 * style.css — MAHS Minimal CSS
 * All layout comes from server-computed Node[] scenes (inline styles).
 * This file handles ONLY: resets, z-layer setup, Flow prose, Z3, modals, scrollbars.
 */

/* ── Global reset ────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}

* {
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100vh;
  overflow: hidden;
  font-family: 'Poppins', ui-sans-serif, system-ui, -apple-system, sans-serif;
  background: #f5f5f5;
  color: #111827;
}

/* ── Z-layers ────────────────────────────────────────────────────── */
#z0 {
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.study-z1,
.study-z2,
.study-z3 {
  position: fixed;
  inset: 0;
  pointer-events: none;
}

.study-z1 {
  z-index: 1000;
}

.study-z2 {
  z-index: 2000;
}

.study-z3 {
  z-index: 3000;
}

.study-z1>*,
.study-z2>*,
.study-z3>* {
  pointer-events: auto;
}

/* ── Global scrollbar — thin overlay style (macOS-like on Linux) ── */
* {
  scrollbar-width: thin;
  scrollbar-color: rgba(155, 155, 155, 0.4) transparent;
}

*::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

*::-webkit-scrollbar-track {
  background: transparent;
}

*::-webkit-scrollbar-thumb {
  background: rgba(155, 155, 155, 0.4);
  border-radius: 3px;
}

*::-webkit-scrollbar-thumb:hover {
  background: rgba(155, 155, 155, 0.6);
}

/* ── Scene node reset ────────────────────────────────────────────── */
#z0>*,
#z1>*,
#z2>* {
  position: absolute;
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Smooth transitions for node position/size/opacity changes */
#z0>div {
  transition: left 0.2s ease, top 0.2s ease, right 0.2s ease, bottom 0.2s ease,
    width 0.2s ease, height 0.2s ease,
    opacity 0.15s ease, background 0.1s ease;
}

/* Prevent text selection on sidebar nav elements */
#left-sidebar,
#left-sidebar * {
  user-select: none;
  -webkit-user-select: none;
}

/* ── Inputs & Textareas ─────────────────────────────────────────── */
#z0 input,
#z0 textarea,
#z1 input,
#z1 textarea,
#z2 input,
#z2 textarea {
  position: absolute;
  box-sizing: border-box;
  font-family: inherit;
  font-size: 14px;
  outline: none;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 10px 14px;
  background: #fff;
  color: #1a1a1a;
}

#z0 input:focus,
#z0 textarea:focus,
#z1 input:focus,
#z1 textarea:focus,
#z2 input:focus,
#z2 textarea:focus {
  outline: none;
  border-color: #5A00AA;
  box-shadow: 0 0 0 3px rgba(90, 0, 170, 0.12);
}

#z0 textarea,
#z1 textarea,
#z2 textarea {
  resize: none;
}

/* Suppress border and focus ring on explicitly borderless inputs */
input[style*="border: none"],
textarea[style*="border: none"] {
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
}
input[style*="border: none"]:focus,
textarea[style*="border: none"]:focus {
  border: none !important;
  box-shadow: none !important;
  outline: none !important;
}

/* ── Flow nodes (html prose) ─────────────────────────────────────── */
[data-flow] {
  position: absolute;
  overflow-y: auto;
}

#z0 [data-flow]>* {
  position: relative;
}

/* Markdown prose inside Flow nodes */
[data-flow] p {
  margin: 0 0 8px;
  line-height: 1.5;
}

[data-flow] ul,
[data-flow] ol {
  padding-left: 20px;
  margin: 0 0 8px;
}

[data-flow] li {
  margin: 0 0 4px;
  line-height: 1.5;
}

[data-flow] code {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

[data-flow] pre {
  background: #1a1a1a;
  color: #e5e7eb;
  padding: 12px 16px;
  border-radius: 8px;
  margin: 0 0 8px;
  overflow-x: auto;
}

[data-flow] pre code {
  background: none;
  padding: 0;
}

[data-flow] strong {
  font-weight: 600;
}

[data-flow] a {
  color: #5A00AA;
  text-decoration: underline;
}

[data-flow] blockquote {
  border-left: 3px solid #d1d5db;
  padding-left: 12px;
  color: #6b7280;
  margin: 0 0 8px;
}

[data-flow] h1,
[data-flow] h2,
[data-flow] h3 {
  font-weight: 600;
  margin: 0 0 8px;
}

/* Chat messages inside Flow */
.chat-sidebar-messages {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.uc-chat-messages {
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.uc-msg-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: msg-fade-in 0.2s ease;
}

.uc-msg-row.uc-msg-user {
  align-items: flex-end;
  padding-left: 20%;
}

.uc-msg-row.uc-msg-assistant {
  align-items: flex-start;
  padding-right: 10%;
}

.uc-msg-bubble {
  position: relative;
  max-width: 100%;
  word-wrap: break-word;
  overflow-wrap: break-word;
  font-size: 14px;
  line-height: 1.5;
  color: #1a3c50;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.uc-msg-row.uc-msg-user .uc-msg-bubble {
  background: #e8f4fd;
  border-radius: 16px 16px 4px 16px;
  padding: 10px 14px;
  color: #1a3c50;
}

.uc-msg-row.uc-msg-assistant .uc-msg-bubble {
  background: #ffffff;
  border-radius: 16px 16px 16px 4px;
  padding: 10px 14px;
  border: 1px solid #e1e8ed;
}

.message-body {
  font-size: 13px;
  line-height: 1.6;
  color: #334155;
}

.message-body .highlight {
  font-weight: 600;
  color: #1a3c50;
}

.message-response {
  font-size: 13px;
  line-height: 1.6;
  color: #334155;
}

.message-avatar-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-bottom: 4px;
}

.message-avatar-wrap img {
  border-radius: 50%;
}

.message-time,
.message-time-muted {
  font-size: 11px;
  color: #94a3b8;
  margin-top: 2px;
}

.message-copy-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 11px;
  color: #94a3b8;
  margin-top: 4px;
  transition: background 0.15s, color 0.15s;
}

.message-copy-btn:hover {
  background: #f1f5f9;
  color: #64748b;
}

.message-action-btn {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 14px;
  background: #5A00AA;
  color: #fff;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s;
}

.message-action-btn:hover {
  background: #470088;
}

.message-error-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: #fef2f2;
  border-radius: 6px;
  font-size: 12px;
  color: #dc2626;
  margin-bottom: 8px;
}

.message-error-icon {
  flex-shrink: 0;
}

.message-retry-btn {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  background: #fee2e2;
  border-radius: 4px;
  cursor: pointer;
  font-size: 11px;
  font-weight: 500;
  color: #dc2626;
}

.message-retry-btn:hover {
  background: #fecaca;
}

.message-list,
.message-list-plain {
  margin: 8px 0 0;
  padding-left: 18px;
  font-size: 13px;
  line-height: 1.5;
  color: #334155;
}

.message-list-item {
  margin-bottom: 4px;
}

.loading-dots-wrap {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 0;
}

.loading-dot {
  width: 6px;
  height: 6px;
  background: #94a3b8;
  border-radius: 50%;
  animation: dot-pulse 1.2s infinite ease-in-out;
}

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

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

.loading-text-sm {
  font-size: 12px;
  color: #94a3b8;
  margin-left: 6px;
}

.empty-state-msg {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 32px 16px;
  font-size: 13px;
  color: #94a3b8;
}

@keyframes dot-pulse {

  0%,
  80%,
  100% {
    transform: scale(0.6);
    opacity: 0.4;
  }

  40% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ── AI-Recommended Course Card Animations ─────────────────────── */
@keyframes ai-pulse-purple {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(90, 0, 170, 0), 0 2px 6px rgba(139, 92, 246, 0.15);
    border-color: rgba(139, 92, 246, 0.5);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(90, 0, 170, 0.15), 0 4px 20px rgba(139, 92, 246, 0.35);
    border-color: rgba(90, 0, 170, 0.8);
  }
}

@keyframes ai-pulse-teal {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(13, 148, 136, 0), 0 2px 6px rgba(13, 148, 136, 0.15);
    border-color: rgba(13, 148, 136, 0.5);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(13, 148, 136, 0.15), 0 4px 20px rgba(13, 148, 136, 0.35);
    border-color: rgba(13, 148, 136, 0.8);
  }
}

@keyframes ai-shimmer {
  0%, 100% { opacity: 0.6; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.02); }
}

/* AI extracurricular cards — strong purple glow */
[data-ai-type="extracurricular"] {
  animation: ai-pulse-purple 2s ease-in-out infinite !important;
  border: 2px solid rgba(90, 0, 170, 0.6) !important;
  background: linear-gradient(135deg, #f5edff 0%, #ede0ff 100%) !important;
}

/* AI CIE/microcredential cards — strong teal glow */
[data-ai-type="cie"] {
  animation: ai-pulse-teal 2s ease-in-out infinite !important;
  border: 2px solid rgba(13, 148, 136, 0.6) !important;
  background: linear-gradient(135deg, #e6fffa 0%, #ccfbf1 100%) !important;
}

/* Shimmer on badge text */
[data-ai-type] [data-ai-badge] {
  animation: ai-shimmer 1.8s ease-in-out infinite;
}

/* Add-course placeholder buttons with AI suggestions */
[data-ai-type="add-extra"] {
  animation: ai-pulse-purple 2.5s ease-in-out infinite !important;
  background: linear-gradient(135deg, #fdfbff 0%, #f3eaff 100%) !important;
}

[data-ai-type="add-cie"] {
  animation: ai-pulse-teal 2.5s ease-in-out infinite !important;
  background: linear-gradient(135deg, #f0fdfa 0%, #d5f5f0 100%) !important;
}

/* ── CIE Loading Overlay Animations ──────────────────────────────── */
@keyframes cie-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

@keyframes cie-dot-pulse {
  0%, 100% { opacity: 0.3; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.2); }
}

@keyframes cie-card-fade-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Spinner ring rotation */
@keyframes cie-bounce-right {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(6px); }
}
[data-animation="bounce-right"] {
  animation: cie-bounce-right 1.2s ease-in-out infinite !important;
}

[data-animation="spin"] {
  animation: cie-spin 1s linear infinite !important;
}

/* Pulsing dots */
[data-animation="pulse"] {
  animation: cie-dot-pulse 1.4s ease-in-out infinite !important;
}

[data-animation="pulse"][data-animation-delay="200ms"] {
  animation-delay: 0.2s !important;
}

[data-animation="pulse"][data-animation-delay="400ms"] {
  animation-delay: 0.4s !important;
}

/* Loading overlay card entrance */
#cie-loading-card {
  animation: cie-card-fade-in 0.4s ease-out !important;
}

/* Semi-transparent overlay backdrop */
#cie-loading-overlay {
  animation: cie-card-fade-in 0.3s ease-out !important;
}

@keyframes msg-fade-in {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: none;
  }
}

/* ── Legacy chat class names (backward compat with running server) ──── */

/* Flow container inside full-screen chat needs padding */
#acm-messages-flow {
  padding: 24px 32px;
  box-sizing: border-box;
}

#acm-messages-flow>*:first-child {
  margin-top: 0;
}

.message-row-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
  animation: msg-fade-in 0.2s ease;
}

.message-row-inner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 100%;
}

.message-row-inner--start {
  justify-content: flex-start;
}

.message-row-inner--end {
  flex-direction: row-reverse;
  justify-content: flex-start;
}

.message-bubble-user {
  background: #e8f4fd;
  border-radius: 18px 18px 4px 18px;
  padding: 12px 16px;
  max-width: 75%;
  font-size: 14px;
  line-height: 1.6;
  color: #1a3c50;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.message-bubble-ai {
  background: #f8f9fa;
  border: 1px solid #e1e8ed;
  border-radius: 18px 18px 18px 4px;
  padding: 12px 16px;
  max-width: 75%;
  font-size: 14px;
  line-height: 1.6;
  color: #334155;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  word-wrap: break-word;
  overflow-wrap: break-word;
}

/* Sidebar-specific: narrower bubbles */
.chat-sidebar-messages .message-bubble-user,
.chat-sidebar-messages .message-bubble-ai {
  max-width: 90%;
  font-size: 13px;
}

.message-avatar-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
  background: #f1f5f9;
}

.message-avatar-wrap img {
  border-radius: 50%;
}

/* ── Z3 popup (dropdown / context menu — client-rendered) ─────────── */
#z3 {
  z-index: 9999;
}

#z3-popup,
.uc-z3-popup {
  position: fixed;
  z-index: 9999;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  min-width: 160px;
}

.uc-z3-item {
  padding: 8px 14px;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}

.uc-z3-item:hover {
  background: #f3f4f6;
}

.uc-z3-item.uc-z3-danger {
  color: #ef4444;
}

.uc-z3-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 4px 0;
}

/* ── Modal overlay (z1/z2 flow HTML) ─────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: #fff;
  border-radius: 12px;
  width: 600px;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.2);
}

.modal-title {
  flex-shrink: 0;
  margin: 0;
  padding: 1.5rem 2rem 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a1a2e;
}

.modal-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 1.25rem 2rem;
}

.modal-actions {
  flex-shrink: 0;
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  padding: 1rem 2rem 1.5rem;
  border-top: 1px solid #e5e7eb;
}

.modal-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.modal-form label {
  font-size: 0.875rem;
  font-weight: 600;
  color: #6b7280;
}

.modal-form input,
.modal-form textarea,
.modal-form select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  font-family: inherit;
  font-size: 1rem;
  background: #fff;
}

.modal-form input:focus,
.modal-form textarea:focus,
.modal-form select:focus {
  outline: none;
  border-color: #5A00AA;
  box-shadow: 0 0 0 3px rgba(90, 0, 170, 0.12);
}

.modal-button {
  padding: 0.625rem 1.25rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  transition: all 0.2s;
}

.modal-button.cancel {
  background: #f3f4f6;
  color: #6b7280;
  border: 1px solid #e5e7eb;
}

.modal-button.cancel:hover {
  background: #e5e7eb;
}

.modal-button.primary {
  background: #5A00AA;
  color: #fff;
}

.modal-button.primary:hover {
  background: #470088;
}

.admin-form-section {
  margin-top: 1.25rem;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  background: #f9fafb;
}

.admin-form-section legend {
  color: #5A00AA;
  font-weight: 600;
  padding: 0 0.5rem;
  font-size: 0.875rem;
}

/* ── Scrollbars ─────────────────────────────────────────────────── */
[data-flow]::-webkit-scrollbar {
  width: 6px;
}

[data-flow]::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 3px;
}

[data-flow]::-webkit-scrollbar-thumb:hover {
  background: #9ca3af;
}

#left-sidebar [id$="-list"]::-webkit-scrollbar {
  width: 4px;
}

#left-sidebar [id$="-list"]::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.25);
  border-radius: 2px;
}

/* ── Sidebar icons ──────────────────────────────────────────────── */
.sidebar-icon-white {
  filter: invert(1);
  opacity: 0.85;
  vertical-align: middle;
}

/* ── Reconnect indicator ────────────────────────────────────────── */
.uc-send-reconnecting {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Custom tooltips (help "?" icons) ────────────────────────────── */
[data-tooltip] {
  position: relative;
}

[data-tooltip]::after {
  content: attr(data-tooltip);
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: #1a3c50;
  color: #fff;
  font-size: 12px;
  font-weight: 400;
  line-height: 1.5;
  padding: 10px 14px;
  border-radius: 8px;
  white-space: normal;
  width: max-content;
  max-width: 240px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 9999;
}

[data-tooltip]:hover::after {
  opacity: 1;
}

/* ── KaTeX math rendering in chat bubbles ─────────────────────────── */
[data-flow] .katex-display {
  margin: 12px 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 8px 0;
}

[data-flow] .katex {
  font-size: 1.05em;
}

[data-flow] .katex-display > .katex {
  font-size: 1.15em;
}

[data-flow] .katex-html {
  white-space: nowrap;
}

[data-flow] .katex-display .katex-html {
  display: flex;
  justify-content: center;
}