:root {
  --ivory: #faf6ef;
  --paper: #ffffff;
  --sand: #ece2d2;
  --sand-2: #ddcfb8;
  --wood: #8a6a4f;
  --wood-dark: #5c4532;
  --ink: #2b2420;
  --muted: #7d7067;
  --gold: #ffcb79;
  --gold-dark: #e9ad4f;
  --ok: #3f7d52;
  --warn: #b07418;
  --err: #b0413e;
  --ig: #c13584;
  --fb: #1877f2;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 8px 24px rgba(60, 40, 20, .07);
  font-family: 'Nunito Sans', system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { display: flex; background: var(--ivory); font-size: 15px; }
h1, h2, h3 { font-family: 'Montserrat', sans-serif; margin: 0; letter-spacing: -.01em; }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 17px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
code { background: var(--sand); padding: 1px 6px; border-radius: 6px; font-size: 13px; }
a { color: var(--wood-dark); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; }
.gap { gap: 10px; }
.wrap { flex-wrap: wrap; }
.end { justify-content: flex-end; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* Barra lateral */
.side { width: 232px; flex-shrink: 0; background: var(--paper); border-right: 1px solid var(--sand); padding: 22px 16px; display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { width: 38px; height: 38px; border-radius: 12px; background: var(--wood-dark); color: var(--gold); display: grid; place-items: center; font-family: Montserrat; font-weight: 700; font-size: 19px; }
.brand strong { font-family: Montserrat; display: block; font-size: 15px; }
.brand small { color: var(--muted); }
nav { display: flex; flex-direction: column; gap: 2px; }
nav a { padding: 9px 12px; border-radius: 10px; text-decoration: none; color: var(--ink); font-weight: 600; }
nav a:hover { background: var(--ivory); }
nav a.active { background: var(--sand); }
.side-foot { margin-top: auto; font-size: 13px; color: var(--muted); line-height: 1.5; }
.side-foot .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; background: var(--sand-2); }
.side-foot .dot.on { background: var(--ok); }

main { flex: 1; overflow: auto; padding: 26px 30px 60px; }
.banner { background: #fff3dc; border: 1px solid var(--gold); padding: 10px 14px; border-radius: 12px; margin-bottom: 18px; font-size: 14px; }
.view-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; }
.view-head p { margin: 4px 0 0; }
.head-actions { display: flex; gap: 6px; }

/* Botones */
.btn { font: inherit; font-weight: 700; border: 1px solid var(--wood-dark); background: var(--wood-dark); color: #fff; padding: 9px 16px; border-radius: 11px; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-gold { background: var(--gold); border-color: var(--gold-dark); color: var(--ink); }
.btn-ghost { background: transparent; color: var(--ink); border-color: var(--sand-2); }
.btn-ghost:hover { background: var(--ivory); filter: none; }
.danger { color: var(--err); }
.icon-btn { border: 0; background: transparent; font-size: 26px; cursor: pointer; color: var(--muted); line-height: 1; }
.link { border: 0; background: none; color: var(--wood-dark); font: inherit; font-weight: 700; cursor: pointer; text-decoration: underline; padding: 0; }
.new-btn { width: 100%; }

/* Formularios */
label { display: flex; flex-direction: column; gap: 5px; font-weight: 600; font-size: 14px; margin-bottom: 10px; }
input, textarea, select { font: inherit; font-weight: 400; border: 1px solid var(--sand-2); border-radius: 10px; padding: 9px 11px; background: #fff; color: var(--ink); width: 100%; }
textarea { resize: vertical; line-height: 1.45; }
input:focus, textarea:focus { outline: 2px solid var(--gold); border-color: var(--gold-dark); }
.switch { flex-direction: row; align-items: center; gap: 10px; font-weight: 600; }
.switch input { width: 18px; height: 18px; accent-color: var(--wood-dark); }
details summary { cursor: pointer; font-weight: 700; margin-bottom: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* Calendario */
.planner { display: grid; grid-template-columns: 1fr 290px; gap: 20px; align-items: start; }
.calendar { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-week div { padding: 10px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); border-bottom: 1px solid var(--sand); }
.day { min-height: 118px; border-right: 1px solid var(--sand); border-bottom: 1px solid var(--sand); padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; }
.day:nth-child(7n) { border-right: 0; }
.day:hover { background: #fffaf2; }
.day.other { background: #fcfaf6; }
.day.other .day-n { opacity: .4; }
.day-n { font-size: 13px; font-weight: 700; width: 26px; height: 26px; display: grid; place-items: center; border-radius: 50%; }
.day.today .day-n { background: var(--gold); }
.chip { font-size: 12px; border-radius: 8px; padding: 4px 6px; background: var(--ivory); border-left: 3px solid var(--sand-2); display: flex; gap: 5px; align-items: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.chip .t { font-weight: 800; }
.chip span.name { overflow: hidden; text-overflow: ellipsis; }
.chip.scheduled { border-left-color: var(--gold-dark); background: #fff6e6; }
.chip.published { border-left-color: var(--ok); background: #eef6f0; }
.chip.error, .chip.partial { border-left-color: var(--err); background: #fbeeed; }
.chip.draft { border-left-style: dashed; }
.chip.publishing { border-left-color: var(--wood); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .55; } }
.mini-nets { display: inline-flex; gap: 2px; }
.net-badge { font-size: 9px; font-weight: 800; color: #fff; border-radius: 4px; padding: 1px 3px; }
.net-badge.ig { background: var(--ig); }
.net-badge.fb { background: var(--fb); }

.upcoming { display: flex; flex-direction: column; gap: 10px; }
.upcoming h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 6px; }
.item { background: var(--paper); border-radius: 12px; box-shadow: var(--shadow); padding: 10px; display: flex; gap: 10px; cursor: pointer; align-items: center; }
.item:hover { outline: 1px solid var(--sand-2); }
.item img, .item video, .item .ph { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; background: var(--sand); flex-shrink: 0; }
.item .meta { min-width: 0; font-size: 13px; }
.item .meta strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.empty { color: var(--muted); font-size: 13px; padding: 4px 2px; }

/* Historial */
.history { display: flex; flex-direction: column; gap: 10px; }
.h-row { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; display: grid; grid-template-columns: 64px 1fr auto; gap: 14px; align-items: center; }
.h-row img, .h-row video, .h-row .ph { width: 64px; height: 64px; border-radius: 10px; object-fit: cover; background: var(--sand); }
.h-row .res { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; font-size: 13px; }
.pill { border-radius: 999px; padding: 2px 9px; font-size: 12px; font-weight: 700; background: var(--sand); }
.pill.ok { background: #e3f1e7; color: var(--ok); }
.pill.err { background: #f8e3e2; color: var(--err); }
.pill.wait { background: #fff1d6; color: var(--warn); }
.h-row details { grid-column: 1 / -1; font-size: 13px; }

/* Conexión */
.setup { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 16px; align-items: start; }
.card { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card p { margin: 0 0 12px; }
.num { width: 22px; height: 22px; border-radius: 50%; background: var(--gold); display: inline-grid; place-items: center; font-size: 12px; }
.page-opt { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid var(--sand); border-radius: 12px; margin-bottom: 8px; cursor: pointer; flex-direction: row; font-weight: 400; }
.page-opt.sel { border-color: var(--gold-dark); background: #fff8ea; }
.page-opt img { width: 34px; height: 34px; border-radius: 50%; }
.page-opt input { width: auto; }

/* Métricas */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--paper); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.stat b { font-family: Montserrat; font-size: 26px; display: block; }
.stat span { color: var(--muted); font-size: 13px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; }
.m-card { background: var(--paper); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); text-decoration: none; color: inherit; }
.m-card img { width: 100%; aspect-ratio: 4/5; object-fit: cover; display: block; background: var(--sand); }
.m-card div { padding: 10px; font-size: 12px; display: flex; flex-wrap: wrap; gap: 4px 10px; }

/* Editor */
.overlay { position: fixed; inset: 0; background: rgba(43, 36, 32, .42); display: grid; place-items: center; z-index: 20; padding: 20px; }
.editor { background: var(--ivory); border-radius: 20px; width: min(1180px, 100%); height: min(860px, 100%); display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 30px 80px rgba(0,0,0,.25); }
.editor-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 22px; border-bottom: 1px solid var(--sand); background: var(--paper); }
.editor-body { flex: 1; display: grid; grid-template-columns: 1fr 380px; overflow: hidden; }
.editor-form { overflow: auto; padding: 18px 22px; }
.field { margin-bottom: 18px; }
.label { display: flex; justify-content: space-between; font-weight: 700; margin-bottom: 7px; }
.seg { display: inline-flex; background: var(--sand); border-radius: 12px; padding: 3px; gap: 2px; }
.seg button { font: inherit; font-weight: 700; border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; cursor: pointer; color: var(--ink); }
.seg button.on { background: var(--paper); box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.seg.small button { padding: 5px 12px; font-size: 13px; }
.nets { display: flex; gap: 10px; flex-wrap: wrap; }
.net { flex-direction: row; align-items: center; gap: 8px; border: 1px solid var(--sand-2); background: var(--paper); border-radius: 12px; padding: 8px 12px; margin: 0; cursor: pointer; }
.net input { width: auto; accent-color: var(--wood-dark); }
.net .net-badge { font-size: 11px; padding: 2px 5px; }
.drop { border: 1.5px dashed var(--sand-2); border-radius: var(--radius); padding: 12px; background: var(--paper); }
.drop.over { border-color: var(--gold-dark); background: #fff8ea; }
.thumbs { display: flex; gap: 10px; flex-wrap: wrap; }
.thumbs:not(:empty) { margin-bottom: 12px; }
.thumb { position: relative; width: 96px; cursor: grab; }
.thumb img, .thumb video { width: 96px; height: 120px; object-fit: cover; border-radius: 10px; display: block; background: var(--sand); }
.thumb .n { position: absolute; top: 5px; left: 5px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 800; border-radius: 6px; padding: 1px 6px; }
.thumb .x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; font-size: 14px; line-height: 1; }
.thumb small { display: block; font-size: 11px; color: var(--muted); margin-top: 3px; line-height: 1.3; }
.thumb.dragging { opacity: .4; }
.drop-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.drop-actions label { margin: 0; flex-direction: row; }
.checks { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.checks li::before { content: '•'; margin-right: 6px; font-weight: 800; }
.checks li.ok { color: var(--ok); }
.checks li.ok::before { content: '✓'; }
.checks li.warn { color: var(--warn); }
.checks li.warn::before { content: '!'; }
.checks li.err { color: var(--err); }
.checks li.err::before { content: '×'; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { font: inherit; font-size: 13px; font-weight: 700; border: 1px solid var(--sand-2); background: var(--paper); border-radius: 999px; padding: 5px 11px; cursor: pointer; }
.chips button:hover { border-color: var(--gold-dark); }
#when { width: auto; }
.log { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 3px; }
.editor-foot { display: flex; gap: 8px; padding: 14px 22px; border-top: 1px solid var(--sand); background: var(--paper); align-items: center; }

/* Vista previa */
.preview-col { background: var(--sand); padding: 18px; display: flex; flex-direction: column; align-items: center; gap: 14px; overflow: auto; }
.phone { width: 320px; background: #fff; border-radius: 34px; border: 8px solid #1d1a18; overflow: hidden; flex-shrink: 0; font-size: 13px; color: #111; font-family: -apple-system, 'Segoe UI', sans-serif; }
.p-top { display: flex; align-items: center; gap: 8px; padding: 10px 12px; }
.p-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--wood-dark) center/cover; flex-shrink: 0; }
.p-name { font-weight: 700; }
.p-sub { font-size: 11px; color: #777; }
.p-media { position: relative; background: #eee; overflow: hidden; }
.p-media img, .p-media video { width: 100%; height: 100%; object-fit: cover; display: block; }
.p-media.r45 { aspect-ratio: 4/5; }
.p-media.r916 { aspect-ratio: 9/16; }
.p-media .arrow { position: absolute; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(255,255,255,.85); cursor: pointer; font-size: 15px; }
.p-media .arrow.l { left: 8px; }
.p-media .arrow.r { right: 8px; }
.p-media .count { position: absolute; top: 10px; right: 10px; background: rgba(0,0,0,.6); color: #fff; border-radius: 10px; padding: 2px 8px; font-size: 11px; }
.p-dots { display: flex; justify-content: center; gap: 4px; padding: 8px 0 0; }
.p-dots i { width: 6px; height: 6px; border-radius: 50%; background: #ccc; }
.p-dots i.on { background: var(--fb); }
.p-actions { padding: 8px 12px 2px; font-size: 18px; letter-spacing: 8px; }
.p-caption { padding: 4px 12px 14px; white-space: pre-wrap; line-height: 1.4; word-wrap: break-word; }
.p-caption .more { color: #888; }
.p-empty { aspect-ratio: 4/5; display: grid; place-items: center; color: #999; background: #f3f3f3; text-align: center; padding: 20px; }
.p-story { position: relative; aspect-ratio: 9/16; background: #111; }
.p-story img, .p-story video { width: 100%; height: 100%; object-fit: cover; }
.p-story .bar { position: absolute; top: 8px; left: 8px; right: 8px; height: 2px; background: rgba(255,255,255,.5); border-radius: 2px; }
.p-story .who { position: absolute; top: 18px; left: 10px; display: flex; align-items: center; gap: 7px; color: #fff; font-weight: 700; font-size: 12px; text-shadow: 0 1px 3px rgba(0,0,0,.5); }
.p-story .reply { position: absolute; bottom: 12px; left: 10px; right: 10px; border: 1px solid rgba(255,255,255,.7); border-radius: 999px; color: #fff; padding: 7px 12px; font-size: 12px; }
.p-story .safe { position: absolute; left: 0; right: 0; border: 1px dashed rgba(255, 203, 121, .9); pointer-events: none; }
.p-reel-cap { position: absolute; left: 10px; right: 50px; bottom: 14px; color: #fff; text-shadow: 0 1px 3px rgba(0,0,0,.6); font-size: 12px; white-space: pre-wrap; max-height: 5.6em; overflow: hidden; }
.preview-note { font-size: 12px; color: var(--wood-dark); max-width: 320px; text-align: center; }

/* Biblioteca y diálogos */
.dialog { background: var(--paper); border-radius: 18px; padding: 22px; width: min(460px, 100%); box-shadow: 0 30px 80px rgba(0,0,0,.25); }
.dialog.wide { width: min(1000px, 100%); height: min(760px, 100%); padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.dialog h2 { margin-bottom: 8px; }
.crumbs { padding: 10px 22px; display: flex; gap: 6px; flex-wrap: wrap; font-size: 14px; border-bottom: 1px solid var(--sand); }
.crumbs button { border: 0; background: none; font: inherit; color: var(--wood-dark); font-weight: 700; cursor: pointer; padding: 0; }
.lib-grid { flex: 1; overflow: auto; padding: 16px 22px; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; align-content: start; }
.lib-item { border: 1px solid var(--sand); border-radius: 12px; overflow: hidden; cursor: pointer; background: var(--ivory); font-size: 12px; }
.lib-item:hover { border-color: var(--gold-dark); }
.lib-item.added { border-color: var(--ok); background: #eef6f0; }
.lib-item.added p { color: var(--ok); font-weight: 700; }
.lib-item .pv { aspect-ratio: 1; background: var(--sand); display: grid; place-items: center; font-size: 30px; }
.lib-item .pv img, .lib-item .pv video { width: 100%; height: 100%; object-fit: cover; }
.lib-item p { margin: 0; padding: 6px 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 40; }
.toast { background: var(--ink); color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14px; max-width: 420px; box-shadow: var(--shadow); }
.toast.err { background: var(--err); }

@media (max-width: 1000px) {
  .planner { grid-template-columns: 1fr; }
  .editor-body { grid-template-columns: 1fr; overflow: auto; }
  .editor-form { overflow: visible; }
  .preview-col { overflow: visible; }
}
@media (max-width: 720px) {
  body { flex-direction: column; }
  .side { width: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px 16px; }
  nav { flex-direction: row; flex-wrap: wrap; }
  .side-foot, .new-btn { display: none; }
  main { padding: 16px; }
  .day { min-height: 70px; }
  .chip span.name { display: none; }
  .grid2 { grid-template-columns: 1fr; }
}

/* Ingreso */
.auth-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { background: var(--paper); border-radius: 20px; box-shadow: var(--shadow); padding: 28px; width: min(400px, 100%); display: flex; flex-direction: column; gap: 4px; }
.auth-card .brand { margin-bottom: 16px; }
.auth-card h1 { font-size: 22px; margin-bottom: 10px; }
.auth-card p { margin: 0 0 12px; font-size: 14px; }
.auth-card .btn { margin-top: 6px; }
.auth-error { color: var(--err); font-weight: 700; }
