/* Tharathip — Premium Glassmorphism Theme CSS */
:root {
  --font-ui: "Poppins", "Sarabun", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-sans: "Poppins", "Sarabun", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  /* Glassmorphism Dark Palette */
  --bg-main: #0c0d12;
  --bg-sidebar: rgba(18, 20, 26, 0.72);
  --bg-surface: rgba(25, 27, 34, 0.65);
  --bg-surface-hover: rgba(255, 255, 255, 0.08);
  --bg-surface-active: rgba(255, 255, 255, 0.12);
  --bg-pill: rgba(25, 27, 34, 0.65);
  --bg-popover: rgba(26, 28, 36, 0.88);
  --bg-modal: rgba(20, 22, 29, 0.85);

  --border: rgba(255, 255, 255, 0.09);
  --border-muted: rgba(255, 255, 255, 0.05);
  --border-strong: rgba(255, 255, 255, 0.16);
  --border-glass: rgba(255, 255, 255, 0.12);

  --fg-primary: #f0f2f5;
  --fg-secondary: #c8cbd0;
  --fg-muted: #8b909a;
  --fg-subtle: #636873;

  --accent-blue: #4493f8;
  --accent-star: linear-gradient(135deg, #4285F4 0%, #9B72CB 50%, #D96570 85%, #F4B400 100%);
  --accent-pink: #d93b77;
  --danger: #f85149;
  --success: #3fb950;

  --blur-sidebar: blur(24px) saturate(190%);
  --blur-pill: blur(28px) saturate(190%);
  --blur-popover: blur(32px) saturate(200%);
  --blur-modal: blur(36px) saturate(200%);

  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.65);
  --shadow-pill: 0 10px 36px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

[data-theme="light"] {
  --bg-main: #f4f6f9;
  --bg-sidebar: rgba(248, 250, 252, 0.78);
  --bg-surface: rgba(255, 255, 255, 0.75);
  --bg-surface-hover: rgba(0, 0, 0, 0.05);
  --bg-surface-active: rgba(0, 0, 0, 0.08);
  --bg-pill: rgba(255, 255, 255, 0.85);
  --bg-popover: rgba(255, 255, 255, 0.92);
  --bg-modal: rgba(255, 255, 255, 0.95);

  --border: rgba(0, 0, 0, 0.08);
  --border-muted: rgba(0, 0, 0, 0.04);
  --border-strong: rgba(0, 0, 0, 0.15);
  --border-glass: rgba(0, 0, 0, 0.08);

  --fg-primary: #181a1f;
  --fg-secondary: #3e4249;
  --fg-muted: #6b7280;
  --fg-subtle: #9ca3af;

  --shadow-sm: 0 4px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.12);
  --shadow-pill: 0 10px 36px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

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

html, body {
  height: 100%;
  width: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg-primary);
  background: var(--bg-main);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: transparent;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: var(--fg-primary);
}

a {
  color: var(--accent-blue);
  text-decoration: none;
}
a:hover {
  text-decoration: underline;
}

/* Lucide Icon Sizing Helpers */
svg.lucide, [data-lucide] {
  width: 18px;
  height: 18px;
  stroke-width: 2;
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  color: var(--fg-secondary);
  transition: all 0.15s ease;
}
.icon-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--fg-primary);
  transform: scale(1.04);
}

/* ---------- App Layout ---------- */
#app {
  display: none;
  height: 100vh;
  width: 100vw;
  display: flex;
}
#app:not(.visible) {
  display: none;
}

/* ---------- Glassmorphic Sidebar ---------- */
.sidebar {
  width: 270px;
  min-width: 270px;
  height: 100%;
  background: var(--bg-sidebar);
  backdrop-filter: var(--blur-sidebar);
  -webkit-backdrop-filter: var(--blur-sidebar);
  border-right: 1px solid var(--border-glass);
  display: flex;
  flex-direction: column;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              min-width 0.25s cubic-bezier(0.4, 0, 0.2, 1),
              opacity 0.2s ease,
              transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  overflow: hidden;
  z-index: 40;
  position: relative;
}

.sidebar.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  opacity: 0;
  pointer-events: none;
  border-right: none;
}

.sidebar-header {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-logo {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
}
.brand-logo svg {
  width: 100%;
  height: 100%;
}

.brand-name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.2px;
  color: var(--fg-primary);
}

.sidebar-nav {
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 14px;
  border-radius: 20px;
  color: var(--fg-secondary);
  font-size: 14px;
  font-weight: 400;
  transition: all 0.15s ease;
  width: 100%;
  text-align: left;
}
.nav-item:hover {
  background: var(--bg-surface-hover);
  color: var(--fg-primary);
}
.nav-item.active {
  background: var(--bg-surface-hover);
  color: var(--fg-primary);
  font-weight: 500;
}

/* Sidebar Search Box (Glass) */
.sidebar-search-box {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  padding: 6px 12px;
  margin: 4px 0;
  gap: 8px;
}
.sidebar-search-box .search-box-icon {
  width: 15px;
  height: 15px;
  color: var(--fg-muted);
}
.sidebar-search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  font-size: 13px;
  color: var(--fg-primary);
}
.sidebar-search-box input::placeholder {
  color: var(--fg-muted);
}
.search-clear-btn {
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: 50%;
}
.search-clear-btn:hover {
  color: var(--fg-primary);
}

.sidebar-group-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-muted);
  padding: 12px 18px 4px;
  letter-spacing: 0.2px;
}

.sidebar-recents {
  flex: 1;
  overflow-y: auto;
  padding: 4px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
}

.conv-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13.5px;
  color: var(--fg-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
  position: relative;
}
.conv-item:hover {
  background: var(--bg-surface-hover);
  color: var(--fg-primary);
}
.conv-item.active {
  background: var(--bg-surface-active);
  color: var(--fg-primary);
  font-weight: 500;
}
.conv-item .conv-title {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-right: 6px;
}
.conv-item .del-btn {
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  color: var(--fg-muted);
  transition: opacity 0.15s ease, color 0.15s ease, background 0.15s ease;
}
.conv-item:hover .del-btn {
  opacity: 1;
}
.conv-item .del-btn:hover {
  color: var(--danger);
  background: rgba(248, 81, 73, 0.18);
}

.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border-muted);
  flex-shrink: 0;
}

.user-profile-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  border-radius: 24px;
  transition: background 0.15s ease;
}
.user-profile-btn:hover {
  background: var(--bg-surface-hover);
}

.user-avatar-circle {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-pink);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(217, 59, 119, 0.4);
}

.user-info {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.user-name {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--fg-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.user-plan {
  font-size: 11.5px;
  color: var(--fg-muted);
}
.settings-trigger {
  width: 32px;
  height: 32px;
  color: var(--fg-muted);
}
.settings-trigger:hover {
  color: var(--fg-primary);
}

/* ---------- Main Canvas Area & Ambient Dynamic Glow ---------- */
.main-canvas {
  flex: 1;
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
  background: var(--bg-main);
  min-width: 0;
  overflow: hidden;
}

/* Ambient Glow Layer */
.ambient-glow-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
  opacity: 0.38;
  transition: opacity 2s cubic-bezier(0.16, 1, 0.3, 1);
}
.main-canvas.streaming-active .ambient-glow-layer {
  opacity: 0.85;
}

.glow-orb {
  position: absolute;
  border-radius: 50%;
  filter: blur(90px);
  transition: transform 2.8s cubic-bezier(0.16, 1, 0.3, 1), opacity 2s ease;
  will-change: transform, opacity;
}
.glow-orb.orb-1 {
  width: 48vw;
  height: 48vw;
  top: -12%;
  left: -8%;
  background: radial-gradient(circle, rgba(66, 133, 244, 0.55) 0%, rgba(66, 133, 244, 0) 70%);
}
.glow-orb.orb-2 {
  width: 52vw;
  height: 52vw;
  top: 15%;
  right: -10%;
  background: radial-gradient(circle, rgba(155, 114, 203, 0.5) 0%, rgba(155, 114, 203, 0) 70%);
}
.glow-orb.orb-3 {
  width: 44vw;
  height: 44vw;
  bottom: -10%;
  left: 15%;
  background: radial-gradient(circle, rgba(217, 101, 112, 0.45) 0%, rgba(217, 101, 112, 0) 70%);
}
.glow-orb.orb-4 {
  width: 38vw;
  height: 38vw;
  bottom: 10%;
  right: 12%;
  background: radial-gradient(circle, rgba(244, 180, 0, 0.35) 0%, rgba(244, 180, 0, 0) 70%);
}

/* Active Streaming: Orbs flow, morph, and orbit dynamically */
.main-canvas.streaming-active .glow-orb.orb-1 {
  animation: flowOrb1 7s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite alternate;
}
.main-canvas.streaming-active .glow-orb.orb-2 {
  animation: flowOrb2 8.5s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite alternate;
}
.main-canvas.streaming-active .glow-orb.orb-3 {
  animation: flowOrb3 9s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite alternate;
}
.main-canvas.streaming-active .glow-orb.orb-4 {
  animation: flowOrb4 7.5s cubic-bezier(0.45, 0.05, 0.55, 0.95) infinite alternate;
}

@keyframes flowOrb1 {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(24vw, 20vh) scale(1.25); }
  100% { transform: translate(12vw, 42vh) scale(0.92); }
}
@keyframes flowOrb2 {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-22vw, 24vh) scale(1.2); }
  100% { transform: translate(-8vw, -16vh) scale(0.88); }
}
@keyframes flowOrb3 {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(18vw, -26vh) scale(1.3); }
  100% { transform: translate(-14vw, -12vh) scale(1.05); }
}
@keyframes flowOrb4 {
  0% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(-26vw, -18vh) scale(1.15); }
  100% { transform: translate(8vw, -30vh) scale(0.95); }
}

.canvas-topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 10;
  position: relative;
  flex-shrink: 0;
}

/* Messages Container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 0;
  scroll-behavior: smooth;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 5;
}

.messages-column {
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  flex-direction: column;
  flex: 1;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

/* Chat Switching Animation */
.messages-column.chat-switch-enter {
  animation: chatSwitchIn 0.28s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}
@keyframes chatSwitchIn {
  0% {
    opacity: 0;
    transform: translateY(14px) scale(0.985);
  }
  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

/* Empty Hero View */
.empty-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 240px;
  padding: 40px 0;
  text-align: center;
  animation: heroFadeIn 0.3s ease-out;
}
@keyframes heroFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.hero-title {
  font-size: 38px;
  font-weight: 400;
  letter-spacing: -0.5px;
  color: var(--fg-primary);
  opacity: 0.95;
  margin-bottom: 8px;
}

/* Message Rows */
.msg {
  display: flex;
  gap: 16px;
  margin-bottom: 28px;
  position: relative;
  animation: fadeInMsg 0.25s ease-out;
}
@keyframes fadeInMsg {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-avatar-col {
  flex-shrink: 0;
}
.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}
.msg.user .msg-avatar {
  background: var(--accent-pink);
  box-shadow: 0 2px 8px rgba(217, 59, 119, 0.4);
}
.msg.assistant .msg-avatar {
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}
.msg.assistant .msg-avatar svg {
  width: 28px;
  height: 28px;
}

.msg-content {
  flex: 1;
  min-width: 0;
}
.msg-author {
  font-size: 13px;
  font-weight: 600;
  color: var(--fg-primary);
  margin-bottom: 4px;
}
.msg.user .msg-author {
  color: var(--fg-secondary);
}

.msg-body {
  font-size: 15px;
  line-height: 1.68;
  color: var(--fg-primary);
  word-wrap: break-word;
}

/* Message Action Toolbars (Glassmorphic) */
.msg-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 10px;
  opacity: 0.9;
}
.msg-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  color: var(--fg-muted);
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  transition: all 0.15s ease;
}
.msg-action-btn svg {
  width: 14px;
  height: 14px;
}
.msg-action-btn:hover {
  color: var(--fg-primary);
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.16);
  transform: translateY(-1px);
}
.msg-action-btn.active-like {
  color: var(--accent-blue);
  background: rgba(68, 147, 248, 0.18);
  border-color: rgba(68, 147, 248, 0.35);
}
.msg-action-btn.active-dislike {
  color: var(--danger);
  background: rgba(248, 81, 73, 0.18);
  border-color: rgba(248, 81, 73, 0.35);
}

/* Markdown Rendering */
.md p { margin: 0 0 14px; }
.md p:last-child { margin-bottom: 0; }
.md h1, .md h2, .md h3, .md h4 {
  font-weight: 600;
  line-height: 1.3;
  margin: 22px 0 10px;
  color: var(--fg-primary);
}
.md h1 { font-size: 24px; border-bottom: 1px solid var(--border-muted); padding-bottom: 6px; }
.md h2 { font-size: 20px; border-bottom: 1px solid var(--border-muted); padding-bottom: 4px; }
.md h3 { font-size: 17px; }
.md ul, .md ol { margin: 0 0 14px; padding-left: 24px; }
.md li { margin-bottom: 4px; }
.md code {
  font-family: var(--font-mono);
  font-size: 88%;
  background: rgba(255, 255, 255, 0.08);
  padding: 2px 6px;
  border-radius: 6px;
  color: #e2b714;
}
.md pre {
  background: rgba(18, 20, 26, 0.7);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-glass);
  border-radius: 8px;
  padding: 14px 16px;
  overflow-x: auto;
  margin: 0 0 14px;
  font-size: 13.5px;
  line-height: 1.5;
}
.md pre code {
  background: transparent;
  padding: 0;
  font-size: 100%;
  color: inherit;
}
.md blockquote {
  margin: 0 0 14px;
  padding: 4px 16px;
  border-left: 3px solid var(--accent-blue);
  color: var(--fg-secondary);
}
.md table {
  border-collapse: collapse;
  margin: 0 0 14px;
  display: block;
  overflow-x: auto;
}
.md th, .md td {
  border: 1px solid var(--border);
  padding: 8px 14px;
}
.md th {
  background: var(--bg-surface);
  font-weight: 600;
}

/* Code Block with Header, Badges, Copy & Monaco Edit Button */
.code-block, .compact-code-block {
  margin: 12px 0 16px;
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(14, 16, 22, 0.75);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}
.code-block .code-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(255, 255, 255, 0.04);
  padding: 8px 12px 8px 14px;
  font-size: 12px;
  border-bottom: 1px solid var(--border-muted);
  font-family: var(--font-sans);
}
.code-head-left {
  display: flex;
  align-items: center;
  gap: 8px;
}
.code-lang-badge {
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 11px;
  color: var(--accent-blue);
  background: rgba(68, 147, 248, 0.12);
  padding: 2px 8px;
  border-radius: 6px;
  letter-spacing: 0.5px;
}
.code-lines-count {
  font-size: 11.5px;
  color: var(--fg-muted);
}
.code-head-right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.code-action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  border-radius: 7px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--fg-secondary);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  transition: all 0.15s ease;
  cursor: pointer;
}
.code-action-btn svg {
  width: 13px;
  height: 13px;
}
.code-action-btn:hover {
  color: var(--fg-primary);
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.18);
  transform: translateY(-1px);
}
.code-action-btn.edit-code-btn {
  color: #fff;
  background: rgba(68, 147, 248, 0.2);
  border-color: rgba(68, 147, 248, 0.35);
}
.code-action-btn.edit-code-btn:hover {
  background: rgba(68, 147, 248, 0.35);
  border-color: rgba(68, 147, 248, 0.55);
}
.code-action-btn.copy-btn.copied {
  color: var(--success);
  border-color: rgba(63, 185, 80, 0.4);
}
.code-block pre {
  margin: 0;
  border: none;
  border-radius: 0;
  background: transparent;
  max-height: 280px;
  overflow: auto;
  padding: 12px 16px;
}
.code-block pre code {
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.55;
}

/* ---------- Right-side Code & Web Preview Panel (Monaco & Preview) ---------- */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(720px, 100vw);
  background: var(--bg-modal);
  backdrop-filter: var(--blur-modal);
  -webkit-backdrop-filter: var(--blur-modal);
  border-left: 1px solid var(--border-glass);
  box-shadow: -8px 0 36px rgba(0, 0, 0, 0.6);
  z-index: 80;
  display: flex;
  flex-direction: column;
  transform: translateX(105%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
.side-panel.open {
  transform: translateX(0);
}

.side-panel-header {
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-muted);
  background: rgba(255, 255, 255, 0.02);
  gap: 12px;
  flex-shrink: 0;
}

.panel-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.panel-lang-badge {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  background: rgba(68, 147, 248, 0.2);
  color: var(--accent-blue);
  border: 1px solid rgba(68, 147, 248, 0.35);
  padding: 2px 8px;
  border-radius: 6px;
}
.panel-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--fg-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Panel Center Tabs (Preview vs Code) */
.panel-tabs {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass);
  border-radius: 20px;
  padding: 3px;
  gap: 2px;
}
.panel-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--fg-secondary);
  transition: all 0.15s ease;
}
.panel-tab-btn svg {
  width: 13px;
  height: 13px;
}
.panel-tab-btn:hover {
  color: var(--fg-primary);
}
.panel-tab-btn.active {
  background: var(--bg-surface-active);
  color: var(--fg-primary);
  box-shadow: var(--shadow-sm);
}

.panel-header-right {
  display: flex;
  align-items: center;
  gap: 6px;
}
.device-switcher {
  display: flex;
  align-items: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-glass);
  border-radius: 16px;
  padding: 2px;
  gap: 2px;
}
.device-btn {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  color: var(--fg-muted);
  transition: all 0.15s ease;
}
.device-btn svg {
  width: 13px;
  height: 13px;
}
.device-btn:hover {
  color: var(--fg-primary);
}
.device-btn.active {
  background: var(--bg-surface-active);
  color: var(--fg-primary);
}

.panel-action-btn, .panel-close-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  color: var(--fg-muted);
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
}
.panel-action-btn:hover, .panel-close-btn:hover {
  color: var(--fg-primary);
  background: var(--bg-surface-hover);
}
.panel-close-btn:hover {
  color: var(--danger);
}

/* Side Panel Body */
.side-panel-body {
  flex: 1;
  overflow: hidden;
  position: relative;
  display: flex;
  background: #14161f;
}
.panel-tab-pane {
  position: absolute;
  inset: 0;
  display: none;
  overflow: hidden;
}
.panel-tab-pane.active {
  display: flex;
}

/* Preview Viewport & Device Simulation */
.preview-viewport-wrapper {
  flex: 1;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: stretch;
  background: #0f1117;
  padding: 0;
  transition: padding 0.25s ease;
}
.preview-viewport-wrapper.device-tablet {
  padding: 20px;
}
.preview-viewport-wrapper.device-tablet iframe {
  max-width: 768px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-glass);
}
.preview-viewport-wrapper.device-mobile {
  padding: 20px;
}
.preview-viewport-wrapper.device-mobile iframe {
  max-width: 375px;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border-glass);
}

#preview-frame {
  width: 100%;
  height: 100%;
  border: none;
  background: #ffffff;
  transition: max-width 0.25s ease;
}

/* Monaco Container */
.monaco-host {
  width: 100%;
  height: 100%;
  background: #1e1e1e;
}

/* Message Image & Lightbox */
.msg-img {
  max-width: min(420px, 100%);
  border-radius: 12px;
  border: 1px solid var(--border-glass);
  cursor: zoom-in;
  display: block;
  margin: 8px 0;
  transition: transform 0.15s ease;
}
.msg-img:hover {
  transform: scale(1.01);
}

/* Streaming Glowing Cursor */
.streaming-cursor {
  display: inline-block;
  width: 7px;
  height: 15px;
  background: var(--fg-primary);
  margin-left: 3px;
  vertical-align: middle;
  border-radius: 1px;
  animation: stream-blink 0.8s infinite;
}
@keyframes stream-blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.1; }
}

/* 3-Dot Typing Indicator */
.typing-dots {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 0;
}
.typing-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--fg-muted);
  animation: dot-wave 1.4s infinite ease-in-out both;
}
.typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.typing-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes dot-wave {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1.1); opacity: 1; }
}

/* Message Error */
.msg-error {
  background: rgba(248, 81, 73, 0.12);
  border: 1px solid var(--danger);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13.5px;
  margin-top: 6px;
}

/* ---------- Glassmorphic Floating Pill Composer & Separated Capsules ---------- */
.composer-container {
  padding: 8px 24px 20px;
  max-width: 820px;
  width: 100%;
  margin: 0 auto;
  position: relative;
  z-index: 20;
}

.pending-attachments-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 0 10px;
}
.pending-attachments-row:empty {
  display: none;
}

.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--border-glass);
  border-radius: 12px;
  padding: 5px 12px;
  background: var(--bg-pill);
  backdrop-filter: var(--blur-pill);
  -webkit-backdrop-filter: var(--blur-pill);
  font-size: 12.5px;
  color: var(--fg-secondary);
  max-width: 260px;
  box-shadow: var(--shadow-sm);
}
.attach-chip .chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attach-chip img.chip-thumb {
  width: 34px;
  height: 34px;
  object-fit: cover;
  border-radius: 6px;
}
.attach-chip .chip-remove {
  color: var(--fg-muted);
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: 50%;
}
.attach-chip .chip-remove:hover {
  color: var(--danger);
}

/* Capsules Row: [+] [Input] [Model] [Mic] [Send] */
.composer-capsules-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  width: 100%;
  position: relative;
}

.capsule-btn {
  height: 48px;
  background: var(--bg-pill);
  backdrop-filter: var(--blur-pill);
  -webkit-backdrop-filter: var(--blur-pill);
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-pill);
  border-radius: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--fg-secondary);
  transition: all 0.15s ease;
  flex-shrink: 0;
  cursor: pointer;
}
.capsule-btn:hover {
  background: var(--bg-surface-hover);
  color: var(--fg-primary);
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

/* [+] Capsule Button */
.plus-capsule {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}
.plus-capsule:hover {
  transform: scale(1.05) rotate(90deg);
}

/* [Input] Capsule (Grows upwards without pulling other buttons) */
.input-capsule {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  background: var(--bg-pill);
  backdrop-filter: var(--blur-pill);
  -webkit-backdrop-filter: var(--blur-pill);
  border: 1px solid var(--border-glass);
  box-shadow: var(--shadow-pill);
  border-radius: 24px;
  padding: 12px 18px;
  display: flex;
  align-items: flex-end;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.input-capsule:focus-within {
  border-color: rgba(255, 255, 255, 0.28);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.input-capsule textarea {
  width: 100%;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  max-height: 240px;
  min-height: 24px;
  font-size: 15px;
  line-height: 1.5;
  color: var(--fg-primary);
  padding: 0;
  margin: 0;
  overflow-y: auto;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE / Edge */
}
.input-capsule textarea::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}
.input-capsule textarea::placeholder {
  color: var(--fg-muted);
}

/* [Model] Switcher Capsule */
.model-capsule {
  height: 48px;
  padding: 0 16px;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--fg-primary);
}
.model-capsule.disabled, .model-capsule:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
  background: rgba(255, 255, 255, 0.03);
}
.model-capsule .model-name {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.model-capsule svg {
  width: 14px;
  height: 14px;
  color: var(--fg-muted);
}

/* [Mic] Capsule Button */
.mic-capsule {
  width: 48px;
  height: 48px;
  border-radius: 50%;
}

/* [Send] Capsule Button */
.send-capsule {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--fg-primary);
  color: var(--bg-main);
  box-shadow: 0 4px 16px rgba(255, 255, 255, 0.2);
}
.send-capsule:hover {
  opacity: 0.94;
  transform: scale(1.06);
  color: var(--bg-main);
  background: var(--fg-primary);
}
.send-capsule.stop-btn {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 4px 16px rgba(248, 81, 73, 0.4);
}

.composer-disclaimer {
  text-align: center;
  font-size: 11.5px;
  color: var(--fg-subtle);
  margin-top: 10px;
}

/* ---------- Glassmorphic Popovers ---------- */
.action-popover, .model-popover {
  position: absolute;
  bottom: calc(100% + 10px);
  background: var(--bg-popover);
  backdrop-filter: var(--blur-popover);
  -webkit-backdrop-filter: var(--blur-popover);
  border: 1px solid var(--border-glass);
  border-radius: 18px;
  padding: 8px;
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  display: none;
  flex-direction: column;
  gap: 4px;
  z-index: 50;
  animation: popoverFade 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes popoverFade {
  from { opacity: 0; transform: translateY(8px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.action-popover {
  left: 0;
  width: 260px;
}
.action-popover.open {
  display: flex;
}

.model-popover {
  right: 60px;
  width: 320px;
  max-width: calc(100vw - 32px);
  max-height: 340px;
  overflow-y: auto;
}
.model-popover.open {
  display: flex;
}

.popover-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  color: var(--fg-secondary);
  transition: all 0.15s ease;
  width: 100%;
  text-align: left;
}
.popover-item:hover {
  background: var(--bg-surface-hover);
  color: var(--fg-primary);
}

.model-popover-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  transition: all 0.15s ease;
  width: 100%;
  text-align: left;
  background: transparent;
}
.model-popover-item:hover {
  background: var(--bg-surface-hover);
  transform: translateY(-1px);
}
.model-popover-item.active {
  background: var(--bg-surface-active);
  border: 1px solid var(--border-glass);
}

.model-item-icon {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--fg-secondary);
  flex-shrink: 0;
  margin-top: 1px;
}
.model-popover-item.active .model-item-icon {
  background: rgba(68, 147, 248, 0.2);
  color: var(--accent-blue);
}

.model-item-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.model-item-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.model-item-title {
  font-size: 13.5px;
  font-weight: 600;
  color: var(--fg-primary);
}

.model-badge {
  font-size: 10px;
  font-weight: 500;
  padding: 1px 6px;
  border-radius: 6px;
  background: rgba(68, 147, 248, 0.15);
  color: var(--accent-blue);
  border: 1px solid rgba(68, 147, 248, 0.3);
}

.model-item-desc {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--fg-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.imgen-status-indicator {
  margin-left: auto;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--fg-muted);
}
.popover-item.active .imgen-status-indicator {
  background: var(--accent-blue);
  box-shadow: 0 0 8px var(--accent-blue);
}

.popover-sub {
  padding: 8px 12px;
  border-top: 1px solid var(--border-muted);
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--fg-muted);
}

.size-dropdown {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-glass);
  border-radius: 8px;
  padding: 6px 8px;
  color: var(--fg-primary);
  outline: none;
  font-size: 13px;
}

.model-popover-head {
  padding: 6px 12px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ---------- Glassmorphic Modals ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  display: none;
  place-items: center;
  padding: 16px;
}
.modal-backdrop.open {
  display: grid;
}

.modal-card {
  background: var(--bg-modal);
  backdrop-filter: var(--blur-modal);
  -webkit-backdrop-filter: var(--blur-modal);
  border: 1px solid var(--border-glass);
  border-radius: 24px;
  width: min(480px, 100%);
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  overflow: hidden;
  animation: modalScale 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modalScale {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-muted);
}
.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.modal-body {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.setting-info {
  display: flex;
  flex-direction: column;
}
.setting-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--fg-primary);
}
.setting-desc {
  font-size: 12px;
  color: var(--fg-muted);
}

.theme-toggle-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-glass);
  color: var(--fg-primary);
  font-size: 13px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.theme-toggle-pill:hover {
  background: rgba(255, 255, 255, 0.12);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-muted);
  display: flex;
  justify-content: flex-end;
}

.btn-signout {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 12px;
  background: rgba(248, 81, 73, 0.12);
  color: var(--danger);
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s ease;
}
.btn-signout:hover {
  background: rgba(248, 81, 73, 0.22);
}

/* ---------- Glassmorphic Login Page ---------- */
#login-page {
  min-height: 100vh;
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-main);
  background-image: 
    radial-gradient(at 20% 20%, rgba(66, 133, 244, 0.18) 0px, transparent 60%),
    radial-gradient(at 80% 80%, rgba(155, 114, 203, 0.18) 0px, transparent 60%);
}
.login-card {
  width: min(380px, 92vw);
  background: var(--bg-modal);
  backdrop-filter: var(--blur-modal);
  -webkit-backdrop-filter: var(--blur-modal);
  border: 1px solid var(--border-glass);
  border-radius: 28px;
  padding: 38px 30px;
  text-align: center;
  box-shadow: var(--shadow-lg), inset 0 1px 0 rgba(255, 255, 255, 0.15);
}
.gemini-star-lg {
  width: 48px;
  height: 48px;
  margin: 0 auto 16px;
}
.gemini-star-lg svg {
  width: 100%;
  height: 100%;
}
.login-card h1 {
  font-size: 24px;
  font-weight: 600;
  margin-bottom: 6px;
}
.login-card p {
  color: var(--fg-muted);
  font-size: 13px;
  margin-bottom: 24px;
}
.input-field-wrap input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border-glass);
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--fg-primary);
  outline: none;
  font-size: 14px;
  margin-bottom: 16px;
  transition: all 0.15s ease;
}
.input-field-wrap input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 12px rgba(68, 147, 248, 0.3);
}
.btn-primary-gemini {
  width: 100%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border-radius: 14px;
  background: var(--fg-primary);
  color: var(--bg-main);
  font-size: 14px;
  font-weight: 600;
  transition: all 0.15s ease;
  box-shadow: 0 4px 16px rgba(255, 255, 255, 0.18);
}
.btn-primary-gemini:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}
.login-error {
  color: var(--danger);
  font-size: 12.5px;
  margin-top: 12px;
  min-height: 18px;
}

/* ---------- Glassmorphic Lightbox ---------- */
#lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 200;
  display: none;
  place-items: center;
  cursor: zoom-out;
}
#lightbox.open {
  display: grid;
}
#lightbox img {
  max-width: 92vw;
  max-height: 92vh;
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
}
.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  color: #fff;
  display: grid;
  place-items: center;
  transition: all 0.15s ease;
}
.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.25);
  transform: scale(1.06);
}

/* ---------- Glassmorphic Toast Popup ---------- */
.toast-popup {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(30px);
  background: rgba(26, 28, 36, 0.9);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-glass);
  border-radius: 20px;
  padding: 8px 18px;
  color: var(--fg-primary);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 300;
}
.toast-popup.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
.toast-popup svg {
  width: 16px;
  height: 16px;
  color: var(--success);
}

/* Drag & Drop Overlay */
.drag-drop-overlay {
  position: absolute;
  inset: 0;
  background: rgba(12, 13, 18, 0.85);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 2px dashed var(--accent-blue);
  border-radius: 20px;
  margin: 12px;
  display: none;
  place-items: center;
  z-index: 80;
  pointer-events: none;
}
.main-canvas.dragging .drag-drop-overlay {
  display: grid;
}
.drag-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--accent-blue);
  font-size: 16px;
  font-weight: 500;
}
.drag-content svg {
  width: 44px;
  height: 44px;
}

/* Scrollbars */
::-webkit-scrollbar {
  width: 7px;
  height: 7px;
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.12);
  border-radius: 4px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.22);
}
::-webkit-scrollbar-track {
  background: transparent;
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 280px;
    box-shadow: var(--shadow-lg);
    transform: translateX(0);
  }
  .sidebar.collapsed {
    transform: translateX(-100%);
    width: 280px !important;
  }
  .messages-column, .composer-container {
    padding-left: 14px;
    padding-right: 14px;
  }
  .hero-title {
    font-size: 28px;
  }
}
