:root {
    --bg-color: #f3f4f6;
    --card-bg: #ffffff;
    --text-main: #1f2937;
    --text-muted: #6b7280;
    --primary: #1e3a8a; 
    --primary-hover: #1e40af;
    --accent: #059669; 
    --accent-hover: #047857;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --border: #e5e7eb;
    --border-focus: #3b82f6;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius: 6px;
    --ring: rgba(59, 130, 246, 0.25);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body { 
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; 
    background-color: var(--bg-color); 
    color: var(--text-main); 
    line-height: 1.5;
}

.app-container { max-width: 1400px; margin: 0 auto; display: flex; flex-direction: column; min-height: 100vh; padding-bottom: 20px;}

.app-header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    padding: 16px 32px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 16px;
    max-width: 1400px;
    margin: 0 auto;
}

.logo-icon {
    font-size: 32px;
    background: var(--primary);
    color: white;
    padding: 8px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

.app-header h1 { color: var(--primary); font-size: 20px; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 2px;}
.app-header p { color: var(--text-muted); font-size: 13px; font-weight: 500; }

.main-layout { display: flex; gap: 24px; align-items: flex-start; flex: 1; padding: 0 20px;}
.panel-controles { flex: 0 0 360px; display: flex; flex-direction: column; gap: 16px; }
.panel-visualizacion { flex: 1; min-width: 0; }

.card { 
    background: var(--card-bg); 
    padding: 20px; 
    border-radius: var(--radius); 
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm); 
}
.workspace-card { min-height: 800px; }
.card h2 { font-size: 14px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; color: var(--primary); margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center;}

.input-group { display: flex; gap: 12px; }
.input-group > div { flex: 1; display: flex; flex-direction: column; }
.form-group { margin-bottom: 16px; }
.mt-15 { margin-top: 16px; }
label { font-size: 12px; font-weight: 600; color: var(--text-main); margin-bottom: 6px; display: block; }

input[type="number"], input[type="text"], input[type="date"], select { 
    width: 100%; 
    padding: 8px 12px; 
    border: 1px solid var(--border); 
    border-radius: var(--radius); 
    font-size: 13px; 
    font-family: inherit;
    color: var(--text-main);
    transition: all 0.2s ease;
    background-color: #fff;
}

input:focus, select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--ring);
}

.radio-group { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--text-main); }
.radio-label { display: flex; align-items: center; gap: 6px; cursor: pointer; }

button { 
    border: none; 
    cursor: pointer; 
    border-radius: var(--radius); 
    font-weight: 600; 
    font-family: inherit;
    transition: all 0.2s ease; 
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-block { width: 100%; margin-bottom: 12px; }
.btn-primario { background: var(--accent); color: white; padding: 8px 16px; border: 1px solid transparent; }
.btn-primario:hover { background: var(--accent-hover); box-shadow: var(--shadow-md); }
.btn-secundario { background: #ffffff; color: var(--text-main); border: 1px solid var(--border); padding: 8px 16px; }
.btn-secundario:hover { background: #f9fafb; border-color: #d1d5db; }
.btn-danger { background: var(--danger); color: white; padding: 8px 16px; border: 1px solid transparent; }
.btn-danger:hover { background: var(--danger-hover); box-shadow: var(--shadow-md); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-large { padding: 10px 20px; font-size: 14px; }

.header-piezas { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
.header-piezas h2 { margin-bottom: 0; border: none; padding: 0; }
.lista-piezas { list-style: none; }
.lista-scroll { max-height: 250px; overflow-y: auto; padding-right: 4px; }

.lista-scroll::-webkit-scrollbar { width: 6px; }
.lista-scroll::-webkit-scrollbar-track { background: #f1f1f1; border-radius: 4px; }
.lista-scroll::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
.lista-scroll::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

.pieza-item { 
    display: flex; justify-content: space-between; align-items: center; 
    padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius); 
    margin-bottom: 8px; font-size: 12px; background: #fafafa;
    transition: border-color 0.2s;
}
.pieza-item:hover { border-color: #cbd5e1; background: #fff; }
.acciones-pieza { display: flex; gap: 4px; }
.acciones-pieza button { padding: 4px 6px; font-size: 14px; line-height: 1; border-radius: 4px; background: transparent;}
.acciones-pieza .btn-editar { background: #f1f5f9; color: #3498db; border: 1px solid #e2e8f0; }
.acciones-pieza .btn-editar:hover { background: #e2e8f0; }
.acciones-pieza .btn-eliminar { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.acciones-pieza .btn-eliminar:hover { background: #fee2e2; }

.acciones-canvas { 
    display: flex; justify-content: space-between; align-items: center; 
    margin-bottom: 24px; background: #f8fafc; padding: 16px; 
    border-radius: var(--radius); border: 1px solid var(--border); 
}
.canvas-actions-left { display: flex; gap: 12px; flex-wrap: wrap;}

.controles-edicion { 
    display: flex; align-items: center; gap: 10px; 
    background: white; padding: 8px 16px; border-radius: 50px; 
    border: 1px solid var(--border); box-shadow: var(--shadow-sm); 
}
.etiqueta-edicion { font-size: 13px; font-weight: 600; color: var(--primary); }

.toggle-switch { position: relative; display: inline-block; width: 36px; height: 20px; flex-shrink: 0;}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #cbd5e1; transition: .3s; border-radius: 20px; }
.slider:before { position: absolute; content: ""; height: 16px; width: 16px; left: 2px; bottom: 2px; background-color: white; transition: .3s; border-radius: 50%; box-shadow: var(--shadow-sm); }
input:checked + .slider { background-color: var(--accent); }
input:checked + .slider:before { transform: translateX(16px); }

.estado-vacio { 
    display: flex; flex-direction: column; align-items: center; justify-content: center; 
    height: 450px; background: #fafafa; border: 2px dashed #cbd5e1; 
    border-radius: 12px; color: var(--text-muted); text-align: center; padding: 32px; 
}
.estado-vacio .icono-vacio { font-size: 48px; line-height: 1; margin-bottom: 20px; opacity: 0.8; }
.estado-vacio h3 { color: var(--text-main); margin-bottom: 12px; font-size: 18px; font-weight: 600; }
.estado-vacio p { font-size: 14px; line-height: 1.6; max-width: 450px; margin-bottom: 8px;}

.canvas-wrapper { 
    position: relative; border: 1px solid var(--primary); 
    border-radius: var(--radius); background: white; 
    margin-bottom: 24px; box-shadow: var(--shadow-md); 
    overflow: hidden;
}
.canvas-header { 
    background: var(--primary); color: white; 
    padding: 10px 16px; font-size: 13px; font-weight: 600; 
    display: flex; justify-content: space-between;
    letter-spacing: 0.5px;
    font-family: 'Inter', monospace;
}
canvas { display: block; width: 100%; border-bottom-left-radius: var(--radius); border-bottom-right-radius: var(--radius); }

.modo-edicion-activo canvas { cursor: grab; }
.modo-edicion-activo canvas:active { cursor: grabbing; }

.accordion-header { cursor: pointer; border-bottom: 1px solid var(--border); padding-bottom: 12px; margin-bottom: 12px; transition: color 0.2s; display: flex; justify-content: space-between; align-items: center;}
.accordion-header:hover { color: var(--primary-hover); }
.accordion-header h2 { margin-bottom: 0; border: none; padding: 0; }
.chevron { font-size: 12px; color: var(--text-muted); transition: transform 0.3s ease; }
.accordion.active .chevron { transform: rotate(180deg); }
.accordion-content { display: none; padding-top: 8px; }
.accordion.active .accordion-content { display: block; animation: fadeIn 0.3s ease; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }

.modal-overlay { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(15, 23, 42, 0.6); backdrop-filter: blur(4px); display: flex; justify-content: center; align-items: center; z-index: 1000; transition: opacity 0.3s; padding: 15px;}
.modal-content { background: white; border-radius: 8px; width: 100%; max-width: 500px; box-shadow: var(--shadow-lg); overflow: hidden; animation: slideUp 0.3s ease; max-height: 95vh; display: flex; flex-direction: column;}
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; background: #f8fafc; flex-shrink: 0;}
.modal-header h3 { color: var(--primary); font-size: 16px; font-weight: 600; margin: 0; }
.btn-close { background: none; border: none; font-size: 24px; line-height: 1; color: #94a3b8; cursor: pointer; padding: 0; }
.btn-close:hover { color: var(--danger); background: transparent;}
.modal-body { padding: 24px; overflow-y: auto;}
.modal-actions { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 12px; background: #f8fafc; flex-shrink: 0;}

@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

.oculto { display: none !important; }

.table-responsive { border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; }
.tabla-canto { width: 100%; border-collapse: collapse; text-align: center; font-size: 13px; min-width: 350px;}
.tabla-canto th, .tabla-canto td { padding: 10px; border-bottom: 1px solid var(--border); }
.tabla-canto th { background: #f1f5f9; color: var(--text-main); font-weight: 600; text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px; }
.tabla-canto tbody tr:last-child td { border-bottom: none; }
.tabla-canto td.fw-bold { font-weight: 500; text-align: left; background: #f8fafc; border-right: 1px solid var(--border); }
.tabla-canto input[type="radio"] { cursor: pointer; width: 16px; height: 16px; accent-color: var(--primary); }

.app-footer {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
}
.app-footer strong {
    color: var(--primary);
    font-weight: bold;
}

@media (max-width: 768px) {
    .app-container { padding: 10px; }
    .app-header { padding: 16px 20px; margin-bottom: 15px; }
    .main-layout { flex-direction: column; gap: 15px; padding: 0;}
    .panel-controles { flex: 1 1 auto; width: 100%; }
    .panel-visualizacion { width: 100%; }
    .acciones-canvas { flex-direction: column; align-items: stretch; gap: 15px; padding: 15px;}
    .canvas-actions-left { flex-direction: column; align-items: stretch; width: 100%;}
    .canvas-actions-left button { width: 100%; margin-bottom: 10px;}
    .controles-edicion { justify-content: center; width: 100%; margin-top: 5px; }
    .input-group { flex-direction: column; gap: 10px; }
    .estado-vacio { height: auto; min-height: 250px; padding: 20px; }
    .estado-vacio .icono-vacio { font-size: 36px; margin-bottom: 10px;}
    .estado-vacio h3 { font-size: 16px; margin-bottom: 8px;}
    .estado-vacio p { font-size: 13px;}
    .modal-content { width: 95%; margin: 10px; padding: 15px; max-height: 90vh;}
    .modal-body { padding: 15px 0;}
    .app-footer { margin-top: 20px; padding-top: 15px; }
}