/* ==========================================================
   NEITCUS Mobile PWA - Stili custom (estende Bootstrap 5.3)
   ========================================================== */

:root {
    --neitcus-primary: #0d6efd;
    --neitcus-secondary: #6610f2;
    --neitcus-dark: #1a1a2e;
    --neitcus-gradient: linear-gradient(135deg, #0d6efd 0%, #6610f2 100%);
    --topbar-height: 56px;
    --safe-area-top: env(safe-area-inset-top, 0);
    --safe-area-bottom: env(safe-area-inset-bottom, 0);
}

* {
    -webkit-tap-highlight-color: transparent;
}

html, body {
    height: 100%;
    overscroll-behavior-y: contain;
}

body {
    background: #f5f6fa;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    padding-top: var(--safe-area-top);
    padding-bottom: var(--safe-area-bottom);
}

/* =================================================================
   TOP BAR
   ================================================================= */
#topbar {
    background: var(--neitcus-gradient);
    height: calc(var(--topbar-height) + var(--safe-area-top));
    padding-top: var(--safe-area-top);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
#topbar .navbar-brand {
    font-weight: 600;
    font-size: 1.05rem;
    letter-spacing: 0.3px;
}
#topbar .btn-link:focus {
    box-shadow: none;
}

/* =================================================================
   MAIN CONTAINER
   ================================================================= */
.app-main {
    min-height: 100vh;
    padding-top: 0;
}
body.has-topbar .app-main {
    padding-top: calc(var(--topbar-height) + var(--safe-area-top));
}

.screen {
    min-height: calc(100vh - var(--topbar-height) - var(--safe-area-top) - var(--safe-area-bottom));
}
.screen-body {
    padding: 1rem;
    max-width: 720px;
    margin: 0 auto;
}

/* =================================================================
   SCHERMATA LOGIN
   ================================================================= */
#screen-login {
    background: var(--neitcus-dark);
    background-image:
        radial-gradient(ellipse at top left, rgba(13,110,253,0.18) 0%, transparent 55%),
        radial-gradient(ellipse at bottom right, rgba(102,16,242,0.18) 0%, transparent 55%);
    min-height: 100vh;
    padding: 1rem;
}
.login-card {
    width: 100%;
    max-width: 420px;
    background: rgba(255,255,255,0.98);
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.5);
    overflow: hidden;
}
.login-header {
    background: var(--neitcus-dark);
    padding: 2rem 1.5rem 1.75rem;
    color: white;
}
.brand-logo-img {
    display: block;
    max-width: 240px;
    width: 70%;
    height: auto;
    margin: 0 auto 0.5rem;
}
.brand-subtitle {
    font-size: 0.85rem;
    opacity: 0.85;
    margin-top: 0.25rem;
    letter-spacing: 0.3px;
}
.login-body {
    padding: 2rem 1.5rem 1rem;
}
.login-footer {
    padding: 0 1.5rem 1.5rem;
}

/* =================================================================
   LISTA TENANT / CONTESTI
   ================================================================= */
.list-group-item {
    border-left: none;
    border-right: none;
    padding: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: background-color 0.15s;
}
.list-group-item:hover,
.list-group-item:active {
    background-color: #f0f4ff;
}
.list-item-icon {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--neitcus-gradient);
    color: white;
    font-size: 1.1rem;
}
.list-item-body {
    flex: 1;
    min-width: 0;
}
.list-item-title {
    font-weight: 600;
    font-size: 0.95rem;
    color: #212529;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.list-item-subtitle {
    font-size: 0.8rem;
    color: #6c757d;
}
.list-item-chevron {
    color: #adb5bd;
    flex-shrink: 0;
}

/* Colori per tipo dashboard nel list item icon */
.icon-economic  { background: linear-gradient(135deg, #0891b2, #0e7490); }
.icon-financial { background: linear-gradient(135deg, #059669, #065f46); }
.icon-banking   { background: linear-gradient(135deg, #d97706, #92400e); }
.icon-partners  { background: linear-gradient(135deg, #db2777, #9f1239); }
.icon-playground{ background: linear-gradient(135deg, #7c3aed, #5b21b6); }
.icon-periodico { background: linear-gradient(135deg, #0d6efd, #0a58ca); }
.icon-predictive{ background: linear-gradient(135deg, #f59e0b, #b45309); }

/* =================================================================
   CHAT
   ================================================================= */
.chat-context-card {
    background: white;
    border-radius: 12px;
    padding: 0.75rem 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.chat-messages {
    min-height: 50vh;
    padding: 1rem 0;
}
.chat-welcome {
    padding: 2rem 1rem;
}
.chat-bubble {
    margin-bottom: 1rem;
    padding: 0.85rem 1rem;
    border-radius: 14px;
    max-width: 92%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    line-height: 1.45;
    word-wrap: break-word;
}
.chat-bubble-user {
    background: var(--neitcus-primary);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}
.chat-bubble-ai {
    background: white;
    color: #212529;
    border-bottom-left-radius: 4px;
    white-space: pre-wrap;
}
.chat-bubble-ai strong { color: var(--neitcus-primary); }
.chat-bubble-loading {
    background: white;
    color: #6c757d;
    border-bottom-left-radius: 4px;
    font-style: italic;
}
.chat-bubble-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.chat-form {
    position: sticky;
    bottom: 0;
    background: #f5f6fa;
    padding: 0.75rem 0;
    display: flex;
    gap: 0.5rem;
    align-items: flex-end;
}
.chat-form textarea {
    resize: none;
    border-radius: 20px;
    padding: 0.6rem 1rem;
    max-height: 120px;
}
.chat-form button {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* =================================================================
   UTILITY
   ================================================================= */
.screen.d-none { display: none !important; }

/* =================================================================
   DARK MODE — attivato via [data-bs-theme="dark"] su <html>
   Default ON (vedi script inline in index.html)
   Palette allineata al sito principale (assets/css/dark-mode.css)
   ================================================================= */
[data-bs-theme="dark"] {
    color-scheme: dark;
}

html[data-bs-theme="dark"],
html[data-bs-theme="dark"] body {
    background-color: #0f172a;
    color: #f1f5f9;
}

/* Forza dark sui contenitori delle schermate (evita "fondi bianchi" residui) */
[data-bs-theme="dark"] .app-main,
[data-bs-theme="dark"] .screen,
[data-bs-theme="dark"] .screen-body {
    background-color: #0f172a;
    color: #f1f5f9;
}

/* Top bar: gradient un po' più scuro in dark, contrasto migliore */
[data-bs-theme="dark"] #topbar {
    background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
    box-shadow: 0 2px 8px rgba(0,0,0,0.4);
}

/* Login screen */
[data-bs-theme="dark"] #screen-login {
    background: #0f172a;
    background-image:
        radial-gradient(ellipse at top left, rgba(59,130,246,0.15) 0%, transparent 55%),
        radial-gradient(ellipse at bottom right, rgba(167,139,250,0.15) 0%, transparent 55%);
}
[data-bs-theme="dark"] .login-card {
    background: #1e293b;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.7);
    border: 1px solid #334155;
}
[data-bs-theme="dark"] .login-header {
    background: linear-gradient(135deg, #0f172a 0%, #1a1a2e 100%);
    border-bottom: 1px solid #334155;
}
[data-bs-theme="dark"] .login-body .form-label {
    color: #cbd5e1;
}
[data-bs-theme="dark"] .login-body .form-control {
    background-color: #263548;
    border-color: #475569;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .login-body .form-control:focus {
    background-color: #263548;
    border-color: #3b82f6;
    color: #f1f5f9;
    box-shadow: 0 0 0 0.2rem rgba(59,130,246,.25);
}
[data-bs-theme="dark"] .login-body .form-control::placeholder {
    color: #64748b;
}
[data-bs-theme="dark"] .login-footer .text-muted {
    color: #64748b !important;
}

/* Override del WebKit autofill (Safari/Chrome iOS): senza questo gli input
   appaiono grigi/giallastri perché il browser sovrascrive bg/colore. */
[data-bs-theme="dark"] .form-control:-webkit-autofill,
[data-bs-theme="dark"] .form-control:-webkit-autofill:hover,
[data-bs-theme="dark"] .form-control:-webkit-autofill:focus,
[data-bs-theme="dark"] .form-control:-webkit-autofill:active,
[data-bs-theme="dark"] textarea:-webkit-autofill,
[data-bs-theme="dark"] textarea:-webkit-autofill:focus {
    -webkit-box-shadow: 0 0 0 1000px #263548 inset !important;
    -webkit-text-fill-color: #f1f5f9 !important;
    caret-color: #f1f5f9 !important;
    border-color: #475569 !important;
    transition: background-color 9999s ease-out 0s;
}

/* List group (tenants e contesti) */
[data-bs-theme="dark"] .list-group {
    background-color: transparent;
}
[data-bs-theme="dark"] .list-group-item {
    background-color: #1e293b;
    border-color: #334155;
    color: #e2e8f0;
}
[data-bs-theme="dark"] .list-group-item:hover,
[data-bs-theme="dark"] .list-group-item:active,
[data-bs-theme="dark"] .list-group-item:focus,
[data-bs-theme="dark"] .list-group-item:focus-visible,
[data-bs-theme="dark"] .list-group-item-action:hover,
[data-bs-theme="dark"] .list-group-item-action:active,
[data-bs-theme="dark"] .list-group-item-action:focus,
[data-bs-theme="dark"] .list-group-item-action:focus-visible {
    background-color: #263548;
    color: #f1f5f9;
    outline: none;
    box-shadow: 0 0 0 2px rgba(59,130,246,0.25);
}
[data-bs-theme="dark"] .list-item-title {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .list-item-subtitle {
    color: #94a3b8;
}
[data-bs-theme="dark"] .list-item-chevron {
    color: #64748b;
}

/* Testo "muted" delle schermate liste */
[data-bs-theme="dark"] .screen-body .text-muted {
    color: #94a3b8 !important;
}

/* Chat */
[data-bs-theme="dark"] .chat-context-card {
    background: #1e293b;
    border: 1px solid #334155;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
[data-bs-theme="dark"] .chat-context-card .text-muted {
    color: #94a3b8 !important;
}
[data-bs-theme="dark"] .chat-context-card .fw-bold {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .chat-bubble-ai {
    background: #1e293b;
    color: #e2e8f0;
    border: 1px solid #334155;
}
[data-bs-theme="dark"] .chat-bubble-ai strong {
    color: #60a5fa;
}
[data-bs-theme="dark"] .chat-bubble-loading {
    background: #1e293b;
    color: #94a3b8;
    border: 1px solid #334155;
}
[data-bs-theme="dark"] .chat-bubble-error {
    background: rgba(220,38,38,0.15);
    color: #fca5a5;
    border-color: rgba(220,38,38,0.4);
}
[data-bs-theme="dark"] .chat-form {
    background: #0f172a;
    border-top: 1px solid #1e293b;
}
[data-bs-theme="dark"] .chat-form textarea {
    background-color: #263548;
    border-color: #475569;
    color: #f1f5f9;
}
[data-bs-theme="dark"] .chat-form textarea:focus {
    background-color: #263548;
    border-color: #3b82f6;
    color: #f1f5f9;
    box-shadow: 0 0 0 0.2rem rgba(59,130,246,.25);
}
[data-bs-theme="dark"] .chat-form textarea::placeholder {
    color: #64748b;
}

/* Spinner / icone vuote */
[data-bs-theme="dark"] #contesti-empty i {
    color: #475569;
}

/* Alert in dark */
[data-bs-theme="dark"] .alert-danger {
    background-color: rgba(220,38,38,0.15);
    border-color: rgba(220,38,38,0.4);
    color: #fca5a5;
}

/* =================================================================
   KPI SUMMARY (schermata chat)
   Griglia compatta 2x3 di KPI estratte dal report selezionato.
   ================================================================= */
.kpi-summary {
    background: white;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    overflow: hidden;
}
.kpi-summary-toggle {
    list-style: none;
    cursor: pointer;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    font-weight: 600;
    color: #212529;
    user-select: none;
}
.kpi-summary-toggle::-webkit-details-marker { display: none; }
.kpi-summary-toggle .kpi-summary-chevron {
    color: #adb5bd;
    transition: transform 0.2s ease;
    font-size: 0.85rem;
}
.kpi-summary[open] .kpi-summary-toggle .kpi-summary-chevron {
    transform: rotate(180deg);
}
.kpi-summary-body {
    padding: 0 0.75rem 0.75rem;
}
.kpi-summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
}
.kpi-card {
    border-radius: 10px;
    padding: 0.65rem 0.75rem;
    background: #f8fafc;
    border-left: 3px solid #cbd5e1;
    min-height: 64px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}
.kpi-card-label {
    font-size: 0.72rem;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    line-height: 1.2;
    margin-bottom: 0.2rem;
}
.kpi-card-value {
    font-size: 1.05rem;
    font-weight: 700;
    color: #0f172a;
    line-height: 1.2;
    word-break: break-word;
}
/* Semafori: bordo sinistro colorato */
.kpi-card.sem-verde   { border-left-color: #16a34a; }
.kpi-card.sem-giallo  { border-left-color: #eab308; }
.kpi-card.sem-rosso   { border-left-color: #dc2626; }
.kpi-card.sem-blu     { border-left-color: #2563eb; }
.kpi-card.sem-grigio  { border-left-color: #94a3b8; }

/* Dark mode (palette deep-black OLED) */
[data-bs-theme="dark"] .kpi-summary {
    background: #14151d;
    border: 1px solid #252633;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
[data-bs-theme="dark"] .kpi-summary-toggle {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .kpi-summary-toggle .kpi-summary-chevron {
    color: #64748b;
}
[data-bs-theme="dark"] .kpi-card {
    background: #1c1d27;
    border-left-color: #2f3140;
}
[data-bs-theme="dark"] .kpi-card-label {
    color: #94a3b8;
}
[data-bs-theme="dark"] .kpi-card-value {
    color: #f1f5f9;
}
[data-bs-theme="dark"] .kpi-card.sem-verde   { border-left-color: #4ade80; }
[data-bs-theme="dark"] .kpi-card.sem-giallo  { border-left-color: #facc15; }
[data-bs-theme="dark"] .kpi-card.sem-rosso   { border-left-color: #f87171; }
[data-bs-theme="dark"] .kpi-card.sem-blu     { border-left-color: #60a5fa; }
[data-bs-theme="dark"] .kpi-card.sem-grigio  { border-left-color: #475569; }

/* Loading spinner inline */
[data-bs-theme="dark"] .kpi-summary-loading,
[data-bs-theme="dark"] .kpi-summary-empty {
    color: #94a3b8 !important;
}
