/* HubCompliance — design system (SPEC §12). Nessuna risorsa esterna. */

:root {
    --c-primary: #1B3A6B;
    --c-accent: #2563EB;
    --c-accent-hover: #1D4ED8;
    --c-text: #111827;
    --c-muted: #6B7280;
    --c-bg: #F3F4F6;
    --c-surface: #FFFFFF;
    --c-border: #E5E7EB;
    --c-success: #059669;
    --c-warning: #D97706;
    --c-danger: #DC2626;

    /* Tinte chiare derivate per sfondi di badge e avvisi */
    --c-success-bg: #ECFDF5;
    --c-warning-bg: #FFFBEB;
    --c-danger-bg: #FEF2F2;
    --c-info-bg: #EFF6FF;
    --c-success-text: #047857;
    --c-warning-text: #B45309;
    --c-danger-text: #B91C1C;
    --c-info-text: #1D4ED8;

    --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
    --radius: 8px;
    --shadow: 0 1px 2px rgba(17, 24, 39, 0.05);
    --shadow-raised: 0 8px 24px rgba(17, 24, 39, 0.12);
    --sidebar-w: 248px;
    --topbar-h: 64px;
    --tap: 40px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--c-text);
    background: var(--c-bg);
}

@media (min-width: 1024px) {
    body {
        font-size: 16px;
    }
}

h1, h2, h3 {
    color: var(--c-primary);
    line-height: 1.25;
    margin: 0;
}

a {
    color: var(--c-accent);
}

a:hover {
    color: var(--c-accent-hover);
}

code, pre {
    font-family: var(--font-mono);
    font-size: 0.9em;
}

:focus-visible {
    outline: 3px solid var(--c-accent);
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    left: 8px;
    top: -48px;
    z-index: 100;
    padding: 8px 16px;
    background: var(--c-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-raised);
}

.skip-link:focus {
    top: 8px;
}

/* Icone: sprite SVG locale, tratto semplice */
.icon {
    width: 20px;
    height: 20px;
    flex: none;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    vertical-align: middle;
}

/* ---------- Layout staff ---------- */

.sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    width: var(--sidebar-w);
    display: flex;
    flex-direction: column;
    background: var(--c-primary);
    color: #fff;
    overflow-y: auto;
}

.sidebar__brand {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--topbar-h);
    padding: 12px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.sidebar__logo {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius);
    background: #fff;
    color: var(--c-primary);
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 0.5px;
}

.sidebar__names {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
    min-width: 0;
}

.sidebar__names small {
    color: rgba(255, 255, 255, 0.72);
    font-size: 12px;
}

.sidebar .sidebar__close {
    margin-left: auto;
    color: #fff;
}

.sidebar__nav {
    padding: 12px 8px 24px;
}

.sidebar__nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
}

.sidebar__link {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: var(--tap);
    padding: 8px 12px;
    margin-bottom: 2px;
    border-radius: 6px;
    color: rgba(255, 255, 255, 0.86);
    text-decoration: none;
    font-size: 15px;
}

.sidebar__link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #fff;
}

.sidebar__link.is-active {
    background: var(--c-accent);
    color: #fff;
    font-weight: 600;
}

.sidebar__link:focus-visible {
    outline-color: #fff;
}

.sidebar__external {
    margin-top: 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0;
    padding-top: 16px;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 35;
    background: rgba(17, 24, 39, 0.45);
}

.main {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    margin-left: var(--sidebar-w);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: var(--topbar-h);
    padding: 8px 24px;
    background: var(--c-surface);
    border-bottom: 1px solid var(--c-border);
}

.topbar .topbar__menu,
.sidebar .sidebar__close {
    display: none;
}

.topbar__title {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 20px;
    font-weight: 650;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.topbar__search {
    position: relative;
    flex: 0 1 320px;
    min-width: 180px;
}

.topbar__search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--c-muted);
    pointer-events: none;
}

.topbar__search input[type="search"] {
    padding-left: 40px;
}

@media (max-width: 1279px) {
    .topbar__user-name {
        display: none;
    }
}

.topbar__user {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: none;
    color: var(--c-muted);
    font-size: 14px;
    white-space: nowrap;
}

.avatar {
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--c-bg);
    color: var(--c-primary);
}

.content {
    flex: 1;
    width: 100%;
    max-width: 1400px;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.content:focus {
    outline: none;
}

.footer {
    padding: 16px 24px;
    color: var(--c-muted);
    font-size: 13px;
    border-top: 1px solid var(--c-border);
}

/* Tablet e mobile: sidebar a scomparsa */
@media (max-width: 1023px) {
    .sidebar {
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: var(--shadow-raised);
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    .main {
        margin-left: 0;
    }

    .topbar {
        padding: 8px 16px;
        gap: 12px;
    }

    .topbar .topbar__menu,
    .sidebar .sidebar__close {
        display: inline-flex;
    }

    .content {
        padding: 16px;
        gap: 16px;
    }
}

@media (max-width: 640px) {
    .topbar {
        flex-wrap: wrap;
    }

    .topbar__title {
        flex: 1;
        font-size: 18px;
    }

    .topbar__search {
        order: 3;
        flex-basis: 100%;
        min-width: 0;
    }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar {
        transition: none;
    }
}

/* ---------- Card ---------- */

.card {
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    min-width: 0;
}

.card__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

.card__title {
    font-size: 17px;
    font-weight: 650;
}

.card > .card__title {
    margin-bottom: 16px;
}

.subtitle {
    font-size: 15px;
    margin: 20px 0 8px;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
    gap: 24px;
}

/* Indicatori */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr));
    gap: 16px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.stat__label {
    color: var(--c-muted);
    font-size: 14px;
}

.stat__value {
    color: var(--c-primary);
    font-size: 30px;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stat__note {
    color: var(--c-muted);
    font-size: 12px;
}

/* ---------- Pulsanti ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 6px;
    font: inherit;
    font-weight: 600;
    font-size: 15px;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    white-space: nowrap;
}

.btn .icon {
    width: 18px;
    height: 18px;
}

.btn--primary {
    background: var(--c-accent);
    color: #fff;
}

.btn--primary:hover {
    background: var(--c-accent-hover);
    color: #fff;
}

.btn--secondary {
    background: var(--c-surface);
    color: var(--c-primary);
    border-color: #D1D5DB;
}

.btn--secondary:hover {
    background: var(--c-bg);
    color: var(--c-primary);
}

.btn--danger {
    background: var(--c-danger);
    color: #fff;
}

.btn--danger:hover {
    background: #B91C1C;
    color: #fff;
}

.btn--small {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 14px;
}

.btn:disabled,
.btn[aria-disabled="true"] {
    opacity: 0.55;
    cursor: not-allowed;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--tap);
    height: var(--tap);
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--c-primary);
    cursor: pointer;
}

.icon-button:hover {
    background: rgba(17, 24, 39, 0.06);
}

.sidebar .icon-button:hover {
    background: rgba(255, 255, 255, 0.12);
}

.button-row,
.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.badge-row {
    margin-top: 16px;
}

/* ---------- Badge di stato: sempre testo + colore ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 10px;
    border-radius: 999px;
    border: 1px solid transparent;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.6;
    white-space: nowrap;
}

.badge::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: currentColor;
}

.badge--success {
    background: var(--c-success-bg);
    color: var(--c-success-text);
    border-color: #A7F3D0;
}

.badge--warning {
    background: var(--c-warning-bg);
    color: var(--c-warning-text);
    border-color: #FDE68A;
}

.badge--danger {
    background: var(--c-danger-bg);
    color: var(--c-danger-text);
    border-color: #FECACA;
}

.badge--info {
    background: var(--c-info-bg);
    color: var(--c-info-text);
    border-color: #BFDBFE;
}

.badge--neutral {
    background: var(--c-bg);
    color: #4B5563;
    border-color: var(--c-border);
}

/* ---------- Tabelle ---------- */

.table-wrap {
    overflow: auto;
    max-height: 70vh;
    border: 1px solid var(--c-border);
    border-radius: 6px;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 15px;
}

.table th {
    position: sticky;
    top: 0;
    z-index: 1;
    background: var(--c-primary);
    color: #fff;
    font-weight: 600;
    text-align: left;
    padding: 12px 14px;
    white-space: nowrap;
}

.table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--c-border);
    vertical-align: middle;
}

.table tbody tr:nth-child(even) {
    background: var(--c-bg);
}

.table tbody tr:last-child td {
    border-bottom: 0;
}

.table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.table .actions {
    text-align: right;
    white-space: nowrap;
}

/* ---------- Moduli ---------- */

.form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field label {
    font-weight: 600;
    font-size: 14px;
}

input[type="text"],
input[type="email"],
input[type="search"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="tel"],
input[type="url"],
select,
textarea {
    width: 100%;
    min-height: var(--tap);
    padding: 8px 12px;
    border: 1px solid #D1D5DB;
    border-radius: 6px;
    background: var(--c-surface);
    color: var(--c-text);
    font: inherit;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--c-accent);
    outline-offset: 0;
    border-color: var(--c-accent);
}

.field--error input,
.field--error select,
.field--error textarea {
    border-color: var(--c-danger);
}

.field__error {
    margin: 0;
    color: var(--c-danger-text);
    font-size: 14px;
}

.field__hint {
    margin: 0;
    color: var(--c-muted);
    font-size: 14px;
}

.field--check {
    flex-direction: row;
    align-items: flex-start;
    gap: 10px;
}

.field--check input {
    width: 20px;
    height: 20px;
    margin: 2px 0 0;
    flex: none;
    accent-color: var(--c-accent);
}

.field--check label {
    font-weight: 400;
    font-size: 15px;
}

.form-summary,
.notice {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    border-radius: var(--radius);
    border: 1px solid;
}

.form-summary {
    margin-bottom: 16px;
    background: var(--c-danger-bg);
    border-color: #FECACA;
    color: var(--c-danger-text);
}

.notice--info {
    background: var(--c-info-bg);
    border-color: #BFDBFE;
    color: #1E3A8A;
}

.notice--warning {
    background: var(--c-warning-bg);
    border-color: #FDE68A;
    color: #92400E;
}

/* ---------- Avanzamento ---------- */

.progress {
    height: 10px;
    border-radius: 999px;
    background: var(--c-border);
    overflow: hidden;
}

.progress__bar {
    width: 0;
    height: 100%;
    border-radius: inherit;
    background: var(--c-accent);
    transition: width 0.3s ease;
}

.progress__text {
    margin: 6px 0 0;
    color: var(--c-muted);
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

/* ---------- Toast ---------- */

.toasts {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 60;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: min(380px, calc(100vw - 32px));
}

.toast {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 14px;
    background: var(--c-surface);
    border: 1px solid var(--c-border);
    border-left: 4px solid var(--c-accent);
    border-radius: var(--radius);
    box-shadow: var(--shadow-raised);
    font-size: 15px;
}

.toast__text {
    flex: 1;
    padding-top: 1px;
}

.toast .icon-button {
    width: 28px;
    height: 28px;
    margin: -4px -6px -4px 0;
    color: var(--c-muted);
}

.toast--success {
    border-left-color: var(--c-success);
}

.toast--success > .icon {
    color: var(--c-success);
}

.toast--warning {
    border-left-color: var(--c-warning);
}

.toast--warning > .icon {
    color: var(--c-warning);
}

.toast--danger {
    border-left-color: var(--c-danger);
}

.toast--danger > .icon {
    color: var(--c-danger);
}

.toast--info > .icon {
    color: var(--c-accent);
}

/* ---------- Layout minimale (errori e portali esterni) ---------- */

.minimal__wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 24px 16px;
}

.minimal__brand {
    color: var(--c-primary);
    font-weight: 700;
    font-size: 18px;
    letter-spacing: 0.2px;
}

.minimal__card {
    width: 100%;
    max-width: 520px;
    padding: 32px;
}

@media (max-width: 480px) {
    .minimal__card {
        padding: 24px 20px;
    }
}

.error-code {
    margin: 0 0 4px;
    color: var(--c-muted);
    font-weight: 700;
    font-size: 14px;
    letter-spacing: 1px;
}

.error-title {
    font-size: 24px;
    margin-bottom: 12px;
}

.error-text {
    color: #374151;
    margin: 0 0 20px;
}

.error-ref {
    color: var(--c-muted);
    font-size: 14px;
    margin: 0 0 20px;
}

.error-debug {
    margin: 0 0 20px;
    padding: 12px;
    background: var(--c-danger-bg);
    border: 1px solid #FECACA;
    border-radius: 6px;
    font-size: 13px;
}

.error-debug pre {
    margin: 8px 0 0;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---------- Fase 2: accesso, utenti, impostazioni, registro ---------- */

.notice--success {
    background: var(--c-success-bg);
    border-color: #A7F3D0;
    color: #065F46;
}

.notice--danger {
    background: var(--c-danger-bg);
    border-color: #FECACA;
    color: var(--c-danger-text);
}

.minimal__card .notice {
    margin-bottom: 16px;
}

.minimal__card--wide {
    max-width: 640px;
}

.auth__title {
    margin: 0 0 8px;
    color: var(--c-primary);
    font-size: 22px;
}

.auth__lead {
    margin: 0 0 20px;
    color: var(--c-muted);
}

.auth__note {
    margin: 20px 0 0;
    color: var(--c-muted);
    font-size: 14px;
}

.auth__secondary {
    margin-top: 12px;
    text-align: center;
}

.btn--block {
    width: 100%;
}

.btn--link {
    min-height: var(--tap);
    padding: 8px;
    border: 0;
    background: none;
    color: var(--c-accent);
    font: inherit;
    font-size: 14px;
    text-decoration: underline;
    cursor: pointer;
}

.btn--link:hover {
    color: var(--c-accent-hover);
}

.input--code {
    font-family: var(--font-mono);
    font-size: 20px;
    letter-spacing: 2px;
}

.steps {
    margin: 0 0 20px;
    padding-left: 20px;
}

.steps li {
    margin-bottom: 12px;
}

.qr {
    display: flex;
    justify-content: center;
    margin: 12px 0;
}

.qr img {
    width: 220px;
    height: 220px;
    padding: 8px;
    border: 1px solid var(--c-border);
    border-radius: var(--radius);
    background: #FFFFFF;
}

.qr__manual summary {
    color: var(--c-accent);
    cursor: pointer;
}

.secret {
    font-family: var(--font-mono);
    font-size: 18px;
    letter-spacing: 1px;
    word-break: break-all;
}

.recovery-codes {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 16px;
    margin: 16px 0 20px;
    padding: 16px;
    border: 1px dashed var(--c-border);
    border-radius: var(--radius);
    list-style: none;
}

.recovery-codes code {
    font-size: 18px;
    letter-spacing: 1px;
}

@media (max-width: 400px) {
    .recovery-codes {
        grid-template-columns: 1fr;
    }
}

.topbar__user-link {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: var(--tap);
    color: var(--c-text);
    text-decoration: none;
}

.topbar__user-link:hover {
    text-decoration: none;
}

.topbar__user-name {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.topbar__user-name small {
    color: var(--c-muted);
    font-size: 12px;
}

.topbar__logout {
    margin: 0;
}

.card--narrow {
    max-width: 640px;
}

.tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--c-border);
}

.tabs__link {
    display: inline-flex;
    align-items: center;
    min-height: var(--tap);
    padding: 8px 16px;
    border-bottom: 3px solid transparent;
    color: var(--c-muted);
    font-weight: 600;
    text-decoration: none;
}

.tabs__link:hover {
    color: var(--c-text);
    text-decoration: none;
}

.tabs__link.is-active {
    border-bottom-color: var(--c-accent);
    color: var(--c-primary);
}

.field__label {
    font-weight: 600;
    font-size: 14px;
}

.field__static {
    margin: 0;
    padding: 8px 0;
}

.details {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 8px 16px;
    margin: 0 0 16px;
}

.details dt {
    color: var(--c-muted);
}

.details dd {
    margin: 0;
}

.temp-password {
    margin-bottom: 16px;
}

.temp-password p {
    margin: 8px 0 0;
}

.temp-password__value {
    display: inline-block;
    margin-left: 8px;
    padding: 2px 8px;
    border-radius: 4px;
    background: #FFFFFF;
    font-size: 18px;
    letter-spacing: 1px;
}

.filters {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px 16px;
    align-items: end;
}

.filters__actions {
    display: flex;
    gap: 8px;
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 16px;
}

.muted {
    color: var(--c-muted);
}

.nowrap {
    white-space: nowrap;
}

@media print {
    .no-print,
    .minimal__brand {
        display: none;
    }

    .minimal__card {
        border: 0;
        box-shadow: none;
    }
}
