:root {
    color-scheme: dark;
    font: 15px/1.55 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    --ink: #f7f8fb;
    --muted: #9da8b8;
    --line: #303744;
    --accent: #c51f30;
    --accent-hover: #a71928;
    --paper: #20252d;
    --paper-raised: #272d37;
    --back: #111419;
    --sidebar: #181d25;
    --header: #171b22;
    --success: #2f9e73;
    --warning: #d29a3a;
    --danger: #d85662;
    --radius: .85rem;
    --shadow: 0 12px 30px rgb(0 0 0 / .18);
}

* { box-sizing: border-box; }
html { min-width: 20rem; background: var(--back); }
body { margin: 0; color: var(--ink); background: var(--back); }

header { background: var(--header); color: white; border-bottom: 1px solid var(--line); }
header > div, main { max-width: 1220px; margin: auto; padding: 1.25rem clamp(1rem, 3vw, 2rem); }
header > div, nav, .toolbar, .filters, .pagination {
    display: flex; align-items: center; flex-wrap: wrap; gap: .75rem 1rem;
}
header > div { justify-content: space-between; }
header a { color: white; }

a { color: #ff8994; text-underline-offset: .16em; }
a:hover { color: #ffabb2; text-decoration-thickness: .14em; }
.brand { display: inline-flex; align-items: center; gap: .7rem; color: #fff; text-decoration: none; }
.brand:hover { color: #fff; }
.brand-mark { display: grid; width: 2rem; height: 2rem; place-items: center; color: #fff; background: var(--accent); border-radius: .58rem; font-weight: 900; box-shadow: 0 6px 16px rgb(197 31 48 / .28); }
.brand-copy { display: grid; line-height: 1.08; }
.brand-copy strong { font-size: .92rem; letter-spacing: .065em; }
.brand-copy small { margin-top: .2rem; color: #aeb8c7; font-size: .7rem; font-weight: 620; letter-spacing: .035em; text-transform: uppercase; }

h1 { margin: .35rem 0 1.2rem; font-size: clamp(1.7rem, 3vw, 2.45rem); line-height: 1.15; overflow-wrap: anywhere; }
h2 { font-size: 1.08rem; margin: 0 0 .85rem; }
section, details {
    margin-bottom: 1rem; padding: 1.2rem; background: var(--paper);
    border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
details .grid { margin-top: 1rem; }
details section { margin-bottom: 0; box-shadow: none; }
summary { cursor: pointer; font-weight: 700; }

.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 16rem), 1fr)); gap: 1rem; }
.dashboard { grid-template-columns: repeat(auto-fit, minmax(min(100%, 25rem), 1fr)); align-items: start; }
.dashboard > section, .dashboard > div { min-width: 0; }
.compact { max-width: 42rem; }

label { display: block; margin-bottom: .85rem; color: #e7eaf0; font-weight: 650; }
input, textarea, select, button { font: inherit; }
input:not([type=hidden], [type=checkbox]), textarea, select {
    display: block; width: 100%; margin-top: .32rem; padding: .62rem .75rem;
    color: var(--ink); background: #171b22; border: 1px solid #505a69; border-radius: .55rem;
    transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
input:not([type=hidden], [type=checkbox]):focus, textarea:focus, select:focus {
    border-color: #df5361; box-shadow: 0 0 0 3px rgb(197 31 48 / .2); background: #191e26; outline: 0;
}
textarea { resize: vertical; }
.check { display: flex; align-items: baseline; gap: .55rem; }
.check input { flex: 0 0 auto; accent-color: var(--accent); }

button, .button {
    display: inline-block; padding: .58rem .9rem; color: white; background: var(--accent);
    border: 1px solid transparent; border-radius: .55rem; cursor: pointer; font-weight: 720;
    text-decoration: none; box-shadow: 0 5px 16px rgb(197 31 48 / .22); transition: .16s ease;
}
button:hover, .button:hover { color: white; background: var(--accent-hover); transform: translateY(-1px); }
button.secondary { color: #f4f6fa; background: #353d49; box-shadow: none; }
button.danger { background: #a72836; }
:focus-visible { outline: 3px solid #ff7b88; outline-offset: 3px; }

.notice { padding: .75rem .9rem; color: #caffeb; background: #173a30; border: 1px solid #2b765d; border-radius: .6rem; }
.error { color: #ffd8dc; background: #4a2026; border-color: #8d3641; }
.muted { color: var(--muted); }
.item { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .35rem .9rem; padding: .75rem 0; border-top: 1px solid var(--line); overflow-wrap: anywhere; }
.count { margin-left: .25rem; color: var(--muted); font-size: .85rem; }
.toolbar { margin-bottom: 1rem; }
.filters { align-items: flex-end; padding: .85rem; background: #191e25; border: 1px solid var(--line); border-radius: .7rem; }
.filters > * { margin-bottom: 0; }
.filters > a { align-self: center; }

.scroll { overflow: auto; border: 1px solid var(--line); border-radius: .7rem; }
table { width: 100%; border-collapse: separate; border-spacing: 0; text-align: left; }
th, td { padding: .68rem .75rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { position: sticky; top: 0; z-index: 1; color: #d9dee7; background: #2b323d; font-size: .8rem; letter-spacing: .035em; text-transform: uppercase; }
tbody tr { background: #20252d; }
tbody tr:nth-child(even) { background: #1d222a; }
tbody tr:hover { background: #292f39; }
tbody tr:last-child td { border-bottom: 0; }
td { min-width: 3rem; max-width: 23rem; overflow-wrap: anywhere; }
.actions { white-space: nowrap; }
.actions a { display: inline-block; margin-right: .55rem; }
.actions a + a { margin-left: 0; }
.pagination { margin-top: 1rem; }

.shell { max-width: none; min-height: 100vh; margin: 0; background: var(--back); }
.authenticated { display: grid; grid-template: auto 1fr / 15rem minmax(0, 1fr); }
.shell header { grid-column: 1 / -1; position: sticky; top: 0; z-index: 20; background: rgb(23 27 34 / .96); backdrop-filter: blur(12px); }
.shell header > div { max-width: none; padding: .78rem clamp(1rem, 2.4vw, 2rem); }
.shell aside { display: flex; flex-direction: column; position: sticky; top: 4.15rem; align-self: start; min-height: calc(100vh - 4.15rem); padding: 1rem .75rem; background: var(--sidebar); border-right: 1px solid var(--line); }
.nav-heading { padding: .25rem .78rem .65rem; color: #727e90; font-size: .68rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.shell aside nav { display: grid; gap: .28rem; align-items: normal; }
.shell aside a {
    display: flex; align-items: center; gap: .72rem; padding: .68rem .78rem; color: #c9d0da; border-left: 3px solid transparent;
    border-radius: .55rem; font-weight: 640; text-decoration: none; transition: .15s ease;
}
.nav-icon { display: inline-grid; flex: 0 0 1.45rem; height: 1.45rem; place-items: center; color: #8e9aac; font-size: .92rem; }
.shell aside a:hover { color: #fff; background: #252b35; }
.shell aside a[aria-current] { color: #fff; background: linear-gradient(90deg, rgb(197 31 48 / .28), rgb(197 31 48 / .08)); border-left-color: var(--accent); }
.shell aside a[aria-current] .nav-icon { color: #ff8e99; }
.shell main { isolation: isolate; position: relative; width: 100%; max-width: none; min-width: 0; margin: 0; padding: 1.6rem clamp(1rem, 2.5vw, 2.4rem); }
.shell main::before {
    content: ""; position: fixed; z-index: 0; inset: 4.2rem 0 0 15rem; pointer-events: none;
    background: url("./agicom-logo-watermark.png?v=20261201-2") center / min(62vw, 52rem) auto no-repeat; opacity: .06;
}
.shell main > * { position: relative; z-index: 1; }
.shell:not(.authenticated) main::before { left: 0; }
.profile { display: flex; align-items: center; flex-wrap: wrap; gap: .55rem 1rem; color: #c5ccd7; font-size: .9rem; }
.profile span { overflow-wrap: anywhere; }

.site-footer {
    margin-top: auto; padding: 1rem .78rem .2rem; color: #707b8b;
    border-top: 1px solid var(--line); font-size: .67rem; line-height: 1.5;
}
.site-footer p { margin: 0 0 .65rem; }
.site-footer strong { color: #aeb8c7; letter-spacing: .035em; }
.site-footer .version { display: inline-block; margin-left: .3rem; padding: .08rem .4rem; color: #cbd2dc; background: #252b34; border: 1px solid #343c48; border-radius: 999px; font-size: .7rem; }

.chart { min-width: 0; }
.chart-row { display: grid; grid-template-columns: minmax(4.5rem, auto) minmax(1.7rem, 1fr) minmax(5rem, auto); gap: .55rem; align-items: center; padding: .32rem 0; font-size: .88rem; }
.chart-row span:last-child { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart-row meter { width: 100%; height: 1rem; }
.chart-row meter::-webkit-meter-bar { background: #343c48; border: 0; border-radius: 999px; }
.chart-row meter::-webkit-meter-optimum-value { background: var(--accent); border-radius: 999px; }
.chart-row meter::-moz-meter-bar { background: var(--accent); }

.metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: 1rem; }
.metric { position: relative; overflow: hidden; min-height: 7.2rem; }
.metric::after { content: ""; position: absolute; right: -1.6rem; bottom: -2rem; width: 6rem; height: 6rem; border-radius: 50%; background: rgb(197 31 48 / .12); }
.metric span { display: block; margin-bottom: .35rem; color: var(--muted); font-size: .87rem; }
.metric strong { display: block; font-size: clamp(1.45rem, 3vw, 2.2rem); overflow-wrap: anywhere; }

.status { display: inline-block; padding: .22rem .58rem; border-radius: 999px; white-space: nowrap; font-size: .8rem; font-weight: 720; }
.status.scaduto { color: #ffdce0; background: #672a33; }
.status.urgente { color: #ffe4d0; background: #674127; }
.status.in-scadenza { color: #fff0ae; background: #5b4b1f; }
.status.ok { color: #d4ffef; background: #205040; }
.certificate-fields { margin-top: 1rem; }
.mfa-card form + form { margin-top: .65rem; }
.mfa-note { padding: .8rem 1rem; color: #cbd2dc; background: #171b22; border: 1px solid var(--line); border-radius: .55rem; }
.mfa-qr-wrap { display: grid; justify-items: center; margin: 1rem 0; padding: 1rem; color: #4a5565; background: #fff; border-radius: .7rem; text-align: center; }
.mfa-qr-wrap p { margin: .75rem 0 0; }
#mfa-qrcode { min-width: 220px; min-height: 220px; }
#mfa-qrcode img, #mfa-qrcode canvas { display: block; max-width: 100%; height: auto; }
.mfa-secret, .mfa-uri { display: block; margin-top: .45rem; padding: .75rem; color: #fff; background: #11151b; border: 1px solid #3a4350; border-radius: .45rem; overflow-wrap: anywhere; user-select: all; }
.mfa-secret { color: #ffabb3; font-size: 1rem; letter-spacing: .12em; }
.mfa-uri { font-size: .75rem; }
button.small { padding: .42rem .65rem; font-size: .78rem; }
.login-help { margin: 1rem 0 0; text-align: center; }
.login-help a { color: #d7dde6; }

@media (max-width: 820px) {
    .authenticated { grid-template: auto auto 1fr / minmax(0, 1fr); }
    .shell header { position: static; }
    .shell aside { position: static; min-height: 0; padding: .65rem; border-right: 0; border-bottom: 1px solid var(--line); }
    .shell aside nav { display: flex; flex-wrap: nowrap; gap: .25rem; overflow-x: auto; scrollbar-width: thin; }
    .shell aside a { flex: 0 0 auto; padding: .52rem .68rem; border-left: 0; border-bottom: 2px solid transparent; }
    .shell aside a[aria-current] { border-bottom-color: var(--accent); }
    .site-footer { display: none; }
    .shell main::before { inset: 0; background-size: min(84vw, 38rem); opacity: .035; }
}

@media (max-width: 520px) {
    header > div { align-items: flex-start; }
    .brand-copy { display: grid; }
    .shell main { padding: 1.15rem .8rem; }
    section, details { padding: 1rem; border-radius: .7rem; }
    .toolbar > *, .toolbar .button, .toolbar button { width: 100%; text-align: center; }
    .actions { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
