:root {
  --paper: #e7ebe8;
  --sheet: #fafbfa;
  --ink: #14201b;
  --ink-2: #4f5d57;
  --ink-3: #6f7c76;
  --line: #cdd5d0;
  --mat: #d6dcd8;
  --accent: #0d655d;
  --accent-hover: #0a4f49;
  --on-accent: #ffffff;
  --pending: #7a4f00;
  --pending-bg: #fbebc8;
  --done: #17663a;
  --done-bg: #d6eedd;
  --off: #55605b;
  --off-bg: #e0e5e2;
  --danger: #a32b1f;
  --sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --serif: "Newsreader", Georgia, "Times New Roman", serif;
  --r-card: 12px;
  --r-ctl: 7px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1513;
    --sheet: #171f1c;
    --ink: #e4ebe7;
    --ink-2: #a3b0aa;
    --ink-3: #7f8c86;
    --line: #2a3631;
    --mat: #0b100e;
    --accent: #4cc2b5;
    --accent-hover: #7fd8cd;
    --on-accent: #05211e;
    --pending: #f0c366;
    --pending-bg: #3a2d0c;
    --done: #7bd49b;
    --done-bg: #12301f;
    --off: #9aa6a0;
    --off-bg: #222c28;
    --danger: #ff9a8d;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 15px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }
h1, h2, h3 { margin: 0; line-height: 1.2; font-weight: 600; }
h1 { font-size: 24px; letter-spacing: -0.01em; }
h2 { font-size: 17px; }
h3 { font-size: 15px; }
code, pre { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
code { background: color-mix(in srgb, var(--ink) 8%, transparent); padding: 1px 5px; border-radius: 4px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0; white-space: nowrap;
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Barra superior ---------- */

.topbar {
  display: flex; align-items: center; gap: 28px;
  height: 56px; padding: 0 24px;
  background: var(--sheet); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 600; color: var(--ink); text-decoration: none; white-space: nowrap;
}
.brand-mark {
  position: relative; width: 18px; height: 18px;
}
.brand-mark::before, .brand-mark::after {
  content: ""; position: absolute; width: 12px; height: 12px; border-radius: 2px;
}
.brand-mark::before { left: 0; top: 0; border: 2px solid var(--ink); }
.brand-mark::after { right: 0; bottom: 0; background: var(--accent); }

.topnav { display: flex; gap: 4px; flex: 1; min-width: 0; overflow-x: auto; }
.topnav a {
  padding: 6px 12px; border-radius: var(--r-ctl);
  color: var(--ink-2); text-decoration: none; white-space: nowrap;
}
.topnav a:hover { color: var(--ink); }
.topnav a[aria-current="page"] { color: var(--ink); background: color-mix(in srgb, var(--ink) 8%, transparent); }
.logout { margin: 0; }

/* ---------- Botones ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: 500 14px/1 var(--sans);
  padding: 10px 14px; border-radius: var(--r-ctl);
  border: 1px solid var(--line); background: var(--sheet); color: var(--ink);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  transition: background-color .12s, border-color .12s;
}
.btn:hover { border-color: var(--ink-3); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-ghost:hover { border-color: var(--line); color: var(--ink); }
.btn-danger:hover { color: var(--danger); }
.btn-small { padding: 7px 10px; font-size: 13px; }
.btn[data-done] { background: var(--done-bg); border-color: var(--done); color: var(--done); }

/* ---------- Estructura del tablero ---------- */

.shell { display: grid; grid-template-columns: 248px minmax(0, 1fr); min-height: calc(100vh - 56px); }

.rail {
  position: sticky; top: 56px; align-self: start;
  height: calc(100vh - 56px); overflow: auto;
  padding: 20px 12px; border-right: 1px solid var(--line);
}
.rail h2 { font-size: 13px; font-weight: 500; color: var(--ink-3); margin: 0 12px 8px; }
.rail a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: var(--r-ctl);
  color: var(--ink); text-decoration: none;
}
.rail a:hover { background: color-mix(in srgb, var(--ink) 7%, transparent); }
.rail a[aria-current="page"] { background: var(--ink); color: var(--paper); }
.swatch { flex: none; width: 10px; height: 10px; border-radius: 3px; background: var(--c, var(--ink-3)); }
.count { margin-left: auto; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink-3); }
.rail a[aria-current="page"] .count { color: inherit; opacity: .75; }

.main { padding: 24px 28px 64px; min-width: 0; }
.main-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.filter { margin: 0; }
.filter select { width: auto; min-width: 190px; }

.tabs { display: flex; gap: 22px; margin: 18px 0 22px; border-bottom: 1px solid var(--line); }
.tabs a {
  padding: 8px 0 10px; margin-bottom: -1px;
  color: var(--ink-2); text-decoration: none; border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--accent); font-weight: 500; }
.tabs .n { margin-left: 4px; font-size: 13px; font-variant-numeric: tabular-nums; color: var(--ink-3); }

.grid {
  display: grid; gap: 20px; align-items: start;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 380px), 1fr));
}

/* ---------- Tarjeta de pieza ---------- */

.post {
  display: flex; flex-direction: column;
  background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-card);
  overflow: hidden; scroll-margin-top: 76px;
}
.post:target { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 30%, transparent); }

.mat {
  display: grid; place-items: center; width: 100%; height: 300px; padding: 16px;
  background: var(--mat); border: 0; border-bottom: 1px solid var(--line);
  cursor: zoom-in; overflow: hidden;
}
.mat img {
  display: block; width: auto; height: auto;
  max-width: 100%; max-height: 268px; /* alto de la mesa (300) menos el margen (2 x 16) */
  box-shadow: 0 1px 2px rgba(0, 0, 0, .2), 0 10px 28px -14px rgba(0, 0, 0, .45);
}

.post-main { padding: 16px 18px 6px; }
.post-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 12px; margin-bottom: 10px; font-size: 13px; color: var(--ink-2); }
.when { margin-left: auto; color: var(--ink-3); }

.chip {
  --pc: var(--ink-3);
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px; border: 1px solid var(--line); border-radius: 999px;
  font-weight: 500; color: var(--ink);
}
.chip i { width: 8px; height: 8px; border-radius: 50%; background: var(--pc); }
.chip[data-p="linkedin"] { --pc: #0a66c2; }
.chip[data-p="facebook"] { --pc: #1877f2; }
.chip[data-p="instagram"] { --pc: #c13584; }
.chip[data-p="tiktok"] { --pc: #00a3a3; }
.chip[data-p="x"] { --pc: var(--ink); }

.client-tag { display: inline-flex; align-items: center; gap: 7px; }

.state { padding: 2px 8px; border-radius: 999px; font-weight: 500; }
.state-publicado { background: var(--done-bg); color: var(--done); }
.state-descartado { background: var(--off-bg); color: var(--off); }

.post-title { margin-bottom: 8px; }

.copy {
  font: 400 17px/1.55 var(--serif);
  white-space: pre-wrap; overflow-wrap: anywhere;
  max-height: calc(1.55em * 8); overflow: hidden;
  max-width: 62ch;
}
.copy.open { max-height: none; }
.more {
  margin: 6px 0 0; padding: 0; border: 0; background: none;
  font: 500 13px var(--sans); color: var(--accent); cursor: pointer;
}
.more:hover { text-decoration: underline; }

.facts { display: flex; gap: 16px; flex-wrap: wrap; margin: 12px 0 0; font-size: 13px; color: var(--ink-2); }

.prompt { margin: 12px 0 4px; border-top: 1px solid var(--line); padding-top: 10px; }
.prompt summary { cursor: pointer; font-size: 13px; font-weight: 500; color: var(--ink-2); }
.prompt pre { margin: 10px 0; white-space: pre-wrap; overflow-wrap: anywhere; color: var(--ink-2); max-height: 240px; overflow: auto; }

.actions {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 14px 18px 16px;
}
.actions .grow, .grow { flex: 1; }
.inline { display: inline; margin: 0; }

.pager { display: flex; align-items: center; justify-content: center; gap: 16px; margin-top: 28px; color: var(--ink-2); }

.empty {
  max-width: 460px; margin: 56px auto; text-align: center; color: var(--ink-2);
}
.empty h2 { color: var(--ink); margin-bottom: 8px; }

/* ---------- Formularios ---------- */

label { display: block; font-size: 14px; font-weight: 500; color: var(--ink-2); }
input, select, textarea {
  display: block; width: 100%; margin-top: 6px;
  font: 400 15px/1.4 var(--sans); color: var(--ink);
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-ctl);
  padding: 9px 11px;
}
input[type="color"] { width: 52px; height: 40px; padding: 3px; cursor: pointer; }
input[type="file"] { padding: 7px; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

.stack { display: grid; gap: 14px; }
.narrow { max-width: 380px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.inline-form { display: flex; align-items: flex-end; gap: 12px; flex-wrap: wrap; }
.inline-form .grow { min-width: 200px; }

/* ---------- Diálogos ---------- */

dialog {
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  padding: 0; border: 1px solid var(--line); border-radius: 14px;
  background: var(--sheet); color: var(--ink);
}
dialog::backdrop { background: rgba(8, 14, 12, .6); }
.dialog-body { padding: 22px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 4px; }

.lightbox { width: auto; max-width: calc(100vw - 32px); background: var(--mat); padding: 16px; overflow: auto; }
.lightbox img { display: block; max-width: 100%; max-height: calc(100vh - 110px); margin: 0 auto; }
.lightbox-close { margin-bottom: 12px; }

/* ---------- Avisos ---------- */

.flash { max-width: 760px; margin: 16px auto 0; padding: 10px 14px; border-radius: var(--r-ctl); font-weight: 500; }
.flash-ok { background: var(--done-bg); color: var(--done); }
.flash-error { background: color-mix(in srgb, var(--danger) 14%, var(--sheet)); color: var(--danger); }
.warn { padding: 10px 14px; border-radius: var(--r-ctl); background: var(--pending-bg); color: var(--pending); }

/* ---------- Páginas de texto (clientes, conexión) ---------- */

.page { max-width: 820px; margin: 0 auto; padding: 32px 24px 80px; }
.lead { color: var(--ink-2); margin: 8px 0 24px; max-width: 62ch; }
.panel {
  background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-card);
  padding: 20px 22px; margin-bottom: 18px;
}
.panel h2 { margin-bottom: 14px; }
.panel h3 { margin: 22px 0 10px; }
.hint { margin: 12px 0; font-size: 14px; color: var(--ink-2); }

.field-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.field-label { width: 130px; font-size: 14px; color: var(--ink-2); }
.field-value { flex: 1; min-width: 0; padding: 8px 10px; overflow-wrap: anywhere; }

.steps { margin: 0 0 18px; padding-left: 20px; color: var(--ink-2); }
.steps li { margin-bottom: 6px; }

.fields { width: 100%; border-collapse: collapse; font-size: 14px; }
.fields th, .fields td { text-align: left; vertical-align: top; padding: 9px 10px; border-bottom: 1px solid var(--line); }
.fields th { font-weight: 500; color: var(--ink-3); }

.codeblock { position: relative; }
.codeblock pre {
  margin: 0 0 10px; padding: 14px; overflow: auto;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--r-ctl);
}

/* ---------- Acceso e instalación ---------- */

.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 24px; }
.auth {
  width: min(400px, 100%); padding: 28px;
  background: var(--sheet); border: 1px solid var(--line); border-radius: var(--r-card);
}
.auth h1 { font-size: 22px; }
.auth .lead { margin-bottom: 20px; }
.auth .warn { margin: 0 0 14px; }

/* ---------- Pantallas chicas ---------- */

@media (max-width: 860px) {
  .topbar { padding: 0 14px; gap: 12px; }
  .brand-name { display: none; }
  .topnav a { padding: 6px 8px; }
  .shell { grid-template-columns: 1fr; }
  .rail {
    position: static; height: auto; display: flex; gap: 6px; overflow-x: auto;
    padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line);
  }
  .rail h2 { display: none; }
  .rail a { white-space: nowrap; }
  .main { padding: 18px 14px 56px; }
  .row { grid-template-columns: 1fr; }
  .field-label { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
