/* === YOUUAY FRAMESTUDIO - DESIGN SYSTEM (BLACK, WHITE, RED) === */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&family=JetBrains+Mono:wght@400;500&family=Poppins:wght@400;500;600;700&display=swap');

:root {
  /* === Typography === */
  --font-display: 'Bitter', Georgia, serif;
  --font-body: 'Source Sans 3', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'Roboto Mono', 'Courier New', monospace;

  /* === Spacing (8px Base Grid) === */
  --space-0: 0;
  --space-px: 1px;
  --space-0p5: 4px;
  --space-1: 8px;
  --space-1p5: 12px;
  --space-2: 16px;
  --space-3: 24px;
  --space-4: 32px;
  --space-5: 40px;
  --space-6: 48px;
  --space-8: 64px;

  /* === Primary Red Accent Palette === */
  --red-vivid: #e50914;
  --red-bright: #ff2a3b;
  --red-core: #dc2626;
  --red-deep: #991b1b;
  --red-darkest: #450a0a;
  --red-glow: rgba(229, 9, 20, 0.3);

  /* === Dark Mode Base (Default) === */
  --bg-base: #060608;
  --bg-elevated: #111116;
  --bg-surface: #181820;
  --bg-surface-hover: #22222e;
  --bg-muted: #0b0b0e;

  /* === Text Colors === */
  --text-primary: #f5f5f7;
  --text-secondary: #a1a1b5;
  --text-tertiary: #656578;
  --text-inverse: #08080a;

  /* === Status Colors === */
  --green-success: #10b981;
  --green-light: #34d399;
  --amber-warning: #f59e0b;
  --blue-info: #3b82f6;

  /* === Borders === */
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-default: rgba(255, 255, 255, 0.16);
  --border-strong: rgba(255, 255, 255, 0.28);
  --border-focus: var(--red-bright);

  /* === Border Radius === */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 999px;

  /* === Shadows === */
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.5);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.8);
  --shadow-glow-red: 0 0 24px var(--red-glow);

  /* === Transitions === */
  --transition-fast: 0.15s ease;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === LIGHT MODE OVERRIDES === */
[data-theme="light"] {
  --bg-base: #f4f5f8;
  --bg-elevated: #ffffff;
  --bg-surface: #eaedf2;
  --bg-surface-hover: #dbe0e8;
  --bg-muted: #e2e6ed;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-tertiary: #64748b;
  --text-inverse: #ffffff;

  --border-subtle: rgba(0, 0, 0, 0.08);
  --border-default: rgba(0, 0, 0, 0.16);
  --border-strong: rgba(0, 0, 0, 0.32);
  --border-focus: var(--red-core);

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.15);
  --shadow-glow-red: 0 0 20px rgba(220, 38, 38, 0.2);
}

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

html {
  font-size: 16px;
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-body);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--text-primary);
  background-color: var(--bg-base);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background-color var(--transition), color var(--transition);
}

/* === Custom Aesthetic Scrollbar === */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}
::-webkit-scrollbar-track {
  background: var(--bg-muted);
}
::-webkit-scrollbar-thumb {
  background: #2a2a38;
  border-radius: var(--radius-full);
  border: 2px solid var(--bg-muted);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--red-vivid);
}

/* Firefox */
* {
  scrollbar-width: thin;
  scrollbar-color: #2a2a38 var(--bg-muted);
}

/* === Layout Shell === */
.app-header {
  height: 64px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-4);
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.brand-container {
  display: flex;
  align-items: center;
}

.brand-svg-logo {
  height: 32px;
  width: auto;
  max-width: 230px;
  display: block;
}

[data-theme="light"] .brand-svg-logo .st0,
[data-theme="light"] .brand-svg-logo .st1 {
  fill: #0f172a;
}

.brand-logo {
  width: 34px;
  height: 34px;
  background: linear-gradient(135deg, var(--red-vivid), var(--red-darkest));
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.2rem;
  box-shadow: var(--shadow-glow-red);
}

.brand-title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.brand-title span.accent {
  color: var(--red-bright);
}

.brand-tag {
  font-size: 0.65rem;
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  padding: 2px 8px;
  background: rgba(229, 9, 20, 0.12);
  border: 1px solid rgba(229, 9, 20, 0.3);
  color: var(--red-bright);
  border-radius: var(--radius-full);
}

/* Studio Modes Header Switcher */
.studio-switcher {
  display: flex;
  align-items: center;
  background: var(--bg-surface);
  padding: 3px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  gap: 3px;
  max-width: 100%;
}

.switcher-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.84rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  flex-shrink: 0;
}

.switcher-icon {
  flex-shrink: 0;
  opacity: 0.85;
}

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

.switcher-btn.active {
  background: var(--red-vivid);
  color: #fff;
  box-shadow: var(--shadow-glow-red);
}

.switcher-btn.active .switcher-icon {
  opacity: 1;
}

.switcher-text-short {
  display: none;
}

.switcher-text-full {
  display: inline;
}

/* Header Action Controls */
.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.theme-toggle {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  width: auto;
  height: 34px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 600;
  font-family: var(--font-body);
  transition: all var(--transition-fast);
}

.theme-toggle:hover {
  border-color: var(--red-bright);
  color: var(--red-bright);
}

/* Main Studio Container */
.studio-body {
  display: grid;
  grid-template-columns: var(--sidebar-width, 460px) 1fr;
  min-height: calc(100vh - 64px);
  position: relative;
}

@media (max-width: 1100px) {
  .studio-body {
    grid-template-columns: 1fr;
  }
}

/* Horizontal Splitter Resizer (Between Stage Preview and History) */
.panel-resizer-horizontal, #panelResizer {
  width: 100%;
  height: 8px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  cursor: row-resize;
  position: relative;
  transition: background var(--transition-fast), border-color var(--transition-fast);
  user-select: none;
  z-index: 10;
  flex: 0 0 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.panel-resizer-horizontal:hover, .panel-resizer-horizontal.is-dragging,
#panelResizer:hover, #panelResizer.is-dragging {
  background: rgba(229, 9, 20, 0.25);
  border-color: var(--red-bright);
  box-shadow: 0 0 10px rgba(229, 9, 20, 0.35);
}

.panel-resizer-horizontal::after,
#panelResizer::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 36px;
  height: 2px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.4);
  transition: background var(--transition-fast), width var(--transition-fast);
}

.panel-resizer-horizontal:hover::after, .panel-resizer-horizontal.is-dragging::after,
#panelResizer:hover::after, #panelResizer.is-dragging::after {
  background: var(--red-bright);
  width: 52px;
}

/* Vertical Splitter Resizer (Prompt Assistant) */
.panel-resizer-right {
  display: none;
  width: 6px;
  background: var(--border-subtle);
  cursor: col-resize;
  position: relative;
  transition: background var(--transition-fast);
  user-select: none;
  z-index: 10;
}

.panel-resizer-right:hover, .panel-resizer-right.is-dragging {
  background: var(--red-bright);
  box-shadow: 0 0 10px var(--red-glow);
}

.panel-resizer-right::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 32px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.3);
}

/* =========================================================
   PROMPT ASSISTANT PANEL (INTEGRATED RIGHT PANEL)
   ========================================================= */
.studio-body.prompt-assistant-active {
  grid-template-columns: var(--sidebar-width, 460px) 1fr 6px minmax(580px, 680px);
}

.prompt-assistant-panel {
  display: none;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-subtle);
  height: calc(100vh - 64px);
  overflow: hidden;
  min-width: 0;
}

.studio-body.prompt-assistant-active .prompt-assistant-panel {
  display: flex;
  flex-direction: column;
}

.studio-body.prompt-assistant-active .panel-resizer-right {
  display: block;
}

.panel-resizer-right {
  display: none;
}

.prompt-assistant-content {
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.prompt-assistant-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(229, 9, 20, 0.05);
  flex-shrink: 0;
}

.prompt-assistant-header-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.prompt-assistant-header-title .title-text {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin: 0;
}

.prompt-assistant-header-title .subtitle-text {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin: 0;
}

.tool-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: rgba(229, 9, 20, 0.2);
  border: 1px solid var(--red-bright);
  font-size: 1.15rem;
}

.panel-close-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  line-height: 1.2;
  transition: all var(--transition-fast);
}

.panel-close-btn:hover {
  background: rgba(229, 9, 20, 0.15);
  border-color: rgba(229, 9, 20, 0.35);
  color: #fff;
}

.panel-close-btn.utilities-close-btn {
  padding: 2px 7px;
  font-size: 0.74rem;
  border-radius: 4px;
}

.prompt-assistant-body {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1.1fr;
  padding: var(--space-3);
  gap: var(--space-3);
  min-height: 0;
  overflow-y: auto;
}

.prompt-assistant-left {
  display: flex;
  flex-direction: column;
  gap: var(--space-2p5, 12px);
  overflow-y: auto;
  padding-right: 4px;
}

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

.prompt-assistant-left label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.prompt-assistant-left .form-select,
.prompt-assistant-left .form-input,
.prompt-assistant-left .form-textarea {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-body);
  padding: 8px 10px;
  font-size: 0.88rem;
}

.prompt-assistant-left .form-textarea {
  resize: vertical;
  min-height: 90px;
}

.prompt-assistant-right {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}

.output-section {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.output-section h3 {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: var(--space-1p5);
}

.output-actions {
  display: flex;
  gap: var(--space-1p5);
  margin-bottom: var(--space-2);
}

.btn-icon {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  cursor: pointer;
  transition: all var(--transition-fast);
  display: flex;
  align-items: center;
  gap: 4px;
}

.btn-icon:hover {
  border-color: var(--red-bright);
  color: var(--red-bright);
  background: rgba(229, 9, 20, 0.05);
}

.pa-tabs-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
}

.pa-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-family: var(--font-display);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 6px 12px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

.pa-tab-btn.active {
  background: rgba(229, 9, 20, 0.15);
  border-color: rgba(229, 9, 20, 0.4);
  color: #fff;
}

.pa-history-count-badge {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  background: rgba(255, 255, 255, 0.1);
  padding: 1px 6px;
  border-radius: 10px;
  color: var(--text-tertiary);
}

.pa-tab-btn.active .pa-history-count-badge {
  background: var(--red-bright);
  color: #fff;
}

.pa-dual-prompts-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-2p5, 12px);
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.pa-prompt-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: border-color var(--transition-fast);
}

.pa-prompt-box:hover {
  border-color: var(--border-subtle);
}

.pa-basic-box {
  flex: 0 0 auto;
  max-height: 180px;
}

.pa-optimized-box {
  flex: 1 1 0;
  min-height: 180px;
  border-color: rgba(229, 9, 20, 0.35);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.25);
}

.pa-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--border-subtle);
}

.pa-box-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pa-box-tag {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: 3px;
}

.pa-box-tag.basic-tag {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

.pa-box-tag.optimized-tag {
  background: rgba(229, 9, 20, 0.2);
  color: var(--red-bright);
  border: 1px solid rgba(229, 9, 20, 0.4);
}

.pa-box-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-primary);
}

.pa-prompt-content-view {
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.55;
  color: var(--text-primary);
  overflow-y: auto;
  flex: 1;
  white-space: pre-wrap;
}

.pa-prompt-content-view.muted-view {
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.15);
  font-size: 0.78rem;
}

.btn-sm {
  padding: 3px 8px;
  font-size: 0.72rem;
}

/* =========================================================
   PROMPT ASSISTANT - HISTORY TAB UI/UX REFINEMENT
   ========================================================= */
.pa-history-pane {
  padding: var(--space-2p5, 12px) var(--space-3) !important;
  background: var(--bg-surface) !important;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  min-height: 0;
  gap: 10px;
}

.pa-history-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.pa-history-search-wrap {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.pa-search-icon {
  position: absolute;
  left: 9px;
  color: var(--text-tertiary);
  pointer-events: none;
}

.pa-search-input {
  width: 100%;
  font-size: 0.74rem;
  padding: 6px 10px 6px 28px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.pa-search-input:focus {
  border-color: rgba(229, 9, 20, 0.45);
  background: var(--bg-surface);
  outline: none;
}

.pa-clear-history-btn {
  background: transparent !important;
  border: 1px solid var(--border-subtle) !important;
  color: var(--text-tertiary) !important;
  font-size: 0.7rem !important;
  padding: 5px 9px !important;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.pa-clear-history-btn:hover {
  color: #ef4444 !important;
  border-color: rgba(239, 68, 68, 0.3) !important;
  background: rgba(239, 68, 68, 0.08) !important;
}

.pa-history-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-right: 2px;
  min-height: 0;
}

/* History Card */
.pa-history-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.pa-history-card:hover {
  border-color: rgba(255, 255, 255, 0.18);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* Header */
.pa-hcard-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.pa-hcard-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.pa-hcard-model {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  color: #fff;
  background: rgba(229, 9, 20, 0.18);
  border: 1px solid rgba(229, 9, 20, 0.35);
  padding: 2px 7px;
  border-radius: 4px;
  white-space: nowrap;
}

.pa-hcard-duration {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.06);
  padding: 2px 5px;
  border-radius: 3px;
}

.pa-hcard-time {
  font-size: 0.66rem;
  color: var(--text-tertiary);
  white-space: nowrap;
}

.pa-hcard-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.pa-hcard-btn {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
  line-height: 1.25;
}

.pa-hcard-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
}

.pa-hcard-btn.primary-action {
  background: rgba(229, 9, 20, 0.16);
  border-color: rgba(229, 9, 20, 0.4);
  color: #fff;
}

.pa-hcard-btn.primary-action:hover {
  background: var(--red-bright);
  border-color: var(--red-bright);
}

.pa-hcard-btn-danger {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  padding: 4px 6px;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.pa-hcard-btn-danger:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

/* Card Body */
.pa-hcard-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.pa-hcard-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

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

.pa-row-pill {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  padding: 1px 5px;
  border-radius: 3px;
  display: inline-flex;
  align-items: center;
}

.pa-row-pill.basic-pill {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-tertiary);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.pa-row-pill.ai-pill {
  background: rgba(229, 9, 20, 0.12);
  color: var(--red-bright);
  border: 1px solid rgba(229, 9, 20, 0.25);
}

.pa-copy-link {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-size: 0.64rem;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  padding: 1px 4px;
  border-radius: 3px;
  transition: all var(--transition-fast);
}

.pa-copy-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.08);
}

.pa-hcard-text {
  border-radius: 4px;
  padding: 6px 9px;
  font-size: 0.72rem;
  line-height: 1.45;
  word-break: break-word;
}

.pa-hcard-text.basic-text {
  color: var(--text-secondary);
  background: rgba(0, 0, 0, 0.22);
  border-left: 2px solid rgba(255, 255, 255, 0.12);
  max-height: 48px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.pa-hcard-text.optimized-text {
  font-family: var(--font-mono);
  font-size: 0.71rem;
  color: var(--text-primary);
  background: rgba(18, 18, 24, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-left: 2px solid var(--red-bright);
  max-height: 64px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

/* Empty State */
.pa-empty-history {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 36px 16px;
  color: var(--text-tertiary);
  text-align: center;
  gap: 6px;
}

.pa-empty-icon-wrap {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
  margin-bottom: 4px;
}

.pa-empty-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.pa-empty-sub {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  max-width: 240px;
  line-height: 1.4;
}

.prompt-assistant-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-2p5, 12px) var(--space-3);
  border-top: 1px solid var(--border-subtle);
  background: rgba(229, 9, 20, 0.04);
  flex-shrink: 0;
}

/* Responsive adjustments for smaller screens */
@media (max-width: 1400px) {
  .studio-body.prompt-assistant-active {
    grid-template-columns: var(--sidebar-width, 440px) 1fr 6px 540px;
  }
}

@media (max-width: 1200px) {
  .studio-body.prompt-assistant-active {
    grid-template-columns: var(--sidebar-width, 420px) 1fr 6px 480px;
  }
  .prompt-assistant-body {
    grid-template-columns: 1fr;
  }
}

/* Sidebar Controls Panel */
.sidebar-panel {
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-subtle);
  padding: var(--space-3);
  overflow-y: auto;
  max-height: calc(100vh - 64px);
}

.section-card {
  background: var(--bg-surface);
  border-radius: var(--radius);
  border: 1px solid var(--border-subtle);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  transition: border-color var(--transition-fast);
}

.section-card:hover {
  border-color: var(--border-default);
}

.card-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-2);
}

.section-label {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--red-bright);
  font-weight: 600;
}

.section-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--text-primary);
}

/* Mode Pills */
.mode-pills {
  display: flex;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
}

.pill-btn {
  flex: 1;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: all var(--transition-fast);
}

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

.pill-btn.active {
  background: rgba(229, 9, 20, 0.12);
  border-color: var(--red-bright);
  color: var(--red-bright);
}

/* Model Selector Box */
.model-select-wrapper {
  margin-bottom: var(--space-2);
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.form-select, .form-input, .form-textarea {
  width: 100%;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--text-primary);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  transition: all var(--transition-fast);
}

.form-select:focus, .form-input:focus, .form-textarea:focus {
  border-color: var(--red-bright);
  box-shadow: 0 0 0 3px var(--red-glow);
}

.form-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23a1a1b5' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
}

.model-badge-info {
  margin-top: 8px;
  font-size: 0.78rem;
  color: var(--text-tertiary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.model-price-tag {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--red-bright);
}

/* Prompt Box */
.prompt-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.chip-btn:hover {
  border-color: var(--red-bright);
  color: var(--red-bright);
}

/* Resolution & Aspect Ratio Selectors */
.res-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

.res-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 8px 4px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: all var(--transition-fast);
}

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

.res-btn.active {
  background: rgba(229, 9, 20, 0.15);
  border-color: var(--red-bright);
  color: var(--red-bright);
  font-weight: 700;
}

.aspect-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-1);
  margin-bottom: var(--space-2);
}

.aspect-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.8rem;
  padding: 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: all var(--transition-fast);
}

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

.aspect-btn.active {
  background: rgba(229, 9, 20, 0.12);
  border-color: var(--red-bright);
  color: var(--red-bright);
  font-weight: 700;
}

.aspect-icon {
  border: 1.5px solid currentColor;
  border-radius: 2px;
}

/* Sliders & Numerical Inputs */
.slider-group {
  margin-bottom: var(--space-2);
}

.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  margin-bottom: 6px;
}

.slider-value {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--red-bright);
  font-weight: 600;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--red-vivid);
  cursor: pointer;
}

/* Dropzone Upload */
.upload-dropzone {
  border: 2px dashed var(--border-default);
  border-radius: var(--radius);
  background: var(--bg-elevated);
  padding: var(--space-3);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  overflow: hidden;
}

.upload-dropzone:hover {
  border-color: var(--red-bright);
  background: rgba(229, 9, 20, 0.04);
}

.upload-dropzone.drag-active,
.multi-add-slot.drag-active {
  border-color: var(--red-bright) !important;
  background: rgba(229, 9, 20, 0.15) !important;
  box-shadow: 0 0 16px rgba(229, 9, 20, 0.35) !important;
  transform: scale(1.02);
}

.gallery-card {
  cursor: grab;
}

.gallery-card:active {
  cursor: grabbing;
}

.gallery-card.is-dragging {
  opacity: 0.5;
  transform: scale(0.96);
  border-color: var(--red-bright);
}

.preview-thumbnail {
  max-height: 120px;
  max-width: 100%;
  border-radius: var(--radius-sm);
  object-fit: contain;
}

/* Multi-Image Reference Gallery */
.multi-image-container {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.multi-image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(82px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.multi-thumb-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  background: #000;
}

.multi-thumb-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--transition-fast);
}

.multi-thumb-wrapper:hover img {
  transform: scale(1.05);
}

.multi-thumb-delete {
  position: absolute;
  top: 4px;
  right: 4px;
  padding: 2px 6px;
  background: rgba(0, 0, 0, 0.85);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
  line-height: 1.2;
}

.multi-thumb-delete:hover {
  background: var(--red-vivid);
  border-color: var(--red-bright);
}

/* =========================================================
   MULTIMODAL REFERENCE TABS & LISTS (VIDEO STUDIO)
   ========================================================= */
.ref-media-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--bg-elevated);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  margin-bottom: var(--space-2);
}

.ref-tab-btn {
  flex: 1;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font-body);
  font-size: 0.76rem;
  font-weight: 600;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: all var(--transition-fast);
}

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

.ref-tab-btn.active {
  background: rgba(229, 9, 20, 0.16);
  border-color: rgba(229, 9, 20, 0.4);
  color: #fff;
}

.ref-tab-counter {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-tertiary);
}

.ref-tab-btn.active .ref-tab-counter {
  background: var(--red-bright);
  color: #fff;
}

.ref-media-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.ref-video-item, .ref-audio-item {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  transition: border-color var(--transition-fast);
}

.ref-video-item:hover, .ref-audio-item:hover {
  border-color: var(--border-default);
}

.ref-media-item-info {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}

.ref-media-name {
  font-size: 0.78rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 170px;
}

.ref-media-duration {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-tertiary);
  background: rgba(255, 255, 255, 0.06);
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
}

.ref-media-audio-player {
  width: 130px;
  height: 24px;
}

.ref-media-del-btn {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
  font-size: 0.7rem;
  padding: 3px 7px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}

.ref-media-del-btn:hover {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.4);
  background: rgba(239, 68, 68, 0.1);
}

.multi-add-slot {
  aspect-ratio: 1;
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.75rem;
  transition: all var(--transition-fast);
  gap: 4px;
}

.multi-add-slot:hover {
  border-color: var(--red-bright);
  color: var(--red-bright);
  background: rgba(229, 9, 20, 0.05);
}

.image-count-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--text-tertiary);
}

/* =========================================================
   FRAMESTUDIO KEYFRAMES STORY STRIP & CARDS
   ========================================================= */
.keyframes-strip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 4px 2px 8px;
  scroll-behavior: smooth;
}

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

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

.keyframe-card {
  flex: 0 0 110px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 5px;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: all var(--transition-fast);
}

.keyframe-card:hover {
  border-color: rgba(229, 9, 20, 0.4);
}

.keyframe-order-badge {
  font-family: var(--font-mono);
  font-size: 0.65rem;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 6px;
  border-radius: 3px;
  margin-bottom: 4px;
  align-self: flex-start;
}

.keyframe-thumb {
  width: 100%;
  aspect-ratio: 16/9;
  object-fit: cover;
  border-radius: 3px;
  border: 1px solid var(--border-subtle);
  margin-bottom: 4px;
  background: #000;
}

.keyframe-delete-btn {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-size: 0.68rem;
  padding: 2px 4px;
  cursor: pointer;
  transition: color var(--transition-fast);
  border-radius: 2px;
}

.keyframe-delete-btn:hover {
  color: #ef4444;
}

.FrameStudio-keyframe-card {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

/* PRIMARY ACTION GENERATE BUTTON WITH PRICE */
.generate-action-box, div:nth-of-type(1) > aside:nth-of-type(1) > div:nth-of-type(6) {
  position: static;
  background: transparent;
  padding: var(--space-2) 0 var(--space-4);
  border-top: none;
  margin: var(--space-3) 0 0;
  box-shadow: none;
}

.btn-generate {
  width: 100%;
  background: linear-gradient(135deg, var(--red-vivid) 0%, #b91c1c 100%);
  color: #ffffff;
  border: none;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-body);
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1p5);
  box-shadow: var(--shadow-glow-red);
  transition: all var(--transition);
}

.btn-generate:hover {
  background: linear-gradient(135deg, var(--red-bright) 0%, var(--red-vivid) 100%);
  transform: translateY(-1px);
  box-shadow: 0 0 32px rgba(229, 9, 20, 0.5);
}

.btn-generate:active {
  transform: translateY(1px);
}

.btn-generate:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.price-pill {
  background: rgba(0, 0, 0, 0.35);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* Workspace Canvas & Output Area */
.workspace-panel {
  background: var(--bg-base);
  padding: 0;
  display: flex;
  flex-direction: column;
  height: calc(100vh - 64px);
  max-height: calc(100vh - 64px);
  overflow: hidden;
  position: relative;
  min-width: 0;
}

/* Active Stage Canvas (Borderless & Native Proportions) - Always Visible Upper Stage */
.stage-card, #stageCard {
  flex: 1 1 0%;
  min-height: 120px;
  background: transparent;
  border: none;
  box-shadow: none;
  border-radius: 0;
  padding: var(--space-2) var(--space-4);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  width: 100%;
}

.stage-placeholder {
  text-align: center;
  color: var(--text-tertiary);
  max-width: 480px;
  padding: var(--space-6) var(--space-4);
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.015);
  margin: auto;
  width: 100%;
  font-family: var(--font-display, var(--font-body));
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.stage-icon {
  font-size: 3rem;
  margin-bottom: var(--space-2);
  color: var(--text-tertiary);
}

.stage-title {
  font-family: var(--font-display);
  font-size: 1.4rem;
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.stage-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Loading & Progress State */
.loading-box {
  text-align: center;
  padding: var(--space-6);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-lg);
  background: rgba(255, 255, 255, 0.015);
  max-width: 480px;
  width: 100%;
  margin: var(--space-4) auto;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid var(--border-default);
  border-top-color: var(--red-bright);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 0 auto var(--space-3);
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.progress-text {
  font-family: var(--font-mono);
  font-size: 0.9rem;
  color: var(--red-bright);
  font-weight: 600;
  margin-bottom: var(--space-1);
}

/* Dynamic Active Stage Container */
#stageMediaWrapper {
  width: 100%;
  height: 100%;
  max-height: 100%;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

/* Active Media Result Display - Adapts to Image/Video Aspect Ratio */
.media-container {
  width: auto;
  max-width: 100%;
  max-height: calc(100% - 46px);
  flex: 1 1 auto;
  min-height: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  border: 1px solid var(--border-subtle);
  background: #000;
}

.media-container img, .media-container video {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  display: block;
  object-fit: contain;
  cursor: zoom-in;
  transition: transform var(--transition-fast);
}

.media-container img:hover, .media-container video:hover {
  opacity: 0.98;
}

.media-toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 3px 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  width: auto;
  max-width: 100%;
  box-sizing: border-box;
  flex-shrink: 0;
}

.media-toolbar-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  flex-wrap: wrap;
}

.btn-stage-action {
  padding: 3px 8px !important;
  font-size: 0.68rem !important;
  font-weight: 500 !important;
  border-radius: 4px !important;
  line-height: 1.2 !important;
  gap: 3px !important;
}

.media-toolbar .brand-tag {
  font-size: 0.58rem;
  padding: 1px 6px;
  letter-spacing: 0.08em;
}

.media-toolbar #renderedMetaBadge {
  font-size: 0.68rem;
  margin-left: 6px;
}

.media-toolbar .btn-icon, .btn-icon {
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all var(--transition-fast);
  line-height: 1.25;
}

.media-toolbar .btn-icon:hover, .btn-icon:hover {
  border-color: var(--red-bright);
  color: var(--red-bright);
}

/* =========================================================
   INDEPENDENT HISTORY DOCK (LOWER WORKSPACE VIEWPORT)
   ========================================================= */
.history-dock-section {
  flex: 0 0 var(--history-height, 240px);
  height: var(--history-height, 240px);
  min-height: 100px;
  max-height: calc(100% - 130px);
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border-top: none;
  padding: var(--space-2) var(--space-4) var(--space-1p5);
  min-width: 0;
  box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.3);
  position: relative;
  overflow: hidden;
  z-index: 5;
}

.gallery-section-title {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-1);
  gap: var(--space-2);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.history-title-group {
  display: flex;
  align-items: center;
  gap: var(--space-1p5);
}

.history-title-group > span:first-child {
  font-family: var(--font-body);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-primary);
}

.history-count-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
}

.history-toolbar-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

/* Thumbnail Size Controls */
.thumb-size-control {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-surface);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.thumb-control-label {
  font-size: 0.72rem;
  color: var(--text-tertiary);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.thumb-size-pills {
  display: flex;
  gap: 2px;
}

.thumb-pill-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 3px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.thumb-pill-btn:hover {
  color: var(--text-primary);
  background: var(--bg-surface-hover);
}

.thumb-pill-btn.active {
  background: var(--red-vivid);
  color: #fff;
  border-color: var(--red-bright);
}

.thumb-range-slider {
  width: 65px;
  height: 4px;
  accent-color: var(--red-vivid);
  cursor: pointer;
}

.history-scroll-viewport {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
}

.gallery-grid {
  --thumb-width: 170px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--thumb-width, 170px), 1fr));
  gap: var(--space-1p5);
  padding: 2px 2px 10px;
}

.gallery-card {
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
  transition: all var(--transition-fast);
  cursor: pointer;
  display: flex;
  flex-direction: column;
}

.gallery-card:hover {
  transform: translateY(-2px);
  border-color: var(--red-bright);
  box-shadow: 0 4px 12px rgba(229, 9, 20, 0.25);
}

.gallery-card.active-media-card {
  border-color: var(--red-bright);
  box-shadow: 0 0 0 2px var(--red-bright);
}

.gallery-thumb {
  width: 100%;
  aspect-ratio: 16 / 10;
  background: #000;
  position: relative;
  overflow: hidden;
}

.gallery-thumb img, .gallery-thumb video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.type-badge {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-family: var(--font-mono);
  font-size: 0.6rem;
  padding: 2px 5px;
  border-radius: 3px;
  text-transform: uppercase;
}

.gallery-info {
  padding: 5px 7px 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.gallery-prompt {
  font-size: 0.73rem;
  color: var(--text-primary);
  line-clamp: 1;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.25;
}

.gallery-meta {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 0.64rem;
  color: var(--text-tertiary);
}

.gallery-card.running-job-card {
  border-color: rgba(229, 9, 20, 0.45);
  background: var(--bg-surface);
  cursor: default;
  animation: pulseRunningJob 2s infinite ease-in-out;
}

@keyframes pulseRunningJob {
  0%, 100% { border-color: rgba(229, 9, 20, 0.35); box-shadow: 0 0 8px rgba(229, 9, 20, 0.15); }
  50% { border-color: rgba(229, 9, 20, 0.75); box-shadow: 0 0 16px rgba(229, 9, 20, 0.35); }
}

.running-job-thumb {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, rgba(229, 9, 20, 0.1) 0%, #0a0a0a 100%) !important;
  gap: 6px;
}

.running-job-timer {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-primary);
  background: rgba(0, 0, 0, 0.55);
  padding: 1px 7px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(255, 255, 255, 0.15);
}

/* Template Chips for Agencies */
.template-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: var(--space-1);
}

.template-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: var(--space-1p5);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.template-card:hover {
  border-color: var(--red-bright);
  background: rgba(229, 9, 20, 0.05);
}

.template-card-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.template-card-desc {
  font-size: 0.72rem;
  color: var(--text-tertiary);
}

/* =========================================================
   FULLSCREEN LIGHTBOX MODAL
   ========================================================= */
.fullscreen-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.94);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 9999;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-2);
  animation: modalFadeIn 0.2s ease-out;
  overflow: hidden;
}

.fullscreen-modal.active {
  display: flex;
}

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

/* Modal Top Bar (Metadata & Toolbar) */
.modal-top-bar {
  position: absolute;
  top: 16px;
  left: 20px;
  right: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 10003;
  pointer-events: auto;
  gap: var(--space-2);
}

.modal-meta-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-pill-badge {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  line-height: 1.2;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.modal-pill-badge.zoom-indicator {
  background: rgba(229, 9, 20, 0.25);
  border-color: var(--red-bright);
  color: #fff;
  transition: all var(--transition-fast);
}

.modal-pill-badge.zoom-indicator.is-real-100 {
  background: rgba(46, 213, 115, 0.22);
  border-color: #2ed573;
  color: #2ed573;
}

.modal-top-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.modal-tool-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 0 12px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  user-select: none;
}

.modal-tool-btn:hover {
  background: var(--red-bright);
  border-color: var(--red-bright);
}

.modal-close-btn {
  position: static;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #fff;
  padding: 0 14px;
  height: 32px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  z-index: 10001;
}

.modal-close-btn:hover {
  background: var(--red-bright);
  border-color: var(--red-bright);
  transform: none;
}

/* Lateral Navigation Chevrons */
.modal-nav-btn {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(20, 20, 26, 0.8);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
  z-index: 10002;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  user-select: none;
}

.modal-nav-prev {
  left: 20px;
}

.modal-nav-next {
  right: 20px;
}

.modal-nav-btn:hover {
  background: var(--red-bright);
  border-color: var(--red-bright);
  transform: translateY(-50%) scale(1.1);
  box-shadow: 0 0 24px rgba(229, 9, 20, 0.6);
}

.modal-nav-btn:active {
  transform: translateY(-50%) scale(0.96);
}

@media (max-width: 768px) {
  .modal-nav-btn {
    width: 40px;
    height: 40px;
  }
  .modal-nav-prev {
    left: 8px;
  }
  .modal-nav-next {
    right: 8px;
  }
}

.modal-content-wrapper {
  position: relative;
  width: 100%;
  max-width: 95vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  margin-top: 38px;
  animation: modalZoomIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalZoomIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* Fullscreen Viewport with Scroll Zoom and Drag Pan */
.fullscreen-viewport {
  position: relative;
  width: 100%;
  max-width: 90vw;
  height: 74vh;
  max-height: 74vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-radius: var(--radius-md);
  cursor: grab;
  user-select: none;
  transition: background 0.25s ease;
}

/* Matte & Transparency Background Variations */
.fullscreen-viewport.matte-dark {
  background: #09090d;
}

.fullscreen-viewport.matte-grid,
.matte-checkerboard {
  background-color: #1a1a24;
  background-image: 
    linear-gradient(45deg, #12121a 25%, transparent 25%), 
    linear-gradient(-45deg, #12121a 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #12121a 75%), 
    linear-gradient(-45deg, transparent 75%, #12121a 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
}

.fullscreen-viewport.matte-white {
  background: #f8fafc;
}

/* Matte Switcher Component */
.modal-matte-switch {
  display: inline-flex;
  align-items: center;
  background: rgba(18, 18, 24, 0.75);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-full);
  padding: 2px;
  gap: 2px;
  backdrop-filter: blur(8px);
}

.matte-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.matte-btn:hover {
  color: #fff;
}

.matte-btn.active {
  background: rgba(229, 9, 20, 0.85);
  color: #fff;
  box-shadow: 0 0 10px rgba(229, 9, 20, 0.4);
}

.fullscreen-viewport.is-panning {
  cursor: grabbing !important;
}

.fullscreen-media {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: var(--radius-md);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 40px rgba(229, 9, 20, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  transform-origin: center center;
  transition: transform 0.05s linear;
  will-change: transform;
}

/* When viewing on transparent / white matte, soften the red drop shadow */
.fullscreen-viewport.matte-white .fullscreen-media {
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.modal-caption {
  width: 100%;
  max-width: 900px;
  margin-top: var(--space-2);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-family: var(--font-body);
  background: rgba(18, 18, 24, 0.85);
  border: 1px solid var(--border-subtle);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  box-sizing: border-box;
}

#modalCaptionText {
  color: var(--text-primary);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
}

.btn-primary {
  background: var(--red-vivid);
  color: white;
  border: none;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

.pa-price-tag {
  font-size: 0.7rem;
  font-family: var(--font-mono);
  font-weight: 700;
  background: rgba(0, 0, 0, 0.32);
  padding: 1px 7px;
  border-radius: var(--radius-full);
  border: 1px solid rgba(255, 255, 255, 0.22);
  line-height: 1.3;
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--red-bright);
  transform: translateY(-1px);
  box-shadow: 0 4px 16px var(--red-glow);
}

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-default);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

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

/* Prompt Assistant Thumbnail & Reference Image Styles */
.pa-image-control-wrapper {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.pa-image-upload-box {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-surface);
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.pa-image-upload-box:hover {
  border-color: var(--red-bright);
  background: rgba(229, 9, 20, 0.05);
}

.pa-upload-text {
  font-size: 0.84rem;
  color: var(--text-secondary);
}

.pa-thumb-container {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  width: fit-content;
  max-width: 100%;
}

.pa-thumb-img {
  width: 58px;
  height: 58px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border-default);
  background: #000;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.pa-thumb-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.pa-thumb-name {
  font-size: 0.8rem;
  color: var(--text-secondary);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pa-thumb-remove-btn {
  background: rgba(229, 9, 20, 0.15);
  color: var(--red-bright);
  border: 1px solid rgba(229, 9, 20, 0.35);
  font-size: 0.75rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
  width: fit-content;
}

.pa-thumb-remove-btn:hover {
  background: var(--red-vivid);
  color: #fff;
  border-color: var(--red-vivid);
}

@keyframes modalZoomIn {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

@keyframes mobileSlideUp {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* =========================================================
   UTILIDADES DROPDOWN & MENU
   ========================================================= */
.utilities-wrapper {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.utilities-chevron {
  transition: transform var(--transition-fast);
}

.utilities-wrapper.open .utilities-chevron {
  transform: rotate(180deg);
}

.utilities-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  width: 320px;
  max-width: calc(100vw - 24px);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  z-index: 1050;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalZoomIn 0.18s ease-out;
}

[data-theme="light"] .utilities-dropdown {
  background: #ffffff;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.15);
}

.utilities-dropdown-header {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.02);
  flex-shrink: 0;
}

.utilities-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2px;
}

.utilities-menu-title {
  font-family: var(--font-display);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
}

.utilities-tag {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  padding: 1px 5px;
  border-radius: 3px;
  background: rgba(229, 9, 20, 0.15);
  border: 1px solid rgba(229, 9, 20, 0.3);
  color: var(--red-bright);
}

.utilities-menu-subtitle {
  font-size: 0.7rem;
  color: var(--text-tertiary);
  margin-top: 1px;
}

.utilities-dropdown-items {
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  max-height: 380px;
}

.utility-item-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  color: var(--text-primary);
}

.utility-item-btn:hover:not(.utility-item-disabled) {
  background: var(--bg-surface-hover);
  border-color: var(--border-subtle);
  transform: translateX(1px);
}

.utility-item-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.utility-item-icon-box {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  background: rgba(229, 9, 20, 0.15);
  border: 1px solid rgba(229, 9, 20, 0.3);
  color: var(--red-bright);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.utility-item-icon-box svg {
  width: 15px;
  height: 15px;
}

.utility-item-icon-box.muted {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-subtle);
  color: var(--text-tertiary);
}

.utility-item-info {
  flex: 1;
  min-width: 0;
}

.utility-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 2px;
}

.utility-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
}

.utility-name.muted {
  color: var(--text-secondary);
}

.utility-desc {
  font-size: 0.68rem;
  color: var(--text-tertiary);
  line-height: 1.3;
}

.utility-badge-novo {
  font-family: var(--font-mono);
  font-size: 0.6rem;
  font-weight: 600;
  background: rgba(229, 9, 20, 0.18);
  border: 1px solid rgba(229, 9, 20, 0.4);
  color: #fff;
  padding: 1px 5px;
  border-radius: 3px;
  white-space: nowrap;
}

.utility-badge-soon {
  font-family: var(--font-mono);
  font-size: 0.62rem;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
  padding: 1px 5px;
  border-radius: 4px;
}

/* =========================================================
   ULTIMATE IMAGE UPSCALER MODAL
   ========================================================= */
.upscaler-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-3);
  animation: modalFadeIn 0.2s ease-out;
}

.upscaler-modal-card {
  width: 100%;
  max-width: 1080px;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-xl);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.85);
  overflow: hidden;
  animation: modalZoomIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="light"] .upscaler-modal-card {
  background: #ffffff;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.18);
}

.upscaler-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.upscaler-header-title {
  display: flex;
  align-items: center;
  gap: 14px;
}

.upscaler-icon-badge {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  background: rgba(229, 9, 20, 0.15);
  border: 1px solid rgba(229, 9, 20, 0.35);
  color: var(--red-bright);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.upscaler-title {
  font-family: var(--font-display);
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-primary);
}

.upscaler-model-tag {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  padding: 2px 8px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  border-radius: 4px;
  color: var(--text-secondary);
}

.upscaler-subtitle {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  margin-top: 2px;
}

.upscaler-body {
  display: grid;
  grid-template-columns: 1fr 1.08fr;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

@media (max-width: 860px) {
  .upscaler-body {
    grid-template-columns: 1fr;
    overflow-y: auto;
  }
}

.upscaler-left-col {
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--border-subtle);
  overflow-y: auto;
}

.upscaler-right-col {
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  background: var(--bg-base);
  overflow: hidden;
}

.upscaler-section {
  display: flex;
  flex-direction: column;
}

/* Source selector tabs */
.upscale-source-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 8px;
  overflow-x: auto;
}

.upscale-tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-tertiary);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

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

.upscale-tab-btn.active {
  background: rgba(229, 9, 20, 0.15);
  border-color: rgba(229, 9, 20, 0.35);
  color: var(--red-bright);
}

.upscale-source-box {
  padding: 12px;
  border: 1px dashed var(--border-default);
  border-radius: var(--radius);
  background: var(--bg-surface);
  text-align: center;
}

.upscale-dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  border: 2px dashed var(--border-default);
  border-radius: var(--radius);
  background: var(--bg-surface);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-align: center;
}

.upscale-dropzone:hover {
  border-color: var(--red-bright);
  background: rgba(229, 9, 20, 0.04);
}

.upscale-history-picker {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  max-height: 140px;
  overflow-y: auto;
  padding: 4px;
}

.upscale-hist-thumb {
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all var(--transition-fast);
  background: #000;
  position: relative;
}

.upscale-hist-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upscale-hist-thumb:hover {
  border-color: var(--red-bright);
  transform: scale(1.04);
}

.upscale-hist-thumb.selected {
  border: 2px solid var(--red-bright);
  box-shadow: 0 0 10px var(--red-glow);
}

.upscale-selected-meta-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-subtle);
}

.upscale-meta-thumb-wrap {
  width: 44px;
  height: 44px;
  border-radius: 4px;
  overflow: hidden;
  background: #000;
  flex-shrink: 0;
  border: 1px solid var(--border-subtle);
}

.upscale-meta-thumb-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.upscale-meta-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.upscale-source-name {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-primary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.upscale-source-res {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-tertiary);
}

.upscale-clear-source-btn {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  font-size: 0.85rem;
  padding: 4px 8px;
  cursor: pointer;
  border-radius: 4px;
  transition: color var(--transition-fast);
}

.upscale-clear-source-btn:hover {
  color: var(--red-bright);
}

/* Resolution grid cards */
.upscale-res-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.upscale-res-card {
  position: relative;
  cursor: pointer;
  border: 1px solid var(--border-default);
  border-radius: var(--radius);
  background: var(--bg-surface);
  transition: all var(--transition-fast);
  overflow: hidden;
}

.upscale-res-card input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.res-card-inner {
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.res-card-title {
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
}

.res-card-px {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: var(--text-tertiary);
}

.res-card-badge {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  padding: 1px 4px;
  background: rgba(229, 9, 20, 0.2);
  border: 1px solid var(--red-bright);
  color: #fff;
  border-radius: 3px;
}

.res-card-desc {
  font-size: 0.72rem;
  color: var(--text-secondary);
  line-height: 1.3;
  min-height: 34px;
}

.res-card-price {
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 700;
  color: var(--green-success);
  margin-top: 4px;
}

.upscale-res-card:hover {
  border-color: var(--border-strong);
  background: var(--bg-surface-hover);
}

.upscale-res-card.active {
  border-color: var(--red-bright);
  background: rgba(229, 9, 20, 0.08);
  box-shadow: 0 0 14px rgba(229, 9, 20, 0.18);
}

/* Output format pills */
.upscale-format-group {
  display: flex;
  gap: 8px;
}

.format-pill-label {
  cursor: pointer;
  position: relative;
  flex: 1;
}

.format-pill-label input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.format-pill {
  display: block;
  text-align: center;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-default);
  background: var(--bg-surface);
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}

.format-pill-label input:checked + .format-pill {
  border-color: var(--red-bright);
  background: rgba(229, 9, 20, 0.12);
  color: #fff;
}

/* Actions box */
.upscaler-actions-box {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#btnExecuteUpscale,
.btn-primary-action {
  width: 100%;
  background: linear-gradient(135deg, var(--red-vivid) 0%, #b91c1c 100%);
  color: #ffffff;
  border: none;
  padding: var(--space-2) var(--space-3);
  font-family: var(--font-body);
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1p5);
  box-shadow: var(--shadow-glow-red);
  transition: all var(--transition);
  outline: none;
}

#btnExecuteUpscale:hover,
.btn-primary-action:hover {
  background: linear-gradient(135deg, var(--red-bright) 0%, var(--red-vivid) 100%);
  transform: translateY(-1px);
  box-shadow: 0 0 32px rgba(229, 9, 20, 0.5);
}

#btnExecuteUpscale:active,
.btn-primary-action:active {
  transform: translateY(1px);
}

#btnExecuteUpscale:disabled,
.btn-primary-action:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

#btnUpscaleText {
  font-family: var(--font-body);
  font-size: 1.05rem;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.01em;
}

#btnUpscalePrice {
  background: rgba(0, 0, 0, 0.35);
  padding: 4px 10px;
  border-radius: var(--radius-full);
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 700;
  border: 1px solid rgba(255, 255, 255, 0.22);
  color: #ffffff;
  line-height: 1.2;
}

.upscale-status-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: rgba(229, 9, 20, 0.12);
  border: 1px solid rgba(229, 9, 20, 0.3);
  font-size: 0.78rem;
  color: var(--text-primary);
}

.spinner-small {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--red-bright);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

.timer-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  margin-left: auto;
  color: var(--text-secondary);
}

/* Right column preview container */
.upscale-preview-container {
  width: 100%;
  height: 100%;
  min-height: 420px;
  border-radius: var(--radius);
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.upscale-preview-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 32px;
}

.upscale-active-preview-box,
.upscale-result-box {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  overflow: hidden;
}

.upscale-active-preview-box img,
.upscale-result-box img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.upscale-badge-overlay {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 10;
  padding: 3px 8px;
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border-default);
  font-family: var(--font-mono);
  font-size: 0.68rem;
  color: #fff;
}

.upscale-badge-overlay.success {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--green-success);
  color: #fff;
}

.upscale-result-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 10px 16px;
  background: rgba(10, 10, 14, 0.88);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.upscale-processing-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 32px;
  position: relative;
  width: 100%;
  height: 100%;
}

.upscale-scanner-line {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--red-bright), transparent);
  box-shadow: 0 0 12px var(--red-bright);
  animation: scanLine 2s ease-in-out infinite alternate;
}

@keyframes scanLine {
  0% { top: 10%; }
  100% { top: 90%; }
}

.processing-title {
  font-family: var(--font-display);
  font-size: 1.05rem;
  font-weight: 700;
  margin-top: 16px;
  color: var(--text-primary);
}

.processing-sub {
  font-size: 0.78rem;
  color: var(--text-tertiary);
  margin-top: 4px;
}

.upscale-live-timer {
  font-family: var(--font-mono);
  font-size: 0.76rem;
  color: var(--red-bright);
  margin-top: 10px;
  padding: 3px 10px;
  background: rgba(229, 9, 20, 0.12);
  border-radius: 4px;
}

/* Background Remover Modal Specific Styling */
.bg-specs-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.bg-spec-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.76rem;
}

.bg-spec-label {
  color: var(--text-tertiary);
  font-family: var(--font-body);
}

.bg-spec-val {
  color: #10b981;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 0.74rem;
}

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

.bg-matte-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 6px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.bg-matte-btn:hover {
  border-color: rgba(255, 255, 255, 0.3);
  color: #fff;
}

.bg-matte-btn.active {
  background: rgba(16, 185, 129, 0.12);
  border-color: #10b981;
  color: #fff;
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.2);
}

.matte-icon {
  width: 22px;
  height: 22px;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.matte-icon.checker-icon {
  background-color: #262633;
  background-image: 
    linear-gradient(45deg, #161620 25%, transparent 25%), 
    linear-gradient(-45deg, #161620 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #161620 75%), 
    linear-gradient(-45deg, transparent 75%, #161620 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0px;
}

.matte-icon.dark-icon {
  background: #0d0d12;
}

.matte-icon.white-icon {
  background: #ffffff;
}

.bg-isolated-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 30px;
  box-sizing: border-box;
  transition: background 0.25s ease, background-color 0.25s ease;
}

.bg-isolated-wrapper img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 10px 20px rgba(0, 0, 0, 0.5));
}

/* =========================================================
   BACKGROUND REMOVER MATTE MODES (Checkerboard, Dark, White)
   ========================================================= */

/* Ensure the result box and source preview box in bgRemoverModal do not hide the matte background */
#bgRemoverModal #bgResultBox,
#bgRemoverModal #bgSourcePreviewBox {
  background: transparent !important;
}

#bgRemoverModal .upscale-preview-container,
#bgRemoverModal .bg-isolated-wrapper,
#bgRemoverModal #bgResultBox,
#bgRemoverModal #bgSourcePreviewBox {
  transition: background 0.25s ease, background-color 0.25s ease;
}

/* 1. Checkerboard (Grade Xadrez transparente para recorte fino) */
#bgRemoverModal #bgPreviewContainer.matte-checkerboard,
#bgRemoverModal .bg-isolated-wrapper.matte-checkerboard,
#bgRemoverModal #bgResultBox.matte-checkerboard,
#bgRemoverModal #bgSourcePreviewBox.matte-checkerboard,
.media-container.matte-checkerboard,
.matte-checkerboard {
  background-color: #242533 !important;
  background-image: 
    linear-gradient(45deg, #161722 25%, transparent 25%), 
    linear-gradient(-45deg, #161722 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #161722 75%), 
    linear-gradient(-45deg, transparent 75%, #161722 75%) !important;
  background-size: 20px 20px !important;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px !important;
}

/* 2. Dark Matte (Fundo Escuro profundo) */
#bgRemoverModal #bgPreviewContainer.matte-dark,
#bgRemoverModal .bg-isolated-wrapper.matte-dark,
#bgRemoverModal #bgResultBox.matte-dark,
#bgRemoverModal #bgSourcePreviewBox.matte-dark,
.matte-dark {
  background-color: #09090d !important;
  background-image: none !important;
}

/* 3. White Matte (Fundo Branco estúdio puro) */
#bgRemoverModal #bgPreviewContainer.matte-white,
#bgRemoverModal .bg-isolated-wrapper.matte-white,
#bgRemoverModal #bgResultBox.matte-white,
#bgRemoverModal #bgSourcePreviewBox.matte-white,
.matte-white {
  background-color: #ffffff !important;
  background-image: none !important;
}

/* Contrast adjustments when White Matte is active in Background Remover */
#bgRemoverModal #bgPreviewContainer.matte-white .upscale-preview-empty h4 {
  color: #09090d !important;
}
#bgRemoverModal #bgPreviewContainer.matte-white .upscale-preview-empty p {
  color: #334155 !important;
}
#bgRemoverModal #bgPreviewContainer.matte-white .upscale-preview-empty svg {
  stroke: #334155 !important;
  opacity: 0.75 !important;
}
#bgRemoverModal #bgPreviewContainer.matte-white .bg-isolated-wrapper img {
  filter: drop-shadow(0 12px 28px rgba(0, 0, 0, 0.25)) !important;
}
#bgRemoverModal #bgPreviewContainer.matte-white .upscale-badge-overlay:not(.success) {
  background: rgba(15, 23, 42, 0.88) !important;
  color: #ffffff !important;
}

/* =========================================================
   RESPONSIVE NAVIGATION & MENUS (TABLET & MOBILE)
   ========================================================= */
@media (max-width: 1024px) {
  .app-header {
    padding: 0 var(--space-3);
    gap: var(--space-2);
  }

  .brand-svg-logo {
    height: 26px;
    max-width: 170px;
  }

  .switcher-btn {
    padding: 5px 10px;
    font-size: 0.8rem;
    gap: 5px;
  }
}

@media (max-width: 860px) {
  .app-header {
    height: auto;
    min-height: 56px;
    padding: 8px 12px;
    flex-wrap: wrap;
    row-gap: 8px;
    justify-content: space-between;
  }

  .brand-container {
    flex-shrink: 0;
  }

  .brand-svg-logo {
    height: 24px;
    max-width: 150px;
  }

  .header-actions {
    flex-shrink: 0;
  }

  .theme-toggle {
    height: 30px;
    padding: 0 10px;
    font-size: 0.72rem;
  }

  /* Full-width responsive menu bar on mobile */
  .studio-switcher {
    order: 3;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding: 4px;
    border-radius: var(--radius-sm);
    justify-content: flex-start;
  }

  .studio-switcher::-webkit-scrollbar {
    display: none;
  }

  .switcher-btn {
    flex: 1 0 auto;
    justify-content: center;
    padding: 6px 10px;
    font-size: 0.76rem;
  }

  .switcher-text-full {
    display: none;
  }

  .switcher-text-short {
    display: inline;
  }

  /* Utilities dropdown position adapts to mobile viewport as a clean bottom sheet */
  .utilities-dropdown {
    position: fixed;
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100vw;
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    border: 1px solid var(--border-default);
    border-bottom: none;
    max-height: 75vh;
    flex-direction: column;
    z-index: 9999;
    box-shadow: 0 -12px 48px rgba(0, 0, 0, 0.9);
    animation: mobileSlideUp 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  }

  .utilities-wrapper.open .utilities-dropdown {
    display: flex !important;
  }

  .utilities-dropdown[style*="display: none"] {
    display: none !important;
  }

  .utilities-dropdown-items {
    max-height: calc(75vh - 70px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px 12px 24px 12px;
    gap: 6px;
  }

  .utility-item-btn {
    padding: 10px 12px !important;
    background: rgba(255, 255, 255, 0.03) !important;
    border: 1px solid var(--border-subtle) !important;
    border-radius: var(--radius-md) !important;
  }

  .utility-item-btn:hover {
    background: rgba(255, 255, 255, 0.08) !important;
  }

  /* Modal Prompt Assistant full screen overlay on mobile */
  .studio-body.prompt-assistant-active {
    grid-template-columns: 1fr;
  }

  .studio-body.prompt-assistant-active .prompt-assistant-panel {
    position: fixed;
    inset: 0;
    top: 56px;
    height: calc(100vh - 56px);
    z-index: 1000;
  }
}

@media (max-width: 480px) {
  .brand-svg-logo {
    height: 20px;
    max-width: 125px;
  }

  .switcher-btn {
    padding: 6px 8px;
    font-size: 0.72rem;
    gap: 4px;
  }

  .switcher-icon {
    width: 12px;
    height: 12px;
  }
}


