/* Missiva — design system
   Palette postale: inchiostro, carta, rosso postale, azzurro aereo. */
:root {
  --ink: #22384e;
  --ink-deep: #1a2c3e;
  --paper: #f4f3ee;
  --card: #ffffff;
  --rosso: #c2413c;
  --azzurro: #3b77b8;
  --azzurro-deep: #2d6099;
  --grafite: #5a6b7a;
  --line: #e4e2da;
  --ok: #2e7d46;
  --ok-bg: #e7f3ea;
  --warn-bg: #fdf3e3;
  --warn: #9a6200;
  --err-bg: #faeae9;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--paper);
}
h1 { font-size: 1.45rem; letter-spacing: -.015em; margin: 0 0 .2em; }
h2 { font-size: 1.02rem; margin: 1.8em 0 .6em; letter-spacing: -.01em; }
a { color: var(--azzurro); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: .88em; }
code { background: #edf0f2; padding: 1px 5px; border-radius: 4px; }
p.lead { color: var(--grafite); margin: 0 0 1.2rem; }
:focus-visible { outline: 2px solid var(--azzurro); outline-offset: 2px; }

/* Firma visiva: bordo "par avion" */
.airmail {
  height: 4px; border-radius: 2px 2px 0 0;
  background: repeating-linear-gradient(-45deg,
    var(--rosso) 0 9px, #fff 9px 18px, var(--azzurro) 18px 27px, #fff 27px 36px);
}

/* ---- Shell admin: sidebar + contenuto ------------------------------------ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 218px; flex-shrink: 0; background: var(--ink); color: #fff;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.brand {
  display: flex; align-items: center; gap: .65rem; padding: 1.1rem 1rem 1rem;
  color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255,255,255,.09);
}
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-flex; color: #fff; }
.brand-mark img { max-height: 34px; max-width: 120px; border-radius: 4px; background: #fff; padding: 2px; }
.brand-name { font-weight: 700; letter-spacing: .01em; font-size: 1.02rem; }

.sidebar nav { flex: 1; padding: .8rem .6rem; display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: .7rem; padding: .55rem .75rem;
  color: #b9c8d6; border-radius: 7px; font-weight: 500; position: relative;
}
.sidebar nav a svg { flex-shrink: 0; opacity: .85; }
.sidebar nav a:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.sidebar nav a.active { background: rgba(255,255,255,.1); color: #fff; }
.sidebar nav a.active::before {
  content: ""; position: absolute; left: -6px; top: 20%; bottom: 20%;
  width: 3px; border-radius: 2px; background: var(--rosso);
}
.sidebar-foot {
  padding: .9rem 1rem; border-top: 1px solid rgba(255,255,255,.09);
  display: flex; align-items: center; justify-content: space-between; gap: .6rem;
}
.sidebar-foot .who { font-family: var(--mono); font-size: .8rem; color: #8fa3b5; overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot a { display: inline-flex; align-items: center; gap: .35rem; color: #ffb3ad; font-size: .85rem; }

.content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
main { width: 100%; max-width: 1080px; margin: 0 auto; padding: 1.4rem 1.6rem 0; flex: 1; display: flex; flex-direction: column; }
main > :last-child { margin-top: auto; }

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.page-head h1 { margin: 0; }
.page-actions { display: flex; gap: .5rem; }

.product-footer {
  margin-top: 2.5rem; padding: 1.1rem 0 1.3rem; border-top: 1px solid var(--line);
  color: #98a4ae; font-size: .78rem; text-align: center; letter-spacing: .02em;
}
.product-footer svg { vertical-align: -2px; margin-right: .2rem; }
.product-footer strong { color: var(--grafite); font-weight: 600; }

/* ---- Pagine pubbliche ---------------------------------------------------- */
body.public { display: flex; min-height: 100vh; }
.public-wrap { width: 100%; max-width: 720px; margin: auto; padding: 2rem 1rem; }
.public-brand {
  display: flex; align-items: center; justify-content: center; gap: .6rem;
  color: var(--ink); margin-bottom: 1.1rem;
}
.public-brand .brand-name { font-weight: 700; font-size: 1.15rem; }
.public-brand img { max-height: 44px; max-width: 170px; }
.public-card { padding: 0 2.2rem 1.8rem; overflow: hidden; }
.public-card > .airmail { margin: 0 -2.2rem 1.2rem; border-radius: 0; }
.illustration { display: block; width: 210px; max-width: 70%; margin: .4rem auto 1rem; }
body.public .product-footer { border-top: 0; margin-top: 1.2rem; padding-top: 0; }

/* ---- Tabelle ------------------------------------------------------------- */
table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; box-shadow: 0 1px 3px rgba(26,44,62,.08); }
th, td { text-align: left; padding: .6rem .75rem; border-bottom: 1px solid #eef0ec; vertical-align: top; }
th { background: #fafaf7; font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--grafite); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfcfd; }
td.wrap { word-break: break-all; }
td.actions { white-space: nowrap; }
td small { color: var(--grafite); }

/* ---- Card e form --------------------------------------------------------- */
.card {
  background: var(--card); padding: 1.4rem; border-radius: 10px; margin: 1rem 0;
  box-shadow: 0 1px 3px rgba(26,44,62,.08);
}
label { display: block; margin: .75rem 0; font-weight: 600; font-size: .84rem; color: var(--ink); }
label input[type=text], label input[type=email], label input[type=password], label input[type=file],
label select, label textarea, .filters input[type=text], .filters select {
  display: block; width: 100%; margin-top: .3rem; padding: .55rem .65rem;
  border: 1px solid #ccd3d0; border-radius: 7px; font: inherit; font-weight: 400;
  background: #fff; color: var(--ink); transition: border-color .12s;
}
label input:focus, label select:focus, label textarea:focus { border-color: var(--azzurro); outline: none; box-shadow: 0 0 0 3px rgba(59,119,184,.12); }
label.check { font-weight: 400; }
label.check input { margin-right: .45rem; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: .9rem 0; padding: .6rem .9rem .8rem; }
legend { font-size: .74rem; font-weight: 700; color: var(--grafite); text-transform: uppercase; letter-spacing: .05em; padding: 0 .4rem; }
textarea { font-family: var(--mono); font-size: .84rem; line-height: 1.5; }
input[type=email], .mono { font-family: var(--mono); }

button, .btn-secondary {
  display: inline-block; background: var(--azzurro); color: #fff; border: 0; padding: .55rem 1.15rem;
  border-radius: 7px; font: inherit; font-weight: 600; cursor: pointer; margin-top: .4rem;
}
button:hover { background: var(--azzurro-deep); }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid #ccd3d0; text-decoration: none; }
.btn-secondary:hover { border-color: var(--grafite); background: #fafaf7; text-decoration: none; color: var(--ink); }
button.link { background: none; color: var(--azzurro); padding: 0; margin: 0; font-weight: 400; }
button.link:hover { text-decoration: underline; background: none; }
.danger, button.link.danger { color: var(--rosso); }
.danger-btn { background: var(--rosso); } .danger-btn:hover { background: #a53531; }
form.inline { display: inline; margin-left: .5rem; }

/* ---- Messaggi ------------------------------------------------------------ */
.flash { padding: .7rem 1rem; border-radius: 8px; margin: .8rem 0; border: 1px solid transparent; }
.flash-success { background: var(--ok-bg); color: var(--ok); border-color: #cbe5d2; }
.flash-error { background: var(--err-bg); color: #8e2721; border-color: #f0cecb; }
.flash-info { background: #e9f1f9; color: #2a557e; border-color: #cfdfef; }

/* ---- Dashboard tiles ------------------------------------------------------ */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .8rem; margin: 1rem 0; }
.tile {
  background: var(--card); border-radius: 10px; padding: .95rem 1.1rem;
  box-shadow: 0 1px 3px rgba(26,44,62,.08); display: flex; flex-direction: column; gap: .1rem;
  border-top: 3px solid var(--azzurro);
}
.tile:nth-child(4n+2) { border-top-color: var(--rosso); }
.tile:nth-child(4n+3) { border-top-color: var(--ink); }
.tile:nth-child(4n) { border-top-color: var(--grafite); }
.tile strong { font-size: 1.55rem; font-family: var(--mono); letter-spacing: -.02em; }
.tile span { font-size: .72rem; color: var(--grafite); text-transform: uppercase; letter-spacing: .06em; }

/* ---- Badge ---------------------------------------------------------------- */
.badge { font-size: .72rem; padding: .16rem .55rem; border-radius: 20px; background: #edf0f2; color: #45535f; white-space: nowrap; font-weight: 600; }
.badge-sending, .badge-queued { background: var(--warn-bg); color: var(--warn); }
.badge-sent, .badge-active { background: var(--ok-bg); color: var(--ok); }
.badge-paused, .badge-pending { background: #e9f1f9; color: #2a557e; }
.badge-failed, .badge-unsubscribed { background: var(--err-bg); color: #8e2721; }

/* ---- Filtri, pager, colonne ---------------------------------------------- */
.filters { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin: 1rem 0; }
.filters input[type=text] { width: 250px; }
.filters select, .filters input { display: inline-block; margin: 0; }
.filters button { margin: 0; }

.cols { display: flex; gap: 1rem; flex-wrap: wrap; }
.cols > * { flex: 1; min-width: 240px; }

.pager { margin: 1rem 0; display: flex; gap: .3rem; flex-wrap: wrap; }
.pager a { padding: .3rem .65rem; border-radius: 6px; background: var(--card); }
.pager a.active { background: var(--azzurro); color: #fff; }

iframe.preview { width: 100%; height: 420px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* ---- simple-datatables ----------------------------------------------------- */
.datatable-wrapper .datatable-top, .datatable-wrapper .datatable-bottom { padding: .5rem 0; }
.datatable-wrapper .datatable-input, .datatable-wrapper .datatable-selector {
  padding: .45rem .65rem; border: 1px solid #ccd3d0; border-radius: 7px; font: inherit; background: #fff;
}
.datatable-wrapper .datatable-info { color: var(--grafite); font-size: .82rem; }
.datatable-wrapper .datatable-pagination a, .datatable-wrapper .datatable-pagination button {
  padding: .3rem .6rem; border-radius: 6px; cursor: pointer; color: var(--ink);
}
.datatable-wrapper .datatable-pagination .datatable-active a,
.datatable-wrapper .datatable-pagination .datatable-active button { background: var(--azzurro); color: #fff; }
.datatable-wrapper table.data { margin-top: .3rem; }
th.datatable-ascending, th.datatable-descending { cursor: pointer; }

/* ---- Varie ----------------------------------------------------------------- */
.muted { color: #93a1ac; font-weight: 400; }
.origin-box {
  background: #fafaf7; border: 1px solid var(--line); border-radius: 8px;
  padding: .75rem .95rem; margin: .9rem 0;
}
.origin-box strong { display: block; font-size: .72rem; text-transform: uppercase; letter-spacing: .05em; color: var(--grafite); margin-bottom: .3rem; }
.logo-preview { display: flex; align-items: center; gap: .8rem; margin: .5rem 0; }
.logo-preview img { max-height: 44px; max-width: 160px; border: 1px solid var(--line); border-radius: 6px; padding: 4px; background: #fff; }

/* ---- Responsive ------------------------------------------------------------ */
@media (max-width: 860px) {
  .shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; padding: .4rem .6rem; }
  .sidebar nav a { padding: .45rem .6rem; }
  .sidebar nav a.active::before { display: none; }
  .sidebar-foot { padding: .5rem 1rem; }
  main { padding: 1rem; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ---- Modali ---------------------------------------------------------------- */
dialog.modal {
  border: 0; border-radius: 12px; padding: 0; width: min(480px, calc(100vw - 2rem));
  box-shadow: 0 24px 70px rgba(16,28,40,.35);
  opacity: 0; transform: translateY(14px) scale(.97);
  transition: opacity .22s ease, transform .22s cubic-bezier(.2,.9,.3,1.2), overlay .22s allow-discrete, display .22s allow-discrete;
}
dialog.modal[open] { opacity: 1; transform: none; }
@starting-style { dialog.modal[open] { opacity: 0; transform: translateY(14px) scale(.97); } }
dialog.modal::backdrop {
  background: rgba(18,30,42,.45); backdrop-filter: blur(3px);
  transition: background .22s ease, overlay .22s allow-discrete, display .22s allow-discrete;
}
dialog.modal > form { padding: 1.3rem 1.4rem 1.2rem; margin: 0; }
dialog.modal::before {
  content: ""; display: block; height: 4px;
  background: repeating-linear-gradient(-45deg, var(--rosso) 0 9px, #fff 9px 18px, var(--azzurro) 18px 27px, #fff 27px 36px);
}
.modal-head { display: flex; align-items: center; gap: .55rem; margin-bottom: .4rem; color: var(--ink); }
.modal-head h2 { margin: 0; }
.modal-head svg { color: var(--azzurro); }
.modal-foot { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1.1rem; }
.modal-foot button { margin-top: 0; }
@media (prefers-reduced-motion: reduce) {
  dialog.modal { transition: none; transform: none; }
}

/* ---- Jodit (editor visuale) ------------------------------------------------ */
.ed-switch { display: flex; justify-content: flex-end; margin: .35rem 0; }
.ed-toggle { font-size: .78rem; padding: .3rem .7rem; margin: 0; }
.jodit-container:not(.jodit_inline) { border-color: #ccd3d0; border-radius: 7px; }
.jodit-toolbar__box:not(:empty) { background: #fafaf7; border-radius: 7px 7px 0 0; }
[class*=jodit] button { background: transparent; color: inherit; padding: revert; margin: 0; border-radius: revert; font-weight: revert; }
[class*=jodit] button:hover { background: transparent; }
.jodit-toolbar-button__button:hover:not([disabled]) { background-color: var(--line); }
.jodit-status-bar { border-radius: 0 0 7px 7px; }
.jodit-ui-button_variant_primary { background: var(--azzurro); }

/* Textarea fuori da label (editor campagne/template) */
form textarea { display: block; width: 100%; margin-top: .3rem; padding: .55rem .65rem;
  border: 1px solid #ccd3d0; border-radius: 7px; font-weight: 400; background: #fff; color: var(--ink); }
form textarea:focus { border-color: var(--azzurro); outline: none; box-shadow: 0 0 0 3px rgba(59,119,184,.12); }

/* Altezza piena per le textarea degli editor (HTML puro) */
#body_html, #tpl_html { min-height: 460px; resize: vertical; }

.att-list { list-style: none; padding: 0; margin: .3rem 0; }
.att-list li { padding: .25rem 0; }

.intro-html { color: var(--grafite); margin: 0 0 1.2rem; }
.intro-html p { margin: 0 0 .7em; }
.intro-html :last-child { margin-bottom: 0; }
