:root {
  --bg-primary: #0b0d13;
  --bg-secondary: #131722;
  --bg-tertiary: #1b2030;
  --bg-card: #161b29;
  --bg-input: #0f121c;
  --border-color: #262d40;
  --border-hover: #3d4766;
  --accent-primary: #5865f2;
  --accent-hover: #4752c4;
  --accent-glow: rgba(88, 101, 242, 0.4);
  --accent-success: #57f287;
  --accent-warning: #fee75c;
  --accent-danger: #ed4245;
  --text-primary: #f2f3f5;
  --text-secondary: #9aa2b1;
  --text-muted: #677083;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --font-main: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Safe Area Insets for Mobile & Discord Client */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-main);
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  -webkit-overflow-scrolling: touch;
}

.app-layout {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* ================= 1. ULTRA-COMPACT UNIFIED HEADER (44px) ================= */
.app-header {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  height: 46px;
  min-height: 46px;
  max-height: 46px;
  padding: max(2px, var(--safe-top)) 14px 2px 14px;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 10px;
}

.header-left {
  display: flex;
  align-items: center;
  justify-content: flex-start;
}

.header-left .logo-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--accent-primary);
  font-weight: 700;
}

.logo-text {
  font-size: 0.92rem;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  font-weight: 700;
  white-space: nowrap;
}

/* Header Live Progress Pill */
.header-progress-pill {
  display: flex;
  align-items: center;
  gap: 7px;
  background-color: var(--bg-primary);
  border: 1px solid var(--accent-primary);
  box-shadow: 0 0 10px var(--accent-glow);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  animation: fadeIn 0.2s ease;
  min-width: 140px;
  max-width: 200px;
}

.status-indicator {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--accent-primary);
  box-shadow: 0 0 6px var(--accent-primary);
  animation: pulseDot 1.2s infinite ease-in-out;
  flex-shrink: 0;
}

@keyframes pulseDot {
  0% { transform: scale(0.85); opacity: 0.6; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.85); opacity: 0.6; }
}

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

.progress-text-row {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.progress-wf-name {
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 55px;
}

.progress-step-text {
  color: var(--text-muted);
  font-size: 0.65rem;
}

.progress-pct-badge {
  color: var(--accent-primary);
  font-weight: 700;
  margin-left: auto;
  font-size: 0.7rem;
}

.header-progress-track {
  width: 100%;
  height: 3px;
  background-color: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.header-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-primary), var(--accent-success));
  transition: width 0.25s ease;
}

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

.nav-tabs {
  display: flex;
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 2px;
  gap: 2px;
}

.nav-tab {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 4px 12px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
  min-height: 28px;
  touch-action: manipulation;
  user-select: none;
}

.nav-tab > * {
  pointer-events: none;
}

.nav-tab:hover {
  color: var(--text-primary);
}

.nav-tab.active {
  background-color: var(--accent-primary);
  color: #ffffff;
  box-shadow: 0 2px 8px var(--accent-glow);
}

.badge-count {
  background-color: rgba(0, 0, 0, 0.4);
  color: white;
  font-size: 0.7rem;
  padding: 1px 5px;
  border-radius: 8px;
  font-weight: 700;
  pointer-events: none;
}

.header-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.server-badges {
  display: flex;
  gap: 4px;
}

.server-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 2px 7px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-weight: 600;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.online {
  background-color: var(--accent-success);
  box-shadow: 0 0 6px rgba(87, 242, 135, 0.6);
}

.status-dot.booting {
  background-color: #fee75c;
  box-shadow: 0 0 6px rgba(254, 231, 92, 0.8);
  animation: pulseDot 1.2s infinite ease-in-out;
}

.server-badge.booting {
  border-color: rgba(254, 231, 92, 0.4);
  background-color: rgba(254, 231, 92, 0.08);
  color: #fee75c;
}

.status-dot.offline {
  background-color: var(--accent-danger);
}

@keyframes pulseDot {
  0% { transform: scale(0.85); opacity: 0.6; }
  50% { transform: scale(1.35); opacity: 1; box-shadow: 0 0 10px rgba(254, 231, 92, 1); }
  100% { transform: scale(0.85); opacity: 0.6; }
}

.user-menu-container {
  position: relative;
  display: flex;
  align-items: center;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 8px 2px 2px;
  background-color: var(--bg-tertiary);
  border-radius: 20px;
  border: 1px solid var(--border-color);
  max-width: 145px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: all 0.2s ease;
}

.user-profile > * {
  pointer-events: none;
}

.user-profile:hover {
  border-color: var(--accent-primary);
  background-color: var(--bg-input);
}

.user-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
}

.user-name {
  font-size: 0.75rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-caret {
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.user-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 250px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  z-index: 200;
  padding: 12px;
  animation: fadeIn 0.15s ease;
}

.dropdown-header {
  padding-bottom: 6px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.dropdown-title {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.setting-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}

.setting-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.setting-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
}

.setting-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.2;
}

/* iOS Style Switch */
.switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
  flex-shrink: 0;
}

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

.switch .slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  transition: 0.2s ease;
  border-radius: 20px;
}

.switch .slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 2px;
  bottom: 2px;
  background-color: var(--text-secondary);
  transition: 0.2s ease;
  border-radius: 50%;
}

.switch input:checked + .slider {
  background-color: var(--accent-primary);
  border-color: var(--accent-primary);
}

.switch input:checked + .slider:before {
  transform: translateX(16px);
  background-color: white;
}

/* ================= 2. MAIN BODY & VIEWS ================= */
.app-body {
  display: flex;
  flex: 1;
  height: calc(100% - 46px);
  min-height: 0;
  overflow: hidden;
}

.tab-view {
  display: flex;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

/* ================= 3. STUDIO / CREATE TAB ================= */
#view-create {
  display: flex;
  flex: 1;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.control-panel {
  width: 380px;
  min-width: 330px;
  max-width: 420px;
  height: 100%;
  min-height: 100%;
  max-height: 100%;
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border-color);
  padding: 0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

/* Full-Width Media Type Category Header Row (Flush to Top) */
.category-header-row {
  display: flex;
  align-items: stretch;
  width: 100%;
  background-color: var(--bg-tertiary);
  border-bottom: 1px solid var(--border-color);
  margin: 0;
  padding: 0;
  flex-shrink: 0;
}

.category-tabs {
  display: flex;
  flex: 1;
  background: transparent;
  padding: 0;
  margin: 0;
  border: none;
  border-radius: 0;
}

.category-tab {
  flex: 1;
  height: 42px;
  padding: 0 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  border-right: 1px solid var(--border-color);
  border-radius: 0;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  white-space: nowrap;
  touch-action: manipulation;
  user-select: none;
}

.category-tab > * {
  pointer-events: none;
}

.category-tab:last-child {
  border-right: none;
}

.category-tab:hover {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.04);
}

.category-tab.active {
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  border-bottom: 2px solid var(--accent-primary);
}

.category-model-picker {
  display: flex;
  align-items: center;
  padding: 0 10px;
  border-left: 1px solid var(--border-color);
  background-color: var(--bg-secondary);
  min-width: 110px;
  max-width: 140px;
}

.model-sub-select {
  height: 28px !important;
  min-height: 28px !important;
  padding: 2px 8px !important;
  font-size: 0.76rem !important;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
}

.control-panel-content {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.section-label {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
  letter-spacing: 0.06em;
  margin-bottom: 6px;
}

.form-select,
.form-input,
.form-textarea {
  width: 100%;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.85rem;
  transition: all 0.2s ease;
  min-height: 38px;
  height: 38px;
}

.form-select:focus,
.form-input:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.form-textarea {
  height: auto;
  min-height: 90px;
  line-height: 1.4;
  resize: vertical;
  padding: 10px 12px;
}

/* Prompt Input Wrapper & Synchronized LoRA Backdrop Highlighter */
.prompt-input-wrapper {
  position: relative;
  width: 100%;
  border-radius: var(--radius-sm);
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  overflow: hidden;
}

.prompt-input-wrapper:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.prompt-highlights {
  position: absolute;
  inset: 0;
  padding: 10px 12px;
  font-family: inherit;
  font-size: 0.85rem;
  line-height: 1.4;
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow-y: auto;
  overflow-x: hidden;
  pointer-events: none;
  color: transparent;
  box-sizing: border-box;
  border: 1px solid transparent;
  user-select: none;
  -webkit-user-select: none;
  margin: 0;
}

.prompt-textarea {
  position: relative;
  z-index: 1;
  background: transparent !important;
  border: 1px solid transparent !important;
  box-shadow: none !important;
  color: var(--text-primary);
  caret-color: var(--text-primary);
  margin: 0;
  box-sizing: border-box;
  display: block;
}

.prompt-textarea:focus {
  border-color: transparent !important;
  box-shadow: none !important;
}

/* Glowing highlight mark for LoRA trigger words */
.lora-highlight-tag {
  background-color: rgba(99, 102, 241, 0.28);
  border-bottom: 2px solid #818cf8;
  border-radius: 3px;
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.25);
  color: transparent;
}

/* Glowing highlight mark for Wildcard tokens (+location, +style, etc.) */
.wildcard-highlight-tag {
  background-color: rgba(16, 185, 129, 0.25);
  border-bottom: 2px solid #34d399;
  border-radius: 3px;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.25);
  color: transparent;
}

/* Wildcard Autocomplete Dropdown Popup */
.wildcard-autocomplete-popup {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  z-index: 1000;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  max-height: 220px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 4px;
  gap: 2px;
}

.wildcard-autocomplete-header {
  padding: 4px 8px;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  margin-bottom: 2px;
}

.wildcard-autocomplete-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-primary);
  transition: background-color 0.1s ease, color 0.1s ease;
  user-select: none;
}

.wildcard-autocomplete-item:hover,
.wildcard-autocomplete-item.selected {
  background-color: rgba(16, 185, 129, 0.2);
  color: #fff;
}

.wildcard-autocomplete-item.selected {
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.wildcard-ac-token {
  font-family: var(--font-mono);
  color: #34d399;
  display: flex;
  align-items: center;
  gap: 4px;
}

.wildcard-ac-token .ac-highlight {
  color: #fff;
  text-decoration: underline;
  font-weight: 700;
}

.wildcard-ac-meta {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 6px;
}

.wildcard-ac-count {
  background-color: var(--bg-secondary);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.65rem;
  border: 1px solid var(--border-color);
  font-family: var(--font-mono);
}

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

.form-group label {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-secondary);
  line-height: 1.2;
}

/* Split Field Row (Aspect Ratio 27% / Resolution Slider 73%) */
.split-field-row {
  display: grid;
  grid-template-columns: minmax(75px, 27%) 1fr;
  gap: 10px;
  margin-bottom: 12px;
  align-items: flex-start;
}

.split-field-row.equal-cols {
  grid-template-columns: 1fr 1fr;
}

.dlss-vsr-group {
  margin-top: 4px;
  margin-bottom: 12px;
}

.dlss-toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.dlss-toggle-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.dlss-toggle-label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
  cursor: pointer;
}

.dlss-toggle-row .field-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.2;
}

.split-col {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.split-col-header,
.slider-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 20px;
  min-height: 20px;
  max-height: 20px;
  margin-bottom: 6px;
  line-height: 1;
}

.split-col-header label,
.slider-header label,
.split-col label {
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin: 0;
  padding: 0;
  display: inline-flex;
  align-items: center;
  line-height: 1;
}

.slider-value-badge {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--accent-primary);
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  letter-spacing: -0.01em;
  line-height: 1;
  display: inline-flex;
  align-items: center;
}

/* Slider Track Box Perfectly Aligned with Form Select */
.slider-track-box {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 38px;
  min-height: 38px;
  max-height: 38px;
  box-sizing: border-box;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.slider-track-box:focus-within {
  border-color: var(--accent-primary);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.form-range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 18px;
  background: transparent;
  outline: none;
  margin: 0;
  padding: 0;
  cursor: pointer;
  display: block;
}

/* Webkit Track (Chrome, Safari, Edge, Discord WebView) */
.form-range::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background-color: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.04);
  transition: background-color 0.15s ease;
}

.form-range:hover::-webkit-slider-runnable-track {
  background-color: rgba(255, 255, 255, 0.22);
}

.form-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  box-shadow: 0 0 6px var(--accent-glow);
  margin-top: -5px; /* (4px track - 14px thumb) / 2 = -5px to center */
  transition: transform 0.15s ease, background-color 0.15s ease;
}

.form-range::-webkit-slider-thumb:hover {
  transform: scale(1.2);
  background: #6875f5;
}

/* Mozilla Firefox Track */
.form-range::-moz-range-track {
  width: 100%;
  height: 4px;
  border-radius: 2px;
  background-color: rgba(255, 255, 255, 0.14);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.form-range:hover::-moz-range-track {
  background-color: rgba(255, 255, 255, 0.22);
}

.form-range::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-primary);
  cursor: pointer;
  border: none;
  box-shadow: 0 0 6px var(--accent-glow);
}

.form-group .field-desc {
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-top: 4px;
  display: block;
}

.alert-banner {
  display: flex;
  gap: 10px;
  padding: 10px 12px;
  background-color: rgba(254, 231, 92, 0.1);
  border: 1px solid rgba(254, 231, 92, 0.3);
  border-radius: var(--radius-sm);
  color: var(--accent-warning);
  font-size: 0.8rem;
}

.alert-text p {
  color: var(--text-secondary);
  font-size: 0.75rem;
  margin-top: 2px;
}

/* Primary Action Bar at Top of Form */
.form-actions-top {
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 6px;
}

.generate-btn-group {
  position: relative;
  width: 100%;
  display: flex;
  align-items: stretch;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #5865F2 0%, #4752C4 100%);
  box-shadow: 0 2px 8px rgba(88, 101, 242, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.2);
  min-height: 42px;
  height: 42px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
  transition: all 0.2s ease;
}

.generate-btn-group:hover {
  box-shadow: 0 4px 14px rgba(88, 101, 242, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.btn-generate-main {
  flex: 1;
  position: relative;
  width: auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent !important;
  border: none !important;
  border-radius: 0 !important;
  height: 100%;
  min-height: 100%;
  cursor: pointer;
  touch-action: manipulation;
  color: #ffffff;
  font-weight: 700;
  box-shadow: none !important;
  padding: 0 12px;
  overflow: hidden;
  transition: background-color 0.15s ease;
}

.btn-generate-main:not(.generating):hover {
  background-color: rgba(255, 255, 255, 0.08) !important;
  transform: none !important;
}

.btn-generate-main.generating {
  background-color: #161820 !important;
  cursor: wait;
}

.btn-enhance-segment {
  width: 15%;
  min-width: 44px;
  max-width: 54px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.2);
  border: none;
  border-left: 1px solid rgba(255, 255, 255, 0.18);
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s ease;
  color: rgba(255, 255, 255, 0.6);
  position: relative;
  z-index: 3;
}

.btn-enhance-segment:hover {
  background-color: rgba(255, 255, 255, 0.15);
  color: #ffffff;
}

.btn-enhance-segment.active {
  background: linear-gradient(135deg, #8b5cf6 0%, #ec4899 100%);
  color: #ffffff;
  box-shadow: inset 0 0 10px rgba(255, 255, 255, 0.35);
  border-left-color: rgba(255, 255, 255, 0.3);
}

.btn-enhance-segment.active .enhance-wand-icon {
  filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.9));
  animation: wandFloat 2.4s infinite ease-in-out;
}

@keyframes wandFloat {
  0%, 100% { transform: scale(1) rotate(0deg); }
  50% { transform: scale(1.18) rotate(6deg); }
}

.btn-primary {
  position: relative;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-tertiary);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-sm);
  min-height: 42px;
  height: 42px;
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  color: #ffffff;
  font-weight: 700;
}

.btn-primary * {
  color: #ffffff;
}

.btn-primary:not(.generating) {
  background: linear-gradient(135deg, #5865F2 0%, #4752C4 100%);
  box-shadow: 0 2px 8px rgba(88, 101, 242, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.btn-primary:not(.generating):hover {
  background: linear-gradient(135deg, #6774f7 0%, #515dd4 100%);
  box-shadow: 0 4px 14px rgba(88, 101, 242, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
  transform: translateY(-1px);
}

.btn-primary:not(.generating):active {
  transform: translateY(1px);
  box-shadow: 0 1px 4px rgba(88, 101, 242, 0.3);
}

.btn-primary.generating {
  background-color: #161820;
  border-color: rgba(88, 101, 242, 0.5);
  cursor: wait;
}

.btn-progress-fill {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  background: linear-gradient(90deg, #4752C4 0%, #5865F2 70%, #7289da 100%);
  width: 0%;
  transition: width 0.2s ease;
  z-index: 1;
  box-shadow: 0 0 10px rgba(88, 101, 242, 0.5);
}

.btn-content {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: #ffffff;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
  pointer-events: none;
}

.btn-icon {
  flex-shrink: 0;
}

.btn-secondary {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background-color: var(--border-color);
}

.btn-subtle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.2s ease;
}

.btn-subtle:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.btn-link {
  background: none;
  border: none;
  color: var(--accent-primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

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

/* Preview Canvas */
.preview-panel {
  flex: 1;
  height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-primary);
  padding: 16px;
  overflow: hidden;
}

.media-display-wrapper {
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: transparent;
  overflow: hidden;
  position: relative;
  padding: 0;
}

.media-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  text-align: center;
  max-width: 320px;
}

.placeholder-icon {
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 50%;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

.media-placeholder h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.media-placeholder p {
  font-size: 0.78rem;
  line-height: 1.4;
  color: var(--text-muted);
}

.result-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  max-height: 100%;
  max-width: 100%;
  width: 100%;
  height: 100%;
  gap: 12px;
}

.result-media-frame {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.55);
  background-color: #0b0c10;
}

.result-media {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-md);
  display: block;
  transition: transform 0.2s ease;
}

.result-media-frame:hover .result-media {
  transform: scale(1.01);
}

.media-hover-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 8px 12px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, rgba(0, 0, 0, 0) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.result-media-frame:hover .media-hover-overlay {
  opacity: 1;
}

.result-action-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Mini Recent Strip - Pinned to Sidebar bottom */
.mini-recent-section {
  flex-shrink: 0;
  width: 100%;
  background-color: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 10px 14px max(10px, var(--safe-bottom)) 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}

.mini-recent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mini-recent-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}

.mini-recent-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  width: 100%;
  overflow: hidden;
}

.mini-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  height: auto;
  min-width: 0;
  min-height: 0;
  border-radius: var(--radius-sm);
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}

.mini-thumb:hover {
  border-color: var(--accent-primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.mini-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

/* ================= 4. GALLERY TAB ================= */
#view-gallery {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.gallery-container {
  max-width: 1300px;
  margin: 0 auto;
  width: 100%;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.gallery-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.gallery-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-danger-subtle {
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.btn-danger-subtle:hover {
  color: #ff5c5c !important;
  border-color: rgba(237, 66, 69, 0.5) !important;
  background-color: rgba(237, 66, 69, 0.12) !important;
}

.gallery-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 5px 12px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  color: var(--text-secondary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.filter-chip:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.filter-chip.active {
  background-color: var(--accent-primary);
  color: white;
  border-color: var(--accent-primary);
}

.gallery-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 50px 20px;
  background-color: var(--bg-secondary);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-lg);
  text-align: center;
  color: var(--text-secondary);
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 10px;
}

.gallery-empty h3 {
  color: var(--text-primary);
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.gallery-empty p {
  font-size: 0.82rem;
  max-width: 360px;
}

/* Full Gallery Card Grid */
.gallery-full-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}

.gallery-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: all 0.25s ease;
  position: relative;
}

.gallery-card:hover {
  transform: translateY(-4px);
  border-color: var(--accent-primary);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.gallery-card-media {
  width: 100%;
  aspect-ratio: 1;
  background-color: var(--bg-tertiary);
  overflow: hidden;
  position: relative;
}

.gallery-card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.gallery-card:hover .gallery-card-media img {
  transform: scale(1.04);
}

.gallery-card-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  background-color: rgba(11, 13, 19, 0.75);
  backdrop-filter: blur(8px);
  color: var(--text-primary);
  font-size: 0.68rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 4px;
}

.gallery-card-star-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background-color: rgba(11, 13, 19, 0.75);
  backdrop-filter: blur(8px);
  color: #fee75c;
  font-size: 0.75rem;
  font-weight: 700;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
}

.chip-starred.active {
  background-color: #fee75c !important;
  color: #111217 !important;
  border-color: #fee75c !important;
  box-shadow: 0 0 10px rgba(254, 231, 92, 0.4);
}

.gallery-card-info {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.gallery-card-prompt {
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.gallery-card-date {
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ================= 5. LIGHTBOX MODAL ================= */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  max-width: 920px;
  width: 100%;
  max-height: 88vh;
  display: flex;
  overflow: hidden;
  position: relative;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.6);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-star-btn {
  position: absolute;
  top: 12px;
  right: 88px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.modal-star-btn:hover {
  color: #fee75c;
  border-color: #fee75c;
}

.modal-star-btn.starred {
  background-color: rgba(254, 231, 92, 0.15);
  border-color: #fee75c;
  color: #fee75c;
  box-shadow: 0 0 10px rgba(254, 231, 92, 0.4);
}

.modal-star-btn.starred .star-icon {
  fill: #fee75c;
}

.modal-expand-btn {
  position: absolute;
  top: 12px;
  right: 50px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.modal-expand-btn:hover {
  background-color: var(--accent-primary);
  border-color: var(--accent-primary);
}

.modal-close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 1.1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 20;
  transition: all 0.2s ease;
  touch-action: manipulation;
}

.modal-close-btn:hover {
  background-color: var(--accent-danger);
  border-color: var(--accent-danger);
}

.modal-card.maximized {
  max-width: 100vw;
  max-height: 100vh;
  width: 100vw;
  height: 100vh;
  border-radius: 0;
  border: none;
}

.modal-card.maximized .modal-media-area {
  flex: 1;
  height: 100vh;
  max-height: 100vh;
  padding: 10px;
  background-color: #000000;
}

.modal-card.maximized .modal-media-area img,
.modal-card.maximized .modal-media-area video {
  max-height: 98vh;
  max-width: 98vw;
}

.modal-card.maximized .modal-info-sidebar {
  display: none;
}

.modal-media-area {
  flex: 1.4;
  background-color: #000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  min-height: 360px;
  position: relative;
}

.modal-media-area img,
.modal-media-area video {
  max-width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.modal-info-sidebar {
  flex: 1;
  min-width: 280px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background-color: var(--bg-secondary);
  overflow-y: auto;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: 24px;
}

.badge-workflow {
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--accent-primary);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  letter-spacing: 0.3px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge-enhanced {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.25) 0%, rgba(236, 72, 153, 0.25) 100%);
  border: 1px solid rgba(236, 72, 153, 0.4);
  color: #f472b6;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  letter-spacing: 0.02em;
}

.badge-enhanced svg {
  color: #ec4899;
}

.modal-raw-box {
  background-color: rgba(255, 255, 255, 0.02);
  border: 1px dashed var(--border-color);
}

.modal-prompt-box {
  background-color: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

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

.modal-prompt-date {
  font-size: 0.7rem;
  font-weight: 500;
  color: var(--text-muted);
}

.modal-prompt-text {
  font-size: 0.82rem;
  color: var(--text-primary);
  line-height: 1.4;
  max-height: 180px;
  overflow-y: auto;
  user-select: text;
}

.modal-loras-box {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.modal-lora-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 0.72rem;
  font-family: var(--font-mono);
  font-weight: 600;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--accent-primary);
}

/* ================= ACTIVE LORA CARDS & SLIDERS ================= */
/* ================= ACTIVE LORA CHIPS & EXPANDABLE SLIDERS ================= */
.active-loras-container {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
  width: 100%;
}

/* 1. Full-Width Sidebar-Wide Single-Line Slider Pills */
.active-loras-sliders-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.lora-slider-pill {
  width: 100%;
  box-sizing: border-box;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 3px 6px 3px 10px;
  min-height: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s ease;
  user-select: none;
  position: relative;
  touch-action: none;
}

.lora-slider-pill:hover {
  border-color: #818cf8;
  background-color: rgba(99, 102, 241, 0.08);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.lora-slider-pill.dragging {
  border-color: #818cf8;
  background-color: rgba(99, 102, 241, 0.18);
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.35);
}

.lora-slider-pill-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #818cf8;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(129, 140, 248, 0.5);
}

.lora-slider-pill-name {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-primary);
  white-space: nowrap;
  flex-shrink: 0;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: ns-resize;
}

.lora-slider-pill-track-wrapper {
  position: relative;
  flex: 1;
  min-width: 50px;
  display: flex;
  align-items: center;
  height: 20px;
  cursor: pointer;
}

.lora-slider-zero-mark {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 1.5px;
  height: 10px;
  background-color: rgba(255, 255, 255, 0.35);
  border-radius: 1px;
  pointer-events: none;
  z-index: 1;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.5);
  transition: background-color 0.15s ease;
}

.lora-slider-pill:hover .lora-slider-zero-mark {
  background-color: rgba(255, 255, 255, 0.7);
}

.lora-inline-slider {
  width: 100%;
  height: 18px;
  margin: 0;
  cursor: pointer;
  position: relative;
  z-index: 2;
}

.lora-slider-pill-val {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--accent-primary);
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  padding: 1px 0;
  border-radius: 4px;
  width: 42px;
  min-width: 42px;
  max-width: 42px;
  text-align: center;
  display: inline-block;
  box-sizing: border-box;
  flex-shrink: 0;
  cursor: ns-resize;
}

.lora-pill-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 1px 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.15s ease;
  flex-shrink: 0;
}

.lora-pill-remove:hover {
  color: #ef4444;
  background-color: rgba(239, 68, 68, 0.2);
}

/* 2. Compact Standard LoRA Chips Strip */
.active-loras-strip {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

/* Interactive LoRA Chip with Mouse-Up/Down Drag & Wheel */
.lora-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 10px;
  border-radius: 20px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.76rem;
  font-weight: 600;
  cursor: ns-resize;
  transition: all 0.15s ease;
  user-select: none;
  touch-action: none;
  position: relative;
}

.lora-chip:hover {
  border-color: #818cf8;
  background-color: rgba(99, 102, 241, 0.12);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.lora-chip.dragging {
  border-color: #818cf8;
  background-color: rgba(99, 102, 241, 0.25);
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
  transform: scale(1.03);
}

.lora-chip-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: #a855f7;
  flex-shrink: 0;
  box-shadow: 0 0 6px rgba(168, 85, 247, 0.5);
}

.lora-chip-name {
  white-space: nowrap;
}

.lora-chip-val {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: 0.68rem;
  font-weight: 700;
  color: #c084fc;
  background-color: var(--bg-input);
  padding: 1px 5px;
  border-radius: 4px;
  border: 1px solid var(--border-color);
  min-width: 28px;
  text-align: center;
  display: inline-block;
  box-sizing: border-box;
  pointer-events: none;
}

.lora-chip-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 1px 3px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.15s ease;
  margin-left: 2px;
}

.lora-chip-remove:hover {
  color: #ef4444;
  background-color: rgba(239, 68, 68, 0.2);
}

/* Add LoRA Pill / Button */
.add-lora-chip {
  border: 1px dashed var(--border-color);
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 500;
  gap: 5px;
  opacity: 0.85;
}

.add-lora-chip:hover {
  background-color: rgba(255, 255, 255, 0.06);
  border-color: var(--text-muted);
  color: var(--text-primary);
  opacity: 1;
}

.add-lora-chip.active {
  background-color: rgba(99, 102, 241, 0.18);
  border-color: var(--accent-primary);
  color: #fff;
  border-style: solid;
  opacity: 1;
}

/* Add Wildcard Pill / Button */
.add-wildcard-chip {
  border: 1px dashed var(--border-color);
  background-color: var(--bg-tertiary);
  color: var(--text-secondary);
  font-weight: 500;
  gap: 5px;
  opacity: 0.85;
}

.add-wildcard-chip:hover {
  background-color: rgba(255, 255, 255, 0.06);
  border-color: #34d399;
  color: #34d399;
  opacity: 1;
}

.add-wildcard-chip.active {
  background-color: rgba(16, 185, 129, 0.18);
  border-color: #10b981;
  color: #fff;
  border-style: solid;
  opacity: 1;
}

/* LoRA & Wildcard Tree / Library Panels */
.lora-tree-panel,
.wildcard-tree-panel {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 380px;
  overflow-y: auto;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
  margin-top: 4px;
}

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

.lora-tree-title {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.lora-tree-count {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 400;
}

.lora-tree-search-wrapper {
  position: relative;
  width: 100%;
}

.lora-tree-search {
  width: 100%;
  padding: 6px 10px 6px 28px;
  font-size: 0.78rem;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  min-height: 32px;
  height: 32px;
}

.lora-tree-search-icon {
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

/* Category Groups */
.lora-tree-categories {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lora-category-group {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background-color: var(--bg-tertiary);
}

.lora-category-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 10px;
  background-color: rgba(255, 255, 255, 0.02);
  cursor: pointer;
  user-select: none;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-secondary);
  transition: background-color 0.15s ease;
}

.lora-category-header:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.lora-category-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.lora-category-badge {
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 10px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.lora-category-chevron {
  transition: transform 0.2s ease;
  color: var(--text-muted);
}

.lora-category-group.open .lora-category-chevron {
  transform: rotate(90deg);
}

.lora-category-items {
  display: none;
  padding: 6px;
  flex-wrap: wrap;
  gap: 6px;
  background-color: var(--bg-primary);
  border-top: 1px solid var(--border-color);
}

.lora-category-group.open .lora-category-items {
  display: flex;
}

/* Individual Item in Tree */
.lora-tree-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 14px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.lora-tree-item:hover {
  border-color: var(--accent-primary);
  background-color: rgba(99, 102, 241, 0.15);
  color: #fff;
  transform: translateY(-1px);
}

.lora-tree-item.active {
  border-color: var(--accent-primary);
  background-color: rgba(99, 102, 241, 0.28);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 0 8px rgba(99, 102, 241, 0.25);
}

/* Individual Wildcard Item in Tree */
.wildcard-tree-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 14px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--text-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  user-select: none;
}

.wildcard-tree-item:hover {
  border-color: #34d399;
  background-color: rgba(16, 185, 129, 0.15);
  color: #fff;
  transform: translateY(-1px);
}

.wildcard-tree-item.active {
  border-color: #10b981;
  background-color: rgba(16, 185, 129, 0.28);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.25);
}

.wildcard-tree-item .wildcard-item-tag {
  font-family: var(--font-mono);
  font-weight: 600;
  color: #34d399;
}

.wildcard-tree-item .wildcard-item-count {
  font-size: 0.68rem;
  color: var(--text-muted);
  font-weight: 400;
}

/* Ungrouped Wildcards Section */
.wildcard-ungrouped-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 10px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  margin-top: 4px;
}

.wildcard-ungrouped-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.wildcard-ungrouped-items {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.btn-copy {
  align-self: flex-start;
}

.modal-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.modal-actions > button {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}

.modal-actions > button.btn-primary,
.modal-actions > button.btn-primary * {
  color: #ffffff !important;
  font-weight: 700;
}

/* Modal Channel Action Row & Split Button */
.modal-channel-action-row {
  margin-top: auto;
  margin-bottom: 8px;
  width: 100%;
  position: relative;
}

.send-channel-btn-group {
  display: flex;
  position: relative;
  width: 100%;
  height: 38px;
  border-radius: 8px;
  background: linear-gradient(135deg, #5865F2 0%, #4752C4 100%);
  box-shadow: 0 4px 14px rgba(88, 101, 242, 0.35);
  overflow: visible;
  transition: all 0.2s ease;
}

.send-channel-btn-group:hover {
  box-shadow: 0 6px 18px rgba(88, 101, 242, 0.45);
}

.btn-send-channel-main {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: transparent !important;
  border: none;
  color: #ffffff !important;
  font-size: 0.84rem;
  font-weight: 700;
  padding: 0 12px;
  cursor: pointer;
  border-top-left-radius: 8px;
  border-bottom-left-radius: 8px;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
  transition: background-color 0.15s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-send-channel-main:hover {
  background-color: rgba(255, 255, 255, 0.12) !important;
}

.btn-send-channel-main.sending {
  cursor: wait;
  opacity: 0.85;
}

.btn-send-channel-main.success {
  background: #10b981 !important;
}

.btn-channel-picker-segment {
  width: 36px;
  min-width: 36px;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.2);
  border: none;
  border-left: 1px solid rgba(255, 255, 255, 0.22);
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
  color: rgba(255, 255, 255, 0.85);
  cursor: pointer;
  touch-action: manipulation;
  transition: all 0.2s ease;
}

.btn-channel-picker-segment:hover {
  background-color: rgba(255, 255, 255, 0.18);
  color: #ffffff;
}

.btn-channel-picker-segment.active {
  background: rgba(0, 0, 0, 0.4);
  color: #ffffff;
}

.btn-channel-picker-segment.active .picker-chevron {
  transform: rotate(180deg);
}

.picker-chevron {
  transition: transform 0.2s ease;
}

/* Channel Dropdown Popup */
.modal-channel-dropdown {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  right: 0;
  background: var(--bg-tertiary, #1a1c23);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
  border-radius: 8px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
  z-index: 100;
  overflow: hidden;
  animation: fadeInDown 0.18s ease;
  max-height: 240px;
  display: flex;
  flex-direction: column;
}

.modal-channel-dropdown-header {
  padding: 8px 12px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted, rgba(255, 255, 255, 0.5));
  border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
  background: rgba(0, 0, 0, 0.2);
}

.modal-channel-list {
  overflow-y: auto;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.modal-channel-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  transition: background-color 0.15s ease;
}

.modal-channel-item:hover {
  background: rgba(88, 101, 242, 0.18);
}

.modal-channel-item.selected {
  background: rgba(88, 101, 242, 0.35);
  font-weight: 600;
}

.modal-channel-item-name {
  font-size: 0.82rem;
  color: var(--text-primary, #ffffff);
  display: flex;
  align-items: center;
  gap: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.modal-channel-item-guild {
  font-size: 0.72rem;
  color: var(--text-muted, rgba(255, 255, 255, 0.5));
  white-space: nowrap;
}

/* ================= 6. FLOATING PROGRESS PILL ================= */
.floating-pill {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background-color: var(--bg-tertiary);
  border: 1px solid var(--accent-primary);
  box-shadow: 0 8px 24px var(--accent-glow);
  padding: 8px 18px;
  border-radius: 30px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  z-index: 200;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { transform: translate(-50%, 20px); opacity: 0; }
  to { transform: translate(-50%, 0); opacity: 1; }
}

.pill-pct {
  background-color: var(--accent-primary);
  color: white;
  padding: 2px 7px;
  border-radius: 12px;
  font-size: 0.72rem;
}

/* ================= 7. MOBILE RESPONSIVE OVERRIDES ================= */
@media (max-width: 860px) {
  .app-header {
    height: 44px;
    min-height: 44px;
    padding: max(2px, var(--safe-top)) 10px 2px 10px;
  }

  .app-body {
    flex-direction: column;
    overflow: visible;
    height: auto;
  }

  #view-create {
    flex-direction: column;
  }

  .control-panel {
    width: 100%;
    min-width: unset;
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    padding: 14px;
    overflow: visible;
  }

  .preview-panel {
    width: 100%;
    overflow: visible;
    padding: 14px;
    padding-bottom: max(90px, calc(var(--safe-bottom) + 80px));
  }

  .media-display-wrapper {
    min-height: 260px;
    max-height: 60vh;
  }

  .gallery-container {
    padding: 14px;
    padding-bottom: max(90px, calc(var(--safe-bottom) + 80px));
  }

  .gallery-full-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
  }

  .gallery-card-info {
    padding: 8px;
  }

  .gallery-card-prompt {
    font-size: 0.75rem;
  }

  /* Modal on Mobile */
  .modal-card {
    flex-direction: column;
    max-height: 85vh;
    border-radius: var(--radius-lg);
  }

  .modal-media-area {
    min-height: 220px;
    max-height: 45vh;
  }

  .modal-info-sidebar {
    padding: 14px;
    min-width: unset;
  }

  .form-select,
  .form-input,
  .form-textarea {
    font-size: 16px;
  }
}

@media (max-width: 600px) {
  .logo-text {
    display: none;
  }
  .server-label {
    display: none;
  }
  .server-badge {
    padding: 3px 5px;
  }
  .user-name {
    display: none;
  }
  .user-profile {
    padding: 1px;
    background: none;
    border: none;
  }
}

/* ================= REFERENCE IMAGES SECTION ================= */
.reference-images-container {
  margin-top: 12px;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: transparent;
  border: none;
  padding: 0;
  box-sizing: border-box;
}

.reference-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  user-select: none;
  margin-bottom: 2px;
}

.reference-title {
  display: block;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
  line-height: 1.2;
}

/* Horizontal scrollable strip: exactly 3 items wide */
.reference-strip {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 2px 2px 6px 2px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-hover) transparent;
  align-items: center;
  -webkit-overflow-scrolling: touch;
}

.reference-strip::-webkit-scrollbar {
  height: 4px;
}

.reference-strip::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.15);
  border-radius: 4px;
}

.reference-strip::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 4px;
}

.reference-strip::-webkit-scrollbar-thumb:hover {
  background: var(--border-hover);
}

/* Sized so exactly 3 tiles fit side by side (2 gaps of 8px = 16px) with 3:4 portrait aspect ratio */
.ref-image-tile,
.ref-add-tile {
  flex: 0 0 calc((100% - 16px) / 3);
  width: calc((100% - 16px) / 3);
  min-width: 70px;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  box-sizing: border-box;
  position: relative;
  user-select: none;
}

.ref-image-tile {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border-color);
  overflow: hidden;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}

.ref-image-tile:hover {
  border-color: var(--accent-primary);
  transform: translateY(-1px);
}

.ref-image-tile.ref-replace-active {
  border-color: var(--accent-primary) !important;
  box-shadow: 0 0 12px rgba(88, 101, 242, 0.5) !important;
  transform: scale(1.03);
}

.ref-image-tile.ref-replace-active::after {
  content: 'Replace';
  position: absolute;
  inset: 0;
  background: rgba(88, 101, 242, 0.85);
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
  z-index: 5;
  border-radius: 7px;
  letter-spacing: 0.5px;
}

.ref-image-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.ref-tile-badge {
  position: absolute;
  bottom: 4px;
  left: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.78);
  backdrop-filter: blur(4px);
  color: #f1f2f4;
  font-size: 0.58rem;
  font-weight: 600;
  text-align: center;
  padding: 2px 4px;
  border-radius: 4px;
  pointer-events: none;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  z-index: 2;
}

/* Reference Tile Vertical Slider (Boost: 1 to 10) */
.ref-slider-container {
  position: absolute;
  left: 6px;
  top: 6px;
  bottom: 24px;
  width: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 12, 18, 0.65);
  backdrop-filter: blur(4px);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  padding: 4px 0;
  z-index: 4;
  opacity: 0.8;
  transition: opacity 0.15s, background-color 0.15s, border-color 0.15s;
  box-sizing: border-box;
}

.ref-image-tile:hover .ref-slider-container,
.ref-slider-container:hover,
.ref-slider-container:focus-within {
  opacity: 1;
  background: rgba(10, 12, 18, 0.88);
  border-color: var(--accent-primary);
}

.ref-vertical-range {
  -webkit-appearance: slider-vertical;
  appearance: slider-vertical;
  writing-mode: vertical-lr;
  direction: rtl;
  width: 12px;
  height: 100%;
  background: transparent;
  cursor: pointer;
  margin: 0;
  padding: 0;
}

.ref-vertical-range::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: 1.5px solid #ffffff;
  cursor: pointer;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.6);
}

.ref-vertical-range::-moz-range-thumb {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-primary);
  border: 1.5px solid #ffffff;
  cursor: pointer;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.6);
}

.ref-delete-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s, background-color 0.15s, transform 0.15s;
  z-index: 3;
}

.ref-image-tile:hover .ref-delete-btn,
.ref-delete-btn:focus {
  opacity: 1;
}

.ref-delete-btn:hover {
  background: var(--accent-danger);
  transform: scale(1.1);
  border-color: var(--accent-danger);
}

.ref-add-tile {
  border: 1.5px dashed var(--border-color);
  background-color: rgba(255, 255, 255, 0.02);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s ease;
  gap: 4px;
}

.ref-add-tile:hover {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  background-color: rgba(88, 101, 242, 0.08);
}

.ref-add-tile.ref-add-drag-active {
  border-color: var(--accent-primary) !important;
  color: var(--accent-primary) !important;
  background-color: rgba(88, 101, 242, 0.18) !important;
  box-shadow: 0 0 12px rgba(88, 101, 242, 0.5) !important;
  transform: scale(1.03);
}

.ref-add-icon {
  width: 20px;
  height: 20px;
  stroke: currentColor;
}

.ref-add-label {
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1;
}
