/* RemoteDesk — console di amministrazione. Font Montserrat (OFL, vedi fonts/OFL-Montserrat.txt), marchio #2563EB.
   Nessuno stile inline: la Content-Security-Policy consente solo questo file. */

@font-face { font-family: "Montserrat"; src: url("fonts/Montserrat-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Montserrat"; src: url("fonts/Montserrat-Medium.ttf") format("truetype"); font-weight: 500; font-display: swap; }
@font-face { font-family: "Montserrat"; src: url("fonts/Montserrat-SemiBold.ttf") format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Montserrat"; src: url("fonts/Montserrat-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
    --brand: #2563eb;
    --brand-strong: #1d4ed8;
    --brand-soft: #e8efff;
    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --text: #0f172a;
    --text-2: #475569;
    --muted: #64748b;
    --ok: #15803d;
    --ok-soft: #dcfce7;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --bad: #b91c1c;
    --bad-soft: #fee2e2;
    --sidebar: #0f172a;
    --sidebar-text: #cbd5e1;
    --sidebar-active: #1e293b;
    --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 1px 3px rgba(15, 23, 42, .08);
    --radius: 10px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --brand: #3b82f6;
        --brand-strong: #60a5fa;
        --brand-soft: #172554;
        --bg: #0b1120;
        --surface: #111827;
        --surface-2: #0f172a;
        --border: #1f2937;
        --text: #e5e7eb;
        --text-2: #cbd5e1;
        --muted: #94a3b8;
        --ok: #4ade80;
        --ok-soft: #052e16;
        --warn: #fbbf24;
        --warn-soft: #3b2a05;
        --bad: #f87171;
        --bad-soft: #3b0d0d;
        --sidebar: #020617;
        --sidebar-active: #111827;
        --shadow: none;
        color-scheme: dark;
    }
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
    margin: 0;
    font-family: "Montserrat", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6rem; }
h1 { font-size: 1.5rem; font-weight: 700; }
h2 { font-size: 1.1rem; font-weight: 600; }
h3 { font-size: .95rem; font-weight: 600; }
p { margin: 0 0 .8rem; }
code, .mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
code { font-size: .9em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1.2rem 0; }

/* ------------------------------------------------------------------ Struttura */
.shell { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar {
    background: var(--sidebar);
    color: var(--sidebar-text);
    padding: 1.2rem .8rem;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}
.brand { display: flex; align-items: center; gap: .6rem; color: #fff; font-weight: 700; font-size: 1.1rem; padding: 0 .6rem 1rem; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; color: #fff; font-size: .9rem; }
.brand small { display: block; font-weight: 500; font-size: .7rem; color: var(--sidebar-text); letter-spacing: .04em; text-transform: uppercase; }
.nav-group { margin-top: 1rem; }
.nav-title { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: #64748b; padding: 0 .6rem .3rem; font-weight: 600; }
.nav a {
    display: flex; align-items: center; justify-content: space-between;
    color: var(--sidebar-text); padding: .45rem .6rem; border-radius: 8px; font-weight: 500; font-size: .92rem;
}
.nav a:hover { background: var(--sidebar-active); color: #fff; text-decoration: none; }
.nav a.active { background: var(--brand); color: #fff; }
.nav .count { background: rgba(255, 255, 255, .14); border-radius: 999px; padding: 0 .5rem; font-size: .75rem; }
.sidebar-footer { margin-top: auto; padding-top: 1rem; border-top: 1px solid #1e293b; font-size: .85rem; }
.sidebar-footer .who { padding: .3rem .6rem; color: #fff; font-weight: 600; }
.sidebar-footer .role { padding: 0 .6rem .5rem; color: #94a3b8; font-size: .78rem; }
.sidebar-footer form { margin: 0; }
.sidebar-footer button { width: 100%; text-align: left; background: none; border: 0; color: var(--sidebar-text); padding: .45rem .6rem; border-radius: 8px; font: inherit; cursor: pointer; }
.sidebar-footer button:hover { background: var(--sidebar-active); color: #fff; }

.main { padding: 1.6rem 2rem 3rem; min-width: 0; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.page-head p { color: var(--muted); margin: 0; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.breadcrumb { font-size: .82rem; color: var(--muted); margin-bottom: .3rem; }

.nav-toggle, .nav-toggle-label { display: none; }

@media (max-width: 900px) {
    .shell { grid-template-columns: 1fr; }
    .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
    .nav-toggle:checked ~ .sidebar { transform: none; }
    .nav-toggle-label {
        display: inline-flex; align-items: center; gap: .4rem; position: sticky; top: 0; z-index: 10;
        background: var(--surface); border-bottom: 1px solid var(--border); padding: .7rem 1rem; width: 100%; font-weight: 600; cursor: pointer;
    }
    .main { padding: 1rem; }
}

/* ------------------------------------------------------------------ Componenti */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem 1.2rem; margin-bottom: 1.2rem; min-width: 0; }
.card > h2:first-child, .card-head { margin-bottom: .8rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card.danger { border-color: var(--bad); }
.card.flush { padding: 0; }
.card.flush > .card-head { padding: 1rem 1.2rem 0; }
.grid { display: grid; gap: 1.2rem; align-items: start; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-sidebar { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 1100px) { .grid-2, .grid-3, .grid-sidebar { grid-template-columns: 1fr; } }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.kpi .label { color: var(--muted); font-size: .8rem; font-weight: 500; }
.kpi .value { font-size: 1.6rem; font-weight: 700; margin-top: .2rem; }
.kpi .sub { color: var(--muted); font-size: .8rem; }
.kpi a { color: inherit; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: .6rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--surface-2); }
td.num, th.num { text-align: right; white-space: nowrap; }
td.actions { white-space: nowrap; text-align: right; }
.card.flush table th:first-child, .card.flush table td:first-child { padding-left: 1.2rem; }
.card.flush table th:last-child, .card.flush table td:last-child { padding-right: 1.2rem; }
.empty { color: var(--muted); padding: 1.2rem; text-align: center; }

dl.details { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1.2rem; margin: 0; font-size: .92rem; }
dl.details dt { color: var(--muted); }
dl.details dd { margin: 0; overflow-wrap: anywhere; }

.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-bad { background: var(--bad-soft); color: var(--bad); }
.badge-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge-brand { background: var(--brand-soft); color: var(--brand); }
.dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; background: var(--muted); margin-right: .35rem; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--border); }

.muted { color: var(--muted); }
.small { font-size: .82rem; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.stack > * + * { margin-top: .6rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.mt { margin-top: 1rem; }
.hidden { display: none; }

/* ------------------------------------------------------------------ Messaggi */
.flash { border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; border: 1px solid; font-weight: 500; }
.flash-success { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); }
.flash-error { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); }
.flash-warning { background: var(--warn-soft); border-color: var(--warn); color: var(--warn); }
.notice { background: var(--brand-soft); border: 1px solid var(--brand); color: var(--text); border-radius: var(--radius); padding: .8rem 1rem; margin-bottom: 1rem; }
.notice.warn { background: var(--warn-soft); border-color: var(--warn); }
.notice.bad { background: var(--bad-soft); border-color: var(--bad); }
.secret-box { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; background: var(--surface); border: 1px dashed var(--brand); border-radius: 8px; padding: .7rem .9rem; margin: .6rem 0; }
.secret-box code { font-size: 1.05rem; font-weight: 600; letter-spacing: .03em; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ Moduli */
form.inline { display: inline; margin: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1.2rem; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: .3rem; }
.field > span, label.label { font-size: .82rem; font-weight: 600; color: var(--text-2); }
.field .hint { font-size: .78rem; color: var(--muted); font-weight: 400; }
.field .error { font-size: .8rem; color: var(--bad); font-weight: 500; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"], input[type="date"], input[type="search"], input[type="url"], select, textarea {
    font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
    padding: .5rem .65rem; width: 100%; min-width: 0;
}
textarea { min-height: 5rem; resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.invalid input, .invalid select, .invalid textarea { border-color: var(--bad); }
.check { display: flex; gap: .5rem; align-items: flex-start; font-size: .9rem; }
.check input { margin-top: .25rem; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .4rem 1rem; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { min-width: 160px; }
.filters .grow { flex: 1; min-width: 220px; }
.price-table input { max-width: 9rem; }
.price-table input.stripe { max-width: 16rem; }
input.short { max-width: 6rem; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    font: inherit; font-weight: 600; font-size: .88rem; line-height: 1.2;
    padding: .55rem .95rem; border-radius: 8px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text); cursor: pointer; white-space: nowrap;
}
.btn:hover { text-decoration: none; border-color: var(--brand); }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-strong); border-color: var(--brand-strong); }
.btn-danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn-danger:hover { filter: brightness(1.1); border-color: var(--bad); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--brand); padding-left: .4rem; padding-right: .4rem; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

details.disclosure { border: 1px solid var(--border); border-radius: 8px; padding: .6rem .9rem; background: var(--surface-2); }
details.disclosure + details.disclosure { margin-top: .6rem; }
details.disclosure summary { cursor: pointer; font-weight: 600; }
details.disclosure[open] summary { margin-bottom: .7rem; }

/* ------------------------------------------------------------------ Paginazione e schede */
.pagination { display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; margin-top: .9rem; }
.pagination .muted { margin-right: .6rem; }
.page { padding: .25rem .6rem; border: 1px solid var(--border); border-radius: 6px; font-size: .85rem; background: var(--surface); }
.page.current { background: var(--brand); border-color: var(--brand); color: #fff; }
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .5rem .9rem; color: var(--text-2); font-weight: 600; font-size: .9rem; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs a:hover { text-decoration: none; color: var(--brand); }
.tabs a.active { color: var(--brand); border-color: var(--brand); }

/* ------------------------------------------------------------------ Grafici (SVG generato dal server) */
.chart { width: 100%; height: 190px; display: block; }
.chart-bar { fill: var(--brand); }
.chart-bar:hover { fill: var(--brand-strong); }
.chart-axis { stroke: var(--border); stroke-width: 1; }
.chart-label { fill: var(--muted); font-size: 11px; font-family: "Montserrat", sans-serif; }
progress { width: 100%; height: .5rem; appearance: none; border: 0; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--surface-2); border-radius: 999px; }
progress::-webkit-progress-value { background: var(--brand); border-radius: 999px; }
progress::-moz-progress-bar { background: var(--brand); border-radius: 999px; }

/* ------------------------------------------------------------------ Catalogo */
.plans { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: 1rem; }
.plan { min-width: 0; border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; background: var(--surface); display: flex; flex-direction: column; gap: .6rem; }
.plan.inactive { opacity: .6; }
.plan h3 { font-size: 1.05rem; margin: 0; }
.plan .price { font-size: 1.4rem; font-weight: 700; overflow-wrap: anywhere; }
/* Prezzi per durata: due colonne strette, il costo mensile va a capo sotto il prezzo per non uscire dalla scheda. */
.plan-prices { table-layout: fixed; }
.plan-prices td { padding: .35rem .2rem; }
.plan-prices td:first-child { padding-left: 0; width: 45%; }
.plan-prices td.num { padding-right: 0; white-space: normal; }
.plan-prices .per-month { display: block; color: var(--muted); font-size: .75rem; white-space: nowrap; }
.plan .price small { font-size: .8rem; color: var(--muted); font-weight: 500; }
.plan ul { margin: 0; padding-left: 1.1rem; font-size: .85rem; color: var(--text-2); }
.plan .limits { display: flex; gap: .4rem; flex-wrap: wrap; }
.plan .foot { margin-top: auto; display: flex; justify-content: space-between; align-items: center; }

/* ------------------------------------------------------------------ Accesso */
.auth-page { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: linear-gradient(160deg, var(--bg), var(--brand-soft)); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 10px 30px rgba(15, 23, 42, .12); padding: 2rem; }
.auth-card .brand { color: var(--text); padding: 0 0 1.2rem; }
.auth-card .brand small { color: var(--muted); }
.auth-card .btn { width: 100%; margin-top: .4rem; }
.auth-card form > * + * { margin-top: .9rem; }
.qr { display: block; margin: .8rem auto; width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 8px; }
.code-input { font-size: 1.4rem !important; letter-spacing: .3em; text-align: center; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; font-family: ui-monospace, Consolas, monospace; font-size: 1.05rem; margin: 1rem 0; }
.codes span { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .4rem .6rem; text-align: center; }
.error-code { font-size: 3rem; font-weight: 700; color: var(--brand); line-height: 1; margin-bottom: .5rem; }

@media print {
    .sidebar, .page-actions, .nav-toggle-label, form, .btn { display: none !important; }
    .shell { display: block; }
    .card { box-shadow: none; break-inside: avoid; }
}
