/* =========================================================
   Agente Social — design system
   ========================================================= */
:root {
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --ink: #0f172a;
    --ink-soft: #334155;
    --muted: #64748b;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;

    --primary: #0e7490;
    --primary-600: #155e75;
    --primary-50: #ecfeff;

    --success: #15803d;
    --success-bg: #dcfce7;
    --warning: #b45309;
    --warning-bg: #fef3c7;
    --danger: #b91c1c;
    --danger-bg: #fee2e2;
    --info: #1d4ed8;
    --info-bg: #dbeafe;

    --radius: 14px;
    --radius-sm: 9px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06);
    --shadow: 0 6px 24px -12px rgba(15, 23, 42, .25);
    --shadow-lg: 0 24px 60px -20px rgba(15, 23, 42, .35);

    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    line-height: 1.6;
    font-size: 15px;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary-600); }

/* ---------- Top bar ---------- */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(255, 255, 255, .85);
    backdrop-filter: saturate(180%) blur(10px);
    border-bottom: 1px solid var(--border);
}
.topbar-inner {
    max-width: 1120px;
    margin: 0 auto;
    padding: 12px 24px;
    display: flex;
    align-items: center;
    gap: 22px;
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 700; letter-spacing: -.01em; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), #0891b2);
    color: #fff; display: grid; place-items: center;
    font-size: .8rem; font-weight: 800; letter-spacing: .02em;
    box-shadow: var(--shadow-sm);
}
.brand-text { font-size: 1rem; }
.topnav { display: flex; gap: 18px; margin-left: 6px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --- Catalogo prodotti --- */
.product-list { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.product-row {
    display: grid;
    grid-template-columns: 64px 1fr auto;
    gap: 14px;
    align-items: center;
    padding: 10px;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 12px;
    background: var(--surface, #fff);
}
.product-thumb img { width: 64px; height: 64px; object-fit: cover; border-radius: 10px; display: block; }
.product-info strong { display: block; margin-bottom: 2px; }
.product-actions { display: flex; gap: 8px; align-items: center; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.thumb video { width: 100%; height: 100%; object-fit: cover; border-radius: 10px; display: block; }
.brand-switch { margin-left: auto; margin-right: 12px; }
.brand-switch select {
    appearance: none;
    background: var(--surface, #fff);
    color: inherit;
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 999px;
    padding: 6px 30px 6px 14px;
    font: inherit;
    font-size: .88rem;
    font-weight: 600;
    cursor: pointer;
    background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
    background-position: calc(100% - 16px) 55%, calc(100% - 11px) 55%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}
.topnav a { color: var(--muted); text-decoration: none; font-size: .92rem; font-weight: 500; }
.topnav a:hover, .topnav a.active { color: var(--primary-600); }
.logout { margin-left: auto; }

/* ---------- Layout ---------- */
.container { max-width: 1120px; margin: 0 auto; padding: 32px 24px 80px; }

h1 { font-size: 1.6rem; font-weight: 750; letter-spacing: -.02em; margin: 0 0 6px; }
h2 { font-size: 1.15rem; font-weight: 700; letter-spacing: -.01em; margin: 0 0 16px; }
h3 { font-size: 1rem; font-weight: 650; margin: 0 0 12px; }

.page-head { margin-bottom: 24px; }
.page-head p { margin: 0; color: var(--muted); }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 22px;
    box-shadow: var(--shadow-sm);
}
.card > h2, .card > h3 { margin-top: 0; }

/* ---------- Forms ---------- */
label { display: block; font-weight: 600; font-size: .84rem; color: var(--ink-soft); margin-bottom: 7px; }
input[type=text], input[type=password], input[type=search], select, textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: .95rem;
    font-family: inherit;
    color: var(--ink);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: #94a3b8; }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(14, 116, 144, .15);
}
textarea { resize: vertical; line-height: 1.55; }

.grid-2 { display: grid; gap: 16px; margin: 4px 0 16px; }
@media (min-width: 780px) { .grid-2 { grid-template-columns: 220px 1fr; } }

.field { margin-bottom: 16px; }

.checkbox-row { display: flex; align-items: center; gap: 9px; margin: 4px 0 18px; font-weight: 500; font-size: .9rem; color: var(--ink-soft); cursor: pointer; }
.checkbox-row input[type=checkbox] { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); flex: 0 0 auto; cursor: pointer; }

/* Interruttore on/off */
.switch { display: flex; align-items: center; gap: 13px; cursor: pointer; font-weight: 500; font-size: .92rem; color: var(--ink-soft); margin: 4px 0 8px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track { width: 48px; height: 27px; border-radius: 999px; background: var(--border-strong); position: relative; transition: background .2s; flex: 0 0 auto; }
.switch-thumb { position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-sm); transition: transform .2s; }
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track .switch-thumb { transform: translateX(21px); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(14, 116, 144, .25); }

/* ---------- Buttons ---------- */
button, .btn {
    --btn-bg: var(--primary);
    display: inline-flex; align-items: center; gap: 7px;
    border: 0; border-radius: var(--radius-sm);
    padding: 11px 18px;
    font-size: .9rem; font-weight: 600; font-family: inherit;
    cursor: pointer;
    background: var(--btn-bg); color: #fff;
    text-decoration: none; line-height: 1.2;
    transition: filter .15s, transform .02s;
    white-space: nowrap;
}
button:hover, .btn:hover { filter: brightness(.93); }
button:active, .btn:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: wait; }
button.primary, .btn.primary { --btn-bg: var(--primary); }
button.secondary, .btn.secondary { --btn-bg: #475569; }
button.danger, .btn.danger { --btn-bg: var(--danger); }
button.ghost, .btn.ghost { --btn-bg: transparent; color: var(--ink-soft); border: 1px solid var(--border-strong); }
button.small, .btn.small { padding: 7px 12px; font-size: .82rem; }
button.block, .btn.block { width: 100%; justify-content: center; }
button.link { background: none; color: var(--muted); text-decoration: none; padding: 6px 8px; font-weight: 500; }
button.link:hover { background: none; filter: none; color: var(--primary-600); }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; margin-bottom: 24px; }
@media (min-width: 760px) { .stats { grid-template-columns: repeat(4, 1fr); } }
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--muted); }
.stat-n { display: block; font-size: 1.9rem; font-weight: 750; line-height: 1.1; letter-spacing: -.02em; }
.stat-l { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.stat.is-pending::before { background: var(--warning); }
.stat.is-pending .stat-n { color: var(--warning); }
.stat.is-published::before { background: var(--success); }
.stat.is-published .stat-n { color: var(--success); }
.stat.is-rejected::before { background: var(--danger); }
.stat.is-rejected .stat-n { color: var(--danger); }

/* ---------- Toolbar ---------- */
.list-head { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; justify-content: space-between; margin: 30px 0 14px; }
.list-head h2 { margin: 0; }
.search { display: flex; gap: 8px; }
.search input { width: 240px; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tab, .tabs .tab {
    background: none; color: var(--muted);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
    padding: 10px 15px;
    text-decoration: none; font-weight: 600; font-size: .88rem;
    border-bottom: 2px solid transparent;
    display: inline-flex; align-items: center; gap: 7px;
}
.tab:hover { background: var(--surface-2); color: var(--primary-600); filter: none; }
.tab.active { color: var(--primary-600); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Table ---------- */
.list { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); box-shadow: var(--shadow-sm); }
.list th, .list td { text-align: left; padding: 13px 16px; border-bottom: 1px solid var(--border); font-size: .9rem; vertical-align: middle; }
.list th { background: var(--surface-2); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.list tbody tr { transition: background .12s; }
.list tbody tr:hover { background: var(--surface-2); }
.list tr:last-child td { border-bottom: 0; }
.list td a:not(.btn) { color: var(--ink); text-decoration: none; font-weight: 600; }
.list td a:not(.btn):hover { color: var(--primary-600); }
.row-actions { display: flex; gap: 8px; align-items: center; justify-content: flex-end; }
.row-actions form { margin: 0; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 4px 11px; border-radius: 999px; font-size: .74rem; font-weight: 700; letter-spacing: .01em; }
.badge.pending { background: var(--warning-bg); color: var(--warning); }
.badge.published { background: var(--success-bg); color: var(--success); }
.badge.rejected { background: var(--danger-bg); color: var(--danger); }
.badge.approved { background: var(--info-bg); color: var(--info); }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.page { padding: 8px 14px; border: 1px solid var(--border); border-radius: var(--radius-sm); text-decoration: none; color: var(--ink-soft); background: var(--surface); font-size: .88rem; font-weight: 600; }
.page:hover { border-color: var(--primary); color: var(--primary-600); }
.page.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Alerts ---------- */
.alert { padding: 14px 18px; border-radius: var(--radius-sm); margin-bottom: 22px; font-size: .92rem; font-weight: 500; border: 1px solid transparent; }
.alert.ok { background: var(--success-bg); color: var(--success); border-color: #bbf7d0; }
.alert.error { background: var(--danger-bg); color: var(--danger); border-color: #fecaca; }

/* ---------- Post detail layout ---------- */
.layout { display: grid; gap: 22px; align-items: start; }
@media (min-width: 1000px) { .layout { grid-template-columns: minmax(0, 1fr) 300px; } }
.sidebar { position: sticky; top: 84px; }
.sidebar .card { padding: 18px; }
.post-header { display: flex; align-items: center; gap: 14px; margin-bottom: 4px; flex-wrap: wrap; }
.post-header h1 { margin: 0; }
.split { display: grid; gap: 20px; }
@media (min-width: 820px) { .split { grid-template-columns: 1fr 1fr; } }
.panel-col { min-width: 0; }
.counter { color: var(--muted); font-size: .8rem; margin: 8px 0 10px; }
.save-bar { margin-top: 20px; display: flex; justify-content: flex-end; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 220px; }
.actions-stack { display: flex; flex-direction: column; gap: 10px; }
.actions-stack button, .actions-stack .btn { width: 100%; justify-content: center; }
.actions-stack form { margin: 0; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.meta-list { font-size: .84rem; color: var(--muted); display: flex; flex-direction: column; gap: 8px; }
.meta-list strong { color: var(--ink-soft); font-weight: 600; }

/* ---------- Social previews ---------- */
.fb-card, .ig-card, .li-card {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    padding: 16px;
    box-shadow: var(--shadow-sm);
}
.fb-head, .ig-head { display: flex; align-items: center; gap: 11px; margin-bottom: 14px; }
.fb-avatar {
    width: 42px; height: 42px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #0891b2);
    color: #fff; display: grid; place-items: center;
    font-weight: 700; font-size: .85rem; flex: 0 0 42px;
}
.fb-name { font-weight: 700; font-size: .92rem; line-height: 1.25; }
.fb-meta { color: var(--muted); font-size: .78rem; }
.fb-text { font-size: .92rem; white-space: normal; margin-bottom: 14px; line-height: 1.55; }
.fb-actions { display: flex; gap: 22px; border-top: 1px solid var(--border); padding-top: 11px; color: var(--muted); font-size: .84rem; font-weight: 600; }
.ig-media { background: var(--surface-2); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); height: 150px; display: grid; place-items: center; color: var(--muted); margin-bottom: 14px; font-size: .85rem; }

.post-image { width: 100%; max-width: 520px; border-radius: var(--radius-sm); display: block; box-shadow: var(--shadow-sm); border: 1px solid var(--border); }
.fb-preview-image { width: 100%; border-radius: 8px; margin-bottom: 12px; display: block; }

.image-tools { display: grid; gap: 16px; margin-top: 18px; }
@media (min-width: 760px) { .image-tools { grid-template-columns: 1fr 1fr; } }
.tool-block { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 15px; }
.tool-label { display: block; font-weight: 600; font-size: .82rem; color: var(--ink-soft); margin-bottom: 10px; }

.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-bottom: 6px; }
.thumb { position: relative; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--border); background: var(--surface-2); aspect-ratio: 1; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb form { position: absolute; top: 0; right: 0; margin: 0; }
.thumb-remove { width: 28px; height: 28px; border-radius: 50%; background: rgba(15, 23, 42, .72); color: #fff; padding: 0; display: grid; place-items: center; font-size: .8rem; margin: 6px; }
.thumb-remove:hover { background: var(--danger); filter: none; }
input[type=file] { width: 100%; font-size: .82rem; color: var(--muted); }
input[type=file]::file-selector-button {
    font-family: inherit; font-size: .82rem; font-weight: 600;
    background: #e2e8f0; color: var(--ink-soft);
    border: 0; border-radius: 7px; padding: 8px 12px; margin-right: 10px; cursor: pointer;
}
input[type=file]::file-selector-button:hover { background: #cbd5e1; }

/* ---------- Loading overlay ---------- */
.loading-overlay {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(15, 23, 42, .55);
    backdrop-filter: blur(3px);
    display: grid; place-items: center;
}
.loading-overlay[hidden] { display: none; }

/* --- Modale di conferma (sostituisce window.confirm) --- */
.modal-backdrop {
    position: fixed; inset: 0; z-index: 120;
    display: grid; place-items: center;
    background: rgba(15, 23, 42, .48);
    backdrop-filter: blur(6px);
    opacity: 0;
    transition: opacity .18s ease;
}
.modal-backdrop.is-visible { opacity: 1; }
.modal {
    width: min(420px, calc(100vw - 32px));
    background: #fff;
    border-radius: 18px;
    padding: 26px 26px 20px;
    text-align: center;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
    transform: translateY(10px) scale(.97);
    transition: transform .18s cubic-bezier(.34, 1.4, .64, 1);
}
.modal-backdrop.is-visible .modal { transform: translateY(0) scale(1); }
.modal-icon {
    width: 48px; height: 48px; margin: 0 auto 12px;
    display: grid; place-items: center;
    font-size: 1.4rem;
    border-radius: 50%;
    background: color-mix(in srgb, var(--brand, #0d9488) 12%, #fff);
}
.modal-text { margin: 0 0 20px; color: var(--text, #0f172a); font-size: .98rem; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }
.modal-actions button { min-width: 130px; justify-content: center; }
/* colori espliciti dei pulsanti della modale */
.modal-actions button.ghost {
    --btn-bg: #f1f5f9;
    color: var(--ink, #0f172a);
    border: 1px solid var(--border-strong, #cbd5e1);
}
.modal-actions button.primary { --btn-bg: var(--brand, var(--primary)); color: #fff; }
.modal-actions button.danger { --btn-bg: var(--danger, #dc2626); color: #fff; }
.modal-icon.is-danger { background: #fee2e2; }
.thumb img.is-broken { display: none; }

/* --- Link "Vedi su Facebook" --- */
.fb-link { display: inline-flex; align-items: center; gap: 7px; font-weight: 600; color: var(--primary-600, #0f766e); text-decoration: none; }
.fb-link:hover { text-decoration: underline; }
.fb-dot {
    width: 20px; height: 20px; border-radius: 50%;
    display: grid; place-items: center;
    background: #1877f2; color: #fff;
    font-weight: 800; font-size: .78rem;
}
.loading-box { background: #fff; border-radius: var(--radius); padding: 34px 44px; text-align: center; box-shadow: var(--shadow-lg); max-width: 340px; }
.spinner {
    width: 46px; height: 46px; margin: 0 auto 18px;
    border: 4px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { margin: 0 0 6px; font-weight: 700; font-size: 1rem; }
.loading-sub { margin: 0; color: var(--muted); font-size: .82rem; }

/* ---------- Misc ---------- */
.hint { color: var(--muted); font-size: .84rem; margin: 12px 0 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.back { color: var(--muted); text-decoration: none; font-size: .88rem; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; margin-bottom: 14px; }
.back:hover { color: var(--primary-600); }
.login-wrap { max-width: 400px; margin: 9vh auto; }
.login-wrap h1 { text-align: center; }
.sub { color: var(--muted); margin: 0 0 22px; text-align: center; }

@media (max-width: 640px) {
    .container { padding: 22px 16px 60px; }
    .search input { width: 150px; }
    h1 { font-size: 1.35rem; }
}

/* --- Badge Instagram --- */
.fb-link.ig { color: #c13584; }
.fb-dot.ig { background: linear-gradient(45deg, #f09433, #e6683c, #dc2743, #cc2366, #bc1888); font-size: .9rem; }

/* --- Pannello commenti / engagement --- */
.engagement-bar { display: flex; flex-wrap: wrap; gap: 14px; align-items: center; margin: 0 0 16px; padding: 10px 14px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.engagement-bar .eng { font-size: .88rem; color: var(--ink-soft); }
.engagement-bar .eng strong { color: var(--ink); font-weight: 700; }
.comment { border-top: 1px solid var(--border); padding: 14px 0 4px; }
.comment:first-of-type { border-top: 0; }
.comment-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 4px; font-size: .9rem; }
.comment-text { margin: 0 0 8px; white-space: pre-wrap; line-height: 1.5; }
.comment-reply { margin: 8px 0 8px 22px; padding-left: 12px; border-left: 3px solid var(--border-strong); }
.comment-reply-form { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.comment-reply-form textarea { width: 100%; }
.comment-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.comment-instructions { flex: 1 1 220px; min-width: 180px; }

/* --- Recap dashboard --- */
.recap-grid { display: grid; gap: 16px; margin-bottom: 24px; }
@media (min-width: 900px) { .recap-grid { grid-template-columns: 1.5fr 1fr; } }
.recap-grid .card { margin: 0; }
.comment-row { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 12px 0; border-top: 1px solid var(--border); }
.comment-row:first-of-type { border-top: 0; }
.comment-row-main { min-width: 0; flex: 1 1 auto; }
.comment-row > .btn { flex: 0 0 auto; }
.comment-row .comment-text { margin: 4px 0; }
