/* ═══════════════════════════════════════════════════════════════
   CLOTO SCENE EDITOR — CSS
   Classes: .cw-*
   ═══════════════════════════════════════════════════════════════ */

/* ── Scene wrapper: fills workspace, scrolls internally ── */
.cw-scene {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  padding: var(--space-10);
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── Title ── */
.cw-scene-title {
  font-family: var(--cloto-font-brand);
  font-size: var(--cloto-fs-2xl);
  font-weight: 400;
  color: var(--cloto-text-100);
  line-height: 1.3;
  margin: 0;
}

/* ── Synopsis panel (guide) ── */
.cw-scene-synopsis {
  border: none;
  margin: 0;
  background: var(--cloto-surface-a6, rgba(255,255,255,0.03));
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-6);
  border-left: 3px solid var(--cloto-teal-a20, rgba(0,200,180,0.12));
}

.cw-scene-synopsis > summary {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  cursor: pointer;
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-xs);
  font-weight: 500;
  color: var(--cloto-teal, #4fd1c5);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  list-style: none;
  user-select: none;
  padding: var(--space-1) 0;
  transition: color var(--duration-fast) var(--ease-spring);
}

.cw-scene-synopsis > summary:hover {
  color: var(--cloto-text-70);
}

/* Custom arrow — ▾ when open, ▸ when closed */
.cw-scene-synopsis > summary::after {
  content: '\25B8'; /* ▸ */
  font-size: 10px;
  color: var(--cloto-text-25);
  transition: transform var(--duration-fast) var(--ease-spring);
  display: inline-block;
  margin-left: auto;
}

.cw-scene-synopsis[open] > summary::after {
  content: '\25BE'; /* ▾ */
}

/* Remove default marker */
.cw-scene-synopsis > summary::-webkit-details-marker { display: none; }
.cw-scene-synopsis > summary::marker { display: none; content: ''; }

.cw-scene-synopsis-text {
  font-family: var(--cloto-font-serif, Georgia, serif);
  font-size: var(--cloto-fs-sm);
  font-style: italic;
  color: var(--cloto-text-30);
  line-height: 1.7;
  padding: var(--space-4) 0 var(--space-1) 0;
  white-space: pre-wrap;
}

/* ── Textarea (the page) ── */
.cw-scene-textarea {
  flex: 1 1 auto;
  min-height: 200px;
  width: 100%;
  box-sizing: border-box;
  resize: none;
  overflow-y: auto;

  font-family: var(--cloto-font-brand);
  font-size: var(--cloto-fs-reading);
  font-weight: 400;
  color: var(--cloto-text-100);
  line-height: 1.8;

  background: transparent;
  border: 1px solid var(--cloto-teal-a8);
  border-radius: var(--radius-lg);
  padding: var(--space-10) var(--space-10);

  transition: border-color var(--duration-normal) var(--ease-spring),
              box-shadow var(--duration-normal) var(--ease-spring);
}

.cw-scene-textarea:focus {
  outline: none;
  border-color: var(--cloto-teal-a25);
  box-shadow: var(--shadow-focus-teal);
}

.cw-scene-textarea::placeholder {
  color: var(--cloto-text-25);
  font-style: italic;
}

/* ── Restore original banner ── */
.cw-restore-original {
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-sm);
  color: var(--cloto-teal);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-6);
  margin-top: var(--space-3);
  background: var(--cloto-teal-a8);
  border: 1px solid var(--cloto-teal-a12);
  border-radius: var(--radius-md);
  transition: background var(--duration-slow), border-color var(--duration-slow);
}

.cw-restore-original:hover {
  background: var(--cloto-teal-a15);
  border-color: var(--cloto-teal-a25);
}

/* ── Bottom bar ── */
.cw-scene-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-4);
  padding: var(--space-2) 0;
  flex-shrink: 0;
}

.cw-scene-bar .cw-scene-save-dot {
  width: 6px;
  height: 6px;
  border-radius: var(--radius-full);
  background: transparent;
  transition: background var(--duration-normal) var(--ease-spring),
              opacity var(--duration-slow) var(--ease-spring);
  flex-shrink: 0;
}

.cw-scene-bar .cw-scene-save-dot.is-saving {
  background: var(--cloto-gold);
  animation: cloto-save-pulse 0.8s ease-in-out infinite;
}

.cw-scene-bar .cw-scene-save-dot.is-saved {
  background: var(--cloto-success);
  animation: cloto-dot-flash 1.5s forwards;
}

/* Submit button: AI style (gold) */
.cw-scene-submit {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 32px;
  padding: var(--space-3) var(--space-7);
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-sm);
  font-weight: 500;
  color: var(--cloto-gold);
  background: var(--cloto-gold-a8);
  border: 1px solid var(--cloto-gold-a20);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--duration-normal) var(--ease-spring),
              border-color var(--duration-normal) var(--ease-spring),
              opacity var(--duration-normal) var(--ease-spring);
}

.cw-scene-submit:hover:not(:disabled) {
  background: var(--cloto-gold-a12);
  border-color: var(--cloto-gold-a25);
}

.cw-scene-submit:disabled {
  opacity: var(--opacity-disabled);
  cursor: not-allowed;
  pointer-events: none;
}

/* Submit spinner */
.cw-scene-submit-spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--cloto-gold-a20);
  border-top-color: var(--cloto-gold);
  border-radius: 50%;
  animation: cw-spin 0.6s linear infinite;
}

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

/* ═══════════════════════════════════════════════════════════════
   TESSILA — Tessuto view + infusion highlights + tooltips
   ═══════════════════════════════════════════════════════════════ */

/* ── Tessuto view: shows the woven text with highlights ── */
.cw-tessuto-view {
  flex: 1 1 auto;
  min-height: 200px;
  overflow-y: auto;

  font-family: var(--cloto-font-brand);
  font-size: var(--cloto-fs-reading);
  font-weight: 400;
  color: var(--cloto-text-100);
  line-height: 1.7;
  white-space: pre-wrap;

  background: transparent;
  border: 1px solid var(--cloto-teal-a8);
  border-radius: var(--radius-lg);
  padding: var(--space-10);
}

/* ── Infusion highlight: teal underline ── */
.cw-infusion {
  border-bottom: 2px solid rgba(45, 212, 191, 0.5);
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.cw-infusion:hover {
  border-bottom-color: var(--cloto-teal);
}

/* ── Correction highlight: gold dotted underline ── */
.cw-correction {
  border-bottom: 2px dotted rgba(154, 126, 48, 0.5);
  cursor: pointer;
  transition: border-color 0.2s ease;
}

.cw-correction:hover {
  border-bottom-color: var(--cloto-gold);
}

/* ── Infusion tooltip (popover) ── */
.cw-infusion-tooltip {
  position: fixed;
  max-width: 320px;
  padding: 10px 14px;
  background: var(--cloto-bg-20, #1a1a2e);
  border: 1px solid rgba(45, 212, 191, 0.3);
  border-radius: 6px;
  font-family: var(--cloto-font-ui);
  font-size: 0.78rem;
  line-height: 1.5;
  color: var(--cloto-text-70);
  z-index: 1000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.cw-infusion-tooltip .cw-fonte {
  font-style: italic;
  margin-top: 4px;
  color: var(--cloto-text-40);
}

/* ── Action buttons bar (centered) ── */
.cw-tessila-actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  justify-content: center;
  flex-shrink: 0;
  position: sticky;
  bottom: 0;
  z-index: 2;
  background: var(--cloto-glass-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--cloto-glass-border);
  margin: 0 calc(-1 * var(--space-10));
  padding: var(--space-4) var(--space-10);
}

.cw-tessila-btn {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: var(--space-3) var(--space-6);
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-sm);
  font-weight: 500;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-spring),
              border-color var(--duration-fast) var(--ease-spring);
}

/* "Accetta" — teal solid */
.cw-tessila-btn--accept {
  color: var(--cloto-surface-100);
  background: var(--cloto-teal);
  border-color: var(--cloto-teal);
}

.cw-tessila-btn--accept:hover {
  background: var(--cloto-teal-bright);
}

/* "Originale" — outline */
.cw-tessila-btn--revert {
  color: var(--cloto-text-60);
  background: transparent;
  border-color: var(--cloto-text-10);
}

.cw-tessila-btn--revert:hover {
  background: var(--cloto-text-6);
  border-color: var(--cloto-text-25);
}

/* "Modifica" — outline */
.cw-tessila-btn--edit {
  color: var(--cloto-text-60);
  background: transparent;
  border-color: var(--cloto-text-10);
}

.cw-tessila-btn--edit:hover {
  background: var(--cloto-text-6);
  border-color: var(--cloto-text-25);
}

/* ── Stats line (centered, below actions) ── */
.cw-tessila-stats {
  font-family: var(--cloto-font-ui);
  font-size: 0.75rem;
  color: var(--cloto-text-40);
  text-align: center;
  padding: var(--space-2) 0;
}

/* ── Granular review: element states ── */

/* Accepted: underline fades */
.cw-el-accepted {
  border-bottom-color: transparent;
  transition: border-color 0.4s ease-out;
}

/* Rejected: strikethrough + fade */
.cw-el-rejected {
  text-decoration: line-through;
  text-decoration-color: rgba(220, 80, 80, 0.6);
  opacity: 0.4;
  transition: opacity 0.4s ease-out;
}

/* Modified: dashed teal */
.cw-el-modified {
  border-bottom: 2px dashed var(--cloto-teal);
  background: var(--cloto-teal-a6);
}

/* Observation marker: gold dot in superscript */
.cw-observation-marker {
  display: inline;
  cursor: pointer;
}
.cw-observation-marker::after {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cloto-gold-a50, rgba(154, 126, 48, 0.5));
  margin-left: 2px;
  vertical-align: super;
}
.cw-observation-marker:hover::after {
  background: var(--cloto-gold);
}

/* ── Popover action buttons ── */
.cw-tip-actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--cloto-text-6);
}

.cw-tip-btn {
  min-height: 26px;
  padding: 2px 10px;
  font-family: var(--cloto-font-ui);
  font-size: 0.72rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-spring);
}

.cw-tip-btn--accept { color: var(--cloto-surface-100); background: var(--cloto-teal); }
.cw-tip-btn--accept:hover { background: var(--cloto-teal-bright); }
.cw-tip-btn--reject { color: #dc5050; border: 1px solid rgba(220,80,80,0.3); background: transparent; }
.cw-tip-btn--reject:hover { background: rgba(220,80,80,0.08); }
.cw-tip-btn--edit   { color: var(--cloto-text-60); border: 1px solid var(--cloto-text-10); background: transparent; }
.cw-tip-btn--edit:hover   { background: var(--cloto-text-6); }
.cw-tip-btn--ok     { color: var(--cloto-text-60); border: 1px solid var(--cloto-text-10); background: transparent; }
.cw-tip-btn--ok:hover     { background: var(--cloto-text-6); }

/* ── Review progress in action bar ── */
.cw-tessila-progress {
  font-family: var(--cloto-font-ui);
  font-size: 0.75rem;
  color: var(--cloto-text-40);
  margin-right: auto;
}

/* ── Confirm button (enabled/disabled) ── */
.cw-tessila-btn--confirm {
  color: var(--cloto-surface-100);
  background: var(--cloto-teal);
  border-color: var(--cloto-teal);
}
.cw-tessila-btn--confirm:hover:not(:disabled) {
  background: var(--cloto-teal-bright);
}
.cw-tessila-btn--confirm:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Discard button ── */
.cw-tessila-btn--discard {
  color: #dc5050;
  background: transparent;
  border-color: rgba(220,80,80,0.3);
}
.cw-tessila-btn--discard:hover {
  background: rgba(220,80,80,0.08);
}

/* ── Inline edit (contenteditable) ── */
.cw-inline-editing {
  outline: 1px dashed var(--cloto-teal);
  outline-offset: 2px;
  border-bottom: none;
  background: var(--cloto-teal-a6);
  min-width: 40px;
}
.cw-inline-edit-actions {
  display: inline-flex;
  gap: 4px;
  margin-left: 4px;
  vertical-align: middle;
}
.cw-inline-edit-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  font-size: 0.65rem;
  border-radius: 3px;
  border: 1px solid var(--cloto-text-10);
  background: var(--cloto-bg-20, #1a1a2e);
  color: var(--cloto-text-60);
  cursor: pointer;
  line-height: 1;
}
.cw-inline-edit-btn--ok { color: var(--cloto-teal); }
.cw-inline-edit-btn--cancel { color: #dc5050; }

/* ── Popover: decided state info ── */
.cw-tip-decided {
  font-size: 0.72rem;
  color: var(--cloto-text-40);
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.cw-tip-decided-label {
  font-style: italic;
}
.cw-tip-undo {
  color: var(--cloto-teal);
  cursor: pointer;
  text-decoration: underline;
  font-size: 0.72rem;
  background: none;
  border: none;
  padding: 0;
  font-family: var(--cloto-font-ui);
}

/* ── Workspace basic card (non-scene) ── */
.cw-ws-basic {
  padding: var(--space-10);
}

.cw-ws-basic-title {
  font-family: var(--cloto-font-brand);
  font-size: var(--cloto-fs-2xl);
  font-weight: 400;
  color: var(--cloto-text-100);
  line-height: 1.3;
  margin: 0 0 var(--space-6);
}

.cw-ws-basic-body {
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-base);
  color: var(--cloto-text-70);
  line-height: 1.8;
  white-space: pre-wrap;
}

.cw-ws-basic-empty {
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-base);
  font-style: italic;
  color: var(--cloto-text-25);
  padding: var(--space-16) 0;
  text-align: center;
}

/* ── Reveal footer ── */
.cw-reveal-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-6);
  padding: var(--space-12) 0;
  opacity: 0;
  transition: opacity 0.4s ease-out;
}

.cw-reveal-footer.is-visible {
  opacity: 1;
}

.cw-reveal-celebration {
  display: flex;
  align-items: center;
  gap: var(--space-4);
  font-family: var(--cloto-font-brand);
  font-size: var(--cloto-fs-md);
  font-style: italic;
  color: var(--cloto-text-40);
}

/* ── Readonly badge (spectator) ── */
.cw-ws-readonly {
  font-family: var(--cloto-font-ui);
  font-size: var(--cloto-fs-xs);
  color: var(--cloto-text-25);
  text-align: center;
  padding: var(--space-8) 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
}

/* ── Light Theme ── */
body.fd-light .cw-scene-textarea {
  border-color: var(--cloto-surface-a8);
}

body.fd-light .cw-scene-textarea:focus {
  border-color: var(--cloto-teal-a25);
}

body.fd-light .cw-scene-submit {
  color: #7a6220;
  background: rgba(154, 126, 48, 0.08);
  border-color: rgba(154, 126, 48, 0.20);
}

body.fd-light .cw-scene-submit:hover:not(:disabled) {
  background: rgba(154, 126, 48, 0.12);
  border-color: rgba(154, 126, 48, 0.25);
}

body.fd-light .cw-tessila-btn--accept {
  color: #fff;
}

body.fd-light .cw-infusion-tooltip {
  background: #f8f7f4;
  border-color: rgba(45, 212, 191, 0.25);
  color: var(--cloto-text-70);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

body.fd-light .cw-tessila-actions {
  background: rgba(255, 255, 255, 0.85);
  border-top-color: var(--cloto-surface-a8);
}

body.fd-light .cw-tip-btn--accept { color: #fff; }
body.fd-light .cw-observation-marker::after { background: rgba(154, 126, 48, 0.4); }
body.fd-light .cw-observation-marker:hover::after { background: #9a7e30; }
body.fd-light .cw-inline-edit-btn { background: #f8f7f4; }
body.fd-light .cw-tessila-btn--confirm { color: #fff; }

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .cw-el-accepted,
  .cw-el-rejected,
  .cw-el-modified,
  .cw-infusion,
  .cw-correction,
  .cw-tip-btn {
    transition: none;
  }
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .cw-scene {
    padding: var(--space-6);
  }

  .cw-scene-textarea {
    padding: var(--space-6);
    min-height: 160px;
    font-size: var(--cloto-fs-md);
  }

  .cw-scene-title {
    font-size: var(--cloto-fs-xl);
  }

  .cw-tessila-actions {
    flex-wrap: wrap;
    margin: 0 calc(-1 * var(--space-6));
    padding: var(--space-4) var(--space-6);
  }

  .cw-tessuto-view {
    padding: var(--space-6);
  }

  .cw-infusion-tooltip {
    max-width: calc(100vw - 32px);
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  .cw-scene-bar .cw-scene-save-dot.is-saving {
    animation: none;
  }

  .cw-scene-submit-spinner {
    animation: none;
  }

  .cw-infusion,
  .cw-correction {
    transition: none;
  }
}
