:root {
  --bg: #f4f6fa;
  --card: #fff;
  --border: #dde3ec;
  --text: #1d2433;
  --muted: #6b7486;
  --primary: #0c7c88;
  --primary-dark: #08626b;
  --danger: #c0392b;
  --warn: #d68910;
  --ok: #1e8449;
  --radius: 8px;
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 16px 0 8px; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.hidden { display: none !important; }

.topbar { display: flex; align-items: center; gap: 32px; background: #14202e; color: #fff; padding: 0 24px; height: 52px; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 16px; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: #c8d3e0; text-decoration: none; padding: 8px 14px; border-radius: 6px; }
.topbar nav a.active, .topbar nav a:hover { background: #24364a; color: #fff; }

main { padding: 24px; max-width: 1500px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; }
.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.layout-side { display: grid; grid-template-columns: 290px 1fr; gap: 16px; align-items: start; }
@media (max-width: 1000px) { .layout-side, .grid2 { grid-template-columns: 1fr; } }

button, .btn { font: inherit; border: 1px solid var(--border); background: #fff; color: var(--text); padding: 7px 14px; border-radius: 6px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
button:hover { border-color: #b9c3d2; background: #f8fafc; }
button.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
button.primary:hover { background: var(--primary-dark); }
button.danger { color: var(--danger); border-color: #ecc5c0; }
button.danger:hover { background: #fdf1ef; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.link { border: none; background: none; color: var(--primary); padding: 0; }

label { display: block; font-weight: 600; font-size: 12px; color: var(--muted); margin: 10px 0 4px; text-transform: uppercase; letter-spacing: .03em; }
input[type=text], input[type=email], input[type=number], input[type=password], input[type=search], select, textarea {
  font: inherit; width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff; color: var(--text);
}
textarea { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9bd3d9; border-color: var(--primary); }
.check { display: flex; align-items: center; gap: 6px; font-weight: normal; text-transform: none; letter-spacing: 0; color: var(--text); font-size: 13px; margin: 0; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid #edf0f5; vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #fafbfd; position: sticky; top: 0; }
tr:hover td { background: #fafcff; }
td.trunc { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; background: #eef1f6; color: var(--muted); white-space: nowrap; }
.badge.running { background: #e3f4f6; color: var(--primary); }
.badge.completed, .badge.sent { background: #e5f5ea; color: var(--ok); }
.badge.paused, .badge.pending { background: #fdf3e1; color: var(--warn); }
.badge.cancelled, .badge.failed { background: #fbe9e7; color: var(--danger); }
.badge.unsub { background: #fbe9e7; color: var(--danger); }

.facet { margin-bottom: 14px; }
.facet-list { max-height: 180px; overflow: auto; border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; background: #fff; }
.facet-list .check { padding: 2px 0; }
.facet-list .count { color: var(--muted); font-size: 11px; margin-left: auto; }
.facet input[type=search] { margin-bottom: 4px; padding: 4px 8px; font-size: 12px; }

.pager { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.stats { display: flex; gap: 12px; flex-wrap: wrap; }
.stat { background: #fafbfd; border: 1px solid var(--border); border-radius: 6px; padding: 10px 16px; min-width: 110px; }
.stat b { display: block; font-size: 22px; }
.progress { height: 10px; background: #e8ecf2; border-radius: 6px; overflow: hidden; display: flex; margin: 12px 0; }
.progress .sent { background: var(--ok); }
.progress .failed { background: var(--danger); }
.progress .skipped { background: #a0a8b6; }

.preview-frame { width: 100%; height: 640px; border: 1px solid var(--border); border-radius: 6px; background: #fff; }
.alert { padding: 10px 14px; border-radius: 6px; background: #fdf3e1; color: #7a5208; border: 1px solid #f3dcae; margin: 10px 0; }
.alert.error { background: #fbe9e7; color: #8e2b20; border-color: #f0c4be; }
.alert.ok { background: #e5f5ea; color: #1d5e33; border-color: #bfe3cb; }

.modal { position: fixed; inset: 0; background: rgba(15, 23, 35, .45); display: flex; align-items: flex-start; justify-content: center; padding: 50px 16px; z-index: 50; overflow: auto; }
.modal-box { background: #fff; border-radius: 10px; padding: 24px; width: 100%; max-width: 760px; position: relative; }
.modal-box.wide { max-width: 1100px; }
.modal-close { position: absolute; top: 10px; right: 10px; border: none; font-size: 22px; padding: 2px 10px; }

#toast { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
#toast div { background: #14202e; color: #fff; padding: 10px 16px; border-radius: 6px; box-shadow: 0 4px 14px rgba(0,0,0,.2); max-width: 420px; }
#toast div.error { background: var(--danger); }
.ph { font-family: ui-monospace, Consolas, monospace; background: #eef1f6; padding: 1px 6px; border-radius: 4px; font-size: 12px; }

.topbar .user { margin-left: auto; display: flex; align-items: center; gap: 10px; color: #c8d3e0; font-size: 13px; }
.topbar .user button { background: transparent; color: #c8d3e0; border-color: #33465c; padding: 4px 12px; }
.topbar .user button:hover { background: #24364a; color: #fff; }
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-box { width: 100%; max-width: 380px; padding: 28px; }
.brand-lg { font-weight: 700; font-size: 20px; margin-bottom: 18px; }

/* Statistiche campagna */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 14px; }
.kpi { background: #fafbfd; border: 1px solid var(--border); border-radius: 6px; padding: 10px 14px; }
.kpi span { display: block; font-size: 12px; color: var(--muted); }
.kpi b { display: block; font-size: 24px; margin: 2px 0; }
.kpi small { color: var(--muted); font-size: 12px; }
.funnel { margin-bottom: 10px; }
.funnel .bar { height: 8px; background: #edf0f5; border-radius: 4px; overflow: hidden; margin-top: 3px; }
.funnel .bar div { height: 100%; background: var(--primary); }
.chart { width: 100%; height: auto; }
.chart text { font-size: 10px; fill: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; align-items: center; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 5px; vertical-align: -1px; }
td.num, th.num { text-align: right; }
