/* ============================================================
   AI PPT Generator — Minimal, clean, ChatGPT-inspired layout
   ============================================================ */

:root {
  --sidebar-w: 260px;
  --topbar-h: 52px;
  --input-h: 72px;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --bg-sidebar: #f9fafb;
  --bg-main: #ffffff;
  --bg-chat: #f7f8fa;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --text-sidebar: #374151;
  --bubble-user: #2563eb;
  --bubble-user-text: #ffffff;
  --bubble-assistant: #ffffff;
  --bubble-assistant-text: #111827;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg-main);
  overflow: hidden;
}

/* ---------- Layout ---------- */
body {
  display: flex;
}

#sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: margin-left 0.25s ease, opacity 0.25s ease;
  z-index: 10;
}
#sidebar.collapsed {
  margin-left: calc(-1 * var(--sidebar-w));
  opacity: 0;
}

#sidebar-header {
  padding: 12px;
  border-bottom: 1px solid var(--border);
}
#btn-new-chat {
  width: 100%;
  padding: 10px 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-main);
  font-size: 14px;
  cursor: pointer;
  color: var(--text);
  transition: background 0.15s;
}
#btn-new-chat:hover { background: var(--bg-chat); }

#conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.conv-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  margin-bottom: 2px;
  transition: background 0.15s;
  font-size: 14px;
  color: var(--text-sidebar);
  position: relative;
}
.conv-item:hover { background: #e5e7eb; }
.conv-item.active { background: #dbeafe; color: var(--accent); font-weight: 500; }
.conv-item .conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.conv-item .conv-delete {
  opacity: 0;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0 4px;
  line-height: 1;
  transition: opacity 0.15s, color 0.15s;
}
.conv-item:hover .conv-delete { opacity: 1; }
.conv-item .conv-delete:hover { color: #ef4444; }

#sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  text-align: center;
}
.version { font-size: 11px; color: var(--text-muted); }

/* ---------- Main area ---------- */
#main {
  flex: 1;
  height: 100vh;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

#topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  background: var(--bg-main);
}
#btn-toggle-sidebar {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px 8px;
  flex-shrink: 0;
}
.logo {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 16px;
}
.topbar-spacer {
  width: 36px; /* balance the toggle button width */
  flex-shrink: 0;
}

/* ---------- Chat area ---------- */
#chat-area {
  flex: 1;
  overflow-y: auto;
  background: var(--bg-chat);
  padding: 20px 0;
}

#messages {
  max-width: 800px;
  margin: 0 auto;
  padding: 0 24px;
}

/* Welcome state */
.welcome {
  text-align: center;
  max-width: 540px;
  margin: 80px auto;
  padding: 0 24px;
}
.welcome h2 {
  font-size: 26px;
  font-weight: 600;
  margin-bottom: 8px;
}
.welcome p {
  color: var(--text-muted);
  margin-bottom: 32px;
  font-size: 15px;
}
.suggestions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.suggestion {
  text-align: left;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-main);
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: border-color 0.15s;
}
.suggestion:hover { border-color: var(--accent); }

/* Messages */
.message {
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
}
.message.user { align-items: flex-end; }
.message.assistant { align-items: flex-start; }
.msg-bubble {
  max-width: 85%;
  padding: 12px 18px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}
.message.user .msg-bubble {
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}
.message.assistant .msg-bubble {
  background: var(--bubble-assistant);
  color: var(--bubble-assistant-text);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
}

/* Loading animation */
.msg-bubble.loading {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 200px;
}
.loading-dots span {
  animation: blink 1.4s infinite both;
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
  line-height: 1;
}
.loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.loading-dots span:nth-child(3) { animation-delay: 0.4s; }
.loading-text {
  font-size: 14px;
  color: var(--text-muted);
}
@keyframes blink {
  0%, 80%, 100% { opacity: 0.2; }
  40% { opacity: 1; }
}

/* ---------- PPT Preview ---------- */
.msg-ppt {
  margin-top: 12px;
  max-width: 95%;
}

.ppt-preview {
  background: var(--bubble-assistant);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.ppt-viewport {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #1a1a2e;
  position: relative;
  overflow: hidden;
}

/* Slide render */
.slide-render {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  padding: 40px 56px;
  font-family: var(--font);
}
.slide-render.theme-dark { color: #ffffff; }
.slide-render.theme-light { color: #111827; }

.slide-render .accent-bar {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 3px;
}
.slide-render.theme-dark .accent-bar { background: #e94560; }
.slide-render.theme-light .accent-bar { background: #2563eb; }

/* slide type: title */
.slide-render.title {
  justify-content: center;
  padding: 48px 64px;
}
.slide-render.title .s-title {
  font-size: clamp(18px, 3vw, 36px);
  font-weight: 700;
  line-height: 1.3;
}
.slide-render.title .s-subtitle {
  margin-top: 16px;
  font-size: clamp(12px, 1.5vw, 18px);
  opacity: 0.7;
}
.slide-render.title .s-divider {
  margin-top: 24px;
  width: 60px;
  height: 3px;
}
.slide-render.theme-dark .s-divider { background: #e94560; }
.slide-render.theme-light .s-divider { background: #2563eb; }

/* slide type: section */
.slide-render.section {
  justify-content: center;
  align-items: center;
  text-align: center;
}
.slide-render.section .s-title {
  font-size: clamp(20px, 3.5vw, 40px);
  font-weight: 700;
}
.slide-render.section .s-subtitle {
  margin-top: 12px;
  font-size: clamp(12px, 1.5vw, 16px);
  opacity: 0.6;
}

/* slide type: content */
.slide-render.content .s-title {
  font-size: clamp(14px, 2vw, 24px);
  font-weight: 600;
  margin-bottom: 20px;
}
.slide-render.content .s-body {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.slide-render.content .s-body li {
  font-size: clamp(10px, 1.4vw, 15px);
  line-height: 1.5;
  opacity: 0.85;
  padding-left: 20px;
  position: relative;
}
.slide-render.content .s-body li::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.slide-render.theme-dark .s-body li::before { background: #e94560; }
.slide-render.theme-light .s-body li::before { background: #2563eb; }

/* slide type: stats */
.slide-render.stats .s-title {
  font-size: clamp(14px, 2vw, 24px);
  font-weight: 600;
  margin-bottom: 24px;
}
.slide-render.stats .s-items {
  display: flex;
  gap: 16px;
  justify-content: center;
}
.slide-render.stats .s-items .stat-card {
  flex: 1;
  text-align: center;
  padding: 20px 12px;
  border-radius: 8px;
}
.slide-render.theme-dark .stat-card { background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.1); }
.slide-render.theme-light .stat-card { background: #f3f4f6; border: 1px solid #e5e7eb; }
.stat-card .stat-value {
  font-size: clamp(18px, 2.5vw, 30px);
  font-weight: 700;
}
.slide-render.theme-dark .stat-value { color: #e94560; }
.slide-render.theme-light .stat-value { color: #2563eb; }
.stat-card .stat-label {
  margin-top: 6px;
  font-size: clamp(10px, 1.2vw, 14px);
  opacity: 0.8;
}

/* Controls */
.ppt-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 16px;
  background: var(--bg-main);
  border-top: 1px solid var(--border);
}
.ppt-controls button {
  background: var(--bg-chat);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: background 0.15s;
}
.ppt-controls button:hover { background: #e5e7eb; }
.ppt-controls button:disabled { opacity: 0.4; cursor: not-allowed; }
.ppt-page-indicator {
  font-size: 13px;
  color: var(--text-muted);
  min-width: 48px;
  text-align: center;
}
.ppt-download {
  background: var(--accent) !important;
  color: #fff !important;
  text-decoration: none;
  border-radius: var(--radius-sm);
  padding: 6px 14px;
  font-size: 14px;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
}
.ppt-download:hover { background: var(--accent-hover) !important; }

/* ---------- Input area ---------- */
#input-area {
  border-top: 1px solid var(--border);
  background: var(--bg-main);
  padding: 10px 16px 8px;
}

#input-options {
  max-width: 800px;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
}

/* Unified pill button (PPT toggle + Model select) */
.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 30px;
  padding: 0 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  outline: none;
}
.pill.active {
  background: #dbeafe;
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 500;
}
.pill:hover {
  border-color: var(--accent);
}

/* Model dropdown */
#model-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  margin-top: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  z-index: 200;
  min-width: 200px;
  overflow: hidden;
}
#model-dropdown.hidden { display: none; }
.model-option {
  display: block;
  width: 100%;
  padding: 10px 16px;
  border: none;
  background: none;
  text-align: left;
  font-size: 13px;
  font-family: var(--font);
  cursor: pointer;
  transition: background 0.1s;
}
.model-option:hover { background: #f3f4f6; }
.model-option.selected { background: #dbeafe; color: var(--accent); font-weight: 500; }
.model-option .model-desc {
  display: block;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  margin-top: 1px;
}

#input-options {
  max-width: 800px;
  margin: 0 auto 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  position: relative;
}
#input-wrapper {
  max-width: 800px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--bg-chat);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
#input-wrapper:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
#user-input {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 15px;
  font-family: var(--font);
  color: var(--text);
  resize: none;
  outline: none;
  line-height: 1.5;
  max-height: 150px;
}
#btn-send {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, opacity 0.15s;
}
#btn-send:hover { background: var(--accent-hover); }
#btn-send:disabled { opacity: 0.5; cursor: not-allowed; }
#btn-send svg { width: 18px; height: 18px; }
.input-hint {
  text-align: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #9ca3af; }

/* ---------- Sidebar overlay (mobile) ---------- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 99;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  :root {
    --sidebar-w: 240px;
  }

  /* Safe area for mobile browser chrome */
  #topbar {
    position: relative;
    z-index: 101;
    padding-top: env(safe-area-inset-top, 0px);
    min-height: calc(var(--topbar-h) + env(safe-area-inset-top, 0px));
  }
  #chat-area {
    padding-top: 8px;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 100;
    padding-top: env(safe-area-inset-top, 0px);
    box-shadow: 2px 0 16px rgba(0,0,0,0.15);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
  }
  #sidebar.open {
    transform: translateX(0);
  }
  .sidebar-overlay.visible { display: block; }

  #messages { padding: 0 12px; }
  .msg-bubble { max-width: 94%; font-size: 14px; }

  /* Tighter input on mobile */
  #input-area {
    padding: 8px 8px max(6px, env(safe-area-inset-bottom, 6px));
  }
  #input-options { gap: 6px; }
  #input-hint { font-size: 10px; }
  .pill { height: 28px; padding: 0 12px; font-size: 12px; }
  #model-dropdown { min-width: 170px; }

  /* PPT preview compact */
  .ppt-preview .s-items { flex-wrap: wrap; gap: 8px; }
  .ppt-viewport { aspect-ratio: auto; min-height: 180px; }
  .slide-render { padding: 20px 24px; }
  .slide-render.title .s-title { font-size: 18px; }
  .slide-render.content .s-title { font-size: 15px; }
  .slide-render.content .s-body li { font-size: 12px; }
  .slide-render.section .s-title { font-size: 20px; }
  .slide-render.stats .s-items { flex-direction: column; }
  .stat-card .stat-value { font-size: 22px; }
  .ppt-controls { gap: 8px; padding: 8px 12px; }
  .ppt-controls button { padding: 4px 10px; font-size: 12px; }

  .welcome h2 { font-size: 20px; }
  .welcome p { font-size: 13px; }
  .suggestion { font-size: 13px; padding: 12px 14px; }
}
