/* ============================================================
   NarraSite — Base Styles
   CSS custom properties are injected by /theme/:tenantId
   Defaults here are the fallback (warm agriturismo palette)
   ============================================================ */

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

:root {
  --color-primary:    #6B4F2A;
  --color-secondary:  #3E6B35;
  --color-accent:     #C17F2A;
  --color-bg:         #F9F4EE;
  --color-surface:    #FFFFFF;
  --color-text:       #1C1612;
  --color-text-muted: #7A6A56;
  --color-border:     #E4D9C8;
  --font-heading:     "Playfair Display", Georgia, serif;
  --font-body:        "Inter", system-ui, sans-serif;
  --radius-md:        0.5rem;
  --radius-lg:        1rem;
  --shadow-md:        0 4px 12px rgba(0,0,0,0.08);
  --shadow-lg:        0 12px 40px rgba(0,0,0,0.13);
  /* --color-bg-gradient: fallback is defined in server.js or index.html if needed -- */
  --story-radius:     50% 50% 30% 70% / 50% 50% 70% 30%;
  --story-clip-path:  none;
  --anim-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  --anim-smooth: cubic-bezier(0.4, 0, 0.2, 1);
  --anim-duration-fast: 0.2s;
  --anim-duration-normal: 0.35s;
  --anim-duration-slow: 0.6s;
  --radius-xl: 1.5rem;
  --radius-full: 9999px;
  --shadow-xl: 0 20px 60px rgba(0,0,0,0.15);
  --blur-glass: blur(12px);
  --max-width: 700px;
  --topbar-h: 60px;
  --footer-safe: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-bg: #0f0f0f;
    --color-surface: #1a1a2e;
    --color-text: #e8e8e8;
    --color-text-muted: #8a8a9a;
    --color-border: #2a2a3e;
    --shadow-md: 0 4px 12px rgba(0,0,0,0.3);
    --shadow-lg: 0 12px 40px rgba(0,0,0,0.4);
  }
}

html, body, #root {
  height: 100%; min-height: 100vh;
  font-family: var(--font-body);
  color: var(--color-text);
  background: var(--color-bg);
  transition: background 0.3s ease;
  -webkit-font-smoothing: antialiased;
}

/* ── Animations ──────────────────────────────────────── */
@keyframes slideInUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-primary) 20%, transparent); }
  50%      { box-shadow: 0 0 0 8px color-mix(in srgb, var(--color-primary) 0%, transparent); }
}
@keyframes typingWave {
  0%, 60%, 100% { transform: translateY(0); }
  30%           { transform: translateY(-6px); }
}

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(18px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
  0%,100% { opacity: 1; } 50% { opacity: 0.45; }
}
@keyframes shimmer {
  0%   { background-position: -400px 0; }
  100% { background-position:  400px 0; }
}
@keyframes factFade {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes sway {
  0%,100% { transform: rotate(-4deg); }
  50%      { transform: rotate(4deg); }
}
@keyframes dotPulse {
  0%,80%,100% { transform: scale(0); opacity: 0; }
  40%          { transform: scale(1); opacity: 1; }
}

/* ── Fullscreen loader ───────────────────────────────── */
.ns-loader {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: #1a2e1e; flex-direction: column; gap: 1rem;
}
.ns-loader__icon { font-size: 2.5rem; animation: sway 3s ease-in-out infinite; }
.ns-loader__text { font-family: var(--font-heading); color: rgba(255,255,255,0.8); font-size: 1.05rem; }



/* ── Chips ───────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; border: none; cursor: pointer;
  font-family: var(--font-body); font-size: .855rem; border-radius: 9999px;
  transition: all .18s; outline: none; -webkit-tap-highlight-color: transparent;
}


.chip--reply { 
  background: linear-gradient(135deg, var(--color-surface), var(--color-bg));
  border: 1.5px solid var(--color-primary);
  color: var(--color-primary);
  font-weight: 600;
  padding: 0.55rem 1.2rem;
  border-radius: var(--radius-full);
  transition: all var(--anim-duration-fast) var(--anim-spring);
}
.chip--reply:hover {
  transform: translateY(-2px) scale(1.03);
  box-shadow: 0 4px 16px color-mix(in srgb, var(--color-primary) 25%, transparent);
}
.chip--reply:disabled { opacity: .45; cursor: default; }
.chip--reply:active {
  transform: scale(0.97);
}

/* ── Chat layout ─────────────────────────────────────── */
.chat {
  display: flex; 
  flex-direction: column;
  height: 100vh;
  height: 100dvh;  /* dynamic viewport height: fondamentale per safari mobile */
  position: fixed; /* blocca il container alla finestra, evitando che il body scrolli off-screen */
  inset: 0;
  background: var(--color-bg);
}

/* ── Topbar ──────────────────────────────────────────── */
.topbar {
  flex-shrink: 0;
  height: 60px;
  position: relative;
  transition: height 0.4s var(--anim-smooth), background-color 0.4s var(--anim-smooth);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 1.25rem;
  background: color-mix(in srgb, var(--color-surface) 85%, transparent);
  backdrop-filter: var(--blur-glass);
  -webkit-backdrop-filter: var(--blur-glass);
  border-bottom: 1px solid var(--color-border);
  box-shadow: 0 1px 6px rgba(0,0,0,.05); z-index: 10;
}
.topbar--start {
  height: 110px;
}
.topbar__brand { 
  font-family: var(--font-heading); 
  font-weight: 600; 
  font-size: 0.95rem; 
  color: var(--color-primary);
  flex-shrink: 0;
  z-index: 2;
}
.topbar__actions {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  flex-shrink: 0;
  z-index: 2;
}
@media (min-width: 600px) {
  .topbar__brand {
    position: absolute;
    left: 1.25rem;
  }
  .topbar__actions {
    position: absolute;
    right: 1.25rem;
  }
}
@media (max-width: 600px) {
  .topbar__brand-name {
    display: none;
  }
}
.topbar__topic {
  display: flex; align-items: center; gap: .45rem;
  background: var(--color-bg); border: 1px solid var(--color-border);
  border-radius: 9999px; padding: .22rem .7rem .22rem .9rem;
}
.topbar__label { font-size: .78rem; font-weight: 500; color: var(--color-text-muted); max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar__clear { background: none; border: none; cursor: pointer; font-size: .7rem; color: var(--color-text-muted); padding: 0; line-height: 1; transition: color .15s; }
.topbar__clear:hover { color: var(--color-text); }

/* ── Chat list ───────────────────────────────────────── */
.chat__list {
  flex: 1; overflow-y: auto;
  padding: 1.5rem 1rem; display: flex; flex-direction: column; gap: 2rem;
}
.chat__list::-webkit-scrollbar { width: 4px; }
.chat__list::-webkit-scrollbar-thumb { background: var(--color-border); border-radius: 2px; }

/* ── Chat footer ─────────────────────────────────────── */
.chat__footer {
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 20;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding: .75rem 1rem calc(1rem + var(--footer-safe));
  display: flex; flex-direction: column; gap: .7rem;
}

/* ── Conversation entry ──────────────────────────────── */
.entry {
  display: flex; flex-direction: column; gap: .7rem;
  max-width: var(--max-width); width: 100%; align-self: center;
  animation: fadeInUp .35s ease both;
}
.entry__q {
  align-self: flex-end; display: flex; align-items: center; gap: .4rem;
  background: var(--color-primary); color: #fff;
  padding: .6rem 1rem; border-radius: 20px;
  max-width: 80%; font-size: .9rem;
  animation: slideInRight var(--anim-duration-normal) var(--anim-spring) both;
}
.entry__cached { font-size: .65rem; opacity: .65; cursor: help; flex-shrink: 0; }

/* ── Cards ───────────────────────────────────────────── */
.card {
  background: var(--color-surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); border: 1px solid var(--color-border); overflow: hidden;
  animation: slideInUp var(--anim-duration-normal) var(--anim-spring) both;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  flex: 1;
  min-width: 0;
  word-break: break-word;
  overflow-wrap: anywhere;
}

/* ── Welcome Card ────────────────────────────────────── */
.card--welcome {
  background: linear-gradient(135deg, #1a2e1e 0%, #2d1f0e 50%, #1a2e1e 100%);
  color: #fff !important;
  padding: 0;
  text-align: center;
  position: relative;
  overflow: hidden;
}

.welcome-overlay {
  position: absolute;
  inset: 0;
  background: #000;
  z-index: 0;
  pointer-events: none;
}

.welcome-content {
  position: relative;
  z-index: 1;
  padding: 2rem;
}

.welcome-brand {
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.welcome-logo {
  width: 80px; height: 80px; border-radius: 50%;
  background: #fff; padding: 10px; object-fit: contain;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
}
.welcome-name {
  font-family: var(--font-heading); font-size: 1.3rem;
  letter-spacing: 0.05em; text-transform: uppercase;
  color: rgba(255,255,255,0.9);
}
.welcome-motto {
  font-size: 0.85rem; color: rgba(255,255,255,0.6); font-style: italic;
}
.welcome-hook {
  font-family: var(--font-heading); font-size: 1.6rem;
  font-style: italic; line-height: 1.3;
  margin: 1rem 0 1.5rem;
  color: #fff !important; text-shadow: 0 2px 12px rgba(0,0,0,0.3);
}
.card--welcome .chip--reply {
  background: rgba(255,255,255,0.12) !important;
  border-color: rgba(255,255,255,0.3) !important;
  color: #fff !important;
}
.card--welcome .chip--reply:hover {
  background: rgba(255,255,255,0.25) !important;
}
.welcome-warning {
  font-size: 0.72rem; color: rgba(255,255,255,0.4);
  margin-top: 1rem;
}
.card__header { padding: 1.25rem 1.5rem 0; }
.card__title  { font-family: var(--font-heading); font-size: 1.4rem; font-weight: 600; color: var(--color-text); line-height: 1.2; }
.card__subtitle { font-size: .9rem; color: var(--color-text-muted); margin-top: .3rem; }
.card__body   { padding: 1rem 1.5rem; font-size: .95rem; line-height: 1.65; color: var(--color-text); }
.card__footer { padding: 0 1.5rem 1.25rem; display: flex; flex-direction: column; gap: .75rem; }

/* text-hero */
.card--hero .card__img { width: 100%; height: 220px; object-fit: cover; display: block; }

/* text-grid */
.card--grid .card__grid {
  display: grid; gap: 0;
  grid-template-columns: 1fr;
}
@media (min-width: 560px) {
  .card--grid .card__grid { grid-template-columns: 1fr 1fr; }
  .card--grid .card__img  { height: 100%; min-height: 180px; object-fit: cover; }
}

/* steps */
.card__steps { list-style: none; padding: .5rem 1.5rem 0; display: flex; flex-direction: column; gap: .75rem; }
.card__step  { display: flex; align-items: flex-start; gap: .85rem; font-size: .92rem; }
.card__step-n {
  flex-shrink: 0; width: 1.75rem; height: 1.75rem; border-radius: 50%;
  background: var(--color-primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem; font-weight: 600; margin-top: .05rem;
}

/* full-media */
.card--media { position: relative; min-height: 260px; }
.card--media .card__img { width: 100%; height: 260px; object-fit: cover; display: block; }
.card--media .card__overlay {
  position: absolute; inset: 0; padding: 1.5rem;
  background: linear-gradient(to top, rgba(0,0,0,.75) 0%, rgba(0,0,0,.1) 60%);
  display: flex; flex-direction: column; justify-content: flex-end; gap: .6rem;
}
.card--media .card__title  { color: #fff; }
.card--media .card__body   { padding: 0; color: rgba(255,255,255,.88); font-size: .9rem; }

/* links */
.card__links { list-style: none; padding: 0 1.5rem; display: flex; flex-direction: column; gap: .35rem; }
.card__links a { color: var(--color-secondary); font-size: .88rem; text-decoration: none; font-weight: 500; }
.card__links a:hover { text-decoration: underline; }

/* CTA button */
.card__cta {
  display: inline-flex; align-items: center; gap: .4rem;
  background: var(--color-primary); color: #fff;
  padding: .65rem 1.4rem; border-radius: 9999px;
  font-size: .88rem; font-weight: 600; text-decoration: none;
  border: none; cursor: pointer; transition: all .18s; align-self: flex-start;
}
.card__cta:hover { background: var(--color-accent); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(0,0,0,.18); }

/* ── Loading card (shimmer + facts) ─────────────────── */
.card--loading { padding: 1.5rem; display: flex; flex-direction: column; gap: 1rem; min-height: 180px; }
.shimmer {
  background: linear-gradient(90deg, var(--color-border) 25%, var(--color-surface) 50%, var(--color-border) 75%);
  background-size: 400px 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--radius-md);
}
.shimmer--title { height: 1.6rem; width: 60%; }
.shimmer--line  { height: 1rem; }
.shimmer--short { width: 75%; }

.loading-fact {
  margin-top: .5rem; display: flex; align-items: flex-start; gap: .6rem;
  padding: .75rem 1rem; background: var(--color-bg);
  border-radius: var(--radius-md); border: 1px solid var(--color-border);
  animation: factFade .5s ease both;
}
.loading-fact__icon { font-size: 1rem; flex-shrink: 0; }
.loading-fact__text { font-size: .82rem; color: var(--color-text-muted); line-height: 1.5; font-style: italic; }

/* ── Status bar (SSE progress messages) ─────────────── */
.status-bar {
  display: flex; align-items: center; gap: .45rem;
  padding: .25rem .1rem;
  animation: factFade .3s ease both;
  transition: opacity 0.6s ease-out;
}
.status-bar__text {
  font-size: .72rem; color: var(--color-text-muted);
  font-family: var(--font-body); letter-spacing: .01em;
  opacity: .75;
}
.status-bar__dots {
  display: inline-flex; align-items: center; gap: 3px; flex-shrink: 0;
}
.status-bar__dots span {
  display: inline-block; width: 4px; height: 4px;
  border-radius: 50%; background: var(--color-text-muted); opacity: .5;
  animation: dotPulse 1.4s ease-in-out infinite;
}
.status-bar__dots span:nth-child(2) { animation-delay: .2s; }
.status-bar__dots span:nth-child(3) { animation-delay: .4s; }

/* ── Suggested replies ───────────────────────────────── */
.replies { 
  display: flex; gap: .6rem; 
  flex-wrap: wrap; 
  width: 100%;
  box-sizing: border-box;
}

/* ── Input bar ───────────────────────────────────────── */
.inputbar {
  display: flex; gap: 0;
  background: var(--color-bg); border: 1.5px solid var(--color-border);
  border-radius: var(--radius-full); overflow: hidden; transition: border-color .18s;
  height: 48px;
}
.inputbar:focus-within {
  border-color: var(--color-primary);
  animation: pulseGlow 2s infinite;
}
.inputbar__field {
  flex: 1; padding: .75rem 1.1rem; background: transparent;
  border: none; outline: none; font-family: var(--font-body); font-size: .95rem; color: var(--color-text);
}
.inputbar__field::placeholder { color: var(--color-text-muted); }
.inputbar__send {
  padding: .75rem 1.1rem; background: transparent; border: none; cursor: pointer;
  color: var(--color-primary); display: flex; align-items: center; justify-content: center;
  transition: color .18s;
}
.inputbar__send:hover:not(:disabled) { color: var(--color-accent); }
.inputbar__send:disabled { opacity: .35; cursor: default; }

/* ── Gallery & Lightbox ────────────────────────────── */
.gallery { display: grid; gap: 8px; margin-top: 1rem; border-radius: var(--radius-md); overflow: hidden; }
.gallery--1 { grid-template-columns: 1fr; }
.gallery--2 { grid-template-columns: 1fr 1fr; }
.gallery--3 { grid-template-columns: 1fr 1fr; }
.gallery--3 figure:first-child { grid-column: span 2; }

.gallery figure { margin: 0; position: relative; cursor: pointer; overflow: hidden; }
.gallery img { width: 100%; height: 200px; object-fit: cover; transition: transform .3s; }
.gallery figure:hover img { transform: scale(1.04); }
.gallery figcaption { 
  position: absolute; bottom: 0; left: 0; right: 0;
  padding: .5rem; background: rgba(0,0,0,.5); color: #fff;
  font-size: .7rem; backdrop-filter: blur(4px);
}

/* Instagram-style carousel */
.instagram-carousel {
  position: relative;
  width: 100%;
  overflow: hidden;
  background-color: var(--color-bg);
  border-bottom: 1px solid var(--color-border);
}

.carousel-container {
  position: relative;
  width: 100%;
  overflow: hidden;
}

.carousel-track {
  display: flex;
  transition: transform 0.3s ease;
  width: 100%;
}

.carousel-slide {
  flex: 0 0 100%;
  width: 100%;
  position: relative;
}

.carousel-slide img {
  width: 100%;
  height: auto;
  max-height: 60vh;
  object-fit: contain;
  display: block;
  cursor: pointer;
}

.carousel-caption {
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  text-align: center;
  background-color: var(--color-bg);
  border-top: 1px solid var(--color-border);
}

.carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(0, 0, 0, 0.5);
  color: white;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  transition: background 0.2s;
}

.carousel-arrow:hover {
  background: rgba(0, 0, 0, 0.7);
}

.carousel-arrow--prev {
  left: 1rem;
}

.carousel-arrow--next {
  right: 1rem;
}

.carousel-dots {
  position: absolute;
  bottom: 1rem;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  z-index: 10;
}

.carousel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: color-mix(in srgb, var(--color-primary) 30%, transparent);
  border: none;
  padding: 0;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.2s;
}

.carousel-dot.active {
  background-color: var(--color-primary);
  transform: scale(1.2);
}

.carousel-dot:hover {
  background-color: color-mix(in srgb, var(--color-primary) 70%, transparent);
}

.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.92);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 2rem; animation: fadeIn .3s ease;
}
.lightbox__content {
  position: relative; max-width: 90vw; max-height: 90vh;
  display: flex; flex-direction: column; align-items: center; gap: 1rem;
}
.lightbox__img { 
  max-width: 100%; max-height: calc(90vh - 80px); 
  border-radius: 4px; box-shadow: 0 10px 40px rgba(0,0,0,.5);
  object-fit: contain;
}
.lightbox__close {
  position: absolute; top: -40px; right: 0;
  background: none; border: none; color: #fff; font-size: 1.5rem; cursor: pointer;
}
.lightbox__caption { color: #fff; font-size: .9rem; text-align: center; max-width: 600px; }
.lightbox__nav {
  display: flex; align-items: center; gap: 1.5rem; color: #fff;
}
.lightbox__nav button {
  background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2);
  color: #fff; width: 40px; height: 40px; border-radius: 50%;
  font-size: 1.2rem; cursor: pointer; transition: background .2s;
}
.lightbox__nav button:hover { background: rgba(255,255,255,.25); }

/* ── Branding & Logo ─────────────────────────────────── */
.landing__logo-wrap {
  width: 120px; height: 120px; border-radius: 50%;
  background: #fff; display: flex; align-items: center; justify-content: center;
  padding: 15px; box-shadow: 0 8px 30px rgba(0,0,0,.2);
  margin-bottom: 0.5rem;
}
.landing__logo { max-width: 100%; max-height: 100%; object-fit: contain; }

.topbar__brand { display: flex; align-items: center; gap: .6rem; }
.topbar__logo { height: 28px; width: auto; object-fit: contain; }

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

/* ── Typing Indicator ────────────────────────────────── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  width: fit-content;
  box-shadow: var(--shadow-md);
}
.typing-indicator span {
  width: 6px;
  height: 6px;
  background-color: var(--color-primary);
  border-radius: 50%;
  animation: typingWave 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }

/* ── Bot Avatar & Wrapper ─────────────────────────────── */
.bot-message-wrapper {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 1rem;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}
.bot-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  border: 2px solid var(--color-primary);
  object-fit: cover;
  flex-shrink: 0;
}

/* ── Book Reader Layout ─────────────────────────────── */
.book-reader {
  background-color: color-mix(in srgb, var(--color-surface) 90%, var(--color-accent) 10%);
  color: var(--color-text);
  padding: 2rem 1.5rem;
  border-radius: var(--radius-xl);
  max-width: 600px;
  margin: 0 auto;
  font-family: Georgia, serif;
}
.book-reader h2.book-title {
  font-family: var(--font-heading);
  text-align: center;
  font-size: 2rem;
  margin-bottom: 1.5rem;
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 1rem;
}
.book-content p {
  font-size: 1.05rem;
  line-height: 1.8;
}
.book-content p:first-of-type::first-letter {
  font-size: 3em;
  float: left;
  line-height: 1;
  margin-right: 0.15em;
  font-family: var(--font-heading);
}
.book-reader .inline-book-image {
  float: right;
  width: 45%;
  margin: 0 0 1rem 1.5rem;
  border-radius: 8px;
}

/* ── Presentation Viewer Layout ──────────────────────── */
.presentation-viewer {
  background: var(--color-surface);
  padding: 1.5rem;
  border-radius: var(--radius-xl);
}
.presentation-viewer img.slide-image {
  width: 100%;
  max-height: 60vh;
  object-fit: cover;
  border-radius: 16px;
  margin-bottom: 1rem;
}
.presentation-viewer h2 {
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1.8rem;
  color: var(--color-text);
}
.presentation-viewer .slide-content {
  font-size: 1rem;
  line-height: 1.6;
  color: var(--color-text-muted);
}

.animate-slide-up {
  animation: slideInUp var(--anim-duration-normal) var(--anim-spring) both;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 768px) {
  .book-reader {
    padding: 1.5rem 1rem;
    font-size: 1rem;
  }
  .book-reader h2.book-title {
    font-size: 1.6rem;
  }
  .book-content {
    line-height: 1.8;
  }
  .presentation-viewer {
    padding: 1rem;
  }
  .presentation-viewer h2 {
    font-size: 1.5rem;
  }
  .bot-message-wrapper {
    max-width: 100%;
    box-sizing: border-box;
  }
  .typing-indicator {
    padding: 8px 12px;
  }
}

@media (max-width: 480px) {
  .card__steps   { padding: .5rem 1rem 0; }
  .card__links   { padding: 0 1rem; }
  .lightbox { padding: 1rem; }
  .lightbox__nav { gap: 1rem; }
  
  .card { 
    max-width: 100%; 
    overflow-wrap: break-word; 
  }
  
  .card--welcome {
    /* padding is now on .welcome-content */
  }
  .welcome-content {
    padding: 1.5rem 1rem;
  }
  
  .book-reader .inline-book-image {
    width: 100%;
    float: none;
    margin: 0 0 1rem 0;
  }
}

/* ── Magazine Layout ─────────────────────────────────── */
.magazine-layout {
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-body);
  padding: 2rem 1.5rem;
  border-radius: var(--radius-xl);
}
.magazine-layout h2 {
  text-transform: uppercase;
  letter-spacing: 0.1em;
  font-size: 2rem;
  font-weight: 800;
  margin-bottom: 2rem;
  border-bottom: 3px solid var(--color-primary);
  padding-bottom: 0.5rem;
}
.magazine-content blockquote {
  border-left: 4px solid var(--color-accent);
  padding-left: 1.5rem;
  margin: 2rem 0;
  font-size: 1.4rem;
  font-style: italic;
  color: var(--color-primary);
}
.magazine-split {
  display: grid;
  grid-template-columns: 1fr;
  gap: 2rem;
  margin-bottom: 3rem;
}
.magazine-split img {
  width: 100%;
  border-radius: 8px;
  object-fit: cover;
}
/* Layout a doppia colonna su desktop con alternanza */
@media (min-width: 768px) {
  .magazine-split { grid-template-columns: 1fr 1fr; align-items: center; }
  .magazine-split:nth-child(even) img { order: 2; }
}

/* ── Cinematic Viewer ────────────────────────────────── */
.cinematic-viewer {
  background: #000;
  color: #fff;
  border-radius: var(--radius-xl);
  overflow: hidden;
}
.cinematic-moment {
  min-height: 75vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 2rem;
  text-align: center;
}
.cinematic-bg {
  position: absolute;
  inset: 0;
  z-index: 0;
  background-size: cover;
  background-position: center;
  background-attachment: fixed; /* Effetto Parallasse su Desktop */
  opacity: 0.5;
  transition: opacity 0.5s ease;
}
/* Su mobile il parallax causa jank su iOS Safari, usiamo scroll normale */
@media (max-width: 768px) {
  .cinematic-bg { background-attachment: scroll; }
}
.cinematic-text {
  position: relative;
  z-index: 1;
  font-size: 1.4rem;
  font-weight: 600;
  line-height: 1.6;
  text-shadow: 0 4px 20px rgba(0,0,0,0.9);
  max-width: 700px;
}

/* ── FORM EDITOR (Hybrid UI) ──────────────────────────────────────────────── */

.fe-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  max-width: 100%;
}

.fe-header {
  margin-bottom: 1.25rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--color-border);
}

.fe-title {
  font-family: var(--font-heading);
  font-size: 1.15rem;
  color: var(--color-text);
  margin: 0;
}

.fe-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.fe-field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.fe-label {
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.fe-input {
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--color-text);
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.85rem;
  outline: none;
  transition: border-color var(--anim-duration-fast) var(--anim-smooth),
              box-shadow var(--anim-duration-fast) var(--anim-smooth);
  width: 100%;
}

.fe-input:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(107, 79, 42, 0.12);
}

.fe-select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%237A6A56'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.85rem center;
  padding-right: 2.2rem;
  cursor: pointer;
}

.fe-pw-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.fe-input--pw {
  padding-right: 2.8rem;
  font-family: var(--font-body);
  letter-spacing: 0.05em;
}

.fe-pw-toggle {
  position: absolute;
  right: 0.5rem;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 0.25rem;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.fe-pw-toggle:hover {
  opacity: 1;
}

.fe-checkbox-label {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: var(--font-body);
  font-size: 0.95rem;
  color: var(--color-text);
  cursor: pointer;
}

.fe-checkbox {
  width: 1.15rem;
  height: 1.15rem;
  accent-color: var(--color-primary);
  cursor: pointer;
}

.fe-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--color-border);
}

.fe-btn {
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.7rem 1.4rem;
  border-radius: var(--radius-md);
  border: none;
  cursor: pointer;
  transition: all var(--anim-duration-fast) var(--anim-smooth);
}

.fe-btn--confirm {
  background: var(--color-primary);
  color: #fff;
  flex: 1;
}

.fe-btn--confirm:hover:not(:disabled) {
  background: var(--color-accent);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.fe-btn--cancel {
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
}

.fe-btn--cancel:hover:not(:disabled) {
  background: var(--color-bg);
  color: var(--color-text);
}

.fe-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Dark mode refinements */
@media (prefers-color-scheme: dark) {
  .fe-input {
    background: #1a1a2e;
    border-color: #2a2a3e;
    color: #e8e8e8;
  }
  .fe-input:focus {
    box-shadow: 0 0 0 3px rgba(193, 127, 42, 0.2);
  }
  .fe-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%238a8a9a'/%3E%3C/svg%3E");
  }
  .narra-mosaic .narra-link-inline:hover {
    box-shadow: 0 4px 20px rgba(255,255,255,0.15);
  }
  .shimmer {
    background: linear-gradient(90deg, var(--color-border) 25%, var(--color-surface) 50%, var(--color-border) 75%);
  }
}

/* ── Typing Effect ──────────────────────────────────────── */
.typing-cursor {
    display: inline;
    animation: cursor-blink 0.7s step-end infinite;
    color: var(--color-primary);
    font-weight: bold;
    margin-left: 1px;
}

@keyframes cursor-blink {
    50% { opacity: 0; }
}

.status-bar--fading {
    opacity: 0;
    pointer-events: none;
}

/* ── IMAGE MOSAIC GRID (Onboarding narra-link images) ──────────────────── */
.narra-mosaic {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  padding: 0.5rem 0;
}
.narra-mosaic .narra-link-inline {
  display: block;
  margin: 0;
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  aspect-ratio: 4/3;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.narra-mosaic .narra-link-inline:hover {
  transform: scale(1.03);
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
}
.narra-mosaic .narra-link-inline:active {
  transform: scale(0.97);
}
.narra-mosaic .narra-link-inline img.inline-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 0;
  margin: 0;
  display: block;
}


@media (max-width: 400px) {
  .narra-mosaic {
    grid-template-columns: repeat(3, 1fr);
    gap: 0.3rem;
  }
}

/* ==========================================================================
   STORIES (Topics Onboarding Row)
   ========================================================================== */

/* Topbar Stories Layout Overrides */
.topbar .stories-row {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0 0.5rem;
  margin: 0;
  width: auto;
  flex: 1;
  min-width: 0;
  overflow-x: auto;
  white-space: nowrap;
  flex-wrap: nowrap;
  scrollbar-width: none;
  -ms-overflow-style: none;
  transition: all 0.4s var(--anim-smooth);
}
.topbar .stories-row::-webkit-scrollbar {
  display: none;
}
@media (min-width: 600px) {
  .topbar .stories-row {
    justify-content: center;
    margin: 0 auto;
    max-width: calc(100% - 400px);
  }
}
@media (max-width: 599px) {
  .topbar .stories-row {
    justify-content: flex-start;
  }
}
.topbar .story-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.2s ease, gap 0.4s var(--anim-smooth);
}
.topbar .story-item:hover {
  transform: translateY(-2px);
}
.topbar .story-avatar-ring {
  width: 36px;
  height: 36px;
  border-radius: var(--story-radius);
  clip-path: var(--story-clip-path);
  background: var(--color-bg-gradient, linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%));
  padding: 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.4s var(--anim-smooth);
}
.topbar .story-avatar {
  width: 100%;
  height: 100%;
  background-color: var(--color-bg);
  background-size: cover;
  background-position: center;
  border-radius: var(--story-radius);
  clip-path: var(--story-clip-path);
  border: 1px solid var(--color-bg);
  transition: all 0.4s var(--anim-smooth);
}
.topbar .story-label {
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--color-text);
  max-width: 75px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: all 0.4s var(--anim-smooth);
}

/* Expanded/Start state for Stories inside Topbar */
.topbar--start .stories-row {
  padding: 0.25rem 0.5rem;
}
.topbar--start .story-item {
  gap: 0.4rem;
}
.topbar--start .story-avatar-ring {
  width: 60px;
  height: 60px;
  padding: 3px;
}
.topbar--start .story-avatar {
  border-width: 2px;
}
.topbar--start .story-label {
  font-size: 0.75rem;
  max-width: 100px;
}

.stories-row {
  display: flex;
  justify-content: flex-start;
  gap: 1.25rem;
  margin-bottom: 2rem;
  padding: 0.5rem 1.25rem;
  width: 100%;
  overflow-x: auto;
  white-space: nowrap;
  flex-wrap: nowrap;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE 10+ */
  transition: all 0.4s var(--anim-smooth);
}

.stories-row::-webkit-scrollbar {
  display: none; /* Safari/Chrome */
}

@media (min-width: 600px) {
  .stories-row {
    justify-content: center;
    padding: 0.5rem 0;
  }
}

.story-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.2s ease, gap 0.4s var(--anim-smooth);
}

.story-item:hover {
  transform: translateY(-3px);
}

.story-avatar-ring {
  width: 76px;
  height: 76px;
  border-radius: var(--story-radius);
  clip-path: var(--story-clip-path);
  background: var(--color-bg-gradient, linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%));
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.4s var(--anim-smooth);
}

.story-avatar {
  width: 100%;
  height: 100%;
  background-color: var(--color-bg);
  background-size: cover;
  background-position: center;
  border-radius: var(--story-radius);
  clip-path: var(--story-clip-path);
  border: 2px solid var(--color-bg);
  transition: all 0.4s var(--anim-smooth);
}

.story-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text);
  transition: all 0.4s var(--anim-smooth);
}

/* Compact Stories Row state */
.stories-row--compact {
  margin-bottom: 0.75rem;
  gap: 0.85rem;
  padding: 0.25rem 1rem;
}

@media (min-width: 600px) {
  .stories-row--compact {
    padding: 0.25rem 0;
  }
}

.stories-row--compact .story-item {
  gap: 0.2rem;
}

.stories-row--compact .story-avatar-ring {
  width: 42px;
  height: 42px;
  padding: 1.5px;
}

.stories-row--compact .story-avatar {
  border-width: 1px;
}

.stories-row--compact .story-label {
  font-size: 0.65rem;
}

/* Splash Screen Overlay */
.ns-splash {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-bg);
  transition: transform 0.6s cubic-bezier(0.85, 0, 0.15, 1), opacity 0.6s ease;
}

.ns-splash--fade-out {
  transform: translateY(-100%);
  opacity: 0;
}

.ns-splash .card--welcome {
  width: 100% !important;
  height: 100% !important;
  border: none !important;
  border-radius: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: center !important;
  align-items: center !important;
  margin: 0 !important;
  box-shadow: none !important;
  animation: none !important;
}

/* ==========================================================================
   MORPHING CANVAS & BENTO GRID POLISH
   ========================================================================== */
.canvas-content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  position: relative;
}

.canvas-focused {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem 1.25rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.canvas-focused > div {
  width: 100%;
  max-width: var(--max-width);
  margin: 0 auto;
}

/* Bento Grid styling polish */
.card--grid {
  border-radius: var(--radius-lg) !important;
}
.card--grid .card__grid {
  display: grid;
  gap: 1.25rem;
  padding: 1.25rem;
  grid-template-columns: 1fr;
}
.card--grid .card__header {
  padding: 1.25rem 1.25rem 0;
}
.card--grid .card__body {
  padding: 0;
}
.card--grid .card__footer {
  padding: 1rem 0 0;
}
.card--grid .gallery {
  margin-top: 0;
  border-radius: var(--radius-md);
  overflow: hidden;
}

@media (min-width: 560px) {
  .card--grid .card__grid {
    grid-template-columns: 1.2fr 1fr;
  }
}

/* ==========================================================================
   FORM EDITOR STEPPER PROGRESS INDICATOR
   ========================================================================== */
.fe-stepper {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding: 0.5rem 0;
  position: relative;
  width: 100%;
}

.fe-stepper::before {
  content: '';
  position: absolute;
  top: 18px;
  left: 10%;
  right: 10%;
  height: 2px;
  background: var(--color-border);
  z-index: 1;
}

.fe-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 2;
  flex: 1;
}

.fe-step-indicator {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 2px solid var(--color-border);
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  transition: all 0.3s ease;
}

.fe-step-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-top: 0.5rem;
  text-align: center;
  transition: all 0.3s ease;
}

/* Stepper States */
.fe-step--completed .fe-step-indicator {
  background: #10b981;
  border-color: #10b981;
  color: #ffffff;
}

.fe-step--completed .fe-step-label {
  color: #10b981;
}

.fe-step--active .fe-step-indicator {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #ffffff;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-primary) 15%, transparent);
}

.fe-step--active .fe-step-label {
  color: var(--color-primary);
  font-weight: 700;
}

.view-table thead tr {
  background: var(--color-bg-secondary, rgba(255,255,255,0.05)) !important;
}
.view-table th {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  color: var(--color-text-muted, #aaa);
}

