@import "tailwindcss";
@import "../../../node_modules/@37signals/lexxy/dist/stylesheets/lexxy-variables.css";
@import "../../../node_modules/@37signals/lexxy/dist/stylesheets/lexxy-editor.css";
@import "../../../node_modules/@37signals/lexxy/dist/stylesheets/lexxy-content.css";

@source "../../views";
@source "../../helpers";
@source "../../javascript";

@theme {
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}

@layer components {
  .btn { @apply inline-flex items-center gap-1 rounded-md bg-stone-800 px-3 py-1.5 text-sm font-medium text-white hover:bg-stone-700 cursor-pointer; }
  .btn-secondary { @apply inline-flex items-center gap-1 rounded-md border border-stone-300 bg-white px-3 py-1.5 text-sm text-stone-800 hover:bg-stone-50 cursor-pointer; }
  .btn-danger { @apply inline-flex items-center gap-1 rounded-md bg-red-700 px-3 py-1.5 text-sm text-white hover:bg-red-600 cursor-pointer; }
  .input { @apply block w-full rounded-md border border-stone-300 bg-white px-3 py-1.5 text-sm focus:border-stone-500 focus:outline-none; }
  .label { @apply mb-1 block text-sm font-medium text-stone-700; }
  .card { @apply rounded-lg border border-stone-200 bg-white p-4; }
  .h1 { @apply text-2xl font-serif font-semibold text-stone-900; }
  .h2 { @apply text-lg font-serif font-semibold text-stone-900; }
  .muted { @apply text-sm text-stone-500; }
  .badge { @apply inline-block rounded bg-stone-100 px-2 py-0.5 text-xs text-stone-700; }
  .table { @apply w-full text-sm; }
  .table th { @apply border-b border-stone-200 py-2 text-left font-medium text-stone-600; }
  .table td { @apply border-b border-stone-100 py-2 align-top; }
  .prose-book { @apply font-serif text-lg leading-relaxed text-stone-900; }
  .prose-book h1 { @apply text-2xl font-semibold my-4; }
  .prose-book h2 { @apply text-xl font-semibold my-3; }
  .prose-book p { @apply my-3; }
  .prose-book blockquote { @apply border-l-4 border-stone-300 pl-4 italic; }
  .prose-book ul { @apply list-disc pl-6; }
  .prose-book ol { @apply list-decimal pl-6; }
  .prose-book table { @apply border-collapse; }
  .prose-book td, .prose-book th { @apply border border-stone-300 px-2; }
  .diff-del { @apply bg-red-100 text-red-900 line-through; }
  .diff-ins { @apply bg-green-100 text-green-900 no-underline; }
}

/* Copertina del libro, formato 2:3 */
.book-cover {
  display: block; aspect-ratio: 2 / 3; object-fit: cover; border-radius: 3px;
  box-shadow: 0 1px 2px rgb(28 25 23 / 0.15), 0 4px 12px rgb(28 25 23 / 0.12);
}
.book-cover-blank {
  display: flex; align-items: center; justify-content: center; padding: 0.5rem; overflow: hidden;
  background: linear-gradient(160deg, var(--color-stone-700), var(--color-stone-900));
  border-left: 3px solid var(--color-stone-500);
}
.book-cover-title {
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden;
  font-family: var(--font-serif); font-size: 0.75rem; line-height: 1.25; text-align: center; color: var(--color-stone-100);
}

/* Albero del manoscritto con trascinamento */
.tree-list { display: flex; flex-direction: column; gap: 0.375rem; }
.tree-nested {
  margin: 0.375rem 0 0 1.25rem; padding: 0 0 0.25rem 0.75rem;
  border-left: 2px solid var(--color-stone-200); min-height: 0.5rem;
}
/* Parte vuota: zona di rilascio visibile */
.tree-nested:not(:has(> .tree-item)) {
  display: flex; align-items: center; min-height: 2.5rem; padding: 0 0.75rem;
  border: 1px dashed var(--color-stone-300); border-radius: 0.5rem;
}
.tree-nested:not(:has(> .tree-item))::before { content: attr(data-empty-text); font-size: 0.75rem; color: var(--color-stone-500); }
.tree-handle {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 1.75rem; height: 1.75rem; margin-left: -0.25rem; border-radius: 0.375rem;
  color: var(--color-stone-400); cursor: grab; touch-action: none;
}
.tree-handle:hover { background: var(--color-stone-100); color: var(--color-stone-700); }
/* Il segnaposto mostra dove cadrà la riga */
.tree-ghost > .tree-row { border: 2px dashed var(--color-stone-400); background: var(--color-stone-100); }
.tree-ghost > .tree-row > *, .tree-ghost > .tree-nested { visibility: hidden; }
/* La riga che segue il puntatore */
.tree-drag { opacity: 0.95 !important; list-style: none; }
.tree-drag > .tree-row { box-shadow: 0 10px 30px rgb(28 25 23 / 0.2); border-color: var(--color-stone-400); }
body.tree-dragging { user-select: none; -webkit-user-select: none; cursor: grabbing; }
body.tree-dragging .tree-handle { cursor: grabbing; }
body.tree-dragging .tree-nested { border-left-color: var(--color-stone-400); min-height: 1.5rem; }

/* Menu offcanvas (dialog modale) */
dialog.offcanvas {
  position: fixed; inset: 0 auto 0 0; margin: 0; padding: 0; border: 0;
  width: min(20rem, 88vw); max-width: none; height: 100dvh; max-height: none;
  background: #fff; color: inherit; box-shadow: 0 10px 40px rgb(28 25 23 / 0.2);
}
dialog.offcanvas[open] { animation: offcanvas-in 0.18s ease-out; }
dialog.offcanvas::backdrop { background: rgb(28 25 23 / 0.35); }
@keyframes offcanvas-in { from { transform: translateX(-100%); } to { transform: none; } }

/* Schermata di scrittura: pagina stile Word al centro, pannello di lato */
body.editor-page { background: var(--color-stone-100); }
.editor-body { display: flex; align-items: flex-start; }
.editor-desk { flex: 1 1 auto; min-width: 0; padding: 1rem 0.5rem 2rem; }
.page {
  margin: 0 auto; max-width: 816px; min-height: 70vh; padding: 2rem 1.25rem 4rem;
  background: #fff; border: 1px solid var(--color-stone-200); border-radius: 2px;
  box-shadow: 0 1px 2px rgb(28 25 23 / 0.06), 0 8px 28px rgb(28 25 23 / 0.07);
}
@media (min-width: 640px) {
  .editor-desk { padding: 2rem 1.5rem 3rem; }
  .page { min-height: 1056px; padding: 4rem 5.5rem 6rem; }
}
.page lexxy-editor { border: 0; border-radius: 0; background: transparent; --lexxy-editor-padding: 0; }
.page lexxy-toolbar { position: sticky; top: 3rem; z-index: 10; background: #fff; margin-bottom: 1rem; }
.page lexxy-editor .lexxy-editor__content { min-height: 60vh; }

.side-panel {
  position: fixed; inset: 0 0 0 auto; z-index: 40; width: min(22rem, 90vw);
  overflow-y: auto; padding: 1rem; background: var(--color-stone-50);
  box-shadow: -10px 0 40px rgb(28 25 23 / 0.2);
  transform: translateX(100%); visibility: hidden; transition: transform 0.18s ease-out, visibility 0.18s;
}
.side-panel[data-open] { transform: none; visibility: visible; }
.panel-backdrop { position: fixed; inset: 0; z-index: 35; background: rgb(28 25 23 / 0.35); }
.panel-backdrop[hidden] { display: none; }
@media (min-width: 1280px) {
  .side-panel {
    position: sticky; top: 3rem; z-index: auto; flex: 0 0 22rem; width: 22rem;
    max-height: calc(100vh - 3rem); padding: 2rem 1.5rem 2rem 0;
    background: transparent; box-shadow: none; transform: none; visibility: visible; transition: none;
  }
  .side-panel[data-collapsed] { display: none; }
  .panel-backdrop { display: none; }
}

/* Indice del libro: pannello a sinistra, separato dal menu */
.index-panel {
  position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(18rem, 85vw);
  display: flex; flex-direction: column; background: #fff;
  box-shadow: 10px 0 40px rgb(28 25 23 / 0.2);
  transform: translateX(-100%); visibility: hidden; transition: transform 0.18s ease-out, visibility 0.18s;
}
.index-panel[data-open] { transform: none; visibility: visible; }
.index-backdrop { position: fixed; inset: 0; z-index: 35; background: rgb(28 25 23 / 0.35); }
.index-backdrop[hidden] { display: none; }
.index-link {
  display: flex; align-items: center; gap: 0.5rem; padding: 0.375rem 0.5rem; border-radius: 0.375rem;
  color: var(--color-stone-800);
}
.index-link[hidden] { display: none; }
.index-link:hover { background: var(--color-stone-100); }
.index-link-current { background: var(--color-stone-200); font-weight: 600; }
.index-dot { flex-shrink: 0; width: 0.5rem; height: 0.5rem; border-radius: 9999px; background: var(--color-stone-300); }
.index-dot-draft { background: var(--color-amber-400); }
.index-dot-revision { background: var(--color-sky-400); }
.index-dot-final { background: var(--color-green-500); }
@media (min-width: 1280px) {
  body.editor-page .index-panel {
    top: 3rem; z-index: 20; width: 15rem; border-right: 1px solid var(--color-stone-200);
    box-shadow: none; transform: none; visibility: visible; transition: none;
  }
  body.editor-page .index-panel[data-collapsed] { display: none; }
  body.editor-page .index-backdrop { display: none; }
  body.editor-page:has(.index-panel:not([data-collapsed])) .writing-area { padding-left: 15rem; }
  body.editor-page .page { padding-left: 4rem; padding-right: 4rem; }
}
@media (min-width: 1536px) { body.editor-page .page { padding-left: 5.5rem; padding-right: 5.5rem; } }

/* Modalità Focus: solo l'editor di testo */
.focus-exit { display: none; }
body.focus-mode { background: #fff; }
body.focus-mode .chrome,
body.focus-mode .focus-hide,
body.focus-mode .panel-backdrop,
body.focus-mode lexxy-toolbar { display: none !important; }
body.focus-mode .editor-desk { padding: 0; }
body.focus-mode .writing-area { padding-left: 0 !important; }
body.focus-mode .index-backdrop { display: none !important; }
body.focus-mode .page {
  max-width: 42rem; min-height: 100vh; padding: 14vh 1.25rem 45vh;
  border: 0; box-shadow: none;
}
body.focus-mode .focus-exit {
  display: inline-flex; position: fixed; top: 0.75rem; right: 0.75rem; z-index: 50;
  padding: 0.35rem 0.75rem; border-radius: 9999px; border: 1px solid var(--color-stone-200);
  background: #fff; color: var(--color-stone-600); font-size: 0.8125rem; cursor: pointer;
  opacity: 0.4; transition: opacity 0.15s;
}
body.focus-mode .focus-exit:hover,
body.focus-mode .focus-exit:focus-visible { opacity: 1; }

/* Accesso, registrazione e password: modulo a sinistra, pannello scuro a destra */
@layer components {
  .auth-title { @apply font-serif text-4xl font-semibold tracking-tight text-stone-900; }
  .auth-lead { @apply mt-3 text-[0.9375rem] leading-relaxed text-stone-600; }
  .auth-form { @apply mt-8 space-y-4; }
  .auth-label { @apply mb-1.5 block text-sm font-medium text-stone-800; }
  .auth-input {
    @apply block w-full rounded-lg border border-stone-300 bg-white px-3.5 py-2.5 text-base text-stone-900 shadow-sm shadow-stone-900/5 transition;
    @apply placeholder:text-stone-400 hover:border-stone-400 focus:border-stone-800 focus:outline-none focus:ring-4 focus:ring-[#d9a441]/25;
  }
  .auth-hint { @apply mt-1.5 text-xs leading-relaxed text-stone-500; }
  .auth-btn {
    @apply mt-2 flex w-full cursor-pointer items-center justify-center rounded-lg bg-stone-900 px-4 py-3 text-base font-medium text-white shadow-md shadow-stone-900/15 transition;
    @apply hover:bg-stone-800 focus-visible:outline-none focus-visible:ring-4 focus-visible:ring-[#d9a441]/40 active:translate-y-px;
  }
  .auth-link { @apply font-medium text-stone-900 underline decoration-[#d9a441] decoration-2 underline-offset-4 hover:decoration-stone-900; }
  .auth-switch { @apply mt-8 border-t border-stone-200 pt-6 text-sm text-stone-600; }
}
.auth-form .field_with_errors { display: contents; }
.auth-form .field_with_errors .auth-input { border-color: var(--color-red-500); }
.auth-main #error_explanation { margin: 1.5rem 0 -0.5rem; border: 1px solid var(--color-red-200); border-radius: 0.5rem; }
.auth-panel {
  background:
    radial-gradient(60rem 36rem at 85% -10%, rgb(217 164 65 / 0.22), transparent 60%),
    radial-gradient(40rem 30rem at -10% 110%, rgb(217 164 65 / 0.10), transparent 60%),
    linear-gradient(160deg, var(--color-stone-800), var(--color-stone-950));
}
/* Lo screenshot esce dal bordo destro e dal fondo, come un foglio sul tavolo */
/* La prima riga dello screenshot (barra dell'app) è tagliata: resta la pagina di scrittura */
.auth-shot { filter: drop-shadow(0 30px 50px rgb(0 0 0 / 0.5)); }
.auth-shot img {
  display: block; width: 135%; max-width: none; margin-top: -4.5%;
  clip-path: inset(6.4% 0 0 0 round 0.75rem 0 0 0);
}
@media (prefers-reduced-motion: no-preference) {
  .auth-main > div { animation: auth-in 0.45s ease-out both; }
  .auth-shot img { animation: auth-shot-in 0.7s 0.1s ease-out both; }
}
@keyframes auth-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes auth-shot-in { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }
