/* Mini CRM */
:root {
    --bg: #f4f5f7;
    --card: #ffffff;
    --text: #1c2430;
    --muted: #667085;
    --line: #e3e6eb;
    --accent: #1d4ed8;
    --accent-dark: #1a3fb0;
    --danger: #b42318;
    --ok-bg: #e8f6ee;
    --ok-text: #14633a;
    --err-bg: #fdecea;
    --err-text: #8f1d14;
    --radius: 8px;
}

* { box-sizing: border-box; }

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

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 24px; line-height: 1.25; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 24px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
p { margin: 0 0 12px; }

.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
main.wrap { padding-top: 24px; padding-bottom: 56px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* Barra superiore */
.top { background: #101828; color: #fff; }
.top-in { display: flex; align-items: center; gap: 20px; min-height: 54px; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 650; font-size: 16px; }
.brand:hover { text-decoration: none; }
.top nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.top nav a { color: #c7cdd8; padding: 6px 10px; border-radius: 6px; }
.top nav a:hover { color: #fff; text-decoration: none; background: rgba(255, 255, 255, 0.08); }
.top nav a.on { color: #fff; background: rgba(255, 255, 255, 0.14); }
.top form { margin: 0; }
.top .btn.ghost { color: #c7cdd8; border-color: rgba(255, 255, 255, 0.25); }
.top .btn.ghost:hover { color: #fff; background: rgba(255, 255, 255, 0.08); }

/* Titolo pagina */
.head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.head p { margin: 4px 0 0; }
.back { margin-bottom: 10px; font-size: 14px; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Card */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card.narrow { max-width: 520px; }
.card.empty { text-align: center; padding: 44px 20px; color: var(--muted); }
.card.empty strong { color: var(--text); }
.card.table-wrap { padding: 0; }
.table-wrap { overflow-x: auto; }

/* Pulsanti */
.btn {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid #cfd4dc;
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    font: inherit;
    font-weight: 550;
    line-height: 1.3;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: #f6f7f9; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-dark); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: #eef0f3; color: var(--text); }
.btn.danger { color: var(--danger); border-color: #f1b8b3; }
.btn.danger:hover { background: var(--err-bg); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.wide { width: 100%; padding: 10px 14px; }

/* Campi */
input[type="text"], input[type="email"], input[type="password"], input[type="search"], input[type="number"], input[type="tel"], input[type="datetime-local"], select, textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #cfd4dc;
    border-radius: 6px;
    background: #fff;
    color: var(--text);
    font: inherit;
}
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid #9db7f5; outline-offset: 1px; border-color: var(--accent); }
input[readonly] { background: #f6f7f9; }
input[type="color"] { width: 44px; height: 36px; padding: 2px; border: 1px solid #cfd4dc; border-radius: 6px; background: #fff; cursor: pointer; }
input.num { width: 72px; }
textarea { resize: vertical; margin-bottom: 10px; }
label { display: block; font-weight: 550; margin-bottom: 14px; }
label input, label select { margin-top: 5px; font-weight: 400; }

form.inline { display: flex; gap: 8px; align-items: center; margin: 0; }
form.inline.wrap-inline { flex-wrap: wrap; }
form.inline.wrap-inline > input, form.inline.wrap-inline > select { flex: 1 1 180px; }

/* Filtri ed etichette di stato */
.filters { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.filters input[type="search"] { flex: 1 1 260px; }
.filters select { flex: 0 1 220px; width: auto; }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; color: var(--text); font-size: 14px; }
.tabs a:hover { text-decoration: none; border-color: #b9c0cc; }
.tabs a b { color: var(--muted); font-weight: 600; margin-left: 4px; }
.tabs a.on { background: #101828; border-color: #101828; color: #fff; }
.tabs a.on b { color: #c7cdd8; }

.badge { display: inline-flex; align-items: center; gap: 7px; padding: 3px 10px 3px 8px; border: 1px solid var(--line); border-radius: 999px; background: #fff; font-size: 13px; font-weight: 550; white-space: nowrap; }
.badge i { width: 9px; height: 9px; border-radius: 50%; flex: none; }

/* Tabelle */
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; padding: 10px 14px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
table.list tbody tr:hover { background: #fafbfc; }
table.list .name { font-weight: 600; }
table.list .msg { max-width: 340px; }
table.form-table td { vertical-align: middle; }
table.form-table form { margin: 0; }
table.form-table form.inline input { min-width: 170px; }

.pager { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; font-size: 14px; }
.pager-nav { display: flex; align-items: center; gap: 10px; }

/* Scheda contatto */
.cols { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 16px; align-items: start; }
dl.data { display: grid; grid-template-columns: minmax(110px, 30%) 1fr; gap: 10px 16px; margin: 0; }
dl.data dt { color: var(--muted); }
dl.data dd { margin: 0; overflow-wrap: anywhere; }
.meta { margin: 20px 0 0; padding-top: 14px; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.danger-zone { margin: 0 0 16px; }

.timeline { list-style: none; margin: 18px 0 0; padding: 0; }
.timeline li { padding: 12px 0 12px 14px; border-left: 3px solid var(--line); margin-left: 2px; }
.timeline li + li { margin-top: 2px; }
.timeline li.t-note { border-left-color: var(--accent); }
.timeline li.t-status { border-left-color: #d97706; }
.t-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.t-body { overflow-wrap: anywhere; }

/* Messaggi */
.flash { padding: 10px 14px; border-radius: 6px; margin-bottom: 16px; }
.flash.ok { background: var(--ok-bg); color: var(--ok-text); }
.flash.error { background: var(--err-bg); color: var(--err-text); }

/* Accesso e primo avvio */
body.bare main.wrap { max-width: 420px; padding-top: 9vh; }
.auth { padding: 28px; }
.auth h1 { margin-bottom: 4px; }
.auth form { margin-top: 20px; }

table.list .when { display: none; }

/* Solleciti */
.chip { display: inline-block; margin-top: 7px; padding: 2px 9px; border-radius: 6px; font-size: 12px; font-weight: 600; background: #eef0f3; color: #475467; white-space: nowrap; }
.chip.overdue { background: #fee4e2; color: #b42318; }
.badges { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.badges .chip { margin-top: 0; }
.timeline li.t-nudge { border-left-color: #b42318; }
input.hours { width: 72px; }
select.unit { width: auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.form-grid .full { grid-column: 1 / -1; }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
label.check input { margin-top: 4px; }
.status-line { margin: 0 0 6px; font-size: 14px; }
.status-line b { font-weight: 600; }
code.copy { display: block; padding: 8px 10px; background: #f6f7f9; border: 1px solid var(--line); border-radius: 6px; font-size: 13px; overflow-wrap: anywhere; margin: 4px 0 12px; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
table.list td .small { overflow-wrap: anywhere; }

@media (max-width: 800px) {
    .cols { grid-template-columns: 1fr; }
    table.list .col-msg { display: none; }
    dl.data { grid-template-columns: 1fr; gap: 2px 0; }
    dl.data dd { margin-bottom: 10px; }
}

@media (max-width: 600px) {
    table.list .col-date, table.list .col-form { display: none; }
    table.list .when { display: block; }
    table.list th, table.list td { padding-left: 12px; padding-right: 12px; }
    .top-in { gap: 8px 14px; padding-top: 8px; padding-bottom: 8px; }
    .top nav { order: 3; flex: 1 0 100%; }
    .top .brand { flex: 1; }
}

/* Elenco filtrato sui contatti fermi */
.filter-note { margin: -4px 0 14px; padding: 9px 14px; border-radius: 6px; background: #fee4e2; color: #8f1d14; font-size: 14px; }

/* Riepilogo */
.card h2 small { font-weight: 400; color: var(--muted); font-size: 13px; margin-left: 6px; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.tile { display: block; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; color: var(--text); }
a.tile:hover { text-decoration: none; border-color: #b9c0cc; }
.tile .lbl { color: var(--muted); font-size: 13px; }
.tile .val { font-size: 30px; font-weight: 650; line-height: 1.2; margin-top: 4px; letter-spacing: -0.01em; }
.tile .sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
.tile .up { color: #14633a; font-weight: 600; }
.tile .down { color: #b42318; font-weight: 600; }
.tile.alert .val { color: #b42318; }

.chart { padding: 8px 0 0 34px; }
.plot { position: relative; height: 200px; }
.plot .grid { position: absolute; left: 0; right: 0; border-top: 1px solid #eceef2; }
.plot .grid:first-child { border-top-color: #cfd4dc; }
.plot .grid span { position: absolute; left: -34px; top: -9px; width: 26px; text-align: right; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.plot .cols { position: absolute; inset: 0; display: flex; align-items: flex-end; }
.plot .col { position: relative; flex: 1 1 0; min-width: 0; height: 100%; display: flex; justify-content: center; align-items: flex-end; outline: none; }
.plot .col .bar { display: block; width: 24px; max-width: 60%; background: #2563eb; border-radius: 4px 4px 0 0; }
.plot .col .bar.now { background: #9db7f5; }
.plot .col em { position: absolute; left: 0; right: 0; text-align: center; font-style: normal; font-size: 12px; font-weight: 600; color: var(--text); }
.plot .col:hover, .plot .col:focus-visible { background: rgba(37, 99, 235, 0.06); border-radius: 4px; }
.plot .col:hover::after, .plot .col:focus-visible::after {
    content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
    background: #101828; color: #fff; font-size: 12px; padding: 5px 9px; border-radius: 6px; white-space: nowrap; z-index: 2; pointer-events: none;
}
.plot .col:first-child:hover::after, .plot .col:first-child:focus-visible::after { left: 0; transform: none; }
.plot .col:last-child:hover::after, .plot .col:last-child:focus-visible::after { left: auto; right: 0; transform: none; }
.xlabels { display: flex; margin-top: 6px; }
.xlabels span { flex: 1 1 0; min-width: 0; overflow: visible; text-align: center; font-size: 12px; color: var(--muted); white-space: nowrap; }
.data-table { margin-top: 14px; font-size: 14px; }
.data-table summary { cursor: pointer; color: var(--accent); }
.data-table table { margin-top: 8px; max-width: 360px; }
.data-table td, .data-table th { padding: 6px 10px; }

.three { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; align-items: start; }
.three .card { margin-bottom: 16px; }
.hbars { list-style: none; margin: 0; padding: 0; }
.hbars li { display: grid; grid-template-columns: 1fr auto; gap: 5px 10px; align-items: center; margin-bottom: 13px; }
.hbars li:last-child { margin-bottom: 0; }
.hbars .nm { font-size: 14px; display: flex; align-items: center; gap: 7px; min-width: 0; overflow-wrap: anywhere; }
.hbars .nm i { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.hbars b { font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; }
.hbars .track { grid-column: 1 / -1; height: 8px; }
.hbars .bar { display: block; height: 8px; min-width: 4px; border-radius: 0 4px 4px 0; background: #2563eb; }
.field-pick { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.field-pick label { margin: 0; font-weight: 400; }

@media (max-width: 900px) {
    .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .three { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
    .xlabels span.odd { visibility: hidden; }
    .xlabels small { display: none; }
    .tile .val { font-size: 26px; }
}

/* Importazione */
.upload { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 6px 0 12px; }
.upload input[type="file"] { flex: 1 1 260px; padding: 8px; border: 1px dashed #b9c0cc; border-radius: 6px; background: #fafbfc; }
.preview-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.preview-card { border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; font-size: 14px; }
.preview-card .pv-name { font-weight: 650; margin: 0; }
.preview-card .muted.small { margin: 0 0 10px; }
.preview-card dl.data { grid-template-columns: minmax(90px, 38%) 1fr; gap: 6px 10px; }
.confirm-bar { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--line); align-items: center; }
.confirm-bar form { margin: 0; }
@media (max-width: 900px) { .preview-grid { grid-template-columns: 1fr; } }

/* Cancellazione dei contatti */
.danger-card { border-color: #f1b8b3; }
.danger-card h2 { color: #b42318; }
.wipe { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-top: 4px; }
.wipe label { margin: 0; flex: 0 1 280px; }
.wipe input { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; letter-spacing: 0.05em; }
.btn.danger-solid { background: #b42318; border-color: #b42318; color: #fff; }
.btn.danger-solid:hover { background: #912018; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Report settimanale */
.report-test { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line); }

/* Promemoria e campo in evidenza */
.chip.rem-future { background: #eef0f3; color: #475467; }
.chip.rem-today { background: #fef0c7; color: #93370d; }
.chip.rem-overdue { background: #fee4e2; color: #b42318; }
.tabs a.known-tab { margin-left: auto; }
.tabs a.rem b.alert { background: #b42318; color: #fff; border-radius: 999px; padding: 0 7px; }
.tabs a.rem.on b.alert { background: #fff; color: #b42318; }
.timeline li.t-reminder { border-left-color: #7c3aed; }
.rem-box .chip { margin: 0 0 12px; font-size: 13px; padding: 4px 11px; }
.rem-box form.inline { flex-wrap: wrap; }
.rem-box input[type="date"] { width: auto; flex: 1 1 150px; padding: 7px 10px; border: 1px solid #cfd4dc; border-radius: 6px; font: inherit; }
.rem-box .quick { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.rem-box .quick form { margin: 0; }
.filters select[name="cat"] { flex: 0 1 220px; width: auto; }
@media (max-width: 800px) { table.list .col-cat { display: none; } }

/* Inserimento e modifica manuale */
.edit-link { vertical-align: middle; margin-left: 8px; font-size: 13px; font-weight: 550; letter-spacing: 0; }
.edit-form .form-grid label { min-width: 0; }
.edit-form textarea { margin-bottom: 0; }
.edit-form .actions { margin-top: 6px; }
.new-field { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); gap: 10px; margin-bottom: 10px; }
.flash.warn { background: #fef0c7; color: #7a2e0e; }
.flash.warn p { margin: 0 0 6px; }
.flash.warn ul { margin: 0 0 10px; padding-left: 20px; }
.flash.warn a { color: #7a2e0e; text-decoration: underline; }
.timeline li.t-edit { border-left-color: #0e9384; }
.timeline li.t-edit .t-body { white-space: pre-line; }
@media (max-width: 600px) { .new-field { grid-template-columns: 1fr; } }

/* Recupero password e sicurezza */
.auth-foot { margin: 16px 0 0; text-align: center; font-size: 14px; }
.notice-bar { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; justify-content: space-between; padding: 10px 14px; margin-bottom: 16px; border-radius: 6px; background: #fef0c7; color: #7a2e0e; }
.notice-bar a { color: #7a2e0e; font-weight: 600; }
.reset-req { border: 1px solid #f5d48a; background: #fffaeb; border-radius: 8px; padding: 12px 14px; margin-bottom: 10px; }
.reset-req dl { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 2px 14px; margin: 0 0 10px; font-size: 14px; }
.reset-req dt { color: var(--muted, #667085); }
.reset-req dd { margin: 0; overflow-wrap: anywhere; }
.reset-req .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.sec-log { font-size: 13px; }
.sec-log td { vertical-align: top; }
.role-form select { width: auto; }
.chip.super { background: #ede9fe; color: #5b21b6; }

/* Piè di pagina e novità */
main.wrap:has(+ .foot) { padding-bottom: 24px; }
.foot { display: flex; gap: 6px 16px; flex-wrap: wrap; justify-content: center; padding-top: 4px; padding-bottom: 28px; color: var(--muted); font-size: 13px; }
.foot a { color: var(--muted); text-decoration: underline; }
.changelog { max-width: 760px; }
.cl-version + .cl-version { border-top: 1px solid #e3e6eb; margin-top: 18px; padding-top: 18px; }
.cl-version h2 { display: flex; align-items: center; gap: 8px; }
.cl-version ul { margin: 6px 0 0; padding-left: 20px; line-height: 1.55; }
.cl-version li + li { margin-top: 4px; }

/* Già noti */
.chip.known { background: #e0f2fe; color: #075985; margin: 2px 0 0; vertical-align: 1px; }
.related { list-style: none; margin: 0; padding: 0; }
.related li { padding: 10px 0; border-top: 1px solid #eef0f3; }
.related li:first-child { border-top: 0; padding-top: 2px; }
.related .r-head { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.related .r-head .badge { font-size: 12px; }
.related .r-msg { margin: 4px 0 0; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.badges .chip.known { margin: 0; text-decoration: none; }

/* Selezione multipla e spam */
.col-check { width: 34px; padding-right: 0 !important; }
.col-check input { width: 17px; height: 17px; margin: 0; cursor: pointer; accent-color: var(--accent); }
tr.selected td { background: #f2f6ff; }
.bulk-bar { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; justify-content: space-between; padding: 8px 12px; margin-bottom: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.bulk-bar.active { border-color: #9db7f5; background: #f2f6ff; }
.bulk-count { color: var(--muted); font-size: 14px; }
.bulk-bar.active .bulk-count { color: var(--text); font-weight: 600; }
.bulk-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.bulk-actions select { width: auto; padding: 5px 8px; font-size: 14px; }
.bulk-actions .btn:disabled { opacity: .45; cursor: default; }
.tabs a.spam-tab:not(.on) { color: var(--muted); border-style: dashed; }
.spam-note { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; justify-content: space-between; }
.spam-note form { margin: 0; }
.spam-form { margin-top: 10px; }
.spam-hint { margin: 10px 0 0; }
