/* ===========================================================================
   Messaggi Web - foglio di stile
   Nessuna dipendenza esterna: colori a token, tema chiaro e scuro.
   =========================================================================== */

:root {
  --bg: #f2f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #dde3ec;
  --text: #1f2933;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e8f0fe;
  --success: #15803d;
  --success-soft: #e7f6ec;
  --warning: #b45309;
  --warning-soft: #fdf3e3;
  --error: #b91c1c;
  --error-soft: #fdecec;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1a2334;
  --surface-2: #141d2c;
  --border: #2b3648;
  --text: #e6ebf3;
  --muted: #94a3b8;
  --accent: #4b8bf5;
  --accent-hover: #6ba0f7;
  --accent-soft: #1e2c46;
  --success: #4ade80;
  --success-soft: #16281d;
  --warning: #fbbf24;
  --warning-soft: #2b2313;
  --error: #f87171;
  --error-soft: #2c1717;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
}

h1, h2, h3 { margin: 0 0 .6rem; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; }
h3 { font-size: .95rem; margin-top: 1.2rem; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

/* ------------------------------- accesso ------------------------------- */

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: linear-gradient(160deg, var(--bg), var(--accent-soft));
}

.login-card {
  width: min(400px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 2rem;
}

.login-logo {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  border-radius: 12px; font-size: 22px;
  margin-bottom: .9rem;
}

/* ------------------------------- struttura ----------------------------- */

.app { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 1rem;
  flex-wrap: wrap;
  padding: .6rem 1.1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}

.brand { font-weight: 700; display: flex; align-items: center; gap: .5rem; }
.brand-mark {
  width: 26px; height: 26px; border-radius: 7px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 14px;
}

.tabs { display: flex; gap: .2rem; flex: 1; flex-wrap: wrap; }

.tab {
  border: none; background: none; color: var(--muted);
  padding: .5rem .8rem; border-radius: 8px;
  font: inherit; font-weight: 600; cursor: pointer;
}
.tab:hover { background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--accent-soft); color: var(--accent); }

.topbar-right { display: flex; align-items: center; gap: .4rem; }
.user-chip {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: .25rem .6rem; border-radius: 999px; font-size: .82rem;
}

.content { flex: 1; padding: 1.1rem; max-width: 1280px; width: 100%; margin: 0 auto; }
.footer { padding: .8rem 1.1rem; text-align: center; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; align-items: start; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr; } }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem;
  margin-bottom: 1rem;
}

.card-head {
  display: flex; justify-content: space-between; align-items: center;
  gap: .6rem; flex-wrap: wrap; margin-bottom: .6rem;
}
.head-actions { display: flex; gap: .4rem; flex-wrap: wrap; }

.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }

/* ------------------------------- moduli -------------------------------- */

label { display: block; font-weight: 600; margin: .8rem 0 .3rem; }
label.check {
  display: flex; align-items: flex-start; gap: .5rem;
  font-weight: 500; margin: .5rem 0;
}
label.check input { margin-top: .2rem; }

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="search"], textarea, select {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, textarea:focus, select:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.inline { display: flex; gap: .4rem; }
.inline input { flex: 1; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: 1rem; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: .55rem 1rem;
  border-radius: 8px;
  font: inherit; font-weight: 600;
  cursor: pointer;
}
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.small { padding: .35rem .7rem; font-size: .82rem; }
.btn.block { width: 100%; }
.btn.danger { color: var(--error); border-color: var(--error); background: transparent; }
.btn.danger:hover:not(:disabled) { background: var(--error-soft); }

.counter-row { display: flex; justify-content: space-between; font-size: .82rem; margin-top: .3rem; }

/* ------------------------------- allegati ------------------------------ */

.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  text-align: center;
  cursor: pointer;
  display: grid; gap: .2rem;
  background: var(--surface-2);
}
.dropzone:hover, .dropzone.dragging {
  border-color: var(--accent); background: var(--accent-soft);
}

.attachments { list-style: none; margin: .6rem 0 0; padding: 0; display: grid; gap: .35rem; }
.attachments li {
  display: flex; align-items: center; gap: .6rem;
  padding: .45rem .6rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2);
}
.attachments .name { flex: 1; word-break: break-all; }
.attachments .size { color: var(--muted); font-size: .82rem; white-space: nowrap; }

.progress { height: 4px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* --------------------------- home dei programmi ------------------------ */

/* La home contiene soltanto i pulsanti dei programmi. */
.hub-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: .9rem;
  margin: .6rem 0;
}

.hub-card {
  display: grid;
  gap: .2rem;
  justify-items: start;
  text-align: left;
  padding: 1.1rem 1.2rem;
  min-height: 128px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  font: inherit;
  color: var(--text);
  cursor: pointer;
  transition: transform .12s, border-color .12s;
}
.hub-card:hover { transform: translateY(-2px); border-color: var(--accent); }
.hub-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.hub-icon {
  width: 40px; height: 40px; margin-bottom: .5rem;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  border-radius: 10px; font-size: 19px;
}
.hub-name { font-weight: 700; font-size: 1rem; }
.hub-note { color: var(--muted); font-size: .82rem; }

.hub-card.empty { border-style: dashed; box-shadow: none; background: var(--surface-2); }
.hub-card.empty .hub-icon { background: var(--border); color: var(--muted); }
.hub-card.empty .hub-name { color: var(--muted); font-weight: 600; }
.hub-card.empty:hover { transform: none; border-color: var(--muted); }

/* ------------------------------ destinatari ---------------------------- */

.channels {
  display: flex; align-items: center; gap: .5rem;
  flex-wrap: wrap; margin-bottom: .6rem;
}
.channels .check { margin: 0; }

/* Stato del canale: un pallino, la spiegazione e' nel suggerimento */
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--muted); margin-right: .7rem;
}
.dot.ok { background: var(--success); }
.dot.ko { background: var(--error); }

details.more { margin: .6rem 0; }
details.more > summary {
  cursor: pointer; color: var(--muted); font-size: .85rem;
  padding: .2rem 0; user-select: none;
}
details.more > summary:hover { color: var(--text); }
details.more textarea { margin-top: .4rem; }

.badge {
  font-size: .75rem; padding: .15rem .55rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.badge.ok { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge.ko { background: var(--error-soft); color: var(--error); border-color: transparent; }

.contact-picker {
  list-style: none; margin: .4rem 0 0; padding: .3rem;
  max-height: 190px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface-2);
}
.contact-picker li { padding: .3rem; border-radius: 6px; }
.contact-picker li:hover { background: var(--surface); }
.contact-picker label { display: flex; gap: .5rem; margin: 0; font-weight: 500; align-items: center; }
.contact-picker .recap { color: var(--muted); font-size: .8rem; }

/* ------------------------------- tabelle ------------------------------- */

.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.table th, .table td {
  text-align: left; padding: .55rem .6rem;
  border-bottom: 1px solid var(--border); vertical-align: top;
}
.table th { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; }
.table tbody tr:hover { background: var(--surface-2); }
.table .nowrap { white-space: nowrap; }

.pill {
  display: inline-block; padding: .1rem .55rem; border-radius: 999px;
  font-size: .75rem; font-weight: 700;
}
.pill.completato, .pill.inviato { background: var(--success-soft); color: var(--success); }
.pill.parziale { background: var(--warning-soft); color: var(--warning); }
.pill.fallito, .pill.errore { background: var(--error-soft); color: var(--error); }
.pill.in_coda, .pill.in_corso { background: var(--accent-soft); color: var(--accent); }

.pager { display: flex; align-items: center; justify-content: space-between; gap: .6rem; margin-top: .7rem; }

.detail-row td { background: var(--surface-2); }
.delivery-line { display: flex; gap: .5rem; padding: .2rem 0; flex-wrap: wrap; }

/* ------------------------------ statistiche ---------------------------- */

.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow);
}
.stat .value { font-size: 1.5rem; font-weight: 700; }
.stat .label { color: var(--muted); font-size: .8rem; }

/* -------------------------------- avvisi ------------------------------- */

.alert, .result {
  border-radius: 8px; padding: .7rem .8rem; margin-top: .8rem;
  border: 1px solid transparent; font-size: .9rem;
}
.alert.error, .result.error { background: var(--error-soft); color: var(--error); }
.alert.ok, .result.ok { background: var(--success-soft); color: var(--success); }
.alert.warn, .result.warn { background: var(--warning-soft); color: var(--warning); }
.result ul { margin: .4rem 0 0; padding-left: 1.1rem; }

.toasts { position: fixed; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; z-index: 50; }
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 8px; box-shadow: var(--shadow);
  padding: .7rem .9rem; max-width: 340px;
}
.toast.ok { border-left-color: var(--success); }
.toast.error { border-left-color: var(--error); }
.toast.warn { border-left-color: var(--warning); }

.logbox {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: .8rem; max-height: 420px; overflow: auto;
  font-family: Consolas, "Courier New", monospace; font-size: .78rem;
  white-space: pre-wrap; word-break: break-word; margin: 0;
}

dialog {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); color: var(--text);
  padding: 1.2rem; max-width: 480px; width: 92%;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .25);
}
dialog::backdrop { background: rgba(15, 23, 42, .45); }
