/* ============================================================
   NestD Publisher — identità visiva NestD (dark theme)
   ============================================================ */

:root {
  --bg: #0a0a0f;
  --card: #111118;
  --card-2: #0d0d14;
  --border: #1e1e30;
  --accent: #8b5cf6;
  --accent-hover: #a78bfa;
  --text: #e2e8f0;
  --dim: #94a3b8;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --sky: #38bdf8;
  --radius: 16px;
  --radius-sm: 12px;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1 { font-size: 26px; margin: 0 0 4px; letter-spacing: -0.02em; }
h2 {
  font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--dim);
  margin: 28px 0 12px;
}
h3 { margin: 0 0 10px; font-size: 18px; }
p { margin: 0 0 8px; }
a { color: var(--accent-hover); }
small { font-size: 12px; }

.hidden { display: none !important; }
.muted { color: var(--dim); }

/* Focus sempre visibile */
:focus-visible {
  outline: 2px solid var(--accent-hover);
  outline-offset: 2px;
}

/* ---------- Filigrana a griglia (testata e login) ---------- */

.topbar-veil,
.login-veil {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(139, 92, 246, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(139, 92, 246, 0.08) 1px, transparent 1px);
  background-size: 44px 44px;
  -webkit-mask-image: radial-gradient(120% 200% at 50% -40%, #000 45%, transparent 78%);
  mask-image: radial-gradient(120% 200% at 50% -40%, #000 45%, transparent 78%);
}

.login-veil {
  position: fixed;
  -webkit-mask-image: radial-gradient(80% 55% at 50% 0%, #000 30%, transparent 75%);
  mask-image: radial-gradient(80% 55% at 50% 0%, #000 30%, transparent 75%);
}

/* ---------- Splash iniziale ---------- */

.splash {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
}

/* ---------- Card ---------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

/* ---------- Bottoni (pill) ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 20px;
  border-radius: 999px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.06s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) {
  border-color: var(--accent);
  color: #fff;
  background: rgba(139, 92, 246, 0.08);
}

.btn-danger { background: transparent; border-color: rgba(248, 113, 113, 0.4); color: var(--red); }
.btn-danger:hover:not(:disabled) { background: rgba(248, 113, 113, 0.1); border-color: var(--red); }

.btn-sm { padding: 6px 14px; font-size: 13px; }
.btn-block { width: 100%; }

/* Spinner dentro il bottone occupato */
.btn.is-busy { color: transparent !important; pointer-events: none; position: relative; }
.btn.is-busy::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 15px;
  height: 15px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.btn-ghost.is-busy::after,
.btn-danger.is-busy::after {
  border-color: rgba(167, 139, 250, 0.3);
  border-top-color: var(--accent-hover);
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Campi modulo ---------- */

.field { display: block; margin-bottom: 16px; }
.field > span,
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--dim);
  margin-bottom: 6px;
}

input[type="email"],
input[type="password"],
input[type="text"],
input[type="url"],
input[type="datetime-local"],
textarea,
select {
  width: 100%;
  background: var(--card-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font: inherit;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea { resize: vertical; min-height: 120px; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.22);
}
input::placeholder, textarea::placeholder { color: #64748b; }
select option { background: var(--card); }
input[readonly] { color: var(--dim); }

.counter { display: block; text-align: right; font-size: 12px; color: var(--dim); margin-top: 5px; }
.counter.over { color: var(--red); font-weight: 700; }

.form-error {
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fca5a5;
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 13px;
  margin: 0 0 14px;
}

/* ---------- Brand ---------- */

.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), #6d28d9);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
  border-radius: 10px;
  box-shadow: 0 4px 18px rgba(139, 92, 246, 0.35);
  flex: none;
}
.brand-name { font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand-name em { font-style: normal; font-weight: 500; color: var(--dim); }
.brand-lg .brand-mark { width: 46px; height: 46px; font-size: 24px; border-radius: 13px; }
.brand-lg .brand-name { font-size: 20px; }

/* ---------- Login ---------- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  position: relative;
}
.login-card { width: min(400px, 100%); padding: 30px 28px; position: relative; }
.login-card .brand { justify-content: center; margin-bottom: 8px; }
.login-sub { text-align: center; margin-bottom: 22px; }

/* ---------- Testata ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(10, 10, 15, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.topbar-inner {
  position: relative;
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  gap: 18px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-inline: auto;
  background: rgba(17, 17, 24, 0.7);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--dim);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 7px 16px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
.tab:hover { color: var(--text); }
.tab.active { background: var(--accent); color: #fff; }

.userbox { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-label {
  color: var(--dim);
  font-size: 13px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Struttura viste ---------- */

.container { max-width: 1100px; margin: 0 auto; padding: 28px 20px 80px; }
.view-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

/* ---------- Badge di stato ---------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 11px;
  border-radius: 999px;
  border: 1px solid;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }

.badge-ok   { color: var(--green); border-color: rgba(52, 211, 153, 0.35); background: rgba(52, 211, 153, 0.08); }
.badge-warn { color: var(--amber); border-color: rgba(251, 191, 36, 0.35); background: rgba(251, 191, 36, 0.08); }

/* Colori per stato dei post */
.st-draft     { color: var(--dim);          border-color: rgba(148, 163, 184, 0.35); background: rgba(148, 163, 184, 0.08); }
.st-pending   { color: var(--amber);        border-color: rgba(251, 191, 36, 0.35);  background: rgba(251, 191, 36, 0.08); }
.st-approved  { color: var(--sky);          border-color: rgba(56, 189, 248, 0.35);  background: rgba(56, 189, 248, 0.08); }
.st-scheduled { color: var(--accent-hover); border-color: rgba(167, 139, 250, 0.4);  background: rgba(139, 92, 246, 0.1); }
.st-published { color: var(--green);        border-color: rgba(52, 211, 153, 0.35);  background: rgba(52, 211, 153, 0.08); }
.st-failed    { color: var(--red);          border-color: rgba(248, 113, 113, 0.35); background: rgba(248, 113, 113, 0.08); }

/* ---------- Stati vuoti e caricamento ---------- */

.empty {
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: rgba(17, 17, 24, 0.5);
  text-align: center;
  padding: 44px 24px;
  color: var(--dim);
}
.empty h3 { color: var(--text); margin-bottom: 6px; }
.empty .btn { margin-top: 14px; }

.loading-block {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--dim);
  padding: 36px 0;
}
.spinner {
  width: 18px;
  height: 18px;
  flex: none;
  border: 2px solid rgba(139, 92, 246, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ---------- Connessioni ---------- */

.conn-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}
.conn-info { min-width: 0; flex: 1; }
.conn-name { font-weight: 700; }
.conn-meta { font-size: 12px; color: var(--dim); }
.conn-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.pages-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 14px;
}
.page-card { display: flex; align-items: center; gap: 12px; padding: 14px 16px; }
.page-avatar {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  object-fit: cover;
  background: #1a1a28;
  border: 1px solid var(--border);
  flex: none;
}
.page-avatar-fallback {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  flex: none;
  display: grid;
  place-items: center;
  background: rgba(139, 92, 246, 0.15);
  color: var(--accent-hover);
  font-weight: 800;
  font-size: 18px;
  border: 1px solid var(--border);
}
.page-info { min-width: 0; flex: 1; }
.page-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-status { margin-top: 5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* ---------- Composer ---------- */

.compose-card { max-width: 720px; }

.editing-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: rgba(139, 92, 246, 0.1);
  border: 1px solid rgba(139, 92, 246, 0.35);
  color: var(--accent-hover);
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.inline-empty {
  background: rgba(251, 191, 36, 0.07);
  border: 1px solid rgba(251, 191, 36, 0.3);
  color: var(--amber);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  gap: 10px;
}
.media-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--card-2);
}
.media-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-item.is-uploading { display: grid; place-items: center; }
.media-remove {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 0;
  background: rgba(5, 5, 10, 0.75);
  color: var(--text);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.media-remove:hover { background: var(--red); color: #fff; }
.media-add {
  aspect-ratio: 1;
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--dim);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: border-color 0.15s, color 0.15s;
}
.media-add:hover { border-color: var(--accent); color: var(--accent-hover); }

.compose-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  flex-wrap: wrap;
}

.publish-result {
  margin-top: 16px;
  background: rgba(52, 211, 153, 0.08);
  border: 1px solid rgba(52, 211, 153, 0.35);
  color: var(--green);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
}
.publish-result a { color: var(--green); font-weight: 700; }

/* ---------- Filtri e card dei post ---------- */

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--dim);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.chip:hover { color: var(--text); border-color: var(--accent); }
.chip.active {
  background: rgba(139, 92, 246, 0.15);
  border-color: var(--accent);
  color: var(--accent-hover);
}

.posts-list { display: flex; flex-direction: column; gap: 12px; }
.post-card { padding: 16px 18px; }
.post-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.post-page { font-weight: 700; }
.post-kind {
  font-size: 12px;
  color: var(--dim);
  border: 1px solid var(--border);
  padding: 1px 9px;
  border-radius: 999px;
}
.post-head .badge { margin-left: auto; }
.post-message {
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  margin: 0 0 6px;
}
.post-thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
.post-thumbs img {
  width: 54px;
  height: 54px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
}
.post-meta {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  font-size: 12.5px;
  color: var(--dim);
  margin-bottom: 4px;
  overflow-wrap: anywhere;
}
.post-note { font-size: 13px; padding: 8px 12px; border-radius: 10px; margin: 8px 0; overflow-wrap: anywhere; }
.post-note.is-error { background: rgba(248, 113, 113, 0.08); border: 1px solid rgba(248, 113, 113, 0.3); color: #fca5a5; }
.post-note.is-review { background: rgba(251, 191, 36, 0.07); border: 1px solid rgba(251, 191, 36, 0.3); color: var(--amber); }
.post-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }

/* ---------- Toast ---------- */

.toasts {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: min(360px, calc(100vw - 32px));
}
.toast {
  background: var(--card);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  cursor: pointer;
  animation: toast-in 0.22s ease-out;
}
.toast a { font-weight: 700; }
.toast-success { border-left-color: var(--green); }
.toast-error { border-left-color: var(--red); }
.toast.out { opacity: 0; transform: translateY(-6px); transition: opacity 0.22s, transform 0.22s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- Modale ---------- */

.modal-root {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: grid;
  place-items: center;
  padding: 20px;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(5, 5, 10, 0.72);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
.modal {
  position: relative;
  width: min(460px, 100%);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
  animation: modal-in 0.18s ease-out;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } }

.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; font-size: 13px; }

/* ---------- Mobile ---------- */

@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; gap: 10px; padding: 12px 14px; }
  .tabs { order: 3; width: 100%; margin: 0; }
  .tab { flex: 1; text-align: center; padding: 8px 6px; }
  .userbox { margin-left: auto; }
  .user-label { display: none; }

  .container { padding: 20px 14px 70px; }
  .view-head { flex-direction: column; align-items: stretch; }
  .view-head .btn { width: 100%; }

  .compose-actions { flex-direction: column-reverse; }
  .compose-actions .btn { width: 100%; }

  .pages-grid { grid-template-columns: 1fr; }
  .post-head .badge { margin-left: 0; }
  .post-actions .btn { flex: 1; }

  .conn-row { align-items: flex-start; }
  .conn-actions { width: 100%; }
  .conn-actions .btn { flex: 1; }

  .toasts { top: auto; bottom: 16px; left: 16px; right: 16px; width: auto; }
}
