/* ICP Console — stile sobrio da prodotto professionale, non giocattolo.
   Zero emoji ovunque nell'interfaccia (vincolo non negoziabile #4). */

:root {
    --bg: #f4f5f7;
    --surface: #ffffff;
    --text: #14181f;
    --muted: #5b6472;
    --border: #dfe3e8;
    --brand: #0f172a;
    --accent: #2563eb;
    --danger: #b91c1c;
    --radius: 10px;

    /* Semaforo — mai solo colore, sempre accoppiato a un'etichetta
       testuale (vincolo accessibilità, vedi app.js STATUS_LABELS). */
    --status-green: #16a34a;
    --status-yellow: #ca8a04;
    --status-red: #dc2626;
    --status-offline: #6b7280;
    --status-off: #9ca3af;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 24px;
    background: var(--brand);
    color: #fff;
    flex-shrink: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.brand-logo {
    height: 28px;
    width: 28px;
    object-fit: contain;
    border-radius: 4px;
}

#app {
    flex: 1;
    display: flex;
}

/* #app è flex (per .centered, usata da #loginView): #homeView, senza
   flex/width propri, si restringeva al contenuto invece di occupare
   tutta la larghezza — bug reale trovato dal vivo (home schiacciata a
   sinistra, mezza pagina vuota a destra), .home-container/margin:auto
   non aveva nulla su cui centrarsi. */
#homeView {
    flex: 1;
    width: 100%;
    min-width: 0;
}

.centered {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px;
    width: 100%;
    max-width: 380px;
}

.card h1 {
    margin: 0 0 8px;
    font-size: 1.35rem;
}

.muted { color: var(--muted); font-size: 0.9rem; }

label {
    display: block;
    margin: 16px 0 6px;
    font-size: 0.85rem;
    font-weight: 600;
}

input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
}

input:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

.btn-primary {
    margin-top: 24px;
    width: 100%;
    padding: 11px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary:hover { background: #1d4ed8; }

.btn-ghost {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.4);
    color: #fff;
    padding: 6px 14px;
    border-radius: 6px;
    cursor: pointer;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-icon-ghost {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    background: transparent;
    border: 1px solid rgba(255,255,255,0.4);
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    flex-shrink: 0;
}

.btn-icon-ghost .icon, .btn-icon-ghost svg { width: 18px; height: 18px; }

/* Dentro il modal (sfondo chiaro), lo stesso pulsante icona ridiventa scuro */
.modal-card .btn-icon-ghost {
    border-color: var(--border);
    color: var(--text);
}

/* ── Pannello preferenze promemoria (Fase 4) ─────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    z-index: 100;
}

.modal-card {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 28px;
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 4px;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.2rem;
}

.toggle-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 20px 0 4px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
}

.toggle-row input { width: auto; }

.category-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 4px;
}

.category-checkboxes label {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-weight: 400;
    font-size: 0.9rem;
    cursor: pointer;
}

.category-checkboxes input { width: auto; }

select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--surface);
    color: var(--text);
}

.notice {
    margin-top: 14px;
    color: var(--status-green);
    font-size: 0.85rem;
}

/* Toast leggero — mai alert() nativo (vincolo di stile). Un solo
   elemento riusato per tutti i messaggi di esito, non una libreria. */
.app-toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translate(-50%, 12px);
    background: var(--brand);
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    font-size: 0.9rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s, transform 0.2s;
    z-index: 200;
    max-width: min(90vw, 420px);
    text-align: center;
}

.app-toast.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ── Onboarding (Fase 6) ──────────────────────────────────────────── */

.stale-notice {
    background: rgba(202, 138, 4, 0.1);
    border: 1px solid var(--status-yellow);
    color: #92610a;
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 0.85rem;
}

.onboarding-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    background: var(--surface);
    border: 1px solid var(--accent);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 24px;
}

.onboarding-text strong { font-size: 1rem; }
.onboarding-text p { margin: 4px 0 0; max-width: 560px; }

.onboarding-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.btn-primary-sm, .btn-ghost-sm {
    padding: 8px 14px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.btn-primary-sm {
    border: none;
    background: var(--accent);
    color: #fff;
}
.btn-primary-sm:hover { background: #1d4ed8; }

.btn-ghost-sm {
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
}
.btn-ghost-sm:hover { border-color: var(--accent); color: var(--accent); }

/* ── Utenti (Fase 6) ──────────────────────────────────────────────── */

.users-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 16px 0;
    max-height: 260px;
    overflow-y: auto;
}

.user-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.user-row-email { flex: 1; min-width: 0; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.role-badge {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 999px;
    background: var(--bg);
    color: var(--muted);
    white-space: nowrap;
}

.btn-danger-sm {
    padding: 5px 10px;
    border: 1px solid var(--danger);
    border-radius: 6px;
    background: transparent;
    color: var(--danger);
    font-size: 0.78rem;
    cursor: pointer;
}
.btn-danger-sm:hover { background: var(--danger); color: #fff; }

.notice-box {
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 14px;
    margin-top: 16px;
}
.conn-state {
    font-size: 0.72rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 999px;
    white-space: nowrap;
}
.conn-state-ok { background: rgba(22, 163, 74, 0.12); color: var(--status-green); }
.conn-state-offline { background: rgba(220, 38, 38, 0.12); color: var(--status-red); }
.conn-state-not_connected { background: var(--bg); color: var(--muted); }

.notice-box code {
    display: block;
    margin-top: 8px;
    padding: 8px 10px;
    background: var(--surface);
    border-radius: 6px;
    font-size: 0.95rem;
    word-break: break-all;
    user-select: all;
}

.error {
    margin-top: 14px;
    color: var(--danger);
    font-size: 0.85rem;
}

/* ── Home aggregata (Fase 2) ──────────────────────────────────────── */

.home-container {
    flex: 1;
    width: 100%;
    max-width: 880px;
    margin: 0 auto;
    padding: 32px 20px 48px;
}

.icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

/* Sei semafori a categoria fissa */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

/* Cross-sell (Fase 6) — discreto per costruzione: testo piccolo, colore
   attenuato, mai un riquadro vistoso o un pop-up. */
.cross-sell-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 40px;
}

.cross-sell-item {
    font-size: 0.8rem;
    color: var(--muted);
}

.cross-sell-item a {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}
.cross-sell-item a:hover { text-decoration: underline; }

.category-chip {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.category-chip .category-icon { color: var(--muted); }

.category-name {
    font-weight: 600;
    font-size: 0.92rem;
}

.category-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.78rem;
    color: var(--muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--status-off);
    flex-shrink: 0;
}

.status-green .status-dot { background: var(--status-green); }
.status-yellow .status-dot { background: var(--status-yellow); }
.status-red .status-dot { background: var(--status-red); }
.status-offline .status-dot { background: var(--status-offline); }
.status-off { opacity: 0.6; }
.status-off .category-icon { color: var(--status-off); }

.attention-section, .metrics-section { margin-bottom: 40px; }

.attention-section h2, .metrics-section h2 {
    font-size: 1rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin: 0 0 16px;
}

.deadlines-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.deadline-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px 16px;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.15s;
}

.deadline-item:hover { border-color: var(--accent); }

.severity-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.severity-critical .severity-dot { background: var(--status-red); }
.severity-warning .severity-dot { background: var(--status-yellow); }
.severity-info .severity-dot { background: var(--accent); }

.deadline-body {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.deadline-app {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--muted);
    font-weight: 600;
}

.deadline-title {
    font-size: 0.95rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.deadline-when {
    font-size: 0.82rem;
    color: var(--muted);
    white-space: nowrap;
    flex-shrink: 0;
}

.deadlines-more {
    text-align: center;
    font-size: 0.82rem;
    color: var(--muted);
    margin: 4px 0 0;
}

.deadline-link {
    flex: 1;
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text);
}

.deadline-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
    margin-left: 8px;
}

.btn-action-sm {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 12px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: transparent;
    color: var(--accent);
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}

.action-icon { width: 14px; height: 14px; flex-shrink: 0; }

.btn-action-sm:hover { background: var(--accent); color: #fff; }

.action-field {
    margin-bottom: 4px;
}

textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    min-height: 70px;
}

.empty-state {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    color: var(--muted);
}

.empty-check { color: var(--status-green); width: 24px; height: 24px; }

.metrics-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.metric-tile {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.metric-value { font-size: 1.6rem; font-weight: 700; }
.metric-label { font-size: 0.82rem; color: var(--text); }
.metric-app { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

.offline-notice {
    background: rgba(107, 114, 128, 0.08);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    font-size: 0.85rem;
    color: var(--muted);
}

/* Footer — stesso contenuto/struttura del blocco .app-footer usato in
   tutte le app del catalogo, qui adattato al tema chiaro della Console
   invece del tema scuro delle altre app (vedi
   icp-catalog-logo-consistency-audit-20260906). */
.app-footer {
    flex-shrink: 0;
    text-align: center;
    padding: 20px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.app-footer-links {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 4px 16px;
    margin-bottom: 8px;
}

.app-footer-links a {
    color: var(--muted);
    font-size: 12px;
    text-decoration: none;
}

.app-footer-links a:hover {
    color: var(--accent);
}

.app-footer-legal {
    font-size: 11px;
    color: var(--muted);
    line-height: 1.6;
    max-width: 560px;
    margin: 0 auto 8px;
}

.app-footer-socials {
    display: flex;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 8px;
}

.app-footer-social-icon {
    width: 30px;
    height: 30px;
    border-radius: 8px;
    background: var(--bg);
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    transition: background 0.15s, color 0.15s;
}

.app-footer-social-icon svg {
    width: 15px;
    height: 15px;
}

.app-footer-social-icon:hover {
    background: var(--accent);
    color: #fff;
}

.app-footer-social-icon.whatsapp:hover {
    background: #25d366;
}

[hidden] { display: none !important; }
