:root {
    --green: #0f3d35;
    --green-soft: #e7f3ef;
    --teal: #0f766e;
    --teal-dark: #0b5f59;
    --yellow: #ffd166;
    --red: #d9534f;
    --blue: #2f80ed;
    --bg: #f4f7f6;
    --card: #ffffff;
    --text: #1f2933;
    --muted: #6b7280;
    --border: #d9e2e7;
    --shadow: 0 14px 35px rgba(15, 61, 53, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app-shell {
    padding: 20px;
    max-width: 1300px;
    margin: 0 auto;
}

.app-header {
    display: grid;
    grid-template-columns: 120px 1fr auto;
    align-items: center;
    gap: 16px;
    padding: 18px 22px;
    background: linear-gradient(135deg, var(--green), var(--teal));
    color: white;
    border-radius: 24px;
    box-shadow: var(--shadow);
    margin-bottom: 22px;
}

.header-logo {
    display: flex;
    justify-content: flex-start;
}

.logo-mark {
    width: 74px;
    height: 74px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    letter-spacing: 1px;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.header-title {
    text-align: center;
}

    .header-title h1 {
        margin: 0;
        font-size: 30px;
        letter-spacing: 0.3px;
    }

    .header-title p {
        margin: 6px 0 0 0;
        color: rgba(255, 255, 255, 0.78);
    }

.header-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    background: rgba(255, 255, 255, 0.14);
    padding: 9px 12px;
    border-radius: 999px;
}

.status-dot {
    width: 9px;
    height: 9px;
    background: #34d399;
    border-radius: 999px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.panel-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 18px;
    box-shadow: var(--shadow);
}

.card-wide {
    grid-column: span 2;
}

.card-heading {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    margin-bottom: 16px;
}

.panel-label {
    color: var(--teal);
    display: block;
    margin-bottom: 6px;
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.6px;
}

.card-heading h2 {
    margin: 0;
    color: var(--green);
    font-size: 20px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
}

.field-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

label {
    font-size: 13px;
    color: var(--green);
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 11px 12px;
    font-size: 14px;
    background: white;
    color: var(--text);
    outline: none;
}

    input:focus,
    select:focus,
    textarea:focus {
        border-color: var(--teal);
        box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.12);
    }

    input[readonly] {
        background: #f5f7f7;
        color: #4b5563;
    }

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 7px 11px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.4px;
    white-space: nowrap;
}

    .badge.neutral {
        background: #eef2f2;
        color: #51605d;
    }

    .badge.warning {
        background: #fff2cc;
        color: #8a6100;
    }

    .badge.good {
        background: #dff5ea;
        color: #087443;
    }

    .badge.danger {
        background: #fde2e2;
        color: #b42318;
    }

.btn {
    border: none;
    border-radius: 12px;
    padding: 11px 16px;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
    transition: 0.15s ease;
}

    .btn.primary {
        background: var(--teal);
        color: white;
    }

        .btn.primary:hover {
            background: var(--teal-dark);
        }

    .btn.success {
        background: var(--green);
        color: white;
    }

        .btn.success:hover {
            background: #0b2f29;
        }

    .btn.secondary {
        background: var(--green-soft);
        color: var(--green);
    }

        .btn.secondary:hover {
            background: #d5ebe4;
        }

    .btn.ghost {
        background: #f2f5f5;
        color: var(--green);
    }

        .btn.ghost:hover {
            background: #e7eeee;
        }

    .btn.danger {
        background: #fde2e2;
        color: #b42318;
    }

    .btn.full {
        width: 100%;
    }

.actions-row {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.mini-note {
    font-size: 12px;
    color: var(--muted);
    margin-top: 10px;
    line-height: 1.4;
}

.kpi-box {
    padding: 18px;
    background: var(--green-soft);
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    margin-bottom: 14px;
}

.kpi-value {
    font-size: 44px;
    color: var(--green);
    font-weight: 900;
    line-height: 1;
}

.kpi-label {
    font-size: 13px;
    color: var(--muted);
    margin-top: 6px;
}

.alert-box {
    background: #fff7df;
    border: 1px solid #ffe3a3;
    color: #704b00;
    padding: 14px;
    border-radius: 14px;
    margin-bottom: 14px;
}

    .alert-box p {
        margin: 6px 0 0 0;
        font-size: 13px;
        line-height: 1.4;
    }

.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    text-align: left;
    background: var(--green-soft);
    color: var(--green);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding: 12px;
}

td {
    padding: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}

.empty-row td {
    text-align: center;
    color: var(--muted);
    padding: 24px;
}

.legal-text {
    margin: 0 0 14px 0;
    color: #3f4f4b;
    line-height: 1.5;
}

.signature-box {
    width: 100%;
    height: 240px;
    border: 2px dashed #7aa899;
    border-radius: 18px;
    background: #f8fbfa;
    overflow: hidden;
    touch-action: none;
}

#signatureCanvas {
    width: 100%;
    height: 100%;
    display: block;
    cursor: crosshair;
}

.signature-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

.email-preview {
    padding: 16px;
    border-radius: 16px;
    background: #f8fbfa;
    border: 1px solid var(--border);
    margin-top: 14px;
    line-height: 1.5;
}

.json-output {
    margin-top: 14px;
    max-height: 360px;
    overflow: auto;
    padding: 16px;
    background: #10201d;
    color: #c9f7e7;
    border-radius: 16px;
    font-size: 12px;
    line-height: 1.5;
}

.hidden {
    display: none !important;
}

.print-area {
    margin-top: 24px;
}

.print-document {
    background: white;
    padding: 32px;
    border-radius: 12px;
    border: 1px solid var(--border);
}

    .print-document h1 {
        color: var(--green);
        margin-top: 0;
    }

.firma-cartacea {
    margin-top: 40px;
    font-size: 16px;
}

.firma-linea {
    margin-top: 36px;
}

@media (max-width: 800px) {
    .app-shell {
        padding: 12px;
    }

    .app-header {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .header-logo {
        justify-content: center;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .card-wide {
        grid-column: span 1;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .actions-row {
        flex-direction: column;
    }

    .btn {
        width: 100%;
    }

    .signature-box {
        height: 260px;
    }
}

@media print {
    body {
        background: white;
    }

    .app-header,
    .dashboard-grid {
        display: none !important;
    }

    .print-area {
        display: block !important;
    }

    .print-document {
        border: none;
        box-shadow: none;
    }
}
