/* ===== Blazor: barra errore non gestito (nascosta finché non c'è un errore) ===== */
#blazor-error-ui {
    display: none; /* Blazor la rende visibile (display:block) solo in caso di errore */
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    z-index: 1000;
    padding: .7rem 2.5rem .7rem 1.1rem;
    background: #fdecee;
    color: #7a2530;
    border-top: 1px solid #e9b9c0;
    box-shadow: 0 -2px 8px rgba(0,0,0,.12);
    font-size: .9rem;
}
#blazor-error-ui .reload {
    color: #7a2530;
    font-weight: 600;
    text-decoration: underline;
    margin-left: .4rem;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: .9rem;
    top: .55rem;
    font-size: 1rem;
}

/* ===== TargaCore Cloud — UI ===== */
:root {
    --bg: #f7f8fa;
    --panel: #ffffff;
    --sidebar: #2b3242;
    --sidebar-2: #262c3a;
    --sidebar-text: #9aa2b1;
    --sidebar-hover: rgba(255,255,255,.05);
    --accent: #6b82ad;
    --accent-2: #7d92ba;
    --primary: #6379a6;
    --primary-h: #556a96;
    --danger: #b9707b;
    --danger-h: #a45f6a;
    --ok: #6a9b80;
    --warn: #c79a52;
    --muted: #828b99;
    --border: #ebedf1;
    --text: #3a414e;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(45,55,75,.05), 0 1px 3px rgba(45,55,75,.04);
    --shadow-lg: 0 10px 30px rgba(45,55,75,.10);
}

* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0; background: var(--bg); color: var(--text);
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
    font-size: 14px; line-height: 1.55; -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; font-weight: 700; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 1rem; font-weight: 650; margin: 0 0 .9rem; }
code { background: #eef2f7; padding: .08rem .35rem; border-radius: 5px; font-size: .85em; }

/* ===== App shell ===== */
.app { display: flex; min-height: 100vh; }
.sidebar {
    width: 250px; flex: 0 0 250px;
    background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
    color: var(--sidebar-text);
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
    border-right: 1px solid rgba(255,255,255,.05);
}
.brand { display: flex; align-items: center; gap: .6rem; padding: 1.25rem 1.25rem .5rem; }
.brand .logo {
    width: 36px; height: 36px; border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    display: grid; place-items: center; color: #fff; box-shadow: 0 4px 12px rgba(99,121,166,.4);
}
.brand .title { font-weight: 700; color: #fff; font-size: 1.02rem; line-height: 1.1; }
.brand .title span { display: block; font-size: .66rem; font-weight: 500; color: #6b7a93; letter-spacing: .08em; text-transform: uppercase; }

.nav-section { padding: .85rem 1.1rem .25rem; font-size: .66rem; letter-spacing: .09em; text-transform: uppercase; color: #5b6b85; }
.nav { display: flex; flex-direction: column; padding: .15rem .6rem; gap: 2px; }
.nav-item {
    display: flex; align-items: center; gap: .65rem;
    padding: .52rem .7rem; border-radius: 9px;
    color: var(--sidebar-text); font-weight: 500; font-size: .9rem;
    position: relative; transition: background .12s, color .12s;
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; opacity: .9; }
.nav-item:hover { background: var(--sidebar-hover); color: #e7ecf4; text-decoration: none; }
.nav-item.active { background: rgba(125,146,186,.2); color: #fff; }
.nav-item.active::before { content: ""; position: absolute; left: -.6rem; top: 20%; bottom: 20%; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent-2); }
.nav-item .pill { margin-left: auto; background: var(--danger); color: #fff; border-radius: 999px; font-size: .68rem; padding: .05rem .4rem; font-weight: 700; }

.sidebar-foot { margin-top: auto; padding: .9rem 1rem; border-top: 1px solid rgba(255,255,255,.06); display: flex; align-items: center; gap: .6rem; }
.sidebar-foot .avatar { width: 32px; height: 32px; border-radius: 50%; background: rgba(255,255,255,.1); display: grid; place-items: center; color: #cbd5e1; font-weight: 600; font-size: .8rem; }
.sidebar-foot .who { flex: 1; min-width: 0; }
.sidebar-foot .who b { display: block; color: #e7ecf4; font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .who span { font-size: .72rem; color: #5b6b85; }
.sidebar-foot form { margin: 0; }
.logout-btn {
    background: transparent; border: 0; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: 8px; flex: 0 0 auto;
    color: var(--sidebar-text); transition: background .12s, color .12s;
}
.logout-btn svg { width: 19px; height: 19px; }
.logout-btn:hover { color: #fff; background: rgba(255,255,255,.1); }

.content { flex: 1; padding: 2rem 2.25rem; max-width: 1280px; }

/* ===== Page header ===== */
.page-head { margin-bottom: 1.5rem; display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.page-head .sub { color: var(--muted); margin: .3rem 0 0; }

/* ===== Cards / grid ===== */
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1.1rem; margin-bottom: 1.25rem; }
.card {
    background: var(--panel); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 1.25rem 1.4rem; margin-bottom: 1.25rem;
}
.card.tight { padding: 1.1rem 1.2rem; margin-bottom: 0; }
.stat { font-size: 2.1rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.1; }
.stat-label { color: var(--muted); font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; }
.kv { color: var(--muted); margin: .25rem 0; }
.kv b { color: var(--text); font-weight: 600; }

/* ===== Badges ===== */
.badge { display: inline-flex; align-items: center; gap: .4rem; padding: .22rem .65rem; border-radius: 999px; font-size: .76rem; font-weight: 600; line-height: 1.2; }
.badge-ok { background: #e6f0ea; color: #437a5c; }
.badge-bad { background: #f4e3e6; color: #9c5560; }
.badge-warn { background: #f6efe0; color: #8a6a2e; }
.badge-muted { background: #eef0f3; color: #5b6473; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px rgba(106,155,128,.2); }
.dot-bad { background: var(--danger); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex; align-items: center; gap: .4rem;
    border: 1px solid var(--border); background: #fff; color: var(--text);
    padding: .48rem .9rem; border-radius: 9px; font-size: .87rem; font-weight: 600;
    cursor: pointer; transition: background .12s, border-color .12s, box-shadow .12s, opacity .12s;
}
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(99,121,166,.25); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-danger { background: #fff; border-color: #e6c6cc; color: var(--danger-h); }
.btn-danger:hover { background: #faf1f2; }
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.2); color: #d6dbe6; }
.btn-ghost:hover { background: rgba(255,255,255,.12); color: #fff; }
.btn-sm { padding: .32rem .65rem; font-size: .8rem; }
.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ===== Tables ===== */
.table-wrap { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .7rem .9rem; border-bottom: 1px solid var(--border); }
.table th { font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: #f8fafc; font-weight: 650; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #f8fafc; }
.table .num { font-variant-numeric: tabular-nums; }
.plate { font-family: ui-monospace, Consolas, monospace; font-weight: 700; letter-spacing: .04em; }

/* ===== Forms ===== */
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .85rem; }
.field > label, .field-label { font-size: .8rem; font-weight: 600; color: #334155; }
.input, select, textarea {
    border: 1px solid var(--border); border-radius: 9px; padding: .55rem .65rem;
    font: inherit; background: #fff; color: var(--text); width: 100%;
}
.input::placeholder, textarea::placeholder { color: #9aa5b6; }
.input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,121,166,.15); }
textarea { resize: vertical; min-height: 90px; }
.toolbar { display: flex; flex-wrap: wrap; gap: .85rem; align-items: flex-end; }
.toolbar .field { margin-bottom: 0; width: auto; }
.toolbar .input, .toolbar select { width: auto; min-width: 140px; }
.check { display: flex; flex-direction: row; align-items: center; gap: .5rem; }
.check input { width: auto; }

/* ===== Alerts ===== */
.alert { padding: .65rem .9rem; border-radius: 9px; margin-top: .85rem; font-weight: 500; }
.alert-ok { background: #e6f0ea; color: #437a5c; }
.alert-bad { background: #f4e3e6; color: #9c5560; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Consolas, monospace; }
.fp { display: block; background: #f8fafc; border: 1px solid var(--border); border-radius: 9px; padding: .65rem; word-break: break-all; font-family: ui-monospace, Consolas, monospace; font-size: .82rem; }

/* ===== Miniature / lightbox ===== */
.thumb { width: 58px; height: 42px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); cursor: pointer; background: #f1f3f6; transition: transform .1s; }
.thumb:hover { transform: scale(1.05); border-color: var(--accent); }
.thumb-empty { width: 58px; height: 42px; border-radius: 6px; border: 1px dashed var(--border); display: inline-flex; align-items: center; justify-content: center; color: #c0c6d0; font-size: .7rem; }
.lightbox { position: fixed; inset: 0; background: rgba(15,20,30,.82); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; z-index: 100; padding: 2rem; }
.lb-stage { position: relative; display: grid; place-items: center; min-width: 120px; min-height: 120px; }
.lightbox img { position: relative; max-width: 92vw; max-height: 80vh; border-radius: 10px; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.lightbox .lb-bar { display: flex; gap: .75rem; align-items: center; color: #e7ecf4; }
.spinner { position: absolute; width: 46px; height: 46px; border: 4px solid rgba(255,255,255,.25); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Login ===== */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(1100px 560px at 25% -10%, #3a4666 0%, transparent 55%), linear-gradient(135deg, #2b3242, #343c52); padding: 1rem; }
.login-card { width: 100%; max-width: 380px; background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg); padding: 2.25rem; }
.login-card .logo { width: 46px; height: 46px; border-radius: 11px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; color: #fff; margin-bottom: 1rem; box-shadow: 0 6px 16px rgba(99,121,166,.4); }
.login-card h1 { font-size: 1.3rem; }
.login-card .sub { color: var(--muted); margin: .25rem 0 1.25rem; }

/* ===== Live feed ===== */
.feed { display: flex; flex-direction: column; gap: .5rem; }
.feed-row { display: flex; align-items: center; gap: .75rem; padding: .55rem .7rem; border: 1px solid var(--border); border-radius: 9px; background: #fff; }
.feed-row.bl { border-color: #e6c6cc; background: #fdf6f7; }
.feed-row .time { color: var(--muted); font-size: .78rem; font-variant-numeric: tabular-nums; }

/* validation (Identity/Blazor) */
.validation-message, .text-danger { color: var(--danger-h); font-size: .82rem; }

/* ===== Mobile shell (topbar + drawer via checkbox-hack) ===== */
.topbar { display: none; }
.nav-toggle { display: none; }
.nav-backdrop { display: none; }

@media (max-width: 860px) {
    .app { flex-direction: column; }

    .topbar {
        display: flex; align-items: center; gap: .75rem;
        position: sticky; top: 0; z-index: 50;
        background: linear-gradient(180deg, var(--sidebar), var(--sidebar-2));
        color: #fff; padding: .65rem 1rem;
        box-shadow: 0 2px 8px rgba(0,0,0,.12);
    }
    .hamburger { display: inline-flex; cursor: pointer; color: #fff; padding: .15rem; }
    .hamburger svg { width: 26px; height: 26px; }
    .topbar-title { font-weight: 600; font-size: 1rem; }
    .topbar-title b { font-weight: 700; }

    /* sidebar diventa drawer a scomparsa */
    .sidebar {
        position: fixed; top: 0; left: 0; bottom: 0; height: 100vh;
        z-index: 60; transform: translateX(-100%);
        transition: transform .22s ease; will-change: transform;
    }
    .nav-toggle:checked ~ .sidebar { transform: translateX(0); box-shadow: 0 0 50px rgba(0,0,0,.45); }
    .nav-toggle:checked ~ .nav-backdrop {
        display: block; position: fixed; inset: 0; z-index: 55; background: rgba(15,20,30,.5);
    }

    .content { padding: 1rem; max-width: 100%; }
    .page-head { margin-bottom: 1rem; }
    h1 { font-size: 1.25rem; }

    /* toolbar e campi a tutta larghezza */
    .toolbar { gap: .6rem; }
    .toolbar .field, .toolbar .input, .toolbar select { width: 100%; min-width: 0; }
    .field { width: 100%; }

    /* ===== Tabelle -> schede impilate ===== */
    .table-wrap { border: none; box-shadow: none; background: transparent; overflow: visible; }
    .table, .table tbody { display: block; width: 100%; }
    .table thead { display: none; }
    .table tr {
        display: block; background: var(--panel);
        border: 1px solid var(--border); border-radius: 11px;
        box-shadow: var(--shadow); margin-bottom: .7rem; padding: .35rem .25rem;
    }
    .table tr:hover { background: var(--panel); }
    .table td {
        display: flex; align-items: center; justify-content: space-between; gap: 1rem;
        border: none; padding: .45rem .75rem; text-align: right;
    }
    .table td::before {
        content: attr(data-label); font-weight: 600; color: var(--muted);
        font-size: .76rem; text-transform: uppercase; letter-spacing: .03em;
        text-align: left; flex: 0 0 auto;
    }
    .table td:not([data-label]) { justify-content: flex-end; }
    .table td .btn-row { justify-content: flex-end; }
    .thumb, .thumb-empty { width: 84px; height: 60px; }

    /* dashboard: colonne impilate */
    .dash-2col { grid-template-columns: 1fr !important; }
}
