:root {
    --primary: #0072a8;
    --primary-dark: #005985;
    --primary-light: #e0f2fe;
    --secondary: #334155;
    --success: #059669;
    --success-bg: #ecfdf5;
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --warning: #d97706;
    --warning-bg: #fffbeb;
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --border-color: #cbd5e1;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --radius: 12px;
    --shadow: 0 2px 10px rgba(15, 23, 42, 0.06);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    font-size: 16px;
    line-height: 1.5;
    padding-bottom: 40px;
}

/* Top Navbar */
.topbar {
    background: var(--bg-card);
    border-bottom: 2px solid var(--primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-inner {
    max-width: 960px;
    margin: 0 auto;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--text-main);
}

.brand img {
    height: 40px;
    width: auto;
}

.brand-title {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
    line-height: 1.2;
}

.brand-sub {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: block;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.nav-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 13px;
    border-radius: 8px;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--secondary);
    background: #f8fafc;
    border: 1px solid var(--border-color);
    transition: all 0.15s ease;
}

.nav-btn:hover {
    background: var(--primary-light);
    color: var(--primary-dark);
    border-color: var(--primary);
}

.nav-btn.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.nav-btn.logout {
    color: var(--danger);
    border-color: #fecaca;
    background: #fff;
}

.nav-btn.logout:hover {
    background: var(--danger-bg);
}

/* Main Container */
.container {
    max-width: 960px;
    margin: 18px auto;
    padding: 0 14px;
}

/* Cards */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid #e2e8f0;
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 18px;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid #f1f5f9;
}

.card-title {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--primary-dark);
    display: flex;
    align-items: center;
    gap: 8px;
}

.step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 700;
}

/* Form Controls */
.form-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
}

@media (min-width: 640px) {
    .form-grid.cols-2 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .form-grid.cols-3 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
    width: 100%;
}

.form-label {
    font-weight: 600;
    font-size: 0.92rem;
    color: var(--secondary);
}

.form-label .req {
    color: var(--danger);
}

.form-control {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 12px 14px;
    font-size: 1rem;
    font-family: inherit;
    color: var(--text-main);
    background-color: #fff;
    border: 1.5px solid var(--border-color);
    border-radius: 9px;
    transition: border-color 0.15s, box-shadow 0.15s;
    min-height: 46px;
}

input[type="date"].form-control,
input[type="time"].form-control {
    display: inline-flex;
    align-items: center;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    -webkit-appearance: none;
    appearance: none;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(0, 114, 168, 0.15);
}

textarea.form-control {
    min-height: 130px;
    resize: vertical;
}

/* Autocomplete Clienti */
.client-search-wrap {
    position: relative;
}

.client-results {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: #fff;
    border: 1.5px solid var(--primary);
    border-radius: 10px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
    max-height: 300px;
    overflow-y: auto;
    z-index: 90;
    display: none;
}

.client-item {
    padding: 12px 14px;
    border-bottom: 1px solid #f1f5f9;
    cursor: pointer;
    transition: background 0.12s;
}

.client-item:last-child {
    border-bottom: none;
}

.client-item:hover,
.client-item:active {
    background: var(--primary-light);
}

.client-item-title {
    font-weight: 700;
    color: var(--text-main);
    font-size: 0.98rem;
}

.client-item-meta {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.selected-client-card {
    margin-top: 10px;
    padding: 14px;
    background: #f0f9ff;
    border: 1.5px solid #bae6fd;
    border-radius: 10px;
    display: none;
}

.selected-client-card.visible {
    display: block;
}

.selected-client-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 10px;
}

/* Checkboxes & Radio Pills (Programmi & Tipo Addebito) */
.Programmi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
    gap: 10px;
}

.check-pill {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border: 1.5px solid var(--border-color);
    border-radius: 9px;
    cursor: pointer;
    user-select: none;
    background: #fff;
    font-weight: 500;
    transition: all 0.15s;
}

.check-pill input[type="checkbox"],
.check-pill input[type="radio"] {
    width: 20px;
    height: 20px;
    accent-color: var(--primary);
    margin: 0;
    flex-shrink: 0;
}

.check-pill:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
    color: var(--primary-dark);
    font-weight: 600;
}

/* Tipo Addebito Cards */
.addebito-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.addebito-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 16px 12px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    cursor: pointer;
    user-select: none;
    background: #fff;
    transition: all 0.15s;
}

.addebito-card input {
    display: none;
}

.addebito-card .title {
    font-weight: 700;
    font-size: 1rem;
    margin-top: 4px;
}

.addebito-card .desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.addebito-card.assistenza.selected {
    border-color: var(--success);
    background: var(--success-bg);
    color: #065f46;
}

.addebito-card.pagamento.selected {
    border-color: #ea580c;
    background: #fff7ed;
    color: #9a3412;
}

/* Cost & Duration Summary Box */
.duration-box {
    margin-top: 16px;
    padding: 16px;
    border-radius: 10px;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
}

.duration-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}

.stat-item {
    background: #fff;
    padding: 12px;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}

.stat-label {
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
    font-weight: 600;
}

.stat-value {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 4px;
}

.cost-highlight {
    margin-top: 14px;
    padding: 16px;
    border-radius: 10px;
    background: linear-gradient(135deg, #fff7ed 0%, #ffedd5 100%);
    border: 2px solid #fb923c;
    display: none;
}

.cost-highlight.visible {
    display: block;
}

.cost-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.cost-total-amount {
    font-size: 1.65rem;
    font-weight: 800;
    color: #c2410c;
}

/* Signature Canvas */
.signature-wrapper {
    border: 2px dashed #94a3b8;
    border-radius: 10px;
    background: #ffffff;
    position: relative;
    overflow: hidden;
    touch-action: none;
}

.signature-canvas {
    width: 100%;
    height: 220px;
    display: block;
    cursor: crosshair;
    touch-action: none;
}

.signature-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
    color: #cbd5e1;
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
    padding: 12px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 1rem;
    font-weight: 600;
    border-radius: 9px;
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    min-height: 46px;
}

.btn-sm {
    padding: 7px 12px;
    font-size: 0.86rem;
    min-height: 36px;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-success {
    background: var(--success);
    color: #fff;
}

.btn-success:hover {
    background: #047857;
}

.btn-secondary {
    background: #f1f5f9;
    color: var(--secondary);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background: #e2e8f0;
}

.btn-danger {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: #fecaca;
}

.btn-block {
    width: 100%;
}

/* Alerts */
.alert {
    padding: 14px 16px;
    border-radius: 10px;
    margin-bottom: 18px;
    font-weight: 500;
}

.alert-success {
    background: var(--success-bg);
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-danger {
    background: var(--danger-bg);
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-warning {
    background: var(--warning-bg);
    color: #92400e;
    border: 1px solid #fde68a;
}

/* Tables */
.table-responsive {
    width: 100%;
    overflow-x: auto;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.data-table th,
.data-table td {
    padding: 11px 12px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

.data-table th {
    background: #f8fafc;
    color: var(--secondary);
    font-weight: 700;
    white-space: nowrap;
}

.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 700;
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
}

.badge-warning {
    background: #fff7ed;
    color: #c2410c;
}

.badge-muted {
    background: #f1f5f9;
    color: var(--text-muted);
}

/* Time input helper */
.input-with-btn {
    display: flex;
    gap: 6px;
    width: 100%;
    min-width: 0;
}

.input-with-btn .form-control {
    flex: 1 1 0%;
    min-width: 0;
}
