:root {
    --bg: #f5f7fa;
    --card: #ffffff;
    --text: #1d2433;
    --muted: #667085;
    --line: #e4e7ec;
    --primary: #1f6feb;
    --primary-d: #1858c0;
    --ok: #16a34a;
    --warn: #d97706;
    --err: #dc2626;
    --off: #98a2b3;
    --radius: 10px;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    color: var(--text);
    background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .25rem; display: flex; align-items: center; gap: .5rem; }
h3 { margin: 0 0 .75rem; font-size: 1.05rem; }
code { background: #eef1f5; padding: 1px 5px; border-radius: 4px; font-size: .9em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.center { text-align: center; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }

/* ---------- barra superiore ---------- */
.topbar {
    display: flex; align-items: center; gap: 1.5rem; padding: .7rem 1.5rem;
    background: #0f1b2d; color: #fff;
}
.topbar a { color: #dbe4f0; }
.topbar .brand { font-weight: 700; color: #fff; }
.topbar nav { display: flex; gap: 1rem; flex: 1; }
.topbar .user { display: flex; align-items: center; gap: .75rem; }
.topbar form { margin: 0; }
.topbar .btn.ghost { color: #dbe4f0; border-color: #3a4a63; }

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------- elementi ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; }
.btn {
    display: inline-flex; align-items: center; gap: .35rem; padding: .5rem .9rem; border-radius: 8px;
    border: 1px solid var(--line); background: #fff; color: var(--text); cursor: pointer; font: inherit; font-size: .9rem;
}
.btn:hover { background: #f0f3f7; text-decoration: none; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-d); }
.btn.danger { background: var(--err); border-color: var(--err); color: #fff; }
.btn.danger.ghost, .btn.ghost.danger { background: transparent; color: var(--err); border-color: #f3c4c4; }
.btn.ghost { background: transparent; }
.btn.small { padding: .25rem .6rem; font-size: .8rem; }
.btn.wide { width: 100%; justify-content: center; margin-top: .5rem; }
.btn:disabled, .btn.disabled { opacity: .5; pointer-events: none; }

input, select, textarea {
    font: inherit; padding: .5rem .65rem; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #bcd3fb; border-color: var(--primary); }
label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; margin-bottom: .75rem; }
label.check { flex-direction: row; align-items: center; gap: .4rem; margin: 0; }
label.check input { width: auto; }
.form-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.form-row input { flex: 1; min-width: 180px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: .25rem 1rem; align-items: end; }
.form-grid .full { grid-column: 1 / -1; }
fieldset.perms { border: 1px solid var(--line); border-radius: 8px; display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; padding: .75rem 1rem; margin: 0 0 .75rem; }
fieldset legend { font-size: .85rem; color: var(--muted); padding: 0 .3rem; }

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: .8rem; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--line); padding: .5rem; }
td { padding: .55rem .5rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.compact td { padding: .35rem .5rem; font-size: .88rem; }
tr.dim td { opacity: .55; }
tr.failed td { color: var(--err); }

.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.alert.err { background: #fef2f2; border-color: #fecaca; color: #991b1b; white-space: pre-line; }
.alert.ok { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: .75rem; background: #eef1f5; color: var(--muted); }
.badge.ok { background: #dcfce7; color: #166534; }
.badge.off { background: #eef1f5; color: #475467; }
.badge.warn { background: #fef3c7; color: #92400e; }

.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--off); flex: none; }
.dot.big { width: 14px; height: 14px; }
.dot.ok { background: var(--ok); box-shadow: 0 0 0 3px #dcfce7; }
.dot.warn { background: var(--warn); }

/* ---------- elenco VM ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.vm-card {
    display: flex; flex-direction: column; gap: .5rem; background: var(--card); border: 1px solid var(--line);
    border-radius: var(--radius); padding: 1rem; color: var(--text); transition: box-shadow .15s, border-color .15s;
}
.vm-card:hover { text-decoration: none; border-color: #bcd3fb; box-shadow: 0 4px 14px rgba(16, 24, 40, .06); }
.vm-card-head { display: flex; align-items: center; gap: .5rem; }
.vm-metrics { display: grid; gap: .2rem; font-size: .9rem; }
.vm-card .badge { align-self: flex-start; }

/* ---------- dettaglio VM ---------- */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; }
.tabs button { background: none; border: none; padding: .6rem 1rem; cursor: pointer; font: inherit; color: var(--muted); border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--primary); border-color: var(--primary); font-weight: 600; }
.sparks { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; }
.spark { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .75rem; }
.spark-head { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); margin-bottom: .3rem; }
.spark-head strong { color: var(--text); }
.spark svg { width: 100%; height: 60px; display: block; }
.spark .line { fill: none; stroke: var(--primary); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.spark .area { fill: #1f6feb18; stroke: none; }

.jobs { display: grid; gap: .5rem; margin-bottom: 1rem; }
.job { border: 1px solid var(--line); border-left: 4px solid var(--primary); background: #fff; border-radius: 8px; padding: .6rem .9rem; }
.job.succeeded { border-left-color: var(--ok); }
.job.failed { border-left-color: var(--err); }
.job-title { display: flex; align-items: center; gap: .5rem; }
.job-err { white-space: pre-wrap; font-size: .8rem; background: #fef2f2; color: #991b1b; padding: .5rem; border-radius: 6px; margin: .4rem 0 0; }
.spinner { width: 14px; height: 14px; border: 2px solid #bcd3fb; border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- finestre di conferma ---------- */
.modal-back { position: fixed; inset: 0; background: rgba(15, 27, 45, .45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal { background: #fff; border-radius: 12px; padding: 1.25rem 1.5rem; width: min(520px, 100%); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

/* ---------- pagine di accesso ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; background: linear-gradient(160deg, #0f1b2d, #1f3b63); }
.auth-card { background: #fff; border-radius: 14px; padding: 2rem; width: min(420px, 100%); box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.auth-title { font-weight: 700; color: var(--primary); margin-bottom: 1.25rem; }
.auth-card input { width: 100%; }
input.code { font-size: 1.4rem; letter-spacing: .3rem; text-align: center; }
.qr { width: 200px; height: 200px; margin: .5rem auto; }
.qr svg { width: 100%; height: 100%; }
code.secret { font-size: 1rem; letter-spacing: .05rem; user-select: all; }
ol.steps { padding-left: 1.2rem; font-size: .9rem; color: var(--muted); }

/* ---------- console ---------- */
.console-root { position: fixed; inset: 0; display: flex; flex-direction: column; background: #111; }
.console-bar { display: flex; align-items: center; gap: .5rem; padding: .4rem .75rem; background: #0f1b2d; color: #fff; flex-wrap: wrap; }
.console-bar input { padding: .25rem .5rem; font-size: .85rem; width: 220px; }
.console-bar .btn { background: #22324a; color: #fff; border-color: #3a4a63; }
.console-bar label.check { color: #dbe4f0; }
.console-screen { flex: 1; overflow: hidden; }
.status { font-size: .85rem; color: #dbe4f0; }
.status.ok { color: #4ade80; }
.status.err { color: #f87171; }

#blazor-error-ui { background: #fffbeb; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, .2); display: none; left: 0; padding: .6rem 1.25rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: .75rem; top: .5rem; }

@media (max-width: 700px) {
    .topbar { flex-wrap: wrap; gap: .5rem 1rem; }
    .container { padding: 1rem; }
    table { font-size: .85rem; }
}
