/* ═══════════════════════════════════════════════════════════
   LAYOUT.CSS — Estrutura do Livro, Página Dupla, Sombras
   Livro Secreto de Operações — Davi Azevedo
═══════════════════════════════════════════════════════════ */

/* ─── App Shell ─── */
#app {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* ─── Book Container ─── */
.book-container {
  width: 100%;
  height: 100vh;
  display: grid;
  grid-template-columns: 64px 1fr;
  grid-template-rows: 1fr;
  border-radius: 0;
  box-shadow: none;
  position: relative;
  overflow: hidden;
}

/* ─── Spine (Lombada) ─── */
.book-spine {
  background: linear-gradient(180deg,
    #3d2408 0%,
    #5c3810 15%,
    #3d2408 30%,
    #6b4415 50%,
    #3d2408 70%,
    #5c3810 85%,
    #3d2408 100%
  );
  border-right: 3px solid #8b5e20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--spacing-md) 0;
  position: relative;
  z-index: 10;
  box-shadow: inset -4px 0 12px rgba(0,0,0,0.4), 4px 0 8px rgba(0,0,0,0.3);
}

.book-spine::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: 50%;
  width: 1px;
  background: linear-gradient(180deg, transparent, rgba(184,132,30,0.4), transparent);
}

.spine-title {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-family: var(--font-title);
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--ink-gold);
  letter-spacing: 0.2em;
  text-shadow: 0 0 8px rgba(184,132,30,0.5);
  transform: rotate(180deg);
  user-select: none;
}

.spine-symbol {
  color: var(--ink-gold);
  font-size: 1.2rem;
  margin: var(--spacing-md) 0;
  opacity: 0.7;
}

/* ─── Page Area ─── */
.page-area {
  display: grid;
  grid-template-columns: 200px 1fr;
  background: var(--paper-bg);
  position: relative;
  overflow: hidden;
}

/* ─── Page Texture Overlay ─── */
.page-area::before {
  content: '';
  position: absolute;
  inset: 0;
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='400' height='400' filter='url(%23n)' opacity='0.06'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 100;
  opacity: 0.4;
}

/* ─── Paper Lines ─── */
.page-area::after {
  content: '';
  position: absolute;
  inset: 0;
  background-image: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 31px,
    rgba(90, 74, 50, 0.08) 31px,
    rgba(90, 74, 50, 0.08) 32px
  );
  pointer-events: none;
  z-index: 1;
}

/* ─── Navigation Panel ─── */
.nav-panel {
  background: linear-gradient(180deg,
    rgba(240, 230, 200, 0.95),
    rgba(220, 208, 176, 0.98)
  );
  border-right: 3px solid var(--ink);
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  z-index: 5;
  box-shadow: inset -2px 0 8px rgba(0,0,0,0.1);
}

/* ─── Content Panel ─── */
.content-panel {
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--spacing-xl) var(--spacing-xl) 80px var(--spacing-xl);
  position: relative;
  z-index: 2;
  background: linear-gradient(180deg,
    var(--parchment-light) 0%,
    var(--parchment) 100%
  );
}

/* ─── Page Transition ─── */
.content-panel {
  transition: opacity var(--flip-duration) ease, transform var(--flip-duration) ease;
  transform-origin: left center;
}

.content-panel.page-flip-out {
  opacity: 0;
  transform: perspective(1000px) rotateY(-15deg);
}

.content-panel.page-flip-in {
  animation: flipIn var(--flip-duration) ease forwards;
}

@keyframes flipIn {
  from {
    opacity: 0;
    transform: perspective(1000px) rotateY(15deg);
  }
  to {
    opacity: 1;
    transform: perspective(1000px) rotateY(0deg);
  }
}

/* ─── Page Number Footer ─── */
.page-footer {
  position: absolute;
  bottom: var(--spacing-md);
  right: var(--spacing-xl);
  font-family: var(--font-title);
  font-size: 0.75rem;
  color: var(--ink-faded);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--spacing-sm);
}

.page-footer::before {
  content: '';
  display: block;
  width: 40px;
  height: 1px;
  background: var(--ink-faded);
}

/* ─── Section Header ─── */
.section-header {
  border-bottom: 3px solid var(--ink);
  padding-bottom: var(--spacing-md);
  margin-bottom: var(--spacing-xl);
  position: relative;
}

.section-header::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 0;
  width: 60%;
  height: 1px;
  background: var(--ink-gold);
}

.section-chapter {
  font-family: var(--font-title);
  font-size: 0.7rem;
  color: var(--ink-red);
  letter-spacing: 0.3em;
  text-transform: uppercase;
  margin-bottom: var(--spacing-xs);
}

/* ─── Responsive Mobile Layout ─── */
@media (max-width: 1024px) {
  #app { padding: var(--spacing-sm); }

  .book-container {
    grid-template-columns: 48px 1fr;
    height: min(820px, 95vh);
  }

  .page-area {
    grid-template-columns: 160px 1fr;
  }

  .content-panel {
    padding: var(--spacing-lg);
  }
}

@media (max-width: 768px) {
  #app {
    padding: 0;
    align-items: stretch;
    min-height: 100vh;
  }

  /* Mobile Top Bar */
  .mobile-top-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 var(--spacing-md);
    background: var(--ink);
    color: var(--parchment-light);
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 900;
    box-shadow: 0 2px 10px rgba(0,0,0,0.5);
    border-bottom: 2px solid var(--ink-gold);
  }

  .mobile-menu-toggle {
    background: transparent;
    border: none;
    color: var(--ink-gold);
    font-size: 1.4rem;
    cursor: pointer;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
  }

  .mobile-brand {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-family: var(--font-title);
    font-size: 1rem;
    font-weight: 700;
    color: var(--parchment-light);
  }

  .mobile-brand__icon {
    font-size: 1.2rem;
  }

  .mobile-theme-btn {
    background: transparent;
    border: 1px solid rgba(212, 168, 48, 0.4);
    color: var(--ink-gold);
    font-size: 1.1rem;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .book-container {
    grid-template-columns: 1fr;
    height: 100vh;
    padding-top: 56px; /* Offset para a top bar */
    border-radius: 0;
    width: 100%;
    transform: none !important;
    animation: none !important;
  }

  .book-spine { display: none; }

  .page-area {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr;
    height: calc(100vh - 56px);
  }

  /* Navigation Panel vira Drawer Lateral/Sobreposição */
  .nav-panel {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: 285px;
    max-width: 85vw;
    height: 100vh;
    z-index: 1000;
    background: var(--parchment-light);
    border-right: 4px solid var(--ink);
    box-shadow: 10px 0 30px rgba(0,0,0,0.6);
    transform: translateX(-105%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
  }

  .nav-panel.mobile-open {
    transform: translateX(0);
  }

  .nav-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-md);
    background: var(--ink);
    color: var(--parchment-light);
    border-bottom: 2px solid var(--ink-gold);
  }

  .nav-drawer-header__title {
    font-family: var(--font-title);
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--ink-gold);
  }

  .nav-drawer-close-btn {
    background: transparent;
    border: none;
    color: var(--parchment-light);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 8px;
  }

  /* Backdrop escuro (atrás do nav-panel) */
  .nav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.65);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    z-index: 990;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

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

  .content-panel {
    padding: var(--spacing-md);
    height: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  .page-footer {
    position: relative;
    bottom: auto; right: auto;
    margin-top: var(--spacing-xl);
    padding: var(--spacing-md) 0;
    justify-content: center;
  }
}

@media (min-width: 769px) {
  .mobile-top-bar, .nav-backdrop, .nav-drawer-header {
    display: none !important;
  }
}
