/* =========================================================================
   Gestionale Tour Operator — stile coerente con Book Your Italy Online
   Palette: navy #002d4b + oro #c5a059 + bianchi caldi + ombre blu-tinted
   Font: system-ui (richiesta dell'utente)
   Layout: topnav fissa, contenuto a tutta larghezza
   ========================================================================= */

*, *::before, *::after { box-sizing: border-box; }
body, h1, h2, h3, p, ul, figure { margin: 0; }
ul { padding: 0; list-style: none; }
img { max-width: 100%; display: block; }

:root {
    /* Brand */
    --navy:           #002d4b;
    --navy-deep:      #001d30;
    --gold:           #c5a059;
    --gold-light:     #e8c97a;
    --gold-soft:      rgba(197, 160, 89, 0.12);
    --gold-border:    rgba(197, 160, 89, 0.5);

    /* Superfici */
    --bg:             #dde2e8;
    --surface:        #ffffff;
    --surface-warm:   #f8f1e3;
    --border:         #c8d0d8;
    --border-soft:    #e1e6eb;

    /* Testo */
    --text:           #2d3436;
    --text-mute:      #636e72;
    --text-on-dark:   #e5e7eb;

    /* Stato */
    --danger:         #b91c1c;
    --danger-bg:      #fef2f2;
    --success:        #15803d;
    --success-bg:     #ecfdf5;
    --warning:        #b45309;
    --warning-bg:     #fffbeb;

    /* Ombre blu-tinted */
    --shadow-soft:    0 4px 16px rgba(0, 45, 75, 0.06);
    --shadow:         0 8px 32px rgba(0, 45, 75, 0.10);
    --shadow-strong:  0 16px 48px rgba(0, 45, 75, 0.15);

    --transition:     all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --radius:         8px;
    --radius-lg:      12px;

    /* Topnav */
    --topnav-h:       56px;
    --topnav-accent:  3px;
}

html, body {
    min-height: 100%;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background-color: var(--bg);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
    font-size: 14px;
    line-height: 1.55;
}

/* Quando la nav è visibile, lascia spazio sotto */
body.has-nav { padding-top: calc(var(--topnav-h) + var(--topnav-accent)); }

a { color: var(--navy); text-decoration: none; }
a:hover { color: var(--gold); }

/* ---------- Top nav (fixed) ------------------------------------------ */
.topnav {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--topnav-h);
    background: linear-gradient(160deg, var(--navy-deep) 0%, var(--navy) 100%);
    border-bottom: var(--topnav-accent) solid var(--gold);
    box-shadow: 0 2px 16px rgba(0, 29, 48, 0.18);
    display: flex;
    align-items: stretch;
    padding: 0 24px;
    z-index: 1000;
    color: var(--text-on-dark);
}

.topnav-brand {
    display: flex;
    align-items: center;
    padding-right: 22px;
    margin-right: 14px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: var(--gold);
    border-right: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}
.topnav-brand:hover { color: var(--gold-light); text-decoration: none; }

.topnav-menu {
    display: flex;
    align-items: stretch;
    flex: 1;
    overflow-x: auto;
    overflow-y: hidden;           /* impedisce la barra verticale */
    scrollbar-width: none;        /* Firefox: nasconde la scrollbar */
    -ms-overflow-style: none;     /* Edge legacy */
}
.topnav-menu::-webkit-scrollbar { width: 0; height: 0; }
.topnav-menu li { display: flex; }
.topnav-menu a {
    display: flex;
    align-items: center;
    padding: 0 10px;
    color: rgba(255, 255, 255, 0.78);
    font-size: 13px;
    letter-spacing: 0.3px;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;          /* il border si sovrappone al gold underline */
    white-space: nowrap;
    transition: var(--transition);
}
.topnav-menu a:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.04);
}
.topnav-menu > li.active > a {
    color: var(--gold-light);
    background: rgba(197, 160, 89, 0.10);
    border-bottom-color: var(--gold);
    font-weight: 600;
}
.topnav-sep {
    width: 1px;
    margin: 12px 4px;
    background: rgba(197, 160, 89, 0.5);
    pointer-events: none;
}

/* Sotto-menu a tendina (es. Catalogo → Modelli mail) */
.topnav-has-sub { position: relative; }
.topnav-has-sub > a::after {
    content: "\25BE";              /* ▾ */
    margin-left: 5px;
    font-size: 10px;
    opacity: 0.7;
}
.topnav-sub {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 180px;
    flex-direction: column;
    background: var(--navy);
    border: 1px solid rgba(197, 160, 89, 0.3);
    border-top: 2px solid var(--gold);
    box-shadow: 0 8px 20px rgba(0, 29, 48, 0.25);
    padding: 4px 0;
    z-index: 1001;
}
.topnav-has-sub:hover .topnav-sub { display: flex; }
.topnav-menu:has(.topnav-has-sub:hover) { overflow: visible; }
.topnav-sub li { display: block; }
.topnav-sub a {
    padding: 8px 16px;
    border-bottom: none;
    margin-bottom: 0;
    white-space: nowrap;
}
.topnav-sub li.active a {
    color: var(--gold-light);
    background: rgba(197, 160, 89, 0.12);
    font-weight: 600;
}

.topnav-user {
    display: flex;
    align-items: center;
    gap: 12px;
    padding-left: 18px;
    margin-left: auto;
    border-left: 1px solid rgba(255, 255, 255, 0.08);
    flex-shrink: 0;
}
.topnav-username {
    font-size: 13px;
    color: rgba(255, 255, 255, 0.85);
}
/* Tendina utente (username → Utenti) */
.topnav-user-sub {
    align-self: stretch;
    display: flex;
    align-items: center;
    cursor: default;
}
.topnav-user-sub > .topnav-username::after {
    content: "\25BE";              /* ▾ */
    margin-left: 5px;
    font-size: 10px;
    opacity: 0.7;
}
.topnav-user-sub .topnav-sub {
    left: auto;
    right: 0;
}
.topnav-user-sub .topnav-sub a {
    display: block;
    color: rgba(255, 255, 255, 0.78);
}
.topnav-user-sub .topnav-sub a:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.04);
}
.topnav-user-sub.active > .topnav-username {
    color: var(--gold-light);
    font-weight: 600;
}
.topnav-anno-sub > .topnav-username {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: var(--radius);
    padding: 5px 8px;
    font-weight: 700;
    transition: var(--transition);
}
.topnav-anno-sub:hover > .topnav-username {
    border-color: var(--gold);
}
/* ---------- Contenuto -------------------------------------------------- */
.content {
    padding: 24px 32px 40px;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
}
.content-full {
    /* schermata di login: nessuna nav, contenuto centrato */
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

/* ---------- Topbar di pagina (titolo + eventuali azioni) ------------- */
.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0 0 14px;
    margin-bottom: 0px;
    border-bottom: 1px solid var(--border-soft);
}
.topbar-center {
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
.page-title {
    font-size: 26px;
    font-weight: 600;
    color: var(--navy);
    letter-spacing: 0.2px;
}
.page-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-self: end;
}
.page-subtitle {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}
.page-localita {
    font-size: 17px;
    font-weight: 600;
    color: var(--gold);
    letter-spacing: 0.2px;
}

/* ---------- Flash ----------------------------------------------------- */
.flash {
    padding: 12px 16px;
    margin-bottom: 14px;
    border-radius: var(--radius);
    border-left: 4px solid;
    background: var(--surface);
    box-shadow: var(--shadow-soft);
}
.flash-success { border-left-color: var(--success); background: var(--success-bg); color: #14532d; }
.flash-error   { border-left-color: var(--danger);  background: var(--danger-bg);  color: #7f1d1d; }
.flash-info    { border-left-color: var(--navy);    background: #eff5fb;            color: var(--navy-deep); }

/* ---------- Card ------------------------------------------------------ */
.card {
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
}
.card h2 {
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    color: var(--gold);
    margin-bottom: 14px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-soft);
}

/* ---------- Riepilogo cliente (KPI) ---------------------------------- */
.kpi-row {
    display: flex;
    gap: 10px;
    align-items: stretch;
}
.kpi {
    flex: 1 1 0;
    min-width: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
    background: var(--surface-warm);
}
.kpi-sep {
    width: 2px;
    background: var(--gold);
    border-radius: 1px;
    margin: 2px 8px;
}
.kpi-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-mute);
    margin-bottom: 5px;
    white-space: nowrap;
}
.kpi-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
    white-space: nowrap;
}
.kpi-value.is-pos { color: var(--success); }
.kpi-value.is-neg { color: var(--danger); }

/* ---------- Bottoni --------------------------------------------------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 9px 18px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    background: var(--navy);
    color: #fff;
    cursor: pointer;
    font: inherit;
    font-size: 13px;
    font-weight: 500;
    letter-spacing: 0.3px;
    transition: var(--transition);
    text-decoration: none;
}
.btn:hover {
    background: var(--navy-deep);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 45, 75, 0.25);
}
.btn-secondary {
    background: var(--surface);
    color: var(--navy);
    border-color: var(--border);
}
.btn-secondary:hover {
    background: var(--surface);
    color: var(--navy);
    border-color: var(--gold);
    box-shadow: var(--shadow-soft);
}
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #991b1b; }
.btn-link {
    background: transparent;
    border: none;
    color: var(--navy);
    padding: 6px 10px;
    font-weight: 500;
}
.btn-link:hover {
    background: var(--gold-soft);
    color: var(--navy-deep);
    box-shadow: none;
}
.btn-gold {
    background: var(--gold);
    color: var(--navy-deep);
    font-weight: 600;
}
.btn-gold:hover {
    background: var(--gold-light);
    color: var(--navy-deep);
}

/* ---------- Form ------------------------------------------------------ */
form .row {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 10px;
    align-items: center;
    margin-bottom: 14px;
}
form label {
    color: var(--text-mute);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
}
form input,
form select,
form textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font: inherit;
    background: #fff;
    color: var(--text);
    transition: var(--transition);
}
form input:focus,
form select:focus,
form textarea:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-soft);
}
form textarea {
    min-height: 80px;
    resize: vertical;
    line-height: 1.5;
}
form .actions {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border-soft);
}

/* ---------- Tabelle --------------------------------------------------- */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.table th,
.table td {
    padding: 5px 5px;
    text-align: left;
    border-bottom: 1px solid var(--border-soft);
    border-right: 1px solid var(--border-soft);
    vertical-align: middle;
}
.table th:last-child,
.table td:last-child { border-right: none; }
.table th {
    background: #fafbfc;
    font-weight: 700;
    color: var(--gold);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 1.8px;
    border-bottom: 2px solid var(--gold);
    white-space: nowrap;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background-color 0.18s ease; }
.table tbody tr:nth-child(even) td { background: rgba(0, 45, 75, 0.05); }
.table tbody tr:hover td { background: rgba(197, 160, 89, 0.06); }

/* Header ordinabili: cursore + freccia di stato */
.table th.sortable {
    cursor: pointer;
    user-select: none;
    padding-right: 24px;
    position: relative;
}
.table th.sortable::after {
    content: '↕';
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 11px;
    opacity: 0.35;
    transition: opacity 0.15s ease, color 0.15s ease;
}
.table th.sortable:hover::after { opacity: 0.7; }
.table th.sort-asc::after  { content: '▲'; opacity: 1; color: var(--gold); }
.table th.sort-desc::after { content: '▼'; opacity: 1; color: var(--gold); }

/* Variante densa per tabelle con molte colonne */
.table-dense th,
.table-dense td {
    padding: 5px 5px;
    font-size: 13px;
}

/* ---------- Login ----------------------------------------------------- */
.login-box {
    width: 520px;
    margin: 0 auto;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    padding: 36px 32px;
    box-shadow: var(--shadow-strong);
    border-top: 4px solid var(--gold);
}
.login-logo {
    display: block;
    margin: 0 auto 20px;
    max-width: 100%;
}
.login-box h1 {
    font-size: 16px;
    margin-bottom: 24px;
    color: var(--navy);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 3px;
    font-weight: 600;
}
.login-box h1::after {
    content: '';
    display: block;
    width: 40px;
    height: 2px;
    background: var(--gold);
    margin: 10px auto 0;
}

/* ---------- Toolbar (header di lista) -------------------------------- */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}
.toolbar-filters {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: nowrap;
}
.toolbar-filters input,
.toolbar-filters select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 13px;
}
.toolbar-filters input[type="search"] {
    width: 220px;
}
.toolbar-filters input:focus,
.toolbar-filters select:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-soft);
}
.btn-link {
    color: var(--text-mute);
    text-decoration: underline;
    font-size: 13px;
}
.btn-link:hover {
    color: var(--navy);
}

/* ---------- Copia tabella --------------------------------------------- */
.table-copy-bar {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 6px;
}
.btn-copy {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-mute);
    padding: 5px 12px;
    border-radius: var(--radius);
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}
.btn-copy:hover {
    border-color: var(--gold);
    color: var(--navy);
}
.btn-copy.is-copied {
    color: var(--success);
    border-color: var(--success);
}

/* ---------- Utility --------------------------------------------------- */
.text-mute    { color: var(--text-mute); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-right  { text-align: right; }
.text-center { text-align: center; }
.table th.text-right,
.table td.text-right { text-align: right; }
.table th.text-center,
.table td.text-center { text-align: center; }
.text-gold   { color: var(--gold); }
.text-navy   { color: var(--navy); }
.text-strong { font-weight: 600; }
.mb-0        { margin-bottom: 0; }
.mt-1        { margin-top: 8px; }

.label-micro {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--gold);
}

/* ---------- Tabs ------------------------------------------------------ */
.tabs {
    display: flex;
    flex-direction: column;
}
.tab-buttons {
    display: flex;
    gap: 4px;
    justify-content: center;
    border-bottom: 2px solid var(--border);
    margin-bottom: 18px;
}
.tab-btn {
    appearance: none;
    background: var(--surface);
    border: 1px solid transparent;
    border-bottom: 2px solid var(--border);
    border-radius: 6px 6px 0 0;
    padding: 10px 18px;
    margin-bottom: -2px;
    font: inherit;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--text-mute);
    cursor: pointer;
    transition: var(--transition);
}
.tab-btn:hover {
    background: #fff;
    border-color: var(--border);
    color: var(--navy);
}
.tab-btn.is-active {
    background: #fff;
    border-color: var(--border);
    border-bottom: 2px solid #fff;
    color: var(--gold);
}
.tab-panel {
    display: none;
}
.tab-panel.is-active {
    display: block;
}
.tab-btn-actions {
    margin-left: auto;
    display: flex;
    gap: 8px;
    align-items: center;
}
.tab-btn-actions .btn { display: none; }
.tabs:has(.tab-panel[data-panel="costi"].is-active) .tab-btn-actions .btn[data-for-tab="costi"],
.tabs:has(.tab-panel[data-panel="fatture"].is-active) .tab-btn-actions .btn[data-for-tab="fatture"] {
    display: inline-flex;
}
.tab-buttons:has(.tab-btn-actions) { justify-content: flex-start; }
.tab-panel .mail-form { padding: 4px 2px 8px; }
.mail-form input[type="file"]::file-selector-button {
    background: var(--gold-soft);
    border: 1px solid var(--border-soft);
    border-radius: 20px;
    color: var(--navy);
    padding: 5px 14px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
    margin-right: 8px;
    transition: var(--transition);
}
.mail-form input[type="file"]::file-selector-button:hover {
    background: var(--gold-light);
    border-color: var(--gold-border);
}
.icon-link {
    display: inline-flex;
    align-items: center;
    vertical-align: middle;
    color: var(--text-mute);
    margin-right: 6px;
}
.icon-link:hover { color: var(--gold); }
.lang-tabs {
    background: var(--bg);
    border-radius: var(--radius);
    padding: 16px 20px 20px;
    margin-top: 8px;
}

/* ---------- Badge ------------------------------------------------------ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-danger  { background: var(--danger-bg);  color: var(--danger); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-info    { background: var(--gold-soft);  color: var(--navy); }
.badge-yellow  { background: #fef08a;           color: #713f12; }
.badge-lg      { font-size: 15px; padding: 5px 16px; }
.page-record-number {
    font-size: 26px;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 1px;
}

/* ---------- Fields grid (2 colonne) ----------------------------------- */
.fields-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    column-gap: 32px;
    row-gap: 14px;
    margin-bottom: 14px;
}
.fields-col {
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.fields-grid .row {
    margin-bottom: 0;
}
.fields-grid .span-2 {
    grid-column: 1 / -1;
}
.fields-grid-3 { grid-template-columns: 1fr 1fr 1fr; grid-template-rows: repeat(3, auto); }
.fields-grid-3 > .fields-col { grid-row: 1 / span 3; display: grid; grid-template-rows: subgrid; }
.fields-duo { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }

/* Vista email: testata a due colonne (dati a sinistra, azioni a destra) */
.mail-head {
    display: grid;
    grid-template-columns: minmax(0, 1.7fr) minmax(260px, 1fr);
    gap: 14px;
    align-items: start;
    margin-bottom: 14px;
}

/* Corpo email reso in iframe isolato; altezza adattata via JS (setupMailFrames) */
.mail-frame {
    display: block;
    width: 100%;
    min-height: 120px;
    border: 0;
    background: #fff;
}

/* Gruppi di campi affiancati (2 o 3 colonne) */
.row-group {
    display: grid;
    gap: 14px;
    margin-bottom: 14px;
}
.row-group-2 { grid-template-columns: repeat(2, 1fr); }
.row-group-3 { grid-template-columns: repeat(3, 1fr); }
.lang-tabs .row-group-2 { max-width: 66.666%; margin-inline: auto; }
.row-group .row,
.lang-tabs .tab-panel > .row {
    grid-template-columns: 1fr;
    align-items: start;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 10px 14px;
}
.row-group .row { margin-bottom: 0; }

/* ---------- Readonly -------------------------------------------------- */
.card.readonly .row {
    grid-template-columns: 160px 1fr;
}
.card.readonly .fields-grid {
    row-gap: 0;
    column-gap: 0;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    overflow: hidden;
}
.card.readonly .fields-col {
    gap: 0;
}
.card.readonly .fields-col:first-child {
    border-right: 1px solid var(--border-soft);
}
.card.readonly .fields-grid-3 .fields-col:nth-child(2) {
    border-right: 1px solid var(--border-soft);
}
.card.readonly .fields-grid .row {
    padding: 12px 16px;
}
.card.readonly .fields-col .row:not(:last-child) {
    border-bottom: 1px solid var(--border-soft);
}
.card.readonly .fields-grid > .span-2 {
    border-top: 1px solid var(--border-soft);
}
.card.readonly .fields-duo {
    gap: 0;
}
.card.readonly .fields-duo > .row:first-child {
    border-right: 1px solid var(--border-soft);
}
.card.readonly input:disabled,
.card.readonly select:disabled,
.card.readonly textarea:disabled {
    opacity: 1;
    background: transparent;
    border-color: transparent;
    color: inherit;
    cursor: default;
    padding-left: 0;
}
.card.readonly textarea:disabled {
    resize: none;
}

/* ---------- Calendario ----------------------------------------------- */
.cal-toolbar { gap: 16px; }

.cal-toggle {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: #fff;
}
.cal-toggle-btn {
    padding: 8px 16px;
    color: var(--text-mute);
    font-size: 13px;
    font-weight: 600;
    background: #fff;
    transition: var(--transition);
}
.cal-toggle-btn:hover { color: var(--navy); text-decoration: none; }
.cal-toggle-btn + .cal-toggle-btn { border-left: 1px solid var(--border); }
.cal-toggle-btn.is-active {
    background: var(--navy);
    color: var(--gold);
}
.cal-toggle-btn.is-active:hover { color: var(--gold-light); }

.cal-nav {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-wrap: nowrap;
}
.cal-nav .btn { padding: 6px 12px; }
.cal-month-label {
    font-size: 16px;
    font-weight: 700;
    color: var(--navy);
    min-width: 160px;
    text-align: center;
}
.cal-nav input[type="date"],
.cal-nav select {
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 13px;
    width: auto;
}

.cal-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    background: #fff;
    box-shadow: var(--shadow-soft);
}
.cal-dow {
    background: var(--navy);
    color: var(--gold);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    text-align: center;
    padding: 8px 4px;
}
.cal-cell {
    background: #fff;
    min-height: 110px;
    padding: 4px;
    border-top: 1px solid var(--border-soft);
    border-left: 1px solid var(--border-soft);
    display: flex;
    flex-direction: column;
    gap: 2px;
    cursor: pointer;
    overflow: hidden;
}
.cal-cell:nth-child(7n+1) { border-left: none; }
.cal-grid--week .cal-cell { min-height: 340px; }
.cal-cell:hover { background: var(--gold-soft); }
.cal-cell.is-other-month { background: #f4f6f8; }
.cal-cell.is-other-month:hover { background: #ecf0f4; }
.cal-cell.is-other-month .cal-day-num { color: #aab2bd; }
.cal-cell.is-today {
    background: var(--surface-warm);
    box-shadow: inset 0 0 0 2px var(--gold);
}
.cal-cell.is-today:hover { background: #f0e6cf; }
.cal-cell.is-today .cal-day-num {
    color: #fff;
    font-weight: 800;
    background: var(--gold);
    border-radius: 999px;
    width: 24px;
    height: 24px;
    line-height: 24px;
    padding: 0;
    margin-left: auto;
    text-align: center;
    box-shadow: 0 2px 6px rgba(197, 160, 89, 0.4);
}
.cal-day-num {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    text-align: right;
    padding: 0 4px 2px;
}

.cal-event {
    display: block;
    font-size: 11px;
    line-height: 1.5;
    padding: 1px 6px;
    color: #fff;
    background: var(--navy);
    border-radius: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-decoration: none;
    cursor: pointer;
    min-height: 18px;
}
.cal-event:hover {
    filter: brightness(1.08);
    color: #fff;
    text-decoration: none;
}
.cal-event.is-single,
.cal-event.is-start { border-top-left-radius: 4px; border-bottom-left-radius: 4px; margin-left: 1px; }
.cal-event.is-single,
.cal-event.is-end   { border-top-right-radius: 4px; border-bottom-right-radius: 4px; margin-right: 1px; }

.cal-event--tipo-tour     { background: var(--gold); color: var(--navy-deep); font-weight: 600; }
.cal-event--tipo-gruppi   { background: var(--navy); color: #fff; }
.cal-event--tipo-trekking { background: var(--success); color: #fff; }
.cal-event--ferie    { background: #2563eb; color: #fff; }
.cal-event--chiusura { background: var(--danger); color: #fff; }
.cal-event--followup { background: var(--warning); color: #fff; font-weight: 600; }
.cal-event--task     { background: #7c3aed; color: #fff; font-weight: 600; }

.cal-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    align-items: center;
    margin-bottom: 16px;
    padding: 10px 14px;
    background: var(--surface);
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    font-size: 13px;
}
.cal-filter-chip { cursor: pointer; user-select: none; }
.cal-filter-chip input { position: absolute; opacity: 0; pointer-events: none; }
.cal-filter-chip-face {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 5px 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-mute);
    background: var(--surface);
    transition: background .15s, border-color .15s, color .15s;
}
.cal-filter-chip-face::before {
    content: "";
    width: 9px;
    height: 9px;
    border-radius: 50%;
    background: var(--border);
    flex-shrink: 0;
    transition: background .15s;
}
.cal-filter-chip input:checked + .cal-filter-chip-face {
    background: var(--chip-color);
    border-color: var(--chip-color);
    color: #fff;
}
.cal-filter-chip input:checked + .cal-filter-chip-face::before { background: #fff; }
.cal-filter-chip input:focus-visible + .cal-filter-chip-face { box-shadow: 0 0 0 3px var(--gold-soft); }
.cal-filter-chip--pratiche { --chip-color: var(--navy); }
.cal-filter-chip--followup { --chip-color: var(--warning); }
.cal-filter-chip--task     { --chip-color: #7c3aed; }
.cal-filter-chip--ferie    { --chip-color: #2563eb; }
.cal-filter-chip--chiusura { --chip-color: var(--danger); }

.cal-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 29, 48, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}
.cal-modal[hidden] { display: none; }
.cal-modal-card {
    background: #fff;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-strong);
    padding: 24px;
    width: 100%;
    max-width: 460px;
}
.cal-modal-title {
    font-size: 18px;
    color: var(--navy);
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--gold);
}
.cal-modal-form { display: grid; gap: 4px; }
.cal-modal-form label {
    font-size: 11px;
    font-weight: 700;
    color: var(--text-mute);
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-top: 10px;
}
.cal-modal-form input,
.cal-modal-form select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 14px;
}
.cal-modal-form input:focus,
.cal-modal-form select:focus {
    outline: none;
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-soft);
}
.cal-modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    justify-content: flex-end;
}
.cal-modal-actions [data-cal-delete] { margin-right: auto; }

.cal-agenda { display: grid; gap: 12px; }
.cal-agenda-day {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow-soft);
}
.cal-agenda-day.is-today {
    border-color: var(--gold);
    box-shadow: 0 0 0 2px var(--gold-soft), var(--shadow-soft);
}
.cal-agenda-day-header {
    background: var(--navy);
    color: var(--gold);
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 1px;
}
.cal-agenda-list { margin: 0; padding: 0; list-style: none; }
.cal-agenda-item {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-soft);
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.cal-agenda-item:last-child { border-bottom: none; }
.cal-agenda-item:hover { background: var(--gold-soft); }
.cal-agenda-tag {
    display: inline-block;
    padding: 2px 10px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 1.5px;
    border-radius: 4px;
    text-transform: uppercase;
    flex-shrink: 0;
    min-width: 80px;
    text-align: center;
}
.cal-agenda-tag--partenza { background: var(--success-bg); color: var(--success); }
.cal-agenda-tag--rientro  { background: #eef2ff; color: #3730a3; }
.cal-agenda-tag--ferie    { background: #dbeafe; color: #1e40af; }
.cal-agenda-tag--chiusura { background: var(--danger-bg); color: var(--danger); }
.cal-agenda-tag--followup { background: var(--warning-bg); color: var(--warning); }
.cal-agenda-tag--task     { background: #ede9fe; color: #6d28d9; }
.cal-agenda-link { font-weight: 600; color: var(--navy); }
.cal-agenda-desc { color: var(--text-mute); font-size: 13px; }
.cal-agenda-meta { margin-left: auto; font-size: 12px; color: var(--text-mute); }

/* ---------- Layout pratica (tabelle etichetta/valore) ----------------- */
.pratica-grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
    margin-bottom: 20px;
}
.pratica-grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}
.pratica-grid-2 .detail-table {
    height: 100%;
}
.pratica-grid-2 .detail-table tr:first-child {
    height: 1px;
}
.detail-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border: 2px solid rgba(0, 45, 75, 0.25);
    border-radius: var(--radius);
    overflow: hidden;
}
.detail-table th,
.detail-table td {
    padding: 10px 14px;
    vertical-align: middle;
    text-align: left;
    border-bottom: 1px solid var(--border-soft);
}
.detail-table tr:last-child th,
.detail-table tr:last-child td { border-bottom: none; }
.detail-table th {
    width: 1%;
    background: #fafbfc;
    color: var(--text);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 1.5px;
    text-transform: uppercase;
    border-right: 1px solid var(--border-soft);
    white-space: nowrap;
}
.detail-table th[colspan] {
    width: auto;
    border-right: none;
    padding-top: 6px;
    padding-bottom: 6px;
}
.detail-table td[colspan] {
    vertical-align: top;
}
.detail-table tr:hover th,
.detail-table tr:hover td {
    background: var(--gold-soft);
}
.detail-table th label {
    font: inherit;
    color: inherit;
    text-transform: inherit;
    letter-spacing: inherit;
}

/* ---------- Stat cards (dashboard) ------------------------------------ */
.stat-cards {
    display: flex;
    gap: 16px;
}
.stat-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px 16px;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    background: var(--bg);
    color: inherit;
    text-decoration: none;
    text-align: center;
}
a.stat-card {
    transition: var(--transition);
}
a.stat-card:hover {
    border-color: var(--gold);
    box-shadow: var(--shadow-soft);
    background: var(--gold-soft);
    color: inherit;
    text-decoration: none;
}
.stat-card-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: var(--text-mute);
}
.stat-card-value {
    font-size: 36px;
    font-weight: 700;
    color: var(--navy);
    line-height: 1;
}
a.stat-card:hover .stat-card-value {
    color: var(--gold);
}

/* ---------- Responsive ------------------------------------------------ */
@media (max-width: 900px) {
    .content { padding: 16px; }
    .mail-head { grid-template-columns: 1fr; }
    form .row { grid-template-columns: 1fr; gap: 6px; }
    form label { margin-top: 4px; }
    .topnav { padding: 0 12px; }
    .topnav-brand { letter-spacing: 2px; padding-right: 12px; margin-right: 8px; }
    .topnav-username { display: none; }
    .cal-cell { min-height: 80px; }
    .cal-event { font-size: 10px; }
    .cal-month-label { min-width: auto; }
}

/* Tabella pivot costing nel catalogo */
.costing-table-wrap {
    overflow-x: auto;
    margin: 0 -4px;
}
.costing-pivot th,
.costing-pivot td {
    white-space: nowrap;
}
.costing-pivot th:nth-child(n+4):nth-last-child(n+2),
.costing-pivot td:nth-child(n+4):nth-last-child(n+2) {
    /* colonne Pax: strette e tabulari */
    min-width: 56px;
    font-variant-numeric: tabular-nums;
}
.costing-pivot th.text-right,
.costing-pivot td.text-right { padding-right: 10px; }

.costing-pivot tbody a {
    font-weight: 500;
    text-decoration: underline;
    text-decoration-color: var(--gold);
    text-decoration-thickness: 1.5px;
    text-underline-offset: 3px;
}
.costing-pivot tbody a:hover {
    color: var(--gold);
    text-decoration-color: currentColor;
}

/* Sezioni linguistiche nei form (catalogo) */
.lang-section {
    border: 1px solid var(--border);
    border-radius: 8px;
    margin-top: 16px;
    background: var(--surface);
}
.lang-section > summary {
    cursor: pointer;
    padding: 10px 14px;
    background: var(--gold-soft);
    border-radius: 8px 8px 0 0;
    user-select: none;
    color: var(--navy);
}
.lang-section[open] > summary {
    border-bottom: 1px solid var(--gold-border);
}
.lang-section > .row {
    padding: 0 14px;
}
.lang-section > .row:first-of-type { padding-top: 12px; }
.lang-section > .row:last-of-type  { padding-bottom: 14px; }

/* Editor rich-text minimale (catalogo: descrizione_short, descrizione, incluso) */
.rt-editor {
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--surface);
    overflow: hidden;
}
.rt-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 2px;
    padding: 4px;
    background: var(--gold-soft);
    border-bottom: 1px solid var(--border-soft);
}
.rt-toolbar button {
    appearance: none;
    border: 1px solid transparent;
    background: transparent;
    color: var(--navy);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 14px;
    cursor: pointer;
    line-height: 1.2;
    min-width: 30px;
}
.rt-toolbar button:hover {
    background: var(--surface);
    border-color: var(--gold-border);
}
.rt-toolbar button:active {
    background: var(--gold-light);
}
.rt-toolbar button.is-active {
    background: var(--navy);
    color: var(--surface);
    border-color: var(--navy);
}
.rt-toolbar button.is-active:hover {
    background: var(--navy-deep);
}
.rt-sep {
    width: 1px;
    background: var(--border-soft);
    margin: 4px 4px;
}
.rt-content {
    min-height: 160px;
    padding: 10px 12px;
    outline: none;
    font: inherit;
    color: inherit;
    line-height: 1.5;
}
.rt-content:focus {
    background: #fefcf6;
}
.rt-content h1, .rt-content h2, .rt-content h3,
.rt-readonly h1, .rt-readonly h2, .rt-readonly h3 {
    margin: 0.6em 0 0.3em;
    color: var(--navy);
}
.rt-content h1, .rt-readonly h1 { font-size: 1.45em; }
.rt-content h2, .rt-readonly h2 { font-size: 1.25em; }
.rt-content h3, .rt-readonly h3 { font-size: 1.1em;  }
.rt-content p,  .rt-readonly p  { margin: 0.4em 0; }
.rt-content ul, .rt-readonly ul { margin: 0.4em 0; padding-left: 1.5em; }
.rt-content li, .rt-readonly li { margin: 0.1em 0; }

/* ---------- Chart (SVG) --------------------------------------------- */
.chart-svg { width: 100%; height: auto; display: block; }
.chart-axis { fill: var(--text-mute); font-size: 11px; }
.chart-legend { display: flex; gap: 1.25rem; margin-bottom: 0.5rem; font-size: 0.85rem; color: var(--text-mute); }
.chart-legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.chart-swatch { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.chart-row { display: flex; gap: 1.5rem; flex-wrap: wrap; }
.chart-col { flex: 1 1 320px; min-width: 0; }
