/* ═════════════════════════════════════════════════════════════════════════════
   Design System — Post Guide (Agentes de IA)
   andrecosta.dev
   ═════════════════════════════════════════════════════════════════════════════ */

/* ── TOKENS — Dark Mode (Factory.ai) ──────────────────────────────────────── */
:root {
  --ivory:   #000000;
  --paper:   #0C0C0D;
  --slate:   #FFFFFF;
  --clay:    #D45628;
  --clay-d:  #B8471E;
  --oat:     #212124;
  --olive:   #6B8C4E;
  --g100:    #161618;
  --g200:    #18181B;
  --g300:    #27272A;
  --g500:    #71717A;
  --g700:    #A1A1AA;

  --serif:   var(--font-display);
  --sans:    var(--font-body);
  --mono:    var(--font-mono);

  --radius:  4px;
  --border:  1px dashed var(--g300);
}

html.light-mode {
  --ivory:   #FAF9F6;
  --paper:   #F2F0EA;
  --slate:   #141413;
  --oat:     #E7E5E4;
  --g100:    #FFFFFF;
  --g200:    #F2F0EA;
  --g300:    #C9C5BF;
  --g500:    #B5B4B0;
  --g700:    #87867F;
}

.post-guide {
  background: var(--ivory);
  color: var(--slate);
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.75;
  overflow-x: hidden;
}

/* Reset para conflitos com .legal-prose */
.post-guide h1, .post-guide h2, .post-guide h3,
.post-guide p, .post-guide ul, .post-guide ol, .post-guide li,
.post-guide table, .post-guide pre, .post-guide code {
  margin: 0;
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  line-height: inherit;
  letter-spacing: inherit;
  color: inherit;
}

/* ── TIPOGRAFIA ──────────────────────────────────────────────────────────── */
.post-guide h1 {
  font-family: var(--serif);
  font-size: clamp(32px, 5vw, 48px);
  font-weight: 400;
  line-height: 1.15;
  letter-spacing: -0.02em;
  color: var(--slate);
  margin: 0 0 20px;
}

.post-guide h2 {
  font-family: var(--serif);
  font-size: clamp(26px, 3.5vw, 32px);
  font-weight: 400;
  line-height: 1.2;
  letter-spacing: -0.015em;
  color: var(--slate);
  margin: 48px 0 20px;
  padding-bottom: 12px;
  border-bottom: var(--border);
}

.post-guide h3 {
  font-family: var(--serif);
  font-size: clamp(20px, 2.5vw, 24px);
  font-weight: 500;
  line-height: 1.25;
  color: var(--slate);
  margin: 40px 0 14px;
}

.post-guide p {
  font-size: 17px;
  line-height: 1.75;
  color: var(--g700);
  margin-bottom: 16px;
  max-width: 720px;
}

.post-guide strong {
  color: var(--slate);
  font-weight: 600;
}

.post-guide a {
  color: var(--clay);
  text-decoration: underline;
  text-decoration-color: var(--oat);
  text-underline-offset: 3px;
  transition: all 0.2s ease;
}

.post-guide a:hover {
  color: var(--clay-d);
  text-decoration-color: var(--clay);
}

.post-guide code {
  font-family: var(--mono);
  font-size: 14px;
  background: var(--g100);
  color: var(--clay-d);
  padding: 2px 6px;
  border-radius: 6px;
  border: 1px solid var(--g200);
}

/* ── LISTAS ──────────────────────────────────────────────────────────────── */
.post-guide ul, .post-guide ol {
  margin: 0 0 20px 0;
  padding-left: 28px;
  max-width: 720px;
}

.post-guide li {
  font-size: 17px;
  line-height: 1.7;
  color: var(--g700);
  margin-bottom: 8px;
}

.post-guide li::marker {
  color: var(--clay);
}

/* ── BLOCKQUOTE ──────────────────────────────────────────────────────────── */
.post-guide blockquote {
  border-left: 3px solid var(--clay);
  padding: 12px 0 12px 20px;
  margin: 24px 0;
  color: var(--g700);
  font-style: italic;
  max-width: 720px;
}

.post-guide blockquote p {
  color: var(--g700);
  margin: 0;
}

/* ── HR ──────────────────────────────────────────────────────────────────── */
.post-guide hr {
  border: none;
  border-top: 1.5px solid var(--g300);
  margin: 48px 0;
}

/* ── DIAGRAMAS ───────────────────────────────────────────────────────────── */
.post-guide .diagram-container {
  margin: 32px 0 36px;
  border: var(--border);
  border-radius: var(--radius);
  background: var(--paper);
  padding: 32px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Neutralizar <p> fantasmas dentro de SVGs gerados pelo markdown parser */
.post-guide .diagram-container p {
  margin: 0;
  display: contents;
}

.post-guide svg.diagram {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Mobile: diagramas são clicáveis para abrir no modal — sem scroll horizontal */
@media (max-width: 640px) {
  .post-guide svg.diagram {
    min-width: auto;
    width: 100%;
  }

  .post-guide .diagram-container {
    overflow-x: visible;
    padding: 16px;
  }

  /* Reduzir fonte dos textos dentro do SVG para caber melhor */
  .post-guide svg.diagram text,
  .post-guide svg.diagram tspan {
    font-size: 10px;
  }

  .post-guide svg.diagram text.label-small,
  .post-guide svg.diagram tspan.label-small {
    font-size: 9px;
  }
}

/* Classes utilitárias para SVG */
.post-guide svg.diagram .box {
  fill: var(--paper);
  stroke: var(--g300);
  stroke-width: 1.5;
}

.post-guide svg.diagram .box.clay {
  fill: var(--paper);
  stroke: var(--clay);
}

.post-guide svg.diagram .box.olive {
  fill: var(--paper);
  stroke: var(--olive);
}

.post-guide svg.diagram .box.oat {
  fill: var(--oat);
  stroke: var(--g300);
}

.post-guide svg.diagram .box.accent {
  fill: var(--g100);
  stroke: var(--clay);
}

.post-guide svg.diagram .box.dark {
  fill: var(--slate);
  stroke: var(--slate);
}

.post-guide svg.diagram .box.dark text,
.post-guide svg.diagram .box.dark tspan {
  fill: var(--ivory);
}

.post-guide svg.diagram .arrow {
  stroke: var(--g500);
  stroke-width: 1.5;
  fill: none;
}

.post-guide svg.diagram .arrow.clay {
  stroke: var(--clay);
}

.post-guide svg.diagram .arrow.olive {
  stroke: var(--olive);
}

.post-guide svg.diagram .arrow.accent {
  stroke: var(--clay);
}

.post-guide svg.diagram .arrow.dashed {
  stroke-dasharray: 5 4;
}

.post-guide svg.diagram text,
.post-guide svg.diagram tspan {
  font-family: var(--mono);
  fill: var(--slate);
}

.post-guide svg.diagram text.label-small,
.post-guide svg.diagram tspan.label-small {
  font-size: 11px;
  fill: var(--g700);
}

/* Text color variants for SVG */
.post-guide svg.diagram text.accent-text,
.post-guide svg.diagram tspan.accent-text {
  fill: var(--clay);
}

.post-guide svg.diagram text.olive-text,
.post-guide svg.diagram tspan.olive-text {
  fill: var(--olive);
}

.post-guide svg.diagram text.muted-text,
.post-guide svg.diagram tspan.muted-text {
  fill: var(--g500);
}

/* Icon dots */
.post-guide svg.diagram circle.dot-clay {
  fill: var(--clay);
}

.post-guide svg.diagram circle.dot-olive {
  fill: var(--olive);
}

.post-guide svg.diagram circle.dot-muted {
  fill: var(--g500);
}

.post-guide svg.diagram circle.dot-oat {
  fill: var(--oat);
}

/* ── CODE BLOCKS ─────────────────────────────────────────────────────────── */
.post-guide pre {
  background: #1a1a18;
  color: #e8e6e1;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.7;
  border-radius: var(--radius);
  padding: 20px 24px;
  overflow-x: auto;
  margin: 32px 0;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.post-guide pre code {
  background: transparent;
  color: inherit;
  padding: 0;
  border: none;
  font-size: inherit;
}

/* Syntax highlighting */
.post-guide pre .kw { color: #c084fc; }
.post-guide pre .fn { color: #67e8f9; }
.post-guide pre .str { color: #a3e635; }
.post-guide pre .cm { color: #9ca3af; font-style: italic; }
.post-guide pre .num { color: #fbbf24; }
.post-guide pre .cls { color: #f472b6; }
.post-guide pre .var { color: #93c5fd; }

/* ── TABELAS ─────────────────────────────────────────────────────────────── */
.post-guide .table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: var(--border);
  margin: 24px 0 28px;
  background: var(--paper);
}

.post-guide table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14.5px;
  border: none;
  border-radius: 0;
  overflow: visible;
  background: transparent;
  display: table;
}

.post-guide table thead {
  position: sticky;
  top: 0;
  z-index: 2;
}

.post-guide table th {
  text-align: left;
  font-family: var(--mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--g500);
  padding: 12px 16px;
  background: var(--g100);
  border-bottom: 1.5px solid var(--g300);
  font-weight: 500;
  white-space: nowrap;
}

.post-guide table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--g200);
  color: var(--slate);
  line-height: 1.6;
}

.post-guide table tbody tr:nth-child(even) {
  background: var(--g100);
}

.post-guide table tbody tr:hover {
  background: var(--oat);
}

.post-guide table tbody tr:last-child td {
  border-bottom: none;
}

/* ── MODAL / LIGHTBOX (Mobile) ───────────────────────────────────────────── */
.post-guide .diagram-container,
.post-guide .table-wrap {
  position: relative;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.post-guide .diagram-container:hover,
.post-guide .table-wrap:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(20, 20, 19, 0.06);
}

/* Indicador de "toque para ampliar" — visível apenas em mobile */
.post-guide .diagram-container::after,
.post-guide .table-wrap::after {
  content: '';
  position: absolute;
  top: 8px;
  right: 8px;
  width: 28px;
  height: 28px;
  background: var(--slate);
  border-radius: var(--radius);
  opacity: 0;
  transform: scale(0.8);
  transition: opacity 0.2s ease, transform 0.2s ease;
  pointer-events: none;
  z-index: 3;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%23FAF9F5' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='15 3 21 3 21 9'%3E%3C/polyline%3E%3Cpolyline points='9 21 3 21 3 15'%3E%3C/polyline%3E%3Cline x1='21' y1='3' x2='14' y2='10'%3E%3C/line%3E%3Cline x1='3' y1='21' x2='10' y2='14'%3E%3C/line%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 14px;
}

.post-guide .diagram-container:hover::after,
.post-guide .table-wrap:hover::after {
  opacity: 0.7;
  transform: scale(1);
}

/* Mobile: mostrar indicador sempre */
@media (max-width: 640px) {
  .post-guide .diagram-container::after,
  .post-guide .table-wrap::after {
    opacity: 0.6;
    transform: scale(1);
  }
}

/* ── Modal Overlay ───────────────────────────────────────────────────────── */
.post-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.post-modal-overlay.is-open {
  opacity: 1;
  visibility: visible;
}

.post-modal-content {
  position: relative;
  background: var(--paper);
  border-radius: var(--radius);
  max-width: 95vw;
  max-height: 90vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding: 24px;
  transform: scale(0.92) translateY(20px);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: none;
}

.post-modal-overlay.is-open .post-modal-content {
  transform: scale(1) translateY(0);
}

/* No mobile, o modal ocupa quase toda a tela */
@media (max-width: 640px) {
  .post-modal-overlay {
    padding: 12px;
  }

  .post-modal-content {
    max-width: 100vw;
    max-height: 92vh;
    border-radius: var(--radius);
    padding: 16px;
  }

  .post-modal-content .diagram-container {
    padding: 12px;
  }
}

.post-modal-close {
  position: fixed;
  top: 16px;
  right: 16px;
  width: 44px;
  height: 44px;
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.1);
  border: none;
  color: var(--ivory);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1001;
  transition: background 0.2s ease, transform 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.post-modal-close:hover,
.post-modal-close:active {
  background: rgba(0, 0, 0, 0.9);
  transform: scale(1.05);
}

.post-modal-close svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
}

/* Conteúdo clonado dentro do modal */
.post-modal-content svg.diagram {
  display: block;
  max-width: 100%;
  max-height: 80vh;
  width: 100%;
  height: auto;
}

/* ── SVG no modal: replicar estilos do .post-guide (clone perde contexto) ── */
.post-modal-content svg.diagram .box {
  fill: var(--paper);
  stroke: var(--g300);
  stroke-width: 1.5;
}

.post-modal-content svg.diagram .box.clay {
  fill: var(--paper);
  stroke: var(--clay);
}

.post-modal-content svg.diagram .box.olive {
  fill: var(--paper);
  stroke: var(--olive);
}

.post-modal-content svg.diagram .box.oat {
  fill: var(--oat);
  stroke: var(--g300);
}

.post-modal-content svg.diagram .box.accent {
  fill: var(--g100);
  stroke: var(--clay);
}

.post-modal-content svg.diagram .arrow {
  stroke: var(--g500);
  stroke-width: 1.5;
  fill: none;
}

.post-modal-content svg.diagram .arrow.clay {
  stroke: var(--clay);
}

.post-modal-content svg.diagram .arrow.olive {
  stroke: var(--olive);
}

.post-modal-content svg.diagram text,
.post-modal-content svg.diagram tspan {
  font-family: var(--mono);
  fill: var(--slate);
}

.post-modal-content svg.diagram text.label-small,
.post-modal-content svg.diagram tspan.label-small {
  font-size: 11px;
  fill: var(--g700);
}

.post-modal-content svg.diagram text.accent-text,
.post-modal-content svg.diagram tspan.accent-text {
  fill: var(--clay);
}

.post-modal-content svg.diagram text.olive-text,
.post-modal-content svg.diagram tspan.olive-text {
  fill: var(--olive);
}

.post-modal-content svg.diagram text.muted-text,
.post-modal-content svg.diagram tspan.muted-text {
  fill: var(--g500);
}

.post-modal-content svg.diagram circle.dot-clay {
  fill: var(--clay);
}

.post-modal-content svg.diagram circle.dot-olive {
  fill: var(--olive);
}

.post-modal-content svg.diagram circle.dot-muted {
  fill: var(--g500);
}

.post-modal-content svg.diagram circle.dot-oat {
  fill: var(--oat);
}

/* No modal, o diagrama precisa ter scroll interno se for maior que a tela */
.post-modal-content .diagram-container {
  overflow: auto;
  max-width: none;
  width: auto;
  padding: 24px;
  border: none;
  background: transparent;
  margin: 0;
}

.post-modal-content .table-wrap {
  overflow: auto;
  border: none;
  margin: 0;
  border-radius: 0;
  background: transparent;
  max-width: 100%;
}

.post-modal-content .table-wrap::after,
.post-modal-content .diagram-container::after {
  display: none;
}

/* Hint no topo do modal */
.post-modal-hint {
  text-align: center;
  font-size: 12px;
  color: var(--g500);
  margin-bottom: 12px;
  font-family: var(--mono);
  letter-spacing: 0.04em;
}

/* ── RESPONSIVIDADE ──────────────────────────────────────────────────────── */
@media (max-width: 880px) {
  .post-guide .diagram-container {
    padding: 20px;
    margin: 24px 0;
    border-radius: var(--radius);
  }

  .post-guide h1 {
    font-size: 32px;
  }

  .post-guide h2 {
    font-size: 26px;
    margin-top: 48px;
  }

  .post-guide p, .post-guide li {
    font-size: 16px;
  }

  .post-guide pre {
    padding: 16px 20px;
    font-size: 13px;
    border-radius: var(--radius);
    margin-left: 0;
    margin-right: 0;
  }

  .post-guide table {
    border-radius: 0;
    margin-left: 0;
    margin-right: 0;
    border-left: none;
    border-right: none;
  }

  .post-guide .table-wrap {
    border-radius: var(--radius);
    margin-left: 0;
    margin-right: 0;
  }
}

@media (max-width: 640px) {
  .post-guide h1 {
    font-size: 28px;
    line-height: 1.2;
  }

  .post-guide h2 {
    font-size: 24px;
    margin-top: 40px;
    padding-bottom: 10px;
  }

  .post-guide h3 {
    font-size: 20px;
    margin-top: 32px;
  }

  .post-guide p, .post-guide li {
    font-size: 15.5px;
    line-height: 1.7;
  }

  .post-guide ul, .post-guide ol {
    padding-left: 22px;
  }

  .post-guide pre {
    padding: 14px 16px;
    font-size: 12.5px;
    border-radius: var(--radius);
  }

  .post-guide code {
    font-size: 13px;
  }

  .post-guide .diagram-container {
    padding: 16px;
    margin: 20px 0;
    border-radius: var(--radius);
  }

  .post-guide .table-wrap {
    border-radius: var(--radius);
    margin: 20px 0;
  }

  .post-guide table {
    font-size: 13.5px;
  }

  .post-guide table th,
  .post-guide table td {
    padding: 10px 12px;
  }

  .post-guide blockquote {
    padding: 10px 0 10px 16px;
    margin: 20px 0;
  }
}

@media (max-width: 480px) {
  .post-guide h1 {
    font-size: 26px;
  }

  .post-guide h2 {
    font-size: 22px;
  }

  .post-guide h3 {
    font-size: 19px;
  }

  .post-guide p, .post-guide li {
    font-size: 15px;
  }

  .post-guide .diagram-container {
    padding: 12px;
    margin: 16px 0;
    border-radius: var(--radius);
  }

  .post-guide pre {
    padding: 12px 14px;
    font-size: 12px;
    border-radius: 6px;
  }

  .post-guide code {
    font-size: 12px;
  }

  .post-guide .table-wrap {
    border-radius: var(--radius);
    margin: 16px 0;
  }

  .post-guide table {
    font-size: 12.5px;
  }

  .post-guide table th,
  .post-guide table td {
    padding: 8px 10px;
  }

  .post-guide ul, .post-guide ol {
    padding-left: 20px;
  }

  .post-guide blockquote {
    padding: 8px 0 8px 14px;
    margin: 16px 0;
  }

  .post-guide hr {
    margin: 36px 0;
  }
}

@media (max-width: 360px) {
  .post-guide h1 {
    font-size: 24px;
  }

  .post-guide h2 {
    font-size: 20px;
  }

  .post-guide p, .post-guide li {
    font-size: 14.5px;
  }

  .post-guide .diagram-container {
    padding: 10px;
  }

  .post-guide pre {
    padding: 10px 12px;
    font-size: 11.5px;
  }

  .post-guide table {
    font-size: 12px;
  }

  .post-guide table th,
  .post-guide table td {
    padding: 6px 8px;
  }

  .post-guide ul, .post-guide ol {
    padding-left: 18px;
  }

  .post-guide blockquote {
    padding: 6px 0 6px 12px;
    margin: 12px 0;
  }

  .post-guide code {
    font-size: 11px;
  }

  .post-guide .diagram-container {
    margin: 12px 0;
    border-radius: 6px;
  }

  .post-guide .table-wrap {
    margin: 12px 0;
    border-radius: 6px;
  }
}
