/* Area agenzia */
:root {
  --bg: #f6f6f8; --surface: #fff; --fg: #16161a; --muted: #6b6b76; --line: #e3e3e8; --soft: #f0f0f4;
  --pri: #6d4aff; --pri-fg: #fff; --danger: #d6336c; --focus: #6d4aff55;
  --grad: linear-gradient(90deg, #6d4aff, #e1306c);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e0e11; --surface: #17171b; --fg: #ececf1; --muted: #9a9aa6; --line: #2a2a31; --soft: #202027;
    --pri: #8b6dff; --danger: #ff5c8d; --focus: #8b6dff66;
  }
}
:root[data-theme="dark"] {
  --bg: #0e0e11; --surface: #17171b; --fg: #ececf1; --muted: #9a9aa6; --line: #2a2a31; --soft: #202027;
  --pri: #8b6dff; --danger: #ff5c8d; --focus: #8b6dff66;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.45 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
h1 { font-size: 24px; margin: 0 0 4px; letter-spacing: -.3px; }
h2 { font-size: 18px; margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.loading { min-height: 60vh; display: grid; place-items: center; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--pri); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* barra in alto */
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; height: 56px; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--line); }
.logo { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 18px; letter-spacing: -.4px; text-decoration: none; }
.crumbs { display: flex; gap: 8px; align-items: center; color: var(--muted); min-width: 0; }
.crumbs a { text-decoration: none; }
.crumbs a:hover { color: var(--fg); }
.crumbs b { color: var(--fg); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top__user { margin-left: auto; display: flex; align-items: center; gap: 12px; color: var(--muted); }
@media (max-width: 600px) { .top { padding: 0 12px; gap: 10px; } }

/* bottoni e campi */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 38px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); font: 600 14px var(--font); text-decoration: none; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .4; cursor: default; }
.btn--sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn--pri { background: var(--pri); border-color: var(--pri); color: var(--pri-fg); }
.btn--pri:hover { filter: brightness(1.08); border-color: var(--pri); }
.btn--ghost { background: var(--soft); border-color: transparent; }
.btn--danger { background: none; border-color: transparent; color: var(--danger); padding-left: 0; }
.btn--icon { width: 32px; height: 32px; padding: 0; }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--muted); }
input, textarea, select { font: 14px/1.4 var(--font); color: var(--fg); background: var(--surface); border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; width: 100%; }
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 3px solid var(--focus); border-color: var(--pri); }
input[type="checkbox"] { width: auto; accent-color: var(--pri); }
.check { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* chip di stato */
.chip { display: inline-flex; align-items: center; height: 24px; padding: 0 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--soft); }
.chip--wait { color: var(--wait); }
.chip--ok { color: var(--ok); }
.chip--chg { color: var(--chg); }

/* dashboard */
.dash { max-width: 1100px; margin: 0 auto; padding: 32px 20px 60px; }
.dash__head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 24px; }
.dash__head p { margin: 0; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.card__main { display: flex; align-items: center; gap: 12px; text-decoration: none; min-width: 0; }
.card__av { width: 52px; height: 52px; font-size: 20px; }
.card__txt { display: flex; flex-direction: column; min-width: 0; }
.card__txt b, .card__txt span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card__stats { display: flex; gap: 6px; flex-wrap: wrap; }
.card__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.empty { background: var(--surface); border: 1px dashed var(--line); border-radius: 16px; padding: 48px 24px; text-align: center; }
.empty p { max-width: 520px; margin: 0 auto 20px; }

/* contatti */
.leads { display: grid; gap: 12px; }
.lead { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.lead__top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lead__top .small { margin-left: auto; }
.lead__row a { color: var(--pri); text-decoration: none; }
.lead__msg { margin: 6px 0 0; white-space: pre-wrap; overflow-wrap: anywhere; }

/* editor */
.ed { display: grid; grid-template-columns: 290px minmax(0, 1fr) 380px; gap: 20px; padding: 20px; max-width: 1500px; margin: 0 auto; align-items: start; }
.ed__prof, .ed__post { position: sticky; top: 76px; max-height: calc(100vh - 96px); overflow-y: auto; display: flex; flex-direction: column; gap: 14px; padding-bottom: 8px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.panel > summary { font-weight: 700; cursor: pointer; list-style: none; display: flex; justify-content: space-between; }
.panel > summary::after { content: "▾"; color: var(--muted); }
.panel:not([open]) > summary::after { content: "▸"; }
.panel__body { margin-top: 14px; }
.panel.placeholder { text-align: center; padding: 40px 20px; }
.avrow { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.avrow__img { width: 56px; height: 56px; font-size: 22px; }
.share { font-size: 12px; margin-bottom: 8px; background: var(--soft); }

.ed__center { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.drops { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; width: 100%; max-width: 470px; }
.drop { display: flex; align-items: center; gap: 10px; padding: 14px; border: 2px dashed var(--line); border-radius: 14px; background: var(--surface); cursor: pointer; color: var(--muted); transition: border-color .15s, background .15s; }
.drop span { display: flex; flex-direction: column; line-height: 1.3; }
.drop b { color: var(--fg); }
.drop small { font-size: 11.5px; }
.drop:hover, .drop.over { border-color: var(--pri); background: color-mix(in srgb, var(--pri) 8%, var(--surface)); color: var(--pri); }
.ed__bar { width: 100%; max-width: 470px; display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 12px; }

.phone { width: 100%; max-width: 470px; border: 1px solid var(--line); border-radius: 28px; padding: 10px 0 0; background: var(--ig-bg); overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.08); }
.phone .ig-tile { cursor: grab; }
.phone .ig-tile.sel { outline: 3px solid var(--pri); outline-offset: -3px; z-index: 1; }
.phone .ig-tile.dragging { opacity: .35; }
.phone .ig-tile.hidden-client > img, .phone .ig-tile.hidden-client > video { opacity: .45; }
.phone .ig-tile.drop-into { outline: 3px dashed var(--pri); outline-offset: -3px; }
.phone .ig-tile.drop-before { box-shadow: inset 4px 0 0 var(--pri); }
.phone .ig-tile.drop-after { box-shadow: inset -4px 0 0 var(--pri); }

/* pannello post */
.pp-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; }
.pp-head > div:first-child { display: flex; align-items: center; gap: 8px; }
.ig-badge--inline { position: static; box-shadow: none; }
.sec { margin: 4px 0 16px; }
.sec__title { font-weight: 700; font-size: 13px; margin-bottom: 8px; display: flex; gap: 8px; align-items: baseline; }
.sec__title .muted { font-weight: 500; font-size: 12px; }
.strip { display: flex; flex-wrap: wrap; gap: 8px; padding: 4px; border-radius: 12px; border: 2px dashed transparent; }
.strip.over { border-color: var(--pri); }
.thumb { position: relative; width: 72px; aspect-ratio: 4 / 5; border-radius: 8px; overflow: hidden; background: var(--soft); cursor: grab; flex: none; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.thumb__n { position: absolute; left: 4px; top: 4px; min-width: 18px; height: 18px; border-radius: 9px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }
.thumb__v { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; pointer-events: none; }
.thumb__v svg { width: 22px; height: 22px; filter: drop-shadow(0 1px 3px rgba(0,0,0,.5)); }
.thumb__x { position: absolute; right: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0; background: rgba(0,0,0,.65); color: #fff; display: grid; place-items: center; cursor: pointer; padding: 0; }
.thumb__x svg { width: 13px; height: 13px; }
.thumb--add { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border: 2px dashed var(--line); color: var(--muted); cursor: pointer; background: none; }
.thumb--add:hover { border-color: var(--pri); color: var(--pri); }
.thumb--add small { font-size: 11px; }
.thumb.drop-before { box-shadow: inset 4px 0 0 var(--pri); }
.thumb.drop-after { box-shadow: inset -4px 0 0 var(--pri); }

.cover { display: flex; gap: 12px; align-items: center; }
.cover__img { width: 72px; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden; background: var(--soft); display: grid; place-items: center; flex: none; }
.cover__img img { width: 100%; height: 100%; object-fit: cover; }
.cover__btns { display: flex; flex-wrap: wrap; gap: 6px; }
.frame { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.frame video { width: 100%; max-height: 360px; background: #000; border-radius: 10px; }

.caption { font-size: 14px; }
.warn-txt { color: var(--chg); }
.counters { display: flex; gap: 12px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.counters .warn { color: var(--danger); font-weight: 600; }
.counters .saved { margin-left: auto; color: var(--ok); }

.log { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; max-height: 280px; overflow-y: auto; }
.log__item { padding: 8px 10px; border-radius: 10px; background: var(--soft); }
.log__item--cliente.log__item--modifiche { background: color-mix(in srgb, var(--chg) 12%, var(--surface)); }
.log__item--cliente.log__item--approvato { background: color-mix(in srgb, var(--ok) 12%, var(--surface)); }
.log__meta { font-size: 12px; color: var(--muted); }
.log__meta b { color: var(--fg); }
.log__text { margin-top: 2px; overflow-wrap: anywhere; }
.reply { display: flex; gap: 6px; }

/* upload in corso */
.uploads { position: fixed; right: 16px; bottom: 16px; z-index: 60; display: flex; flex-direction: column; gap: 8px; width: 280px; }
.up { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; box-shadow: 0 8px 30px rgba(0,0,0,.12); transition: opacity .5s; }
.up.done { opacity: 0; }
.up__name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 6px; }
.up__name span { color: var(--muted); font-weight: 500; }
.up__bar { height: 5px; border-radius: 3px; background: var(--soft); overflow: hidden; }
.up__bar i { display: block; height: 100%; width: 0; background: var(--grad); transition: width .2s; }

/* finestra */
.dlg { border: 0; border-radius: 18px; padding: 0; background: var(--surface); color: var(--fg); width: min(440px, calc(100vw - 32px)); box-shadow: 0 30px 80px rgba(0,0,0,.3); }
.dlg::backdrop { background: rgba(0,0,0,.45); }
.dlg__body { padding: 22px; }
.dlg__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

@media (max-width: 1200px) {
  .ed { grid-template-columns: minmax(0, 1fr) 380px; }
  .ed__prof { grid-column: 1 / -1; position: static; max-height: none; display: grid; grid-template-columns: 1fr 1fr; align-items: start; }
  .ed__prof > .btn--danger { grid-column: 1 / -1; justify-self: start; }
}
@media (max-width: 899px) {
  .ed { grid-template-columns: 1fr; padding: 12px; }
  .ed__prof { grid-template-columns: 1fr; }
  .ed__post { position: static; max-height: none; }
  .drops { grid-template-columns: 1fr; }
  .uploads { left: 16px; width: auto; }
}

/* menu, ruoli e squadra */
.nav { display: flex; gap: 4px; }
.nav a { text-decoration: none; color: var(--muted); font-weight: 600; padding: 6px 10px; border-radius: 8px; }
.nav a:hover { color: var(--fg); background: var(--soft); }
.nav a.on { color: var(--fg); background: var(--soft); }
.plan { font-size: 12px; white-space: nowrap; }
.chip--super { background: var(--grad); color: #fff; margin-left: 4px; height: 20px; font-size: 11px; }
.as-bar { display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap; padding: 8px 16px; background: #ffe8a3; color: #3d2e00; font-size: 13px; }
.as-bar[hidden] { display: none; }
.notice { background: color-mix(in srgb, var(--chg) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--chg) 35%, transparent); border-radius: 12px; padding: 10px 14px; margin: 0 0 16px; }
.sec-h { font-size: 15px; margin: 24px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.people { display: grid; gap: 10px; }
.person { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.person > div:first-child { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.person select { width: auto; }
.op { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 0; border-bottom: 1px solid var(--line); }
.op > div:first-child { display: flex; flex-direction: column; min-width: 0; }
.op .muted { overflow-wrap: anywhere; }
#access > .row { margin-top: 12px; }
.invites { margin-top: 12px; display: grid; gap: 8px; }
.inv { background: var(--soft); border-radius: 10px; padding: 8px 10px; display: flex; flex-direction: column; gap: 6px; }
.pw { display: flex; gap: 6px; }
.pw input { flex: 1; }
.creds { background: var(--soft); border-radius: 10px; padding: 12px; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere; }
.form-err { color: var(--danger); font-weight: 600; font-size: 13px; min-height: 18px; margin: 8px 0 0; }
.scope { display: grid; gap: 6px; max-height: 240px; overflow-y: auto; margin: 8px 0 4px; padding: 8px; background: var(--soft); border-radius: 10px; }
.scope[hidden] { display: none; }
.dlg .sec__title { margin-top: 8px; }
@media (max-width: 900px) { .plan { display: none; } .top { flex-wrap: wrap; height: auto; padding: 10px 12px; } .nav { order: 3; width: 100%; overflow-x: auto; } }
#post-count { white-space: nowrap; }

/* ---------------------------------------------------------------- telefono */
.who-short { display: none; width: 28px; height: 28px; border-radius: 50%; background: var(--grad); color: #fff; place-items: center; font-weight: 800; font-size: 12px; }
.hint-touch { display: none; }
@media (max-width: 900px) {
  .crumbs { display: none; }
  .top__user { margin-left: auto; }
}
@media (max-width: 600px) {
  .who-full { display: none; }
  .who-short { display: inline-grid; }
  #account { padding: 0 6px; }
}
@media (max-width: 899px) {
  /* sul telefono prima la griglia e il caricamento, poi il post, poi accessi e profilo */
  .ed__center { order: 1; }
  .ed__post { order: 2; }
  .ed__prof { order: 3; }
  .drops { gap: 8px; }
  .ed__bar { flex-wrap: wrap; }
}
@media (pointer: coarse) {
  .hint-mouse { display: none; }
  .hint-touch { display: inline; }
  .thumb__x { width: 32px; height: 32px; right: 2px; top: 2px; }
  .thumb__x svg { width: 16px; height: 16px; }
  .thumb { width: 84px; }
  .btn--sm { min-height: 36px; }
  .btn--icon { width: 40px; height: 40px; }
}
.drop small span { display: inline; }
.drop small .hint-touch { display: none; }
@media (pointer: coarse) {
  .drop small .hint-mouse { display: none; }
  .drop small .hint-touch { display: inline; }
}

/* abbonamento, fatture, servizio scaduto */
.blocked { max-width: 560px; margin: 0 auto; padding: 72px 20px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.blocked__ico { font-size: 44px; }
.blocked h1 { margin: 0; }
.blocked .row { justify-content: center; margin-top: 8px; }
.billing-sw { display: inline-flex; padding: 4px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); margin: 8px 0 16px; }
.billing-sw button { border: 0; background: none; color: var(--muted); font: 600 14px var(--font); padding: 8px 16px; border-radius: 9px; cursor: pointer; }
.billing-sw button.on { background: var(--pri); color: #fff; }
.plans-mini { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-bottom: 10px; }
.plan-mini { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 16px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }
.plan-mini.on { border: 2px solid var(--pri); }
.plan-mini > span:first-of-type { font-size: 20px; font-weight: 800; }
.plan-mini small { font-weight: 500; }
.bill-form { max-width: 640px; }
.pay > div:first-child { gap: 3px; }
.pay--done { opacity: .75; }
@media (max-width: 700px) { .plans-mini { grid-template-columns: 1fr; } }
@media (max-width: 900px) {
  /* tutte le voci del menu visibili anche con 6 voci (Super Admin): vanno a capo invece di uscire dallo schermo */
  .nav { overflow: visible; flex-wrap: wrap; row-gap: 2px; }
  .nav a { padding: 6px 9px; font-size: 14px; }
}

/* ---------------------------------------------------------------- iPhone
   Safari ingrandisce la pagina quando si tocca un campo con testo sotto i 16 px, e non torna indietro:
   la pagina sembra più larga dello schermo. Sui telefoni tutti i campi stanno a 16 px. */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { overflow-x: clip; }
@media (pointer: coarse), (max-width: 900px) {
  input, textarea, select { font-size: 16px !important; }
}
.dlg { max-width: calc(100vw - 24px); max-height: calc(100dvh - 24px); overflow-y: auto; margin: auto; }
.dlg__body { padding: 20px; }
.dlg__actions { flex-wrap: wrap; }
.creds { word-break: break-word; overflow-wrap: anywhere; }
.person > div:first-child span, .op span { overflow-wrap: anywhere; }
