:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --ink: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #111827;
  --accent: #2563eb;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --info: #1d4ed8;
  --info-bg: #dbeafe;
  --gray-bg: #eceef1;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1115;
    --surface: #181b21;
    --ink: #f3f4f6;
    --muted: #9ca3af;
    --line: #2a2f38;
    --brand: #f3f4f6;
    --accent: #60a5fa;
    --ok: #4ade80; --ok-bg: #14301f;
    --warn: #fbbf24; --warn-bg: #36290e;
    --bad: #f87171; --bad-bg: #3a1717;
    --info: #93c5fd; --info-bg: #14233d;
    --gray-bg: #232830;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- Estructura ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar-in {
  max-width: 1120px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; text-decoration: none; color: var(--ink); }
.brand-dot { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: var(--bg); display: grid; place-items: center; font-size: 16px; }
.grow { flex: 1; }
.who { color: var(--muted); font-size: 14px; }
.page { max-width: 1120px; margin: 0 auto; padding: 24px 16px 64px; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.crumbs { color: var(--muted); font-size: 14px; margin-bottom: 6px; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { text-decoration: underline; }

/* ---------- Controles ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  padding: 8px 14px; border-radius: 10px; cursor: pointer; font-weight: 600; font-size: 14px;
  text-decoration: none; min-height: 38px;
}
.btn:hover { background: var(--gray-bg); }
.btn:focus-visible, .field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn-primary { background: var(--brand); color: var(--bg); border-color: var(--brand); }
.btn-primary:hover { background: var(--brand); opacity: .88; }
.btn-ok { background: var(--ok); color: #fff; border-color: var(--ok); }
.btn-ok:hover { background: var(--ok); opacity: .9; }
.btn-warn { background: var(--surface); color: var(--bad); border-color: var(--bad); }
.btn-warn:hover { background: var(--bad-bg); }
.btn-danger { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn-sm { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-ghost { border-color: transparent; background: transparent; }

.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > label, .field > .lbl { font-weight: 600; font-size: 14px; }
.field input[type=text], .field input[type=password], .field input[type=datetime-local], .field select, .field textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.field textarea { min-height: 120px; resize: vertical; }
.hint { color: var(--muted); font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.error-msg { color: var(--bad); background: var(--bad-bg); padding: 10px 12px; border-radius: 10px; font-size: 14px; margin-bottom: 12px; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.pad { padding: 18px; }

/* ---------- Chips y pestañas ---------- */
.chip { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--gray-bg); color: var(--muted); white-space: nowrap; }
.chip-draft { background: var(--gray-bg); color: var(--muted); }
.chip-pending { background: var(--warn-bg); color: var(--warn); }
.chip-approved { background: var(--ok-bg); color: var(--ok); }
.chip-changes { background: var(--bad-bg); color: var(--bad); }
.chip-published { background: var(--info-bg); color: var(--info); }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 18px; }
.tab { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 6px 14px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--muted); }
.tab[aria-selected="true"] { background: var(--brand); color: var(--bg); border-color: var(--brand); }
.tab .n { opacity: .7; margin-left: 4px; font-weight: 500; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login { width: 100%; max-width: 380px; }
.login h1 { margin: 14px 0 4px; }
.login p { color: var(--muted); margin: 0 0 20px; }

/* ---------- Tarjetas de clientes (admin) ---------- */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.client-card { padding: 18px; display: grid; gap: 12px; }
.client-top { display: flex; gap: 12px; align-items: center; }
.client-top .nm { font-weight: 700; }
.client-top .sub { color: var(--muted); font-size: 13px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.inactive { opacity: .6; }

/* ---------- Lista de publicaciones ---------- */
.post-card { overflow: hidden; display: flex; flex-direction: column; cursor: pointer; text-align: left; padding: 0; width: 100%; background: var(--surface); }
.post-card:hover { box-shadow: 0 4px 14px rgba(16, 24, 40, .12); }
.post-thumb { aspect-ratio: 1 / 1; background: var(--gray-bg); display: grid; place-items: center; color: var(--muted); position: relative; overflow: hidden; }
.post-thumb img, .post-thumb video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.post-thumb .fmt { position: absolute; top: 8px; left: 8px; background: rgba(17, 24, 39, .75); color: #fff; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.post-body { padding: 12px 14px 14px; display: grid; gap: 6px; }
.post-body .cap { color: var(--ink); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 14px; min-height: 42px; }
.post-meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }

/* ---------- Detalle ---------- */
.detail { display: grid; grid-template-columns: minmax(0, 520px) minmax(0, 1fr); gap: 24px; align-items: start; }
@media (max-width: 900px) { .detail { grid-template-columns: 1fr; } }
.panel { padding: 18px; display: grid; gap: 14px; }
.meta { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
.meta strong { color: var(--ink); }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

.thread { display: grid; gap: 10px; max-height: 420px; overflow: auto; padding-right: 4px; }
.msg { border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--surface); }
.msg .by { display: flex; gap: 8px; align-items: baseline; font-size: 13px; color: var(--muted); margin-bottom: 2px; }
.msg .by strong { color: var(--ink); }
.msg .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.client { background: var(--info-bg); border-color: transparent; }
.msg.k-approval { background: var(--ok-bg); border-color: transparent; }
.msg.k-changes { background: var(--bad-bg); border-color: transparent; }
.msg.system { background: transparent; border-style: dashed; color: var(--muted); font-size: 13px; }
.tagline { font-weight: 700; font-size: 13px; margin-bottom: 2px; }

/* ---------- Modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 50; display: grid; place-items: start center; overflow: auto; padding: 24px 12px; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 560px; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.modal.wide { max-width: 1020px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 20px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 24px; }
@media (max-width: 860px) { .editor { grid-template-columns: 1fr; } }
.preview-pane { background: var(--bg); border-radius: 12px; padding: 16px; display: flex; justify-content: center; align-items: flex-start; }
.preview-label { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: 8px; }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; }
.thumb { position: relative; width: 72px; height: 72px; border-radius: 8px; overflow: hidden; background: var(--gray-bg); border: 1px solid var(--line); }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 2px; right: 2px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(17, 24, 39, .85); color: #fff; cursor: pointer; line-height: 1; }
.avatar-sm { width: 44px; height: 44px; border-radius: 50%; overflow: hidden; background: var(--gray-bg); display: grid; place-items: center; font-weight: 700; flex: none; }
.avatar-sm img { width: 100%; height: 100%; object-fit: cover; }

/* ---------- Toasts ---------- */
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; width: min(92vw, 420px); }
.toast { background: var(--ink); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: var(--shadow); font-size: 14px; }
.toast.err { background: var(--bad); color: #fff; }

/* =====================================================================
   VISTAS PREVIAS (siempre en claro, como la red social real)
   ===================================================================== */
.pv-wrap { width: 100%; display: flex; justify-content: center; }
.pv { background: #fff; color: #262626; font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; width: 100%; max-width: 470px; border: 1px solid #dbdbdb; border-radius: 8px; overflow: hidden; font-size: 14px; line-height: 1.4; }
.pv * { box-sizing: border-box; }
.pv button { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; }
.pv-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; }
.pv-name { flex: 1; min-width: 0; }
.pv-name strong { font-weight: 600; }
.pv-sub { color: #65676b; font-size: 12px; display: flex; align-items: center; gap: 4px; }
.pv-more-dots { color: #262626; display: flex; }
.pv-avatar { border-radius: 50%; overflow: hidden; display: inline-grid; place-items: center; flex: none; background: #efefef; }
.pv-avatar img { width: 100%; height: 100%; object-fit: cover; }
.pv-avatar-fallback { background: linear-gradient(135deg, #f09433, #dc2743 60%, #bc1888); color: #fff; font-weight: 700; }
.pv-media { position: relative; background: #000; overflow: hidden; }
.pv-stage { position: absolute; inset: 0; }
.pv-cover { width: 100%; height: 100%; object-fit: cover; display: block; }
.pv-empty { position: absolute; inset: 0; display: grid; place-items: center; background: #efefef; color: #8e8e8e; font-size: 13px; }
.pv-screen .pv-empty { position: absolute; background: #262626; color: #a8a8a8; }
.pv-nav { position: absolute; top: 50%; transform: translateY(-50%); width: 26px; height: 26px; border-radius: 50%; background: rgba(255, 255, 255, .85) !important; color: #262626; display: grid; place-items: center; z-index: 3; }
.pv-prev { left: 8px; } .pv-next { right: 8px; }
.pv-counter { position: absolute; top: 10px; right: 10px; background: rgba(26, 26, 26, .75); color: #fff; font-size: 12px; padding: 2px 8px; border-radius: 12px; z-index: 3; }
.pv-dots { display: flex; justify-content: center; gap: 4px; padding: 8px 0 0; }
.pv-dots span { width: 6px; height: 6px; border-radius: 50%; background: #c7c7c7; }
.pv-dots span.on { background: #0095f6; }
.pv-actions { display: flex; align-items: center; gap: 14px; padding: 8px 12px 4px; }
.pv-actions .pv-spacer { flex: 1; }
.pv-actions span { display: flex; }
.pv-likes { padding: 0 12px; font-weight: 600; }
.pv-caption { padding: 4px 12px 0; overflow-wrap: anywhere; }
.pv-caption strong { font-weight: 600; }
.pv-more { color: #8e8e8e; }
.pv-tag { color: #00376b; }
.pv-date { padding: 6px 12px 12px; color: #8e8e8e; font-size: 10px; letter-spacing: .2px; }

.pv-reel { max-width: 320px; border-radius: 16px; border: 0; background: #000; }
.pv-screen { position: relative; aspect-ratio: 9 / 16; background: #1c1c1c; color: #fff; overflow: hidden; }
.pv-screen > video, .pv-screen > img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.pv-screen::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 45%; background: linear-gradient(transparent, rgba(0, 0, 0, .65)); pointer-events: none; }
.pv-reel-top { position: absolute; top: 12px; left: 14px; z-index: 2; font-size: 18px; }
.pv-playbtn { position: absolute; inset: 0; display: grid; place-items: center; z-index: 2; pointer-events: none; color: rgba(255, 255, 255, .9); }
.pv-side { position: absolute; right: 10px; bottom: 90px; z-index: 2; display: grid; gap: 18px; justify-items: center; }
.pv-bottom { position: absolute; left: 12px; right: 56px; bottom: 12px; z-index: 2; display: grid; gap: 8px; }
.pv-who { display: flex; align-items: center; gap: 8px; }
.pv-follow { border: 1px solid #fff; border-radius: 8px; padding: 1px 10px; font-size: 12px; font-weight: 600; }
.pv-reel .pv-caption { padding: 0; font-size: 13px; }
.pv-reel .pv-more { color: rgba(255, 255, 255, .75); }
.pv-reel .pv-tag { font-weight: 600; color: #fff; }
.pv-audio { font-size: 12px; display: flex; align-items: center; gap: 4px; opacity: .95; }

.pv-fb { border-radius: 8px; border-color: #ced0d4; }
.pv-fb .pv-caption { padding: 0 16px 12px; font-size: 15px; color: #050505; }
.pv-fb .pv-more { color: #65676b; font-weight: 600; }
.pv-fbtag { color: #216fdb; }
.pv-fb-single img, .pv-fb-single video { width: 100%; display: block; max-height: 640px; object-fit: cover; }
.pv-fb-grid { display: grid; gap: 2px; grid-template-columns: 1fr 1fr; }
.pv-fb-cell { position: relative; aspect-ratio: 1 / 1; background: #000; overflow: hidden; }
.pv-fb-cell img, .pv-fb-cell video { width: 100%; height: 100%; object-fit: cover; display: block; }
.pv-fb-grid-3 .pv-fb-cell:first-child { grid-column: 1 / -1; aspect-ratio: 2 / 1; }
.pv-fb-more { position: absolute; inset: 0; background: rgba(0, 0, 0, .5); color: #fff; display: grid; place-items: center; font-size: 32px; }
.pv-fb-bar { display: flex; justify-content: space-around; border-top: 1px solid #ced0d4; margin: 8px 12px 0; padding: 8px 0; color: #65676b; font-weight: 600; font-size: 14px; }
.pv-fb-bar span { display: inline-flex; align-items: center; gap: 6px; }
.pv-fb .pv-head + .pv-caption { padding-top: 0; }
