/* ==========================================================================
   Eclyzer Main Chat UI
   Aligned visual system with login + admin dashboard
   ========================================================================== */

/* ---------- Design Tokens ---------- */
/* Token warna/ tipografi/ radius berasal dari theme.css (satu sumber).
   Blok ini hanya menyimpan token tata letak khusus halaman chat. */
:root {
  --sidebar-width: 278px;
  --sidebar-collapsed-width: 54px;
  --chat-max-width: 840px;
  --composer-max-width: 820px;
  --composer-bottom-offset: 0px;
  --mobile-chat-bottom-space: 132px;
}

/* Mode terang ditangani theme.css. */

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
  background: var(--bg-base);
  color: var(--text-main);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.62;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

a[x-apple-data-detectors],
.user-email a {
  color: inherit !important;
  text-decoration: none !important;
  font-size: inherit !important;
  font-family: inherit !important;
  font-weight: inherit !important;
  line-height: inherit !important;
}

strong,
b,
h1,
h2,
h3,
h4,
h5,
h6,
label,
.brand-title,
.brand-large-text,
.history-group-title,
.settings-tab-content h3,
.message-user-label {
  font-weight: 500 !important;
}

.hidden {
  display: none !important;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 4px;
  height: 4px;
}

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

::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
}

body.theme-light ::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.1);
}

/* ---------- App Layout ---------- */
.app-container {
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  max-height: 100dvh;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: minmax(0, 1fr);
  overflow: hidden;
}

a,
button,
[role="button"],
.history-item,
.history-group-toggle,
.sidebar-primary-box,
.profile-menu-btn,
.mode-option {
  -webkit-tap-highlight-color: transparent;
}

.mobile-header,
.sidebar-overlay {
  display: none;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-width);
  height: 100%;
  max-height: 100dvh;
  min-height: 0;
  background: var(--bg-sidebar);
  border-right: 0;
  display: flex;
  flex-direction: column;
  transition: width 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  overflow: hidden;
}

.sidebar-top {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 14px 0 8px;
}

.brand-container {
  height: 44px;
  display: flex;
  align-items: center;
  position: relative;
  margin-bottom: 8px;
  overflow: hidden;
  white-space: nowrap;
  flex-shrink: 0;
}

.brand-container .brand-title {
  padding-left: 19px;
}

.brand-title {
  font-family: var(--font-brand);
  font-size: 26px;
  font-weight: 800 !important;
  letter-spacing: 0;
  line-height: 1;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.brand-link,
.brand-home-link {
  display: inline-flex;
  align-items: center;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}

.brand-link:focus,
.brand-link:focus-visible,
.brand-home-link:focus,
.brand-home-link:focus-visible {
  outline: none;
}

.mobile-menu-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.sidebar-toggle-btn {
  position: absolute;
  right: 10px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: right 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), background 0.15s ease, color 0.15s ease;
}

.toggle-icon-lucide {
  position: absolute;
  width: 16px;
  height: 16px;
  opacity: 1;
  transform: scale(1);
  transition: opacity 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.toggle-icon-logo {
  position: absolute;
  width: 20px;
  height: 20px;
  object-fit: contain;
  opacity: 0;
  transform: scale(0.5);
  transition: opacity 0.3s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sidebar-toggle-btn:hover,
.mobile-menu-btn:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

.sidebar-primary-box,
.new-chat-btn,
.sidebar-search-btn,
.sidebar-docs-btn {
  width: 100%;
  min-height: 38px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 10px 0 19px;
  font-size: 14px;
  text-align: left;
  transition: color 0.15s ease, width 0.3s cubic-bezier(0.2, 0.8, 0.2, 1);
  overflow: hidden;
  white-space: nowrap;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
}

.sidebar-primary-box::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: -1;
}

.btn-text {
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.sidebar-primary-box + .sidebar-primary-box {
  margin-top: 2px;
}

.sidebar-primary-box svg,
.sidebar-primary-box i {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.sidebar-primary-box:hover::before {
  background: var(--bg-soft);
}

.sidebar-primary-box:hover {
  color: var(--text-main);
}

body.theme-light .sidebar-primary-box,
body.theme-light .history-item {
  color: #000;
}

body.theme-light .sidebar-primary-box:hover::before,
body.theme-light .history-item:hover {
  background: #eef2f7;
}

.sidebar-sections {
  margin-top: 12px;
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-y: overlay;
  padding-left: 10px;
  padding-right: 8px;
  margin-right: 0;
  max-height: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
  scrollbar-width: none;
}

.sidebar-sections::-webkit-scrollbar {
  width: 4px;
}

.sidebar-sections::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar-sections::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: var(--radius-pill);
  transition: background 0.3s ease;
}

.sidebar-sections.is-scrolling::-webkit-scrollbar-thumb,
.sidebar-sections:hover::-webkit-scrollbar-thumb {
  background: var(--border-hover);
}

.nav-content {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.history-group {
  margin-bottom: 12px;
}

#pinned-group {
  display: none;
}

.history-group-toggle {
  width: 100%;
  min-height: 30px;
  border: 0;
  border-radius: 0;
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 6px;
  padding: 0 10px;
  color: var(--text-muted);
  transition: color 0.16s ease;
}

.history-group-toggle:hover {
  background: transparent;
  color: var(--text-muted);
}

.history-group-toggle:focus,
.history-group-toggle:focus-visible,
.history-group-toggle:active {
  outline: none;
  box-shadow: none;
  background: transparent;
  color: var(--text-muted);
}

.history-group-toggle i,
.history-group-toggle svg {
  width: 11px;
  height: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: rotate(90deg);
  transform-origin: center;
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.16s ease;
  margin-top: 0;
}

.history-group.collapsed .history-group-toggle i,
.history-group.collapsed .history-group-toggle svg {
  transform: rotate(0deg);
}

.history-group-toggle:hover i,
.history-group-toggle:hover svg,
.history-group-toggle:focus-visible i,
.history-group-toggle:focus-visible svg {
  opacity: 1;
}

.history-group-title {
  display: inline-flex;
  align-items: center;
  line-height: 1;
  margin-top: 0;
}

.pinned-items-container,
.recent-items-container {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: visible;
  max-height: 900px;
  opacity: 1;
  transform: none;
  transition: max-height 0.22s ease, opacity 0.18s ease, transform 0.18s ease;
}

.history-group.collapsed .pinned-items-container,
.history-group.collapsed .recent-items-container {
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transform: translateY(-4px);
  pointer-events: none;
}

.history-group-title {
  padding: 0;
  font-size: 11px !important;
  letter-spacing: 0.05em !important;
  text-transform: uppercase !important;
  color: var(--text-muted) !important;
}

.history-item {
  position: relative;
  z-index: 1;
  min-height: 35px;
  margin: 0;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  transition: var(--transition-fast);
}

.history-item.menu-open {
  z-index: 40;
}

.history-item:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

.history-item.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

body.theme-light .history-item.active {
  background: #e7ebf1;
}

.history-item-main {
  min-width: 0;
  flex: 1;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: default;
}

.history-item:not(.is-pinned) .history-item-main {
  gap: 0;
}

.history-leading-icon {
  width: 14px;
  height: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  flex-shrink: 0;
}

.history-leading-icon svg,
.history-leading-icon i {
  width: 14px;
  height: 14px;
}

.history-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13.5px;
  font-weight: 400;
  user-select: none;
}

.history-more-btn {
  width: 25px;
  height: 25px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: var(--transition-fast);
}

.history-more-btn svg,
.history-more-btn i {
  width: 12px;
  height: 12px;
}

.history-item:hover .history-more-btn,
.history-item.active .history-more-btn,
.history-item.menu-open .history-more-btn {
  display: inline-flex;
}

.history-item.renaming .history-more-btn {
  display: none !important;
}

.history-more-btn:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

.history-dropdown {
  position: absolute;
  top: calc(100% + 5px);
  right: 4px;
  z-index: 220;
  min-width: 162px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-popover);
  padding: 5px;
  display: none;
  flex-direction: column;
  gap: 2px;
}

.history-dropdown.show {
  display: flex;
}

.history-dropdown.dropup {
  top: auto;
  bottom: calc(100% + 5px);
}

.history-dropdown-item {
  width: 100%;
  min-height: 32px;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  font-size: 12px;
  transition: var(--transition-fast);
}

.history-dropdown-item svg,
.history-dropdown-item i {
  width: 12px;
  height: 12px;
}

.history-dropdown-item:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

.rename-editor {
  position: absolute;
  inset: 2px 8px 2px 8px;
  border-radius: 10px;
  border: 0;
  background: transparent;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  z-index: 10;
}

.rename-input {
  min-width: 0;
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-main);
  font-size: 13px;
  line-height: 1.4;
}

.rename-input:focus {
  outline: none;
}

.rename-action-btn {
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.rename-action-btn:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

.rename-action-btn svg,
.rename-action-btn i {
  width: 12px;
  height: 12px;
}

.history-placeholder-item {
  cursor: default;
  opacity: 0.78;
}

.history-placeholder-item:hover {
  background: transparent;
  border-color: transparent;
}

.sidebar-bottom {
  border-top: 0;
  margin-top: auto;
  padding: 10px 0;
  flex: 0 0 auto;
  position: relative;
  z-index: 30;
}

.user-profile-wrap {
  position: relative;
}

.user-profile {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 6px 13px;
  cursor: pointer;
  transition: var(--transition-fast);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
  white-space: nowrap;
  position: relative;
  z-index: 1;
}

.user-profile::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  border-radius: var(--radius-md);
  background: transparent;
  transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  z-index: -1;
}

.user-profile * {
  user-select: none;
  -webkit-user-select: none;
  position: relative;
  z-index: 2;
}

.user-profile::selection,
.user-profile *::selection {
  background: transparent;
}

.user-profile:hover::before {
  background: var(--bg-soft);
}

.user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #27272a 0%, #09090b 100%);
  border: 1px solid var(--border);
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 500;
  flex-shrink: 0;
  overflow: hidden;
}

.user-info {
  min-width: 0;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.user-name,
.user-email {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  user-select: none;
}

.user-name {
  font-size: 13px;
  color: var(--text-main);
}

.user-email {
  margin-top: 1px;
  font-size: 11px;
  color: var(--text-muted);
}

.profile-menu {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: calc(100% + 6px);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-popover);
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 26;
}

.profile-menu.show {
  display: flex;
}

.profile-menu-divider {
  height: 0;
  margin: 1px 2px;
}

.profile-menu-item {
  width: 100%;
  min-height: 34px;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  font-size: 13px;
  transition: var(--transition-fast);
}

.profile-menu-item svg,
.profile-menu-item i {
  width: 14px;
  height: 14px;
}

.profile-menu-item:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

.profile-menu-item.logout:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

.profile-menu-item.upgrade {
  color: var(--text-secondary);
}

.sidebar.collapsed {
  width: var(--sidebar-collapsed-width);
  overflow: visible;
}

.sidebar.collapsed .brand-title,
.sidebar.collapsed .btn-text,
.sidebar.collapsed .user-info {
  opacity: 0;
  visibility: hidden;
}

.sidebar.collapsed .sidebar-sections {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.sidebar.collapsed .sidebar-primary-box::before,
.sidebar.collapsed .user-profile::before {
  width: 32px;
  height: 32px;
  margin: auto;
}

.sidebar.collapsed .brand-container {
  margin-bottom: 8px;
}

.sidebar.collapsed .sidebar-toggle-btn {
  right: 11px;
}

.sidebar.collapsed .toggle-icon-lucide {
  opacity: 0;
  transform: scale(0.5);
}

.sidebar.collapsed .toggle-icon-logo {
  opacity: 1;
  transform: scale(1);
}

.sidebar.collapsed .profile-menu {
  left: 10px;
  right: auto;
  bottom: calc(100% + 6px);
  width: 220px;
}

/* ---------- Main Area ---------- */
.main-content {
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.viewport-inner {
  position: relative;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.top-share-btn {
  position: absolute;
  top: max(14px, env(safe-area-inset-top, 0px));
  right: clamp(12px, 2.4vw, 24px);
  z-index: 110;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--text-secondary);
  padding: 5px 10px;
  margin: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  font-size: 13px;
  line-height: 1.2;
  font-weight: 500;
  letter-spacing: 0;
  white-space: nowrap;
  box-shadow: none;
  transition: color 0.15s ease, opacity 0.15s ease;
}

.top-share-btn i,
.top-share-btn svg {
  width: 14px;
  height: 14px;
}

.top-share-btn:hover,
.top-share-btn:focus-visible {
  background: var(--bg-soft);
  color: var(--text-main);
  text-decoration: none;
}

.top-share-btn:focus {
  outline: none;
}

.viewport-inner.has-top-share .chat-viewport {
  padding-top: 56px;
}

.viewport-inner.home-state {
  justify-content: center;
}

.home-container {
  flex: 0 0 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.home-brand {
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-large-text {
  font-family: var(--font-brand);
  font-size: clamp(34px, 5.1vw, 56px);
  font-weight: 800 !important;
  letter-spacing: -0.02em;
  line-height: 1.04;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.viewport-inner.home-state .composer-container {
  padding-top: 18px;
  padding-bottom: 0;
  background: transparent;
}

.chat-viewport {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 30px 24px var(--chat-bottom-padding, 0px);
}

.chat-viewport.hidden {
  display: none;
}

.chat-messages {
  width: min(var(--chat-max-width), 100%);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0;
  padding: 0 2px 30px;
}

.message {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message + .message {
  margin-top: 28px;
}

.message.user {
  align-self: flex-end;
  align-items: flex-end;
  max-width: min(72%, 700px);
}

.message.ai {
  align-self: flex-start;
  align-items: flex-start;
  max-width: 100%;
}

.message-user-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding-right: 4px;
  font-size: 11px;
  color: var(--text-muted);
}

.message-user-dot {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

.message-body {
  width: 100%;
}

.user-content {
  background: var(--bg-soft);
  border: 0;
  border-radius: 18px;
  padding: 10px 14px;
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.58;
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
}

body:not(.theme-light) .user-content {
  background: var(--bg-elevated);
}

.user-attachment-float {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  max-width: 100%;
  padding: 4px 10px;
  margin: 0 2px 6px 0;
  border: 0;
  border-radius: 999px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 12px;
  line-height: 1.3;
}

.user-attachment-float i,
.user-attachment-float svg {
  width: 12px;
  height: 12px;
  color: var(--text-muted);
}

.message.user .user-attachment-float .file-name {
  max-width: min(56vw, 260px);
}

.assistant-content {
  width: min(100%, 780px);
  color: var(--text-main);
  font-size: 14.7px;
  line-height: 1.76;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

.assistant-content > * + * {
  margin-top: 0.72em;
}

.assistant-content p {
  margin: 0;
  letter-spacing: 0.003em;
}

.assistant-content h1,
.assistant-content h2,
.assistant-content h3,
.assistant-content h4,
.assistant-content h5,
.assistant-content h6 {
  margin: 0.88em 0 0.38em;
  line-height: 1.32;
}

.assistant-content h1 { font-size: 1.34em; }
.assistant-content h2 { font-size: 1.24em; }
.assistant-content h3 { font-size: 1.16em; }
.assistant-content h4,
.assistant-content h5,
.assistant-content h6 { font-size: 1.08em; }

.assistant-content ul,
.assistant-content ol {
  margin: 0.4em 0 0.46em 1.24em;
}

.assistant-content li {
  margin: 0.14em 0;
}

.assistant-content blockquote {
  margin: 0.6em 0;
  padding: 0.5em 0.85em;
  border-left: 3px solid rgba(var(--tint-rgb), 0.36);
  border-radius: 8px;
  background: rgba(var(--tint-rgb), 0.06);
  color: var(--text-secondary);
}

.assistant-content a {
  color: #e4e4e7;
  text-decoration: underline;
  text-underline-offset: 2px;
  transition: var(--transition-fast);
}

body.theme-light .assistant-content a {
  color: #27272a;
}

.assistant-content a:hover {
  color: #ffffff;
}

body.theme-light .assistant-content a:hover {
  color: #000000;
}

.assistant-content hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 0.86em 0;
}

.assistant-content img {
  display: block;
  max-width: 100%;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin: 0.6em 0;
}

.assistant-content code {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-soft);
  border-radius: 7px;
  padding: 0.1em 0.38em;
  font-size: 0.9em;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, "Liberation Mono", monospace;
}

body.theme-light .assistant-content code {
  background: rgba(0, 0, 0, 0.06);
}

.assistant-content pre {
  margin: 0;
  white-space: pre;
}

.code-block {
  margin: 0.68em 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  overflow: hidden;
  box-shadow: var(--shadow-soft);
}

.code-block-header {
  min-height: 38px;
  padding: 0 10px 0 12px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--bg-elevated);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.code-lang-label {
  color: var(--text-secondary);
  font-size: 12px;
  text-transform: lowercase;
}

.code-copy-btn {
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.code-copy-btn:hover {
  background: var(--bg-soft);
  border-color: var(--border);
  color: var(--text-main);
}

.code-block pre {
  overflow-x: auto;
  padding: 12px 14px;
}

.code-block code {
  display: block;
  border: 0;
  background: transparent;
  border-radius: 0;
  padding: 0;
  font-size: 13px;
  line-height: 1.56;
}

.assistant-table-wrap {
  max-width: 100%;
  overflow-x: auto;
  margin: 0.55em 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.assistant-content table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  font-size: 13.5px;
}

.assistant-content th,
.assistant-content td {
  padding: 8px 10px;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

.assistant-content th:last-child,
.assistant-content td:last-child {
  border-right: 0;
}

.assistant-content tr:last-child td {
  border-bottom: 0;
}

.assistant-content th {
  background: var(--bg-elevated);
}

.assistant-content .katex-display {
  margin: 0.72em 0;
  overflow-x: auto;
  overflow-y: hidden;
  padding-bottom: 2px;
}

.assistant-content .katex {
  color: var(--text-main);
}

.assistant-meta-label {
  color: var(--text-secondary);
  font-weight: 500;
}

.message-actions {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-top: 2px;
}

.message.user .copy-message-btn {
  opacity: 0;
  pointer-events: none;
}

.message.user:hover .copy-message-btn,
.message.user:focus-within .copy-message-btn {
  opacity: 1;
  pointer-events: auto;
}

.message-action-btn,
.copy-message-btn {
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.message-action-btn svg,
.copy-message-btn svg,
.message-action-btn i,
.copy-message-btn i {
  width: 13px;
  height: 13px;
}

.message-action-btn:hover,
.copy-message-btn:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

.message-action-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.message-action-btn.is-processing {
  background: var(--bg-soft);
}

.typing-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 2px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: eclyzerTyping 0.9s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.12s; }
.typing-dot:nth-child(3) { animation-delay: 0.24s; }

@keyframes eclyzerTyping {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-1px); }
}

/* ---------- Thinking Process ---------- */
.thinking-response-shell,
.thinking-final-shell {
  width: min(100%, 780px);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.thinking-inline-card {
  width: fit-content;
  max-width: min(100%, 320px);
  min-height: 34px;
  border: 0;
  border-radius: 0;
  padding: 1px 0;
  background: transparent;
  color: var(--text-main);
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  text-align: left;
  box-shadow: none;
  transition: var(--transition-smooth);
  position: relative;
  overflow: visible;
}

.thinking-inline-card::after {
  display: none;
}

.thinking-inline-card.is-active::after {
  animation: none;
}

.thinking-inline-card:hover {
  color: var(--text-secondary);
  transform: none;
}

.thinking-inline-card.is-active {
  box-shadow: none;
}

.thinking-orb {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
  position: relative;
  flex-shrink: 0;
}

.thinking-orb::after {
  display: none;
}

.thinking-inline-card.is-active .thinking-orb::after {
  animation: none;
}

.thinking-orb span {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--text-main);
  box-shadow: 0 0 16px rgba(var(--accent-rgb), 0.5);
}

.thinking-inline-card.is-active .thinking-orb span {
  animation: thinkingDotGlow 1.45s infinite ease-in-out;
}

.thinking-inline-card.is-complete .thinking-orb span {
  width: 9px;
  height: 5px;
  border-radius: 0;
  border-left: 1.5px solid var(--text-main);
  border-bottom: 1.5px solid var(--text-main);
  background: transparent;
  box-shadow: none;
  transform: translateY(-1px) rotate(-45deg);
}

.thinking-inline-card.is-error .thinking-orb span {
  background: var(--danger);
  box-shadow: none;
}

.thinking-inline-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  position: relative;
  z-index: 1;
}

.thinking-inline-head {
  display: flex;
  align-items: baseline;
  gap: 7px;
  min-width: 0;
}

.thinking-inline-title {
  font-family: var(--font-brand);
  font-size: 12.8px;
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.thinking-inline-card.is-active .thinking-inline-title {
  animation: thinkingTextGlow 1.8s infinite ease-in-out;
}

.thinking-inline-detail,
.thinking-inline-progress,
.thinking-inline-meta {
  font-size: 11.2px;
  line-height: 1.35;
  color: var(--text-muted);
}

.thinking-inline-detail,
.thinking-inline-progress {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.thinking-inline-progress {
  display: none;
}

.thinking-inline-meta {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
  transform: translateY(-0.5px);
}

.assistant-stream-output {
  color: var(--text-main);
  font-size: 14.7px;
  line-height: 1.76;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  min-height: 0;
}

.thinking-response-shell.stream-rich .assistant-stream-output {
  white-space: normal;
}

.assistant-stream-rendered-live {
  width: 100%;
}

.assistant-stream-rendered-live > :first-child {
  margin-top: 0;
}

.assistant-stream-rendered-live > :last-child {
  margin-bottom: 0;
}

.thinking-response-shell.has-output .assistant-stream-output::after {
  content: "";
  display: inline-block;
  width: 0.45ch;
  height: 1em;
  margin-left: 2px;
  border-right: 1.5px solid var(--accent, #7c3aed);
  transform: translateY(2px);
  animation: streamCursorBlink 0.7s step-end infinite;
}

@keyframes streamCursorBlink {
  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .thinking-response-shell.has-output .assistant-stream-output::after {
    animation: none;
  }
}

.thinking-response-shell:not(.has-output) .assistant-stream-output {
  min-height: 10px;
}

.thinking-response-shell.has-output .thinking-inline-card {
  width: fit-content;
  max-width: min(100%, 310px);
  min-height: 32px;
  padding: 0;
  box-shadow: none;
}

.thinking-final-shell .thinking-inline-card {
  margin-bottom: 2px;
  box-shadow: none;
}

.assistant-final-output {
  width: 100%;
}

.thinking-panel-overlay {
  position: fixed;
  inset: 0;
  z-index: 1040;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.22s ease, visibility 0.22s ease;
}

.thinking-panel-overlay.show {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

.thinking-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1050;
  width: min(420px, calc(100vw - 18px));
  height: 100dvh;
  padding: calc(18px + env(safe-area-inset-top, 0px)) 18px calc(18px + env(safe-area-inset-bottom, 0px));
  background:
    radial-gradient(circle at 18% 0%, rgba(var(--tint-rgb), 0.055), transparent 34%),
    var(--bg-panel);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-popover);
  color: var(--text-main);
  transform: translateX(104%);
  transition: transform 0.34s cubic-bezier(0.2, 0.78, 0.2, 1);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow: hidden;
}

.thinking-panel.show {
  transform: translateX(0);
}

.thinking-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.thinking-panel-title-wrap {
  min-width: 0;
}

.thinking-panel-kicker {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  padding: 0 7px;
  border-radius: 999px;
  background: rgba(var(--tint-rgb), 0.05);
  color: var(--text-muted);
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.thinking-panel h3 {
  margin: 10px 0 4px;
  font-family: var(--font-brand);
  font-size: 21px;
  line-height: 1.1;
  letter-spacing: -0.02em;
}

.thinking-panel p {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.55;
}

.thinking-panel-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 10px;
  background: var(--bg-soft);
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0;
  cursor: pointer;
  transition: var(--transition-fast);
}

.thinking-panel-close:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--text-main);
}

body.theme-light .thinking-panel-close:hover {
  background: rgba(0, 0, 0, 0.08);
}

.thinking-panel-close svg,
.thinking-panel-close i {
  width: 14px;
  height: 14px;
}

.thinking-panel-live-card {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 11px;
  align-items: center;
  padding: 12px;
  border-radius: 16px;
  background: rgba(var(--tint-rgb), 0.04);
  border: 1px solid var(--border);
}

.thinking-panel-orb {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid var(--border-hover);
  background: transparent;
  position: relative;
}

.thinking-panel-orb::before,
.thinking-panel-orb::after {
  content: "";
  position: absolute;
  border-radius: inherit;
}

.thinking-panel-orb::before {
  inset: 10px;
  background: var(--text-main);
  box-shadow: 0 0 16px rgba(var(--accent-rgb), 0.48);
}

.thinking-panel-orb::after {
  inset: -4px;
  border-radius: inherit;
  border: 1px solid rgba(var(--tint-rgb), 0.12);
  animation: thinkingPulse 1.45s infinite ease-out;
}

.thinking-panel-live-card.is-complete .thinking-panel-orb {
  background: transparent;
}

.thinking-panel-live-card.is-error .thinking-panel-orb {
  border-color: rgba(var(--danger-rgb), 0.42);
}

.thinking-panel-live-card.is-complete .thinking-panel-orb::before {
  inset: 9px 8px 10px 9px;
  width: 10px;
  height: 6px;
  border-left: 1.7px solid var(--text-main);
  border-bottom: 1.7px solid var(--text-main);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  transform: rotate(-45deg);
}

.thinking-panel-live-card.is-complete .thinking-panel-orb::after,
.thinking-panel-live-card.is-error .thinking-panel-orb::after {
  animation: none;
  opacity: 0;
}

.thinking-panel-live-card strong {
  display: block;
  font-size: 14px;
  line-height: 1.3;
}

.thinking-panel-live-card span:not(.thinking-panel-orb) {
  display: block;
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
}

.thinking-panel-note {
  border-radius: 13px;
  padding: 9px 11px;
  background: rgba(var(--tint-rgb), 0.04);
  color: var(--text-muted);
  font-size: 11.75px;
  line-height: 1.5;
}

.thinking-steps-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow-y: auto;
  min-height: 0;
  padding: 2px 2px 10px;
}

.thinking-step-item {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  gap: 10px;
  position: relative;
  padding: 0 0 18px;
}

.thinking-step-item:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 8px;
  top: 18px;
  bottom: 0;
  width: 1px;
  background: var(--border);
}

.thinking-step-marker {
  width: 16px;
  height: 16px;
  border-radius: 999px;
  margin-top: 2px;
  border: 1px solid var(--border-hover);
  background: transparent;
  position: relative;
  z-index: 1;
}

.thinking-step-item.done .thinking-step-marker {
  background: transparent;
  border-color: var(--border-hover);
}

.thinking-step-item.done .thinking-step-marker::before {
  content: "";
  position: absolute;
  left: 4px;
  top: 4px;
  width: 7px;
  height: 4px;
  border-left: 1.5px solid var(--text-main);
  border-bottom: 1.5px solid var(--text-main);
  transform: rotate(-45deg);
}

.thinking-step-item.active .thinking-step-marker {
  background: transparent;
  border-color: rgba(var(--accent-rgb), 0.42);
  box-shadow: 0 0 0 5px rgba(var(--accent-rgb), 0.055);
}

.thinking-step-item.error .thinking-step-marker {
  background: var(--danger);
  border-color: transparent;
}

.thinking-step-body {
  min-width: 0;
  padding: 0 0 0 2px;
}

.thinking-step-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.thinking-step-head strong {
  font-size: 13px;
  line-height: 1.35;
  color: var(--text-main);
}

.thinking-step-head span {
  color: var(--text-muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.thinking-step-body p {
  margin-top: 2px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.5;
}

@keyframes thinkingPulse {
  0% { opacity: 0.6; transform: scale(0.86); }
  100% { opacity: 0; transform: scale(1.55); }
}

@keyframes thinkingDotGlow {
  0%, 100% {
    opacity: 0.55;
    transform: scale(0.82);
    box-shadow: 0 0 6px rgba(var(--accent-rgb), 0.22);
  }
  50% {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 0 16px rgba(var(--accent-rgb), 0.5);
  }
}

@keyframes thinkingTextGlow {
  0%, 100% {
    color: var(--text-main);
    text-shadow: 0 0 0 rgba(var(--accent-rgb), 0);
  }
  50% {
    color: var(--text-secondary);
    text-shadow: 0 0 14px rgba(var(--tint-rgb), 0.22);
  }
}

/* ---------- Composer ---------- */
.composer-container {
  position: relative;
  flex-shrink: 0;
  padding: 10px 24px 20px;
  background: linear-gradient(to top, var(--bg-base) 60%, rgba(0, 0, 0, 0));
}

body.theme-light .composer-container {
  background: linear-gradient(to top, var(--bg-base) 60%, rgba(255, 255, 255, 0));
}

.jump-bottom-btn {
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 4;
  width: 44px;
  height: 44px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-input);
  color: var(--text-secondary);
  box-shadow: var(--shadow-soft);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transform: translateX(-50%);
  transition: opacity 0.16s ease, transform 0.16s ease, background 0.16s ease, color 0.16s ease;
  -webkit-tap-highlight-color: transparent;
}

.jump-bottom-btn:hover,
.jump-bottom-btn:focus-visible {
  background: var(--bg-soft);
  color: var(--text-main);
  outline: none;
}

.jump-bottom-btn svg,
.jump-bottom-btn i {
  width: 18px;
  height: 18px;
}

.viewport-inner.home-state .jump-bottom-btn {
  display: none !important;
}

.file-preview-indicator {
  width: min(var(--composer-max-width), 100%);
  max-width: min(var(--composer-max-width), 100%);
  margin: 0 auto 8px;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  padding: 0;
}

.file-preview-chip {
  width: fit-content;
  max-width: calc(100% - 8px);
  min-height: 34px;
  border: 0;
  border-radius: 14px;
  background: var(--bg-input);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 7px;
  padding: 0 12px;
  color: var(--text-secondary);
  font-size: 13px;
  overflow: hidden;
}

.file-preview-indicator i,
.file-preview-indicator svg {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
}

.file-name {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-preview-indicator .file-name {
  flex: 0 1 auto;
  max-width: min(42vw, 150px);
}

.remove-file-btn {
  margin-left: auto;
  width: 24px;
  height: 24px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.remove-file-btn:hover {
  background: var(--bg-elevated);
  color: var(--text-main);
}

.composer-pill {
  width: min(var(--composer-max-width), 100%);
  margin: 0 auto;
  min-height: 50px;
  border: 0;
  border-radius: 32px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01)), var(--bg-input);
  box-shadow: 0 0 10px rgba(203, 213, 225, 0.24), 0 10px 24px rgba(0, 0, 0, 0.22);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  transition: var(--transition-fast);
}

.composer-pill:focus-within {
  box-shadow: 0 0 12px rgba(203, 213, 225, 0.3), 0 14px 32px rgba(0, 0, 0, 0.28);
}

.composer-disclaimer {
  width: min(var(--composer-max-width), 100%);
  margin: 7px auto 0;
  padding: 0 12px;
  color: var(--text-muted);
  font-size: 11.5px;
  line-height: 1.35;
  letter-spacing: 0.005em;
  text-align: center;
  opacity: 0.78;
  user-select: none;
  overflow-wrap: anywhere;
}

.textarea-wrapper {
  min-width: 0;
  display: flex;
  align-items: center;
  min-height: 34px;
}

.composer-textarea {
  width: 100%;
  min-height: 22px;
  max-height: 220px;
  border: 0;
  background: transparent;
  color: var(--text-main);
  resize: none;
  font-size: 15px;
  line-height: 1.45;
  overflow-y: auto;
  padding: 5px 0 4px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.composer-textarea::-webkit-scrollbar {
  width: 0;
  height: 0;
  display: none;
}

.composer-textarea:focus {
  outline: none;
}

.composer-textarea::placeholder {
  color: var(--text-muted);
}

.composer-action-btn,
.composer-submit-btn,
.mode-dropdown-trigger {
  min-height: 34px;
  border: 0;
  border-radius: var(--radius-md);
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition-fast);
}

.composer-action-btn {
  width: 34px;
  border-radius: 999px;
  align-self: flex-end;
}

.attach-btn {
  color: var(--text-secondary);
}

.attach-btn svg,
.attach-btn i {
  width: 18px;
  height: 18px;
}

.composer-action-btn:hover,
.mode-dropdown-trigger:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

.composer-submit-btn {
  width: 32px;
  min-height: 32px;
  border-radius: 999px;
  background: transparent;
  color: var(--text-muted);
  align-self: flex-end;
}

.composer-submit-btn:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

.composer-submit-btn svg,
.composer-submit-btn i {
  width: 17px;
  height: 17px;
}

.composer-submit-btn.is-cancel {
  background: transparent;
  color: #fca5a5;
}

.composer-submit-btn.is-cancel:hover {
  background: rgba(var(--danger-rgb), 0.14);
}

.composer-right-controls {
  display: inline-flex;
  align-items: flex-end;
  gap: 6px;
  align-self: flex-end;
}

.mode-dropdown {
  position: relative;
}

.mode-dropdown-trigger {
  min-width: 82px;
  padding: 0 8px;
  gap: 6px;
  background: transparent;
  font-size: 13px;
  border-radius: 999px;
}

.selected-mode-text {
  color: var(--text-main);
  font-size: 13px;
}

.mode-dropdown-trigger svg,
.mode-dropdown-trigger i {
  width: 12px;
  height: 12px;
  transition: transform 0.18s ease;
}

.mode-dropdown-trigger.open svg,
.mode-dropdown-trigger.open i {
  transform: rotate(180deg);
}

.mode-dropdown-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  width: min(214px, 92vw);
  min-width: 214px;
  max-width: min(214px, 92vw);
  border: 0;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  box-shadow: var(--shadow-popover);
  padding: 4px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 24;
}

.viewport-inner.home-state .mode-dropdown-menu {
  top: calc(100% + 8px);
  bottom: auto;
}

.mode-dropdown-menu.show {
  display: flex;
}

.mode-option {
  border: 0;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  color: var(--text-secondary);
  transition: var(--transition-fast);
  cursor: pointer;
}

.mode-option-header i,
.mode-option-header svg {
  display: none !important;
}

.mode-option:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

.mode-option.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
}

body.theme-light .mode-option.active {
  background: #e7ebf1;
}

body.theme-light .composer-pill {
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(255, 255, 255, 0.62)), var(--bg-input);
}

/* ---------- Light Mode Main Page ----------
   Blok token duplikat dihapus (addendum §1: jangan menumpuk override yang
   saling bertabrakan). Permukaan kini murni berasal dari theme.css:
   --bg (putih lembut) untuk utama dan --bg-sidebar (sedikit lebih gelap). */
body.theme-light .main-content,
body.theme-light .viewport-inner,
body.theme-light .chat-viewport,
body.theme-light .home-container {
  background: var(--bg-base);
}

body.theme-light .composer-container {
  background: linear-gradient(to top, var(--bg-base) 62%, rgba(255, 255, 255, 0));
}

body.theme-light .composer-pill {
  background: var(--bg-input);
  border: 0;
  box-shadow: 0 0 8px rgba(148, 163, 184, 0.26), 0 10px 24px rgba(15, 23, 42, 0.06);
}

body.theme-light .profile-menu,
body.theme-light .history-dropdown,
body.theme-light .mode-dropdown-menu {
  background: #f7f8fa;
  border: 0;
  box-shadow: 0 12px 28px rgba(15, 23, 42, 0.08);
}

body.theme-light .settings-modal-content {
  background: #f9fafb;
  border: 1px solid #e5e7eb;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.1);
}

body.theme-light .settings-header,
body.theme-light .settings-sidebar,
body.theme-light .settings-panel {
  background: #ffffff;
}

body.theme-light .settings-sidebar::after {
  background: #e5e7eb;
}

.mode-option.disabled {
  opacity: 0.52;
}

.mode-option-header {
  display: inline-flex;
  align-items: center;
  gap: 0;
  font-size: 12.5px;
  margin-bottom: 2px;
}

.mode-option-desc {
  font-size: 11.5px;
  color: var(--text-muted);
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.mode-dropdown-divider {
  height: 1px;
  margin: 2px 2px 1px;
  background: var(--border-soft);
}

.mode-more-trigger {
  width: 100%;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  min-height: 32px;
  padding: 7px 10px;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  transition: var(--transition-fast);
}

body:not(.theme-light) .composer-pill {
  background: var(--bg-elevated);
}

.mode-more-trigger i,
.mode-more-trigger svg {
  width: 12px;
  height: 12px;
  color: var(--text-muted);
  transition: transform 0.15s ease;
}

.mode-more-trigger:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

.mode-more-trigger[aria-expanded="true"] i,
.mode-more-trigger[aria-expanded="true"] svg {
  transform: rotate(90deg);
}

.mode-more-panel {
  border: 0;
  border-radius: var(--radius-sm);
  margin: 2px 0 2px;
  padding: 2px 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.mode-more-item {
  min-height: 28px;
  padding: 6px 10px;
  border-radius: 8px;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  opacity: 0.88;
}

.mode-more-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mode-coming-badge {
  border: 0;
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 10px;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.08);
  line-height: 1.1;
  white-space: nowrap;
}

body.theme-light .mode-coming-badge {
  background: rgba(0, 0, 0, 0.08);
}

/* ---------- Generic Overlays ---------- */
.search-modal,
.settings-modal,
.delete-modal,
.logout-modal,
.upgrade-modal,
.doc-modal,
.docs-modal,
.share-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.search-modal.show,
.settings-modal.show,
.delete-modal.show,
.logout-modal.show,
.upgrade-modal.show,
.doc-modal.show,
.docs-modal.show,
.share-modal.show {
  display: flex;
}

.search-modal-content,
.settings-modal-content,
.delete-modal-content,
.logout-modal-content,
.upgrade-modal-content,
.doc-modal-content,
.share-modal-content {
  width: min(720px, 100%);
  max-height: 90vh;
  overflow: auto;
  border: 0;
  border-radius: var(--radius-lg);
  background: var(--bg-panel);
  box-shadow: var(--shadow-popover);
}

.search-modal-content,
.doc-modal-content,
.share-modal-content,
.delete-modal-content,
.logout-modal-content,
.upgrade-modal-content {
  padding: 16px;
}

/* ---------- Search Modal ---------- */
.search-input-wrapper {
  min-height: 42px;
  border: 0;
  border-radius: var(--radius-md);
  background: var(--bg-input);
  display: grid;
  grid-template-columns: 18px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 0 10px;
}

.search-input-wrapper input {
  border: 0;
  background: transparent;
  color: var(--text-main);
  font-size: 14px;
}

.search-input-wrapper input:focus {
  outline: none;
}

.search-results {
  margin-top: 10px;
  max-height: min(56vh, 480px);
  overflow-y: auto;
}

.search-results-empty {
  padding: 22px 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.search-result-item {
  min-height: 38px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 10px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  transition: var(--transition-fast);
  cursor: pointer;
}

.search-result-item:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

/* ---------- Settings Modal ---------- */
.settings-modal,
.upgrade-modal {
  background: rgba(4, 4, 6, 0.8) !important;
  backdrop-filter: blur(16px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(16px) saturate(180%) !important;
  transition: all 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
}

.settings-modal-content,
.upgrade-modal-content {
  background: linear-gradient(135deg, rgba(23, 26, 31, 0.96) 0%, rgba(17, 17, 21, 0.98) 100%);
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.65), 
              inset 0 1px 0 rgba(255, 255, 255, 0.05);
  animation: modalContentFadeIn 0.35s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

body:not(.theme-light) .settings-modal-content {
  background: var(--bg-elevated);
  border: 0;
  box-shadow: var(--shadow-popover);
}

body.theme-light .settings-modal-content,
body.theme-light .upgrade-modal-content {
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.98) 0%, rgba(248, 250, 252, 0.98) 100%);
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.08), 
              inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

@keyframes modalContentFadeIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.settings-modal-content {
  width: min(860px, 94vw);
  padding: 0;
  height: min(78dvh, 620px);
  min-height: min(78dvh, 620px);
  max-height: min(78dvh, 620px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-radius: var(--radius-lg);
}

.settings-header {
  min-height: 64px;
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
}

.settings-header h2 {
  font-family: var(--font-brand);
  font-size: 20px;
  font-weight: 700 !important;
  color: var(--text-main);
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.settings-body {
  min-height: 0;
  max-height: none;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: 196px 1fr;
}

.settings-sidebar {
  border-right: 0;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

.settings-sidebar::after {
  content: "";
  position: absolute;
  right: 0;
  top: 18px;
  bottom: 18px;
  width: 1px;
  background: var(--border-soft);
}

.settings-tab-btn {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition-smooth);
  position: relative;
  overflow: hidden;
}

.settings-tab-btn svg,
.settings-tab-btn i {
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  transition: var(--transition-smooth);
}

.settings-tab-btn::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 0;
  background: #a1a1aa;
  border-radius: 0 3px 3px 0;
  transition: var(--transition-smooth);
}

body.theme-light .settings-tab-btn::before {
  background: #71717a;
}

.settings-tab-btn:hover {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-main);
  padding-left: 18px; /* slide transition */
}

body.theme-light .settings-tab-btn:hover {
  background: #eef2f7;
}

.settings-tab-btn:hover svg,
.settings-tab-btn:hover i {
  color: var(--text-main);
}

.settings-tab-btn.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  font-weight: 600;
  padding-left: 18px;
}

.settings-tab-btn.active::before {
  height: 18px;
}

.settings-tab-btn.active svg,
.settings-tab-btn.active i {
  color: var(--text-main);
  transform: scale(1.1);
}

body.theme-light .settings-tab-btn.active {
  background: #e7ebf1;
  color: var(--text-main);
}

body.theme-light .settings-tab-btn.active svg,
body.theme-light .settings-tab-btn.active i {
  color: var(--text-main);
}

.settings-panel {
  padding: 24px;
  min-height: 0;
  overflow-y: auto;
  max-height: none;
}

.settings-tab-content {
  display: none;
}

.settings-tab-content.active {
  display: block;
}

.settings-tab-content h3 {
  font-family: var(--font-brand);
  font-size: 18px;
  font-weight: 700 !important;
  color: var(--text-main);
  margin-bottom: 18px;
}

.settings-account-info {
  display: block;
}

.settings-form-group {
  margin-bottom: 16px;
}

.settings-form-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  font-weight: 600 !important;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.settings-readonly-field,
.settings-form-group input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text-main);
  display: flex;
  align-items: center;
  padding: 0 14px;
  font-size: 14px;
  transition: var(--transition-smooth);
}

body.theme-light .settings-readonly-field,
body.theme-light .settings-form-group input {
  background: #f3f5f8;
  border-color: #dbe1e8;
}

.settings-form-group input:focus {
  outline: none;
  border-color: var(--text-muted);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.06);
  background: rgba(255, 255, 255, 0.04);
}

body.theme-light .settings-form-group input:focus {
  border-color: #71717a;
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.04);
  background: #eef2f7;
}

.settings-readonly-field,
.settings-plan-badge {
  user-select: none;
}

.settings-plan-badge {
  display: inline-flex;
  align-items: center;
  width: auto;
  max-width: 100%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600 !important;
  letter-spacing: 0.02em;
  min-height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

body.theme-light .settings-plan-badge {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-main);
  border: 1px solid var(--border);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.02);
}

.settings-guest-notice {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  padding: 20px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: flex-start;
}

.settings-guest-notice.hidden {
  display: none !important;
}

.settings-guest-notice i,
.settings-guest-notice svg {
  color: var(--text-muted);
  width: 20px;
  height: 20px;
}

.settings-guest-notice p {
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-secondary);
}

.settings-login-link {
  min-height: 38px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--text-main);
  color: var(--bg-base) !important;
  display: inline-flex;
  align-items: center;
  padding: 0 16px;
  font-weight: 500;
  transition: var(--transition-smooth);
}

.settings-login-link:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

body.theme-light .settings-login-link {
  background: #111111;
  color: #ffffff !important;
}

.settings-divider {
  height: 1px;
  background: var(--border-soft);
  margin: 18px 0;
}

.settings-danger-btn {
  min-height: 42px;
  border: 1px solid rgba(var(--danger-rgb), 0.2);
  border-radius: var(--radius-sm);
  background: rgba(var(--danger-rgb), 0.06);
  color: var(--danger);
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition-smooth);
}

.settings-danger-btn svg,
.settings-danger-btn i {
  width: 15px;
  height: 15px;
}

.settings-danger-btn:hover {
  background: rgba(var(--danger-rgb), 0.14);
  color: #ff6b6b;
  border-color: rgba(var(--danger-rgb), 0.35);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(var(--danger-rgb), 0.1);
}

body.theme-light .settings-danger-btn {
  background: rgba(var(--danger-rgb), 0.05);
  border-color: rgba(var(--danger-rgb), 0.2);
  color: var(--danger);
}

body.theme-light .settings-danger-btn:hover {
  background: rgba(var(--danger-rgb), 0.1);
  color: var(--danger);
  border-color: rgba(var(--danger-rgb), 0.3);
}

.usage-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.usage-panel-secondary {
  margin-top: 14px;
}

.usage-title {
  font-size: 11px;
  font-weight: 600 !important;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.usage-meter {
  height: 12px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--bg-soft);
  overflow: hidden;
  position: relative;
}

.usage-meter-fill {
  height: 100%;
  width: 0;
  background: #ffffff; /* White progress bar in dark mode */
  box-shadow: 0 0 12px rgba(255, 255, 255, 0.3);
  position: relative;
  border-radius: var(--radius-pill);
}

.usage-meter-fill::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.3) 50%,
    rgba(255, 255, 255, 0) 100%
  );
  animation: none;
}

@keyframes usagePulse {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

body.theme-light .usage-meter-fill {
  background: #71717a; /* Grey progress bar in light mode */
  box-shadow: 0 0 8px rgba(113, 113, 122, 0.2);
}

body.theme-light .usage-meter-fill::after {
  background: linear-gradient(
    90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, 0.4) 50%,
    rgba(255, 255, 255, 0) 100%
  );
}

.usage-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.usage-grid > div {
  border: 0;
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  padding: 14px;
  text-align: center;
  transition: var(--transition-smooth);
}

.usage-grid > div:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
}

.usage-grid span {
  display: block;
  font-size: 11px;
  font-weight: 600 !important;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.usage-grid strong {
  font-size: 20px;
  font-family: var(--font-brand);
  font-weight: 700 !important;
  color: var(--text-main);
}

.theme-options-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stream-render-group {
  margin-top: 16px;
}

.stream-render-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.stream-render-option {
  position: relative;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--text-secondary);
  width: 100%;
  min-height: 78px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  cursor: pointer;
  text-align: left;
  transition: var(--transition-smooth);
}

.stream-render-option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.stream-render-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.2;
}

.stream-render-desc {
  font-size: 11.5px;
  line-height: 1.35;
  color: var(--text-muted);
}

.stream-render-option:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

.stream-render-option:focus-visible {
  outline: none;
  box-shadow: var(--shadow-soft);
}

.stream-render-option.is-active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  box-shadow: 0 8px 24px rgba(255, 255, 255, 0.04);
}

body.theme-light .stream-render-option.is-active {
  background: rgba(0, 0, 0, 0.05);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.06);
}

.settings-helper-text {
  margin-top: 9px;
  font-size: 12px;
  line-height: 1.4;
  color: var(--text-muted);
}

.theme-card {
  border: 0;
  border-radius: var(--radius-md);
  background: var(--bg-soft);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: var(--text-secondary);
  transition: var(--transition-smooth);
  cursor: pointer;
}

.theme-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-soft);
  color: var(--text-main);
}

.theme-card.active {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-main);
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(255, 255, 255, 0.04);
}

body.theme-light .theme-card.active {
  background: rgba(0, 0, 0, 0.04);
  color: var(--text-main);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.02);
}

.theme-card span {
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}

.theme-card-preview {
  border-radius: 8px;
  overflow: hidden;
  border: 0;
}

/* ---------- Small Modals ---------- */
.delete-modal-content,
.logout-modal-content {
  width: min(420px, 100%);
}

.delete-modal h3,
.logout-modal h3 {
  font-family: var(--font-brand);
  font-size: 18px;
  margin-bottom: 8px;
}

.delete-modal p,
.logout-modal p {
  color: var(--text-secondary);
  font-size: 13.5px;
  line-height: 1.55;
}

.delete-modal strong {
  display: inline-block;
  margin-top: 2px;
  color: var(--text-main);
  font-size: 13px;
  line-height: 1.4;
  word-break: break-word;
}

.delete-modal-actions,
.logout-modal-actions,
.doc-modal-actions,
.share-modal-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

/* ---------- Plan Upgrade Modal ---------- */
.upgrade-modal-content {
  width: min(460px, 94vw);
  padding: 32px 28px 24px;
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  gap: 16px;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.upgrade-modal-content::before {
  content: "";
  position: absolute;
  top: -80px;
  left: 50%;
  transform: translateX(-50%);
  width: 160px;
  height: 160px;
  background: radial-gradient(circle, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0) 70%);
  z-index: 0;
  pointer-events: none;
}

body.theme-light .upgrade-modal-content::before {
  background: radial-gradient(circle, rgba(0, 0, 0, 0.05) 0%, rgba(0, 0, 0, 0) 70%);
}

.upgrade-modal-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  z-index: 1;
}

.upgrade-modal h3 {
  font-family: var(--font-brand);
  font-size: 24px;
  font-weight: 800 !important;
  letter-spacing: -0.01em;
  background: var(--brand-gradient);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  margin: 0;
}

.upgrade-modal-desc {
  font-size: 14.5px;
  line-height: 1.66;
  color: var(--text-secondary);
  margin: 0 auto;
  max-width: 380px;
  z-index: 1;
}

.upgrade-contacts-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 6px;
  z-index: 1;
}

.upgrade-contact-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.02);
  transition: var(--transition-smooth);
  text-align: left;
  position: relative;
}

body.theme-light .upgrade-contact-card {
  background: rgba(0, 0, 0, 0.01);
}

.upgrade-contact-card:hover {
  transform: translateY(-3px);
  background: rgba(255, 255, 255, 0.04);
  box-shadow: var(--shadow-soft);
}

body.theme-light .upgrade-contact-card:hover {
  background: rgba(0, 0, 0, 0.03);
}

.upgrade-contact-card.instagram:hover {
  border-color: rgba(225, 48, 108, 0.5);
  box-shadow: 0 8px 24px rgba(225, 48, 108, 0.15);
}

.upgrade-contact-card.email:hover {
  border-color: var(--text-muted);
  box-shadow: 0 8px 24px rgba(255, 255, 255, 0.04);
}

body.theme-light .upgrade-contact-card.email:hover {
  border-color: #71717a;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.02);
}

.upgrade-contact-card svg,
.upgrade-contact-card i {
  width: 20px;
  height: 20px;
  color: var(--text-muted);
  transition: var(--transition-smooth);
  flex-shrink: 0;
}

.upgrade-contact-card.instagram:hover svg,
.upgrade-contact-card.instagram:hover i {
  color: #e1306c;
  transform: scale(1.1);
}

.upgrade-contact-card.email:hover svg,
.upgrade-contact-card.email:hover i {
  color: var(--text-main);
  transform: scale(1.1);
}

.upgrade-contact-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  flex: 1;
}

.contact-label {
  font-size: 11px;
  font-weight: 600 !important;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.contact-value {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.contact-arrow {
  width: 14px !important;
  height: 14px !important;
  opacity: 0.5;
  transition: var(--transition-smooth) !important;
}

.upgrade-contact-card:hover .contact-arrow {
  opacity: 1;
  transform: translate(3px, -3px) scale(1.1);
  color: var(--text-main) !important;
}

.upgrade-close-btn {
  align-self: center;
  min-height: 40px;
  min-width: 120px;
  border-radius: 999px;
  background: var(--text-main);
  color: var(--bg-base);
  font-weight: 600 !important;
  border: 1px solid transparent;
  transition: var(--transition-smooth);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  margin-top: 8px;
  z-index: 1;
}

.upgrade-close-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  background: var(--text-secondary);
  color: var(--bg-base) !important;
}

body.theme-light .upgrade-close-btn {
  background: #111111;
  color: #ffffff;
}

body.theme-light .upgrade-close-btn:hover {
  background: #000000;
  color: #ffffff !important;
}

/* ---------- Docs / Share Modals ---------- */
.doc-modal-content,
.share-modal-content {
  width: min(680px, 100%);
}

.doc-modal-content h3,
.share-modal-content h3 {
  font-family: var(--font-brand);
  font-size: 17px;
  margin-bottom: 8px;
}

.doc-modal-content p,
.share-modal-content p,
.docs-empty {
  color: var(--text-muted);
  font-size: 13px;
}

.doc-modal-content label {
  display: block;
  margin: 10px 0 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

/* ---------- Dark Mode Surface Sync (Search / Docs / Share) ---------- */
body:not(.theme-light) .search-modal-content,
body:not(.theme-light) .share-modal-content {
  background: var(--bg-elevated);
  color: var(--text-main);
  border: 0;
  box-shadow: var(--shadow-popover);
}

body:not(.theme-light) .search-input-wrapper {
  background: var(--bg-soft);
  color: var(--text-main);
  border: 1px solid var(--border-soft);
}

body:not(.theme-light) .search-input-wrapper input::placeholder {
  color: var(--text-muted);
}

body:not(.theme-light) .search-results-empty,
body:not(.theme-light) .share-modal-content p,
body:not(.theme-light) .docs-empty {
  color: var(--text-secondary);
}

body:not(.theme-light) .search-result-item {
  color: var(--text-secondary);
}

body:not(.theme-light) .search-result-item:hover {
  background: var(--bg-soft);
  color: var(--text-main);
}

/* ---------- Light Mode Surface Polish (Search / Docs / Share) ---------- */
body.theme-light .search-modal-content,
body.theme-light .share-modal-content {
  background: #f9fafb;
  border: 1px solid rgba(15, 23, 42, 0.08);
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.1);
}

/* Sidebar TIDAK lagi dipaksa putih di mode terang. Sebelumnya aturan
   `body.theme-light .sidebar{background:#ffffff}` membuat sidebar dan area
   utama sama-sama putih sehingga batas permukaan hilang. Sekarang sidebar
   memakai token --bg-sidebar (di mode terang = --surface #f7f8fa) sehingga
   tetap ada pemisahan halus yang konsisten dengan mode gelap. */
body.theme-light .settings-modal-content,
body.theme-light .settings-header,
body.theme-light .settings-sidebar,
body.theme-light .settings-panel {
  background: #ffffff;
}

body.theme-light .settings-modal-content {
  border: 1px solid #e5e7eb;
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.1);
}

body.theme-light .settings-sidebar::after {
  background: #e5e7eb;
}

body.theme-light .search-input-wrapper {
  background: #f3f5f8;
  border: 0;
  color: #0f172a;
}

body.theme-light .search-input-wrapper input::placeholder {
  color: #64748b;
}

body.theme-light .search-results-empty,
body.theme-light .share-modal-content p,
body.theme-light .docs-empty {
  color: #475569;
}

body.theme-light .search-result-item {
  color: #334155;
}

body.theme-light .search-result-item:hover {
  background: #eef2f7;
  color: #0f172a;
}

body.theme-light .user-content {
  background: #eef2f7;
  border: 0;
}

body.theme-light ::selection {
  background: #dfe6ef;
  color: #0f172a;
}

/* ---------- Sidebar Contrast Boost (Requested) ---------- */
body:not(.theme-light) .sidebar-primary-box,
body:not(.theme-light) .sidebar-primary-box .btn-text,
body:not(.theme-light) .history-item,
body:not(.theme-light) .history-text,
body:not(.theme-light) .history-group-title,
body:not(.theme-light) .history-group-toggle {
  color: #ffffff !important;
}

body:not(.theme-light) .sidebar-primary-box svg,
body:not(.theme-light) .sidebar-primary-box i,
body:not(.theme-light) .history-leading-icon,
body:not(.theme-light) .history-leading-icon svg,
body:not(.theme-light) .history-leading-icon i,
body:not(.theme-light) .history-more-btn,
body:not(.theme-light) .history-more-btn svg,
body:not(.theme-light) .history-more-btn i,
body:not(.theme-light) .history-group-toggle svg,
body:not(.theme-light) .history-group-toggle i {
  color: #ffffff !important;
}

body.theme-light .sidebar-primary-box,
body.theme-light .sidebar-primary-box .btn-text,
body.theme-light .history-item,
body.theme-light .history-text,
body.theme-light .history-group-title,
body.theme-light .history-group-toggle {
  color: #000000 !important;
}

body.theme-light .sidebar-primary-box svg,
body.theme-light .sidebar-primary-box i,
body.theme-light .history-leading-icon,
body.theme-light .history-leading-icon svg,
body.theme-light .history-leading-icon i,
body.theme-light .history-more-btn,
body.theme-light .history-more-btn svg,
body.theme-light .history-more-btn i,
body.theme-light .history-group-toggle svg,
body.theme-light .history-group-toggle i {
  color: #000000 !important;
}

body:not(.theme-light) .history-dropdown-item,
body:not(.theme-light) .history-dropdown-item span,
body:not(.theme-light) .history-dropdown-item.pin-opt,
body:not(.theme-light) .history-dropdown-item.rename-opt,
body:not(.theme-light) .history-dropdown-item.delete-opt,
body:not(.theme-light) .search-result-item,
body:not(.theme-light) .search-result-item span {
  color: #ffffff !important;
}

body:not(.theme-light) .history-dropdown-item svg,
body:not(.theme-light) .history-dropdown-item i {
  color: #ffffff !important;
}

body.theme-light .history-dropdown-item,
body.theme-light .history-dropdown-item span,
body.theme-light .history-dropdown-item.pin-opt,
body.theme-light .history-dropdown-item.rename-opt,
body.theme-light .history-dropdown-item.delete-opt,
body.theme-light .search-result-item,
body.theme-light .search-result-item span {
  color: #000000 !important;
}

body.theme-light .history-dropdown-item svg,
body.theme-light .history-dropdown-item i {
  color: #000000 !important;
}

/* ---------- Optional hidden bars ---------- */
.quick-tools-bar,
.response-actions-bar {
  display: none !important;
}

/* ---------- Responsive ---------- */
@media (max-width: 1024px) {
  :root {
    --sidebar-width: 250px;
    --chat-max-width: 800px;
    --composer-max-width: 780px;
  }
}

@media (max-width: 768px) {
  .mobile-header {
    position: fixed;
    top: 10px;
    left: 10px;
    z-index: 120;
    display: block;
  }

  .mobile-menu-btn {
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    color: var(--text-main);
    padding: 0;
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .app-container {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    height: 100dvh !important;
    width: var(--sidebar-width);
    z-index: 130;
    transform: translateX(-100%);
    transition: transform 0.18s ease;
  }

  /* JS membuka laci dengan kelas `mobile-open` (openMobileSidebar di script.js),
     sedangkan aturan lama hanya menggayai `.sidebar.show`. Tanpa menyertakan
     `mobile-open` di sini, menekan tombol menu di ponsel hanya memunculkan
     lapisan gelap sementara sidebar tetap di luar layar (x = -250), sehingga
     Library/Projects/Jobs/Pengaturan tidak dapat dijangkau sama sekali.
     Kedua nama kelas didukung agar tidak ada pemanggil lama yang rusak. */
  .sidebar.show,
  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    display: block;
    z-index: 120;
    background: rgba(0, 0, 0, 0.52);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
  }

  .sidebar-overlay.show {
    opacity: 1;
    pointer-events: auto;
  }

  .chat-viewport {
    padding: 56px 14px var(--mobile-chat-bottom-space);
  }

  .top-share-btn {
    top: calc(10px + env(safe-area-inset-top, 0px));
    right: 12px;
    font-size: 12px;
    min-height: 28px;
    padding: 4px 9px;
  }

  .viewport-inner.has-top-share .chat-viewport {
    padding-top: calc(56px + env(safe-area-inset-top, 0px));
  }

  .chat-messages {
    padding: 0 0 22px;
  }

  .message.user {
    max-width: 84%;
  }

  .assistant-content {
    width: 100%;
    font-size: 14px;
    line-height: 1.66;
  }

  .composer-container {
    position: relative;
    bottom: auto;
    z-index: 20;
    padding: 8px 10px calc(14px + env(safe-area-inset-bottom, 0px) + var(--composer-bottom-offset));
  }

  .viewport-inner:not(.home-state) .composer-container {
    position: fixed;
    left: 0;
    right: 0;
    bottom: calc(env(safe-area-inset-bottom, 0px) + var(--composer-bottom-offset));
    z-index: 90;
    padding: 8px 10px 12px;
    background: linear-gradient(to top, var(--bg-base) 78%, rgba(0, 0, 0, 0));
    transition: bottom 0.2s ease, padding 0.2s ease;
  }

  body.theme-light .viewport-inner:not(.home-state) .composer-container {
    background: linear-gradient(to top, var(--bg-base) 78%, rgba(255, 255, 255, 0));
  }

  body.keyboard-open .viewport-inner:not(.home-state) .composer-container {
    transition: bottom 0.12s linear, padding 0.12s linear;
  }

  .composer-pill {
    grid-template-columns: auto minmax(0, 1fr) auto;
    border-radius: var(--radius-xl);
    align-items: end;
    gap: 8px;
  }

  .textarea-wrapper {
    min-height: 34px;
    align-self: end;
    align-items: center;
  }

  .composer-textarea {
    min-height: 23px;
    max-height: 112px;
    line-height: 1.42;
    padding: 4px 0;
  }

  .composer-disclaimer {
    margin-top: 6px;
    padding: 0 8px;
    font-size: 10.8px;
    line-height: 1.32;
  }

  .composer-right-controls {
    grid-column: auto;
    align-self: end;
    align-items: flex-end;
    justify-content: flex-end;
    padding-bottom: 1px;
  }

  .composer-action-btn,
  .composer-submit-btn {
    align-self: end;
  }

  .mode-dropdown-trigger {
    min-width: 70px;
  }

  .mode-dropdown-menu {
    width: min(230px, 94vw);
    min-width: 0;
    max-width: min(230px, 94vw);
  }

  .mode-more-trigger {
    min-height: 34px;
  }

  .mode-more-item {
    min-height: 30px;
  }

  .sidebar-primary-box,
  .history-group-toggle,
  .history-item,
  .profile-menu-btn,
  .settings-tab-btn,
  .mode-option {
    user-select: none;
    -webkit-user-select: none;
  }

  .mode-dropdown-menu {
    width: min(230px, 94vw);
    min-width: 0;
    max-width: min(230px, 94vw);
  }

  .mode-option {
    padding: 7px 8px;
  }

  .mode-option-header {
    font-size: 12px;
    margin-bottom: 1px;
  }

  .mode-option-desc {
    font-size: 11px;
  }

  .settings-body {
    min-height: 0;
    max-height: none;
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
  }

  .settings-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 8px;
    padding: 10px 12px 12px;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
  }

  .settings-sidebar::after {
    display: none;
  }

  .settings-tab-btn {
    flex: 0 0 auto;
    justify-content: center;
    padding: 0 12px;
    min-height: 38px;
    min-width: 108px;
    white-space: nowrap;
  }

  .settings-tab-btn span {
    display: inline;
  }

  .settings-tab-btn::before {
    left: 50%;
    top: auto;
    bottom: 0;
    transform: translateX(-50%);
    width: 0;
    height: 3px;
    border-radius: 3px 3px 0 0;
  }

  .settings-tab-btn.active::before {
    width: 24px;
    height: 3px;
  }

  .settings-tab-btn:hover {
    padding-left: 12px; /* disable slide out on mobile */
  }

  .settings-tab-btn.active {
    padding-left: 12px;
  }

  .settings-sidebar::-webkit-scrollbar {
    height: 4px;
  }

  .settings-sidebar::-webkit-scrollbar-track {
    background: transparent;
  }

  .settings-sidebar::-webkit-scrollbar-thumb {
    background: var(--border-hover);
    border-radius: 999px;
  }

  .settings-modal-content {
    height: min(78vh, 620px);
    min-height: min(78vh, 620px);
    max-height: min(78vh, 620px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }

  @supports (height: 1svh) {
    .settings-modal-content {
      height: min(78svh, 620px);
      min-height: min(78svh, 620px);
      max-height: min(78svh, 620px);
    }
  }

  .settings-header {
    position: sticky;
    top: 0;
    z-index: 4;
    background: var(--bg-panel);
  }

  .settings-panel {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    padding: 14px;
  }

  .theme-options-grid,
  .usage-grid {
    grid-template-columns: 1fr;
  }

  .stream-render-grid {
    grid-template-columns: 1fr;
  }

  .history-item .history-more-btn {
    display: inline-flex !important;
  }

  

  

  /* Hide user profile at the bottom of the sidebar during renaming to prevent keyboard push-up on mobile only */
  .sidebar.has-renaming .sidebar-bottom,
  .sidebar:has(.rename-editor) .sidebar-bottom {
    display: none !important;
  }
}

@media (max-width: 540px) {
  .message.user {
    max-width: 88%;
  }

  .thinking-inline-card {
    width: fit-content;
    max-width: 100%;
    grid-template-columns: 16px minmax(0, 1fr);
    gap: 7px;
  }

  .thinking-inline-meta {
    font-size: 10.5px;
  }

  .composer-pill {
    padding: 9px;
  }

  .composer-disclaimer {
    font-size: 10.4px;
    line-height: 1.28;
  }

  .settings-tab-btn {
    font-size: 12px;
    padding: 0 8px;
    gap: 6px;
  }

  .settings-tab-btn svg,
  .settings-tab-btn i {
    width: 13px;
    height: 13px;
  }

  .settings-header {
    padding: 0 16px;
  }

  .settings-panel {
    padding: 16px 12px;
  }

  .upgrade-modal-content {
    padding: 24px 18px 18px;
    border-radius: 18px;
  }

  .upgrade-modal h3 {
    font-size: 20px;
  }

  .upgrade-close-btn {
    align-self: stretch;
  }
}

@media (orientation: landscape) and (max-height: 540px) {
  .composer-textarea {
    max-height: 120px;
  }

  .thinking-panel {
    width: min(420px, 72vw);
    padding-top: 12px;
    padding-bottom: 12px;
  }
}

/* Landscape orientation low-height overrides (e.g. mobile rotated landscape) */
@media (max-height: 580px) {
  .settings-modal-content {
    height: 92dvh !important;
    min-height: 92dvh !important;
    max-height: 92dvh !important;
    border-radius: var(--radius-md) !important;
  }

  .settings-body {
    flex-direction: row !important; /* side by side settings on landscape */
  }

  .settings-sidebar {
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    border-bottom: 0 !important;
    border-right: 1px solid var(--border-soft) !important;
    width: 170px !important;
    padding: 10px !important;
    overflow-y: auto !important;
  }

  .settings-sidebar::after {
    display: none !important;
  }

  .settings-tab-btn {
    flex: 0 0 auto !important;
    justify-content: flex-start !important;
    font-size: 13px !important;
  }

  .settings-tab-btn::before {
    left: 0 !important;
    top: 50% !important;
    bottom: auto !important;
    transform: translateY(-50%) !important;
    width: 3px !important;
    height: 0 !important;
  }

  .settings-tab-btn.active::before {
    height: 18px !important;
    width: 3px !important;
  }

  .upgrade-modal-content {
    max-height: 92dvh !important;
    overflow-y: auto !important;
    padding: 16px 20px !important;
  }

  .upgrade-sparkle-icon {
    width: 44px !important;
    height: 44px !important;
  }

  .upgrade-sparkle-icon svg,
  .upgrade-sparkle-icon i {
    width: 20px !important;
    height: 20px !important;
  }

  .upgrade-modal h3 {
    font-size: 20px !important;
  }
}

@media (max-width: 768px) {
  .thinking-panel {
    width: 100vw;
    max-width: 100vw;
    border-left: 0;
    padding-left: 16px;
    padding-right: 16px;
  }

  .thinking-panel-overlay {
    background: rgba(0, 0, 0, 0.42);
  }

  .thinking-panel h3 {
    font-size: 20px;
  }

  .thinking-panel-live-card {
    grid-template-columns: 32px minmax(0, 1fr);
    padding: 12px;
  }

  .thinking-panel-orb {
    width: 32px;
    height: 32px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .thinking-inline-card,
  .thinking-panel,
  .thinking-panel-overlay {
    transition: none !important;
  }

  .thinking-inline-card.is-active::after,
  .thinking-orb::after,
  .thinking-inline-card.is-active .thinking-orb span,
  .thinking-inline-card.is-active .thinking-inline-title,
  .thinking-panel-orb::after {
    animation: none !important;
  }
}
