:root {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: #17201f;
    background: #f4f6f5;
    --surface: #ffffff;
    --surface-soft: #f7f9f8;
    --border: #e2e8e5;
    --text: #17201f;
    --muted: #66736f;
    --accent: #1c6758;
    --accent-strong: #145044;
    --accent-soft: #e8f3ef;
    --danger: #a93636;
    --sidebar: #13231f;
    --sidebar-text: #dce7e3;
    --sidebar-muted: #8fa39c;
    --shadow: 0 12px 35px rgba(20, 45, 37, .07);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: #f4f6f5; color: var(--text); }
a { color: inherit; }
button, input { font: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; background: var(--sidebar); color: var(--sidebar-text); }
.sidebar-header { padding: 24px 20px 18px; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark { width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px; background: #dff2eb; color: #173f35; font-weight: 850; font-size: 1.05rem; }
.brand-copy { display: grid; gap: 1px; }
.brand-copy strong { font-size: 1rem; letter-spacing: -.02em; }
.brand-copy small { color: var(--sidebar-muted); font-size: .69rem; letter-spacing: .035em; }
.main-nav { padding: 18px 12px; display: grid; gap: 5px; }
.nav-section-label { margin: 18px 10px 7px; color: var(--sidebar-muted); font-size: .68rem; font-weight: 750; text-transform: uppercase; letter-spacing: .12em; }
.nav-item { min-height: 44px; display: flex; align-items: center; gap: 11px; padding: 0 12px; border-radius: 10px; color: var(--sidebar-text); text-decoration: none; font-size: .9rem; }
.nav-item.active { background: rgba(223, 242, 235, .11); color: #fff; }
.nav-item-disabled { color: #7d918a; cursor: default; }
.nav-icon { width: 20px; text-align: center; opacity: .9; }
.sidebar-footer { margin-top: auto; padding: 18px 20px 22px; border-top: 1px solid rgba(255,255,255,.07); }
.environment-badge { display: flex; align-items: center; gap: 9px; color: var(--sidebar-muted); font-size: .78rem; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #72c7a7; box-shadow: 0 0 0 4px rgba(114,199,167,.1); }

.workspace { min-width: 0; }
.topbar { min-height: 74px; padding: 0 30px; display: flex; justify-content: space-between; align-items: center; gap: 24px; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--border); }
.topbar-context, .user-copy { display: grid; gap: 2px; }
.context-label, .user-copy span { color: var(--muted); font-size: .72rem; }
.topbar-context strong, .user-copy strong { font-size: .86rem; }
.topbar-user { display: flex; align-items: center; gap: 12px; }
.topbar-user form { margin: 0; }
.user-copy { text-align: right; }
.avatar { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); font-size: .82rem; font-weight: 800; }
.page-shell { width: min(1240px, calc(100% - 56px)); margin: 0 auto; padding: 42px 0 64px; }

.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.eyebrow { color: var(--accent); text-transform: uppercase; letter-spacing: .12em; font-size: .69rem; font-weight: 800; }
h1 { margin: 7px 0 8px; font-size: clamp(1.9rem, 4vw, 2.6rem); letter-spacing: -.045em; line-height: 1.08; }
h2 { margin: 6px 0 8px; font-size: 1.18rem; letter-spacing: -.025em; }
p { margin: 0; color: var(--muted); line-height: 1.6; }

.summary-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.summary-card, .panel, .state-card, .auth-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }
.summary-card { padding: 20px; display: grid; gap: 7px; }
.summary-label { color: var(--muted); text-transform: uppercase; letter-spacing: .08em; font-size: .68rem; font-weight: 750; }
.summary-card strong { overflow-wrap: anywhere; font-size: 1rem; }
.summary-card small { color: var(--muted); font-size: .78rem; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, .75fr); gap: 16px; }
.panel { padding: 26px; }
.panel-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; margin-bottom: 20px; }
.status-pill { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 999px; font-size: .72rem; font-weight: 750; white-space: nowrap; }
.status-pill-success { background: #e7f4ef; color: #246250; }
.check-list { display: grid; gap: 12px; }
.check-item { display: flex; gap: 13px; padding: 15px; border: 1px solid var(--border); background: var(--surface-soft); border-radius: 12px; }
.check-icon { flex: 0 0 28px; width: 28px; height: 28px; display: grid; place-items: center; border-radius: 50%; background: var(--accent-soft); color: var(--accent-strong); font-weight: 850; }
.check-item div { display: grid; gap: 3px; }
.check-item strong { font-size: .9rem; }
.check-item span:last-child { color: var(--muted); font-size: .8rem; line-height: 1.45; }
.next-panel p { margin-top: 4px; }
.module-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 20px; }
.module-tags span { padding: 7px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface-soft); color: #53615d; font-size: .75rem; }

.button { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 9px; padding: 0 14px; text-decoration: none; cursor: pointer; font-weight: 700; font-size: .82rem; }
.button-primary, .primary-button { border: 0; background: var(--accent); color: #fff; }
.button-primary:hover, .primary-button:hover { background: var(--accent-strong); }
.button-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.primary-button { width: 100%; min-height: 44px; margin-top: 20px; border-radius: 10px; cursor: pointer; }
.primary-link { color: var(--accent-strong); font-weight: 700; }

.auth-body { min-height: 100vh; background: radial-gradient(circle at top right, #e6f1ed 0, transparent 34%), #f4f6f5; }
.auth-topbar { min-height: 78px; display: flex; align-items: center; padding: 0 32px; }
.brand-auth .brand-copy small { color: var(--muted); }
.auth-shell { width: min(460px, calc(100% - 32px)); margin: 7vh auto 40px; }
.auth-card { padding: 32px; }
.auth-heading { margin-bottom: 26px; }
.auth-heading h1 { font-size: 2rem; }
label { display: block; margin: 17px 0 7px; font-weight: 700; font-size: .84rem; }
input[type="email"], input[type="password"], input[type="text"] { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #cad4d0; background: #fff; border-radius: 9px; color: var(--text); outline: none; }
input:focus { border-color: #6d9c8e; box-shadow: 0 0 0 3px rgba(28,103,88,.09); }
.check-row { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.validation { color: var(--danger); font-size: .82rem; }

.state-card { width: min(620px, 100%); margin: 8vh auto; padding: 42px; text-align: center; }
.state-code { margin-bottom: 14px; color: #b8c5c1; font-size: 3.5rem; font-weight: 850; letter-spacing: -.06em; }
.state-card p { margin: 0 auto 22px; max-width: 470px; }
.request-id { font-size: .78rem; }

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 82px minmax(0, 1fr); }
    .sidebar-header { padding-inline: 17px; }
    .brand-copy, .nav-item span:not(.nav-icon), .nav-section-label, .environment-badge span:not(.status-dot) { display: none; }
    .main-nav { padding-inline: 14px; }
    .nav-item { justify-content: center; padding: 0; }
    .nav-icon { width: auto; }
    .sidebar-footer { display: flex; justify-content: center; padding-inline: 0; }
    .summary-grid { grid-template-columns: 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
    .app-shell { display: block; }
    .sidebar { position: static; height: auto; }
    .sidebar-header { padding: 14px 18px; }
    .brand-copy { display: grid; }
    .main-nav, .sidebar-footer { display: none; }
    .topbar { padding: 14px 18px; min-height: 68px; }
    .topbar-context, .user-copy { display: none; }
    .page-shell { width: min(100% - 28px, 1240px); padding-top: 28px; }
    .page-heading { display: grid; }
    .page-heading .status-pill { justify-self: start; }
    .panel-heading { display: grid; }
    .panel-heading .status-pill { justify-self: start; }
    .auth-topbar { padding-inline: 18px; }
    .auth-shell { margin-top: 3vh; }
    .auth-card, .panel, .state-card { padding: 24px; }
}

/* STEP 1.1 — amministrazione tenant e icone applicative più leggibili */
.nav-icon { width: 30px; min-width: 30px; height: 30px; display: grid; place-items: center; }
.nav-icon svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.button-icon { margin-right: 7px; font-size: 1.15rem; line-height: 1; }
.alert { margin-bottom: 18px; padding: 13px 15px; border-radius: 11px; border: 1px solid var(--border); font-size: .86rem; }
.alert-success { background: #e9f5f0; border-color: #cbe7dc; color: #245f4f; }
.table-panel { padding: 0; overflow: hidden; }
.data-table-wrap { width: 100%; overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; min-width: 850px; }
.data-table th, .data-table td { padding: 15px 18px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.data-table th { color: var(--muted); background: var(--surface-soft); font-size: .7rem; text-transform: uppercase; letter-spacing: .07em; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table code { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .78rem; color: #42514d; }
.actions-column { width: 220px; }
.table-actions { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.table-actions form { margin: 0; }
.entity-cell { display: flex; align-items: center; gap: 12px; }
.entity-icon { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; background: var(--accent-soft); font-size: 1.15rem; }
.entity-cell div { display: grid; gap: 3px; }
.entity-cell strong { font-size: .9rem; }
.entity-cell small { color: var(--muted); font-size: .68rem; }
.status-pill-muted { background: #eef1f0; color: #697570; }
.button-danger-soft { background: #fff2f2; border-color: #f0d3d3; color: #9c3c3c; }
.button-success-soft { background: #edf7f3; border-color: #cde6dc; color: #28644f; }
.empty-state { padding: 64px 24px; text-align: center; }
.empty-state .empty-icon { font-size: 2.2rem; margin-bottom: 12px; }
.empty-state p { margin: 0 auto 20px; max-width: 420px; }
.form-layout { display: grid; gap: 16px; }
.form-panel { padding: 26px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.field { min-width: 0; }
.field-wide { grid-column: 1 / -1; }
.field label { margin-top: 0; }
.field small { display: block; margin-top: 6px; color: var(--muted); font-size: .76rem; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 4px; }
.validation-summary:empty { display: none; }
.tenant-summary-grid { margin-bottom: 16px; }

@media (max-width: 720px) {
    .form-grid { grid-template-columns: 1fr; }
    .field-wide { grid-column: auto; }
    .form-actions { flex-direction: column-reverse; }
    .form-actions .button { width: 100%; }
}

/* STEP 1.2 — utenti tenant e ruoli */
select { width: 100%; min-height: 44px; padding: 10px 12px; border: 1px solid #cad4d0; background: #fff; border-radius: 9px; color: var(--text); outline: none; }
select:focus { border-color: #6d9c8e; box-shadow: 0 0 0 3px rgba(28,103,88,.09); }
select:disabled { background: var(--surface-soft); color: var(--muted); }
.role-pill { display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border-radius: 999px; background: #edf1f7; color: #45566f; font-size: .72rem; font-weight: 750; }
.password-panel { margin-top: 20px; }
.password-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 12px; }
.password-row .field label { margin-top: 0; }
@media (max-width: 720px) { .password-row { grid-template-columns: 1fr; } .password-row .button { width: 100%; } }

/* STEP 1.3 — matrice ruoli e permessi */
.permission-tenant-selector { margin-bottom: 16px; }
.permission-tenant-selector .field { max-width: 520px; }
.permission-panel { padding: 0; overflow: hidden; }
.permission-panel .panel-heading { padding: 26px 26px 0; }
.permission-table-wrap { width: 100%; overflow-x: auto; }
.permission-table { width: 100%; border-collapse: collapse; min-width: 900px; }
.permission-table th, .permission-table td { padding: 18px; border-top: 1px solid var(--border); border-right: 1px solid var(--border); vertical-align: middle; }
.permission-table th:last-child, .permission-table td:last-child { border-right: 0; }
.permission-table th { min-width: 180px; background: var(--surface-soft); text-align: left; }
.permission-table th:first-child { min-width: 170px; }
.permission-table th strong { display: block; font-size: .8rem; }
.permission-table th small { display: block; margin-top: 5px; color: var(--muted); font-size: .68rem; font-weight: 500; line-height: 1.35; }
.permission-check-cell { text-align: center; }
.permission-check { width: 40px; height: 40px; display: inline-grid; place-items: center; margin: 0; cursor: pointer; }
.permission-check input { position: absolute; opacity: 0; pointer-events: none; }
.permission-check span { width: 32px; height: 32px; display: grid; place-items: center; border: 1px solid #cbd5d1; border-radius: 9px; color: transparent; background: #fff; font-weight: 900; transition: .15s ease; }
.permission-check input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.permission-check input:disabled + span { opacity: .55; cursor: not-allowed; }
.permission-lock-note { display: block; margin-top: 7px; color: var(--muted); font-size: .68rem; }
.permission-note { margin: 22px 26px 0; padding: 14px 16px; display: grid; gap: 4px; border: 1px solid var(--border); border-radius: 11px; background: var(--surface-soft); }
.permission-note strong { font-size: .78rem; }
.permission-note span { color: var(--muted); font-size: .76rem; line-height: 1.45; }
.permission-panel .form-actions { padding: 22px 26px 26px; }
.muted-action { color: var(--muted); font-size: .75rem; }


/* STEP 1.4 — piani, sottoscrizioni e feature tenant */
.feature-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.feature-option { position: relative; display: block; margin: 0; cursor: pointer; }
.feature-option input { position: absolute; opacity: 0; pointer-events: none; }
.feature-option-copy { min-height: 118px; display: grid; align-content: start; gap: 6px; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-soft); transition: .15s ease; }
.feature-option-copy strong { font-size: .9rem; }
.feature-option-copy small { color: var(--muted); font-size: .76rem; line-height: 1.45; }
.feature-option-copy code { width: fit-content; padding: 4px 7px; border-radius: 6px; background: #fff; color: #52625d; font-size: .68rem; }
.feature-option input:checked + .feature-option-copy { border-color: #6d9c8e; box-shadow: 0 0 0 3px rgba(28,103,88,.08); background: #edf7f3; }
.feature-override-list { display: grid; gap: 10px; }
.feature-override-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(210px, 280px); gap: 18px; align-items: center; padding: 16px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-soft); }
.feature-override-copy { display: grid; gap: 5px; }
.feature-override-copy strong { font-size: .9rem; }
.feature-override-copy span { color: var(--muted); font-size: .76rem; line-height: 1.45; }
.feature-override-copy small { color: #53615d; font-size: .72rem; }
.feature-override-control select { margin: 0; }

@media (max-width: 720px) {
    .feature-grid { grid-template-columns: 1fr; }
    .feature-override-row { grid-template-columns: 1fr; }
}

/* STEP 1.5 - user invitations */
.alert-warning { background: #fff7e6; border: 1px solid #f0d39a; color: #6b4b0b; }
.info-box { padding: 16px 18px; border: 1px solid var(--border); border-radius: 12px; background: #f8faf9; }
.info-box p { margin: 6px 0 0; }

/* STEP 1.6 - Usage & limits */
.usage-tenant-list {
    display: grid;
    gap: 1.25rem;
}

.usage-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
}

.usage-card {
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 14px;
    padding: 1rem;
    background: #fff;
}

.usage-card-heading,
.usage-value {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: baseline;
}

.usage-card-heading span,
.usage-card small {
    color: #6b7280;
}

.usage-value {
    margin: .85rem 0 .6rem;
}

.usage-value strong {
    font-size: 1.65rem;
}

.usage-progress {
    height: 8px;
    overflow: hidden;
    border-radius: 999px;
    background: #e5e7eb;
    margin-bottom: .55rem;
}

.usage-progress > span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: currentColor;
}
