/* ==========================================================================
   CHAT-FREE — MODALS, DIALOGS & FLOATING POPOVERS (modals.css)
   ========================================================================== */

/* ==========================================================================
   FLOATING POPOVER MENUS
   ========================================================================== */
.grok-popover {
  position: absolute;
  background: var(--popover-bg);
  border: 1px solid var(--popover-border);
  border-radius: 16px;
  padding: 6px;
  box-shadow: var(--popover-shadow);
  z-index: 100;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: popoverFadeIn 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  backdrop-filter: blur(20px);
}

.popover-header-title {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 5px 10px 4px;
  flex-shrink: 0;
}

.popover-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 9px;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 12.5px;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
  width: 100%;
  flex-shrink: 0;
}

.popover-item-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.popover-item-left span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.popover-item:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

.popover-item.active {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
  font-weight: 500;
}

.popover-item.danger:hover {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
}

.popover-footer-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 3px 6px;
  flex-shrink: 0;
}

.check-icon {
  color: #3b82f6;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
  margin-left: auto;
}

/* Scrollable Models & Persona List (Compact so top of popup is always visible) */
.popover-models-list {
  max-height: 155px;
  overflow-y: auto;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 2px 4px 2px 0;
  overscroll-behavior: contain;
}

.grok-app:not(.empty-state) .popover-models-list {
  max-height: 195px;
}

.popover-models-list::-webkit-scrollbar {
  width: 5px;
}
.popover-models-list::-webkit-scrollbar-track {
  background: transparent;
}
.popover-models-list::-webkit-scrollbar-thumb {
  background: var(--border-medium);
  border-radius: 4px;
}
.popover-models-list::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* Specific Popover Placements */
.model-popover {
  bottom: calc(100% + 8px);
  right: 0;
  width: 310px;
  max-height: 295px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.grok-app:not(.empty-state) .model-popover {
  max-height: 335px;
}

.model-popover > .popover-item {
  flex-shrink: 0;
}

.attach-popover {
  bottom: calc(100% + 8px);
  left: 0;
  width: 240px;
}

.header-popover {
  top: calc(100% + 8px);
  right: 0;
  width: 200px;
}

.user-popover {
  bottom: calc(100% + 2px);
  left: 10px;
  width: 224px;
  border-radius: 18px;
  padding: 10px 8px;
  gap: 2px;
}

.user-popover-subtitle {
  font-size: 13px;
  font-weight: 400;
  color: var(--text-muted);
  padding: 6px 12px 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-popover .popover-item {
  padding: 9px 12px;
  gap: 12px;
  font-size: 14px;
  font-weight: 500;
  border-radius: 10px;
}

.user-popover .popover-item svg {
  color: var(--text-secondary);
  flex-shrink: 0;
  transition: color 0.15s ease;
}

.user-popover .popover-item:hover svg {
  color: var(--text-primary);
}

.popover-chevron-right {
  margin-left: auto;
  color: var(--text-muted);
}

.char-popover {
  position: fixed;
  min-width: 190px;
  background: var(--popover-bg);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
  padding: 6px;
  z-index: 9999;
}

[data-theme="light"] .char-popover {
  background: #ffffff;
  border-color: #e5e7eb;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
}

.persona-popover {
  bottom: calc(100% + 8px);
  right: 0;
  width: 240px;
  min-width: 210px;
  max-height: 270px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ==========================================================================
   MODAL BASE
   ========================================================================== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  transition: opacity 0.2s ease;
  opacity: 1;
}

.modal.hidden {
  opacity: 0;
  pointer-events: none;
  display: flex !important;
}

.modal-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(8px);
}

.modal-content {
  position: relative;
  z-index: 61;
  background: var(--bg-modal);
  border: 1px solid var(--border-medium);
  border-radius: 20px;
  max-width: 600px;
  width: 90%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-modal);
  color: var(--text-primary);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  background: inherit;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  z-index: 2;
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
}

.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  border-top: 1px solid var(--border-subtle);
  position: sticky;
  bottom: 0;
  background: inherit;
  border-bottom-left-radius: 20px;
  border-bottom-right-radius: 20px;
  justify-content: flex-end;
  z-index: 2;
}

/* ==========================================================================
   SETTINGS MODAL (Centered Grok Dialog)
   ========================================================================== */
.settings-modal-card {
  position: relative;
  z-index: 65;
  background: var(--bg-modal);
  border: 1px solid var(--border-medium);
  border-radius: 20px;
  width: 900px;
  max-width: 92vw;
  height: 620px;
  max-height: 85vh;
  display: flex;
  flex-direction: row;
  overflow: hidden;
  box-shadow: var(--shadow-modal);
  animation: modalPopIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalPopIn {
  from { opacity: 0; transform: scale(0.97) translateY(8px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.settings-nav-rail {
  width: 220px;
  min-width: 220px;
  background: var(--bg-modal-rail);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: 16px 10px;
  gap: 14px;
  overflow-y: auto;
}

.settings-nav-section {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.settings-nav-header, .settings-nav-category {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  padding: 4px 12px 6px;
}

.settings-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.15s ease;
}

.settings-nav-item:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

.settings-nav-item.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

[data-theme="dark"] .settings-nav-item.active {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.settings-content-area {
  flex: 1;
  padding: 24px 28px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  background: var(--bg-modal);
  position: relative;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.settings-header h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.settings-tab-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
  animation: panelFade 0.15s ease;
}

.settings-user-card {
  display: flex;
  gap: 18px;
  align-items: center;
  padding: 16px;
  background: var(--bg-sidebar-hover);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
}

.user-avatar-lg {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #3b82f6;
  color: #ffffff;
  font-size: 20px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.settings-user-fields {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-group small, .settings-subtext {
  font-size: 11px;
  color: var(--text-muted);
}

.settings-input, .settings-select {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s ease;
}

.settings-input:focus, .settings-select:focus, .settings-textarea:focus {
  border-color: var(--border-focus);
}

.settings-textarea {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: inherit;
  resize: vertical;
  outline: none;
  line-height: 1.5;
}

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

.theme-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 12px;
  background: var(--bg-card);
  border: 2px solid var(--border-subtle);
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
}

.theme-card:hover {
  border-color: var(--border-medium);
}

.theme-card.active {
  border-color: #3b82f6;
  background: rgba(59, 130, 246, 0.08);
}

.theme-preview {
  width: 100%;
  height: 54px;
  border-radius: 8px;
  border: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  padding: 8px;
  gap: 6px;
}

.theme-light-preview {
  background: #ffffff;
}
.theme-light-preview .preview-bar {
  width: 50%;
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
}
.theme-light-preview .preview-box {
  width: 80%;
  height: 14px;
  background: #f3f4f6;
  border-radius: 4px;
}

.theme-dark-preview {
  background: #09090b;
}
.theme-dark-preview .preview-bar {
  width: 50%;
  height: 6px;
  background: #27272a;
  border-radius: 3px;
}
.theme-dark-preview .preview-box {
  width: 80%;
  height: 14px;
  background: #18181b;
  border-radius: 4px;
}

.theme-system-preview {
  background: linear-gradient(135deg, #ffffff 50%, #09090b 50%);
}
.theme-system-preview .preview-bar {
  width: 50%;
  height: 6px;
  background: rgba(128, 128, 128, 0.4);
  border-radius: 3px;
}
.theme-system-preview .preview-box {
  width: 80%;
  height: 14px;
  background: rgba(128, 128, 128, 0.2);
  border-radius: 4px;
}

.settings-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-top: 1px solid var(--border-subtle);
}

.settings-toggle-row h4 {
  font-size: 13.5px;
  color: var(--text-primary);
  font-weight: 500;
}
.settings-toggle-row p {
  font-size: 11.5px;
  color: var(--text-muted);
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #3f3f46;
  transition: .2s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .2s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: #3b82f6;
}

input:checked + .slider:before {
  transform: translateX(20px);
}

.persona-chips-container {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.persona-chip {
  padding: 6px 14px;
  border-radius: 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.persona-chip:hover {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
}

.persona-chip.active {
  background: var(--bg-sidebar-hover);
  color: var(--text-primary);
  border-color: var(--border-medium);
  font-weight: 600;
}

.usage-header h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge-pro {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: rgba(168, 85, 247, 0.2);
  color: #c084fc;
  padding: 2px 6px;
  border-radius: 4px;
}

.usage-header p {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.usage-card {
  background: var(--bg-sidebar-hover);
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  padding: 16px;
  margin: 14px 0 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.usage-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.usage-label {
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-primary);
}

.usage-val {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
}

.progress-bar-track {
  width: 100%;
  height: 8px;
  background: rgba(128, 128, 128, 0.2);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #3b82f6, #00e5ff);
  border-radius: 4px;
  transition: width 0.3s ease;
}

.usage-sub {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11.5px;
  color: var(--text-muted);
}

.text-btn-xs {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 500;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: all 0.15s ease;
}

.text-btn-xs:hover {
  background: var(--bg-card);
  color: var(--text-primary);
}

.key-input-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
}

.key-input-wrapper .settings-input {
  flex: 1;
}

.prompt-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.provider-usage-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.provider-usage-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  font-size: 13px;
}

.provider-usage-name {
  font-weight: 500;
  color: var(--text-primary);
}

.provider-usage-counts {
  font-size: 11.5px;
  color: var(--text-muted);
}

.provider-cards-section {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.provider-cards-header h3 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.provider-cards-header p {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 3px;
}

.provider-key-cards-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.provider-key-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: all 0.15s ease;
}

.provider-key-card:hover {
  border-color: var(--border-medium);
}

.provider-key-card.active-provider {
  border-color: rgba(59, 130, 246, 0.6);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.12);
}

.provider-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.provider-card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}

.provider-key-badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
}

.provider-key-badge.badge-saved {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}

.provider-key-badge.badge-empty {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
}

.provider-link {
  font-size: 11.5px;
  color: #60a5fa;
  text-decoration: none;
}

.provider-link:hover {
  text-decoration: underline;
}

.ollama-card {
  border-left: 3px solid #8b5cf6;
}

.settings-supergrok-banner {
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.banner-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.banner-logo {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.settings-supergrok-banner strong {
  font-size: 13px;
  color: var(--text-primary);
}

.settings-supergrok-banner p {
  font-size: 11px;
  color: var(--text-muted);
}

.badge-pill {
  padding: 4px 10px;
  border-radius: 14px;
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  font-size: 11px;
  font-weight: 600;
}

/* ==========================================================================
   SEARCH THROUGH CHATS MODAL (Split View)
   ========================================================================== */
.search-modal-card {
  position: relative;
  z-index: 65;
  background: var(--bg-modal);
  border: 1px solid var(--border-medium);
  border-radius: 20px;
  width: 880px;
  max-width: 92vw;
  height: 580px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-modal);
  animation: modalPopIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.search-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border-subtle);
  gap: 16px;
}

.search-input-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
}

.search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

#chat-search-input {
  background: transparent;
  border: none;
  outline: none;
  font-size: 15px;
  color: var(--text-primary);
  width: 100%;
  font-family: inherit;
}

.search-filter-pills {
  display: flex;
  align-items: center;
  gap: 8px;
}

.search-tab-pill {
  padding: 4px 12px;
  border-radius: 14px;
  background: var(--bg-sidebar-hover);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.search-split-container {
  flex: 1;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

.search-results-pane {
  width: 320px;
  min-width: 320px;
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 10px;
  gap: 6px;
  background: var(--bg-modal-rail);
}

.search-actions-bar {
  margin-bottom: 6px;
}

.search-action-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 12px;
  background: rgba(168, 85, 247, 0.1);
  border: 1px solid rgba(168, 85, 247, 0.3);
  border-radius: 10px;
  color: var(--accent-purple);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.search-action-item:hover {
  background: rgba(168, 85, 247, 0.18);
}

.search-group-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-muted);
  letter-spacing: 0.5px;
  padding: 8px 8px 4px;
}

.search-thread-result {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 9px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  border: 1px solid transparent;
}

.search-thread-result:hover {
  background: var(--bg-sidebar-hover);
}

.search-thread-result.active {
  background: var(--bg-sidebar-hover);
  border-color: var(--border-medium);
}

.search-thread-result-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-thread-result-meta {
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}

.search-preview-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 20px;
  background: var(--bg-modal);
}

.search-preview-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  font-size: 14px;
}

.search-preview-content {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 14px;
}

.preview-header h3 {
  font-size: 15px;
  color: var(--text-primary);
  font-weight: 600;
}

.preview-messages-stream {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.preview-msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 13px;
}

.preview-msg-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
}

.preview-msg-body {
  line-height: 1.5;
  color: var(--text-primary);
}

/* ==========================================================================
   CHARACTER DIRECTORY MODAL
   ========================================================================== */
.char-dir-dialog {
  position: relative;
  width: 880px;
  max-width: 95vw;
  height: 720px;
  max-height: 90vh;
  background: var(--bg-modal);
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.75);
  z-index: 1001;
}

[data-theme="light"] .char-dir-dialog {
  background: #ffffff;
  border-color: #e5e7eb;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.15);
}

.char-dir-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.char-dir-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
}

.char-tab-btn {
  padding: 6px 14px;
  border-radius: 16px;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
}

.char-tab-btn:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.char-tab-btn.active {
  background: var(--bg-hover);
  border-color: var(--border-subtle);
  color: var(--text-primary);
}

.char-dir-toolbar {
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border-bottom: 1px solid var(--border-subtle);
}

.char-search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  color: var(--text-primary);
}

.char-search-box input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13px;
}

.char-dir-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.char-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 20px;
}

.char-grid-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.char-grid-card:hover {
  transform: translateY(-2px);
  border-color: var(--text-muted);
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.25);
}

.char-card-visual {
  width: 96px;
  height: 96px;
  border-radius: 18px;
  background: var(--bg-hover);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  margin-bottom: 14px;
  overflow: hidden;
}

.char-card-visual img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.char-card-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.char-card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.char-card-subtitle {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.char-card-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.char-card-chat-btn {
  flex: 1;
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--text-primary);
  color: var(--text-inverse);
  border: none;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s ease;
}

.char-card-chat-btn:hover {
  opacity: 0.9;
}

.char-card-edit-btn {
  padding: 6px 12px;
  border-radius: 8px;
  background: var(--bg-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease;
}

.char-card-edit-btn:hover {
  background: var(--bg-sidebar-hover);
}

.char-empty-state {
  grid-column: 1 / -1;
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.char-empty-icon {
  font-size: 48px;
  opacity: 0.8;
}

/* ==========================================================================
   CHARACTER CREATOR MODAL
   ========================================================================== */
.modal-content.character-creator {
  max-width: 650px;
}

.char-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.char-section h3 {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.char-input {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 13.5px;
  font-family: inherit;
  outline: none;
}
.char-input:focus {
  border-color: var(--border-focus);
}

.char-row {
  display: flex;
  gap: 8px;
}
.char-row .char-input {
  flex: 1;
}

.char-avatar-picker-row {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 8px;
}

.char-avatar-preview-box {
  width: 68px;
  height: 68px;
  border-radius: 14px;
  background: var(--bg-hover);
  border: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 30px;
  flex-shrink: 0;
  overflow: hidden;
}

.char-avatar-controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.char-avatar-btn-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.secondary-btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  border-radius: 8px;
  background: var(--bg-hover);
  border: 1px solid var(--border-medium);
  color: var(--text-primary);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.secondary-btn-sm svg {
  stroke: currentColor;
}

.secondary-btn-sm:hover {
  background: var(--bg-sidebar-hover);
  border-color: var(--border-focus);
  color: var(--text-primary);
}

/* ==========================================================================
   LOREBOOK DIALOG
   ========================================================================== */
.lorebook-dialog {
  position: relative;
  z-index: 10;
  width: 90%;
  max-width: 780px;
  max-height: 85vh;
  background: var(--bg-modal);
  border: 1px solid var(--border-medium);
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-modal);
}

.lorebook-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-card);
}

.lorebook-header-left h2 {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.lorebook-header-left p {
  font-size: 12px;
  color: var(--text-secondary);
}

.lorebook-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.lorebook-body {
  padding: 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.lorebook-search-row input {
  width: 100%;
}

.lorebook-entries-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lore-entry-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.15s ease;
}

.lore-entry-card:hover {
  border-color: var(--border-medium);
}

.lore-entry-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.lore-entry-keys-input {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  padding: 6px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-primary);
}

.lore-entry-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.lore-entry-content-area {
  width: 100%;
  font-size: 13px;
  padding: 8px 10px;
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  color: var(--text-primary);
  resize: vertical;
}

/* ==========================================================================
   KEYBOARD SHORTCUTS PALETTE
   ========================================================================== */
.shortcuts-dialog {
  max-width: 520px;
}

.shortcuts-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shortcut-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-primary);
}

.shortcut-key {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  font-weight: 600;
  background: var(--chip-bg);
  border: 1px solid var(--border-medium);
  padding: 3px 8px;
  border-radius: 6px;
  color: var(--accent-white);
}

/* ==========================================================================
   USER PERSONA DIALOG
   ========================================================================== */
.persona-dialog {
  max-width: 480px;
}

/* ==========================================================================
   ONBOARDING MODAL
   ========================================================================== */
#onboarding-modal .modal-content.onboarding {
  max-width: 440px;
  text-align: center;
  padding: 36px;
  align-items: center;
}

.onboarding-header {
  margin-bottom: 24px;
}

.onboarding-logo {
  margin-bottom: 12px;
  color: var(--text-primary);
}

.onboarding-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
}

.onboarding-header p {
  color: var(--text-muted);
  font-size: 13px;
}

.onboarding-body {
  text-align: left;
  margin-bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
}
