:root {
  --bg-dark: #07090e;
  --bg-card: #0d111a;
  --bg-card-border: #1a2233;
  --primary: #00f2fe;
  --primary-glow: rgba(0, 242, 254, 0.35);
  --accent-pink: #ff007f;
  --accent-pink-glow: rgba(255, 0, 127, 0.35);
  --text-main: #f0f4f8;
  --text-muted: #8292a6;
  --success: #00e676;
  --warning: #ffb300;
  --font-sans: 'Plus Jakarta Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 12px;
}

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

html, body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  font-family: var(--font-sans);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  max-width: 100vw;
  width: 100%;
}


/* Header */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: rgba(13, 17, 26, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--bg-card-border);
}

.logo-group {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-group a,
.logo-group a:visited,
.logo-group a:hover,
.logo-group a:active {
  color: inherit;
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo-symbol {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--primary), var(--accent-pink));
  color: #000;
  font-weight: 900;
  font-size: 1.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  box-shadow: 0 0 20px var(--primary-glow);
}

.logo-text h1 {
  color: #f8fafc;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin: 0;
}

.logo-text h1 span {
  color: var(--primary);
  text-shadow: 0 0 12px var(--primary-glow);
}

.logo-text .tagline {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}


.header-badges {
  display: flex;
  gap: 0.75rem;
}

.badge {
  background: #121826;
  border: 1px solid var(--bg-card-border);
  padding: 0.4rem 0.85rem;
  border-radius: 20px;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
}

.badge.online .dot {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
}

/* Studio Layout */
.studio-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1.5rem;
  padding: 1.25rem 1.75rem;
  flex: 1;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

@media (max-width: 1140px) {
  .studio-layout {
    grid-template-columns: 1fr;
    padding: 1rem 1rem;
    gap: 1.25rem;
  }
}

.studio-panel {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

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

.card-header h3 {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #e2e8f0;
}

/* Forms & Inputs */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

input, select, textarea {
  background: #090c14;
  border: 1px solid #1e293b;
  border-radius: 8px;
  color: #fff;
  padding: 0.65rem 0.85rem;
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 10px var(--primary-glow);
}

textarea#promptInput {
  resize: vertical;
  min-height: 110px;
  font-size: 0.88rem;
  line-height: 1.5;
}

.prompt-input-group {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.prompt-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.preset-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
}

.preset-selector select {
  flex: 1;
}

.ai-settings {
  background: #06080e;
  padding: 0.85rem;
  border-radius: 8px;
  border: 1px solid #161e2e;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.hidden {
  display: none !important;
}

/* Buttons */
.btn {
  background: var(--primary);
  color: #000;
  border: none;
  border-radius: 8px;
  padding: 0.75rem 1.25rem;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
  text-decoration: none;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), #00b4d8);
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.8rem;
}
.btn-text:hover {
  color: var(--primary);
}

.btn-small {
  background: #1a2233;
  color: var(--primary);
  border: 1px solid #28354d;
  padding: 0.35rem 0.75rem;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-small:hover {
  background: #222d44;
}

.render-action-bar {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.btn-render {
  width: 100%;
  max-width: 100%;
  padding: 0.95rem 1.25rem;
  background: linear-gradient(135deg, #00f2fe 0%, #ff007f 100%);
  color: #fff;
  border-radius: 10px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 20px var(--primary-glow);
  box-sizing: border-box;
}

.btn-render:hover {
  box-shadow: 0 6px 30px var(--accent-pink-glow);
  transform: translateY(-2px);
}

.btn-render .btn-text-main {
  font-size: 1.1rem;
  font-weight: 900;
  letter-spacing: 0.5px;
}

.btn-success {
  background: linear-gradient(135deg, #00e676, #00b0ff);
  color: #000;
  width: 100%;
  padding: 0.85rem;
}

/* Code Editor */
.full-width-code-card {
  grid-column: 1 / -1;
  width: 100%;
  padding: 0.85rem 1.25rem;
  transition: all 0.25s ease;
}

#codeEditorWrapper {
  width: 100%;
}

textarea#codeEditor {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.92rem;
  line-height: 1.6;
  background: #030509;
  color: #38bdf8;
  border: 1px solid #1e293b;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  width: 100%;
  height: 420px;
  resize: vertical;
  white-space: pre;
  tab-size: 2;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.7);
  outline: none;
}

textarea#codeEditor:focus {
  border-color: #00f2fe;
  box-shadow: 0 0 15px rgba(0, 242, 254, 0.2), inset 0 2px 10px rgba(0, 0, 0, 0.7);
}

/* Modalità Schermo Intero per Code Editor */
.code-card.expanded {
  position: fixed;
  inset: 0;
  z-index: 99999;
  border-radius: 0;
  border: none;
  background: rgba(4, 7, 15, 0.98);
  padding: 1.5rem 2rem;
  display: flex;
  flex-direction: column;
}

.code-card.expanded #codeEditorWrapper {
  flex: 1;
  display: flex !important;
  flex-direction: column;
}

.code-card.expanded textarea#codeEditor {
  flex: 1;
  height: 82vh !important;
  max-height: 85vh;
  font-size: 0.96rem;
}

/* Stage & Preview */
.stage-card {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.stage-card .card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.65rem;
}

.stage-viewport {
  position: relative;
  width: 100%;
  max-width: 100%;
  aspect-ratio: 16 / 9;
  min-height: 240px;
  max-height: 560px;
  background: #020306;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid #1a253a;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.7);
  transition: all 0.3s ease;
  box-sizing: border-box;
}

/* Modalità Ingrandita / Fullscreen */
.stage-viewport.expanded {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  max-height: 100vh;
  z-index: 99999;
  border-radius: 0;
  border: none;
  background: rgba(4, 6, 12, 0.96);
  padding: 1.5rem;
  box-shadow: none;
}

#previewFrame {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
  background: #000;
}

#liveSceneContainer, #liveCanvas, #liveSvg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.stage-status {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* Progress Card */
.progress-bar-container {
  width: 100%;
  height: 14px;
  background: #070a12;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid #182236;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--primary), var(--accent-pink), var(--primary));
  background-size: 200% 100%;
  border-radius: 8px;
  transition: width 0.35s ease;
  box-shadow: 0 0 12px var(--primary-glow);
}

.progress-bar-fill.active {
  animation: progressPulseGlow 1.8s linear infinite;
}

@keyframes progressPulseGlow {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.progress-percent {
  font-family: var(--font-mono);
  font-weight: 700;
  color: var(--primary);
}

.progress-status-msg {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* Video Result */
.video-container {
  width: 100%;
  max-width: 100%;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  border: 1px solid #1a253a;
  box-sizing: border-box;
}

.video-container video {
  width: 100%;
  max-width: 100%;
  max-height: 440px;
  display: block;
  object-fit: contain;
}

/* Storyboard Multi-Scene Cards */
.scenes-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-height: 560px;
  overflow-y: auto;
  padding-right: 0.35rem;
}

.scene-item {
  background: #090d16;
  border: 1px solid #1a2538;
  border-left: 4px solid var(--primary);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: all 0.2s ease;
}

.scene-item:hover {
  background: #0d1424;
  border-color: #273956;
}

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

.scene-item-badge {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.scene-item-duration {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--text-muted);
  background: #05070d;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

.scene-item-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #fff;
}

.scene-item-desc {
  font-size: 0.8rem;
  color: #94a3b8;
  line-height: 1.4;
}

.scene-bg-ctrl {
  margin-top: 0.65rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.scene-bg-ctrl label:hover {
  background: rgba(0, 242, 254, 0.2) !important;
}

/* Scene Link Control (Nexthcast) */
.scene-link-ctrl {
  margin-top: 0.65rem;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
}

.scene-link-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.scene-link-label {
  font-size: 0.74rem;
  color: #94a3b8;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.scene-link-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.scene-link-view-btn {
  font-size: 0.72rem;
  color: #38bdf8;
  text-decoration: none;
  padding: 2px 8px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.3);
  border-radius: 5px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
  font-weight: 600;
}

.scene-link-view-btn:hover {
  background: rgba(56, 189, 248, 0.25);
  color: #7dd3fc;
  box-shadow: 0 0 8px rgba(56, 189, 248, 0.3);
}

.scene-link-remove-btn {
  font-size: 0.72rem;
  color: #f43f5e;
  background: rgba(244, 63, 94, 0.1);
  border: 1px solid rgba(244, 63, 94, 0.25);
  border-radius: 5px;
  padding: 2px 7px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  transition: all 0.2s ease;
  font-weight: 600;
}

.scene-link-remove-btn:hover {
  background: rgba(244, 63, 94, 0.25);
  color: #fb7185;
}

.scene-link-input-group {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.scene-link-input {
  flex: 1;
  font-size: 0.75rem;
  padding: 5px 8px;
  background: #07090f;
  border: 1px solid #1e293b;
  border-radius: 6px;
  color: #e2e8f0;
  font-family: inherit;
  transition: border-color 0.2s ease;
}

.scene-link-input:focus {
  outline: none;
  border-color: #00f2fe;
}

.scene-link-save-btn {
  font-size: 0.72rem;
  background: rgba(0, 242, 254, 0.12);
  border: 1px solid rgba(0, 242, 254, 0.3);
  color: var(--primary);
  padding: 5px 10px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.scene-link-save-btn:hover {
  background: rgba(0, 242, 254, 0.25);
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.25);
}


/* Main App Wrapper */
.main-app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  width: 100%;
}

.main-app-container.hidden {
  display: none !important;
}

/* Auth Modal & File Dropzone (Unica schermata iniziale) */
.auth-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: var(--bg-dark);
  z-index: 999999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-overlay.hidden {
  display: none !important;
}

.auth-card {
  background: #0d121e;
  border: 1px solid #1f2c42;
  border-radius: 16px;
  padding: 2.5rem 2rem;
  max-width: 460px;
  width: 100%;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.9);
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.85rem;
  margin-bottom: 0.25rem;
}

.auth-brand .brand-text {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: #fff;
}

.auth-brand .brand-text span {
  color: var(--primary);
  text-shadow: 0 0 12px var(--primary-glow);
}

.auth-icon {
  font-size: 3rem;
  margin-bottom: -0.5rem;
}

.auth-card h2 {
  font-size: 1.5rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.5px;
}

.auth-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.token-dropzone {
  border: 2px dashed #24344d;
  background: #070a12;
  border-radius: 12px;
  padding: 2rem 1.5rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  transition: all 0.2s ease;
}

.token-dropzone:hover, .token-dropzone.dragover {
  border-color: var(--primary);
  background: #0a1120;
  box-shadow: 0 0 15px var(--primary-glow);
}

.dropzone-icon {
  font-size: 2.2rem;
}

.dropzone-text {
  font-size: 0.95rem;
  color: #e2e8f0;
}

.dropzone-sub {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.auth-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
}

/* Regole per Modali e Archivio Storico */
.hidden {
  display: none !important;
}

.history-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 15, 0.88);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  animation: modalFadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalFadeIn {
  from { opacity: 0; transform: scale(0.98); }
  to { opacity: 1; transform: scale(1); }
}

.history-modal-content {
  background: #090e1a;
  border: 1px solid rgba(0, 242, 254, 0.25);
  border-radius: 16px;
  box-shadow: 0 25px 60px rgba(0, 0, 0, 0.85), 0 0 35px rgba(0, 242, 254, 0.12);
  width: 100%;
  max-width: 960px;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.history-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(15, 23, 42, 0.5);
}

.history-modal-close {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  color: #94a3b8;
  font-size: 1.25rem;
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.history-modal-close:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.4);
  color: #f87171;
}

.history-modal-body {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  flex: 1;
}

.history-list-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.history-card {
  background: rgba(13, 19, 34, 0.85);
  border: 1px solid #1e293b;
  border-radius: 12px;
  padding: 1.15rem 1.35rem;
  transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.history-card:hover {
  border-color: rgba(0, 242, 254, 0.45) !important;
  box-shadow: 0 6px 24px rgba(0, 242, 254, 0.1);
  transform: translateY(-1px);
}

.history-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.history-card-title {
  font-size: 1.02rem;
  font-weight: 700;
  color: #f8fafc;
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.history-card-date {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 3px;
}

.history-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.history-badge {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 600;
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid #1e293b;
  color: #94a3b8;
}

.history-badge.gpu {
  background: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.35);
  color: #34d399;
}

.history-badge.spaces {
  background: rgba(0, 242, 254, 0.1);
  border-color: rgba(0, 242, 254, 0.3);
  color: #38bdf8;
}

.history-badge.res {
  background: rgba(168, 85, 247, 0.12);
  border-color: rgba(168, 85, 247, 0.35);
  color: #c084fc;
}

.history-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  padding-top: 0.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
}

.btn-history-action {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.18s ease;
  border: 1px solid #1e293b;
  background: #111827;
  color: #e2e8f0;
  text-decoration: none;
}

.btn-history-action:hover {
  background: #1f2937;
  border-color: #38bdf8;
  color: #38bdf8;
}

.btn-history-action.primary {
  background: rgba(0, 242, 254, 0.15);
  border-color: rgba(0, 242, 254, 0.4);
  color: #38bdf8;
}

.btn-history-action.primary:hover {
  background: rgba(0, 242, 254, 0.28);
  border-color: #00f2fe;
}

.btn-history-action.success {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}

.btn-history-action.success:hover {
  background: rgba(16, 185, 129, 0.28);
  border-color: #10b981;
}

.btn-history-action.danger {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
  margin-left: auto;
}

.btn-history-action.danger:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: #ef4444;
}

.history-links-preview {
  margin-top: 4px;
  padding: 6px 10px;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 6px;
  border: 1px dashed rgba(255, 255, 255, 0.08);
  font-size: 0.74rem;
  color: #94a3b8;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.history-links-preview a {
  color: #38bdf8;
  text-decoration: none;
}

.history-links-preview a:hover {
  text-decoration: underline;
}

/* =====================================================
   RESPONSIVE DESIGN & MENU HAMBURGER (Mobile / Tablet)
   ===================================================== */

/* Hamburger Button (Default: nascosto su Desktop) */
.hamburger-btn {
  display: none;
  flex-direction: column;
  justify-content: space-between;
  width: 40px;
  height: 40px;
  background: rgba(18, 24, 38, 0.85);
  border: 1px solid rgba(0, 242, 254, 0.25);
  border-radius: 8px;
  padding: 10px 8px;
  cursor: pointer;
  z-index: 102;
  transition: all 0.25s ease;
}

.hamburger-btn:hover {
  background: rgba(26, 34, 51, 0.95);
  border-color: var(--primary);
  box-shadow: 0 0 12px var(--primary-glow);
}

.hamburger-bar {
  display: block;
  width: 100%;
  height: 2px;
  background: #38bdf8;
  border-radius: 2px;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: center;
}

/* Animazione Hamburger -> X */
.hamburger-btn.active .hamburger-bar:nth-child(1) {
  transform: translateY(7px) rotate(45deg);
  background: var(--primary);
}

.hamburger-btn.active .hamburger-bar:nth-child(2) {
  opacity: 0;
  transform: scaleX(0);
}

.hamburger-btn.active .hamburger-bar:nth-child(3) {
  transform: translateY(-7px) rotate(-45deg);
  background: var(--primary);
}

/* Intestazione Mobile Drawer (Nascosto su Desktop) */
.mobile-nav-header {
  display: none;
}

/* Backdrop Overlay per Drawer Mobile */
.nav-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 4, 10, 0.75);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 99;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.nav-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}

/* Blocco scroll quando menu aperto */
body.nav-open {
  overflow: hidden;
}

/* =====================================================
   BREAKPOINT: Schermi Tablet & Mobile (<= 860px)
   ===================================================== */
@media (max-width: 860px) {
  .app-header {
    padding: 0.85rem 1.25rem;
    position: relative;
    z-index: 90;
  }

  .logo-text h1 {
    font-size: 1.15rem;
  }

  .logo-text .tagline {
    display: none;
  }

  .logo-symbol {
    width: 38px;
    height: 38px;
    font-size: 1.1rem;
  }

  /* Mostra Hamburger */
  .hamburger-btn {
    display: flex;
  }

  /* Drawer Laterale Navigazione */
  .header-badges {
    position: fixed;
    top: 0;
    right: 0;
    width: min(320px, 86vw);
    height: 100vh;
    height: 100dvh;
    background: #090e1a;
    border-left: 1px solid rgba(0, 242, 254, 0.25);
    box-shadow: -15px 0 45px rgba(0, 0, 0, 0.9), 0 0 30px rgba(0, 242, 254, 0.08);
    padding: 1.5rem 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 1rem;
    z-index: 101;
    overflow-y: auto;
    overflow-x: hidden;
    transform: translateX(105%);
    visibility: hidden;
    pointer-events: none;
    transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1), visibility 0.32s;
  }

  .header-badges.open {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
  }


  /* Header del Drawer */
  .mobile-nav-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 0.85rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  }

  .mobile-nav-title {
    font-size: 1rem;
    font-weight: 800;
    color: #f8fafc;
    display: flex;
    align-items: center;
    gap: 6px;
    background: linear-gradient(135deg, var(--primary), var(--accent-pink));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }

  .mobile-nav-close {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    transition: all 0.2s ease;
  }

  .mobile-nav-close:hover {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border-color: rgba(239, 68, 68, 0.4);
  }

  /* Elementi nel Drawer */
  .header-badges .badge {
    width: 100%;
    justify-content: flex-start;
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-size: 0.85rem;
  }

  .btn-history-nav {
    width: 100%;
    justify-content: center;
    padding: 0.85rem 1rem !important;
    border-radius: 10px !important;
    font-size: 0.88rem !important;
  }

  .btn-logout-nav {
    width: 100%;
    text-align: center;
    margin-left: 0 !important;
    margin-top: auto;
    padding: 0.85rem 1rem;
    background: rgba(255, 0, 127, 0.1);
    border: 1px solid rgba(255, 0, 127, 0.3);
    border-radius: 10px;
    font-size: 0.88rem !important;
    font-weight: 700;
    transition: all 0.2s ease;
  }

  .btn-logout-nav:hover {
    background: rgba(255, 0, 127, 0.25);
    border-color: var(--accent-pink);
  }

  /* Studio Layout su Schermi Piccoli */
  .studio-layout {
    grid-template-columns: 1fr;
    padding: 1rem 1rem;
    gap: 1.25rem;
  }

  /* Viewport Anteprima Adattivo */
  .stage-viewport {
    min-height: 220px !important;
    max-height: 55vh !important;
  }
}

/* =====================================================
   BREAKPOINT: Mobile Smartphone (<= 600px)
   ===================================================== */
@media (max-width: 600px) {
  .app-header {
    padding: 0.75rem 0.85rem;
  }

  .logo-group {
    gap: 0.65rem;
  }

  .logo-symbol {
    width: 34px;
    height: 34px;
    font-size: 0.95rem;
  }

  .logo-text h1 {
    font-size: 1.05rem;
  }

  .studio-layout {
    padding: 0.75rem 0.65rem;
    gap: 1rem;
  }

  .card {
    padding: 1rem 0.85rem;
    gap: 0.85rem;
  }

  .card-header h3 {
    font-size: 0.92rem;
  }

  .form-grid, .form-row {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  .prompt-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .preset-selector {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .preset-selector select {
    width: 100%;
  }

  #generateAiBtn {
    width: 100%;
    padding: 0.85rem 1rem;
  }

  .podcast-hosts-panel > div:first-child {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 6px;
  }

  #hostsSelectorsContainer {
    grid-template-columns: 1fr 1fr !important;
  }

  .btn-render {
    padding: 0.85rem 1rem;
    font-size: 0.85rem;
  }

  .btn-render .btn-text-main {
    letter-spacing: 0.5px;
  }

  /* Code Card Header */
  #toggleCodeCardHeader {
    flex-direction: column;
    align-items: flex-start !important;
    gap: 0.65rem;
  }

  .editor-buttons {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }

  .editor-buttons button {
    flex: 1 1 auto;
    text-align: center;
  }

  textarea#codeEditor {
    height: 280px;
    font-size: 0.82rem;
    padding: 0.75rem;
  }

  /* Result Actions */
  .result-actions {
    flex-direction: column;
    align-items: stretch !important;
    gap: 0.65rem;
  }

  .result-actions > a,
  .result-actions > button {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  /* Storyboard Scenes */
  .scene-item {
    padding: 0.65rem 0.75rem;
  }

  .scene-item-header {
    flex-wrap: wrap;
    gap: 4px;
  }

  .scene-link-row {
    flex-direction: column;
    align-items: stretch !important;
  }

  .scene-link-input {
    width: 100%;
  }

  .scene-link-save-btn {
    width: 100%;
    justify-content: center;
  }

  /* Modali su Mobile */
  .history-modal-overlay {
    padding: 0.5rem;
  }

  .history-modal-content {
    max-height: 94vh;
    border-radius: 12px;
  }

  .history-modal-header {
    padding: 1rem 0.85rem;
  }

  .history-modal-body {
    padding: 0.85rem 0.65rem;
  }

  .history-card {
    padding: 0.85rem 0.75rem;
  }

  .history-card-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .history-card-actions {
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }

  .btn-history-action {
    width: 100%;
    justify-content: center;
    padding: 8px 10px;
  }

  .btn-history-action.danger {
    margin-left: 0;
  }

  /* Auth Card su piccoli display */
  .auth-card {
    padding: 1.75rem 1.25rem;
  }

  .token-dropzone {
    padding: 1.5rem 1rem;
  }
}

/* =====================================================
   MODAL PRICING & MEMBERSHIP STRIPE
   ===================================================== */
.pricing-modal-content {
  background: #080c16;
  border: 1px solid rgba(0, 242, 254, 0.35);
  box-shadow: 0 25px 70px rgba(0, 0, 0, 0.9), 0 0 40px rgba(0, 242, 254, 0.15);
}

.pricing-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.25rem;
  align-items: stretch;
}

@media (max-width: 860px) {
  .pricing-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
}

.pricing-card {
  background: rgba(13, 18, 30, 0.85);
  border: 1px solid #1e293b;
  border-radius: 14px;
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.pricing-card:hover {
  transform: translateY(-3px);
  border-color: rgba(0, 242, 254, 0.4);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
}

.pricing-card.featured {
  background: linear-gradient(180deg, rgba(23, 25, 48, 0.95), rgba(12, 17, 33, 0.95));
  border: 2px solid rgba(168, 85, 247, 0.6);
  box-shadow: 0 0 35px rgba(168, 85, 247, 0.25);
  transform: scale(1.02);
}

.pricing-card.featured:hover {
  transform: scale(1.02) translateY(-3px);
  border-color: #c084fc;
  box-shadow: 0 12px 40px rgba(168, 85, 247, 0.4);
}

.featured-ribbon {
  position: absolute;
  top: -12px;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  padding: 4px 14px;
  border-radius: 20px;
  letter-spacing: 0.5px;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.pricing-badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
  display: inline-block;
  margin-bottom: 0.75rem;
  text-transform: uppercase;
}

.pricing-badge.free {
  background: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.pricing-badge.pro {
  background: rgba(0, 242, 254, 0.15);
  color: #38bdf8;
  border: 1px solid rgba(0, 242, 254, 0.4);
}

.pricing-badge.annual {
  background: rgba(168, 85, 247, 0.2);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.5);
}

.pricing-title {
  font-size: 1.15rem;
  font-weight: 800;
  color: #f8fafc;
  margin-bottom: 0.5rem;
}

.pricing-price {
  font-size: 2rem;
  font-weight: 900;
  color: #fff;
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 0.5rem;
}

.pricing-period {
  font-size: 0.85rem;
  color: #94a3b8;
  font-weight: 600;
}

.pricing-desc {
  font-size: 0.78rem;
  color: #94a3b8;
  line-height: 1.45;
  margin-bottom: 1.25rem;
  min-height: 38px;
}

.pricing-features {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  font-size: 0.82rem;
  color: #cbd5e1;
}

.pricing-features li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  line-height: 1.4;
}

.pricing-features .check {
  color: #10b981;
  font-weight: 800;
}

.pricing-features .check.glow {
  color: #38bdf8;
  text-shadow: 0 0 8px rgba(56, 189, 248, 0.5);
}

.pricing-features .cross {
  color: #ef4444;
  font-weight: 800;
}

.pricing-status-pill {
  width: 100%;
  text-align: center;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
}

.pricing-status-pill.current {
  background: rgba(148, 163, 184, 0.1);
  color: #94a3b8;
  border: 1px dashed rgba(148, 163, 184, 0.3);
}

.pricing-status-pill.active-member {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.btn-checkout {
  width: 100%;
  padding: 0.85rem 1rem;
  font-size: 0.88rem;
  font-weight: 700;
  border-radius: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-annual {
  background: linear-gradient(135deg, #a855f7 0%, #ec4899 100%);
  color: #fff;
  border: none;
  box-shadow: 0 4px 18px rgba(168, 85, 247, 0.35);
}

.btn-annual:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 24px rgba(168, 85, 247, 0.55);
}

/* =====================================================
   STILI PER GESTIONE LINK INTERATTIVI PER PAGINA (INTERVACTION)
   ===================================================== */
.page-link-card {
  background: rgba(13, 19, 34, 0.95);
  border: 1px solid #1e293b;
  border-radius: 12px;
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  transition: all 0.2s ease;
}

.page-link-card:hover {
  border-color: rgba(0, 242, 254, 0.4);
}

.page-link-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.page-link-title {
  font-size: 0.95rem;
  font-weight: 700;
  color: #f8fafc;
  display: flex;
  align-items: center;
  gap: 8px;
}

.page-link-time {
  font-size: 0.75rem;
  padding: 2px 7px;
  border-radius: 5px;
  background: rgba(168, 85, 247, 0.15);
  color: #c084fc;
  border: 1px solid rgba(168, 85, 247, 0.35);
  font-weight: 600;
}

.page-link-status {
  font-size: 0.74rem;
  padding: 3px 8px;
  border-radius: 6px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.page-link-status.synced {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.page-link-status.pending {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

.page-link-status.empty {
  background: rgba(148, 163, 184, 0.1);
  color: #94a3b8;
  border: 1px dashed rgba(148, 163, 184, 0.25);
}

.page-link-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.page-link-inputs-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 768px) {
  .page-link-inputs-grid {
    grid-template-columns: 1fr;
  }
}

.page-link-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.page-link-field-label {
  font-size: 0.74rem;
  color: #94a3b8;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 4px;
}

.page-link-text-input,
.page-link-input {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: #060911;
  border: 1px solid #1e293b;
  border-radius: 8px;
  color: #f1f5f9;
  font-size: 0.82rem;
  font-family: inherit;
  transition: all 0.2s ease;
}

.page-link-text-input:focus,
.page-link-input:focus {
  outline: none;
  border-color: #00f2fe;
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.25);
}

.page-link-url-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.page-link-url-row .page-link-input {
  flex: 1;
}

.page-link-actions-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.04);
}

.btn-link-action {
  padding: 0.5rem 0.9rem;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  transition: all 0.18s ease;
  border: 1px solid transparent;
}

.btn-link-action.add {
  background: rgba(0, 242, 254, 0.15);
  border-color: rgba(0, 242, 254, 0.4);
  color: #38bdf8;
}

.btn-link-action.add:hover {
  background: rgba(0, 242, 254, 0.28);
  border-color: #00f2fe;
}

.btn-link-action.save {
  background: rgba(16, 185, 129, 0.15);
  border-color: rgba(16, 185, 129, 0.4);
  color: #34d399;
}

.btn-link-action.save:hover {
  background: rgba(16, 185, 129, 0.28);
  border-color: #10b981;
}

.btn-link-action.delete {
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.3);
  color: #f87171;
}

.btn-link-action.delete:hover {
  background: rgba(239, 68, 68, 0.25);
  border-color: #ef4444;
}

.btn-link-action.test {
  background: #1e293b;
  border-color: #334155;
  color: #94a3b8;
  text-decoration: none;
}

.btn-link-action.test:hover {
  color: #f1f5f9;
  border-color: #64748b;
}

/* ==========================================================================
   Multilingual Language Switcher & RTL Support
   ========================================================================== */
.lang-selector-wrapper {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid rgba(0, 242, 254, 0.25);
  border-radius: 8px;
  padding: 3px 8px;
  transition: all 0.2s ease;
}

.lang-selector-wrapper:hover,
.lang-selector-wrapper:focus-within {
  border-color: rgba(0, 242, 254, 0.6);
  box-shadow: 0 0 10px rgba(0, 242, 254, 0.15);
}

.lang-selector-wrapper .lang-icon {
  font-size: 0.85rem;
  user-select: none;
}

.lang-selector-select {
  background: transparent;
  border: none;
  color: #38bdf8;
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  outline: none;
  padding: 2px 2px;
}

.lang-selector-select option {
  background: #0b1120;
  color: #e2e8f0;
  font-weight: 600;
  padding: 6px 10px;
}

/* RTL Support (Arabic) */
html[dir="rtl"], body[dir="rtl"] {
  direction: rtl;
  text-align: right;
}

[dir="rtl"] .app-header {
  flex-direction: row-reverse;
}

[dir="rtl"] .header-badges {
  flex-direction: row-reverse;
}

@media (max-width: 860px) {
  [dir="rtl"] .header-badges {
    right: auto;
    left: 0;
    border-left: none;
    border-right: 1px solid rgba(0, 242, 254, 0.25);
    box-shadow: 15px 0 45px rgba(0, 0, 0, 0.9), 0 0 30px rgba(0, 242, 254, 0.08);
    transform: translateX(-105%);
    flex-direction: column;
  }
  [dir="rtl"] .header-badges.open {
    transform: translateX(0);
  }
}


[dir="rtl"] .logo-group {
  flex-direction: row-reverse;
}

[dir="rtl"] .card-header {
  flex-direction: row-reverse;
}

[dir="rtl"] .history-modal-header {
  flex-direction: row-reverse;
}

[dir="rtl"] .pricing-card ul {
  text-align: right;
  padding-right: 0;
}

[dir="rtl"] .pricing-features li {
  flex-direction: row-reverse;
}


