/* ==========================================================================
   HAICCP — Pannello amministratore
   Richiede css/base.css
   ========================================================================== */

.admin-shell { display: none; min-height: 100vh; }
.admin-shell.ready { display: flex; }

.a-sidebar {
    position: fixed; inset: 0 auto 0 0; width: 232px; z-index: 50;
    display: flex; flex-direction: column; gap: 4px;
    padding: 16px 10px; background: var(--surface); border-right: 1px solid var(--border);
}
.a-sidebar .mark { padding: 0 8px 14px; }
.a-nav-label { padding: 14px 10px 4px; font-size: 11px; font-weight: 600; letter-spacing: 0.04em; text-transform: uppercase; color: var(--text-3); }
.a-nav {
    display: flex; align-items: center; gap: 10px; height: 34px; padding: 0 10px;
    font-size: 13.5px; font-weight: 500; color: var(--text); border-radius: var(--radius-sm);
    background: none; border: 0; width: 100%; text-align: left; cursor: pointer; text-decoration: none;
}
.a-nav i { width: 16px; color: var(--text-2); text-align: center; }
.a-nav:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.a-nav.active { background: var(--accent-soft); color: var(--accent-hover); }
.a-nav.active i { color: var(--accent); }
.a-count { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--warn); color: #fff; font-size: 11px; font-weight: 600; line-height: 20px; text-align: center; }
.a-sidebar-foot { margin-top: auto; padding: 12px 8px 0; border-top: 1px solid var(--border); font-size: 12px; color: var(--text-2); }
.a-sidebar-foot .btn { margin-top: 10px; }

.a-main { flex: 1; min-width: 0; margin-left: 232px; padding: 28px 32px 48px; max-width: 1400px; }
.a-section { display: none; }
.a-section.active { display: block; }
.a-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.a-head h1 { font-size: 20px; }
.a-head p { margin-top: 2px; font-size: 13px; color: var(--text-2); }
.a-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

.stats-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.stat-value { font-size: 22px; font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12.5px; color: var(--text-2); }
.stat-card.c-danger .stat-value { color: var(--bad); }
.stat-card.c-warning .stat-value { color: var(--warn); }
.stat-card.c-success .stat-value { color: var(--ok); }

.table-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.table-card-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.table-card-header h2 { font-size: 14px; }
.table-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.table-actions .search-input { width: 260px; }
.table-actions select { width: auto; }
.table-wrap { overflow-x: auto; }
table.a-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.a-table th { padding: 9px 14px; text-align: left; font-size: 12px; font-weight: 600; color: var(--text-2); background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.a-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.a-table tr:last-child td { border-bottom: 0; }
.a-table tbody tr:hover td { background: var(--surface-2); }
.a-table .sub { display: block; font-size: 12px; color: var(--text-2); }
.a-table .num { text-align: right; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.key-display { font-family: var(--font-mono); font-size: 12px; padding: 3px 6px; border-radius: 4px; background: var(--surface-3); color: var(--ink); cursor: copy; white-space: nowrap; }
.empty-state { padding: 40px 16px; text-align: center; color: var(--text-2); font-size: 13px; }
.empty-state i { display: block; font-size: 20px; color: var(--text-3); margin-bottom: 8px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--text-3); }
.status.active::before { background: var(--ok); }
.status.suspended::before { background: var(--warn); }
.status.expired::before { background: var(--bad); }
.status.new::before { background: var(--bad); }
.status.contacted::before { background: var(--warn); }
.status.done::before { background: var(--ok); }

.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.settings-card { padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.settings-card h3 { font-size: 15px; margin-bottom: 4px; }
.settings-card > p { font-size: 13px; color: var(--text-2); margin-bottom: 14px; }
.settings-card.danger { border-color: #F3C4C4; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form .form-control { flex: 1; min-width: 200px; }
.tfa-state { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 14px; border-radius: var(--radius); font-size: 13px; }
.tfa-state.on { background: var(--ok-soft); color: #0F5A2B; }
.tfa-state.off { background: var(--warn-soft); color: #7A3B05; }
.banner-2fa { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }

/* Modali */
.modal-overlay { display: none; position: fixed; inset: 0; z-index: 1000; align-items: flex-start; justify-content: center; padding: 6vh 16px 24px; overflow-y: auto; background: rgba(17, 24, 39, 0.45); }
.modal-overlay.open { display: flex; }
.modal { width: 100%; max-width: 560px; padding: 20px 22px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
.modal.wide { max-width: 720px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding-bottom: 12px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 16px; font-weight: 600; color: var(--ink); }
.close-btn { width: 30px; height: 30px; border: 0; border-radius: var(--radius-sm); background: transparent; font-size: 20px; color: var(--text-2); cursor: pointer; }
.close-btn:hover { background: var(--surface-3); color: var(--ink); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; flex-wrap: wrap; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); }
.check-list label { display: flex; align-items: center; gap: 8px; font-weight: 400; cursor: pointer; }
.subhead { margin: 18px 0 10px; font-size: 13px; font-weight: 600; color: var(--ink); }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--text-2); }
.kv dd { color: var(--ink); word-break: break-word; }

.gen-key-box { padding: 16px; border: 1px dashed var(--border-strong); border-radius: var(--radius); text-align: center; background: var(--surface-2); }
.gen-key-value { margin: 6px 0 12px; font-family: var(--font-mono); font-size: 18px; font-weight: 600; color: var(--ink); letter-spacing: 0.04em; word-break: break-all; }
.secret-box { font-family: var(--font-mono); font-size: 13px; padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-3); word-break: break-all; }
.qr-box { display: grid; place-items: center; padding: 12px; margin: 12px 0; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); }
.qr-box svg { width: 200px; height: 200px; }
.codes-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 12px 0; font-family: var(--font-mono); font-size: 14px; }
.codes-grid span { padding: 6px; text-align: center; border-radius: var(--radius-sm); background: var(--surface-3); color: var(--ink); }

/* Accesso */
.a-login { position: relative; min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--grad-dark); overflow: hidden; }
.a-login-grid { position: absolute; inset: 0; pointer-events: none; background-image: radial-gradient(rgba(255,255,255,.09) 1px, transparent 1px); background-size: 26px 26px; -webkit-mask-image: radial-gradient(circle at 50% 40%, #000, transparent 75%); mask-image: radial-gradient(circle at 50% 40%, #000, transparent 75%); }
.a-login-box { position: relative; width: 100%; max-width: 400px; }
.a-login-box > .mark { display: flex; justify-content: center; margin-bottom: 28px; }
.a-login-card { padding: 32px 28px 28px; background: var(--surface); border-radius: var(--radius-xl); box-shadow: 0 30px 80px rgba(0,0,0,.45); }
.a-login-ico { width: 52px; height: 52px; display: grid; place-items: center; margin-bottom: 18px; border-radius: 15px; font-size: 21px; color: #fff; background: var(--grad-brand); box-shadow: 0 10px 24px rgba(12,84,67,.3); }
.a-login-card h1 { font-size: 22px; letter-spacing: -0.02em; font-weight: 700; }
.a-login-card .lead { margin: 6px 0 22px; font-size: 14px; color: var(--text-2); }
.a-login-card .form-control { height: 42px; }
.a-login-card .btn-primary { height: 44px; border-radius: 10px; font-size: 14.5px; }
.otp-input { font-family: var(--font-mono); font-size: 22px; letter-spacing: 0.35em; text-align: center; height: 48px; }

@media (max-width: 1100px) { .stats-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } .settings-grid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 860px) {
    .a-sidebar { position: static; width: 100%; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 10px; border-right: 0; border-bottom: 1px solid var(--border); }
    .admin-shell.ready { flex-direction: column; }
    .a-nav-label, .a-sidebar-foot span { display: none; }
    .a-nav { width: auto; }
    .a-sidebar-foot { margin: 0 0 0 auto; padding: 0; border: 0; }
    .a-sidebar-foot .btn { margin: 0; }
    .a-main { margin-left: 0; padding: 20px 16px 40px; }
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-row, .check-list { grid-template-columns: 1fr; }
    .table-actions .search-input { width: 100%; }
}

/* ==========================================================================
   Tema del marchio: barra laterale scura e indicatori
   ========================================================================== */
.admin-shell.ready { background: var(--bg); }
.a-sidebar { padding: 18px 12px; background: linear-gradient(180deg, var(--brand-900) 0%, var(--brand-950) 100%); border-right: 0; }
.a-sidebar .mark { padding: 0 8px 18px; margin-bottom: 4px; border-bottom: 1px solid rgba(255,255,255,.07); }
.a-nav-label { color: rgba(255,255,255,.38); }
.a-nav { height: 38px; color: rgba(255,255,255,.74); border-radius: 9px; }
.a-nav i { color: rgba(255,255,255,.45); }
.a-nav:hover { background: rgba(255,255,255,.06); color: #fff; }
.a-nav.active { background: rgba(23,160,122,.22); color: #fff; box-shadow: inset 3px 0 0 var(--brand-300); }
.a-nav.active i { color: var(--brand-300); }
.a-count { background: var(--sun); color: #2A1A00; }
.a-sidebar-foot { border-top-color: rgba(255,255,255,.08); color: rgba(255,255,255,.5); }
.a-sidebar-foot .btn-secondary { color: #fff; background: rgba(255,255,255,.06); border-color: rgba(255,255,255,.18); }
.a-sidebar-foot .btn-secondary:hover { background: rgba(255,255,255,.12); }

.a-head h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.a-head p { font-size: 14px; }
.stats-grid { gap: 14px; }
.stat-card { position: relative; padding: 18px 18px 16px; overflow: hidden; box-shadow: var(--shadow-sm); }
.stat-card::before { content: ""; position: absolute; inset: 0 0 auto 0; height: 3px; background: var(--grad-brand); }
.stat-card.c-success::before { background: linear-gradient(90deg, #22C55E, #15803D); }
.stat-card.c-warning::before { background: linear-gradient(90deg, #FFB020, #D97706); }
.stat-card.c-danger::before { background: linear-gradient(90deg, #F05252, #C81E1E); }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -0.03em; }
.table-card { box-shadow: var(--shadow-sm); }
.table-card-header h2 { font-size: 15px; }
.a-table th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; }

@media (max-width: 860px) {
    .a-sidebar .mark { border-bottom: 0; padding-bottom: 0; margin-bottom: 0; }
    .a-sidebar-foot { margin-left: auto; }
}

/* Moduli dell'account */
.modules-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin: 4px 0 8px; }
.modules-mode { font-size: 13px; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; }
.modules-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; padding: 12px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 14px; }
.modules-group { display: flex; flex-direction: column; gap: 6px; }
.modules-group-title { font-size: 11.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--text-2); margin-bottom: 2px; }
.modules-group label { display: flex; align-items: flex-start; gap: 8px; font-weight: 400; cursor: pointer; font-size: 13.5px; }
.modules-group input { margin-top: 3px; }
.modules-group small { font-size: 11.5px; }

/* Campo utente per i gestori di password (invisibile) e chiavi mascherate senza type=password */
.autofill-user { position: absolute !important; left: -10000px !important; width: 1px !important; height: 1px !important; opacity: 0 !important; pointer-events: none !important; }
.secret-input { -webkit-text-security: disc; font-family: var(--font-mono, monospace); }
.secret-input:focus { -webkit-text-security: none; }
/* Rileva la compilazione automatica del browser (vedi clearAutofilledSearch) */
.search-input:-webkit-autofill { animation: haiccp-autofill 1ms; }
@keyframes haiccp-autofill { from { opacity: 1; } to { opacity: 1; } }

/* ---------- Incassi, salute clienti, comunicazioni ---------- */
.a-count.warn { background: var(--warn); color: #fff; }
.form-row.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.pay-badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
.pay-badge.ok { background: var(--ok-soft); color: var(--ok); }
.pay-badge.warn { background: var(--warn-soft); color: var(--warn); }
.pay-badge.danger { background: var(--bad-soft); color: var(--bad); }
.health-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; vertical-align: middle; background: var(--text-2); flex: none; }
.health-dot.green { background: var(--ok); }
.health-dot.yellow { background: var(--warn); }
.health-dot.red { background: var(--bad); }
.health-dot.grey { background: #B8BEC6; }
.text-danger { color: var(--bad) !important; }
.lm-quick { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.lm-health { font-size: 13px; line-height: 1.5; padding: 8px 10px; border-radius: var(--radius); background: var(--surface-2, #F6F7F9); }
.lm-health:empty { display: none; }
.pay-form { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px 10px; align-items: end; padding: 12px; border: 1px dashed var(--border); border-radius: var(--radius); margin-top: 10px; }
.pay-form .form-group { margin: 0; }
.pay-form .pay-note { grid-column: span 2; }
.pay-form .pay-extend { grid-column: span 2; }
.pay-form .pay-actions { grid-column: 1 / -1; }
.inline-check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; font-weight: 400; cursor: pointer; margin: 6px 0; }
.mini-list, .notes-list { display: flex; flex-direction: column; gap: 6px; }
.mini-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); font-size: 13.5px; }
.mini-row span { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.mini-row small { color: var(--text-2); font-size: 12px; }
.note-form { display: flex; gap: 8px; margin-bottom: 8px; }
.note-form .form-control { flex: 1; }
.ai-rates { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 12.5px; color: var(--text-2); }
.ai-rates label { display: flex; align-items: center; gap: 6px; }
.ai-rates .form-control { width: 80px; height: 32px; }
.news-item { display: flex; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); margin-bottom: 8px; }
.news-item.warn { border-left-color: var(--warn); }
.news-item.success { border-left-color: var(--ok); }
.news-item.ended { opacity: .55; }
.news-item p { margin: 4px 0; font-size: 13.5px; }
.news-item small { color: var(--text-2); font-size: 12px; }
.chart-card { margin-top: 16px; }
.revenue-chart { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 8px; align-items: end; height: 220px; padding: 16px 16px 8px; }
.rc-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; min-width: 0; }
.rc-bar { width: 100%; max-width: 40px; min-height: 2px; background: var(--accent); border-radius: 4px 4px 0 0; }
.rc-val { font-size: 11px; color: var(--text-2); white-space: nowrap; }
.rc-lbl { font-size: 11.5px; color: var(--text-2); text-transform: capitalize; }
@media (max-width: 760px) {
    .form-row.three, .pay-form { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
    .revenue-chart .rc-val { display: none; }
}
#health-counter-badge { background: var(--bad); }
