/* ValeBeauty — Console di Pubblicazione V5 */

/* ── Token ──────────────────────────────────────────────────────────────── */
:root {
  --bg:         var(--tg-theme-bg-color,           #0d0d14);
  --surface:    var(--tg-theme-secondary-bg-color,  #1a1a26);
  --text:       var(--tg-theme-text-color,          #f0f0f5);
  --hint:       var(--tg-theme-hint-color,          #666680);
  --accent:     var(--tg-theme-button-color,        #00d084);
  --accent-txt: var(--tg-theme-button-text-color,   #ffffff);
  --border:     rgba(255,255,255,0.07);
  --r:          14px;
  --r-sm:       10px;
  --shadow:     0 4px 24px rgba(0,0,0,0.35);
  --font:       -apple-system, BlinkMacSystemFont, 'Inter', sans-serif;

  /* semaforo */
  --green:  #00d084;
  --yellow: #ffcc00;
  --red:    #ff3b5c;
  --grey:   #555570;

  /* action buttons */
  --pub-h: 58px;
  --gen-h: 56px;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*,*::before,*::after { box-sizing:border-box; margin:0; padding:0; }
html { height:100%; -webkit-tap-highlight-color:transparent; touch-action:manipulation; }
body {
  font-family: var(--font);
  background:  var(--bg);
  color:       var(--text);
  height:      100%;
  overflow:    hidden;       /* no scroll su body — scroll solo action-area */
  display:     flex;
  flex-direction: column;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
.hdr {
  flex-shrink: 0;
  display:     flex;
  align-items: center;
  justify-content: space-between;
  padding:     10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  background:  var(--surface);
  border-bottom: 1px solid var(--border);
}
.hdr-brand { display:flex; align-items:center; gap:8px; }
.hdr-logo  { font-size:22px; }
.hdr-title { font-size:16px; font-weight:700; letter-spacing:-.3px; }

/* ── Status pill ─────────────────────────────────────────────────────────── */
.status-pill {
  display:     flex;
  align-items: center;
  gap:         5px;
  padding:     4px 10px;
  border-radius: 20px;
  font-size:   11px;
  font-weight: 600;
  white-space: nowrap;
}
.status-pill--ok      { background:rgba(0,208,132,.15); color:var(--green); }
.status-pill--error   { background:rgba(255,59,92,.12); color:var(--red); }
.status-pill--loading { background:rgba(255,255,255,.06); color:var(--hint); }
.status-dot {
  width:6px; height:6px; border-radius:50%; background:currentColor; flex-shrink:0;
}
.status-pill--ok .status-dot { animation: blink 2s ease-in-out infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.3} }

/* ── Views ───────────────────────────────────────────────────────────────── */
.view {
  display:        none !important;  /* !important batte selettori ID */
  flex:           1;
  flex-direction: column;
  overflow:       hidden;
}
.view.active { display:flex !important; }

/* ── Splash (loading / empty / generating) ───────────────────────────────── */
.splash {
  flex:            1;
  display:         flex;
  flex-direction:  column;
  align-items:     center;
  justify-content: center;
  gap:             14px;
  padding:         24px;
  text-align:      center;
}
.splash-emoji { font-size:52px; }
.splash-text  { font-size:17px; font-weight:600; }
.splash-sub   { font-size:13px; color:var(--hint); max-width:260px; line-height:1.5; }

/* ── Spinner (loading) ───────────────────────────────────────────────────── */
.splash-ring {
  width:48px; height:48px; border-radius:50%;
  border:3px solid rgba(255,255,255,.08);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform:rotate(360deg); } }

/* ── Generating animation ────────────────────────────────────────────────── */
.gen-anim {
  position:relative; width:80px; height:80px;
  display:flex; align-items:center; justify-content:center;
}
.gen-ring {
  position:absolute; border-radius:50%;
  border:2px solid transparent;
  animation: spin-ring 1.4s linear infinite;
}
.r1 { width:80px; height:80px; border-top-color:var(--accent);  animation-duration:1.0s; }
.r2 { width:60px; height:60px; border-top-color:var(--yellow);  animation-duration:1.4s; animation-direction:reverse; }
.r3 { width:40px; height:40px; border-top-color:var(--red);     animation-duration:2.0s; }
@keyframes spin-ring { to { transform:rotate(360deg); } }
.gen-core { font-size:22px; z-index:1; animation: pulse-core 1s ease-in-out infinite alternate; }
@keyframes pulse-core { to { transform:scale(1.3); } }

/* ── Buttons (generic) ───────────────────────────────────────────────────── */
.btn-ghost {
  background:none; border:1px solid var(--border);
  color:var(--hint); font-size:13px; font-family:var(--font);
  padding:8px 20px; border-radius:20px; cursor:pointer;
}
.btn-ghost:active { opacity:.6; }

/* ── Ready view layout ───────────────────────────────────────────────────── */
#view-ready {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* TOP — preview area (≈45% altezza) */
.preview-area {
  flex-shrink: 0;
  display:     flex;
  flex-direction: column;
}

/* Frame immagine */
.img-frame {
  position:   relative;
  width:      100%;
  aspect-ratio: 1 / 1;
  max-height: 42vw;          /* max ~38% viewport su iPhone */
  overflow:   hidden;
  background: var(--surface);
}
.img-frame img {
  width:100%; height:100%; object-fit:cover; display:block;
}
.img-frame img.hidden   { display:none; }
.img-placeholder {
  position:absolute; inset:0;
  display:flex; flex-direction:column;
  align-items:center; justify-content:center; gap:8px;
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
}
.img-placeholder.hidden { display:none; }
#placeholder-emoji { font-size:40px; }
#placeholder-label { font-size:13px; color:var(--hint); text-align:center; padding:0 16px; }

/* Score bar (sotto immagine) */
.score-bar {
  display:     flex;
  align-items: center;
  gap:         10px;
  padding:     10px 16px 6px;
  background:  var(--surface);
  border-bottom: 1px solid var(--border);
}

/* Semaforo */
.score-light {
  width:14px; height:14px; border-radius:50%; flex-shrink:0;
  transition: background .4s, box-shadow .4s;
}
.score-light--green  { background:var(--green);  box-shadow:0 0 8px var(--green); }
.score-light--yellow { background:var(--yellow); box-shadow:0 0 8px var(--yellow); animation:blink 1.5s infinite; }
.score-light--red    { background:var(--red);    box-shadow:0 0 8px var(--red); }
.score-light--none   { background:var(--grey); }

.score-info  { display:flex; align-items:baseline; gap:2px; }
.score-value { font-size:22px; font-weight:800; line-height:1; }
.score-label { font-size:11px; color:var(--hint); }

.content-meta {
  margin-left:auto;
  display:flex; align-items:center; gap:4px;
  font-size:11px; color:var(--hint);
}
.meta-sep { opacity:.4; }

/* Avviso score basso */
.score-warn {
  display:    flex;
  align-items: center;
  justify-content: space-between;
  gap:         10px;
  padding:     8px 16px;
  background:  rgba(255,204,0,.07);
  border-bottom: 1px solid rgba(255,204,0,.15);
  font-size:   12px;
  color:       var(--yellow);
}
.score-warn.hidden { display:none; }
.btn-warn-regen {
  flex-shrink:0; background:rgba(255,204,0,.15); border:none;
  color:var(--yellow); font-size:11px; font-weight:600; font-family:var(--font);
  padding:4px 10px; border-radius:12px; cursor:pointer; white-space:nowrap;
}

/* BOTTOM — action area (resto) */
.action-area {
  flex:      1;
  display:   flex;
  flex-direction: column;
  gap:       10px;
  padding:   12px 12px;
  padding-bottom: max(16px, env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* Caption card */
.caption-card {
  background:    var(--surface);
  border-radius: var(--r);
  overflow:      hidden;
  cursor:        pointer;
  border:        1px solid var(--border);
  transition:    border-color .2s;
  flex-shrink:   0;
}
.caption-card:active { border-color: var(--accent); }
.caption-card.flash  { border-color: var(--accent); animation: flash-border .5s ease; }
@keyframes flash-border {
  0%,100%  { border-color: var(--border); }
  50%      { border-color: var(--accent); background: rgba(0,208,132,.06); }
}

.caption-hdr {
  display:     flex;
  align-items: center;
  justify-content: space-between;
  padding:     10px 14px 6px;
}
.caption-label-tag {
  font-size:11px; font-weight:600; text-transform:uppercase;
  letter-spacing:.6px; color:var(--hint);
}
.btn-copy-inline {
  background: rgba(0,208,132,.12);
  border:     none;
  color:      var(--accent);
  font-size:  11px;
  font-weight:700;
  font-family:var(--font);
  padding:    4px 10px;
  border-radius:12px;
  cursor:     pointer;
  letter-spacing:.4px;
}
.btn-copy-inline:active { opacity:.7; }

.caption-text {
  padding:     6px 14px 14px;
  font-size:   14px;
  line-height: 1.55;
  color:       var(--text);
  max-height:  90px;
  overflow-y:  auto;
  user-select: text;
  -webkit-user-select: text;
}

/* Bottoni azione */
.action-btns {
  display: grid;
  grid-template-columns: 1fr 1.6fr;
  gap: 10px;
  flex-shrink: 0;
}

.btn-action {
  height:        var(--pub-h);
  display:       flex;
  align-items:   center;
  justify-content: center;
  gap:           8px;
  border:        none;
  border-radius: var(--r);
  font-family:   var(--font);
  font-size:     13px;
  font-weight:   700;
  letter-spacing:.4px;
  cursor:        pointer;
  transition:    transform .1s, opacity .15s;
}
.btn-action:active:not(:disabled) { transform:scale(.97); }
.btn-action:disabled { opacity:.38; cursor:default; }

.btn-icon { font-size:18px; }

/* Salva */
.btn-action--sec {
  background: var(--surface);
  border:     1px solid var(--border);
  color:      var(--text);
}
.btn-action--sec:active { background:rgba(255,255,255,.06); }

/* Pubblica — stati */
.btn-pub--active {
  background: linear-gradient(135deg,#00d084 0%,#00b36f 100%);
  color:      #000;
  box-shadow: 0 4px 16px rgba(0,208,132,.35);
}
.btn-pub--warn {
  background: rgba(255,204,0,.12);
  border:     1.5px solid rgba(255,204,0,.5);
  color:      var(--yellow);
}
.btn-pub--disabled {
  background: rgba(255,59,92,.08);
  border:     1.5px solid rgba(255,59,92,.2);
  color:      var(--red);
}

/* Genera Nuovo */
.btn-gen {
  flex-shrink:0; width:100%;
  height:      var(--gen-h);
  display:     flex;
  align-items: center;
  justify-content: center;
  gap:         8px;
  border:      none;
  border-radius: var(--r);
  font-family: var(--font);
  font-size:   15px;
  font-weight: 700;
  letter-spacing:.3px;
  cursor:      pointer;
  transition:  transform .1s, opacity .15s;
}
.btn-gen:active { transform:scale(.98); }
.btn-gen--hero {
  background: linear-gradient(135deg,#7b2ff7 0%,#00d084 100%);
  color:      #fff;
  box-shadow: 0 4px 20px rgba(123,47,247,.3);
}

/* ── Bottom sheet ─────────────────────────────────────────────────────────── */
.sheet-overlay {
  position: fixed; inset:0; z-index:100;
  background: rgba(0,0,0,.55);
  display:    flex;
  align-items: flex-end;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.sheet-overlay.hidden { display:none; }

.sheet-panel {
  width:       100%;
  background:  var(--surface);
  border-radius: 20px 20px 0 0;
  padding:     8px 12px max(20px,env(safe-area-inset-bottom));
  transform:   translateY(100%);
  transition:  transform .28s cubic-bezier(.4,0,.2,1);
}
.sheet-panel--in { transform:translateY(0); }

.sheet-notch {
  width:36px; height:4px; border-radius:2px;
  background:rgba(255,255,255,.18); margin:0 auto 16px;
}
.sheet-title {
  font-size:13px; font-weight:600; color:var(--hint);
  text-transform:uppercase; letter-spacing:.6px;
  padding:0 4px 10px;
}

.sheet-opt {
  width:100%; display:flex; align-items:center; gap:14px;
  padding:14px 12px; background:none; border:none;
  border-top:1px solid var(--border);
  color:var(--text); font-family:var(--font); text-align:left;
  cursor:pointer; border-radius:0; transition:background .1s;
}
.sheet-opt:first-of-type { border-top:none; }
.sheet-opt:active { background:rgba(255,255,255,.04); }

.sheet-opt-icon { font-size:26px; flex-shrink:0; }
.sheet-opt strong { display:block; font-size:15px; font-weight:600; }
.sheet-opt small  { display:block; font-size:12px; color:var(--hint); margin-top:1px; }

.sheet-opt--cancel {
  justify-content:center;
  color:var(--red);
  font-weight:600;
  font-size:15px;
  border-top:1px solid var(--border) !important;
  margin-top:6px;
}

/* ── Configuratore di Lancio ─────────────────────────────────────────────── */

/* Step indicator */
.cfg-steps {
  display:     flex;
  align-items: center;
  gap:         8px;
  padding:     0 4px 14px;
}
.cfg-step {
  display:     flex;
  align-items: center;
  gap:         5px;
  flex-shrink: 0;
}
.cfg-step-num {
  width:22px; height:22px; border-radius:50%;
  display:flex; align-items:center; justify-content:center;
  font-size:11px; font-weight:700;
  background: rgba(255,255,255,.08);
  color: var(--hint);
  transition: background .2s, color .2s;
}
.cfg-step-lbl {
  font-size:12px; font-weight:500; color:var(--hint);
  transition: color .2s;
}
.cfg-step--active .cfg-step-num { background:var(--accent); color:#000; }
.cfg-step--active .cfg-step-lbl { color:var(--text); }
.cfg-step--done   .cfg-step-num { background:rgba(0,208,132,.18); color:var(--accent); }
.cfg-step--done   .cfg-step-lbl { color:var(--accent); }
.cfg-step-line {
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Pages */
.cfg-page { overflow:hidden; }
.cfg-page.hidden { display:none; }

.cfg-page-title {
  font-size:13px; font-weight:600; color:var(--hint);
  text-transform:uppercase; letter-spacing:.6px;
  padding:0 2px 10px;
}

/* Back row (step 2) */
.cfg-back-row {
  display:     flex;
  align-items: center;
  gap:         10px;
  margin-bottom: 6px;
}
.cfg-back-btn {
  background:none; border:none; color:var(--hint);
  font-size:13px; font-family:var(--font);
  cursor:pointer; padding:0;
}
.cfg-back-btn:active { opacity:.6; }
.cfg-selected-prod {
  font-size:13px; font-weight:600; color:var(--accent);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}

/* Product grid */
.cfg-grid {
  display:  grid;
  grid-template-columns: repeat(2, 1fr);
  gap:      8px;
  max-height: 42vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding:  2px;
}
.cfg-card {
  background:    var(--surface);
  border:        1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding:       10px 8px;
  display:       flex;
  flex-direction: column;
  align-items:   center;
  gap:           4px;
  cursor:        pointer;
  text-align:    center;
  transition:    border-color .15s, transform .1s;
  font-family:   var(--font);
}
.cfg-card:active { transform:scale(.97); }
.cfg-card--sel {
  border-color: var(--accent);
  background:   rgba(0,208,132,.08);
}
.cfg-card-emoji { font-size:26px; line-height:1; }
.cfg-card-name  { font-size:12px; font-weight:600; color:var(--text); line-height:1.3; }
.cfg-card-hint  {
  font-size:10px; color:var(--hint); line-height:1.2;
  max-height:2.4em; overflow:hidden;
}

/* Skeleton loader */
.cfg-skeleton {
  height: 72px; border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--surface) 0%, rgba(255,255,255,.04) 50%, var(--surface) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* Angle chips */
.cfg-angles {
  display:  flex;
  flex-wrap: wrap;
  gap:      8px;
  max-height: 40vh;
  overflow-y: auto;
  padding:  2px;
}
.cfg-chip {
  background:    var(--surface);
  border:        1.5px solid var(--border);
  border-radius: 20px;
  padding:       8px 12px;
  display:       flex;
  align-items:   center;
  gap:           6px;
  cursor:        pointer;
  font-family:   var(--font);
  text-align:    left;
  flex-direction: column;
  align-items:   flex-start;
  min-width:     calc(50% - 4px);
  transition:    border-color .15s, transform .1s;
}
.cfg-chip:active { transform:scale(.97); }
.cfg-chip--sel {
  border-color: var(--accent);
  background:   rgba(0,208,132,.08);
}
.cfg-chip-emoji { font-size:18px; }
.cfg-chip-label { font-size:13px; font-weight:600; color:var(--text); }
.cfg-chip-desc  { font-size:10px; color:var(--hint); line-height:1.2; }

/* Footer */
.cfg-footer {
  display:     flex;
  gap:         10px;
  padding-top: 14px;
  border-top:  1px solid var(--border);
  margin-top:  10px;
}
.cfg-cancel-btn {
  flex-shrink:0; background:none; border:1px solid var(--border);
  color:var(--hint); font-size:13px; font-family:var(--font);
  padding:10px 14px; border-radius:var(--r-sm); cursor:pointer;
}
.cfg-gen-btn {
  flex:1; display:flex; align-items:center; justify-content:center;
  gap:6px; height:50px;
  background: linear-gradient(135deg, #7b2ff7 0%, #00d084 100%);
  color:#fff; border:none; border-radius:var(--r-sm);
  font-family:var(--font); font-size:13px; font-weight:700;
  cursor:pointer; transition:opacity .15s, transform .1s;
  letter-spacing:.3px;
}
.cfg-gen-btn:disabled {
  background: rgba(255,255,255,.06);
  color:      var(--hint);
  cursor:     default;
}
.cfg-gen-btn:not(:disabled):active { transform:scale(.98); }
.cfg-gen-icon { font-size:18px; }

/* Gen params badges (view-generating) */
.gen-params {
  display:     flex;
  gap:         8px;
  flex-wrap:   wrap;
  justify-content: center;
  margin-top:  4px;
}
.gen-tag {
  background:  rgba(255,255,255,.07);
  border:      1px solid var(--border);
  border-radius: 14px;
  padding:     4px 10px;
  font-size:   12px;
  color:       var(--text);
  font-weight: 500;
}

/* ── Archivio pubblicati ─────────────────────────────────────────────────── */
.archive-section {
  flex-shrink: 0;
  padding-top: 4px;
}
.archive-section.archive-empty .archive-strip { display:none; }

.archive-hdr {
  display:     flex;
  align-items: center;
  justify-content: space-between;
  padding:     0 2px 8px;
}
.archive-title {
  font-size:   11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .6px;
  color:       var(--hint);
}
.archive-hint {
  font-size:   11px;
  color:       var(--accent);
  font-weight: 600;
}

.archive-strip {
  display:  flex;
  gap:      10px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 4px;
}
.archive-strip::-webkit-scrollbar { display:none; }

.archive-none {
  font-size: 12px;
  color: var(--hint);
  padding: 6px 2px;
}

.arc-item {
  flex-shrink:   0;
  width:         72px;
  background:    var(--surface);
  border:        1px solid var(--border);
  border-radius: var(--r-sm);
  padding:       8px 6px 7px;
  display:       flex;
  flex-direction: column;
  align-items:   center;
  gap:           4px;
  cursor:        default;
  transition:    border-color .15s;
}
.arc-item:active { border-color:var(--accent); }

.arc-icon-wrap {
  position: relative;
  width:    36px;
  height:   36px;
  display:  flex;
  align-items: center;
  justify-content: center;
}
.arc-icon  { font-size:26px; line-height:1; }

.arc-check {
  position:   absolute;
  bottom:     -3px;
  right:      -4px;
  width:      16px;
  height:     16px;
  background: var(--green);
  border-radius: 50%;
  font-size:  9px;
  font-weight:800;
  color:      #000;
  display:    flex;
  align-items:center;
  justify-content:center;
  line-height:1;
  box-shadow: 0 0 6px rgba(0,208,132,.5);
}
.arc-clock {
  position: absolute;
  bottom:   -3px;
  right:    -4px;
  font-size:13px;
  line-height:1;
  filter:   grayscale(.4) opacity(.7);
}

.arc-name {
  font-size:   10px;
  font-weight: 500;
  color:       var(--text);
  text-align:  center;
  line-height: 1.3;
  word-break:  break-word;
  max-height:  2.6em;
  overflow:    hidden;
}
.arc-date {
  font-size:  9px;
  color:      var(--hint);
  font-weight:500;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position:fixed;
  bottom: max(24px, env(safe-area-inset-bottom, 24px));
  left:50%; transform:translateX(-50%);
  background:rgba(20,20,36,.92);
  color:#fff; padding:10px 20px;
  border-radius:20px; font-size:13px; font-weight:500;
  pointer-events:none; transition:opacity .25s;
  white-space:nowrap; backdrop-filter:blur(8px);
  z-index:200; border:1px solid rgba(255,255,255,.1);
}
.toast.hidden { opacity:0; }
