/* FPS Italia — Instagram Automation Manager. Nessun font esterno: font di sistema. */
:root {
  --brand: #EA552A;
  --brand-ink: #b83a14;
  --brand-soft: #fdeee8;
  --bg: #f6f6f4;
  --surface: #ffffff;
  --surface-2: #f1f1ee;
  --line: #e4e3df;
  --ink: #17171a;
  --ink-2: #4b4b52;
  --ink-3: #7a7a82;
  --ok: #1f8a4c;
  --ok-soft: #e6f4ec;
  --warn: #a86400;
  --warn-soft: #fdf2df;
  --err: #c62f2f;
  --err-soft: #fbe9e9;
  --info: #2c5fb3;
  --info-soft: #e8effb;
  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 2px 10px rgba(0,0,0,.04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --brand-soft: #3a1d14; --bg: #0f0f11; --surface: #18181b; --surface-2: #222226; --line: #2e2e33;
    --ink: #f2f2f3; --ink-2: #c4c4ca; --ink-3: #8d8d96; --brand-ink: #ff8a63;
    --ok: #4cc27f; --ok-soft: #12291c; --warn: #f0a640; --warn-soft: #2e2210; --err: #ff6b6b; --err-soft: #321616;
    --info: #7aa7f5; --info-soft: #152238; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --brand-soft: #3a1d14; --bg: #0f0f11; --surface: #18181b; --surface-2: #222226; --line: #2e2e33;
  --ink: #f2f2f3; --ink-2: #c4c4ca; --ink-3: #8d8d96; --brand-ink: #ff8a63;
  --ok: #4cc27f; --ok-soft: #12291c; --warn: #f0a640; --warn-soft: #2e2210; --err: #ff6b6b; --err-soft: #321616;
  --info: #7aa7f5; --info-soft: #152238; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
html { -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
button, a, [role="button"], .chip, .step { touch-action: manipulation; }
button, .tabbar a, .more-menu a, .step, .seg button { user-select: none; -webkit-user-select: none; }
a { color: var(--brand-ink); }
button, input, select, textarea { font: inherit; color: inherit; }
h1 { font-size: 1.45rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
h3 { font-size: .95rem; margin: 0 0 .5rem; }
p { margin: 0 0 .75rem; }
.muted { color: var(--ink-3); }
.small { font-size: .85rem; }
.mono { font-family: var(--mono); font-size: .85em; overflow-wrap: anywhere; }
.hidden { display: none !important; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---------- impaginazione ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100dvh; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0;
  height: 100dvh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand-mark { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); color: #fff; display: grid;
  place-items: center; font-weight: 800; font-size: .8rem; letter-spacing: .02em; flex: none; }
.brand b { display: block; font-size: .95rem; line-height: 1.2; }
.brand span { font-size: .75rem; color: var(--ink-3); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: var(--radius-s);
  color: var(--ink-2); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--ink); }
.nav a.on { background: var(--brand-soft); color: var(--brand-ink); }
.nav svg { width: 18px; height: 18px; flex: none; }
.nav .badge { margin-left: auto; }
.side-foot { margin-top: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.main { padding: 26px 32px 80px; max-width: 1180px; width: 100%; min-width: 0; }
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.head p { margin: 4px 0 0; color: var(--ink-3); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.stack > * + * { margin-top: 16px; }

/* barra in basso su telefono */
.tabbar { display: none; }
@media (max-width: 860px) {
  /* Telefono: la pagina non scorre, scorre solo <main>. Così il rimbalzo di iOS e la barra
     dell'indirizzo che si chiude non trascinano la barra in basso. */
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  .shell { grid-template-columns: minmax(0, 1fr); height: 100dvh; min-height: 0; }
  .side { display: none; }
  .main { padding: 16px 16px calc(84px + env(safe-area-inset-bottom, 0px)); height: 100dvh; overflow-y: auto;
    overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; background: var(--surface);
    border-top: 1px solid var(--line); padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: .68rem; color: var(--ink-3);
    text-decoration: none; padding: 4px 6px; min-width: 56px; }
  .tabbar a.on { color: var(--brand-ink); }
  .tabbar svg { width: 22px; height: 22px; }
  .more-menu { position: fixed; right: 10px; bottom: calc(70px + env(safe-area-inset-bottom)); z-index: 21;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 30px rgba(0,0,0,.25);
    padding: 6px; min-width: 190px; }
  .more-menu a { display: flex; align-items: center; gap: 10px; padding: 11px 12px; border-radius: var(--radius-s);
    color: var(--ink-2); text-decoration: none; font-weight: 500; }
  .more-menu a.on { background: var(--brand-soft); color: var(--brand-ink); }
  .more-menu svg { width: 18px; height: 18px; }
  h1 { font-size: 1.25rem; }
}

/* ---------- componenti ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px;
  box-shadow: var(--shadow); }
.card.flat { box-shadow: none; }
.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.kpi { padding: 14px 16px; }
.kpi .v { font-size: 1.7rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.kpi .l { color: var(--ink-3); font-size: .82rem; margin-top: 2px; }
.kpi.bad .v { color: var(--err); }
.kpi.warn .v { color: var(--warn); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); border-radius: var(--radius-s); padding: 8px 14px; font-weight: 600;
  cursor: pointer; text-decoration: none; min-height: 38px; white-space: nowrap; transition: background .15s, border-color .15s, transform .1s; }
.btn:hover { background: var(--surface-2); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #d84a20; }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn svg { width: 16px; height: 16px; }

.badge { display: inline-flex; align-items: center; gap: 5px; border-radius: 999px; padding: 2px 9px; font-size: .75rem;
  font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.err { background: var(--err-soft); color: var(--err); }
.badge.info { background: var(--info-soft); color: var(--info); }
.badge.brand { background: var(--brand-soft); color: var(--brand-ink); }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 999px; padding: 3px 6px 3px 11px; font-size: .85rem; max-width: 100%; }
.chip span { overflow-wrap: anywhere; }
.chip button { border: 0; background: transparent; cursor: pointer; width: 22px; height: 22px; border-radius: 50%;
  color: var(--ink-3); display: grid; place-items: center; padding: 0; }
.chip button:hover { background: var(--line); color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

label.f { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 6px; }
.hint { color: var(--ink-3); font-size: .82rem; margin-top: 5px; }
input[type=text], input[type=password], input[type=number], input[type=search], input[type=url], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius-s); padding: 9px 11px;
  font-size: 16px; min-height: 40px; }
textarea { min-height: 96px; resize: vertical; line-height: 1.45; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.field + .field { margin-top: 16px; }

.switch { display: flex; align-items: flex-start; gap: 12px; cursor: pointer; }
.switch input { appearance: none; width: 42px; height: 24px; border-radius: 999px; background: var(--line); position: relative;
  cursor: pointer; flex: none; transition: background .2s; margin: 1px 0 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%;
  background: #fff; transition: transform .2s; box-shadow: 0 1px 2px rgba(0,0,0,.25); }
.switch input:checked { background: var(--brand); }
.switch input:checked::after { transform: translateX(18px); }
.switch b { display: block; }
.switch small { color: var(--ink-3); display: block; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: var(--radius-s); padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 6px; cursor: pointer; font-weight: 600;
  color: var(--ink-2); font-size: .85rem; min-height: 32px; }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

.alert { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border-radius: var(--radius-s);
  background: var(--info-soft); color: var(--ink); border: 1px solid transparent; }
.alert.warning { background: var(--warn-soft); }
.alert.error { background: var(--err-soft); }
.alert .grow { min-width: 0; overflow-wrap: anywhere; }
.alert .ico { font-weight: 800; width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  font-size: .8rem; flex: none; background: var(--info); color: #fff; }
.alert.warning .ico { background: var(--warn); }
.alert.error .ico { background: var(--err); }

/* tabelle e liste */
.tbl { width: 100%; border-collapse: collapse; font-size: .9rem; }
.tbl th { text-align: left; font-weight: 600; color: var(--ink-3); font-size: .78rem; text-transform: uppercase;
  letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.scroll-x { overflow-x: auto; }

.thumb { width: 48px; height: 48px; border-radius: 8px; object-fit: cover; background: var(--surface-2); flex: none; display: block; }
.thumb.lg { width: 100%; height: auto; aspect-ratio: 4/5; border-radius: 10px; }
.thumb-ph { display: grid; place-items: center; color: var(--ink-3); font-size: .7rem; }

/* contenuti */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.media { border: 2px solid transparent; border-radius: var(--radius); background: var(--surface); cursor: pointer; padding: 6px;
  text-align: left; display: flex; flex-direction: column; gap: 6px; position: relative; border-color: var(--line); }
.media:hover { border-color: var(--ink-3); }
.media.on { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.media .cap { font-size: .8rem; color: var(--ink-2); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; overflow-wrap: anywhere; min-height: 2.4em; }
.media .meta { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: .75rem; color: var(--ink-3); }
.media .tag { position: absolute; top: 12px; left: 12px; }
.media .rules { position: absolute; top: 12px; right: 12px; }

/* automazioni */
.rule { display: grid; grid-template-columns: 56px 1fr auto; gap: 14px; align-items: center; }
.rule .title { font-weight: 700; overflow-wrap: anywhere; }
.rule .facts { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--ink-3); font-size: .82rem; margin-top: 4px; }
.rule .acts { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.rule-tools { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 640px) {
  .rule { grid-template-columns: 48px 1fr; }
  .rule-tools { grid-column: 1 / -1; justify-content: flex-start; }
}

/* procedura guidata */
.steps { display: flex; gap: 6px; margin-bottom: 18px; overflow-x: auto; padding-bottom: 2px; }
.step { display: flex; align-items: center; gap: 8px; padding: 6px 12px 6px 6px; border-radius: 999px; background: var(--surface);
  border: 1px solid var(--line); font-size: .85rem; font-weight: 600; color: var(--ink-3); white-space: nowrap; cursor: pointer; }
.step i { font-style: normal; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  background: var(--surface-2); font-size: .78rem; }
.step.on { color: var(--ink); border-color: var(--brand); }
.step.on i { background: var(--brand); color: #fff; }
.step.done i { background: var(--ok-soft); color: var(--ok); }
.wiz-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 18px; position: sticky; bottom: 0;
  background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 6px; }
@media (max-width: 860px) { .wiz-foot { bottom: calc(64px + env(safe-area-inset-bottom)); } }

.action-card { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; padding: 14px 16px; }
.action-card + .action-card { margin-top: 10px; }

/* anteprima tipo telefono */
.phone { max-width: 360px; border: 1px solid var(--line); border-radius: 22px; padding: 14px; background: var(--surface); }
.phone h4 { margin: 0 0 10px; font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.cmt { display: flex; gap: 10px; font-size: .9rem; }
.cmt + .cmt { margin-top: 10px; }
.cmt.reply { margin-left: 34px; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--surface-2); flex: none; display: grid; place-items: center;
  font-size: .7rem; font-weight: 700; color: var(--ink-3); overflow: hidden; }
.avatar.brand { background: var(--brand); color: #fff; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.cmt b { margin-right: 6px; }
.cmt span { overflow-wrap: anywhere; white-space: pre-wrap; }
.bubble { background: var(--surface-2); border-radius: 18px 18px 18px 6px; padding: 10px 13px; white-space: pre-wrap;
  overflow-wrap: anywhere; font-size: .9rem; max-width: 92%; }
.bubble.me { background: var(--brand); color: #fff; border-radius: 18px 18px 6px 18px; margin-left: auto; }
.liked { color: var(--err); font-size: .78rem; margin-left: 34px; }

/* registro */
.log-item { padding: 14px 16px; }
.log-item + .log-item { margin-top: 10px; }
.log-top { display: flex; gap: 12px; align-items: flex-start; }
.log-top b { overflow-wrap: anywhere; min-width: 0; }
.log-text { font-size: .93rem; overflow-wrap: anywhere; white-space: pre-wrap; }
.acts-line { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
details.more { margin-top: 10px; }
details.more summary { cursor: pointer; color: var(--ink-3); font-size: .85rem; }
.attempt { font-size: .82rem; color: var(--ink-2); padding: 6px 0; border-top: 1px dashed var(--line); overflow-wrap: anywhere; }

.empty { text-align: center; padding: 40px 16px; color: var(--ink-3); }
.empty b { display: block; color: var(--ink); font-size: 1rem; margin-bottom: 6px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; z-index: 50;
  transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
@media (max-width: 860px) { .toast { bottom: calc(80px + env(safe-area-inset-bottom)); } }

/* accesso */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login .card { width: 100%; max-width: 380px; padding: 26px; }

.split { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.split-3 { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; align-items: start; }
@media (max-width: 860px) { .split, .split-3 { grid-template-columns: 1fr; } }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: .9rem; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.profile { display: flex; align-items: center; gap: 14px; }
.profile img, .profile .avatar { width: 56px; height: 56px; border-radius: 50%; }
.spark { display: flex; align-items: flex-end; gap: 3px; height: 54px; }
.spark i { flex: 1; background: var(--brand); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .85; }
.counter { font-size: .78rem; color: var(--ink-3); text-align: right; margin-top: 4px; font-variant-numeric: tabular-nums; }
.counter.over { color: var(--err); font-weight: 700; }
.var-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: center; margin-top: 16px; }
.problems { margin: 0; padding-left: 18px; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
