:root {
    --primary: #0ea5e9;
    --secondary: #0284c7;
    --accent: #f59e0b;
    --glass: rgba(255, 255, 255, 0.7);
    --dark: #0c4a6e;
    --light: #f0f9ff;
    --text-main: #0f172a;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

body {
    background: linear-gradient(135deg, #bae6fd, #e0f2fe);
    color: var(--text-main);
    min-height: 100vh;
    padding: 2rem;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem;
    background: var(--glass);
    backdrop-filter: blur(10px);
    border-radius: 20px;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 8px 32px 0 rgba(0,0,0,0.1);
}

h1 {
    font-size: 2.5rem;
    color: var(--dark);
    margin-bottom: 0.5rem;
}

.setup-card {
    background: var(--glass);
    backdrop-filter: blur(10px);
    padding: 2rem;
    border-radius: 20px;
    margin-bottom: 2rem;
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    align-items: flex-end;
    border: 1px solid rgba(255,255,255,0.1);
}

.form-group {
    flex: 1;
    min-width: 250px;
}

label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--secondary);
}

select, input {
    width: 100%;
    padding: 0.8rem;
    border-radius: 10px;
    border: 1px solid rgba(15, 23, 42, 0.1);
    background: white;
    color: var(--text-main);
    outline: none;
    transition: 0.3s;
}

select:focus, input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 10px rgba(14, 165, 233, 0.2);
}

.audit-grid {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 2rem;
}

.infracciones-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.infraccion-card {
    background: var(--glass);
    padding: 1.5rem;
    border-radius: 15px;
    border-left: 5px solid transparent;
    transition: 0.3s;
}

.infraccion-card.grave { border-left-color: var(--danger); }
.infraccion-card.muy-grave { border-left-color: #7c2d12; }
.infraccion-card.leve { border-left-color: var(--warning); }

.infraccion-card:hover {
    transform: translateX(10px);
    background: rgba(255,255,255,0.9);
}

.header-card {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.badge {
    padding: 0.2rem 0.8rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
}

.badge.grave { background: var(--danger); color: white; }
.badge.muy-grave { background: #7c2d12; color: white; }
.badge.leve { background: var(--warning); color: white; }

.requirements {
    list-style: none;
    margin-top: 1rem;
}

.requirement-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: #475569;
    flex-wrap: wrap;
}

.req-text {
    flex: 1;
    min-width: 0;
}

/* Grupo trabajadores por ítem — solo visible cuando el checkbox está marcado */
.workers-group {
    display: none;
    align-items: center;
    gap: 0.3rem;
    flex-shrink: 0;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    padding: 0.2rem 0.5rem;
}
.requirement-item.checked .workers-group {
    display: flex;
}
.workers-input {
    width: 3.5rem;
    padding: 0.15rem 0.3rem;
    border: none;
    background: transparent;
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--secondary);
    text-align: center;
    outline: none;
}
.workers-input::-webkit-inner-spin-button { opacity: 1; }
.workers-label {
    font-size: 0.75rem;
    color: #64748b;
    font-weight: 500;
    white-space: nowrap;
}

.summary-sidebar {
    position: sticky;
    top: 2rem;
    background: var(--glass);
    backdrop-filter: blur(10px);
    padding: 2rem;
    border-radius: 20px;
    height: fit-content;
    border: 1px solid rgba(255,255,255,0.1);
    box-shadow: 0 8px 32px 0 rgba(0,0,0,0.1);
}

.total-multa {
    font-size: 2rem;
    font-weight: bold;
    color: var(--secondary);
    margin: 1rem 0;
}

.desglose-multa {
    font-size: 0.78rem;
    color: #64748b;
    margin-bottom: 0.5rem;
    max-height: 180px;
    overflow-y: auto;
}
.desglose-row {
    display: flex;
    justify-content: space-between;
    padding: 0.2rem 0;
    border-bottom: 1px dashed #e2e8f0;
}
.desglose-art { font-weight: 600; color: var(--dark); }
.desglose-monto { color: var(--danger); font-weight: 600; }

.btn-ai {
    width: 100%;
    padding: 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    margin-top: 1rem;
    transition: 0.3s;
}

.btn-ai:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.ai-recommendation {
    margin-top: 1.5rem;
    padding: 1rem;
    background: rgba(255,255,255,0.5);
    border-radius: 10px;
    font-size: 0.9rem;
    line-height: 1.6;
    border-left: 3px solid var(--primary);
    display: none;
}

input[type="checkbox"] {
    width: 1.2rem;
    height: 1.2rem;
    cursor: pointer;
}

/* ── Botón Limpiar Todo ── */
.btn-clear {
    width: 100%;
    padding: 0.75rem;
    background: #f1f5f9;
    color: #64748b;
    border: 1px solid #cbd5e1;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    margin-top: 1rem;
    transition: 0.2s;
}
.btn-clear:hover {
    background: #fee2e2;
    color: var(--danger);
    border-color: var(--danger);
}

/* ── Header derecho de cada artículo ── */
.header-right {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

/* ── Botón Editar Tabla de Multas ── */
.btn-multas {
    width: 100%;
    padding: 0.75rem;
    background: #f5f3ff;
    color: #6d28d9;
    border: 1px solid #c4b5fd;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    margin-top: 1rem;
    transition: 0.2s;
}
.btn-multas:hover {
    background: #ede9fe;
    border-color: #6d28d9;
}

/* ── Botón Editar ── */
.btn-editar {
    padding: 0.2rem 0.7rem;
    font-size: 0.75rem;
    font-weight: 600;
    background: transparent;
    border: 1px solid #6366f1;
    color: #6366f1;
    border-radius: 20px;
    cursor: pointer;
    transition: 0.2s;
    white-space: nowrap;
}
.btn-editar:hover {
    background: #6366f1;
    color: white;
}

/* ── Modal de edición ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 1rem;
}
.modal-box {
    background: white;
    border-radius: 16px;
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.2rem 1.5rem;
    border-bottom: 1px solid #e2e8f0;
}
.modal-header h3 {
    font-size: 1.1rem;
    color: var(--dark);
}
.modal-close {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    color: #64748b;
    padding: 0.2rem 0.5rem;
    border-radius: 6px;
    transition: 0.2s;
}
.modal-close:hover { background: #fee2e2; color: var(--danger); }

.modal-body {
    padding: 1.5rem;
    overflow-y: auto;
    flex: 1;
}
.modal-label {
    display: block;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--secondary);
    margin-bottom: 0.4rem;
}
.modal-textarea {
    width: 100%;
    padding: 0.7rem;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    font-size: 0.88rem;
    line-height: 1.5;
    resize: vertical;
    font-family: inherit;
}
.modal-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(14,165,233,0.15);
}
.modal-item-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: flex-start;
}
.modal-item-input {
    flex: 1;
    padding: 0.5rem 0.7rem;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    font-size: 0.85rem;
    font-family: inherit;
}
.modal-item-input:focus {
    outline: none;
    border-color: var(--primary);
}
.btn-del-item {
    flex-shrink: 0;
    background: #fee2e2;
    color: var(--danger);
    border: none;
    border-radius: 6px;
    padding: 0.4rem 0.6rem;
    cursor: pointer;
    font-size: 0.85rem;
    transition: 0.2s;
}
.btn-del-item:hover { background: var(--danger); color: white; }

.btn-add-item {
    margin-top: 0.5rem;
    background: #f0fdf4;
    color: #16a34a;
    border: 1px dashed #86efac;
    border-radius: 8px;
    padding: 0.5rem 1rem;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    width: 100%;
    transition: 0.2s;
}
.btn-add-item:hover { background: #dcfce7; }

.modal-footer {
    display: flex;
    gap: 0.8rem;
    justify-content: flex-end;
    padding: 1rem 1.5rem;
    border-top: 1px solid #e2e8f0;
}
.btn-cancel {
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    background: white;
    color: #64748b;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
}
.btn-cancel:hover { background: #f1f5f9; }

.btn-save {
    padding: 0.6rem 1.4rem;
    border-radius: 8px;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
}
.btn-save:hover { filter: brightness(1.1); }

.modal-msg {
    font-size: 0.82rem;
    text-align: center;
    padding: 0 1.5rem 0.8rem;
    color: var(--success);
    min-height: 1.2rem;
}

/* ── Modal wide (tabla de multas) ── */
.modal-box-wide { max-width: 860px; }

.modal-hint {
    font-size: 0.82rem;
    color: #64748b;
    margin-bottom: 1rem;
    padding: 0.5rem 0.8rem;
    background: #f8fafc;
    border-radius: 8px;
    border-left: 3px solid var(--primary);
}

.multas-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}
.multas-table th {
    background: #f1f5f9;
    padding: 0.5rem 0.7rem;
    text-align: left;
    font-weight: 600;
    color: var(--dark);
    border-bottom: 2px solid #e2e8f0;
    white-space: nowrap;
}
.multas-table td {
    padding: 0.3rem 0.4rem;
    border-bottom: 1px solid #f1f5f9;
    vertical-align: middle;
}
.multas-table tr:hover td { background: #f8fafc; }

.multa-input {
    width: 80px;
    padding: 0.3rem 0.4rem;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 0.82rem;
    text-align: right;
}
.multa-input:focus {
    outline: none;
    border-color: var(--primary);
    background: #f0f9ff;
}
.multa-input.leve:focus  { border-color: var(--warning); }
.multa-input.grave:focus { border-color: var(--danger); }
.multa-input.muyg:focus  { border-color: #7c2d12; }

.tipo-tag {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}
.tipo-tag.micro { background: #dbeafe; color: #1d4ed8; }
.tipo-tag.pyme  { background: #dcfce7; color: #15803d; }
.tipo-tag.nomype{ background: #fef3c7; color: #92400e; }

/* ── Modal: fila de 2 columnas ── */
.modal-row-2col {
    display: flex;
    gap: 1rem;
    margin-bottom: 0.5rem;
}
.modal-row-2col > div { flex: 1; }

.modal-select, .modal-input-sm {
    width: 100%;
    padding: 0.6rem 0.7rem;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    font-size: 0.88rem;
    font-family: inherit;
    background: white;
}
.modal-select:focus, .modal-input-sm:focus {
    outline: none;
    border-color: var(--primary);
}

/* ── Botón Personalizar ── */
.btn-personalizar {
    padding: 0.2rem 0.7rem;
    font-size: 0.75rem;
    font-weight: 600;
    background: transparent;
    border: 1px solid #94a3b8;
    color: #64748b;
    border-radius: 20px;
    cursor: pointer;
    transition: 0.2s;
    white-space: nowrap;
}
.btn-personalizar:hover {
    background: #f0f9ff;
    border-color: var(--primary);
    color: var(--primary);
}
.infraccion-card.edit-mode .btn-personalizar {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* ── Botón toggle de ítem (solo visible en modo edición) ── */
.btn-toggle-item {
    display: none;
    flex-shrink: 0;
    width: 1.4rem;
    height: 1.4rem;
    font-size: 0.7rem;
    line-height: 1;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: #dcfce7;
    color: #16a34a;
    transition: 0.2s;
    padding: 0;
}
.infraccion-card.edit-mode .btn-toggle-item {
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ítem desactivado en modo edición: se ve tachado */
.infraccion-card.edit-mode .requirement-item.item-disabled {
    opacity: 0.45;
    text-decoration: line-through;
    text-decoration-color: var(--danger);
}
.infraccion-card.edit-mode .requirement-item.item-disabled .btn-toggle-item {
    background: #fee2e2;
    color: var(--danger);
}

/* ítem desactivado fuera de modo edición: oculto */
.requirement-item.item-disabled {
    display: none;
}
.infraccion-card.edit-mode .requirement-item.item-disabled {
    display: flex;
}

/* Aviso de personalización activa */
.edit-mode-notice {
    display: none;
    font-size: 0.78rem;
    color: var(--primary);
    margin-top: 0.5rem;
    padding: 0.4rem 0.6rem;
    background: #e0f2fe;
    border-radius: 8px;
}
.infraccion-card.edit-mode .edit-mode-notice {
    display: block;
}
