/* ═══════════════════════════════════════════════
   Phase 9 — Advanced UI
   Image viewer, Mermaid, KaTeX, split screen, shortcuts
   ═══════════════════════════════════════════════ */

/* ── Image Lightbox ── */
#image-viewer {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.85);
  z-index: 500;
  align-items: center;
  justify-content: center;
  cursor: zoom-out;
}
#image-viewer.open { display: flex; }

#image-viewer img {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  border-radius: var(--radius);
  box-shadow: 0 0 40px rgba(0,0,0,.5);
  animation: viewerIn .2s ease;
}
@keyframes viewerIn { from { opacity: 0; transform: scale(.9); } to { opacity: 1; transform: scale(1); } }

#image-viewer .iv-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: rgba(0,0,0,.5);
  border: none;
  color: #fff;
  font-size: 28px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
}
#image-viewer .iv-close:hover { background: rgba(255,71,87,.8); }

#image-viewer .iv-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0,0,0,.4);
  border: none;
  color: #fff;
  font-size: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .2s;
}
#image-viewer .iv-nav:hover { background: rgba(0,0,0,.7); }
#image-viewer .iv-prev { left: 16px; }
#image-viewer .iv-next { right: 16px; }

/* ── Mermaid Diagrams ── */
.mermaid-wrap {
  margin: 12px 0;
  padding: 12px;
  background: #fff;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  border: 1px solid var(--border);
}
[data-theme="dark"] .mermaid-wrap {
  background: #1a1d23;
}
.mermaid-wrap svg { max-width: 100%; }

/* ── KaTeX Math ── */
.katex-wrap {
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 0;
}
.msg-bubble .katex { font-size: 1.1em; }
.msg-bubble .katex-display {
  margin: 10px 0;
  overflow-x: auto;
  overflow-y: hidden;
}

/* ── Split Screen ── */
#main.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
#main.split #chat-area { border-right: 1px solid var(--border); }
#main.split #chat-area:last-child { border-right: none; }

#split-panel {
  display: none;
  flex-direction: column;
  background: var(--bg);
}
#main.split #split-panel { display: flex; }

.sp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  background: var(--surface);
}
.sp-header select {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  outline: none;
}

.split-msgs {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}
.split-msgs .msg { margin-bottom: 16px; }
.split-msgs .msg-bubble {
  max-width: 95%;
  font-size: 13px;
  padding: 8px 12px;
}

/* ── Shortcuts Help Modal ── */
#shortcuts-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 400;
  align-items: center;
  justify-content: center;
}
#shortcuts-overlay.open { display: flex; }

.shortcuts-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 90%;
  max-width: 480px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 20px 24px;
  box-shadow: var(--shadow-lg);
}
.shortcuts-panel h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-bright);
}

.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.shortcut-row:last-child { border-bottom: none; }
.shortcut-row .sc-label { color: var(--text); }
.shortcut-row .sc-key {
  display: flex;
  gap: 4px;
}
.shortcut-row kbd {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0,0,0,.1);
}
