/* ============================================================
   Repasse do Zero — Preview App
   Editorial limpo, mobile-first
   ============================================================ */

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

:root {
  /* Cores — paleta editorial */
  --bg: #fafaf7;
  --bg-elevated: #ffffff;
  --bg-sidebar: #1a1a1a;
  --bg-sidebar-hover: #2a2a2a;
  --bg-sidebar-active: #ffffff;
  --border: #e8e6e0;
  --border-strong: #d4d2cc;
  --text: #1a1a1a;
  --text-muted: #5a5a5a;
  --text-soft: #8a8a8a;
  --text-sidebar: #e8e6e0;
  --text-sidebar-muted: #8a8a8a;
  --text-sidebar-active: #1a1a1a;
  --accent: #c4731f;
  --accent-hover: #a35e15;
  --accent-soft: #fef4e6;

  /* Badges de fase */
  --phase-entrega: #1a1a1a;
  --phase-projeto: #6b6b6b;
  --phase-fonte: #8b6b3f;
  --phase-avatar: #5b46c4;
  --phase-produto: #2d8659;
  --phase-vsl: #c4731f;
  --phase-lp: #b04b6a;
  --phase-ads: #2d7a96;
  --phase-whatsapp: #25a05c;

  /* Tipografia */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  --font-serif: "Iowan Old Style", "Apple Garamond", Baskerville, "Times New Roman", "Droid Serif", Times, "Source Serif Pro", serif;
  --font-mono: "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;

  /* Spacing scale (8px base) */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  /* Z-index */
  --z-topbar: 50;
  --z-progress: 51;
  --z-watermark: 5;
  --z-backdrop: 100;
  --z-sidebar: 110;

  /* Layout */
  --topbar-h: 56px;
  --sidebar-w: 300px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  overflow-x: hidden;
  /* Permite seleção pra leitura (anti-download básico é só atalhos/right-click) */
}

/* ============================================================
   Watermark (sutil, atrás de tudo)
   ============================================================ */
.watermark {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) rotate(-25deg);
  font-size: clamp(14px, 4vw, 28px);
  letter-spacing: 0.2em;
  color: rgba(0, 0, 0, 0.04);
  font-weight: 700;
  pointer-events: none;
  white-space: nowrap;
  z-index: var(--z-watermark);
  user-select: none;
}

/* ============================================================
   Topbar (sticky)
   ============================================================ */
.topbar {
  position: sticky;
  top: 0;
  z-index: var(--z-topbar);
  display: flex;
  align-items: center;
  gap: var(--s3);
  height: var(--topbar-h);
  padding: 0 var(--s4);
  padding-top: env(safe-area-inset-top);
  background: rgba(250, 250, 247, 0.92);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
}

.menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin-left: -10px;
  background: transparent;
  border: none;
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  transition: background 150ms ease;
}
.menu-btn:active { background: var(--border); }

.topbar-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
}
.topbar-phase {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 2px;
}
.topbar-title h1 {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.topbar-counter {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.progress-bar {
  position: sticky;
  top: var(--topbar-h);
  z-index: var(--z-progress);
  height: 2px;
  background: transparent;
}
.progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 200ms ease;
}

/* ============================================================
   Layout (mobile = stack, desktop = sidebar + content)
   ============================================================ */
.layout {
  display: flex;
  min-height: calc(100vh - var(--topbar-h));
  min-height: calc(100dvh - var(--topbar-h));
}

/* ============================================================
   Sidebar (mobile = drawer, desktop = fixed)
   ============================================================ */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: min(85vw, var(--sidebar-w));
  height: 100vh;
  height: 100dvh;
  background: var(--bg-sidebar);
  color: var(--text-sidebar);
  z-index: var(--z-sidebar);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform 280ms cubic-bezier(0.32, 0.72, 0, 1);
  overflow: hidden;
}

.sidebar.open { transform: translateX(0); }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--s4) var(--s5);
  padding-top: max(var(--s4), env(safe-area-inset-top));
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--s3);
}
.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.02em;
}
.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}
.brand-text strong {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-sidebar);
}
.brand-text span {
  font-size: 11px;
  color: var(--text-sidebar-muted);
  margin-top: 2px;
}

.sidebar-close {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  color: var(--text-sidebar);
  font-size: 24px;
  cursor: pointer;
  border-radius: 6px;
}
.sidebar-close:active { background: var(--bg-sidebar-hover); }

.doc-list {
  flex: 1;
  overflow-y: auto;
  padding: var(--s3) var(--s2);
  -webkit-overflow-scrolling: touch;
}

.doc-item {
  display: flex;
  align-items: flex-start;
  gap: var(--s3);
  padding: var(--s3) var(--s3);
  border-radius: 8px;
  cursor: pointer;
  transition: background 120ms ease;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  color: var(--text-sidebar);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  margin-bottom: 2px;
}

.doc-item:hover { background: var(--bg-sidebar-hover); }
.doc-item:active { background: var(--bg-sidebar-hover); }
.doc-item.active {
  background: var(--bg-sidebar-active);
  color: var(--text-sidebar-active);
}
.doc-item.active .doc-num { color: var(--accent); }
.doc-item.active .doc-phase { opacity: 1; }

.doc-num {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-sidebar-muted);
  letter-spacing: 0.02em;
  flex-shrink: 0;
  min-width: 22px;
  padding-top: 2px;
}

.doc-info {
  flex: 1;
  min-width: 0;
}

.doc-phase {
  display: inline-block;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 2px 6px;
  border-radius: 3px;
  margin-bottom: 4px;
  color: white;
  opacity: 0.85;
}

.doc-title {
  font-size: 13px;
  font-weight: 500;
  line-height: 1.35;
}

.sidebar-footer {
  padding: var(--s4) var(--s5);
  padding-bottom: max(var(--s4), env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-sidebar-muted);
  font-size: 11px;
  line-height: 1.5;
  flex-shrink: 0;
}

.backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: var(--z-backdrop);
  opacity: 0;
  visibility: hidden;
  transition: opacity 280ms ease, visibility 280ms ease;
}
.backdrop.open {
  opacity: 1;
  visibility: visible;
}

/* ============================================================
   Content
   ============================================================ */
.content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 10;
}

.doc {
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: var(--s6) var(--s4) var(--s7);
  font-size: 17px;
  line-height: 1.7;
  color: var(--text);
}

.loading {
  text-align: center;
  padding: var(--s7) var(--s4);
  color: var(--text-muted);
  font-size: 14px;
}

/* ============================================================
   Markdown rendering — editorial typography
   ============================================================ */
.doc h1, .doc h2, .doc h3, .doc h4, .doc h5, .doc h6 {
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
  margin-top: var(--s6);
  margin-bottom: var(--s4);
  color: var(--text);
}

.doc > h1:first-child {
  margin-top: 0;
  font-size: clamp(28px, 6vw, 38px);
  letter-spacing: -0.03em;
  line-height: 1.15;
  padding-bottom: var(--s4);
  border-bottom: 2px solid var(--border-strong);
  margin-bottom: var(--s5);
}

.doc h1 { font-size: clamp(24px, 5vw, 32px); }
.doc h2 {
  font-size: clamp(20px, 4.2vw, 26px);
  margin-top: var(--s7);
  padding-top: var(--s5);
  border-top: 1px solid var(--border);
}
.doc h3 { font-size: clamp(18px, 3.6vw, 21px); }
.doc h4 { font-size: 17px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }

.doc p {
  margin-bottom: var(--s4);
  max-width: 65ch;
}

.doc strong { font-weight: 700; color: var(--text); }
.doc em { font-style: italic; }

.doc a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  word-break: break-word;
}
.doc a:hover { color: var(--accent-hover); }

.doc ul, .doc ol {
  margin-bottom: var(--s4);
  padding-left: var(--s5);
}
.doc li {
  margin-bottom: var(--s2);
  line-height: 1.65;
}
.doc li > ul, .doc li > ol {
  margin-top: var(--s2);
  margin-bottom: var(--s2);
}

.doc blockquote {
  border-left: 3px solid var(--accent);
  padding: var(--s3) var(--s4);
  margin: var(--s5) 0;
  background: var(--accent-soft);
  font-style: italic;
  color: var(--text);
  border-radius: 0 6px 6px 0;
}
.doc blockquote p:last-child { margin-bottom: 0; }
.doc blockquote strong { font-style: normal; }

.doc code {
  font-family: var(--font-mono);
  font-size: 0.88em;
  background: #f0ede5;
  padding: 2px 6px;
  border-radius: 4px;
  color: #1a1a1a;
  word-break: break-word;
}

.doc pre {
  background: #1a1a1a;
  color: #f0ede5;
  padding: var(--s4);
  border-radius: 8px;
  overflow-x: auto;
  margin: var(--s4) 0;
  font-size: 13px;
  line-height: 1.6;
  -webkit-overflow-scrolling: touch;
}
.doc pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

.doc hr {
  border: none;
  border-top: 1px solid var(--border-strong);
  margin: var(--s7) 0;
}

/* Tables — mobile-responsive */
.doc table {
  width: 100%;
  border-collapse: collapse;
  margin: var(--s5) 0;
  font-size: 14px;
  display: block;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 6px;
}
.doc table thead {
  background: #f4f1ea;
}
.doc table th {
  text-align: left;
  padding: var(--s3) var(--s4);
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}
.doc table td {
  padding: var(--s3) var(--s4);
  border-top: 1px solid var(--border);
  vertical-align: top;
}
.doc table tr:nth-child(even) td { background: #fbf9f4; }

/* Images & embeds */
.doc img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: var(--s4) 0;
}

/* ============================================================
   Pager (prev / next)
   ============================================================ */
.pager {
  display: flex;
  gap: var(--s3);
  max-width: 720px;
  width: 100%;
  margin: 0 auto;
  padding: var(--s4);
  padding-bottom: max(var(--s4), env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  bottom: 0;
  z-index: 20;
}

.pager-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  min-height: 48px;
  padding: 0 var(--s4);
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 150ms ease, transform 100ms ease;
  -webkit-tap-highlight-color: transparent;
}
.pager-btn:hover { background: #f4f1ea; }
.pager-btn:active:not(:disabled) { transform: scale(0.98); }
.pager-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.pager-btn-primary {
  background: var(--text);
  border-color: var(--text);
  color: white;
}
.pager-btn-primary:hover { background: #000; }

/* ============================================================
   Desktop layout (≥ 1024px)
   ============================================================ */
@media (min-width: 1024px) {
  .topbar { padding-left: calc(var(--sidebar-w) + var(--s5)); }
  .menu-btn { display: none; }
  .sidebar {
    position: fixed;
    transform: translateX(0);
    border-right: 1px solid rgba(255, 255, 255, 0.05);
  }
  .sidebar-close { display: none; }
  .backdrop { display: none; }
  .layout { padding-left: var(--sidebar-w); }
  .doc { padding: var(--s8) var(--s7) var(--s8); }
  .pager { padding: var(--s5) var(--s7); padding-bottom: var(--s5); }
}

/* ============================================================
   Reduce motion
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ============================================================
   Anti-print
   ============================================================ */
@media print {
  body::before {
    content: "Conteúdo confidencial — impressão bloqueada";
    display: block;
    text-align: center;
    padding: 40px;
    font-size: 24px;
  }
  .layout, .topbar, .progress-bar { display: none !important; }
}

/* Block selection of UI chrome */
.topbar, .sidebar, .pager, .watermark {
  user-select: none;
  -webkit-user-select: none;
}
