/* ═══════════════════════════════════════════
   D4rk Sh3ll  —  Terminal Dark Theme v4
   ═══════════════════════════════════════════ */

/* ── Font retro estilo 8-bit (NES/Zelda) ──
   Press Start 2P, servida localmente (la CSP bloquea fuentes externas).
   Coloca el .ttf en static/fonts/. Ver README para la descarga.
   Se usa SOLO en banner y títulos para no sacrificar legibilidad del cuerpo. */
@font-face {
  font-family: 'Press Start 2P';
  src: url('../fonts/PressStart2P-Regular.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

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

:root {
  --bg:        #0d0d0d;
  --bg2:       #111111;
  --bg3:       #1a1a1a;
  --border:    #222222;
  --green:     #00ff41;
  --green-dim: #00cc33;
  --text:      #b8b8b8;
  --text-dim:  #666666;
  --white:     #e8e8e8;
  --red:       #ff4444;
  --radius:    3px;
  --font:      'Courier New', Courier, monospace;
  --font-retro:'Press Start 2P', 'Courier New', monospace;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.75;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--green); text-decoration: none; }
a:hover { color: var(--white); text-decoration: underline; }

/* ── Layout ── */
.wrapper {
  width: 100%;
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ── Header ── */
header {
  border-bottom: 1px solid var(--border);
  padding: 28px 0 18px;
}

/* Logo binario: 4 grupos arriba, 5 abajo */
.binary-logo {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-bottom: 18px;
}

.binary-logo span {
  color: var(--green);
  font-family: var(--font-retro);
  font-size: 11px;
  letter-spacing: 3px;
  opacity: .75;
  word-break: break-all;
  line-height: 1.8;
  text-shadow: 0 0 6px rgba(0, 255, 65, .35);
}

/* ── Nav ── */
nav ul {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 0;
}

nav > ul > li { position: relative; }

nav > ul > li > a,
nav > ul > li > form > button {
  display: inline-block;
  color: var(--green);
  font-size: 13px;
  letter-spacing: 1px;
  padding: 4px 14px 4px 0;
  transition: color .15s;
  text-decoration: none;
}

nav > ul > li > a:hover,
nav > ul > li > form > button:hover {
  color: var(--white);
  text-decoration: none;
}

/* Dropdown */
.has-dropdown { position: relative; }

.dropdown {
  display: block;                /* siempre presente para poder animar opacidad */
  visibility: hidden;
  opacity: 0;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 180px;
  z-index: 100;
  padding: 6px 0;
  /* Retardo al CERRAR: el menú tarda 0.5s en desaparecer tras quitar el cursor,
     dándote tiempo de sobra para hacer click. Al abrir es instantáneo. */
  transition: opacity .15s ease, visibility 0s linear .5s;
}

/* "Puente" invisible que cubre el hueco entre el item y el submenú,
   evitando que se cierre al cruzar ese espacio con el cursor. */
.has-dropdown::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 0;
  width: 180px;
  height: 8px;
}

.has-dropdown:hover .dropdown,
.has-dropdown:focus-within .dropdown {
  visibility: visible;
  opacity: 1;
  /* Al abrir, sin retardo. */
  transition: opacity .15s ease, visibility 0s;
}

.dropdown li a {
  display: block;
  padding: 6px 16px;
  font-size: 12px;
  color: var(--text);
  letter-spacing: .5px;
  white-space: nowrap;
}

.dropdown li a:hover { color: var(--green); background: var(--bg3); text-decoration: none; }

/* ── Main ── */
main { flex: 1; padding: 38px 0 60px; }

/* ── Typography ── */
h1, h2, h3, h4 { color: var(--white); line-height: 1.3; }

h2 {
  font-family: var(--font-retro);
  font-size: .92em;
  border-left: 3px solid var(--green);
  padding-left: 12px;
  margin-bottom: 26px;
  line-height: 1.5;
  text-shadow: 0 0 5px rgba(0, 255, 65, .25);
}

h3 {
  font-size: 1.05em;
  color: var(--green);
  margin: 22px 0 10px;
}

p { margin-bottom: 14px; }

pre, code {
  font-family: var(--font);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: #a8ff78;
  font-size: 13px;
}

code { padding: 1px 5px; }

pre {
  padding: 14px 16px;
  overflow-x: auto;
  margin: 16px 0;
  white-space: pre;
  line-height: 1.6;
}

pre code { background: none; border: none; padding: 0; }

/* ── Post content ── */
.post-content { line-height: 1.85; }
.post-content h3 { margin-top: 28px; }
.post-content p  { color: var(--text); }
.post-content a  { color: var(--green); }
.post-content img {
  max-width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 12px 0;
}

/* ── Post meta ── */
.post-meta {
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 24px;
  letter-spacing: .5px;
}

.post-meta span { margin-right: 14px; }

/* ── Blog / Manual list ── */
.post-list { list-style: none; }

.post-list li {
  padding: 22px 0;
  border-bottom: 1px solid var(--border);
}

.post-list li:first-child { padding-top: 0; }
.post-list li:last-child  { border-bottom: none; }

.post-list .post-title {
  font-size: 1em;
  font-weight: bold;
  color: var(--green);
  display: block;
  margin-bottom: 5px;
}

.post-list .post-title:hover { color: var(--white); }

.post-list .post-excerpt {
  font-size: 13.5px;
  color: #909090;
  margin-top: 7px;
}

/* ── Disclaimer ── */
.disclaimer {
  margin-top: 32px;
  padding: 13px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 12.5px;
  color: var(--text-dim);
}

/* ── Forms ── */
.field-group { margin-bottom: 18px; }

.field-group label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
  letter-spacing: .5px;
}

.field-group input,
.field-group textarea,
.field-group select {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--white);
  font-family: var(--font);
  font-size: 14px;
  padding: 9px 11px;
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s;
  appearance: none;
}

.field-group input:focus,
.field-group textarea:focus,
.field-group select:focus { border-color: var(--green); }

.field-group textarea { height: 130px; resize: vertical; }

/* ── Buttons ── */
.btn {
  display: inline-block;
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 22px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s, color .15s;
  letter-spacing: .5px;
  border: none;
}

.btn-primary {
  background: transparent;
  border: 1px solid var(--green);
  color: var(--green);
}

.btn-primary:hover { background: var(--green); color: #000; text-decoration: none; }

.btn-danger {
  background: transparent;
  border: 1px solid var(--red);
  color: var(--red);
}

.btn-danger:hover { background: var(--red); color: #000; }

.btn-sm { padding: 4px 12px; font-size: 12px; }

/* ── Flash messages ── */
.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 20px; font-size: 13px; }
.flash-success { background: #001a00; border: 1px solid var(--green); color: var(--green); }
.flash-error   { background: #1a0000; border: 1px solid var(--red);   color: var(--red); }

/* ── Footer ── */
footer {
  border-top: 1px solid var(--border);
  padding: 18px 0;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
}

/* ══════════════════════════════════════
   ADMIN PANEL
   ══════════════════════════════════════ */
.admin-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 28px;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.admin-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: normal;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  letter-spacing: .5px;
}

.admin-table td {
  padding: 10px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.admin-table td:last-child { white-space: nowrap; }
.admin-table tr:last-child td { border-bottom: none; }

/* ── Editor ── */
.editor-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

#content-editor {
  width: 100%;
  min-height: 360px;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--white);
  font-family: var(--font);
  font-size: 13.5px;
  padding: 12px;
  resize: vertical;
  border-radius: var(--radius);
  outline: none;
  line-height: 1.7;
}

#content-editor:focus { border-color: var(--green); }

#live-preview {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  min-height: 360px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.8;
}

#live-preview h3 { color: var(--green); margin: 16px 0 8px; }
#live-preview pre {
  background: var(--bg3); border: 1px solid var(--border);
  padding: 12px; overflow-x: auto; border-radius: var(--radius);
  margin: 10px 0; font-size: 13px; white-space: pre;
}
#live-preview code { background: var(--bg3); padding: 1px 5px; border-radius: 2px; }
#live-preview img  { max-width: 100%; border: 1px solid var(--border); border-radius: var(--radius); }
#live-preview a    { color: var(--green); }

.split-view { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-top: 6px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 5px; margin-bottom: 7px; }

.tool-btn {
  font-family: var(--font); font-size: 11px; padding: 3px 10px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: transparent; color: var(--text-dim); cursor: pointer;
}

.tool-btn:hover { border-color: var(--green); color: var(--green); }

.paste-hint { font-size: 11px; color: var(--text-dim); margin-top: 5px; }

/* ── Subcats subrow ── */
#cat-row, #subcat-row { transition: opacity .15s; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .binary-logo span { font-size: 10px; letter-spacing: 1px; }
  nav > ul > li > a { font-size: 12px; padding-right: 10px; }
  .dropdown { position: fixed; left: 14px; right: 14px; width: auto; }
  .editor-grid { grid-template-columns: 1fr; }
  .split-view  { grid-template-columns: 1fr; }
  .admin-table th:nth-child(3),
  .admin-table td:nth-child(3) { display: none; }
}

@media (max-width: 400px) {
  body { font-size: 14px; }
  .wrapper { padding: 0 14px; }
}

/* ══════════════════════════════════════
   ALINEACIÓN DE IMÁGENES EN CONTENIDO
   (clases permitidas por la allowlist de nh3)
   ══════════════════════════════════════ */
.post-content img.img-left,
#live-preview img.img-left {
  float: left; margin: 6px 18px 12px 0; max-width: 50%;
}
.post-content img.img-right,
#live-preview img.img-right {
  float: right; margin: 6px 0 12px 18px; max-width: 50%;
}
.post-content img.img-center,
#live-preview img.img-center {
  display: block; margin: 16px auto; max-width: 100%;
}
.post-content::after { content: ""; display: block; clear: both; }

/* ── Tamaño de imagen (clases size-NN, NN = % del ancho del contenedor) ──
   Se combinan con la alineación. El max-width manda sobre el de alineación
   gracias a la mayor especificidad de tener dos clases. */
.post-content img.size-25,  #live-preview img.size-25  { width: 25%;  max-width: 25%;  }
.post-content img.size-50,  #live-preview img.size-50  { width: 50%;  max-width: 50%;  }
.post-content img.size-75,  #live-preview img.size-75  { width: 75%;  max-width: 75%;  }
.post-content img.size-100, #live-preview img.size-100 { width: 100%; max-width: 100%; }

/* ══════════════════════════════════════
   SCROLL INFINITO — sentinel + spinner
   ══════════════════════════════════════ */
#scroll-sentinel { height: 1px; }

.infinite-loader {
  text-align: center;
  padding: 24px 0;
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 1px;
}
.infinite-loader::before {
  content: "▓▒░ ";
  color: var(--green);
  animation: blink 1s steps(2) infinite;
}
@keyframes blink { 50% { opacity: .3; } }

.infinite-end {
  text-align: center;
  padding: 22px 0;
  color: var(--text-dim);
  font-size: 12px;
}

/* ══════════════════════════════════════
   PERFIL
   ══════════════════════════════════════ */
.profile-box {
  max-width: 460px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.profile-box .user-tag {
  color: var(--green);
  font-size: 13px;
  margin-bottom: 20px;
  letter-spacing: 1px;
}

/* ══════════════════════════════════════
   LOGIN — caja centrada
   ══════════════════════════════════════ */
.login-box {
  max-width: 360px;
  margin: 40px auto;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
}
.login-box h2 { margin-bottom: 24px; }

/* ══════════════════════════════════════
   EDITOR — categoría / orden manuales
   ══════════════════════════════════════ */
.editor-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 16px;
}
@media (max-width: 640px) {
  .editor-meta { grid-template-columns: 1fr; }
}

.cat-order-list {
  list-style: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  background: var(--bg2);
}
.cat-order-list li {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  cursor: grab;
  display: flex;
  justify-content: space-between;
}
.cat-order-list li:last-child { border-bottom: none; }
.cat-order-list li.dragging { opacity: .4; }
.cat-order-list .handle { color: var(--text-dim); }

/* Índice numerado de manuales */
.manual-index {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg2);
  padding: 14px 18px;
  margin: 18px 0 26px;
}
.manual-index ol { margin-left: 20px; }
.manual-index li { margin: 4px 0; }
.manual-index .idx-title {
  color: var(--text-dim);
  font-size: 12px;
  letter-spacing: 1px;
  margin-bottom: 8px;
  display: block;
}
