/**
 * sidebarAI - ScholarAI & SSPAI Sidebar Styles
 * Extracted from index.js (ScholarSlide viewer)
 */

@media print {
  .scholar-ai-sidebar { display: none !important; }
  .ssp-ai-sidebar { display: none !important; }
}

body.viewer-in-app-fs .scholar-ai-sidebar,
body.viewer-in-app-fs .ssp-ai-sidebar { display: none !important; }

/* ========== ScholarAI Sidebar (우측 도킹 영역 안, 본문 오른쪽) ========== */
.scholar-ai-sidebar {
  width: 0;
  min-width: 0;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #13161d;
  border-right: 1px solid #1e2332;
  transition: min-width 0.2s;
  position: relative;
}
body.theme-light .scholar-ai-sidebar { background: #e2e8f0; border-right-color: #cbd5e1; }
.scholar-ai-sidebar.open { min-width: 280px; width: 380px; max-width: 90vw; }
.scholar-ai-sidebar.fullscreen { position: fixed !important; inset: 0 !important; z-index: 2147483500 !important; min-width: 100% !important; width: 100% !important; max-width: none !important; border: none !important; overflow: auto !important; }
.scholar-ai-sidebar.popup.open {
  position: fixed !important;
  z-index: 2147483450 !important;
  left: auto;
  right: auto;
  top: auto;
  bottom: auto;
  width: 480px !important;
  min-width: 320px !important;
  max-width: min(94vw, 920px) !important;
  height: 80vh !important;
  min-height: 280px !important;
  max-height: calc(100vh - 16px) !important;
  border: 1px solid #334155 !important;
  border-radius: 10px !important;
  box-shadow: 0 18px 54px rgba(0,0,0,0.35) !important;
  overflow: hidden !important;
  resize: both;
}
body.theme-light .scholar-ai-sidebar.popup.open { border-color: #cbd5e1 !important; }
.scholar-ai-sidebar.popup .scholar-ai-header { cursor: move; user-select: none; }
.scholar-ai-sidebar.popup .scholar-ai-resize-handle { display: none !important; }

.scholar-ai-resize-handle {
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 8px;
  cursor: col-resize;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  flex-shrink: 0;
}
.scholar-ai-resize-handle:hover { background: rgba(79,142,247,0.08); }
.scholar-ai-resize-handle::before { content: ""; width: 2px; height: 32px; border-radius: 1px; background: rgba(79,142,247,0.35); }
.scholar-ai-resize-handle:hover::before { background: #4f8ef7; opacity: 0.9; }
body.theme-light .scholar-ai-resize-handle::before { background: rgba(79,142,247,0.4); }
body.theme-light .scholar-ai-resize-handle:hover::before { background: #4f8ef7; }

.scholar-ai-sidebar > .scholar-ai-inner {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
  min-height: 0;
  position: relative;
  padding-right: 8px;
}

.scholar-ai-header {
  flex-shrink: 0;
  padding: 8px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #1e2332;
}
body.theme-light .scholar-ai-header { border-color: #cbd5e1; }
.scholar-ai-header h3 { font-size: 13px; color: #4f8ef7; margin: 0; }
.scholar-ai-header .sa-btn { background: #1a1e28; border: 1px solid #2e3447; color: #b0bac8; border-radius: 6px; padding: 4px 10px; font-size: 11px; cursor: pointer; margin-left: 4px; }
body.theme-light .scholar-ai-header .sa-btn { background: #fff; border-color: #94a3b8; color: #475569; }

.scholar-ai-body {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
#scholar-ai-model-panel { flex-shrink: 0; }
#scholar-ai-model-panel label { display: block; margin-bottom: 6px; color: #94a3b8; font-size: 11px; }
#scholar-ai-model-select { min-height: 36px; cursor: pointer; }
.scholar-ai-body label { font-size: 11px; color: #94a3b8; display: block; margin-bottom: 4px; }
.scholar-ai-body textarea {
  width: 100%;
  min-height: 60px;
  padding: 8px;
  font-size: 12px;
  line-height: 1.5;
  border: 1px solid #1e2332;
  border-radius: 6px;
  background: #0c0e13;
  color: #b0bac8;
  resize: vertical;
  box-sizing: border-box;
}
body.theme-light .scholar-ai-body textarea { background: #fff; color: #1e293b; border-color: #e2e8f0; }
.scholar-ai-body .sa-btn.ghost.active { border-color: #4f8ef7; color: #4f8ef7; background: rgba(79,142,247,0.15); }
body.theme-light .scholar-ai-body .sa-btn.ghost.active { border-color: #4f8ef7; color: #4f8ef7; background: rgba(79,142,247,0.2); }

#scholar-ai-pre-prompt-text, .scholar-ai-pre-prompt-ta { color: #fff; }
body.theme-light #scholar-ai-pre-prompt-panel .scholar-ai-pre-prompt-ta,
body.theme-light #scholar-ai-pre-prompt-panel textarea,
body.theme-light #scholar-ai-model-panel select { background: #f1f5f9; color: #1e293b; border-color: #cbd5e1; }
body.theme-light #scholar-ai-pre-prompt-text { color: #1e293b; }

.scholar-ai-prompt-wrap { display: flex; flex-direction: column; height: 120px; min-height: 80px; max-height: 300px; position: relative; flex-shrink: 0; }
.scholar-ai-selected-wrap { display: flex; flex-direction: column; height: 120px; min-height: 80px; max-height: 520px; position: relative; flex-shrink: 0; }
.scholar-ai-selected-wrap #scholar-ai-selected { flex: 1; min-height: 60px; resize: none; }
.scholar-ai-selected-wrap .scholar-ai-selected-resize-handle { height: 12px; cursor: row-resize; background: rgba(79,142,247,0.12); flex-shrink: 0; border-radius: 0 0 4px 4px; border-top: 1px solid rgba(79,142,247,0.22); position: relative; }
.scholar-ai-selected-wrap .scholar-ai-selected-resize-handle:hover { background: rgba(79,142,247,0.35); }
.scholar-ai-selected-wrap .scholar-ai-selected-resize-handle::after { content: ""; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 36px; height: 3px; border-radius: 999px; background: rgba(79,142,247,0.55); }
body.theme-light .scholar-ai-selected-wrap .scholar-ai-selected-resize-handle { background: rgba(79,142,247,0.15); }
body.theme-light .scholar-ai-selected-wrap .scholar-ai-selected-resize-handle:hover { background: rgba(79,142,247,0.3); }
.scholar-ai-prompt-wrap .scholar-ai-prompt-resize-handle { height: 12px; cursor: row-resize; background: rgba(79,142,247,0.12); flex-shrink: 0; border-radius: 0 0 4px 4px; border-top: 1px solid rgba(79,142,247,0.22); position: relative; }
.scholar-ai-prompt-wrap .scholar-ai-prompt-resize-handle:hover { background: rgba(79,142,247,0.35); }
.scholar-ai-prompt-wrap .scholar-ai-prompt-resize-handle::after { content: ""; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 36px; height: 3px; border-radius: 999px; background: rgba(79,142,247,0.55); }
body.theme-light .scholar-ai-prompt-wrap .scholar-ai-prompt-resize-handle { background: rgba(79,142,247,0.15); }
body.theme-light .scholar-ai-prompt-wrap .scholar-ai-prompt-resize-handle:hover { background: rgba(79,142,247,0.3); }
#scholar-ai-prompt-wrap #scholar-ai-prompt { flex: 1; min-height: 60px; resize: none; }

.scholar-ai-result-wrap { display: flex; flex-direction: column; flex: 1; min-height: 200px; max-height: 600px; position: relative; }
.scholar-ai-result-wrap .scholar-ai-result { flex: 1; min-height: 120px; }
.scholar-ai-result-resize-handle { height: 12px; cursor: row-resize; background: rgba(79,142,247,0.12); flex-shrink: 0; border-radius: 0 0 4px 4px; border-top: 1px solid rgba(79,142,247,0.22); position: relative; }
.scholar-ai-result-resize-handle:hover { background: rgba(79,142,247,0.35); }
.scholar-ai-result-resize-handle::after { content: ""; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: 36px; height: 3px; border-radius: 999px; background: rgba(79,142,247,0.55); }
body.theme-light .scholar-ai-result-resize-handle { background: rgba(79,142,247,0.15); }
body.theme-light .scholar-ai-result-resize-handle:hover { background: rgba(79,142,247,0.3); }

.scholar-ai-result-zoom-overlay { position: fixed; inset: 0; z-index: 2147483550; background: rgba(0,0,0,0.5); display: none; align-items: center; justify-content: center; padding: 20px; }
.scholar-ai-result-zoom-overlay.open { display: flex; }
.scholar-ai-result-zoom-box { background: #13161d; border: 1px solid #2e3447; border-radius: 12px; max-width: 90%; max-height: 90%; width: 700px; height: 80vh; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 16px 48px rgba(0,0,0,0.4); }
body.theme-light .scholar-ai-result-zoom-box { background: #fff; border-color: #cbd5e1; }
.scholar-ai-result-zoom-box .scholar-ai-result-zoom-header { flex-shrink: 0; padding: 10px 14px; border-bottom: 1px solid #2e3447; display: flex; justify-content: space-between; align-items: center; }
body.theme-light .scholar-ai-result-zoom-box .scholar-ai-result-zoom-header { border-color: #e2e8f0; }
.scholar-ai-result-zoom-box .scholar-ai-result-zoom-header span { font-size: 13px; color: #94a3b8; }
.scholar-ai-result-zoom-box .scholar-ai-result-zoom-body { flex: 1; min-height: 0; padding: 12px; overflow: auto; }
.scholar-ai-result-zoom-box .scholar-ai-result-zoom-body textarea { width: 100%; height: 100%; min-height: 200px; font-size: 16px; line-height: 1.6; padding: 12px; border: 1px solid #2e3447; border-radius: 8px; background: #0c0e13; color: #e8ecf4; resize: none; box-sizing: border-box; }
body.theme-light .scholar-ai-result-zoom-box .scholar-ai-result-zoom-body textarea { background: #f8fafc; color: #1e293b; border-color: #e2e8f0; }
.scholar-ai-result-zoom-box .scholar-ai-result-zoom-view { width: 100%; height: 100%; min-height: 200px; padding: 12px; border: 1px solid #2e3447; border-radius: 8px; background: #0c0e13; color: #e8ecf4; box-sizing: border-box; overflow: auto; line-height: 1.7; }
body.theme-light .scholar-ai-result-zoom-box .scholar-ai-result-zoom-view { background: #f8fafc; color: #1e293b; border-color: #e2e8f0; }
.scholar-ai-result-zoom-box .scholar-ai-result-zoom-view p { margin: 0 0 0.75em; }
.scholar-ai-result-zoom-box .scholar-ai-result-zoom-view pre { white-space: pre-wrap; overflow-wrap: anywhere; }

.scholar-ai-result { min-height: 260px; font-size: 13px; flex: 1; }

.scholar-ai-footer {
  flex-shrink: 0;
  padding: 8px 10px;
  border-top: 1px solid #1e2332;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
body.theme-light .scholar-ai-footer { border-color: #cbd5e1; }
.scholar-ai-footer .sa-font { font-size: 11px; color: #94a3b8; margin-right: 4px; }
.scholar-ai-footer .sa-btn { background: #4f8ef7; color: #fff; border: none; border-radius: 6px; padding: 5px 10px; font-size: 11px; cursor: pointer; }
.scholar-ai-footer .sa-btn.ghost { background: #1a1e28; border: 1px solid #2e3447; color: #b0bac8; }
body.theme-light .scholar-ai-footer .sa-btn.ghost { background: #fff; border-color: #94a3b8; color: #475569; }

.scholar-ai-insert-wrap { position: relative; display: inline-block; }
.scholar-ai-insert-menu { display: none; position: absolute; bottom: 100%; left: 0; margin-bottom: 4px; background: #13161d; border: 1px solid #2e3447; border-radius: 6px; padding: 4px; min-width: 160px; z-index: 10; }
.scholar-ai-insert-menu.open { display: block; }
.scholar-ai-insert-menu button { display: block; width: 100%; text-align: left; padding: 6px 10px; font-size: 12px; border: none; background: none; color: #b0bac8; cursor: pointer; border-radius: 4px; }
.scholar-ai-insert-menu button:hover { background: #252a37; color: #fff; }

.scholar-ai-history { flex-shrink: 0; padding: 8px 10px; border-top: 1px solid #1e2332; display: flex; flex-direction: column; gap: 6px; max-height: 200px; min-height: 0; }
body.theme-light .scholar-ai-history { border-top-color: #cbd5e1; }
.scholar-ai-history label { font-size: 11px; color: #94a3b8; margin: 0; }
.scholar-ai-history-search { width: 100%; padding: 6px 8px; font-size: 11px; border: 1px solid #1e2332; border-radius: 4px; background: #0c0e13; color: #b0bac8; box-sizing: border-box; }
body.theme-light .scholar-ai-history-search { background: #fff; border-color: #e2e8f0; color: #1e293b; }
.scholar-ai-history-list { overflow-y: auto; flex: 1; min-height: 60px; max-height: 120px; }
.scholar-ai-history-item { display: flex; align-items: center; gap: 6px; padding: 6px 8px; margin-bottom: 4px; background: #1a1e28; border: 1px solid #2e3447; border-radius: 4px; font-size: 11px; color: #b0bac8; }
body.theme-light .scholar-ai-history-item { background: #f1f5f9; border-color: #cbd5e1; color: #475569; }
.scholar-ai-history-item .sa-h-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.scholar-ai-history-item .sa-h-save { padding: 2px 6px; font-size: 10px; cursor: pointer; border: none; border-radius: 4px; background: #4f8ef7; color: #fff; }
.scholar-ai-history-item .sa-h-del { padding: 2px 6px; font-size: 10px; cursor: pointer; border: none; border-radius: 4px; background: #64748b; color: #fff; }
.scholar-ai-history-item .sa-h-del:hover { background: #ef4444; }

/* ========== SSPAI Sidebar (우측 도킹 영역 안, ScholarAI 오른쪽) ========== */
.ssp-ai-sidebar {
  width: 0;
  min-width: 0;
  overflow: hidden;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: #13161d;
  border-right: 1px solid #1e2332;
  transition: min-width 0.2s;
  position: relative;
}
body.theme-light .ssp-ai-sidebar { background: #e2e8f0; border-right-color: #cbd5e1; }
.ssp-ai-sidebar.open { min-width: 320px; width: 400px; max-width: 90vw; }
.ssp-ai-sidebar.popup.open {
  position: fixed !important;
  z-index: 2147483450 !important;
  left: auto;
  right: auto;
  top: auto;
  bottom: auto;
  width: 420px !important;
  min-width: 320px !important;
  max-width: min(94vw, 920px) !important;
  height: 80vh !important;
  min-height: 280px !important;
  max-height: calc(100vh - 16px) !important;
  border: 1px solid #334155 !important;
  border-radius: 10px !important;
  box-shadow: 0 18px 54px rgba(0,0,0,0.35) !important;
  overflow: hidden !important;
  resize: both;
}
body.theme-light .ssp-ai-sidebar.popup.open { border-color: #cbd5e1 !important; }
.ssp-ai-sidebar.popup .ssp-header { cursor: move; user-select: none; }

.ssp-ai-sidebar .ssp-inner { display: flex; flex-direction: column; flex: 1; min-width: 0; min-height: 0; padding: 10px; overflow: hidden; --ssp-main-size: 62%; }
.ssp-ai-sidebar .ssp-main { flex: 0 0 var(--ssp-main-size, 62%); min-height: 160px; overflow-y: auto; }
.ssp-ai-sidebar .ssp-header { flex-shrink: 0; padding: 8px 0; border-bottom: 1px solid #1e2332; margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }
body.theme-light .ssp-ai-sidebar .ssp-header { border-color: #cbd5e1; }
.ssp-ai-sidebar .ssp-header h3 { font-size: 13px; color: #f59e0b; margin: 0; }

.ssp-ai-sidebar .ssp-upload { border: 2px dashed #2e3447; border-radius: 8px; padding: 16px; text-align: center; font-size: 11px; color: #94a3b8; cursor: pointer; margin-bottom: 8px; min-height: 60px; max-height: 160px; overflow: hidden; flex-shrink: 0; }
body.theme-light .ssp-ai-sidebar .ssp-upload { border-color: #cbd5e1; color: #64748b; }
.ssp-ai-sidebar .ssp-upload:hover { border-color: #f59e0b; color: #f59e0b; }

.ssp-ai-sidebar label { font-size: 10px; color: #94a3b8; display: block; margin-bottom: 4px; }
.ssp-ai-sidebar select, .ssp-ai-sidebar textarea { width: 100%; padding: 6px 8px; font-size: 11px; border: 1px solid #1e2332; border-radius: 4px; background: #0c0e13; color: #b0bac8; box-sizing: border-box; margin-bottom: 8px; }
body.theme-light .ssp-ai-sidebar select, body.theme-light .ssp-ai-sidebar textarea { background: #fff; color: #1e293b; border-color: #e2e8f0; }
.ssp-ai-sidebar textarea { min-height: 56px; resize: vertical; max-height: none; flex-shrink: 0; }

.ssp-action-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.ssp-btn-generate { background: #f59e0b !important; color: #fff !important; border: none !important; padding: 6px 12px !important; border-radius: 6px !important; cursor: pointer; font-size: 12px !important; }
.ssp-btn-imgbb { background: #0d9488 !important; color: #fff !important; border: none !important; padding: 6px 12px !important; border-radius: 6px !important; cursor: pointer; font-size: 12px !important; }
.ssp-btn-imgbb:hover { background: #0f766e !important; }
.ssp-img-link-label { font-size: 10px; color: #94a3b8; display: block; margin: 10px 0 4px; }
.ssp-img-link-row { display: grid; grid-template-columns: repeat(2, minmax(0, max-content)); gap: 6px; align-items: stretch; margin-bottom: 4px; }
.ssp-image-link-input { grid-column: 1 / -1; width: 100%; min-width: 120px; padding: 6px 8px; font-size: 10px; border: 1px solid #1e2332; border-radius: 4px; background: #0c0e13; color: #b0bac8; box-sizing: border-box; }
body.theme-light .ssp-image-link-input { background: #fff; color: #1e293b; border-color: #e2e8f0; }
.ssp-btn-insert-md, .ssp-btn-insert-html { font-size: 10px !important; padding: 6px 10px !important; min-width: 72px; }

.ssp-ai-sidebar .ssp-ratio-wrap { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.ssp-ai-sidebar .ssp-ratio-btn { padding: 4px 10px; font-size: 10px; border: 1px solid #2e3447; border-radius: 4px; background: #1a1e28; color: #94a3b8; cursor: pointer; }
.ssp-ai-sidebar .ssp-ratio-btn.active { border-color: #f59e0b; color: #f59e0b; background: rgba(245,158,11,0.15); }

.ssp-ai-sidebar .ssp-result { max-width: 100%; max-height: 200px; width: auto; height: auto; object-fit: contain; border-radius: 6px; margin-top: 8px; display: block; cursor: pointer; }
.ssp-ai-sidebar .ssp-status { font-size: 10px; color: #94a3b8; margin-top: 6px; }
.ssp-ai-sidebar .ssp-seed-loaded { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.ssp-ai-sidebar .ssp-seed-loaded img { max-width: 100%; max-height: 100px; border-radius: 6px; object-fit: contain; cursor: pointer; }
.ssp-ai-sidebar .ssp-seed-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }

.ssp-ai-sidebar .ssp-progress-wrap { margin-top: 8px; display: none; flex-direction: column; gap: 6px; }
.ssp-ai-sidebar .ssp-progress-wrap.visible { display: flex; }
.ssp-ai-sidebar .ssp-progress-bar { height: 8px; background: #1e2332; border-radius: 4px; overflow: hidden; }
body.theme-light .ssp-ai-sidebar .ssp-progress-bar { background: #e2e8f0; }
.ssp-ai-sidebar .ssp-progress-fill { height: 100%; width: 0%; background: #f59e0b; transition: width 0.3s ease; }
.ssp-ai-sidebar .ssp-progress-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.ssp-ai-sidebar .ssp-history-resizer { height: 10px; flex-shrink: 0; margin: 8px 0 6px; border-top: 1px solid #94a3b8; border-bottom: 1px solid rgba(148,163,184,0.2); cursor: row-resize; position: relative; }
.ssp-ai-sidebar .ssp-history-resizer::after { content: ""; position: absolute; left: 50%; top: 50%; width: 44px; height: 4px; transform: translate(-50%, -50%); border-radius: 999px; background: rgba(100,116,139,0.45); }
body.theme-light .ssp-ai-sidebar .ssp-history-resizer { border-top-color: #94a3b8; }
.ssp-ai-sidebar .ssp-img-history { flex: 1 1 auto; min-height: 120px; display: flex; flex-direction: column; overflow: hidden; }
.ssp-ai-sidebar .ssp-img-history-list { display: flex; flex-direction: column; gap: 6px; flex: 1; min-height: 0; overflow-y: auto; }
.ssp-ai-sidebar .ssp-img-history-item { display: flex; align-items: center; gap: 6px; padding: 4px 6px; background: #1a1e28; border-radius: 4px; font-size: 10px; }
body.theme-light .ssp-ai-sidebar .ssp-img-history-item { background: #e2e8f0; }
.ssp-ai-sidebar .ssp-img-history-item img { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; cursor: pointer; flex-shrink: 0; }
.ssp-ai-sidebar .ssp-img-history-item .ssp-h-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #94a3b8; }
body.theme-light .ssp-ai-sidebar .ssp-img-history-item .ssp-h-label { color: #64748b; }
.ssp-ai-sidebar .ssp-img-history-item .ssp-h-del { width: 20px; height: 20px; padding: 0; border: none; background: #475569; color: #fff; border-radius: 4px; cursor: pointer; font-size: 12px; line-height: 1; flex-shrink: 0; }
.ssp-ai-sidebar .ssp-img-history-item .ssp-h-del:hover { background: #f87171; }

/* SSP Fullscreen overlay */
.viewer-fs-overlay { position: fixed; inset: 0; z-index: 2147483600; background: rgba(0,0,0,0.9); display: none; flex-direction: column; align-items: center; justify-content: center; }
.viewer-fs-overlay.open { display: flex; }
.viewer-fs-toolbar { position: absolute; top: 12px; right: 12px; z-index: 10001; display: flex; gap: 6px; align-items: center; background: #323234; padding: 8px 12px; border-radius: 10px; border: 1px solid #555; }
.viewer-fs-toolbar button { padding: 6px 10px; border-radius: 6px; border: 1px solid #555; background: #454545; color: #ddd; cursor: pointer; font-size: 12px; }
.viewer-fs-toolbar button:hover { background: #555; color: #fff; border-color: #4f8ef7; }
.viewer-fs-insert-btn { display: none !important; }
.viewer-fs-gallery { position: absolute; top: 72px; left: 16px; bottom: 16px; width: 210px; z-index: 10000; display: flex; flex-direction: column; gap: 10px; padding: 12px; border-radius: 16px; background: rgba(15,23,42,0.82); border: 1px solid rgba(148,163,184,0.28); box-shadow: 0 16px 36px rgba(0,0,0,0.25); backdrop-filter: blur(10px); }
.viewer-fs-gallery-title { font-size: 12px; font-weight: 800; color: #e2e8f0; letter-spacing: 0.03em; }
.viewer-fs-gallery-list { flex: 1; min-height: 0; overflow-y: auto; display: grid; gap: 8px; }
.viewer-fs-gallery-item { display: grid; grid-template-columns: 52px 1fr; gap: 8px; align-items: center; padding: 6px; border-radius: 12px; border: 1px solid rgba(148,163,184,0.2); background: rgba(30,41,59,0.82); cursor: pointer; color: #cbd5e1; text-align: left; }
.viewer-fs-gallery-item.active { border-color: rgba(96,165,250,0.85); box-shadow: 0 0 0 1px rgba(96,165,250,0.35) inset; }
.viewer-fs-gallery-item img { width: 52px; height: 52px; object-fit: cover; border-radius: 10px; background: #fff; }
.viewer-fs-gallery-meta { min-width: 0; display: grid; gap: 3px; }
.viewer-fs-gallery-label { font-size: 11px; font-weight: 700; color: #f8fafc; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-fs-gallery-time { font-size: 10px; color: #94a3b8; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-fs-area { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; cursor: grab; padding: 60px 16px 16px 248px; }
.viewer-fs-overlay.gallery-hidden .viewer-fs-area { padding-left: 16px; }
.viewer-fs-area:active { cursor: grabbing; }
.viewer-fs-wrap { transform-origin: center center; transition: transform 0.08s ease-out; line-height: 0; }
.viewer-fs-wrap img { max-width: min(95vw, calc(100vw - 32px)); max-height: min(95vh, calc(100vh - 80px)); width: auto; height: auto; object-fit: contain; display: block; pointer-events: none; border-radius: 8px; box-shadow: 0 8px 40px rgba(0,0,0,0.4); background: #fff; }
.viewer-fs-imgbb-info { position: absolute; top: 68px; right: 14px; left: auto; width: min(390px, calc(100vw - 284px)); z-index: 10000; display: none; padding: 8px; border-radius: 9px; background: rgba(15, 23, 42, 0.92); border: 1px solid rgba(148, 163, 184, 0.3); color: #e2e8f0; box-shadow: 0 10px 24px rgba(0, 0, 0, 0.22); backdrop-filter: blur(10px); }
.viewer-fs-overlay.gallery-hidden .viewer-fs-imgbb-info { width: min(390px, calc(100vw - 28px)); }
.viewer-fs-imgbb-title { font-size: 9px; font-weight: 800; margin-bottom: 5px; letter-spacing: 0.02em; }
.viewer-fs-link-grid { display: grid; gap: 6px; }
.viewer-fs-link-field { display: grid; gap: 2px; }
.viewer-fs-link-label { font-size: 8px; font-weight: 700; color: #cbd5e1; text-transform: uppercase; letter-spacing: 0.04em; }
.viewer-fs-link-input-wrap { display: flex; gap: 5px; align-items: center; }
.viewer-fs-link-input-wrap input { flex: 1; min-width: 0; max-width: none; height: 20px; padding: 1px 6px; border-radius: 5px; border: 1px solid rgba(148, 163, 184, 0.42); background: rgba(15, 23, 42, 0.72); color: #f8fafc; font-size: 8px; line-height: 1.1; }
.viewer-fs-link-insert { flex-shrink: 0; height: 20px; padding: 0 7px; border-radius: 5px; border: 1px solid rgba(45, 212, 191, 0.45); color: #99f6e4; background: rgba(13, 148, 136, 0.12); text-decoration: none; font-size: 8px; font-weight: 700; cursor: pointer; }
.viewer-fs-link-insert:hover { background: rgba(13, 148, 136, 0.22); color: #ccfbf1; }
.viewer-fs-link-open { flex-shrink: 0; height: 20px; display: inline-flex; align-items: center; justify-content: center; padding: 0 7px; border-radius: 5px; border: 1px solid rgba(96, 165, 250, 0.45); color: #bfdbfe; text-decoration: none; font-size: 8px; font-weight: 700; }
.viewer-fs-link-open:hover { background: rgba(59, 130, 246, 0.16); color: #dbeafe; }
.viewer-fs-imgbb-saved { margin-top: 5px; font-size: 8px; color: #cbd5e1; }

@media (max-width: 640px) {
  .ssp-img-link-row { grid-template-columns: 1fr; }
  .viewer-fs-toolbar { left: 12px; right: 12px; top: 12px; flex-wrap: wrap; justify-content: center; }
  .viewer-fs-gallery { display: none; }
  .viewer-fs-area { padding-left: 16px; }
  .viewer-fs-imgbb-info { top: 108px; left: 16px; right: 16px; width: auto; }
  .viewer-fs-link-input-wrap { flex-direction: column; align-items: stretch; }
  .viewer-fs-link-open { text-align: center; }
}

/* App font-size sync (follow main app font controls) */
:root {
  --md-app-font-size: 16px;
  --ai-font-base: clamp(12px, calc(var(--md-app-font-size, 16px) * 0.84), 22px);
  --ai-font-sm: calc(var(--ai-font-base) * 0.9);
  --ai-font-xs: calc(var(--ai-font-base) * 0.82);
  --ai-font-lg: calc(var(--ai-font-base) * 1.08);
}

.scholar-ai-sidebar,
.ssp-ai-sidebar,
.viewer-fs-overlay {
  font-size: var(--ai-font-base);
}

.scholar-ai-header h3,
.ssp-ai-sidebar .ssp-header h3 {
  font-size: var(--ai-font-lg);
}

.scholar-ai-body label,
#scholar-ai-model-panel label,
.scholar-ai-history label,
.ssp-ai-sidebar label,
.ssp-img-link-label,
.ssp-ai-sidebar .ssp-status,
.viewer-fs-gallery-title,
.viewer-fs-gallery-label {
  font-size: var(--ai-font-sm) !important;
}

.scholar-ai-header .sa-btn,
.scholar-ai-footer .sa-btn,
.scholar-ai-insert-menu button,
.scholar-ai-history-search,
.scholar-ai-history-item,
.scholar-ai-history-item .sa-h-save,
.scholar-ai-history-item .sa-h-del,
.ssp-ai-sidebar select,
.ssp-ai-sidebar textarea,
.ssp-ai-sidebar .ssp-upload,
.ssp-btn-generate,
.ssp-btn-imgbb,
.ssp-btn-insert-md,
.ssp-btn-insert-html,
.ssp-image-link-input,
.ssp-ai-sidebar .ssp-ratio-btn,
.viewer-fs-toolbar button,
.viewer-fs-gallery-time {
  font-size: var(--ai-font-sm) !important;
}

.scholar-ai-body textarea,
.scholar-ai-result,
.scholar-ai-result-zoom-box .scholar-ai-result-zoom-body textarea,
.scholar-ai-result-zoom-box .scholar-ai-result-zoom-view {
  font-size: var(--ai-font-base) !important;
}

/* Override inline tiny-size declarations in injected HTML */
#sa-pre-prompt-btn,
#sa-model-btn,
#scholar-ai-pre-prompt-text,
#scholar-ai-model-select,
#scholar-ai-run-btn,
#scholar-ai-stop-btn,
#scholar-ai-zoom-label,
#scholar-ai-zoom-mode-edit,
#scholar-ai-zoom-mode-view,
#ssp-progress-pct,
#ssp-progress-wrap .sa-btn,
#ssp-imgbb-settings label,
#ssp-imgbb-settings-status,
#viewer-fs-zoom-val {
  font-size: var(--ai-font-sm) !important;
}

.scholar-ai-footer .sa-font {
  font-size: var(--ai-font-xs) !important;
}

/* Purple theme alignment (keep imgBB green) */
:root {
  --md-ai-purple: #4f46e5;
  --md-ai-purple-strong: #4338ca;
  --md-ai-purple-soft: #eef2ff;
  --md-ai-purple-border: #c7d2fe;
}

body.theme-light .scholar-ai-header h3,
body.theme-light .ssp-ai-sidebar .ssp-header h3 {
  color: var(--md-ai-purple);
  font-weight: 800;
}

body.theme-light .scholar-ai-body label,
body.theme-light #scholar-ai-model-panel label,
body.theme-light .scholar-ai-history label,
body.theme-light .ssp-ai-sidebar label,
body.theme-light .ssp-img-link-label,
body.theme-light .ssp-ai-sidebar .ssp-status {
  color: #64748b;
  font-weight: 700;
}

.scholar-ai-sidebar .sa-btn,
.ssp-ai-sidebar .sa-btn,
.viewer-fs-toolbar button {
  font-weight: 700;
}

body.theme-light .scholar-ai-sidebar .sa-btn:not(.ghost),
body.theme-light .ssp-ai-sidebar .sa-btn:not(.ghost),
body.theme-light #scholar-ai-run-btn,
body.theme-light .ssp-btn-generate {
  background: var(--md-ai-purple) !important;
  border-color: var(--md-ai-purple) !important;
  color: #ffffff !important;
}

body.theme-light .scholar-ai-sidebar .sa-btn:not(.ghost):hover,
body.theme-light .ssp-ai-sidebar .sa-btn:not(.ghost):hover,
body.theme-light #scholar-ai-run-btn:hover,
body.theme-light .ssp-btn-generate:hover {
  background: var(--md-ai-purple-strong) !important;
  border-color: var(--md-ai-purple-strong) !important;
}

body.theme-light .scholar-ai-sidebar .sa-btn.ghost,
body.theme-light .ssp-ai-sidebar .sa-btn.ghost {
  background: var(--md-ai-purple-soft) !important;
  border: 1px solid var(--md-ai-purple-border) !important;
  color: var(--md-ai-purple-strong) !important;
}

body.theme-light .scholar-ai-sidebar .sa-btn.ghost:hover,
body.theme-light .ssp-ai-sidebar .sa-btn.ghost:hover {
  background: #e0e7ff !important;
  border-color: #a5b4fc !important;
}

body.theme-light .scholar-ai-body .sa-btn.ghost.active {
  border-color: var(--md-ai-purple) !important;
  color: var(--md-ai-purple) !important;
  background: #e0e7ff !important;
}

body.theme-light .ssp-ai-sidebar .ssp-ratio-btn.active {
  border-color: var(--md-ai-purple) !important;
  color: var(--md-ai-purple) !important;
  background: rgba(79, 70, 229, 0.16) !important;
}

/* Keep imgBB actions green */
body.theme-light .ssp-btn-imgbb,
body.theme-light .ssp-btn-imgbb:hover,
body.theme-light .viewer-fs-imgbb-btn,
body.theme-light .viewer-fs-imgbb-btn:hover,
body.theme-light .ssp-h-upload,
body.theme-light .ssp-h-upload:hover {
  background: #0d9488 !important;
  border-color: #0f766e !important;
  color: #ffffff !important;
}
