
:root {
    --sidebar-width: 256px;
    --header-height: 80px;
    --loading-spinner-size: 24px;
    --brand-primary: #ffcc33;
    --brand-primary-strong: #e6b800;
    --brand-primary-soft: #ffe066;
    --brand-secondary: #0d0d0d;
    --brand-secondary-soft: #1a1a1a;
    --carbon-950: #0d0d0d;
    --carbon-900: #141414;
    --carbon-800: #1d1d1d;
    --steel-700: #3d3d3d;
    --steel-600: #6b6b6b;
    --stone-200: #d9dce1;
    --stone-300: #d9dce1;
    --pearl-50: #fdfdfe;
    --pearl-100: #f3f3f3;
    --pearl-200: #e8eaed;
    --white: #ffffff;
    --text-primary: #0d0d0d;
    --text-secondary: #5c5c5c;
    --text-on-dark: rgba(255, 255, 255, 0.92);
    --border-soft: rgba(0, 0, 0, 0.1);
    --border-strong: rgba(0, 0, 0, 0.16);
    --surface-base: rgba(255, 255, 255, 0.9);
    --surface-raised: linear-gradient(180deg, rgba(255, 255, 255, 0.98) 0%, rgba(243, 243, 243, 0.98) 100%);
    --surface-muted: linear-gradient(180deg, rgba(250, 250, 251, 0.98) 0%, rgba(238, 238, 238, 0.98) 100%);
    --surface-dark: linear-gradient(180deg, rgba(20, 20, 20, 0.98) 0%, rgba(0, 0, 0, 1) 100%);
    --shadow-soft: 0 16px 34px rgba(0, 0, 0, 0.08);
    --shadow-card: 0 20px 48px rgba(0, 0, 0, 0.12);
    --shadow-strong: 0 28px 64px rgba(0, 0, 0, 0.18);
    --ring-accent: 0 0 0 4px rgba(255, 204, 51, 0.22);
    --primary-color: var(--brand-primary);
    --sidebar-bg: linear-gradient(180deg, #161616 0%, #0a0a0a 100%);
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
    color-scheme: dark;
    accent-color: var(--brand-primary);
}

body {
    font-family: NouvelR, 'Helvetica Neue', Arial, sans-serif;
    color: var(--text-primary);
    background-color: var(--pearl-50);
    background-image:
        radial-gradient(circle at top right, rgba(255, 204, 51, 0.10), transparent 28%),
        radial-gradient(circle at bottom left, rgba(23, 23, 23, 0.08), transparent 32%),
        linear-gradient(180deg, #fdfdfe 0%, #f3f4f6 100%);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    line-height: 1.55;
}

/* Dark premium shell: login, wall, dashboard, admin, org, reports */
body.pc-shell {
    min-height: 100vh;
    background-color: #0d0d0d;
    background-image:
        radial-gradient(circle at top right, rgba(255, 204, 51, 0.08), transparent 24%),
        linear-gradient(180deg, #0d0d0d 0%, #151515 100%);
    color: #f8fafc;
    color-scheme: dark;
}

::selection {
    background: rgba(255, 204, 51, 0.30);
    color: var(--carbon-950);
}

h1,
h2,
h3,
h4,
h5,
h6,
.table-title,
.panel-title,
.modal-title {
    font-family: NouvelR, 'Helvetica Neue', Arial, sans-serif;
    letter-spacing: 0.02em;
    color: var(--carbon-950);
    line-height: 1.05;
}

p,
li,
label,
small,
span {
    letter-spacing: 0.01em;
}

a {
    color: var(--brand-primary);
    text-decoration-color: rgba(255, 204, 51, 0.35);
    transition: color 180ms ease, text-decoration-color 180ms ease;
}

a:hover {
    color: var(--brand-primary-strong);
    text-decoration-color: rgba(230, 184, 0, 0.60);
}

img, video {
    max-width: 100%;
    height: auto;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
}

table {
    border-collapse: collapse;
    width: 100%;
}

hr {
    border: 0;
    border-top: 1px solid var(--border-soft);
}

::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

::-webkit-scrollbar-track {
    background: rgba(23, 23, 23, 0.08);
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(61, 61, 61, 0.85) 0%, rgba(23, 23, 23, 0.9) 100%);
    border-radius: 999px;
    border: 2px solid rgba(255, 255, 255, 0.45);
}

.skip-to-content {
    position: absolute;
    left: -9999px;
    z-index: 9999;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-strong) 100%);
    color: #17150a;
    text-decoration: none;
    border-radius: 0 0 1rem 0;
    box-shadow: var(--shadow-strong);
}

.skip-to-content:focus {
    left: 0;
    top: 0;
    outline: 2px solid white;
    outline-offset: 2px;
}

.loading-spinner {
    display: inline-block;
    width: var(--loading-spinner-size);
    height: var(--loading-spinner-size);
    border: 3px solid rgba(255, 204, 51, 0.22);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(253, 253, 254, 0.78);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    backdrop-filter: blur(6px);
}

.btn-loading {
    position: relative;
    color: transparent !important;
    pointer-events: none;
}

.btn-loading::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin: -8px 0 0 -8px;
    border: 2px solid rgba(255, 255, 255, 0.28);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.pull-to-refresh {
    position: fixed;
    top: 0;
    left: 50%;
    transform: translateX(-50%) translateY(-100%);
    background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-strong) 100%);
    color: #17150a;
    padding: 0.7rem 1.1rem;
    border-radius: 0 0 1.1rem 1.1rem;
    box-shadow: var(--shadow-card);
    z-index: 9999;
    transition: transform 0.3s ease;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
    font-weight: 600;
    letter-spacing: 0.03em;
}

.pull-to-refresh.active,
.pull-to-refresh.pulling {
    transform: translateX(-50%) translateY(0);
}

.sidebar-gradient {
    position: fixed;
    top: 0;
    left: 0;
    background: linear-gradient(180deg, rgba(21, 21, 21, 0.98) 0%, rgba(10, 10, 10, 1) 100%) !important;
    color: var(--text-on-dark);
    box-shadow: 24px 0 48px rgba(8, 10, 13, 0.22);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-gradient::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: linear-gradient(180deg, var(--brand-primary) 0%, rgba(255, 204, 51, 0.25) 100%);
}

.sidebar-gradient a {
    color: rgba(255, 255, 255, 0.82);
}

.sidebar-gradient a:hover,
.sidebar-gradient a:focus-visible {
    color: #ffffff;
}

/* --- Sidebar shell condivisa (dashboard.php e pagine sezione come Clienti) --- */
.mobile-header {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 64px;
    background: rgba(16, 16, 16, 0.92);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid rgba(255,255,255,0.08);
    z-index: 998;
    padding: 0 1rem;
    align-items: center;
    justify-content: space-between;
}
.header-mobile-actions { display: none; }
.sidebar-account-card {
    border-radius: 1.25rem;
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.04);
    padding: 0.5rem;
}
.sidebar-footer-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    border-radius: 1rem;
    padding: 0.8rem 0.9rem;
}
.pc-brand-lockup {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.pc-brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.85rem;
    font-family: NouvelR, 'Helvetica Neue', Arial, sans-serif;
    font-weight: 700;
    font-size: 1.35rem;
    line-height: 1;
    color: #17150a;
    background:
        linear-gradient(145deg, rgba(255,255,255,0.16), transparent 34%),
        linear-gradient(135deg, #ffcc33 0%, #e6b800 100%);
    box-shadow: 0 14px 30px rgba(255, 204, 51, 0.26);
}
/* Sidebar come colonna flex: brand compatto, menu che scrolla nel proprio
   spazio, footer in flusso. Nessuna geometria assoluta ne' altezze magiche:
   il footer non puo' sovrapporsi al menu a nessuna altezza di finestra/zoom. */
.sidebar-gradient {
    display: flex;
    flex-direction: column;
}
.sidebar-gradient nav {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: thin;
    padding-right: 2px;
    padding-bottom: 0.5rem;
}
.sidebar-gradient .sidebar-footer {
    flex: 0 0 auto;
    margin-top: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: 1rem;
}
.sidebar-gradient .pc-nav-chip {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.7rem 0.9rem;
    border-radius: 1rem;
    border: 1px solid transparent;
    color: rgba(255,255,255,0.82);
    font-size: 0.95rem;
    font-weight: 500;
    transition: background-color 0.18s ease, border-color 0.18s ease, color 0.18s ease;
}
.sidebar-gradient .pc-nav-chip svg {
    flex: 0 0 auto;
}
.sidebar-gradient .pc-nav-chip:hover,
.sidebar-gradient .pc-nav-chip:focus-visible {
    background: rgba(255,255,255,0.07);
    border-color: rgba(255,255,255,0.1);
    color: #fff;
}
.sidebar-gradient .pc-nav-chip.is-active {
    background: linear-gradient(90deg, rgba(255, 204, 51, 0.26), rgba(255, 204, 51, 0.06));
    border-color: rgba(255, 204, 51, 0.38);
    color: #fff;
    font-weight: 600;
    box-shadow: inset 2px 0 0 rgba(255, 204, 51, 0.95), inset 0 1px 0 rgba(255,255,255,0.05);
}

/* --- Paginazione condivisa (includes/Paginator.php) --- */
.pc-pager {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(255,255,255,0.06);
}
.pc-pager-info {
    font-size: 0.78rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #9aa6b7;
}
.pc-pager-controls {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.4rem;
}
.pc-pager-btn,
.pc-pager-page {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.2rem;
    min-height: 2.2rem;
    padding: 0.35rem 0.7rem;
    border-radius: 0.7rem;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.05);
    color: #e5edf8;
    font-size: 0.82rem;
    font-weight: 600;
    text-decoration: none;
    transition: background-color 0.18s ease, border-color 0.18s ease;
}
.pc-pager-btn:hover,
.pc-pager-page:hover {
    background: rgba(255,255,255,0.12);
    color: #fff;
}
.pc-pager-page.is-current {
    background: linear-gradient(135deg, #ffcc33, #e6b800);
    border-color: rgba(255, 204, 51, 0.5);
    color: #17150a;
    cursor: default;
}
.pc-pager-gap {
    color: #6f7d90;
    padding: 0 0.15rem;
}
.pc-pager-per {
    margin-left: 0.5rem;
    min-height: 2.2rem;
    padding: 0.35rem 0.6rem;
    border-radius: 0.7rem;
    border: 1px solid rgba(255,255,255,0.1);
    background: #1c1c1c;
    color: #e5edf8;
    font-size: 0.82rem;
}

.sidebar-close-btn {
    display: none;
    position: absolute;
    top: 1rem;
    right: 1rem;
    width: 36px;
    height: 36px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: white;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, border-color 0.2s ease, transform 0.2s ease;
    box-shadow: none;
}

.sidebar-close-btn:hover {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.18);
    transform: translateY(-1px);
}

.sidebar-gradient .sidebar-close-btn {
    display: flex;
}

.mobile-header {
    background: rgba(18, 18, 18, 0.92) !important;
    color: var(--text-on-dark);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 12px 32px rgba(8, 10, 13, 0.18);
}

.main-content {
    color: var(--text-primary);
}

.glass-card,
.kpi-card,
.card-adaptive,
.skeleton-card,
.skeleton-stat-card,
.modal-fullscreen-mobile,
.toast-notification,
:where(.bg-white.rounded-xl),
:where(.bg-white.rounded-2xl),
:where(.bg-white.rounded-lg) {
    background: var(--surface-raised);
    border: 1px solid var(--border-soft);
    box-shadow: var(--shadow-card);
}

/* Table wrappers own border/shadow only: the light plate is overridden/dead in the dark shell */
.table-container {
    border: 1px solid var(--border-soft);
    box-shadow: var(--shadow-card);
}

/* Table wrappers must not paint a light plate inside dark shell panels */
body.pc-shell .table-container {
    background: transparent;
    border-color: rgba(255, 255, 255, 0.08);
}

.glass-card,
.kpi-card,
.card-adaptive,
.skeleton-card,
.skeleton-stat-card,
:where(.bg-white.rounded-xl),
:where(.bg-white.rounded-2xl),
:where(.bg-white.rounded-lg) {
    border-radius: 1.1rem;
}

.glass-card {
    position: relative;
    overflow: hidden;
}

.glass-card::after,
.kpi-card::after {
    content: '';
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.75) 0%, rgba(255, 255, 255, 0) 100%);
    pointer-events: none;
}

.kpi-card {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.table-container {
    overflow: hidden;
    border-radius: 1.15rem;
}

.table-container table,
table {
    background: transparent;
}

thead th {
    font-family: NouvelR, 'Helvetica Neue', Arial, sans-serif;
    font-size: 0.84rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.09em;
    padding: 1rem 1.1rem;
    background: linear-gradient(180deg, rgba(19, 22, 27, 0.94) 0%, rgba(29, 29, 29, 0.94) 100%);
    color: rgba(255, 255, 255, 0.86);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

tbody td {
    padding: 1rem 1.1rem;
    border-bottom: 1px solid rgba(21, 21, 21, 0.08);
}

tbody tr {
    transition: background-color 180ms ease, transform 180ms ease, box-shadow 180ms ease;
}

/* Dark-friendly rows inside the premium shell */
body.pc-shell tbody td {
    color: var(--text-on-dark);
    border-bottom-color: rgba(255, 255, 255, 0.07);
}

body.pc-shell tbody tr {
    background: transparent;
}

body.pc-shell tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.03);
}

body.pc-shell tbody tr:hover {
    background: rgba(255, 255, 255, 0.06);
}

button:not(:where([class*="absolute"], [class*="text-left"], [class*="text-xs"])),
.btn,
.btn-primary,
.btn-secondary,
.btn-outline,
a[role="button"],
input[type="submit"],
input[type="button"] {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.625rem;
    min-height: 44px;
    padding: 0.8rem 1.2rem;
    border-radius: 999px;
    border: 1px solid transparent;
    font-weight: 600;
    letter-spacing: 0.02em;
    transition: transform 180ms ease, box-shadow 180ms ease, background-color 180ms ease, border-color 180ms ease, color 180ms ease;
    box-shadow: 0 12px 28px rgba(17, 17, 17, 0.14);
}

button:not(:where([class*="absolute"], [class*="text-left"], [class*="text-xs"])),
.btn,
.btn-secondary,
input[type="submit"],
input[type="button"] {
    background: linear-gradient(180deg, #1f1f1f 0%, #141414 100%);
    color: var(--white);
}

.btn-primary,
.btn-accent {
    background: linear-gradient(135deg, var(--brand-primary) 0%, var(--brand-primary-strong) 100%);
    color: #17150a;
}

.btn-danger,
button.bg-red-600,
a.bg-red-600 {
    background: linear-gradient(135deg, #ff5d68 0%, #d63c47 100%);
    color: var(--white);
}

.btn-outline,
.btn-secondary.bg-white,
button.bg-white {
    background: rgba(255, 255, 255, 0.82);
    color: var(--carbon-950);
    border-color: rgba(21, 21, 21, 0.12);
    box-shadow: var(--shadow-soft);
}

button:not(:where([class*="absolute"], [class*="text-left"], [class*="text-xs"])):hover,
.btn:hover,
.btn-primary:hover,
.btn-secondary:hover,
.btn-outline:hover,
a[role="button"]:hover,
input[type="submit"]:hover,
input[type="button"]:hover {
    transform: translateY(-1px);
    box-shadow: 0 18px 34px rgba(17, 17, 17, 0.18);
}

button:not(:where([class*="absolute"], [class*="text-left"], [class*="text-xs"])):disabled,
.btn:disabled,
.btn-primary:disabled,
.btn-secondary:disabled,
.btn-outline:disabled,
input[type="submit"]:disabled,
input[type="button"]:disabled {
    opacity: 0.58;
    cursor: not-allowed;
    pointer-events: none;
    transform: none;
    box-shadow: var(--shadow-soft);
}

button:focus-visible,
.btn:focus-visible,
a[role="button"]:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.focus-visible-ring:focus-visible {
    outline: none;
    box-shadow: var(--ring-accent);
}

label {
    display: inline-block;
    margin-bottom: 0.45rem;
    color: var(--text-primary);
    font-weight: 600;
}

input:not([type='checkbox']):not([type='radio']):not([type='range']),
select,
textarea {
    min-height: 46px;
    border-radius: 0.95rem;
    border: 1px solid rgba(21, 21, 21, 0.12);
    background: rgba(255, 255, 255, 0.92);
    color: var(--text-primary);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65), 0 8px 24px rgba(17, 17, 17, 0.05);
    transition: border-color 180ms ease, box-shadow 180ms ease, background-color 180ms ease;
}

input::placeholder,
textarea::placeholder {
    color: #8b949f;
}

input:not([type='checkbox']):not([type='radio']):not([type='range']):focus,
select:focus,
textarea:focus {
    border-color: rgba(255, 204, 51, 0.4);
    box-shadow: var(--ring-accent);
}

/* Dark form controls inside the premium shell (focus ring stays as defined above) */
body.pc-shell input:not([type='checkbox']):not([type='radio']):not([type='range']):not(:focus),
body.pc-shell select:not(:focus),
body.pc-shell textarea:not(:focus) {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.08);
    color: #f8fafc;
    box-shadow: none;
}

body.pc-shell input:not([type='checkbox']):not([type='radio']):not([type='range']):focus,
body.pc-shell select:focus,
body.pc-shell textarea:focus {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 204, 51, 0.4);
    color: #f8fafc;
}

/* Badges/pills: this block owns the SHAPE only. Forcing color/background here
   used to flatten every variant (success/danger/warning/muted/purple) into the
   same red tint at ~2.1:1 contrast on the dark shell. */
.badge,
.status-badge,
.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    min-height: 32px;
    padding: 0.32rem 0.8rem;
    border-radius: 999px;
    border: 1px solid transparent;
    font-weight: 600;
    letter-spacing: 0.02em;
}

/* Neutral default inside the dark premium shell */
body.pc-shell .badge,
body.pc-shell .status-badge,
body.pc-shell .status-pill {
    background: rgba(148, 163, 184, 0.14);
    color: #dbe3ef;
    border-color: rgba(148, 163, 184, 0.18);
}

/* Semantic variants for the dark shell. Scoped with body.pc-shell so they
   win over per-page inline <style> blocks regardless of stylesheet order.
   Every color below stays >= 9:1 on the carbon surface (#1c1c1c). */
body.pc-shell .badge-muted,
body.pc-shell .badge-neutral {
    background: rgba(148, 163, 184, 0.14);
    color: #dbe3ef;
    border-color: rgba(148, 163, 184, 0.18);
}

body.pc-shell .badge-success {
    background: rgba(34, 197, 94, 0.16);
    color: #9ef0b8;
    border-color: rgba(34, 197, 94, 0.24);
}

body.pc-shell .badge-danger {
    background: rgba(255, 93, 104, 0.16);
    color: #ffb4be;
    border-color: rgba(255, 93, 104, 0.24);
}

body.pc-shell .badge-warning {
    background: rgba(240, 173, 44, 0.16);
    color: #ffd58a;
    border-color: rgba(240, 173, 44, 0.24);
}

body.pc-shell .badge-info {
    background: rgba(0, 72, 254, 0.16);
    color: #a9d0ff;
    border-color: rgba(0, 72, 254, 0.24);
}

body.pc-shell .badge-purple {
    background: rgba(168, 85, 247, 0.16);
    color: #d7b5ff;
    border-color: rgba(168, 85, 247, 0.24);
}

body.pc-shell .badge-indigo {
    background: rgba(99, 102, 241, 0.16);
    color: #c4c7ff;
    border-color: rgba(99, 102, 241, 0.24);
}

.live-region,
.aria-live-region {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.focus-trap {
    position: fixed;
    inset: 0;
    z-index: 9998;
}

@keyframes slideInUp {
    from {
        transform: translateY(100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes slideOutRight {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

@keyframes progressShrink {
    from { width: 100%; }
    to { width: 0%; }
}

.toast-container {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast-container > * {
    pointer-events: auto;
}

.toast-notification {
    position: relative;
    padding: 1rem 1rem 1.4rem;
    border-radius: 1rem;
    box-shadow: 0 20px 44px rgba(8, 10, 13, 0.24);
    max-width: 390px;
    min-width: 300px;
    display: flex;
    align-items: flex-start;
    gap: 0.875rem;
    animation: slideInUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    background: linear-gradient(180deg, rgba(20, 20, 20, 0.98) 0%, rgba(10, 10, 10, 0.98) 100%);
    color: white;
    border: 1px solid rgba(255, 255, 255, 0.08);
    overflow: hidden;
}

.toast-notification::before {
    content: '';
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--brand-primary);
}

.toast-notification.hiding {
    animation: slideOutRight 0.3s ease forwards;
}

.toast-icon {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.12);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08);
}

.toast-body {
    flex: 1;
    min-width: 0;
}

.toast-title {
    font-weight: 700;
    font-size: 0.95rem;
    margin-bottom: 0.15rem;
    letter-spacing: 0.02em;
}

.toast-message {
    font-size: 0.875rem;
    opacity: 0.95;
    line-height: 1.5;
    color: rgba(255, 255, 255, 0.92);
}

.toast-dismiss {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border: 1px solid transparent;
    background: transparent;
    color: inherit;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s ease, background 0.2s ease, border-color 0.2s ease;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 0.5rem;
    box-shadow: none;
}

.toast-dismiss:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.1);
}

.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: rgba(255, 255, 255, 0.22);
    border-radius: 0 0 1rem 1rem;
    animation: progressShrink var(--toast-duration, 4000ms) linear forwards;
}

.toast-notification.success::before {
    background: #2ac17b;
}

.toast-notification.error::before {
    background: #ff5d68;
}

.toast-notification.info::before {
    background: #5c8bff;
}

.toast-notification.warning::before {
    background: #f0ad2c;
}

.skeleton {
    background: linear-gradient(90deg, #eee7df 20%, #f9f6f2 50%, #e9e1d8 80%);
    background-size: 200% 100%;
    animation: skeleton-shimmer 1.5s ease-in-out infinite;
    border-radius: 0.5rem;
}

@keyframes skeleton-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-text {
    height: 0.875rem;
    margin-bottom: 0.5rem;
}

.skeleton-text-sm {
    height: 0.75rem;
}

.skeleton-text-lg {
    height: 1.25rem;
}

.skeleton-text-xl {
    height: 1.5rem;
}

.skeleton-title {
    height: 1.75rem;
    width: 55%;
    margin-bottom: 0.75rem;
}

.skeleton-avatar {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    flex-shrink: 0;
}

.skeleton-avatar-sm {
    width: 2rem;
    height: 2rem;
}

.skeleton-avatar-lg {
    width: 3rem;
    height: 3rem;
}

.skeleton-button {
    height: 2.75rem;
    width: 7rem;
    border-radius: 999px;
}

.skeleton-card {
    padding: 1.25rem;
}

.skeleton-card-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid rgba(21, 21, 21, 0.08);
}

.skeleton-card-body {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.skeleton-table {
    width: 100%;
}

.skeleton-table-row {
    display: flex;
    align-items: center;
    padding: 1rem 0.75rem;
    border-bottom: 1px solid rgba(21, 21, 21, 0.06);
    gap: 1rem;
}

.skeleton-table-row > div {
    flex: 1;
}

.skeleton-line {
    height: 0.875rem;
    border-radius: 0.25rem;
}

.skeleton-line-sm {
    height: 0.75rem;
    width: 60%;
}

.skeleton-line-lg {
    height: 1rem;
}

.skeleton-badge {
    height: 1.5rem;
    width: 5rem;
    border-radius: 9999px;
}

.skeleton-chart {
    height: 280px;
    border-radius: 0.75rem;
}

.skeleton-stat-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
}

.skeleton-stat-card {
    padding: 1.25rem;
}

.skeleton-stat-icon {
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 0.6rem;
    margin-bottom: 0.75rem;
}

.skeleton-stat-value {
    height: 2rem;
    width: 50%;
    margin-bottom: 0.5rem;
}

.skeleton-stat-label {
    height: 0.875rem;
    width: 70%;
}

.loading-dots {
    display: inline-flex;
    gap: 3px;
    align-items: center;
}

.loading-dots span {
    width: 6px;
    height: 6px;
    background: currentColor;
    border-radius: 50%;
    animation: dot-bounce 1.4s ease-in-out infinite;
}

.loading-dots span:nth-child(1) { animation-delay: 0s; }
.loading-dots span:nth-child(2) { animation-delay: 0.15s; }
.loading-dots span:nth-child(3) { animation-delay: 0.3s; }

@keyframes dot-bounce {
    0%, 80%, 100% { transform: scale(0.7); opacity: 0.6; }
    40% { transform: scale(1); opacity: 1; }
}

.skeleton-inline {
    display: inline-block;
    vertical-align: middle;
}

.skeleton-circle {
    border-radius: 50%;
}

.skeleton-rounded {
    border-radius: 0.5rem;
}

@media (max-width: 1024px) {
    :root {
        --sidebar-width: 0px;
    }

    .sidebar-gradient {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 286px;
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        overflow-y: auto;
        overflow-x: hidden;
    }

    .sidebar-gradient.active {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(9, 11, 14, 0.58);
        backdrop-filter: blur(8px);
        z-index: 999;
        opacity: 0;
        transition: opacity 0.3s ease;
    }

    .sidebar-overlay.active {
        display: block;
        opacity: 1;
    }

    .main-content {
        margin-left: 0 !important;
        padding-top: 72px !important;
    }

    .mobile-header {
        display: flex !important;
    }

    .stats-grid,
    .stats-grid-3,
    .stats-grid-4,
    .grid-cols-2-responsive {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    }

    .mobile-full-width {
        width: 100% !important;
        margin-left: 0 !important;
    }
}

@media (max-width: 768px) {
    html {
        font-size: 14px;
    }

    .stats-grid,
    .stats-grid-3,
    .stats-grid-4 {
        grid-template-columns: 1fr !important;
    }

    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        position: relative;
    }

    /* Only wide DATA tables keep the horizontal scroll; tables rendered as
       cards (.mobile-card-view) must shrink to the container width. */
    .table-container table:not(.mobile-card-view) {
        min-width: 600px;
    }

    .mobile-card-view {
        display: block;
    }

    .mobile-card-view tbody {
        display: flex;
        flex-direction: column;
        gap: 1rem;
    }

    .mobile-card-view tr {
        display: flex;
        flex-direction: column;
        background: var(--surface-raised);
        border-radius: 1rem;
        padding: 1rem;
        box-shadow: var(--shadow-soft);
        border: 1px solid var(--border-soft);
        margin-bottom: 0.5rem;
    }

    body.pc-shell .mobile-card-view tr {
        background: rgba(255, 255, 255, 0.04);
        border-color: rgba(255, 255, 255, 0.08);
    }

    body.pc-shell .mobile-card-view td::before {
        color: rgba(255, 255, 255, 0.55);
    }

    .mobile-card-view td {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-start;
        justify-content: space-between;
        gap: 0.35rem 1rem;
        min-width: 0;
        padding: 0.6rem 0;
        border: none !important;
        text-align: right;
        overflow-wrap: anywhere;
        word-break: break-word;
    }

    .mobile-card-view td > * {
        min-width: 0;
        max-width: 100%;
    }

    .mobile-card-view td::before {
        content: attr(data-label);
        flex: 0 0 auto;
        font-family: NouvelR, 'Helvetica Neue', Arial, sans-serif;
        font-weight: 700;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        text-align: left;
        color: var(--steel-600);
    }

    .mobile-card-view td > .action-buttons {
        flex: 1 0 100%;
        flex-wrap: wrap;
        justify-content: flex-end;
        min-width: 0;
    }

    .mobile-card-view td > button {
        flex: 0 1 auto;
        min-width: 0;
    }

    .mobile-card-view thead {
        display: none;
    }

    .hide-on-mobile {
        display: none !important;
    }

    .form-grid-2-cols {
        grid-template-columns: 1fr !important;
    }

    .mobile-nav-tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
        scrollbar-width: none;
        gap: 0.75rem;
    }

    .mobile-nav-tabs::-webkit-scrollbar {
        display: none;
    }

    .mobile-nav-tabs > * {
        scroll-snap-align: start;
    }

    .skeleton-stat-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .glass-card {
        padding: 1.35rem !important;
    }

    .glass-card h1 {
        font-size: 1.55rem;
    }

    .login-container {
        padding: 1rem;
    }

    .btn-mobile-full {
        width: 100%;
    }

    .action-buttons {
        flex-direction: column;
        gap: 0.5rem;
    }

    .action-buttons button {
        width: 100%;
        justify-content: center;
    }

    /* Tailwind's space-x-* keeps a horizontal margin on the stacked siblings.
       With width:100% buttons that margin (0.5rem = 7px at the 14px mobile
       root font-size) pushed the last button past the cell content box. */
    .action-buttons > * {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }

    .header-actions {
        display: none;
    }

    .header-mobile-actions {
        display: flex !important;
    }

    .report-stats {
        grid-template-columns: 1fr !important;
    }

    .kpi-card {
        flex-direction: column;
        text-align: center;
        align-items: center;
    }

    .modal-fullscreen-mobile {
        max-width: 100% !important;
        margin: 0 !important;
        border-radius: 0 !important;
        min-height: 100vh !important;
        border-left: 0;
        border-right: 0;
    }

    .toast-container {
        left: 1rem;
        right: 1rem;
        bottom: 1rem;
    }

    .toast-notification {
        max-width: none;
        min-width: auto;
    }
}

@media (min-width: 1025px) {
    .mobile-header,
    .sidebar-overlay,
    .sidebar-close-btn {
        display: none !important;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .skeleton {
        animation: none;
        background: #e8e1d8;
    }

    .toast-notification,
    .toast-progress,
    .loading-dots span {
        animation: none;
    }

    .toast-progress {
        width: 0%;
    }

    .loading-dots span {
        opacity: 0.6;
    }
}

@media (hover: none) and (pointer: coarse) {
    button, a {
        min-height: 44px;
        min-width: 44px;
    }

    input, select, textarea {
        min-height: 44px;
    }
}

@container (max-width: 480px) {
    .card-adaptive {
        padding: 0.75rem;
    }

    .text-adaptive {
        font-size: 0.875rem;
    }
}

@media print {
    .sidebar-gradient,
    .mobile-header,
    .sidebar-overlay,
    .skip-to-content,
    .pull-to-refresh,
    .toast-container {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
}

@supports (container-type: inline-size) {
    .adaptive-grid {
        display: grid;
        gap: 1rem;
    }

    @container (min-width: 600px) {
        .adaptive-grid {
            grid-template-columns: repeat(2, 1fr);
        }
    }

    @container (min-width: 900px) {
        .adaptive-grid {
            grid-template-columns: repeat(3, 1fr);
        }
    }
}

/* Dialogo trascrizione a bolle stile chat (una voce a sinistra, l'altra a
   destra, parita' della voce; una rara terza voce torna a sinistra): usato
   dalla modale Trascrizioni della dashboard e dalle card Conversazioni
   Telefoniche di customers. I colori distinguono solo il LATO (sinistra
   neutra, destra tinta brand), non chi e' operatore e chi cliente: la
   diarizzazione non lo dice. */
.pc-chat {
    display: flex;
    flex-direction: column;
    gap: .4rem;
    white-space: normal;
}

.pc-bubble {
    max-width: 78%;
    padding: .45rem .7rem;
    border-radius: .9rem;
    line-height: 1.55;
    overflow-wrap: break-word;
}

/* Nella modale trascrizione le bolle fuori viewport non vengono renderizzate:
   trascrizioni lunghe (centinaia di bolle) pagano layout/paint solo del
   visibile. Solo qui: le card Conversazioni di customers restano eager
   (contesti piccoli, l'istima intrinsic-size sposterebbe il layout). */
.pc-modal-body .pc-bubble {
    content-visibility: auto;
    contain-intrinsic-size: auto 84px;
}

.pc-bubble.pc-left {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-bottom-left-radius: .3rem;
    color: #dbe3ee;
}

.pc-bubble.pc-right {
    align-self: flex-end;
    background: rgba(0, 72, 254, 0.2);
    border: 1px solid rgba(0, 72, 254, 0.45);
    border-bottom-right-radius: .3rem;
    color: #e8effb;
}

/* una battuta puo' contenere newline interni (parseSegments usa (.+?) col
   flag s): preservali */
.pc-bubble-text {
    white-space: pre-line;
}

/* Riassunto AI in cima al modale trascrizione: GIALLO brand saturo con
   testo scuro — netta separazione dalle bolle della conversazione
   (grigia a sinistra, blu a destra), nessuna tinta tenue che si confonda */
.pc-summary-box {
    margin: 0 0 1rem;
    padding: 0.7rem 0.95rem;
    border-radius: 0.75rem;
    background: rgba(255, 204, 51, 0.92);
    color: #17150a;
}

.pc-summary-box p {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.5;
}

.pc-summary-box strong {
    display: block;
    margin-bottom: 0.1rem;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: #6b5d00;
}

/* etichetta "Voce N" solo per screen reader, mai visibile */
.pc-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;
}
