:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: #e3e3e8;
  --accent: #5b4bff;
  --accent-ink: #ffffff;
  --ok: #1f9d55;
  --ok-bg: #e6f6ec;
  --warn: #c2410c;
  --warn-bg: #fff1e6;
  --wait: #8a6d00;
  --wait-bg: #fff8d6;
  --danger: #d12c2c;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; display: block; }
h1 { font-size: 24px; margin: 0 0 6px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 4px 0; }
code { background: #eee; padding: 1px 6px; border-radius: 6px; }
[hidden] { display: none !important; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- Topo ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: rgba(255,255,255,.9);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
}
.brand { font-weight: 700; color: var(--text); font-size: 16px; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav a { color: var(--muted); padding: 6px 10px; border-radius: 8px; font-weight: 500; font-size: 14px; }
.nav a:hover { background: var(--bg); text-decoration: none; color: var(--text); }
.nav a.on { color: var(--text); background: var(--bg); }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 64px; }
.narrow { max-width: 460px; margin: 0 auto; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

/* ---------- Avisos ---------- */
.flash { padding: 10px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }
.flash-ok { background: var(--ok-bg); color: #145c33; }
.flash-err { background: #fdecec; color: #8f1d1d; }

.empty {
  background: var(--surface); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 32px 20px; text-align: center; color: var(--muted);
}

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 600; font-size: 14px;
  cursor: pointer; text-decoration: none; transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: #fafafa; text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #4a3bf0; }
.btn-block { width: 100%; }
.btn-link-danger { background: none; border: none; color: var(--danger); font-weight: 500; padding: 6px 0; }
.btn-link-danger:hover { background: none; text-decoration: underline; }
.link { background: none; border: none; padding: 0; color: var(--muted); font: inherit; cursor: pointer; }

/* ---------- Formulários ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px; }
.form label, .field-label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 14px; }
.form input, .form select, .form textarea, .client-filter select, .note-form textarea {
  display: block; width: 100%; margin-top: 6px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; font-weight: 400; background: #fff; color: var(--text);
}
.form textarea, .note-form textarea { resize: vertical; min-height: 80px; }
.form input:focus, .form select:focus, .form textarea:focus, .note-form textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,75,255,.15);
}
.form fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 14px 14px 2px; margin: 0 0 16px; }
.form legend { font-weight: 700; padding: 0 6px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.field { margin-bottom: 14px; }
.field-label { margin-bottom: 8px; }

/* ---------- Login / instalação ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
body.guest .container { padding: 0; }
.auth-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 18px; padding: 28px; box-shadow: var(--shadow); border: 1px solid var(--line); }
.auth-card.wide { max-width: 520px; }

/* ---------- Layout ---------- */
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }
.grid-post { grid-template-columns: minmax(0, 1fr) 360px; }

/* ---------- Status ---------- */
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--bg); color: var(--muted); }
.chip:hover { text-decoration: none; }
.chip-pendente { background: var(--wait-bg); color: var(--wait); }
.chip-aprovado { background: var(--ok-bg); color: var(--ok); }
.chip-ajuste { background: var(--warn-bg); color: var(--warn); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }

.tabs { display: flex; gap: 6px; flex-wrap: wrap; }
.tab { padding: 7px 12px; border-radius: 999px; color: var(--muted); font-weight: 600; font-size: 14px; background: var(--surface); border: 1px solid var(--line); }
.tab span { display: inline-block; min-width: 20px; padding: 0 6px; margin-left: 4px; border-radius: 999px; background: var(--bg); font-size: 12px; text-align: center; }
.tab:hover { text-decoration: none; color: var(--text); }
.tab.on { background: var(--text); color: #fff; border-color: var(--text); }
.tab.on span { background: rgba(255,255,255,.2); }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.client-filter select { margin: 0; min-width: 200px; }

/* ---------- Lista do admin ---------- */
.post-list { display: grid; gap: 12px; }
.post-row {
  display: grid; grid-template-columns: 96px minmax(0,1fr) auto; gap: 16px; align-items: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
  border-left: 4px solid var(--line);
}
.post-row.status-pendente { border-left-color: #f2c94c; }
.post-row.status-aprovado { border-left-color: var(--ok); }
.post-row.status-ajuste { border-left-color: var(--warn); }
.thumb { position: relative; width: 96px; aspect-ratio: 4/5; border-radius: 10px; overflow: hidden; background: var(--bg); display: grid; place-items: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-count { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; padding: 1px 6px; border-radius: 999px; }
.thumb-empty { font-size: 12px; color: var(--muted); }
.post-row-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.caption-snippet { margin: 6px 0 0; color: #3a3a3c; font-size: 14px; white-space: pre-line; }
.note-box { margin-top: 10px; background: var(--warn-bg); border-radius: 10px; padding: 10px 12px; font-size: 14px; }
.note-box p { margin: 4px 0 0; }

/* ---------- Clientes ---------- */
.client-row { padding: 0; }
.client-row summary { list-style: none; cursor: pointer; padding: 16px 20px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; align-items: center; }
.client-row summary::-webkit-details-marker { display: none; }
.client-row[open] summary { border-bottom: 1px solid var(--line); }
.client-row .form, .client-row .delete-form { padding: 16px 20px 0; }
.client-row .delete-form { padding-bottom: 12px; }
.form-inline { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.row-actions { grid-column: 1 / -1; }

/* ---------- Upload de imagens ---------- */
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 10px; margin-bottom: 10px; }
.img-grid:empty { display: none; }
.img-tile { position: relative; aspect-ratio: 4/5; border-radius: 10px; overflow: hidden; background: var(--bg); border: 1px solid var(--line); }
.img-tile img { width: 100%; height: 100%; object-fit: cover; }
.img-tile:first-child::before { content: "capa"; position: absolute; top: 6px; left: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 999px; z-index: 1; }
#new-grid .img-tile:first-child::before { content: none; }
.new-badge { position: absolute; top: 6px; right: 6px; background: var(--accent); color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 999px; }
.img-tools { position: absolute; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; padding: 6px; background: linear-gradient(transparent, rgba(0,0,0,.55)); }
.img-tools button { width: 28px; height: 28px; border-radius: 50%; border: none; background: rgba(255,255,255,.92); cursor: pointer; font-size: 15px; line-height: 1; }
.img-tools button[data-remove], .img-tools button[data-r] { color: var(--danger); }
.dropzone {
  display: flex !important; flex-direction: column; align-items: center; gap: 4px; text-align: center;
  position: relative; border: 2px dashed var(--line); border-radius: 12px; padding: 22px 14px; cursor: pointer; font-weight: 400 !important;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--accent); background: rgba(91,75,255,.04); }
.dropzone input { position: absolute; width: 1px; height: 1px; opacity: 0; }

/* ---------- Histórico ---------- */
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.history li { border-left: 3px solid var(--line); padding: 2px 0 2px 10px; font-size: 14px; }
.history li.h-aprovado { border-left-color: var(--ok); }
.history li.h-ajuste { border-left-color: var(--warn); }
.history p { margin: 4px 0 0; background: var(--bg); padding: 8px 10px; border-radius: 8px; }
.steps { padding-left: 18px; margin: 0; color: #3a3a3c; }
.steps li { margin-bottom: 6px; }

/* ---------- Feed do cliente ---------- */
.feed-head { margin-bottom: 14px; }
.tabs-feed { margin-bottom: 26px; }
.feed { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 22px; align-items: start; }
.feed > .empty { grid-column: 1 / -1; }
@media (max-width: 980px) { .feed { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 620px) { .feed { grid-template-columns: 1fr; } }

.ig-card { background: var(--surface); border-radius: 12px; overflow: hidden; box-shadow: 0 1px 3px rgba(0,0,0,.06), 0 6px 20px rgba(0,0,0,.06); }

.carousel { position: relative; background: #111; }
.carousel-track { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.carousel-track::-webkit-scrollbar { display: none; }
.slide { flex: 0 0 100%; scroll-snap-align: start; aspect-ratio: 4 / 5; background: #111; position: relative; overflow: hidden; }
.slide img, .slide video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; display: block; background: #111; }
.slide img { cursor: zoom-in; }
.car-btn {
  position: absolute; top: 50%; transform: translateY(-50%);
  width: 32px; height: 32px; border-radius: 50%; border: none; cursor: pointer; padding: 0;
  background: #fff; color: #222; font-size: 20px; line-height: 1; display: grid; place-items: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.25);
}
.car-prev { left: 10px; }
.car-next { right: 10px; }
.car-counter { position: absolute; top: 10px; right: 10px; background: rgba(20,20,20,.72); color: #fff; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; }
.car-dots { position: absolute; bottom: 10px; left: 0; right: 0; display: flex; justify-content: center; gap: 5px; pointer-events: none; }
.car-dots span { width: 6px; height: 6px; border-radius: 50%; background: rgba(255,255,255,.5); }
.car-dots span.on { background: #fff; }
.car-expand {
  position: absolute; top: 10px; left: 10px; width: 30px; height: 30px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(20,20,20,.72); color: #fff; font-size: 15px; line-height: 1; display: grid; place-items: center;
  opacity: 0; transition: opacity .15s;
}
.carousel:hover .car-expand, .car-expand:focus-visible { opacity: 1; }
@media (hover: none) { .carousel:has(video) .car-expand { opacity: 1; } }

.ig-body { padding: 16px 14px 16px; text-align: center; }
.ig-title { font-size: 12.5px; font-weight: 600; color: #6b6b70; text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px; }
.ig-body > .chip { font-size: 12px; }
.ig-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 16px; }
.ig-actions form { display: contents; }
.ig-actions .btn { padding: 9px 6px; font-size: 14.5px; border-radius: 8px; white-space: nowrap; }
.btn-approve { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-approve:hover { background: #188547; }
.btn-approve:disabled { opacity: 1; background: var(--ok-bg); border-color: var(--ok-bg); color: var(--ok); }
.btn-note { color: var(--warn); border-color: #cfcfd4; }
.note-form { margin-top: 14px; text-align: left; }

/* Detalhe (aparece na tela ampliada) */
.pd-meta { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pd-title { text-align: left; margin-bottom: 4px; }
.pd-h { font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 16px 0 6px; }
.pd-caption { font-size: 14.5px; line-height: 1.6; white-space: normal; word-wrap: break-word; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 500; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 50; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }

/* ---------- Celular ---------- */
@media (max-width: 860px) {
  .grid-2, .grid-post { grid-template-columns: 1fr; }
  .form-inline { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .container { padding: 16px 12px 48px; }
  .form-row { grid-template-columns: 1fr; gap: 0; }
  .post-row { grid-template-columns: 72px minmax(0,1fr); gap: 12px; }
  .thumb { width: 72px; }
  .post-row-actions { grid-column: 1 / -1; }
  .post-row-actions .btn { width: 100%; }
  .feed { gap: 16px; }
  .tabs-feed { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .tabs-feed .tab { white-space: nowrap; }
  h1 { font-size: 21px; }
}

/* ---------- Postagem ampliada ---------- */
.lightbox { position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.92); display: flex; }
.lb-stage { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; padding: 48px 64px; }
.lb-media { max-width: 100%; max-height: 100%; display: flex; align-items: center; justify-content: center; }
.lb-el { max-width: 100%; max-height: calc(100vh - 96px); object-fit: contain; border-radius: 4px; display: block; }
.lb-side { width: 380px; flex: none; background: var(--surface); padding: 56px 22px 24px; overflow-y: auto; }
.lb-close, .lb-btn {
  position: absolute; border: none; cursor: pointer; color: #fff; background: rgba(255,255,255,.14);
  border-radius: 50%; display: grid; place-items: center; line-height: 1; z-index: 2;
}
.lb-close:hover, .lb-btn:hover { background: rgba(255,255,255,.28); }
.lb-close { top: 12px; right: 12px; width: 40px; height: 40px; font-size: 18px; background: rgba(0,0,0,.55); }
.lb-btn { top: 50%; transform: translateY(-50%); width: 46px; height: 46px; font-size: 30px; }
.lb-prev { left: 10px; }
.lb-next { right: 10px; }
.lb-counter { position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%); color: #fff; font-size: 14px; opacity: .8; }
body.lb-open { overflow: hidden; }
@media (max-width: 820px) {
  .lightbox { flex-direction: column; overflow-y: auto; }
  .lb-stage { flex: none; min-height: 70vh; padding: 56px 8px 56px; }
  .lb-el { max-height: 62vh; }
  .lb-btn { top: auto; bottom: 8px; transform: none; }
  .lb-prev { left: 16px; } .lb-next { right: 16px; }
  .lb-side { width: auto; padding: 20px 18px 32px; }
}

/* Miniaturas de vídeo no admin */
.thumb video, .img-tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.video-badge {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); pointer-events: none;
  width: 30px; height: 30px; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff;
  display: grid; place-items: center; font-size: 12px; padding-left: 2px;
}
