/*
 * iAdmin-gov — console di amministrazione.
 * Palette "istituzionale dark" sobria: stessa impostazione scura della dashboard
 * Flutter (iadmin-core-frontend) ma con accenti desaturati, meno "neon".
 */
:root {
    --bg: #0F1722;
    --surface: #16212E;
    --surface-raised: #1C2A3A;
    --surface-inset: #121B25;

    --border: #25303F;
    --border-strong: #36465A;

    --accent: #6E9BC0;          /* azzurro acciaio spento */
    --accent-strong: #5A88AE;
    --accent-fg: #0E1622;       /* testo su sfondo accent */
    --teal: #4E9A92;            /* verde-acqua spento */
    --online: #5BA37F;          /* verde spento */
    --warning: #C09A57;         /* ambra spenta */
    --danger: #C46B6B;          /* rosso mattone spento */

    --text-primary: #DBE1E9;
    --text-secondary: #93A0B1;
    --text-muted: #6A7686;

    --radius: 10px;
    --radius-sm: 8px;
    --sidebar-w: 256px;
    --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
    --sans: "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;

    /* tinte rgba derivate dagli accenti (per glow, badge, alert) */
    --accent-rgb: 110, 155, 192;
    --online-rgb: 91, 163, 127;
    --warning-rgb: 192, 154, 87;
    --danger-rgb: 196, 107, 107;
    --teal-rgb: 78, 154, 146;
}

* { box-sizing: border-box; }

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

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

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface-inset);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
}

.sidebar__brand {
    padding: 20px 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
}
.sidebar__logo {
    width: 38px; height: 38px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent-strong), var(--teal));
    display: flex; align-items: center; justify-content: center;
    color: #0E1622; font-weight: 800; font-size: 16px;
    flex-shrink: 0;
}
.sidebar__title { font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.sidebar__subtitle { font-size: 11px; color: var(--text-muted); }

.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav__section { color: var(--text-muted); font-size: 10.5px; font-weight: 700;
    letter-spacing: 1px; text-transform: uppercase; padding: 14px 12px 6px; }
.nav__item {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; border-radius: var(--radius-sm);
    color: var(--text-secondary); font-weight: 500;
    cursor: pointer; transition: background .15s, color .15s;
}
.nav__item:hover { background: var(--surface-raised); color: var(--text-primary); text-decoration: none; }
.nav__item.is-active { background: var(--surface-raised); color: var(--accent); }
.nav__item.is-active .nav__icon { color: var(--accent); }
.nav__icon { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar__footer { margin-top: auto; padding: 14px 16px; border-top: 1px solid var(--border);
    font-size: 11px; color: var(--text-muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

/* ---------- Topbar ---------- */
.topbar {
    height: 62px; flex-shrink: 0;
    border-bottom: 1px solid var(--border);
    background: rgba(22, 33, 46, .7);
    backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 26px; position: sticky; top: 0; z-index: 5;
}
.topbar__title { font-size: 17px; font-weight: 700; }
.topbar__right { display: flex; align-items: center; gap: 16px; }
.user-chip { display: flex; align-items: center; gap: 10px; }
.user-chip__avatar {
    width: 34px; height: 34px; border-radius: 50%;
    background: var(--surface-raised); border: 1px solid var(--border-strong);
    display: flex; align-items: center; justify-content: center;
    color: var(--accent); font-weight: 700; font-size: 13px;
}
.user-chip__meta { line-height: 1.2; }
.user-chip__email { font-size: 13px; font-weight: 600; }
.user-chip__role { font-size: 11px; color: var(--text-muted); }

.content { padding: 26px; max-width: 1280px; width: 100%; }
.page-head { margin-bottom: 22px; }
.page-head h1 { margin: 0 0 4px; font-size: 22px; }
.page-head p { margin: 0; color: var(--text-secondary); }

/* ---------- Cards ---------- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.card__head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card__title { font-size: 15px; font-weight: 700; margin: 0; }

.grid { display: grid; gap: 16px; }
.grid--stats { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid--health { grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); }

/* ---------- Health card ---------- */
.health-card { padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; }
.health-card__top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.health-card__name { font-weight: 700; font-size: 14.5px; }
.health-card__meta { display: flex; gap: 16px; font-size: 12px; color: var(--text-muted); }
.health-card__meta .text-mono { color: var(--text-secondary); }
.health-card__url { font-size: 11.5px; color: var(--text-muted); word-break: break-all; }
.health-card--up { border-left: 3px solid var(--online); }
.health-card--down { border-left: 3px solid var(--danger); }
.health-card--warn { border-left: 3px solid var(--warning); }

/* ---------- Stat cards ---------- */
.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    position: relative;
    overflow: hidden;
}
.stat::before {
    content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
    background: var(--accent);
}
.stat--teal::before { background: var(--teal); }
.stat--online::before { background: var(--online); }
.stat--warning::before { background: var(--warning); }
.stat__label { font-size: 12px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .5px; }
.stat__value { font-size: 30px; font-weight: 800; margin-top: 6px; font-family: var(--mono); }
.stat__hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table.tbl { width: 100%; border-collapse: collapse; background: var(--surface); }
.tbl th {
    text-align: left; font-size: 11.5px; letter-spacing: .6px; text-transform: uppercase;
    color: var(--text-secondary); font-weight: 700;
    padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-inset);
    white-space: nowrap;
}
.tbl td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.tbl tr:last-child td { border-bottom: none; }
.tbl tbody tr:hover { background: var(--surface-raised); }
.tbl .muted { color: var(--text-muted); }
.tbl__actions { display: flex; gap: 8px; }

.empty { padding: 44px 20px; text-align: center; color: var(--text-muted); }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
    border: 1px solid var(--border-strong);
}
.badge--on { color: var(--online); border-color: rgba(var(--online-rgb),.4); background: rgba(var(--online-rgb),.1); }
.badge--off { color: var(--text-muted); background: var(--surface-inset); }
.badge--accent { color: var(--accent); border-color: rgba(var(--accent-rgb),.4); background: rgba(var(--accent-rgb),.1); }
.badge--down { color: var(--danger); border-color: rgba(var(--danger-rgb),.4); background: rgba(var(--danger-rgb),.1); }
.badge--warn { color: var(--warning); border-color: rgba(var(--warning-rgb),.4); background: rgba(var(--warning-rgb),.1); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; gap: 8px; justify-content: center;
    padding: 9px 16px; border-radius: var(--radius-sm);
    font-size: 13.5px; font-weight: 600; cursor: pointer;
    border: 1px solid transparent; background: transparent; color: var(--text-primary);
    transition: filter .15s, background .15s, border-color .15s; text-decoration: none;
}
.btn:hover { text-decoration: none; }
.btn--primary { background: var(--accent); color: var(--accent-fg); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--ghost { border-color: var(--border-strong); color: var(--text-primary); background: var(--surface-inset); }
.btn--ghost:hover { background: var(--surface-raised); }
.btn--danger { background: rgba(var(--danger-rgb),.12); color: var(--danger); border-color: rgba(var(--danger-rgb),.4); }
.btn--danger:hover { background: rgba(var(--danger-rgb),.22); }
.btn--sm { padding: 6px 11px; font-size: 12.5px; }
.btn--block { width: 100%; }
.btn__icon { width: 16px; height: 16px; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px; }
.form-grid .col-span-2 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; color: var(--text-secondary); font-weight: 600; }
.field .req { color: var(--danger); }
.input, .textarea, .select {
    width: 100%; background: var(--surface-inset);
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    color: var(--text-primary); padding: 10px 12px; font-size: 14px; font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
}
.input:focus, .textarea:focus, .select:focus {
    outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.18);
}
/* Select: rimuove l'aspetto nativo (freccia di sistema) e usa un chevron coerente */
.select {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    padding-right: 38px; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2393A0B1' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; background-size: 16px;
}
.select option { background: var(--surface); color: var(--text-primary); }
.input.is-invalid, .textarea.is-invalid { border-color: var(--danger); }

/* File input: stile coerente col tema scuro */
input[type=file].input { padding: 7px 10px; line-height: 1.4; cursor: pointer; color: var(--text-secondary); }
input[type=file].input::file-selector-button {
    margin-right: 12px; padding: 7px 14px; border-radius: 6px;
    border: 1px solid var(--border-strong); background: var(--surface-raised);
    color: var(--text-primary); font: inherit; font-weight: 600; cursor: pointer;
    transition: background .15s, border-color .15s;
}
input[type=file].input::file-selector-button:hover { background: var(--border); border-color: var(--accent); }
.textarea { resize: vertical; min-height: 90px; }
.field__error { color: var(--danger); font-size: 12px; }
.field__hint { color: var(--text-muted); font-size: 12px; }

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input[type=checkbox] {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    width: 38px; height: 22px; border-radius: 999px; flex-shrink: 0; position: relative; cursor: pointer;
    background: var(--surface-raised); border: 1px solid var(--border-strong);
    transition: background .15s, border-color .15s;
}
.switch input[type=checkbox]::before {
    content: ""; position: absolute; top: 50%; left: 3px; transform: translateY(-50%);
    width: 16px; height: 16px; border-radius: 50%; background: var(--text-secondary);
    transition: left .15s, background .15s;
}
.switch input[type=checkbox]:checked { background: rgba(var(--accent-rgb), .35); border-color: var(--accent); }
.switch input[type=checkbox]:checked::before { left: 19px; background: var(--accent); }
.switch input[type=checkbox]:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(var(--accent-rgb),.18); }

.form-actions { display: flex; gap: 12px; margin-top: 22px; }

.input-icon-wrap { position: relative; }
.input-icon-wrap .input { padding-left: 38px; }
.input-icon-wrap svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
    width: 17px; height: 17px; color: var(--text-muted); }

/* ---------- Alerts ---------- */
.alert { padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13.5px;
    border: 1px solid transparent; margin-bottom: 16px; display: flex; gap: 10px; align-items: flex-start; }
.alert--success { background: rgba(var(--online-rgb),.1); color: var(--online); border-color: rgba(var(--online-rgb),.35); }
.alert--error { background: rgba(var(--danger-rgb),.1); color: var(--danger); border-color: rgba(var(--danger-rgb),.35); }
.alert--info { background: rgba(var(--accent-rgb),.1); color: var(--accent); border-color: rgba(var(--accent-rgb),.35); }
.alert svg { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }

/* ---------- Modal di conferma ---------- */
.modal { position: fixed; inset: 0; z-index: 50; padding: 24px;
    background: rgba(7, 12, 20, .66); backdrop-filter: blur(3px);
    display: none; align-items: center; justify-content: center; }
.modal.is-open { display: flex; }
.modal__dialog { width: 430px; max-width: 100%; background: var(--surface);
    border: 1px solid var(--border-strong); border-radius: 14px; padding: 26px; text-align: center;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .55); animation: modalIn .14s ease-out; }
@keyframes modalIn { from { opacity: 0; transform: translateY(8px) scale(.98); } to { opacity: 1; transform: none; } }
.modal__icon { width: 50px; height: 50px; border-radius: 50%; margin: 0 auto 14px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(var(--danger-rgb), .12); color: var(--danger); }
.modal__icon svg { width: 26px; height: 26px; }
.modal__title { margin: 0 0 8px; font-size: 18px; }
.modal__msg { margin: 0 0 22px; color: var(--text-secondary); }
.modal__actions { display: flex; gap: 12px; justify-content: center; }

/* ---------- Definition list (detail) ---------- */
.dl { display: grid; grid-template-columns: 180px 1fr; gap: 0; }
.dl dt { padding: 11px 0; color: var(--text-secondary); font-size: 13px; border-bottom: 1px solid var(--border); }
.dl dd { padding: 11px 0; margin: 0; border-bottom: 1px solid var(--border); }
.dl > dt:last-of-type, .dl > dd:last-of-type { border-bottom: none; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; gap: 8px; margin-top: 18px; justify-content: flex-end; }
.pagination__info { color: var(--text-muted); font-size: 13px; margin-right: auto; }

/* ---------- Logos ---------- */
.logo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 14px; }
.logo-card { background: var(--surface-inset); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 14px; text-align: center; }
.logo-card img { max-width: 100%; height: 64px; object-fit: contain; background: #fff;
    border-radius: 6px; padding: 4px; }
.logo-card__size { font-family: var(--mono); font-size: 12px; color: var(--text-secondary); margin-top: 8px; }
.logo-card--empty { display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--text-muted); min-height: 96px; border-style: dashed; }

/* ---------- Auth (login) ---------- */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 24px; background:
        radial-gradient(1200px 600px at 80% -10%, rgba(var(--accent-rgb),.06), transparent),
        radial-gradient(900px 500px at -10% 110%, rgba(var(--teal-rgb),.06), transparent),
        var(--bg); }
.auth-card { width: 420px; max-width: 100%; background: var(--surface);
    border: 1px solid var(--border); border-radius: 14px; padding: 32px; }
.auth-brand { display: flex; flex-direction: column; align-items: center; text-align: center; margin-bottom: 24px; }
.auth-brand .sidebar__logo { width: 52px; height: 52px; font-size: 20px; border-radius: 13px; margin-bottom: 12px; }
.auth-brand h1 { margin: 0; font-size: 20px; }
.auth-brand p { margin: 4px 0 0; color: var(--text-secondary); font-size: 13px; }
.tabs { display: flex; background: var(--surface-inset); border: 1px solid var(--border);
    border-radius: var(--radius-sm); padding: 4px; margin-bottom: 20px; gap: 4px; }
.tab { flex: 1; text-align: center; padding: 8px; border-radius: 6px; cursor: pointer;
    color: var(--text-secondary); font-weight: 600; font-size: 13px; }
.tab.is-active { background: var(--surface-raised); color: var(--accent); }
.hidden { display: none !important; }
.auth-divider { display: flex; align-items: center; gap: 12px; color: var(--text-muted);
    font-size: 12px; margin: 18px 0; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- Error page ---------- */
.error-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.error-card { text-align: center; max-width: 480px; }
.error-code { font-size: 84px; font-weight: 900; font-family: var(--mono);
    color: var(--accent); line-height: 1; opacity: .9; }
.error-card h1 { margin: 8px 0; font-size: 24px; }
.error-card p { color: var(--text-secondary); margin-bottom: 22px; }

.mb-0 { margin-bottom: 0; }
.mt-16 { margin-top: 16px; }
.text-mono { font-family: var(--mono); }
.text-muted { color: var(--text-muted); }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.gap-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

.toggle-list { list-style: none; margin: 0; padding: 0; }
.toggle-list__item { padding: 11px 0; border-bottom: 1px solid var(--border); }
.toggle-list__item:last-child { border-bottom: none; }

.code-block {
    background: var(--bg-subtle, #f6f8fa);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px 14px;
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.5;
    overflow-x: auto;
    white-space: pre;
    margin: 0 0 4px;
}

@media (max-width: 860px) {
    .sidebar { display: none; }
    .form-grid { grid-template-columns: 1fr; }
    .dl { grid-template-columns: 1fr; }
    .dl dt { border-bottom: none; padding-bottom: 0; }
}
