:root {
  --bg: #f5f5f8;
  --surface: #ffffff;
  --surface-2: #f0f0f5;
  --border: #e2e2ea;
  --text: #1c1b29;
  --muted: #6b6a7d;
  --accent: #5b4bdb;
  --accent-soft: #ecebfd;
  --ok: #18865a;
  --ok-soft: #e3f5ec;
  --warn: #a15c00;
  --warn-soft: #fff3df;
  --err: #c0322b;
  --err-soft: #fde8e7;
  --draft: #6b6a7d;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 20, 40, .06), 0 2px 8px rgba(20, 20, 40, .04);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45; }
a { color: var(--accent); }
h1 { font-size: 1.45rem; margin: 0 0 4px; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 0 0 8px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- Barra superior ---------- */
.topbar {
  display: flex; align-items: center; gap: 20px; padding: 10px 24px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: #fff; font-size: .9rem; }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; white-space: nowrap; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.mode { font-size: .75rem; font-weight: 700; letter-spacing: .04em; padding: 4px 10px; border-radius: 99px; white-space: nowrap; }
.mode.sim { background: var(--warn-soft); color: var(--warn); }
.mode.real { background: var(--ok-soft); color: var(--ok); }

.container { max-width: 1240px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

/* ---------- Tarjetas y formularios ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.stack > * + * { margin-top: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > .field { flex: 1 1 160px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: .85rem; font-weight: 600; }
.field .hint { font-size: .8rem; color: var(--muted); font-weight: 400; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=number], select, textarea {
  font: inherit; color: inherit; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; min-height: 140px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.check { display: flex; gap: 8px; align-items: center; font-size: .92rem; }

.btn {
  font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 8px; padding: 8px 14px; cursor: pointer;
  background: var(--accent); color: #fff; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--surface); color: var(--err); border-color: #f2c4c1; }
.btn.small { padding: 5px 10px; font-size: .85rem; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.segmented { display: inline-flex; background: var(--surface-2); border-radius: 9px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.segmented button { font: inherit; border: 0; background: transparent; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); font-weight: 600; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Avisos ---------- */
.notice { border-radius: 8px; padding: 10px 12px; font-size: .9rem; }
.notice.err { background: var(--err-soft); color: var(--err); }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice.info { background: var(--accent-soft); color: var(--accent); }
.notice ul { margin: 0; padding-left: 18px; }
.notice .btn-row { margin-top: 8px; }

.pill { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px; white-space: nowrap; }
.pill.pending { background: var(--accent-soft); color: var(--accent); }
.pill.publishing { background: var(--warn-soft); color: var(--warn); }
.pill.published { background: var(--ok-soft); color: var(--ok); }
.pill.error { background: var(--err-soft); color: var(--err); }
.pill.draft { background: var(--surface-2); color: var(--draft); }
.pill.cancelled { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
.tag { font-size: .72rem; font-weight: 600; color: var(--muted); background: var(--surface-2); padding: 1px 7px; border-radius: 5px; }

.toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--text); color: #fff; padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; font-size: .9rem; }
.toast.err { background: var(--err); }

/* ---------- Login ---------- */
.login { max-width: 360px; margin: 12vh auto 0; }
.login .brand { justify-content: center; font-size: 1.2rem; margin-bottom: 20px; }

/* ---------- Calendario ---------- */
.week-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.day { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); min-height: 170px; padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.day.today { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.day-head { display: flex; justify-content: space-between; font-size: .8rem; font-weight: 700; color: var(--muted); text-transform: capitalize; }
.day-head .num { color: var(--text); }
.day-empty { color: var(--border); font-size: .8rem; margin: auto; }
.slot { display: flex; gap: 6px; align-items: center; padding: 5px; border-radius: 7px; background: var(--surface-2); text-decoration: none; color: inherit; border-left: 3px solid var(--accent); }
.slot:hover { filter: brightness(.97); }
.slot.published { border-left-color: var(--ok); }
.slot.error { border-left-color: var(--err); }
.slot.draft { border-left-color: var(--draft); border-left-style: dashed; }
.slot.cancelled { opacity: .5; border-left-color: var(--muted); }
.slot img, .slot video, .thumb-ph { width: 34px; height: 34px; border-radius: 5px; object-fit: cover; flex: none; background: var(--border); }
.slot .meta { min-width: 0; font-size: .78rem; line-height: 1.25; }
.slot .meta b { display: block; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 12px; overflow-x: auto; }
.tabs button { font: inherit; background: none; border: 0; padding: 8px 12px; cursor: pointer; color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs .count { font-size: .75rem; background: var(--surface-2); border-radius: 99px; padding: 0 7px; margin-left: 4px; }

.list { display: flex; flex-direction: column; }
.list-item { display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.list-item:last-child { border-bottom: 0; }
.list-item .thumb { width: 56px; height: 56px; border-radius: 7px; object-fit: cover; background: var(--surface-2); }
.list-item .title { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; font-weight: 600; }
.list-item .caption { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.list-item .error-text { color: var(--err); font-size: .85rem; }
.empty { text-align: center; color: var(--muted); padding: 28px 0; }

/* ---------- Editor ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 20px; align-items: start; }
.preview-col { position: sticky; top: 76px; }
.dropzone { border: 2px dashed var(--border); border-radius: var(--radius); padding: 18px; text-align: center; color: var(--muted); cursor: pointer; background: var(--surface-2); }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.media-strip { display: flex; gap: 10px; flex-wrap: wrap; }
.media-tile { position: relative; width: 104px; }
.media-tile img, .media-tile video { width: 104px; height: 104px; object-fit: cover; border-radius: 8px; display: block; background: var(--surface-2); border: 2px solid transparent; }
.media-tile.bad img, .media-tile.bad video { border-color: var(--err); }
.media-tile.warn img, .media-tile.warn video { border-color: #f0b44c; }
.media-tile .info { font-size: .72rem; color: var(--muted); margin-top: 3px; text-align: center; }
.media-tile .num { position: absolute; top: 4px; left: 4px; background: rgba(0,0,0,.65); color: #fff; font-size: .7rem; font-weight: 700; border-radius: 5px; padding: 0 6px; }
.media-tile .tools { position: absolute; top: 4px; right: 4px; display: flex; gap: 3px; }
.media-tile .tools button { border: 0; background: rgba(0,0,0,.65); color: #fff; width: 22px; height: 22px; border-radius: 5px; cursor: pointer; font-size: .8rem; line-height: 1; }
.counter { font-size: .8rem; color: var(--muted); text-align: right; }
.counter.over { color: var(--err); font-weight: 700; }
.ai-box { display: flex; gap: 8px; }
.ai-box input { flex: 1; }
.events { font-size: .82rem; max-height: 260px; overflow: auto; }
.events div { padding: 4px 0; border-bottom: 1px dashed var(--border); }
.events .error { color: var(--err); }
.events .warn { color: var(--warn); }

/* ---------- Vista previa ---------- */
.phone { background: #fff; border: 1px solid var(--border); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.ig-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; font-size: .85rem; font-weight: 600; }
.avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, #f9ce34, #ee2a7b, #6228d7); object-fit: cover; flex: none; }
.ig-frame { position: relative; background: #000; overflow: hidden; }
.ig-frame img, .ig-frame video { width: 100%; height: 100%; object-fit: cover; display: block; }
.ig-frame.contain img, .ig-frame.contain video { object-fit: contain; }
.ig-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #aaa; font-size: .9rem; background: var(--surface-2); }
.ig-actions { display: flex; gap: 14px; padding: 8px 12px 2px; font-size: 1.15rem; }
.ig-dots { display: flex; justify-content: center; gap: 4px; padding: 6px 0 0; }
.ig-dots i { width: 6px; height: 6px; border-radius: 50%; background: #c7c7cc; }
.ig-dots i.on { background: var(--accent); }
.ig-caption { padding: 4px 12px 12px; font-size: .85rem; white-space: pre-wrap; word-break: break-word; }
.ig-caption .more { color: var(--muted); }
.ig-nav { position: absolute; top: 50%; transform: translateY(-50%); border: 0; width: 28px; height: 28px; border-radius: 50%; background: rgba(255,255,255,.85); cursor: pointer; font-weight: 700; }
.ig-nav.prev { left: 8px; } .ig-nav.next { right: 8px; }
.ig-counter { position: absolute; top: 8px; right: 8px; background: rgba(0,0,0,.6); color: #fff; font-size: .72rem; border-radius: 99px; padding: 2px 8px; }

.story { position: relative; aspect-ratio: 9 / 16; background: #111; border-radius: 14px; overflow: hidden; box-shadow: var(--shadow); }
.story > img, .story > video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.story.cover > img, .story.cover > video { object-fit: cover; }
.safe { position: absolute; left: 0; right: 0; background: repeating-linear-gradient(45deg, rgba(255, 80, 80, .28) 0 8px, rgba(255, 80, 80, .14) 8px 16px); color: #fff; font-size: .7rem; font-weight: 700; display: flex; align-items: center; justify-content: center; text-shadow: 0 1px 2px #000; pointer-events: none; }
.safe.top { top: 0; height: 14%; align-items: flex-end; padding-bottom: 4px; }
.safe.bottom { bottom: 0; height: 20%; align-items: flex-start; padding-top: 4px; }
.story-bar { position: absolute; top: 8px; left: 8px; right: 8px; height: 3px; border-radius: 3px; background: rgba(255,255,255,.45); }
.story-user { position: absolute; top: 18px; left: 10px; display: flex; gap: 6px; align-items: center; color: #fff; font-size: .78rem; font-weight: 600; text-shadow: 0 1px 2px #000; }
.story-user .avatar { width: 24px; height: 24px; }
.reel-caption { position: absolute; left: 10px; right: 46px; bottom: 22%; color: #fff; font-size: .78rem; text-shadow: 0 1px 2px #000; white-space: pre-wrap; max-height: 3.8em; overflow: hidden; }
.preview-legend { font-size: .78rem; color: var(--muted); margin-top: 8px; }

/* ---------- Recorte ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(20, 20, 40, .55); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; padding: 18px; max-width: 760px; width: 100%; max-height: 94vh; overflow: auto; }
.crop-stage { position: relative; display: inline-block; max-width: 100%; cursor: crosshair; user-select: none; overflow: hidden; vertical-align: top; }
.crop-stage img { display: block; max-width: 100%; max-height: 62vh; }
.crop-box { position: absolute; border: 2px solid #fff; box-shadow: 0 0 0 9999px rgba(0,0,0,.55); pointer-events: none; }

/* ---------- Cuentas ---------- */
.accounts { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.account-head { display: flex; gap: 12px; align-items: center; }
.account-head .avatar { width: 48px; height: 48px; }
.dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: .85rem; margin: 12px 0; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; word-break: break-word; }

/* ---------- Carga masiva ---------- */
table.grid { width: 100%; border-collapse: collapse; font-size: .87rem; }
table.grid th, table.grid td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
table.grid th { font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
table.grid .thumbs { display: flex; gap: 3px; flex-wrap: wrap; max-width: 140px; }
table.grid .thumbs img, table.grid .thumbs video { width: 40px; height: 40px; object-fit: cover; border-radius: 5px; }
table.grid tr.bad td { background: #fff8f7; }
.table-wrap { overflow-x: auto; }
pre.sample { background: var(--surface-2); padding: 10px 12px; border-radius: 8px; font-size: .82rem; overflow-x: auto; }

@media (max-width: 980px) {
  .editor { grid-template-columns: 1fr; }
  .preview-col { position: static; max-width: 380px; }
  .week { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
  .container { padding: 16px; }
  .topbar { flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .nav { order: 3; flex-basis: 100%; }
  .week { grid-template-columns: 1fr; }
  .day { min-height: 0; }
  .list-item { grid-template-columns: 48px 1fr; }
  .list-item > :last-child { grid-column: 1 / -1; }
}
