/* =================================================================
   DemoApp - Foglio di stile principale
   ================================================================= */

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    color: #2c3e50;
    background: #f4f6fa;
    line-height: 1.5;
}

a { color: #3D4A58; text-decoration: none; }
a:hover { text-decoration: underline; }

h1 { font-size: 22px; margin: 0 0 14px; color: #3D4A58; }
h2 { font-size: 18px; margin: 18px 0 10px; color: #34495e; }
h3 { font-size: 15px; margin: 16px 0 8px; color: #3D4A58; border-bottom: 1px solid #eef0f5; padding-bottom: 4px; }

code {
    background: #f0f2f7;
    padding: 2px 6px;
    border-radius: 3px;
    font-family: "SF Mono", Menlo, Consolas, monospace;
    font-size: 13px;
}

small { color: #7f8c8d; }
.muted { color: #95a5a6; }

/* ===================== LAYOUT GUEST (login) ===================== */
body.guest {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, #1f3a93 0%, #34495e 100%);
}

.lang-switcher {
    position: absolute;
    top: 18px;
    right: 24px;
}
.lang-switcher a {
    color: rgba(255,255,255,.75);
    margin: 0 4px;
    font-size: 13px;
    font-weight: 500;
}
.lang-switcher a.active { color: #fff; text-decoration: underline; }

.guest-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 30px 16px;
}
.guest-footer {
    text-align: center;
    color: rgba(255,255,255,.6);
    padding: 14px;
}
.guest-footer small { color: rgba(255,255,255,.6); }

.login-card {
    width: 100%;
    max-width: 420px;
}
.login-card h1 { text-align: center; margin-bottom: 4px; }
.login-card h2 { text-align: center; font-weight: normal; color: #7f8c8d; margin-top: 0; }

/* ===================== LAYOUT APP ===================== */
body.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: #3D4A58;
    color: #fff;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 72px;
    box-shadow: 0 2px 6px rgba(0,0,0,.18);
}
.topbar a { color: #fff; }

/* ── Brand / Logo ── */
.brand-link { text-decoration: none; display: inline-flex; align-items: center; }
.brand-link:hover { opacity: .88; text-decoration: none; }
.brand-levia   { color: #F47920; font-weight: 700; font-size: 19px; letter-spacing: 1.5px; }
.brand-slash   { color: #F47920; font-size: 22px; font-weight: 300; margin: 0 1px; line-height: 1; }
.brand-outcome { color: rgba(255,255,255,.95); font-size: 19px; font-weight: 300; }

.tenant-badge {
    background: rgba(255,255,255,.15);
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    margin-left: 12px;
    color: rgba(255,255,255,.85);
}
.topnav a {
    margin: 0 12px;
    font-size: 14px;
    opacity: .85;
    padding-bottom: 2px;
    border-bottom: 2px solid transparent;
    transition: color .15s, border-color .15s, opacity .15s;
}
.topnav a:hover  { opacity: 1; color: #F47920; border-bottom-color: #F47920; text-decoration: none; }
.topnav a.is-active { opacity: 1; color: #F47920; border-bottom-color: #F47920; font-weight: 600; }

.user-menu {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
}
.user-info { color: rgba(255,255,255,.95); }
.user-info small { color: rgba(255,255,255,.6); }
.tenant-switcher {
    background: rgba(255,255,255,.15);
    color: #fff;
    border: 1px solid rgba(255,255,255,.3);
    padding: 4px 6px;
    border-radius: 4px;
    font-size: 12px;
}
.tenant-switcher option { color: #2c3e50; }

.lang-mini a {
    color: rgba(255,255,255,.7);
    margin: 0 2px;
    font-size: 11px;
    font-weight: 500;
}
.lang-mini a.active { color: #fff; text-decoration: underline; }

.btn-logout {
    background: rgba(255,255,255,.15);
    color: #fff !important;
    padding: 6px 12px;
    border-radius: 4px;
    font-size: 12px;
}
.btn-logout:hover { background: rgba(255,255,255,.25); text-decoration: none; }

.app-main {
    flex: 1;
    padding: 24px 32px;
    width: 100%;
    box-sizing: border-box;
}

.app-footer {
    text-align: center;
    padding: 14px;
    color: #7f8c8d;
    border-top: 1px solid #e9ecef;
    background: #fff;
}

/* ===================== CARD ===================== */
.card {
    background: #fff;
    border-radius: 10px;
    padding: 24px;
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
    margin-bottom: 20px;
}
.card.center { text-align: center; }

.row-between {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

/* ===================== FORM ===================== */
form label {
    display: block;
    margin: 12px 0;
}
form label > span {
    display: block;
    font-size: 13px;
    color: #555;
    margin-bottom: 4px;
    font-weight: 500;
}
form label > small {
    display: block;
    font-size: 12px;
    color: #95a5a6;
    margin-top: 4px;
}
input[type=text], input[type=email], input[type=password],
input[type=number], input[type=date], input[type=time], select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid #d0d7e0;
    border-radius: 6px;
    font-size: 14px;
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #1f3a93;
    box-shadow: 0 0 0 3px rgba(31, 58, 147, .1);
}
input:disabled, select:disabled {
    background: #f4f6fa;
    color: #7f8c8d;
    cursor: not-allowed;
}
textarea { min-height: 80px; resize: vertical; }

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px 18px;
}
.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px 18px;
}
@media (max-width: 720px) {
    .grid-2, .grid-4 { grid-template-columns: 1fr; }
}

.form-actions {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid #eef0f5;
    display: flex;
    gap: 10px;
}

/* ===================== BUTTONS ===================== */
.btn-primary, button[type=submit].btn-primary, button.btn-primary {
    background: #1f3a93;
    color: #fff;
    border: 0;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    font-weight: 500;
    text-decoration: none;
    display: inline-block;
}
.btn-primary:hover { background: #162a6e; text-decoration: none; }

.btn-secondary {
    background: #ecf0f1;
    color: #34495e;
    border: 0;
    padding: 10px 18px;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    display: inline-block;
}
.btn-secondary:hover { background: #dde4e6; text-decoration: none; }

button.link {
    background: none;
    border: 0;
    color: #1f3a93;
    cursor: pointer;
    text-decoration: underline;
    font-size: 13px;
    padding: 0;
}

/* ===================== TABLE ===================== */
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}
.data-table th, .data-table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid #eef0f5;
    font-size: 13px;
}
.data-table th {
    background: #f8f9fb;
    color: #555;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.data-table tr:hover { background: #fafbfc; }

/* ===================== BADGES ===================== */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
}
.badge.ok { background: #d4f4dd; color: #1aaf5d; }
.badge.ko { background: #fde2e2; color: #c0392b; }
.badge.warn { background: #fff3cd; color: #856404; }
.badge.info { background: #d1ecf1; color: #0c5460; }

/* ===================== FLASH ===================== */
.flashes { margin: 12px 0 0; padding: 0 8px; }
.flash {
    padding: 11px 14px;
    border-radius: 6px;
    margin-bottom: 10px;
    font-size: 14px;
    border-left: 4px solid;
}
.flash-success { background: #d4f4dd; border-color: #1aaf5d; color: #155724; }
.flash-error   { background: #fde2e2; border-color: #c0392b; color: #721c24; }
.flash-warn, .warn {
    background: #fff8e1; border-color: #f39c12; color: #856404;
    padding: 11px 14px; border-radius: 6px; border-left: 4px solid #f39c12;
}
.flash-info    { background: #d1ecf1; border-color: #17a2b8; color: #0c5460; }

/* ===================== STATS / TILES ===================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin: 16px 0;
}
.stat {
    background: #f8f9fb;
    border-radius: 8px;
    padding: 18px;
    text-align: center;
    border: 1px solid #eef0f5;
}
.stat .num {
    display: block;
    font-size: 32px;
    font-weight: 700;
    color: #1f3a93;
    line-height: 1;
    margin-bottom: 6px;
}
.stat span:not(.num) {
    font-size: 12px;
    color: #7f8c8d;
    text-transform: uppercase;
    letter-spacing: .5px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 14px;
    margin: 14px 0;
}
.tile {
    background: #fff;
    border: 1px solid #eef0f5;
    border-radius: 8px;
    padding: 18px;
    text-decoration: none;
    color: inherit;
    transition: transform .12s, box-shadow .12s;
    display: block;
}
.tile:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,.08);
    text-decoration: none;
}
.tile.disabled {
    opacity: .55;
    cursor: not-allowed;
}
.tile h3 { margin-top: 0; border: 0; padding: 0; }
.tile p { margin: 6px 0 0; color: #7f8c8d; font-size: 13px; }

/* ===== Admin area (Milestone 2) ===== */
.admin-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 20px;
    align-items: start;
    transition: grid-template-columns .22s ease;
}
.admin-layout.sidebar-collapsed {
    grid-template-columns: 54px 1fr;
}
.admin-sidebar {
    background: #fff;
    border: 1px solid #eef0f5;
    border-radius: 8px;
    padding: 18px;
    position: sticky;
    top: 16px;
    overflow: hidden;
    transition: padding .22s ease;
}
.admin-layout.sidebar-collapsed .admin-sidebar {
    padding: 12px 6px;
    overflow: visible;
}

/* ── Toggle button ── */
.admin-sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    margin-bottom: 10px;
}
.admin-layout.sidebar-collapsed .admin-sidebar-toggle {
    justify-content: center;
    margin-bottom: 12px;
}
.admin-sidebar-toggle button {
    background: none;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 14px;
    color: #6b7280;
    line-height: 1;
    transition: background .12s, color .12s;
}
.admin-sidebar-toggle button:hover {
    background: #f4f6fa;
    color: #F47920;
}

.admin-sidebar-title {
    margin: 0 0 12px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #7f8c8d;
    border: 0;
    padding: 0;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity .18s, max-height .18s;
}
.admin-layout.sidebar-collapsed .admin-sidebar-title {
    opacity: 0;
    max-height: 0;
    margin: 0;
}
.admin-menu {
    list-style: none;
    padding: 0;
    margin: 0 0 16px;
}
.admin-menu li {
    margin: 2px 0;
}
.admin-menu li a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 6px;
    color: #2c3e50;
    text-decoration: none;
    transition: background .12s;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
}
.admin-layout.sidebar-collapsed .admin-menu li a {
    padding: 9px 0;
    justify-content: center;
    gap: 0;
}
.admin-menu li a:hover {
    background: #f4f6fa;
    text-decoration: none;
}
.admin-menu li.is-active a {
    background: #F47920;
    color: #fff;
    font-weight: 600;
}
.admin-menu-icon { font-size: 16px; line-height: 1; width: 20px; text-align: center; flex-shrink: 0; }
.admin-menu-label { transition: opacity .15s, width .15s; overflow: hidden; }
.admin-layout.sidebar-collapsed .admin-menu-label {
    opacity: 0;
    width: 0;
    display: none;
}

/* ── Tooltip icon-mode: si applica a TUTTE le sidebar (admin e non-admin) ── */
.admin-menu li { position: relative; }
.admin-layout.sidebar-collapsed .admin-menu li a[data-label]::after {
    content: attr(data-label);
    position: absolute;
    left: 52px;
    top: 50%;
    transform: translateY(-50%);
    background: #1e293b;
    color: #fff;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s .1s;
    z-index: 9999;
    box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.admin-layout.sidebar-collapsed .admin-menu li a[data-label]:hover::after {
    opacity: 1;
}
.admin-sidebar-back {
    margin: 12px 0 0;
    padding-top: 12px;
    border-top: 1px solid #eef0f5;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity .18s;
}
.admin-layout.sidebar-collapsed .admin-sidebar-back {
    opacity: 0;
    pointer-events: none;
    border-top: none;
    margin: 0;
    padding: 0;
}
.admin-sidebar-back a { color: #7f8c8d; text-decoration: none; }
.admin-sidebar-back a:hover { color: #F47920; }
.admin-content { min-width: 0; }
.admin-header { margin-bottom: 18px; }
.admin-header h1 { margin: 0 0 4px; }
.admin-subtitle { color: #7f8c8d; margin: 0; }
.admin-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
    margin-top: 20px;
}
.quick-links { list-style: none; padding: 0; margin: 0; }
.quick-links li { padding: 6px 0; }
.quick-links li a { color: #1f3a93; text-decoration: none; }
.quick-links li a:hover { text-decoration: underline; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.badge-success { background: #e8f5e9; color: #2e7d32; }
.badge-warning { background: #fff3e0; color: #ef6c00; }
.badge-danger  { background: #ffebee; color: #c62828; }
.badge-info    { background: #e3f2fd; color: #1565c0; }
.badge-primary { background: #eef2ff; color: #1f3a93; }
.text-muted { color: #7f8c8d; }
.text-center { text-align: center; }

@media (max-width: 900px) {
    .admin-layout { grid-template-columns: 1fr; }
    .admin-sidebar { position: static; }
}

/* ===== Admin: tabelle e form (M2 task #4) ===== */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid #eef0f5;
    vertical-align: middle;
}
.data-table th {
    background: #f8f9fc;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: #5a6877;
}
.data-table tbody tr:hover { background: #fafbfd; }
.data-table .actions-col { white-space: nowrap; text-align: right; }
.role-badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 11px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.role-admin     { background: #fff3e0; color: #ef6c00; }
.role-sales     { background: #e3f2fd; color: #1565c0; }
.role-pre_sales { background: #e8eaf6; color: #3949ab; }
.role-plan      { background: #f3e5f5; color: #7b1fa2; }

.admin-filter {
    display: flex;
    gap: 10px;
    margin: 12px 0 16px;
    flex-wrap: wrap;
    align-items: center;
}
.admin-filter input[type=text],
.admin-filter select {
    padding: 7px 10px;
    border: 1px solid #d6dae3;
    border-radius: 6px;
    font-size: 14px;
}

/* Bottoni icona compatti */
.btn-icon {
    display: inline-block;
    padding: 4px 9px;
    margin: 0 1px;
    background: transparent;
    border: 1px solid #d6dae3;
    border-radius: 6px;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    color: #2c3e50;
    text-decoration: none;
    transition: all .12s;
}
.btn-icon:hover { background: #f4f6fa; border-color: #1f3a93; color: #1f3a93; text-decoration: none; }
.btn-icon-danger:hover { background: #ffebee; border-color: #c62828; color: #c62828; }

/* Form layout */
.form-row { margin-bottom: 14px; display: flex; flex-direction: column; }
.form-row label { font-size: 13px; font-weight: 600; color: #34495e; margin-bottom: 5px; }
.form-row input[type=text],
.form-row input[type=email],
.form-row input[type=password],
.form-row input[type=number],
.form-row select,
.form-row textarea {
    padding: 9px 11px;
    border: 1px solid #d6dae3;
    border-radius: 6px;
    font-size: 14px;
    font-family: inherit;
}
.form-row input[readonly], .form-row select[disabled] { background: #f4f6fa; color: #7f8c8d; }
.form-row textarea { min-height: 90px; resize: vertical; }
.field-error { color: #c62828; font-size: 12px; margin-top: 4px; }
.form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { margin-top: 18px; display: flex; gap: 10px; }
.check-inline { display: flex; align-items: center; gap: 8px; font-weight: 500; }

.flash-info { background: #e3f2fd; color: #0d47a1; border-left: 4px solid #1976d2; padding: 10px 14px; margin-bottom: 14px; border-radius: 4px; }
.flash-warning { background: #fff3e0; color: #ef6c00; border-left: 4px solid #ef6c00; padding: 10px 14px; margin-bottom: 14px; border-radius: 4px; }

/* Skill radio buttons (1-5 livelli) */
.skill-radio { display: flex; gap: 8px; flex-wrap: wrap; }
.skill-option input[type=radio] { display: none; }
.skill-option .skill-level,
.skill-option .skill-none {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 38px;
    height: 38px;
    border-radius: 6px;
    border: 1px solid #d6dae3;
    background: #fff;
    cursor: pointer;
    font-weight: 700;
    transition: all .12s;
}
.skill-option:hover .skill-level,
.skill-option:hover .skill-none { border-color: #1f3a93; }
.skill-option input[type=radio]:checked + .skill-none { background: #f4f6fa; border-color: #5a6877; color: #5a6877; }
.skill-option input[type=radio]:checked + .skill-level-1 { background: #ffebee; border-color: #c62828; color: #c62828; }
.skill-option input[type=radio]:checked + .skill-level-2 { background: #fff3e0; border-color: #ef6c00; color: #ef6c00; }
.skill-option input[type=radio]:checked + .skill-level-3 { background: #fffde7; border-color: #f9a825; color: #f9a825; }
.skill-option input[type=radio]:checked + .skill-level-4 { background: #e8f5e9; border-color: #2e7d32; color: #2e7d32; }
.skill-option input[type=radio]:checked + .skill-level-5 { background: #1f3a93; border-color: #1f3a93; color: #fff; }

@media (max-width: 700px) {
    .form-grid-2 { grid-template-columns: 1fr; }
}

/* ===== Admin: tabs bar (M2 task #6) ===== */
.tabs-bar, .tab-nav {
    display: flex;
    gap: 2px;
    margin-bottom: 20px;
    border-bottom: 2px solid #e2e6ea;
    flex-wrap: wrap;
    padding: 0;
}
.tabs-bar .tab, .tab-nav .tab-link {
    padding: 10px 20px;
    text-decoration: none;
    color: #6c757d;
    font-weight: 600;
    font-size: 14px;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border-radius: 4px 4px 0 0;
    transition: color .15s, border-color .15s, background .15s;
    white-space: nowrap;
}
.tabs-bar .tab:hover, .tab-nav .tab-link:hover {
    color: #1f3a93;
    background: #f0f4ff;
    text-decoration: none;
}
.tabs-bar .tab.is-active, .tab-nav .tab-link.is-active {
    color: #1f3a93;
    background: #f0f4ff;
    border-bottom-color: #1f3a93;
    font-weight: 700;
}
.tabs-bar .tab-count {
    display: inline-block;
    background: #e2e6ea;
    color: #6c757d;
    border-radius: 10px;
    padding: 1px 8px;
    font-size: 11px;
    font-weight: 700;
}
.tabs-bar .tab.is-active .tab-count {
    background: #1f3a93;
    color: #fff;
}

/* Code inline (per valori min/max) */
.data-table code {
    background: #f4f6fa;
    padding: 2px 7px;
    border-radius: 4px;
    font-family: 'SFMono-Regular', Menlo, Consolas, monospace;
    font-size: 12px;
    color: #2c3e50;
}

/* ===== Admin: SMTP (M2 task #7) ===== */
.smtp-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 20px;
    align-items: start;
}
.smtp-test-card {
    background: #fafbfd;
    border: 1px dashed #c8cdd9;
}
.smtp-test-card h3 { color: #1f3a93; }

@media (max-width: 1000px) {
    .smtp-grid { grid-template-columns: 1fr; }
}

/* ===== Admin: Templates email (M2 task #8) ===== */
.templates-legend {
    display: flex;
    gap: 18px;
    flex-wrap: wrap;
    margin-top: 8px;
    font-size: 13px;
}
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(420px, 1fr));
    gap: 18px;
    margin-top: 8px;
}
.template-card {
    background: #fff;
    border: 1px solid #e2e6ee;
    border-radius: 8px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.template-card-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    margin-bottom: 6px;
}
.template-card-head h3 {
    margin: 0;
    font-size: 16px;
    color: #1f3a93;
}
.template-key {
    background: #f4f6fa;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    color: #6c7a89;
    font-family: 'SFMono-Regular', Menlo, Consolas, monospace;
}
.template-desc {
    color: #4a5568;
    font-size: 13px;
    margin: 6px 0;
}
.template-recipients {
    font-size: 12px;
    color: #6c7a89;
    margin: 6px 0 12px;
}
.template-langs {
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-top: 1px solid #eef0f5;
    padding-top: 10px;
}
.template-lang-row {
    display: grid;
    grid-template-columns: 38px auto 30px 1fr;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 5px;
    text-decoration: none;
    color: #2c3e50;
    transition: background 0.12s;
}
.template-lang-row:hover {
    background: #f4f6fa;
}
.lang-code {
    font-weight: 700;
    font-size: 13px;
    color: #1f3a93;
}
.lang-tag {
    font-size: 10px;
    background: #ffd866;
    color: #5a4500;
    padding: 1px 6px;
    border-radius: 3px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.lang-subject {
    font-size: 12px;
    color: #5a6772;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Editor form */
.template-editor-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 360px;
    gap: 18px;
    align-items: start;
    margin-top: 8px;
}
.template-editor-main { min-width: 0; }
.code-area {
    font-family: 'SFMono-Regular', Menlo, Consolas, monospace;
    font-size: 13px;
    line-height: 1.5;
    width: 100%;
    box-sizing: border-box;
}
.template-editor-side .card { margin-bottom: 14px; padding: 14px 16px; }
.merge-fields-card h4,
.preview-card h4 {
    margin: 0 0 8px;
    color: #1f3a93;
    font-size: 14px;
}
.merge-fields-list {
    list-style: none;
    padding: 0;
    margin: 0;
    max-height: 320px;
    overflow-y: auto;
}
.merge-fields-list li {
    padding: 6px 0;
    border-bottom: 1px solid #f0f2f6;
    font-size: 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.merge-fields-list li:last-child { border-bottom: 0; }
.merge-field-chip {
    background: #f4f6fa;
    border: 1px solid #d6dbe5;
    border-radius: 4px;
    padding: 3px 8px;
    cursor: pointer;
    font-size: 12px;
    align-self: flex-start;
    transition: background 0.15s;
}
.merge-field-chip:hover {
    background: #e7ecf5;
    border-color: #1f3a93;
}
.merge-field-chip code {
    background: transparent;
    color: #1f3a93;
    padding: 0;
    font-weight: 600;
}
.merge-field-auto {
    background: #fff8e1;
    padding: 6px 8px !important;
    border-radius: 4px;
    border-bottom: 0 !important;
}
.preview-subject {
    background: #f4f6fa;
    padding: 6px 10px;
    border-radius: 4px;
    font-size: 13px;
}
.preview-subject strong { color: #1f3a93; word-break: break-word; }

@media (max-width: 1100px) {
    .template-editor-grid { grid-template-columns: 1fr; }
    .template-editor-side { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
    .template-editor-side .card { margin-bottom: 0; }
}
@media (max-width: 700px) {
    .template-editor-side { grid-template-columns: 1fr; }
    .template-lang-row { grid-template-columns: 32px auto 28px 1fr; }
}

/* ===== Admin: Sections + Fields (M2 task #9) ===== */

/* Sotto-menu nella sidebar per le fasi delle sezioni */
.admin-menu-group {
    margin-top: 4px;
}
.admin-menu-group-label {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    font-size: 13px;
    font-weight: 600;
    color: #5a6772;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
    overflow: hidden;
}
.admin-layout.sidebar-collapsed .admin-menu-group-label {
    justify-content: center;
    padding: 9px 0;
    gap: 0;
}
.admin-layout.sidebar-collapsed .admin-menu-group-label .admin-menu-label { display: none; }
.admin-menu-group-label .admin-menu-icon { font-size: 16px; line-height: 1; width: 20px; text-align: center; }
.admin-submenu {
    list-style: none;
    padding: 0;
    margin: 2px 0 0;
    overflow: hidden;
    transition: opacity .15s;
}
.admin-layout.sidebar-collapsed .admin-submenu {
    display: none;
}
.admin-submenu li { margin: 1px 0; }
.admin-submenu li a {
    display: block;
    padding: 6px 12px 6px 38px;
    font-size: 13px;
    color: #2c3e50;
    text-decoration: none;
    border-radius: 5px;
    transition: background .12s;
}
.admin-submenu li a:hover { background: #f4f6fa; }
.admin-submenu li.is-active a {
    background: #1f3a93;
    color: #fff;
    font-weight: 600;
}

/* Indicatori lingua nelle tabelle (sezioni e campi) */
.lang-flags {
    display: flex;
    gap: 3px;
    flex-wrap: wrap;
}
.lang-flag {
    display: inline-block;
    min-width: 26px;
    padding: 2px 5px;
    text-align: center;
    border-radius: 3px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    border: 1px solid transparent;
}
.lang-flag.lang-on {
    background: #d7f5e3;
    color: #1e6e3a;
    border-color: #a8e5bf;
}
.lang-flag.lang-off {
    background: #f4f6fa;
    color: #b0b6c0;
    border-color: #e2e6ee;
}

/* Counter cliccabile (numero campi → link a fields page) */
.link-counter {
    color: #1f3a93;
    text-decoration: none;
    font-weight: 600;
    font-size: 13px;
}
.link-counter:hover { text-decoration: underline; }
.link-counter small { font-weight: 400; margin-left: 4px; }

/* Bottoni small (riusato nelle azioni di riga) */
.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    line-height: 1.4;
}

/* Tasto disabilitato visivamente nelle tabelle */
.data-table button[disabled],
.data-table .btn-danger[disabled] {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ===================== WIZARD RICHIESTA (M3) ===================== */
.wizard-wrap { max-width: 820px; margin: 0 auto; }

/* Progress bar */
.wizard-progress {
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    margin-bottom: 28px;
    gap: 0;
}
.wizard-step-dot {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    position: relative;
    z-index: 1;
}
.wizard-step-dot::before {
    content: '';
    position: absolute;
    top: 16px;
    left: -50%;
    width: 100%;
    height: 2px;
    background: #d0d7e0;
    z-index: -1;
}
.wizard-step-dot:first-child::before { display: none; }
.wizard-step-dot.done::before,
.wizard-step-dot.active::before { background: #1f3a93; }

.wizard-dot-circle {
    width: 32px; height: 32px;
    border-radius: 50%;
    border: 2px solid #d0d7e0;
    background: #fff;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; color: #7f8c8d;
    margin-bottom: 6px;
}
.wizard-step-dot.done .wizard-dot-circle {
    background: #1f3a93; border-color: #1f3a93; color: #fff;
}
.wizard-step-dot.active .wizard-dot-circle {
    background: #fff; border-color: #1f3a93; color: #1f3a93;
    box-shadow: 0 0 0 3px rgba(31,58,147,.15);
}
.wizard-dot-label {
    font-size: 11px; color: #7f8c8d; text-align: center; line-height: 1.3;
    max-width: 80px;
}
.wizard-step-dot.active .wizard-dot-label { color: #1f3a93; font-weight: 600; }
.wizard-step-dot.done .wizard-dot-label  { color: #1f3a93; }

/* Sezione indirizzo (2 colonne) */
.wizard-address-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    margin-bottom: 16px;
}
.wizard-address-block { border: 1px solid #e9ecef; border-radius: 8px; padding: 16px; }
.wizard-address-block h3 { margin-top: 0; }

/* Prodotti step 4 */
.wizard-product-card {
    border: 1px solid #d0d7e0;
    border-radius: 8px;
    margin-bottom: 16px;
    overflow: hidden;
}
.wizard-product-card-header {
    background: #f4f6fa;
    padding: 10px 16px;
    display: flex; align-items: center; gap: 10px;
    cursor: pointer;
    user-select: none;
}
.wizard-product-card-header input[type=checkbox] { width: 18px; height: 18px; }
.wizard-product-card-header label { font-weight: 600; margin: 0; cursor: pointer; }
.wizard-product-body {
    padding: 16px;
    display: none;
}
.wizard-product-body.open { display: block; }
.wizard-dates-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 12px;
}
.wizard-date-slot { border: 1px solid #e9ecef; border-radius: 6px; padding: 10px; }
.wizard-date-slot small { display: block; font-weight: 600; color: #34495e; margin-bottom: 6px; }

/* Review step 5 */
.review-section { margin-bottom: 20px; }
.review-section h3 { color: #1f3a93; }
.review-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.review-table td { padding: 6px 10px; border-bottom: 1px solid #f0f2f7; vertical-align: top; }
.review-table td:first-child { font-weight: 600; color: #34495e; width: 38%; }
.review-badge {
    display: inline-block;
    padding: 2px 10px; border-radius: 12px;
    font-size: 12px; font-weight: 600;
    background: #eef2ff; color: #1f3a93;
}

/* Step custom fields */
.wizard-custom-section { margin-bottom: 20px; }
.wizard-custom-section h3 { font-size: 14px; }

/* Navigazione wizard */
.wizard-nav {
    display: flex; justify-content: space-between; align-items: center;
    margin-top: 24px; padding-top: 16px;
    border-top: 1px solid #e9ecef;
}
.wizard-nav .btn-ghost {
    background: none; border: none; color: #7f8c8d;
    cursor: pointer; font-size: 13px; padding: 8px 0;
}
.wizard-nav .btn-ghost:hover { color: #2c3e50; }

@media (max-width: 640px) {
    .wizard-address-grid { grid-template-columns: 1fr; }
    .wizard-dates-grid   { grid-template-columns: 1fr; }
    .wizard-dot-label    { display: none; }
}

/* ===================== DETTAGLIO RICHIESTA (M3) ===================== */

/* Layout 2 colonne: dati (70%) + log stati (30%) */
.show-grid {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    align-items: start;
}
@media (max-width: 900px) {
    .show-grid { grid-template-columns: 1fr; }
}

/* Pulsante annulla (rosso) */
.btn-danger {
    background: #e74c3c;
    color: #fff;
    border: none;
    padding: 9px 18px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
}
.btn-danger:hover { background: #c0392b; }

/* Timeline log stati */
.timeline {
    list-style: none;
    margin: 0;
    padding: 0;
}
.timeline-item {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    position: relative;
}
.timeline-item:not(:last-child)::after {
    content: '';
    position: absolute;
    left: 7px;
    top: 20px;
    bottom: -10px;
    width: 2px;
    background: #e9ecef;
}
.timeline-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #1f3a93;
    border: 2px solid #fff;
    box-shadow: 0 0 0 2px #1f3a93;
    flex-shrink: 0;
    margin-top: 3px;
}
.timeline-body { flex: 1; }

/* ===================== RESPONSIVE (M7) ===================== */

/* Hamburger: nascosto su desktop */
.hamburger { display: none; }

/* ================================================================
   BREAKPOINT ≤ 820px  — tablet / mobile
   ================================================================ */
@media (max-width: 820px) {

    /* --- Topbar --- */
    .topbar {
        flex-wrap: wrap;      /* permette al topnav di andare a capo */
        height: auto;
        padding: 0;
    }
    .topbar .brand {
        flex: 1;
        padding: 0 14px;
        min-height: 52px;
        display: flex;
        align-items: center;
    }
    .tenant-badge { display: none; }

    /* Hamburger visibile su mobile */
    .hamburger {
        display: flex;
        align-items: center;
        justify-content: center;
        background: rgba(255,255,255,.15);
        border: 1px solid rgba(255,255,255,.3);
        color: #fff;
        font-size: 20px;
        line-height: 1;
        width: 38px;
        height: 38px;
        border-radius: 6px;
        cursor: pointer;
        flex-shrink: 0;
        margin-right: 12px;
        transition: background .15s;
    }
    .hamburger:hover { background: rgba(255,255,255,.28); }

    /* topnav: nascosto, appare come drawer sotto la topbar */
    .topnav {
        display: none;
        order: 10;
        width: 100%;
        flex-direction: column;
        background: #162a6e;
        border-top: 1px solid rgba(255,255,255,.15);
    }
    .topnav.mob-open { display: flex; }
    .topnav a {
        margin: 0;
        padding: 12px 20px;
        font-size: 15px;
        border-bottom: 1px solid rgba(255,255,255,.07);
        opacity: 1;
    }
    .topnav a:last-child { border-bottom: none; }

    /* user-menu: nascosto su mobile, appare come drawer */
    .user-menu {
        display: none;
        order: 11;
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 10px;
        padding: 10px 18px 12px;
        background: #13236a;
        border-top: 1px solid rgba(255,255,255,.12);
    }
    .user-menu.mob-open { display: flex; }

    /* App main */
    .app-main { padding: 10px 12px; }
    .flashes { padding: 0 12px; margin-top: 8px; }

    /* Cards */
    .card { padding: 14px 16px; }

    /* Tables: scroll orizzontale */
    .card:has(.data-table) {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        padding: 0;
    }
    .data-table { min-width: 520px; }
    .data-table th, .data-table td { padding: 8px 10px; }

    /* Filtri: stack verticale */
    .admin-filter { flex-direction: column; align-items: stretch; }
    .admin-filter input[type=text],
    .admin-filter select,
    .admin-filter button { width: 100%; }

    /* Layout vari */
    .row-between { flex-direction: column; align-items: flex-start; gap: 8px; }
    .admin-header { flex-wrap: wrap; }
    .grid-2, .grid-4 { grid-template-columns: 1fr; }
    .form-grid-2 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .admin-layout { gap: 14px; }
    .admin-sidebar { padding: 12px; }
    .admin-menu li a { padding: 8px 10px; }
    .btn-primary, .btn-secondary { font-size: 13px; padding: 8px 14px; }
    .col-hide-mob { display: none !important; }
}

/* ================================================================
   BREAKPOINT ≤ 480px  — smartphone portrait stretto
   ================================================================ */
@media (max-width: 480px) {
    h1 { font-size: 18px; }
    .app-main { padding: 8px 10px; }
    .card { padding: 12px; }
    .stats-grid { grid-template-columns: 1fr; }
    .brand a { font-size: 14px; }
    .wizard-dot-label { display: none; }
    .tabs-bar .tab { padding: 8px 12px; font-size: 13px; }
}
