/* ============================================================
   Design tokens
   ============================================================ */
:root {
    --primary:        #2563eb;
    --primary-h:      #1d4ed8;
    --primary-dark:   #1e3a8a;
    --primary-light:  #eff6ff;
    --danger:         #ef4444;
    --danger-h:       #dc2626;
    --danger-light:   #fef2f2;
    --success:        #22c55e;
    --success-h:      #16a34a;
    --success-light:  #f0fdf4;
    --warning:        #f59e0b;
    --warning-light:  #fffbeb;

    --bg:       #f1f5f9;
    --surface:  #ffffff;
    --surface-2:#f8fafc;

    --border:   #e2e8f0;
    --border-2: #cbd5e1;
    --text:     #0f172a;
    --text-2:   #475569;
    --muted:    #94a3b8;

    --radius:    8px;
    --radius-sm: 5px;
    --radius-lg: 14px;

    --shadow-xs: 0 1px 2px rgba(0,0,0,.06);
    --shadow-sm: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px -1px rgba(0,0,0,.08);
    --shadow:    0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.06);
    --shadow-lg: 0 12px 24px -4px rgba(0,0,0,.12), 0 4px 8px -2px rgba(0,0,0,.06);

    --navbar-h:   54px;
    --groupbar-h: 44px;
}

/* ============================================================
   Reset & base
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    min-height: 100%;
}

.hidden { display: none !important; }

/* ============================================================
   Login
   ============================================================ */
#page-login {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    background:
        radial-gradient(ellipse at 20% 30%, rgba(37,99,235,.12) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 70%, rgba(99,102,241,.08) 0%, transparent 60%),
        var(--bg);
}

.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.75rem 2.25rem;
    width: 100%;
    max-width: 390px;
}

.login-brand {
    text-align: center;
    margin-bottom: 2rem;
}

.login-brand img {
    display: block;
    margin: 0 auto .75rem;
    max-height: 72px;
    max-width: 200px;
    object-fit: contain;
}

.login-brand h1 {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -.03em;
    margin: 0;
}

/* ============================================================
   Forms (shared)
   ============================================================ */
form label {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 1rem;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-2);
}

form input,
form select,
form textarea {
    padding: .5rem .75rem;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    transition: border-color .15s, box-shadow .15s;
    line-height: 1.5;
    font-family: inherit;
}

form input:focus,
form select:focus,
form textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.13);
}

form input[type=file] {
    padding: .4rem .6rem;
    border-style: dashed;
    background: var(--bg);
    cursor: pointer;
    color: var(--text-2);
}

form input[type=number] { appearance: textfield; }

.form-row {
    display: flex;
    gap: .75rem;
    margin-bottom: 0;
}
.form-row > label { margin-bottom: 1rem; flex: 1; }

.form-actions {
    display: flex;
    gap: .5rem;
    margin-top: 1.25rem;
    justify-content: flex-end;
    align-items: center;
}

.field-hint  { font-size: 11.5px; color: var(--muted); font-weight: 400; margin-top: 1px; }
.error-msg   { color: var(--danger);  font-size: 12px; font-weight: 500; margin-top: .4rem; }
.status-msg  { font-size: 13px; margin-top: .6rem; min-height: 1.2em; }
.status-msg.ok  { color: var(--success-h); font-weight: 500; }
.status-msg.err { color: var(--danger);    font-weight: 500; }

/* ============================================================
   Buttons
   ============================================================ */
button {
    cursor: pointer;
    border: none;
    border-radius: var(--radius-sm);
    padding: .45rem 1rem;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    font-family: inherit;
    transition: background .15s, box-shadow .12s, transform .1s, color .15s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .3rem;
}

button:disabled {
    opacity: .55;
    cursor: not-allowed;
}

/* Primary */
.btn-primary {
    background: var(--primary);
    color: #fff;
    box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255,255,255,.1);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-h);
    box-shadow: var(--shadow-sm);
}
.btn-primary:active:not(:disabled) {
    transform: translateY(1px);
    box-shadow: none;
}

/* Danger */
.btn-danger {
    background: var(--danger);
    color: #fff;
}
.btn-danger:hover:not(:disabled) { background: var(--danger-h); }

/* Small */
.btn-sm { padding: .25rem .65rem; font-size: 12px; }

/* Icon (calendar prev/next) */
.btn-icon {
    background: var(--surface);
    border: 1px solid var(--border-2);
    color: var(--text-2);
    font-size: 1.3rem;
    padding: .2rem .6rem;
    line-height: 1.2;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }

/* Default (secondary) */
button:not(.btn-primary):not(.btn-danger):not(.btn-icon):not(.modal-close):not(#btn-logout):not(.nav-btn):not(.settings-tab):not(.nav-toggle) {
    background: var(--surface);
    border: 1px solid var(--border-2);
    color: var(--text-2);
}
button:not(.btn-primary):not(.btn-danger):not(.btn-icon):not(.modal-close):not(#btn-logout):not(.nav-btn):not(.settings-tab):not(.nav-toggle):hover:not(:disabled) {
    background: var(--surface-2);
    color: var(--text);
}

/* ============================================================
   APP SHELL — full-height flex layout
   ============================================================ */
#page-app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* ============================================================
   Navbar
   ============================================================ */
.navbar {
    height: var(--navbar-h);
    display: flex;
    align-items: center;
    padding: 0 1rem 0 1.25rem;
    gap: .25rem;
    background: var(--primary);
    flex-shrink: 0;
    z-index: 50;
    position: relative;
    box-shadow: 0 2px 6px rgba(0,0,0,.18);
}

.navbar-brand-area {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-shrink: 0;
}

.navbar-logo {
    height: 28px;
    width: auto;
    max-width: 100px;
    object-fit: contain;
    border-radius: 4px;
}

.navbar-brand {
    font-weight: 700;
    font-size: .95rem;
    color: #fff;
    letter-spacing: -.02em;
    white-space: nowrap;
}

/* Vertical separator */
.navbar-sep {
    width: 1px;
    height: 22px;
    background: rgba(255,255,255,.22);
    margin: 0 .5rem;
    flex-shrink: 0;
}

.navbar-links {
    display: flex;
    gap: .1rem;
    flex: 1;
    align-items: center;
    overflow: hidden;
}

.nav-btn {
    background: transparent;
    color: rgba(255,255,255,.72);
    border: none;
    padding: .38rem .75rem;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
}
.nav-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.nav-btn.active {
    background: rgba(255,255,255,.18);
    color: #fff;
    font-weight: 600;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: .6rem;
    margin-left: auto;
    flex-shrink: 0;
}

#navbar-username {
    font-size: 12px;
    color: rgba(255,255,255,.75);
    font-weight: 500;
    white-space: nowrap;
}

#btn-logout {
    background: rgba(255,255,255,.1);
    color: rgba(255,255,255,.88);
    border: 1px solid rgba(255,255,255,.22);
    padding: .28rem .7rem;
    font-size: 12px;
    border-radius: var(--radius-sm);
}
#btn-logout:hover { background: rgba(255,255,255,.2); color: #fff; }

/* Hamburger button (hidden on desktop) */
.nav-toggle {
    display: none;
    flex-direction: column;
    justify-content: space-between;
    align-items: stretch;   /* annulla il "align-items:center" del reset button */
    gap: 0;                 /* annulla il "gap:.3rem" del reset button */
    width: 32px;
    height: 32px;
    padding: 7px 4px;
    background: rgba(255,255,255,.1);
    border: 1px solid rgba(255,255,255,.18);
    border-radius: var(--radius-sm);
    cursor: pointer;
    flex-shrink: 0;
    margin-right: .25rem;
}

.nav-toggle span {
    display: block;
    width: 100%;            /* occupa tutta la larghezza del bottone */
    height: 2px;
    background: rgba(255,255,255,.95);
    border-radius: 2px;
    transition: transform .22s ease, opacity .18s ease;
    transform-origin: center;
    flex-shrink: 0;
}

/* Hamburger → X animation
   Le tre linee sono separabili di ~7px (padding 7px, area utile 18px → gap ~8px).
   translateY di 8px le sovrappone per formare la X. */
#page-app.nav-open .nav-toggle span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
#page-app.nav-open .nav-toggle span:nth-child(2) { opacity: 0; transform: scaleX(0); }
#page-app.nav-open .nav-toggle span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }

/* ============================================================
   Group selector bar
   ============================================================ */
.tenant-bar {
    height: var(--groupbar-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    gap: .75rem;
    flex-shrink: 0;
    box-shadow: 0 1px 0 rgba(0,0,0,.04);
}

.tenant-bar label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: .6rem;
    margin: 0;
    font-weight: 600;
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .04em;
    white-space: nowrap;
}

.tenant-bar select {
    min-width: 180px;
    max-width: 300px;
    padding: .32rem .65rem;
    font-size: 13px;
    font-weight: 500;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--text);
    margin: 0;
    cursor: pointer;
    transition: border-color .15s, box-shadow .15s;
}
.tenant-bar select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}

/* ============================================================
   Views wrapper — fills remaining height
   ============================================================ */
.views-wrap {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
}

/* Every view fills the wrap absolutely */
.view {
    position: absolute;
    inset: 0;
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--bg);
}

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    flex-shrink: 0;
}

.view-header h2,
h2.view-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.02em;
}

h2.view-title {
    margin-bottom: 1.25rem;
}

.view-hint {
    font-size: 12.5px;
    color: var(--muted);
    margin-bottom: 1rem;
    line-height: 1.5;
}

/* ============================================================
   Calendar view — special: fills viewport, no page scroll
   ============================================================ */
#view-calendar {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    padding: .625rem .875rem;
    gap: .5rem;
}

.calendar-header {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-shrink: 0;
}

.calendar-header h2 {
    flex: 1;
    text-align: center;
    font-size: .95rem;
    font-weight: 600;
    color: var(--text);
    text-transform: capitalize;
    letter-spacing: -.01em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#calendar-grid {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow-xs);
}

/* ============================================================
   Calendar view toggle (Settimana / Mese)
   ============================================================ */
.cal-view-toggle {
    display: flex;
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    overflow: hidden;
    flex-shrink: 0;
}

.cal-mode-btn {
    background: var(--surface);
    border: none;
    border-radius: 0;
    color: var(--text-2);
    padding: .3rem .75rem;
    font-size: 12px;
    font-weight: 500;
    border-right: 1px solid var(--border-2);
    transition: background .15s, color .15s;
}
.cal-mode-btn:last-child { border-right: none; }
.cal-mode-btn:hover { background: var(--bg); color: var(--text); }
.cal-mode-btn.active {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
}

/* ============================================================
   Weekly Calendar (wcal-*) — height driven by flex
   ============================================================ */
.wcal-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    user-select: none;
}

/* Day headers */
.wcal-header {
    display: flex;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

.wcal-gutter-head {
    flex-shrink: 0;
    width: 52px;
    border-right: 1px solid var(--border);
}

.wcal-day-headers { display: flex; flex: 1; }

.wcal-day-head {
    flex: 1;
    text-align: center;
    padding: .4rem .2rem .35rem;
    border-right: 1px solid var(--border);
    min-width: 0;
    transition: background .15s;
}
.wcal-day-head:last-child { border-right: none; }
.wcal-day-head.today { background: var(--primary-light); }

.wcal-wday {
    display: block;
    font-size: 9.5px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--muted);
    letter-spacing: .07em;
}
.wcal-day-head.today .wcal-wday { color: var(--primary); }

.wcal-mday {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: .9rem;
    font-weight: 600;
    color: var(--text);
    width: 26px;
    height: 26px;
    border-radius: 50%;
    margin-top: .15rem;
}
.wcal-mday.today-circle {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 6px rgba(37,99,235,.35);
}

/* Scrollable body */
.wcal-body {
    flex: 1;
    min-height: 0;
    display: flex;
    overflow-y: auto;
    position: relative;
    scroll-behavior: smooth;
}

/* Gutter (time labels) */
.wcal-gutter {
    flex-shrink: 0;
    width: 52px;
    position: relative;
    border-right: 1px solid var(--border);
    background: var(--surface);
}

.wcal-time-lbl {
    position: absolute;
    right: 7px;
    font-size: 9.5px;
    color: var(--muted);
    transform: translateY(-50%);
    white-space: nowrap;
    font-weight: 500;
    letter-spacing: .01em;
}

/* Day columns area */
.wcal-days-area { flex: 1; position: relative; overflow: hidden; }

.wcal-bg-lines { position: absolute; inset: 0; pointer-events: none; }

.wcal-hour-line {
    position: absolute; left: 0; right: 0;
    height: 1px; background: var(--border);
}
.wcal-half-line {
    position: absolute; left: 0; right: 0;
    height: 1px; background: #eef2f7;
}

.wcal-day-col {
    position: absolute;
    top: 0;
    border-right: 1px solid var(--border);
    cursor: pointer;
    transition: background .1s;
}
.wcal-day-col:last-child { border-right: none; }
.wcal-day-col.today { background: rgba(37,99,235,.025); }
.wcal-day-col:not(.today):hover { background: rgba(0,0,0,.015); }

/* Now line */
.wcal-now-line {
    position: absolute; left: 0; right: 0;
    height: 2px; background: #ef4444;
    z-index: 5; pointer-events: none;
}
.wcal-now-line::before {
    content: '';
    position: absolute; left: -4px; top: -3px;
    width: 8px; height: 8px;
    border-radius: 50%; background: #ef4444;
}

/* Slots */
.wcal-slot {
    position: absolute;
    background: var(--primary);
    color: #fff;
    border-radius: 5px;
    padding: 3px 6px;
    overflow: hidden;
    cursor: pointer;
    z-index: 3;
    border-left: 3px solid rgba(0,0,0,.18);
    box-shadow: 0 1px 4px rgba(37,99,235,.25);
    transition: filter .1s, transform .1s, box-shadow .1s;
    min-width: 0;
}
.wcal-slot:hover {
    filter: brightness(1.07);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(37,99,235,.3);
}

.wcal-slot-time {
    font-size: 10px; font-weight: 700;
    opacity: .9; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
}
.wcal-slot-names {
    font-size: 11px; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis;
    margin-top: 1px; opacity: .88;
}
.wcal-slot-compact {
    font-size: 10px; white-space: nowrap;
    overflow: hidden; text-overflow: ellipsis; line-height: 1.3;
}

/* ============================================================
   Monthly Calendar (mcal-*)
   ============================================================ */
.mcal-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    background: var(--surface);
    overflow: hidden;
}

/* Row of weekday names */
.mcal-header {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    flex-shrink: 0;
}

.mcal-wday-head {
    text-align: center;
    padding: .4rem .25rem;
    font-size: 10px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .07em;
    border-right: 1px solid var(--border);
}
.mcal-wday-head:last-child { border-right: none; }

/* Body: 6-row grid */
.mcal-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    grid-template-rows: repeat(var(--mcal-rows, 6), 1fr);
    overflow-y: auto;
}

/* Individual day cell */
.mcal-cell {
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding: .3rem .35rem .25rem;
    cursor: pointer;
    min-height: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 2px;
    transition: background .1s;
}
.mcal-cell:nth-child(7n) { border-right: none; }   /* ultima colonna */
.mcal-cell:hover { background: var(--bg); }

.mcal-cell.mcal-today { background: var(--primary-light); }
.mcal-cell.mcal-today:hover { background: #dbeafe; }
.mcal-cell.mcal-other-month { background: var(--surface-2); }
.mcal-cell.mcal-other-month .mcal-day-num { opacity: .4; }

/* Day number */
.mcal-day-num {
    flex-shrink: 0;
    text-align: right;
    line-height: 1;
    margin-bottom: 1px;
}

.mcal-day-num span {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    width: 22px;
    height: 22px;
    border-radius: 50%;
}

.mcal-today-circle {
    background: var(--primary);
    color: #fff !important;
    box-shadow: 0 2px 5px rgba(37,99,235,.3);
}

/* Slot pill */
.mcal-slot-pill {
    display: flex;
    align-items: center;
    gap: 3px;
    background: var(--primary);
    color: #fff;
    border-radius: 3px;
    padding: 1px 5px;
    font-size: 10.5px;
    font-weight: 500;
    overflow: hidden;
    cursor: pointer;
    flex-shrink: 0;
    white-space: nowrap;
    transition: filter .1s;
    border-left: 3px solid rgba(0,0,0,.15);
}
.mcal-slot-pill:hover { filter: brightness(1.1); }

/* Slot che continua da/verso un altro giorno: rimuovi bordo-raggio */
.mcal-pill-cont-left  { border-radius: 0 3px 3px 0; border-left: none; margin-left: -3px; padding-left: 5px; }
.mcal-pill-cont-right { border-radius: 3px 0 0 3px; margin-right: -3px; }

.mcal-pill-time {
    font-weight: 700;
    opacity: .9;
    flex-shrink: 0;
}
.mcal-pill-name {
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

/* "+N altri" link */
.mcal-more {
    font-size: 10.5px;
    font-weight: 600;
    color: var(--primary);
    padding: 0 2px;
    cursor: pointer;
    flex-shrink: 0;
}
.mcal-more:hover { text-decoration: underline; }

/* ============================================================
   Data table
   ============================================================ */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
    border: 1px solid var(--border);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    min-width: 480px;
}

.data-table th {
    text-align: left;
    padding: .6rem 1rem;
    background: var(--surface-2);
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .055em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table td {
    padding: .7rem 1rem;
    font-size: 13px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg); }

/* ============================================================
   Badges
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 9px;
    border-radius: 99px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .01em;
    white-space: nowrap;
}
.badge-superadmin  { background: #ede9fe; color: #6d28d9; }
.badge-user        { background: #dbeafe; color: #1d4ed8; }
.badge-active      { background: var(--success-light); color: var(--success-h); }
.badge-inactive    { background: var(--danger-light);  color: var(--danger-h); }
.badge-group-count { background: #f1f5f9; color: var(--text-2);
                     max-width: 14ch; overflow: hidden; text-overflow: ellipsis;
                     cursor: default; }

/* ============================================================
   Settings view
   ============================================================ */
.settings-tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid var(--border);
    margin-bottom: 1.5rem;
}

.settings-tab {
    background: transparent;
    border: none;
    border-bottom: 2.5px solid transparent;
    border-radius: 0;
    padding: .55rem 1.1rem;
    margin-bottom: -2px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    transition: color .15s, border-color .15s;
}
.settings-tab:hover { color: var(--text-2); background: transparent; }
.settings-tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    font-weight: 600;
}

/* Card-style settings form */
.settings-form {
    max-width: 520px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-xs);
}

.settings-form-header {
    padding: .875rem 1.25rem .75rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface-2);
    margin-bottom: 1.25rem;
}

.settings-form-header h3 {
    font-size: .95rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.01em;
}

/* Adjust padding for form body */
.settings-form > label,
.settings-form > .form-row,
.settings-form > .form-actions,
.settings-form > .status-msg,
#s-oauth2-fields,
#s-basic-fields {
    padding-left: 1.25rem;
    padding-right: 1.25rem;
}
.settings-form > .form-actions { padding-bottom: 1.25rem; }

/* Auth mode sub-panels */
#s-oauth2-fields,
#s-basic-fields {
    background: var(--bg);
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    padding-top: .875rem;
    padding-bottom: .1rem;
    margin-bottom: .25rem;
}

/* Email test section (second card) */
.settings-form + .settings-form .settings-form-header { /* inherits */ }

/* ============================================================
   Checkbox list
   ============================================================ */
.checkbox-list {
    display: flex;
    flex-direction: column;
    gap: .3rem;
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .5rem .6rem;
    margin-bottom: 1rem;
    background: var(--bg);
}

.checkbox-list label {
    flex-direction: row;
    align-items: center;
    gap: .5rem;
    font-weight: 400;
    margin: 0;
    cursor: pointer;
    color: var(--text);
}
.checkbox-list input[type=checkbox] { width: 15px; height: 15px; cursor: pointer; flex-shrink: 0; }

/* ============================================================
   Modal
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10,16,30,.5);
    z-index: 100;
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    z-index: 200;
    width: 100%;
    max-width: 480px;
    max-height: 92vh;
    overflow-y: auto;
    padding: 1rem;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg), 0 0 0 1px rgba(0,0,0,.06);
    padding: 1.5rem;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    padding-bottom: .875rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -.01em;
}

.modal-close {
    background: var(--surface-2);
    color: var(--muted);
    border: none;
    width: 28px;
    height: 28px;
    border-radius: var(--radius-sm);
    font-size: 1.1rem;
    line-height: 1;
    padding: 0;
    flex-shrink: 0;
}
.modal-close:hover { background: var(--border); color: var(--text); }

/* ============================================================
   Presence dashboard
   ============================================================ */
.presence-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
    gap: .875rem;
}

.presence-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-left: 4px solid var(--border);
    border-radius: var(--radius);
    padding: .9rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .25rem;
    box-shadow: var(--shadow-xs);
    transition: border-color .2s, box-shadow .15s, transform .1s;
}
.presence-card:hover {
    box-shadow: var(--shadow-sm);
    transform: translateY(-1px);
}
.presence-card.status-available { border-left-color: var(--success); }
.presence-card.status-dnd        { border-left-color: var(--danger); }
.presence-card.status-unknown    { border-left-color: var(--muted); }

.presence-card .ext-name {
    font-weight: 600;
    font-size: .9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text);
}
.presence-card .ext-number {
    font-size: 11px;
    color: var(--muted);
    font-weight: 500;
}
.presence-card .ext-status {
    display: flex;
    align-items: center;
    gap: .4rem;
    margin-top: .2rem;
    font-size: 13px;
    color: var(--text-2);
}
.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status-dot.available { background: var(--success); box-shadow: 0 0 0 2px var(--success-light); }
.status-dot.dnd        { background: var(--danger);  box-shadow: 0 0 0 2px var(--danger-light); }
.status-dot.unknown    { background: var(--muted); }

.presence-card .ext-oncall {
    font-size: 11px;
    font-weight: 700;
    color: var(--primary);
    margin-top: .2rem;
    letter-spacing: .01em;
}
.presence-card .ext-last-set {
    font-size: 11px;
    color: var(--muted);
}

/* ============================================================
   Branding — logo preview
   ============================================================ */
.brand-logo-preview {
    display: inline-block;
    margin: 0 1.25rem 1rem;
    padding: .875rem 1rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.brand-logo-preview img {
    display: block;
    max-height: 70px;
    max-width: 190px;
    object-fit: contain;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px;
    background: var(--surface);
}

/* ============================================================
   Footer
   ============================================================ */
.app-footer {
    flex-shrink: 0;
    text-align: center;
    font-size: 11px;
    color: var(--muted);
    padding: .35rem 1rem;
    background: var(--surface);
    border-top: 1px solid var(--border);
    letter-spacing: .01em;
}

/* ============================================================
   Navbar logo / brand
   ============================================================ */
@media (max-width: 480px) {
    .navbar-logo:not(.hidden) + .navbar-brand { display: none; }
}

/* ============================================================
   Responsive — tablet (≤ 900px): compact nav
   ============================================================ */
@media (max-width: 900px) {
    .nav-btn { padding: .38rem .55rem; font-size: 12.5px; }
    .navbar-brand { font-size: .88rem; }
    .navbar-sep { margin: 0 .3rem; }
}

/* ============================================================
   Responsive — mobile (≤ 768px): hamburger nav
   ============================================================ */
@media (max-width: 768px) {
    /* Show hamburger, hide separator */
    .nav-toggle { display: flex; align-items: stretch; gap: 0; }
    .navbar-sep { display: none; }

    /* Nav links collapse to vertical dropdown */
    .navbar-links {
        display: none;
        position: absolute;
        top: var(--navbar-h);
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        background: var(--primary-dark);
        padding: .5rem .75rem .75rem;
        gap: .15rem;
        z-index: 49;
        box-shadow: 0 6px 16px rgba(0,0,0,.22);
        border-top: 1px solid rgba(255,255,255,.1);
    }

    #page-app.nav-open .navbar-links { display: flex; }

    .nav-btn {
        text-align: left;
        padding: .65rem 1rem;
        border-radius: var(--radius-sm);
        font-size: 14px;
    }
    .nav-btn.active { background: rgba(255,255,255,.2); }

    /* Views: tighter padding */
    .view { padding: 1rem .875rem; }
    #view-calendar { padding: .5rem .5rem; }

    /* Calendar: horizontal scroll (weekly) */
    .wcal-days-area { min-width: 400px; }
    #calendar-grid  { overflow-x: auto; }
    .wcal-slot-names { display: none; }
    .wcal-wday { font-size: 9px; }
    .wcal-mday { font-size: .82rem; width: 22px; height: 22px; }
    .wcal-day-head { padding: .3rem .1rem; }

    /* Calendar: monthly */
    .mcal-slot-pill { font-size: 9.5px; }
    .mcal-pill-name { display: none; }      /* su mobile mostra solo l'orario */
    .mcal-day-num span { font-size: 11px; width: 18px; height: 18px; }

    /* Settings: full-width form */
    .settings-form { max-width: 100%; }

    /* Presence: 2 columns or 1 */
    .presence-grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); }

    /* Group bar */
    .tenant-bar { padding: 0 .875rem; }
    .tenant-bar select { min-width: 140px; }
}

/* ============================================================
   Responsive — small mobile (≤ 480px)
   ============================================================ */
@media (max-width: 480px) {
    .login-box { padding: 2rem 1.5rem; }

    /* Stack form rows */
    .form-row { flex-direction: column; gap: 0; }
    .form-row > label { flex: unset; }

    /* Modal full screen */
    .modal { padding: .5rem; max-height: 96vh; }
    .modal-content { padding: 1.25rem; border-radius: var(--radius); }

    /* Presence: single column */
    .presence-grid { grid-template-columns: 1fr; }

    .view-header h2 { font-size: 1rem; }
    .view-header { margin-bottom: .875rem; }
}
