:root {
    --bg: #f4f7fb;
    --card: #ffffff;
    --text: #172033;
    --muted: #6b7280;
    --line: #e5e7eb;
    --primary: #1f6feb;
    --primary-dark: #184ea8;
    --green: #0f9f6e;
    --red: #d64545;
    --yellow: #b7791f;
    --blue-soft: #eaf2ff;
    --shadow: 0 18px 45px rgba(15, 23, 42, .08);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: Inter, Segoe UI, Arial, sans-serif;
    color: var(--text);
    background: linear-gradient(135deg, #eef4ff 0%, #f8fafc 42%, #eefbf6 100%);
}

a { color: inherit; text-decoration: none; }
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
    width: 265px;
    padding: 24px 18px;
    background: #0f172a;
    color: #fff;
    position: sticky;
    top: 0;
    height: 100vh;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 28px; }
.brand-mark {
    width: 46px; height: 46px; border-radius: 14px;
    background: linear-gradient(135deg, #60a5fa, #34d399);
    display: grid; place-items: center; font-weight: 800;
}
.brand span { display: block; color: #a5b4fc; font-size: 12px; margin-top: 3px; }
.sidebar nav { display: grid; gap: 8px; }
.sidebar a {
    padding: 12px 14px;
    border-radius: 12px;
    color: #cbd5e1;
}
.sidebar a:hover, .sidebar a.active { background: rgba(255,255,255,.10); color: #fff; }
.main { flex: 1; padding: 28px; }
.topbar { display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; margin-bottom: 22px; }
.topbar h1 { margin: 0 0 6px; font-size: 30px; }
.topbar p { margin: 0; color: var(--muted); }
.grid { display: grid; gap: 18px; }
.grid.cards { grid-template-columns: repeat(4, minmax(160px, 1fr)); }
.card {
    background: rgba(255,255,255,.88);
    border: 1px solid rgba(229,231,235,.9);
    border-radius: 22px;
    padding: 20px;
    box-shadow: var(--shadow);
}
.metric strong { font-size: 30px; display: block; margin-bottom: 5px; }
.metric span { color: var(--muted); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.btn {
    border: 0;
    background: var(--primary);
    color: #fff;
    border-radius: 12px;
    padding: 10px 14px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #e5e7eb; color: #111827; }
.btn.danger { background: var(--red); }
.btn.ok { background: var(--green); }
.btn.small { padding: 7px 10px; border-radius: 10px; font-size: 13px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: #475569; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: rgba(31,111,235,.035); }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(220px, 1fr)); gap: 14px; }
.form-grid .full { grid-column: 1 / -1; }
label { display: grid; gap: 7px; color: #334155; font-weight: 700; font-size: 14px; }
input, select, textarea {
    width: 100%;
    border: 1px solid #d1d5db;
    border-radius: 12px;
    padding: 11px 12px;
    background: #fff;
    font: inherit;
}
textarea { min-height: 92px; resize: vertical; }
.help { color: var(--muted); font-size: 13px; }
.badge {
    display: inline-flex;
    padding: 6px 10px;
    border-radius: 999px;
    background: #e5e7eb;
    color: #374151;
    font-size: 12px;
    font-weight: 800;
}
.badge.ok { background: #dcfce7; color: #166534; }
.badge.danger { background: #fee2e2; color: #991b1b; }
.badge.warn { background: #fef3c7; color: #92400e; }
.badge.blue { background: #dbeafe; color: #1e40af; }

.badge.tipo-riparazione.interna { background: #dbeafe; color: #1e40af; }
.badge.tipo-riparazione.esterna { background: #fef3c7; color: #92400e; }
.preventivo-type-box {
    grid-column: 1 / -1;
    border: 1px solid #bfdbfe;
    border-radius: 14px;
    padding: 12px 14px;
    background: #eff6ff;
    color: #1e3a8a;
    font-size: 13px;
    line-height: 1.45;
}
.preventivo-type-box.esterna { background: #fff7ed; border-color: #fed7aa; color: #92400e; }
.preventivo-type-box.muted { background: #f8fafc; border-color: #e5e7eb; color: #64748b; }
.preventivo-type-box strong { display: inline-block; margin-right: 6px; }
.tipo-preventivo-line { margin-top: 8px; }
.quote-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(230px, 1fr));
    gap: 16px;
}
.total-box {
    border-radius: 22px;
    padding: 22px;
    background: var(--blue-soft);
    border: 1px solid #bfdbfe;
}
.total-box.reject { background: #fff7ed; border-color: #fed7aa; }
.total-box strong { font-size: 34px; display: block; margin-top: 8px; }
.notice {
    border-radius: 16px;
    padding: 14px 16px;
    background: #ecfdf5;
    border: 1px solid #bbf7d0;
    color: #166534;
    margin-bottom: 16px;
}
.notice-soft {
    border-radius: 14px;
    padding: 12px 14px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    color: #1e3a8a;
    margin: 10px 0 16px;
    font-size: 13px;
    line-height: 1.45;
}
.checkline { display: flex; gap: 8px; align-items: center; font-weight: 600; }
.checkline input { width: auto; }
.print-only { display: none; }
@media (max-width: 900px) {
    .app-shell { display: block; }
    .sidebar { width: auto; height: auto; position: relative; }
    .sidebar nav { grid-template-columns: repeat(2, 1fr); }
    .grid.cards, .form-grid, .quote-summary { grid-template-columns: 1fr; }
    .main { padding: 18px; }
}
@media print {
    body { background: #fff; }
    .sidebar, .actions, .no-print { display: none !important; }
    .main { padding: 0; }
    .card { box-shadow: none; border: 0; padding: 0; }
    .print-only { display: block; }
}


.company-document-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
    padding: 0 0 18px;
    margin-bottom: 20px;
    border-bottom: 2px solid #0057b8;
}
.company-brand {
    display: flex;
    align-items: center;
    gap: 16px;
}
.company-logo {
    width: 150px;
    max-height: 70px;
    object-fit: contain;
    flex: 0 0 auto;
}
.company-document-header h1 {
    margin: 0 0 6px;
    font-size: 24px;
}
.company-document-header p {
    margin: 0;
    color: var(--muted);
}
.company-data {
    min-width: 250px;
    text-align: right;
    font-size: 13px;
    line-height: 1.45;
    color: #111827;
}
.company-data strong {
    font-size: 14px;
}

/* Documento preventivo con doppia ipotesi economica */
.document-heading {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 18px;
}
.document-heading h2 { margin-top: 0; }
.document-date {
    color: var(--muted);
    font-weight: 700;
    white-space: nowrap;
}
.quote-info-grid {
    grid-template-columns: repeat(2, minmax(240px, 1fr));
    margin-top: 22px;
}
.diagnosis-grid {
    border-top: 1px solid var(--line);
    padding-top: 18px;
}
.quote-option {
    margin-top: 26px;
    border: 1px solid var(--line);
    border-radius: 22px;
    overflow: hidden;
    background: #fff;
}
.quote-option-head {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 20px;
    background: #f8fafc;
    border-bottom: 1px solid var(--line);
}
.quote-option-head h2 { margin: 0 0 5px; }
.quote-option-head p { margin: 0; color: var(--muted); }
.quote-option-head strong {
    font-size: 28px;
    white-space: nowrap;
}
.accept-option .quote-option-head { background: #ecfdf5; }
.reject-option .quote-option-head { background: #fff7ed; }
.quote-table tfoot td {
    font-weight: 800;
    background: #f8fafc;
}
.quote-table tfoot .grand-total td {
    font-size: 18px;
    color: var(--text);
}
.internal-detail {
    margin-top: 26px;
    padding-top: 16px;
    border-top: 1px dashed #cbd5e1;
}

.quote-deadline {
    color: var(--red);
    font-weight: 800;
    margin: 12px 0 0;
}

.choice-box {
    margin-top: 28px;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 18px;
    background: #f8fafc;
}
.choice-box h2 { margin-top: 0; }
.choice-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.choice-grid label {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    font-weight: 700;
}
.square {
    width: 18px;
    height: 18px;
    border: 2px solid #111827;
    display: inline-block;
    flex: 0 0 auto;
    margin-top: 1px;
}
.signature-grid {
    margin-top: 45px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 60px;
}

@media (max-width: 900px) {
    .company-document-header { display: block; }
    .company-brand { align-items: flex-start; }
    .company-data { text-align: left; margin-top: 12px; }
    .document-heading, .quote-option-head { display: block; }
    .quote-info-grid, .choice-grid, .signature-grid { grid-template-columns: 1fr; }
    .document-date { margin-top: 8px; }
    .quote-option-head strong { display: block; margin-top: 10px; }
}

@media print {
    @page { size: A4; margin: 12mm; }
    body { font-size: 12px; color: #111827; }
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .quote-deadline,
    .quote-deadline strong {
        color: #d00000 !important;
        font-weight: 800 !important;
    }
    h1 { font-size: 24px; }
    h2 { font-size: 16px; }
    .quote-document { width: 100%; }
    .company-document-header {
        gap: 14px;
        padding-bottom: 10px;
        margin-bottom: 14px;
        border-bottom: 1.5px solid #0057b8;
    }
    .company-logo { width: 120px; max-height: 55px; }
    .company-document-header h1 { font-size: 20px; }
    .company-document-header p, .company-data { font-size: 11px; }
    .document-heading, .quote-summary, .quote-info-grid, .choice-grid, .signature-grid {
        break-inside: avoid;
    }
    .quote-option {
        break-inside: avoid;
        page-break-inside: avoid;
        margin-top: 18px;
        border-radius: 12px;
    }
    .quote-option-head { padding: 12px 14px; }
    .quote-option-head strong { font-size: 20px; }
    .total-box { padding: 12px; border-radius: 12px; }
    .total-box strong { font-size: 22px; }
    th, td { padding: 8px 7px; }
    tr:hover td { background: transparent; }
    .choice-box { break-inside: avoid; }
}

/* Scheda cliente avanzata */
.form-section-title {
    margin-top: 10px;
    padding: 12px 14px;
    border-radius: 14px;
    background: #f8fafc;
    border: 1px solid var(--line);
    color: #0f172a;
    font-weight: 900;
    letter-spacing: .02em;
}
.address-list {
    display: grid;
    gap: 14px;
}
.address-row {
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 14px;
    background: #fbfdff;
}
.address-row-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}
.compact-grid {
    grid-template-columns: repeat(3, minmax(180px, 1fr));
}
@media (max-width: 900px) {
    .compact-grid { grid-template-columns: 1fr; }
    .address-row-head { align-items: flex-start; flex-direction: column; }
}


/* Archivio ricambi */
.two-cols {
    grid-template-columns: repeat(2, minmax(280px, 1fr));
}
.danger-notice {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}
@media (max-width: 900px) {
    .two-cols { grid-template-columns: 1fr; }
}

.small-help { display:block; margin-top:6px; font-size:12px; color:#64748b; }


/* Suggerimenti ricerca cliente in riparazioni/preventivi */
.cliente-search-box {
    position: relative;
    margin-bottom: 8px;
}

.cliente-suggestions {
    position: absolute;
    z-index: 35;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 14px;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.16);
    overflow: hidden;
    max-height: 360px;
    overflow-y: auto;
}

.cliente-suggestion-item {
    width: 100%;
    border: 0;
    background: #ffffff;
    text-align: left;
    padding: 12px 14px;
    display: grid;
    gap: 4px;
    cursor: pointer;
    border-bottom: 1px solid #eef2f7;
    font: inherit;
}

.cliente-suggestion-item:hover,
.cliente-suggestion-item:focus {
    background: #f8fafc;
    outline: none;
}

.cliente-suggestion-item strong {
    color: #0f172a;
    font-size: 14px;
}

.cliente-suggestion-item span {
    color: #475569;
    font-size: 12px;
}

.cliente-suggestion-more {
    padding: 10px 14px;
    background: #f8fafc;
    color: #64748b;
    font-size: 12px;
}

/* Suggerimenti ricerca ricambi nel preventivo */
.ricambio-search-box {
    position: relative;
}

.ricambio-suggestions {
    position: absolute;
    z-index: 30;
    left: 0;
    right: 0;
    top: calc(100% - 14px);
    background: #ffffff;
    border: 1px solid #d1d5db;
    border-radius: 14px;
    box-shadow: 0 18px 45px rgba(15, 23, 42, 0.16);
    overflow: hidden;
    max-height: 360px;
    overflow-y: auto;
}

.ricambio-suggestion-item {
    width: 100%;
    border: 0;
    background: #ffffff;
    text-align: left;
    padding: 12px 14px;
    display: grid;
    gap: 4px;
    cursor: pointer;
    border-bottom: 1px solid #eef2f7;
    font: inherit;
}

.ricambio-suggestion-item:hover,
.ricambio-suggestion-item:focus {
    background: #f8fafc;
    outline: none;
}

.ricambio-suggestion-item strong {
    color: #0f172a;
    font-size: 14px;
}

.ricambio-suggestion-item span {
    color: #475569;
    font-size: 13px;
}

.ricambio-suggestion-item em {
    color: #0f766e;
    font-size: 12px;
    font-style: normal;
    font-weight: 700;
}

.ricambio-suggestion-more {
    padding: 10px 14px;
    background: #f8fafc;
    color: #64748b;
    font-size: 12px;
}

/* Login e ruoli utente */
.user-box {
    margin: -8px 0 20px;
    padding: 13px 14px;
    border-radius: 16px;
    background: rgba(255,255,255,.08);
    color: #e2e8f0;
    display: grid;
    gap: 3px;
}
.user-box span,
.user-box small { color: #94a3b8; font-size: 12px; }
.user-box strong { color: #fff; }
.user-box a {
    margin-top: 6px;
    display: inline-flex;
    width: fit-content;
    padding: 5px 9px;
    border-radius: 9px;
    background: rgba(255,255,255,.10);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
}
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}
.login-card {
    width: min(460px, 100%);
    background: rgba(255,255,255,.92);
    border: 1px solid rgba(229,231,235,.9);
    border-radius: 26px;
    padding: 28px;
    box-shadow: var(--shadow);
}
.login-brand { margin-bottom: 18px; }
.login-brand span { color: var(--muted); }
.login-card h1 { margin: 0 0 8px; }
.login-form { display: grid; gap: 14px; margin-top: 18px; }
.login-form .btn { width: 100%; margin-top: 4px; }
.login-demo { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
@media print {
    .user-box { display: none !important; }
}


/* Permessi utenti */
.permissions-box {
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 16px;
    background: #f8fafc;
}
.permissions-box h3 { margin: 0 0 6px; }
.permissions-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    gap: 10px;
    margin-top: 12px;
}
.permission-item {
    padding: 10px 12px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
}
.permissions-disabled {
    opacity: .65;
}
.success { background: #ecfdf5; border-color: #86efac; color: #166534; }
@media (max-width: 900px) {
    .permissions-grid { grid-template-columns: 1fr; }
}

.company-logo-preview {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    background: #f9fafb;
    margin: 10px 0 18px;
}
.company-logo-preview img {
    max-height: 72px;
    max-width: 220px;
    object-fit: contain;
    background: #ffffff;
    border: 1px solid #eef2f7;
    border-radius: 10px;
    padding: 8px;
}
.notice.danger {
    border-color: #fecaca;
    background: #fff1f2;
    color: #991b1b;
}

.standard-cost-usage-note {
    background: #fff7ed;
    border-color: #fed7aa;
    color: #7c2d12;
}

/* Scheda guidata Riparazioni */
.repair-guided-form {
    display: grid;
    gap: 18px;
    margin-top: 16px;
}
.repair-step {
    border: 1px solid var(--line);
    border-radius: 22px;
    background: #ffffff;
    box-shadow: 0 10px 28px rgba(15, 23, 42, .06);
    overflow: hidden;
}
.repair-step-head {
    display: flex;
    gap: 16px;
    align-items: center;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(229, 231, 235, .9);
    position: relative;
}
.repair-step-head::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 8px;
    background: currentColor;
    opacity: .9;
}
.repair-step-head > div {
    min-width: 0;
}
.repair-step-head h3 {
    margin: 0 0 4px;
    font-size: 1.16rem;
    line-height: 1.2;
    font-weight: 800;
    letter-spacing: .01em;
    color: #0f172a;
}
.repair-step-head p {
    margin: 0;
    color: var(--muted);
    line-height: 1.4;
    font-size: .94rem;
}
.repair-step-number {
    width: 58px;
    height: 58px;
    flex: 0 0 58px;
    border-radius: 18px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 900;
    font-size: 1.55rem;
    line-height: 1;
    color: #ffffff;
    background: #2563eb;
    box-shadow: 0 10px 22px rgba(37, 99, 235, .28), inset 0 -3px 0 rgba(0,0,0,.12);
    border: 3px solid rgba(255,255,255,.88);
    position: relative;
    z-index: 1;
    text-shadow: 0 1px 0 rgba(0,0,0,.18);
}
.repair-step-status {
    margin-left: auto;
    white-space: nowrap;
    font-size: .8rem;
    font-weight: 800;
    padding: 8px 12px;
    border-radius: 999px;
    color: #334155;
    background: rgba(255,255,255,.92);
    border: 1px solid rgba(148, 163, 184, .26);
    box-shadow: 0 2px 10px rgba(15, 23, 42, .05);
}
.repair-step-body {
    padding: 18px 20px 20px;
}
.repair-step .card.soft {
    box-shadow: none;
}
.repair-step-blue .repair-step-head { background: linear-gradient(90deg, #dbeafe 0%, #eff6ff 68%); color: #2563eb; }
.repair-step-blue .repair-step-number { background: linear-gradient(135deg, #2563eb, #1d4ed8); }
.repair-step-orange .repair-step-head { background: linear-gradient(90deg, #ffedd5 0%, #fff7ed 68%); color: #ea580c; }
.repair-step-orange .repair-step-number { background: linear-gradient(135deg, #f97316, #ea580c); }
.repair-step-green .repair-step-head { background: linear-gradient(90deg, #dcfce7 0%, #ecfdf5 68%); color: #16a34a; }
.repair-step-green .repair-step-number { background: linear-gradient(135deg, #16a34a, #15803d); }
.repair-step-purple .repair-step-head { background: linear-gradient(90deg, #ede9fe 0%, #f5f3ff 68%); color: #7c3aed; }
.repair-step-purple .repair-step-number { background: linear-gradient(135deg, #7c3aed, #6d28d9); }
.repair-step-final .repair-step-head { background: linear-gradient(90deg, #dcfce7 0%, #f0fdf4 68%); color: #15803d; }
.repair-step-final .repair-step-number { background: linear-gradient(135deg, #15803d, #166534); }
@media (max-width: 720px) {
    .repair-step-head {
        align-items: flex-start;
        flex-wrap: wrap;
    }
    .repair-step-status {
        margin-left: 74px;
    }
    .repair-step-number {
        width: 52px;
        height: 52px;
        flex-basis: 52px;
        font-size: 1.35rem;
        border-radius: 16px;
    }
}
.repair-choice-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(220px, 1fr));
    gap: 14px;
}
.repair-choice-card {
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 14px;
    display: grid;
    gap: 5px;
    background: #f8fafc;
}
.repair-choice-card strong { color: #0f172a; }
.repair-choice-card span { color: var(--muted); }
.repair-choice-card em { font-style: normal; font-weight: 700; }
.repair-choice-card.warning {
    background: #fff7ed;
    border-color: #fed7aa;
}
.repair-choice-card.warning em { color: #9a3412; }
.repair-choice-card.muted em { color: #475569; }
.repair-checklist {
    display: grid;
    grid-template-columns: repeat(2, minmax(220px, 1fr));
    gap: 10px 16px;
}
.repair-checklist .checkline {
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
}
.repair-save-actions {
    padding: 0 18px 18px;
}
@media (max-width: 900px) {
    .repair-step-head { align-items: flex-start; }
    .repair-step-status { display: none; }
    .repair-choice-grid,
    .repair-checklist {
        grid-template-columns: 1fr;
    }
}
