:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --ink: #111111;
  --ink-2: #5e5852;
  --ink-3: #9a938b;
  --line: #e6e0d8;
  --accent: #111111;
  --ig: #a8577a;
  --ig-soft: #f5e8ee;
  --tt: #2f7f7a;
  --tt-soft: #e2f0ee;
  --error: #b3261e;
  --error-soft: #fbe9e7;
  --warn: #8a5a00;
  --warn-soft: #fbf0d9;
  --ok: #2e6f4a;
  --today: #fbf6ea;
  --radius: 4px;
  --shadow: 0 1px 2px rgba(17, 17, 17, .04), 0 6px 20px rgba(17, 17, 17, .05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --brand: "Jost", "Futura", "Avenir Next", -apple-system, sans-serif;
  --serif: var(--brand);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  background: rgba(247, 243, 238, .94); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand img { height: 30px; width: auto; display: block; }
.brand em { color: var(--ink-3); font-style: normal; font-family: var(--brand); font-size: 11px; letter-spacing: .18em; text-transform: uppercase; border-left: 1px solid var(--line); padding-left: 14px; }
.tabs { display: flex; gap: 6px; }
.tab { border: 0; background: none; padding: 8px 10px 6px; cursor: pointer; color: var(--ink-3); font-family: var(--brand); font-size: 13px; letter-spacing: .14em; text-transform: uppercase; border-bottom: 1px solid transparent; }
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--ink); }
.sync { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.sync-time { color: var(--ink-3); font-size: 13px; }

.btn {
  border: 1px solid var(--ink); background: transparent; border-radius: 2px;
  padding: 7px 16px; cursor: pointer; white-space: nowrap; min-height: 36px;
  font-family: var(--brand); font-size: 12px; letter-spacing: .14em; text-transform: uppercase;
}
.btn:hover { background: var(--ink); color: var(--bg); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.btn-primary:hover { background: #2b2b2b; }
.btn-ghost { background: none; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: none; color: var(--ink); }
.btn[disabled] { opacity: .5; cursor: default; }

main { max-width: 1280px; margin: 0 auto; padding: 16px; }

/* Estados de carga / login / errores */
.center { min-height: 60vh; display: grid; place-items: center; text-align: center; color: var(--ink-2); }
.login { width: min(340px, 100%); text-align: center; }
.login .login-logo { width: 210px; max-width: 70%; height: auto; display: block; margin: 0 auto 26px; }
.login .rule { width: 40px; height: 1px; background: var(--ink); margin: 0 auto 18px; border: 0; }
.login p { margin: 0 0 30px; color: var(--ink-3); font-family: var(--brand); font-size: 11px; letter-spacing: .22em; text-transform: uppercase; }
.login input { width: 100%; padding: 12px 2px; border: 0; border-bottom: 1px solid var(--ink-3); border-radius: 0; margin-bottom: 22px; background: transparent; text-align: center; font-size: 16px; letter-spacing: .08em; }
.login input:focus { outline: none; border-bottom-color: var(--ink); }
.login .btn { width: 100%; min-height: 46px; }
.login-page { min-height: 78vh; }
.login .err { color: var(--error); margin: 10px 0 0; font-size: 14px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }

.banner { border-radius: var(--radius); padding: 10px 14px; margin-bottom: 12px; font-size: 14px; }
.banner-error { background: var(--error-soft); color: var(--error); }
.banner-warn { background: var(--warn-soft); color: var(--warn); }
.banner ul { margin: 4px 0 0; padding-left: 18px; }

/* Barra de herramientas del calendario */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-bottom: 12px; }
.toolbar h2 { font-family: var(--brand); font-weight: 300; font-size: 26px; letter-spacing: .02em; margin: 0; min-width: 9ch; }
.nav { display: flex; gap: 4px; }
.icon-btn { width: 36px; height: 36px; padding: 0; font-size: 16px; letter-spacing: 0; }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 2px; padding: 3px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 2px; cursor: pointer; color: var(--ink-2); }
.seg button.is-active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg button { font-family: var(--brand); font-size: 12px; letter-spacing: .12em; text-transform: uppercase; }
.spacer { flex: 1; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; align-items: center; }
.chip-toggle { border: 1px solid var(--line); background: var(--surface); border-radius: 2px; padding: 6px 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; min-height: 36px; }
.chip-toggle[aria-pressed="false"] { opacity: .45; }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none; }
.dot-instagram { background: var(--ig); }
.dot-tiktok { background: var(--tt); }
.filters select { border: 1px solid var(--line); background: var(--surface); border-radius: 2px; padding: 7px 30px 7px 12px; min-height: 36px; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%236b5f57'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; max-width: 100%; }
.filters select:disabled { opacity: .5; }
.filters select.is-set { border-color: var(--accent); }
.filter-hint { font-size: 12px; color: var(--ink-3); }
.count { font-size: 13px; color: var(--ink-3); margin-left: auto; }

/* Vista mensual */
.month { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.weekdays, .grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.weekdays div { padding: 10px 8px; font-family: var(--brand); font-size: 11px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .16em; border-bottom: 1px solid var(--line); }
.day { min-height: 118px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 6px; cursor: pointer; display: flex; flex-direction: column; gap: 4px; min-width: 0; background: none; border-top: 0; border-left: 0; text-align: left; }
.day:nth-child(7n) { border-right: 0; }
.day.is-out { background: #fbf9f6; }
.day.is-out .num { color: var(--ink-3); }
.day.is-today { background: var(--today); }
.day.is-selected { outline: 2px solid var(--accent); outline-offset: -2px; }
.num { font-size: 13px; color: var(--ink-2); }
.day.is-today .num { font-weight: 700; color: var(--ink); }
.dots { display: none; gap: 3px; flex-wrap: wrap; }

.post-chip { display: flex; align-items: center; gap: 5px; border: 0; width: 100%; text-align: left; padding: 3px 6px; border-radius: 6px; font-size: 12px; cursor: pointer; min-width: 0; }
.post-chip.instagram { background: var(--ig-soft); }
.post-chip.tiktok { background: var(--tt-soft); }
.post-chip .t { font-variant-numeric: tabular-nums; color: var(--ink-2); flex: none; }
.post-chip .c { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.flag { flex: none; font-size: 11px; line-height: 1; }
.flag-error { color: var(--error); }
.flag-aviso { color: var(--warn); }

/* Lista de un día / semana */
.agenda { margin-top: 14px; }
.agenda h3 { font-size: 15px; margin: 0 0 8px; color: var(--ink-2); font-weight: 600; }
.card { display: flex; gap: 12px; width: 100%; text-align: left; background: var(--surface); border: 1px solid var(--line); border-left: 4px solid var(--line); border-radius: var(--radius); padding: 10px; cursor: pointer; margin-bottom: 8px; align-items: flex-start; }
.card.instagram { border-left-color: var(--ig); }
.card.tiktok { border-left-color: var(--tt); }
.card:hover { box-shadow: var(--shadow); }
.thumb { width: 64px; height: 64px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex: none; display: grid; place-items: center; color: var(--ink-3); font-size: 11px; }
.card-body { min-width: 0; flex: 1; }
.card-meta { display: flex; flex-wrap: wrap; gap: 4px 8px; font-size: 12px; color: var(--ink-2); align-items: center; margin-bottom: 2px; }
.card-caption { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.pill { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--surface-2); color: var(--ink-2); }
.pill-error { background: var(--error-soft); color: var(--error); }
.pill-aviso { background: var(--warn-soft); color: var(--warn); }
.empty { color: var(--ink-3); font-size: 14px; padding: 6px 0 12px; }

.week { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 8px; }
.week-day { min-width: 0; }
.week-day h3 { font-size: 13px; margin: 0 0 6px; color: var(--ink-2); font-weight: 600; padding: 6px 8px; border-radius: 8px; }
.week-day.is-today h3 { background: var(--today); color: var(--ink); }
.week .card { flex-direction: column; gap: 6px; }
.week .thumb { width: 100%; height: auto; aspect-ratio: 4 / 5; }

/* Panel de problemas */
.issues { margin-top: 20px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 14px; }
.issues summary { cursor: pointer; padding: 10px 0; font-weight: 600; }
.issues .ok { color: var(--ok); }
.issue-row { display: flex; gap: 10px; padding: 8px 0; border-top: 1px solid var(--line); cursor: pointer; background: none; border-left: 0; border-right: 0; border-bottom: 0; width: 100%; text-align: left; align-items: flex-start; }
.issue-row ul { margin: 0; padding-left: 16px; font-size: 13px; }

/* Detalle */
.detail { border: 0; padding: 0; border-radius: var(--radius); width: min(640px, calc(100% - 32px)); max-height: calc(100% - 32px); box-shadow: 0 20px 60px rgba(0, 0, 0, .25); background: var(--surface); color: var(--ink); }
.detail::backdrop { background: rgba(43, 36, 32, .45); }
.detail-head { position: sticky; top: 0; background: var(--surface); padding: 16px 18px 10px; border-bottom: 1px solid var(--line); display: flex; gap: 10px; align-items: flex-start; }
.detail-head h2 { margin: 0; font-size: 19px; font-family: var(--brand); font-weight: 400; }
.detail-head .sub { color: var(--ink-2); font-size: 13px; }
.detail-head .close { margin-left: auto; }
.detail-body { padding: 14px 18px 22px; }
.section { margin-bottom: 16px; }
.section h4 { margin: 0 0 6px; font-family: var(--brand); font-weight: 500; font-size: 11px; text-transform: uppercase; letter-spacing: .16em; color: var(--ink-3); display: flex; align-items: center; gap: 8px; }
.section h4 .btn { padding: 2px 10px; min-height: 26px; font-size: 12px; text-transform: none; letter-spacing: 0; }
.text-block { white-space: pre-wrap; background: var(--bg); border-radius: 8px; padding: 10px 12px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tags span { background: var(--surface-2); border-radius: 999px; padding: 2px 10px; font-size: 13px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: 14px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; }
.problems { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.problems li { border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.problems .error { background: var(--error-soft); color: var(--error); }
.problems .aviso { background: var(--warn-soft); color: var(--warn); }
.assets { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.asset { border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.asset img, .asset .noimg { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; display: block; background: var(--surface-2); }
.asset .noimg { display: grid; place-items: center; color: var(--ink-3); font-size: 13px; }
.asset-info { padding: 8px; font-size: 12px; }
.asset-info strong { display: block; word-break: break-all; font-weight: 600; }
.asset-info span { color: var(--ink-3); display: block; word-break: break-word; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--accent); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 14px; z-index: 100; }

/* Celular */
@media (max-width: 760px) {
  main { padding: 12px 16px 40px; }
  .topbar { gap: 8px 12px; position: static; }
  .tabs { order: 3; width: 100%; }
  .tab { flex: 1; text-align: center; }
  .brand { font-size: 16px; }
  .brand em { display: none; }
  .brand img { height: 26px; }
  .sync .btn { min-height: 32px; padding: 5px 12px; font-size: 11px; }
  .sync-time { display: none; }
  .toolbar h2 { font-size: 19px; order: -1; width: 100%; }
  .day { min-height: 54px; padding: 4px; align-items: center; }
  .day .post-chip { display: none; }
  .dots { display: flex; justify-content: center; }
  .weekdays div { padding: 6px 2px; text-align: center; font-size: 11px; }
  .week { grid-template-columns: 1fr; }
  .week .card { flex-direction: row; }
  .week .thumb { width: 64px; height: 64px; aspect-ratio: auto; }
  .count { width: 100%; margin-left: 0; }
  .detail { width: 100%; max-width: 100%; max-height: 100%; height: 100%; border-radius: 0; margin: 0; }
}
@media (min-width: 761px) {
  .agenda.only-mobile { display: none; }
}

/* Biblioteca */
.lib-summary { display: flex; gap: 6px; flex-wrap: wrap; }
.pill-btn { border: 1px solid var(--line); background: var(--surface); border-radius: 2px; padding: 4px 12px; font-size: 13px; cursor: pointer; min-height: 32px; }
.pill-btn.warn { color: var(--warn); border-color: #ecd29a; background: var(--warn-soft); }
.pill-btn.is-set { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.search { flex: 1 1 220px; min-width: 0; border: 1px solid var(--line); background: var(--surface); border-radius: 2px; padding: 7px 14px; min-height: 36px; }
.lib-legend { font-size: 12px; color: var(--ink-3); margin: -6px 0 14px; }
.lib-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 12px; }
.lib-card { display: flex; flex-direction: column; text-align: left; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--surface); cursor: pointer; min-width: 0; }
.lib-card:hover { box-shadow: var(--shadow); }
.lib-card.no_asignado { border-color: #e6c27a; box-shadow: 0 0 0 1px #e6c27a; }
.lib-thumb { position: relative; display: block; aspect-ratio: 4 / 5; background: var(--surface-2); }
.lib-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.lib-thumb .noimg { position: absolute; inset: 0; display: grid; place-items: center; color: var(--ink-3); font-size: 12px; }
.badge-video, .badge-status { position: absolute; font-size: 11px; padding: 2px 8px; border-radius: 999px; }
.badge-video { left: 6px; bottom: 6px; background: rgba(0, 0, 0, .6); color: #fff; }
.badge-status { right: 6px; top: 6px; }
.badge-status.asignado { background: rgba(255, 255, 255, .92); color: var(--ok); }
.badge-status.no_asignado { background: var(--warn-soft); color: var(--warn); font-weight: 600; }
.lib-info { padding: 8px 10px 10px; font-size: 12px; min-width: 0; }
.lib-info strong { display: block; font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lib-info span { display: block; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.more { text-align: center; margin: 18px 0; }
.asset-big { width: 100%; min-height: 240px; max-height: 60vh; object-fit: contain; background: var(--surface-2); border-radius: var(--radius); margin-bottom: 14px; display: block; }
.asset-big.noimg { height: 200px; display: grid; place-items: center; color: var(--ink-3); }
@media (max-width: 760px) {
  .lib-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .filters .search { flex-basis: 100%; }
  .filters select[data-lib="folder"] { flex: 1 1 100%; }
}
.badge-status.publicado { background: rgba(255, 255, 255, .92); color: var(--ink-2); }
.lib-card.publicado .lib-thumb img { opacity: .75; }

/* Esta semana */
.wa-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 12px 14px; }
.stat b { display: block; font-size: 30px; font-family: var(--brand); font-weight: 300; line-height: 1.1; }
.stat span { color: var(--ink-2); font-size: 13px; }
.stat.warn b { color: var(--warn); }
.stat.ok b { color: var(--ok); }
.wa-day { margin-bottom: 18px; }
.wa-day h3 { font-size: 15px; margin: 0 0 8px; color: var(--ink-2); font-weight: 600; }
.wa-rel { background: var(--accent); color: var(--bg); border-radius: 2px; padding: 2px 8px; font-family: var(--brand); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; margin-right: 6px; vertical-align: 2px; }
.wa-item { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); margin-bottom: 10px; overflow: hidden; }
.wa-item .card { border: 0; border-left: 4px solid var(--line); border-radius: 0; margin: 0; }
.wa-item .card.instagram { border-left-color: var(--ig); }
.wa-item .card.tiktok { border-left-color: var(--tt); }
.wa-status { padding: 8px 12px 10px 16px; border-top: 1px solid var(--line); font-size: 13px; display: flex; flex-wrap: wrap; gap: 6px 16px; align-items: flex-start; }
.wa-when { color: var(--ink-2); white-space: nowrap; }
.wa-ok { color: var(--ok); font-weight: 600; }
.wa-missing { margin: 0; padding-left: 18px; color: var(--error); }
.wa-item.has-missing { border-color: #efc3bf; }
.banner a { color: inherit; font-weight: 600; }

/* Buscar */
.search-big { font-size: 16px; padding: 11px 16px; min-height: 46px; }
.sr-h { font-family: var(--brand); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .16em; color: var(--ink-3); margin: 20px 0 10px; }
.sr-h span { background: var(--surface-2); border-radius: 999px; padding: 1px 8px; color: var(--ink-2); margin-left: 4px; }
.doc-list { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.doc-row { display: block; padding: 10px 14px; border-top: 1px solid var(--line); text-decoration: none; color: var(--ink); }
.doc-row:first-child { border-top: 0; }
.doc-row:hover { background: var(--bg); }
.doc-row span { display: block; color: var(--ink-3); font-size: 12px; }
@media (max-width: 760px) {
  .tab { padding: 8px 2px 6px; font-size: 11px; letter-spacing: .1em; white-space: nowrap; }
}

/* Secciones de la biblioteca */
.lib-sections { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 8px; scrollbar-width: none; }
.lib-sections::-webkit-scrollbar { display: none; }
.lib-section { flex: none; display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface); border-radius: 2px; padding: 7px 14px; cursor: pointer; white-space: nowrap; min-height: 38px; }
.lib-section .n { color: var(--ink-3); font-size: 13px; }
.lib-section.is-active { background: var(--accent); border-color: var(--accent); color: var(--bg); }
.lib-section { font-family: var(--brand); font-size: 13px; letter-spacing: .04em; }
.lib-section.is-active .n { color: rgba(247, 243, 238, .7); }
.lib-summary { margin-bottom: 10px; }
.lib-legend { margin: 0 0 10px; }
.is-login .topbar { display: none; }
.banner-info { background: #eef0f3; color: var(--ink); }
.linklike { border: 0; background: none; padding: 0; color: inherit; font: inherit; font-weight: 600; text-decoration: underline; cursor: pointer; }
.wa-range { margin: -4px 0 12px; }
.toolbar a.btn { text-decoration: none; }
