:root {
    --primary: #0c2d4a;
    --primary-light: #1d4a73;
    --accent: #e07820;
    --accent-light: #f3a35c;
    --bg: #f4f6f8;
    --card-bg: #ffffff;
    --border: #d8e0e6;
    --text: #1f2d36;
    --text-light: #5f7585;
    --success: #2e8b57;
    --danger: #c0392b;
    --radius: 8px;
    --shadow: 0 2px 8px rgba(12,45,74,0.08);
}

* { box-sizing: border-box; }

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    line-height: 1.5;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px;
}

header.app-header {
    background: var(--primary);
    color: #fff;
    padding: 20px 0;
    box-shadow: var(--shadow);
}
header.app-header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
header.app-header h1 {
    margin: 0;
    font-size: 1.4rem;
    font-weight: 600;
}
header.app-header .subtitle {
    color: var(--accent-light);
    font-size: 0.85rem;
}

/* Stepper */
.stepper {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 24px 0;
    flex-wrap: wrap;
}
.stepper .step {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 20px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    font-size: 0.85rem;
    color: var(--text-light);
}
.stepper .step.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.stepper .step.done {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}
.stepper .step .num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px; height: 22px;
    border-radius: 50%;
    background: rgba(255,255,255,0.25);
    font-weight: 700;
    font-size: 0.75rem;
}
.stepper .step:not(.active):not(.done) .num {
    background: var(--border);
    color: var(--text-light);
}

/* Card */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 28px;
    margin-bottom: 24px;
}
.card h2 {
    margin-top: 0;
    color: var(--primary);
    font-size: 1.3rem;
    border-bottom: 2px solid var(--border);
    padding-bottom: 12px;
}
.card h3 {
    color: var(--primary-light);
    font-size: 1.05rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 12px 24px;
    border-radius: var(--radius);
    border: none;
    background: var(--accent);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.95rem;
    text-decoration: none;
    transition: background 0.15s ease, transform 0.05s ease;
}
.btn:hover { background: #c8650f; }
.btn:active { transform: scale(0.98); }
.btn.btn-secondary {
    background: var(--border);
    color: var(--text);
}
.btn.btn-secondary:hover { background: #c5d0d8; }
.btn.btn-outline {
    background: transparent;
    border: 2px solid var(--primary);
    color: var(--primary);
}
.btn.btn-outline:hover { background: var(--primary); color: #fff; }
.btn.btn-danger { background: var(--danger); }
.btn.btn-danger:hover { background: #a13325; }
.btn.btn-success { background: var(--success); }
.btn.btn-success:hover { background: #256b43; }
.btn.btn-sm { padding: 6px 14px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-row {
    display: flex;
    justify-content: space-between;
    margin-top: 28px;
    gap: 12px;
    flex-wrap: wrap;
}

/* Forms */
label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.9rem;
    color: var(--primary);
}
input[type=text], input[type=email], input[type=tel], input[type=number],
input[type=password], textarea, select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: #fff;
    color: var(--text);
    font-family: inherit;
}
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(224,120,32,0.15);
}
.form-group { margin-bottom: 18px; }
.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}
.hint {
    font-size: 0.8rem;
    color: var(--text-light);
    margin-top: 4px;
}
fieldset {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}
legend {
    font-weight: 700;
    color: var(--primary);
    padding: 0 8px;
}

/* Choice cards (step 1) */
.choice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 16px;
}
.choice-card {
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}
.choice-card:hover { border-color: var(--accent-light); }
.choice-card.selected {
    border-color: var(--accent);
    background: #fff8f0;
}
.choice-card h3 { margin-top: 0; }
.choice-card input[type=radio] {
    position: absolute;
    top: 20px; right: 20px;
    width: 20px; height: 20px;
}
.choice-card ul { padding-left: 20px; margin: 10px 0 0; font-size: 0.9rem; color: var(--text-light); }
.choice-card .price-tag {
    display: inline-block;
    margin-top: 12px;
    padding: 4px 10px;
    border-radius: 20px;
    background: var(--border);
    font-size: 0.8rem;
    font-weight: 700;
}

/* Matrix table - stile "foglio di calcolo" */
.matrix-wrapper {
    overflow-x: auto;
    margin: 16px 0;
    border-radius: var(--radius);
    background: var(--card-bg);
    -webkit-overflow-scrolling: touch;
}
table.matrix {
    border-collapse: collapse;
    width: 100%;
    font-size: 0.85rem;
    table-layout: fixed;
}
table.matrix th, table.matrix td {
    border: 1px solid var(--border);
    padding: 6px;
    text-align: center;
    vertical-align: middle;
}
table.matrix thead th {
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    vertical-align: middle;
    padding: 8px 4px;
}
table.matrix th.corner {
    background: #f0f4f7;
    color: var(--text);
    vertical-align: middle;
}

/* Colonna sinistra: nome accesso/cilindro + articolo + misure */
table.matrix td.cyl-name-cell, table.matrix th.cyl-name-cell {
    text-align: left;
    background: #f0f4f7;
    position: sticky;
    left: 0;
    z-index: 2;
    width: 200px;
    min-width: 200px;
    box-shadow: 2px 0 0 var(--border);
}
table.matrix th.corner.cyl-name-cell {
    z-index: 3;
}
table.matrix .cyl-row-inner {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
table.matrix .cyl-row-inner input.cyl-name-input-horizontal {
    font-size: 0.85rem;
    font-weight: 700;
    padding: 4px 6px;
    width: 100%;
}
table.matrix .cyl-row-inner select,
table.matrix .cyl-row-inner .misure-row input {
    font-size: 0.75rem;
    padding: 3px 4px;
}
table.matrix .cyl-row-inner select {
    width: 100%;
}
table.matrix .cyl-row-inner .misure-row {
    display: flex;
    gap: 4px;
}
table.matrix .cyl-row-inner .misure-row input {
    width: 50%;
    text-align: center;
}

/* Intestazioni colonna utente: layout verticale come in un foglio Excel */
table.matrix .user-header {
    width: 64px;
    min-width: 64px;
    max-width: 64px;
    padding: 8px 2px;
}
table.matrix .user-header-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}
table.matrix .user-header-inner input.user-name-input {
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    text-align: center;
    width: 26px;
    min-height: 100px;
    font-size: 0.8rem;
    padding: 4px 2px;
    border: 1px solid rgba(255,255,255,0.4);
    background: rgba(255,255,255,0.08);
    color: #fff;
}
table.matrix .user-header-inner input.user-name-input::placeholder {
    color: rgba(255,255,255,0.6);
}
table.matrix .user-header-inner .remove-btn {
    align-self: center;
}

/* Checkbox accessi */
table.matrix input.access-checkbox {
    width: 22px;
    height: 22px;
    cursor: pointer;
    accent-color: var(--accent);
}

/* Riga "numero di chiavi" in fondo */
table.matrix tr.num-chiavi-row td.cyl-name-cell {
    font-weight: 700;
    color: var(--primary);
    background: #e8f1fb;
}
table.matrix tr.num-chiavi-row td {
    background: #e8f1fb;
}
table.matrix .num-chiavi-label {
    font-size: 0.85rem;
}

table.matrix input.qty-input {
    width: 44px;
    text-align: center;
    padding: 6px 2px;
    font-size: 0.85rem;
}
table.matrix input.qty-input.has-value {
    background: #fff;
    border-color: var(--accent);
    font-weight: 700;
    color: var(--primary);
}
table.matrix .remove-btn {
    background: var(--danger);
    color: #fff;
    border: none;
    border-radius: 4px;
    width: 22px; height: 22px;
    cursor: pointer;
    font-size: 0.8rem;
    line-height: 1;
    flex-shrink: 0;
}
table.matrix .add-col-cell, table.matrix .add-row-cell {
    background: #f0f4f7;
    width: 40px;
    min-width: 40px;
}
table.matrix tbody tr:nth-child(even) td:not(.cyl-name-cell) {
    background: #fafcfd;
}
table.matrix tbody tr:hover td:not(.cyl-name-cell) {
    background: #eef5fb;
}
table.matrix tbody tr.num-chiavi-row:hover td {
    background: #e8f1fb;
}

.toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

/* Summary / offer pages */
.summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    margin: 12px 0;
}
.summary-table th, .summary-table td {
    border: 1px solid var(--border);
    padding: 10px;
    text-align: left;
}
.summary-table th { background: var(--primary); color: #fff; }
.summary-table tfoot td { font-weight: 700; background: #f0f4f7; }
.summary-table .text-right { text-align: right; }
.summary-table .text-center { text-align: center; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 700;
    color: #fff;
}
.badge.nuova { background: var(--accent); }
.badge.in_lavorazione { background: #8a6d3b; }
.badge.offerta_pronta { background: #2980b9; }
.badge.inviata { background: var(--success); }
.badge.accettata { background: #1c7c3f; }
.badge.rifiutata { background: var(--danger); }

.alert {
    padding: 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}
.alert.success { background: #e6f4ea; color: var(--success); border: 1px solid var(--success); }
.alert.error { background: #fdecea; color: var(--danger); border: 1px solid var(--danger); }
.alert.info { background: #e8f1fb; color: #2980b9; border: 1px solid #2980b9; }

.success-page {
    text-align: center;
    padding: 60px 20px;
}
.success-page .icon {
    font-size: 4rem;
    color: var(--success);
}

footer.app-footer {
    text-align: center;
    padding: 24px;
    color: var(--text-light);
    font-size: 0.85rem;
}

a { color: var(--primary-light); }

/* Admin */
.admin-nav {
    display: flex;
    gap: 16px;
    align-items: center;
}
.admin-nav a { color: #fff; text-decoration: none; font-size: 0.9rem; }
.admin-nav a:hover { text-decoration: underline; }

.list-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.list-table th, .list-table td {
    border: 1px solid var(--border);
    padding: 10px;
    text-align: left;
}
.list-table th { background: var(--primary); color: #fff; }
.list-table tr:hover { background: #f8fafc; }
.list-table a.row-link { text-decoration: none; color: var(--text); display: block; }

@media (max-width: 700px) {
    header.app-header .container { flex-direction: column; gap: 10px; text-align: center; }
    .card { padding: 18px; }
}
