/* ============================================
   SISTEMA DE CONTRATOS BLOCKCHAIN
   Diseño Minimalista - Modo Claro/Oscuro
   ============================================ */

/* Variables CSS para temas */
:root {
    /* Modo Claro (por defecto) */
    --bg-primary: #ffffff;
    --bg-secondary: #f8f9fa;
    --bg-tertiary: #e9ecef;
    --text-primary: #212529;
    --text-secondary: #6c757d;
    --text-muted: #adb5bd;
    --border-color: #dee2e6;
    --border-light: #e9ecef;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.12);
    
    /* Colores de acento - Solo para firmas */
    --firma-ok: #22c55e;
    --firma-ok-bg: #f0fdf4;
    --firma-ok-border: #86efac;
    --firma-pending: #ef4444;
    --firma-pending-bg: #fef2f2;
    --firma-pending-border: #fca5a5;
    
    /* Estados */
    --success: #22c55e;
    --error: #ef4444;
    --warning: #f59e0b;
    --info: #6b7280;
}

/* Modo Oscuro */
[data-theme="dark"] {
    --bg-primary: #121212;
    --bg-secondary: #1e1e1e;
    --bg-tertiary: #2d2d2d;
    --text-primary: #f5f5f5;
    --text-secondary: #a0a0a0;
    --text-muted: #6b6b6b;
    --border-color: #333333;
    --border-light: #404040;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.5);
    
    --firma-ok-bg: #052e16;
    --firma-ok-border: #166534;
    --firma-pending-bg: #450a0a;
    --firma-pending-border: #991b1b;
}

/* Reset */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-secondary);
    color: var(--text-primary);
    min-height: 100vh;
    padding: 20px;
    transition: background-color 0.3s, color 0.3s;
    line-height: 1.6;
}

/* ============================================
   CONTROLES SUPERIORES (IDIOMA Y TEMA)
   ============================================ */
.top-controls {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    display: flex;
    gap: 10px;
    align-items: center;
}

/* Toggle de Idioma */
.lang-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: var(--shadow-sm);
}

.lang-toggle:hover {
    box-shadow: var(--shadow-md);
    background: var(--bg-secondary);
}

.lang-toggle-icon {
    font-size: 1.1rem;
}

.lang-toggle-text {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Toggle de Tema */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: 50px;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: var(--shadow-sm);
}

.theme-toggle:hover {
    box-shadow: var(--shadow-md);
}

.theme-toggle-icon {
    font-size: 1.2rem;
    transition: transform 0.3s;
}

.theme-toggle:hover .theme-toggle-icon {
    transform: rotate(15deg);
}

.theme-toggle-text {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

/* ============================================
   CONTENEDOR PRINCIPAL
   ============================================ */
.container {
    max-width: 1100px;
    margin: 0 auto;
}

/* ============================================
   HEADER
   ============================================ */
header {
    text-align: center;
    margin-bottom: 40px;
    padding: 30px 0;
}

header h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ============================================
   ESTADÍSTICAS
   ============================================ */
.stats-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-primary);
    padding: 24px;
    border-radius: 12px;
    text-align: center;
    border: 1px solid var(--border-color);
    transition: all 0.2s;
}

.stat-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stat-value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
    font-variant-numeric: tabular-nums;
}

.stat-label {
    color: var(--text-secondary);
    font-size: 0.85rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================
   TARJETAS
   ============================================ */
.card {
    background: var(--bg-primary);
    border-radius: 12px;
    padding: 28px;
    margin-bottom: 24px;
    border: 1px solid var(--border-color);
    transition: box-shadow 0.2s;
}

.card:hover {
    box-shadow: var(--shadow-sm);
}

.card h2 {
    color: var(--text-primary);
    margin-bottom: 20px;
    font-size: 1.25rem;
    font-weight: 600;
}

/* ============================================
   FORMULARIO
   ============================================ */
.form-group {
    margin-bottom: 20px;
    flex: 1;
}

.form-row {
    display: flex;
    gap: 20px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9rem;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.2s;
}

.form-group input:focus {
    outline: none;
    border-color: var(--text-primary);
    box-shadow: 0 0 0 3px rgba(0,0,0,0.05);
}

[data-theme="dark"] .form-group input:focus {
    box-shadow: 0 0 0 3px rgba(255,255,255,0.1);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

/* ============================================
   BOTONES
   ============================================ */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-right: 12px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.btn-primary {
    background: var(--text-primary);
    color: var(--bg-primary);
}

.btn-primary:hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

.btn-success {
    background: var(--text-primary);
    color: var(--bg-primary);
    border: 2px solid var(--text-primary);
}

.btn-success:hover {
    background: transparent;
    color: var(--text-primary);
}

.btn-info {
    background: transparent;
    color: var(--text-primary);
    border: 2px solid var(--border-color);
}

.btn-info:hover {
    border-color: var(--text-primary);
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: var(--border-color);
}

button:disabled,
.btn:disabled,
.btn-disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none !important;
}

/* ============================================
   TABS
   ============================================ */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.tabs {
    display: flex;
    gap: 8px;
}

.tab {
    padding: 8px 20px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: var(--text-secondary);
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    font-size: 0.9rem;
}

.tab.active {
    background: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

.tab:hover:not(.active) {
    border-color: var(--text-primary);
    color: var(--text-primary);
}

/* ============================================
   LISTA DE CONTRATOS
   ============================================ */
.contratos-list {
    display: grid;
    gap: 16px;
}

.contrato-item {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 20px;
    background: var(--bg-primary);
    transition: all 0.2s;
}

.contrato-item:hover {
    box-shadow: var(--shadow-md);
}

.contrato-item.listo-minar {
    border-width: 2px;
}

.contrato-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.contrato-nombre {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.contrato-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.badge-minado {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.badge-listo {
    background: var(--text-primary);
    color: var(--bg-primary);
}

.badge-pendiente {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

/* ============================================
   TARJETAS DE FIRMA (Con color)
   ============================================ */
.contrato-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin: 16px 0;
}

.info-firma {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    border-radius: 10px;
    border: 2px solid;
    transition: all 0.2s;
    position: relative;
}

/* Firma completada - VERDE */
.info-firma.firma-ok {
    border-color: var(--firma-ok);
    background: var(--firma-ok-bg);
}

.info-firma.firma-ok .firma-status-icon {
    background: var(--firma-ok);
    color: white;
}

.info-firma.firma-ok .firma-estado-text {
    color: var(--firma-ok);
}

/* Firma pendiente - ROJO */
.info-firma.firma-pending {
    border-color: var(--firma-pending);
    background: var(--firma-pending-bg);
}

.info-firma.firma-pending .firma-status-icon {
    background: var(--firma-pending-bg);
    color: var(--firma-pending);
    border: 2px solid var(--firma-pending);
}

.info-firma.firma-pending .firma-estado-text {
    color: var(--firma-pending);
}

/* Firma clickeable */
.info-firma.clickeable {
    cursor: pointer !important;
}

.info-firma.clickeable:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.25);
}

.info-firma.clickeable * {
    pointer-events: none;
}

.firma-action-hint {
    position: absolute;
    top: 12px;
    right: 12px;
    font-size: 1.2rem;
    opacity: 0.5;
    transition: all 0.2s;
}

.info-firma.clickeable:hover .firma-action-hint {
    opacity: 1;
    transform: scale(1.1);
}

.firma-status-icon {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 1.2rem;
    font-weight: bold;
    flex-shrink: 0;
}

.firma-details {
    flex: 1;
    min-width: 0;
}

.firma-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.firma-nombre {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 2px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.firma-estado-text {
    font-size: 0.8rem;
    font-weight: 600;
}

/* ============================================
   META INFO
   ============================================ */
.contrato-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
    margin-top: 16px;
}

.meta-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.meta-icon {
    font-size: 1rem;
    opacity: 0.7;
}

/* ============================================
   ACCIONES DE CONTRATO
   ============================================ */
.contrato-acciones {
    display: flex;
    gap: 12px;
    margin-top: 16px;
    flex-wrap: wrap;
}

.btn-trazabilidad {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.btn-trazabilidad:hover {
    border-color: var(--text-primary);
    background: var(--bg-tertiary);
}

/* Banner firmas completas */
.firmas-completas-banner {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 12px;
    background: var(--firma-ok-bg);
    border: 1px solid var(--firma-ok);
    color: var(--firma-ok);
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
}

.check-icon {
    font-size: 1.2rem;
}

/* Botón Minar */
.btn-minar-listo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    padding: 14px 24px;
    background: var(--text-primary);
    color: var(--bg-primary);
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    margin-top: 12px;
}

.btn-minar-listo:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.minar-icon {
    font-size: 1.2rem;
}

/* ============================================
   BLOCKCHAIN
   ============================================ */
.blockchain-list {
    display: grid;
    gap: 12px;
}

.bloque-item {
    border-left: 3px solid var(--text-primary);
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-radius: 0 8px 8px 0;
    transition: all 0.3s ease;
}

.bloque-item.bloque-manipulado {
    border-left-color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.bloque-header {
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 10px;
    font-size: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
}

.btn-demo-edit {
    font-size: 0.7rem;
    padding: 4px 10px;
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.btn-demo-edit:hover {
    transform: scale(1.05);
    box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
}

.bloque-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.8;
}

.hash {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 0.75rem;
    word-break: break-all;
    background: var(--bg-tertiary);
    padding: 8px 12px;
    border-radius: 6px;
    margin: 6px 0;
    color: var(--text-secondary);
    transition: all 0.3s ease;
}

.hash.hash-modified {
    background: linear-gradient(135deg, #fef2f2, #fee2e2);
    border: 2px solid #ef4444;
    color: #dc2626;
    animation: pulse-warning 1.5s infinite;
}

.hash.hash-mismatch {
    background: linear-gradient(135deg, #fefce8, #fef9c3);
    border: 2px dashed #f59e0b;
    color: #d97706;
}

@keyframes pulse-warning {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

.demo-controls {
    margin-top: 20px;
    padding: 15px;
    background: linear-gradient(135deg, var(--bg-secondary), var(--bg-tertiary));
    border-radius: 8px;
    border: 1px dashed var(--border-color);
    text-align: center;
}

.demo-controls .btn-warning {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    margin-bottom: 10px;
}

.demo-controls .btn-warning:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.demo-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 10px 0 0 0;
    line-height: 1.5;
}

[data-theme="dark"] .hash.hash-modified {
    background: linear-gradient(135deg, #450a0a, #7f1d1d);
    color: #fca5a5;
}

[data-theme="dark"] .hash.hash-mismatch {
    background: linear-gradient(135deg, #422006, #78350f);
    color: #fcd34d;
}

/* ============================================
   MENSAJES / NOTIFICACIONES
   ============================================ */
.mensaje {
    position: fixed;
    top: 80px;
    right: 20px;
    padding: 16px 24px;
    border-radius: 10px;
    font-weight: 500;
    z-index: 10000;
    transform: translateX(150%);
    transition: transform 0.3s ease;
    max-width: 380px;
    box-shadow: var(--shadow-lg);
    font-size: 0.95rem;
}

.mensaje.show {
    transform: translateX(0);
}

.mensaje.success {
    background: var(--firma-ok);
    color: white;
}

.mensaje.error {
    background: var(--firma-pending);
    color: white;
}

.mensaje.info {
    background: var(--text-primary);
    color: var(--bg-primary);
}

.mensaje.warning {
    background: var(--warning);
    color: white;
}

/* ============================================
   ESTADOS DE CARGA
   ============================================ */
.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 50px;
    color: var(--text-secondary);
}

.spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border-color);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 16px;
}

.spinner-small {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border-color);
    border-top-color: var(--text-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-right: 8px;
    vertical-align: middle;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-state {
    text-align: center;
    padding: 40px;
    color: var(--firma-pending);
}

.error-state button {
    margin-top: 16px;
}

.empty-state {
    text-align: center;
    padding: 50px;
    color: var(--text-muted);
}

/* ============================================
   MODAL
   ============================================ */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
}

[data-theme="dark"] .modal {
    background-color: rgba(0, 0, 0, 0.7);
}

.modal.show {
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--bg-primary);
    padding: 32px;
    border-radius: 16px;
    max-width: 700px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    animation: slideIn 0.3s;
    border: 1px solid var(--border-color);
}

@keyframes slideIn {
    from {
        transform: translateY(-30px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h2 {
    margin: 0;
    color: var(--text-primary);
    font-size: 1.25rem;
}

.close-modal {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s;
}

.close-modal:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ============================================
   TRAZABILIDAD TIMELINE
   ============================================ */
.trazabilidad-timeline {
    position: relative;
    padding-left: 35px;
}

.trazabilidad-timeline::before {
    content: '';
    position: absolute;
    left: 12px;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--border-color);
}

.traza-item {
    position: relative;
    margin-bottom: 24px;
    padding: 16px;
    background: var(--bg-secondary);
    border-radius: 10px;
    border: 1px solid var(--border-color);
}

.traza-item::before {
    content: '';
    position: absolute;
    left: -27px;
    top: 20px;
    width: 12px;
    height: 12px;
    background: var(--bg-primary);
    border: 2px solid var(--text-secondary);
    border-radius: 50%;
}

.traza-item.estado-firma1_completada::before,
.traza-item.estado-firma2_completada::before {
    border-color: var(--firma-ok);
    background: var(--firma-ok);
}

.traza-item.estado-finalizado::before {
    border-color: var(--text-primary);
    background: var(--text-primary);
}

.traza-estado {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
    margin-bottom: 6px;
}

.traza-descripcion {
    color: var(--text-secondary);
    margin-bottom: 8px;
    font-size: 0.9rem;
}

.traza-firmante {
    color: var(--text-primary);
    font-weight: 500;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.traza-fecha {
    font-size: 0.8rem;
    color: var(--text-muted);
}

/* ============================================
   MODAL DE FIRMA
   ============================================ */
.modal-firma {
    display: none;
    position: fixed;
    z-index: 3000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 10px;
}

.modal-firma.show {
    display: block;
    animation: fadeIn 0.2s;
}

.modal-firma-content {
    background: var(--bg-primary);
    padding: 20px;
    border-radius: 16px;
    max-width: 520px;
    width: calc(100% - 20px);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border-color);
    margin: 10px auto;
}

.firma-header {
    text-align: center;
    margin-bottom: 12px;
}

.firma-header h3 {
    color: var(--text-primary);
    margin-bottom: 4px;
    font-size: 1rem;
}

.firma-header p {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.descripcion-proceso {
    margin-bottom: 10px;
}

.descripcion-proceso label {
    display: block;
    margin-bottom: 4px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.8rem;
}

.descripcion-proceso input,
.descripcion-proceso textarea {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    background: var(--bg-primary);
    color: var(--text-primary);
    resize: vertical;
}

.descripcion-proceso textarea {
    min-height: 40px;
}

.descripcion-proceso input:focus,
.descripcion-proceso textarea:focus {
    outline: none;
    border-color: var(--text-primary);
}

.canvas-container {
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-primary);
    margin: 10px 0;
    position: relative;
    overflow: hidden;
    width: 100%;
}

#canvasFirma {
    display: block;
    cursor: crosshair;
    touch-action: none;
    background: var(--bg-primary);
    width: 100%;
    max-width: 100%;
}

[data-theme="dark"] #canvasFirma {
    filter: invert(1);
}

.canvas-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-muted);
    font-size: 1rem;
    pointer-events: none;
}

.firma-acciones {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 16px;
    flex-wrap: wrap;
}

.btn-limpiar {
    background: transparent;
    color: var(--firma-pending);
    padding: 10px 16px;
    border: 1px solid var(--firma-pending);
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.btn-limpiar:hover {
    background: var(--firma-pending);
    color: white;
}

.btn-confirmar {
    background: var(--firma-ok);
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.btn-confirmar:hover {
    opacity: 0.9;
}

.btn-cancelar {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    font-size: 0.9rem;
}

.btn-cancelar:hover {
    background: var(--border-color);
}

/* Opción firma almacenada */
#opcionFirmaAlmacenada {
    padding: 12px;
    background: var(--firma-ok-bg);
    border: 1px solid var(--firma-ok);
    border-radius: 8px;
    margin-bottom: 20px;
}

#opcionFirmaAlmacenada p {
    color: var(--firma-ok);
    font-weight: 600;
    margin-bottom: 12px;
}

/* ============================================
   RESPONSIVE - PANTALLAS GRANDES
   ============================================ */
@media (min-width: 1400px) {
    .container {
        max-width: 1300px;
    }
}

/* ============================================
   RESPONSIVE - TABLETS Y PANTALLAS MEDIANAS
   ============================================ */
@media (max-width: 992px) {
    .container {
        max-width: 100%;
        padding: 0 15px;
    }
    
    .stats-container {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .contrato-info-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .modal-content {
        max-width: 95%;
        padding: 24px;
    }
    
    .modal-content-large {
        max-width: 95%;
    }
}

/* ============================================
   RESPONSIVE - MÓVILES
   ============================================ */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    header {
        margin-bottom: 24px;
        padding: 20px 0;
    }
    
    header h1 {
        font-size: 1.4rem;
        padding-right: 90px;
    }
    
    .subtitle {
        font-size: 0.9rem;
    }
    
    /* Controles superiores en móvil */
    .top-controls {
        top: 10px;
        right: 10px;
        gap: 6px;
    }
    
    .lang-toggle {
        padding: 8px 10px;
    }
    
    .lang-toggle-text {
        display: none;
    }
    
    .theme-toggle {
        padding: 8px 10px;
    }
    
    .theme-toggle-text {
        display: none;
    }
    
    /* Estadísticas */
    .stats-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }
    
    .stat-card {
        padding: 16px 12px;
    }
    
    .stat-value {
        font-size: 1.8rem;
    }
    
    .stat-label {
        font-size: 0.75rem;
    }
    
    /* Cards */
    .card {
        padding: 20px 16px;
        border-radius: 10px;
    }
    
    .card h2 {
        font-size: 1.1rem;
    }
    
    /* Formulario */
    .form-row {
        flex-direction: column;
        gap: 0;
    }
    
    .form-group {
        margin-bottom: 16px;
    }
    
    .form-group input {
        padding: 10px 14px;
        font-size: 16px; /* Evita zoom en iOS */
    }
    
    /* Section header y tabs */
    .section-header {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }
    
    .tabs {
        display: flex;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 6px;
        padding-bottom: 4px;
    }
    
    .tab {
        flex-shrink: 0;
        padding: 8px 14px;
        font-size: 0.85rem;
    }
    
    /* Contratos */
    .contrato-item {
        padding: 16px;
    }
    
    .contrato-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .contrato-nombre {
        font-size: 1rem;
    }
    
    .contrato-info-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    
    .info-firma {
        padding: 14px;
    }
    
    .firma-status-icon {
        width: 36px;
        height: 36px;
        font-size: 1rem;
    }
    
    .contrato-meta {
        flex-direction: column;
        gap: 8px;
    }
    
    .contrato-acciones {
        flex-direction: column;
        gap: 10px;
    }
    
    .btn-trazabilidad {
        width: 100%;
        justify-content: center;
    }
    
    .btn-minar-listo {
        padding: 12px 20px;
        font-size: 0.95rem;
    }
    
    /* Botones */
    .btn {
        padding: 10px 18px;
        font-size: 0.9rem;
        width: 100%;
        justify-content: center;
        margin-right: 0;
        margin-bottom: 8px;
    }
    
    /* Modales */
    .modal-content,
    .modal-firma-content {
        padding: 16px;
        width: 100%;
        max-width: 100%;
        margin: 0;
        max-height: none;
        border-radius: 12px;
    }
    
    .modal-firma {
        padding: 10px;
    }
    
    .modal-header {
        margin-bottom: 12px;
        padding-bottom: 10px;
    }
    
    .modal-header h2 {
        font-size: 1.1rem;
    }
    
    .close-modal {
        width: 36px;
        height: 36px;
        font-size: 1.5rem;
    }
    
    /* Modal firma específico */
    .firma-header {
        margin-bottom: 12px;
    }
    
    .firma-header h3 {
        font-size: 1rem;
    }
    
    .firma-header p {
        font-size: 0.8rem;
    }
    
    .firma-acciones {
        flex-direction: column;
        gap: 8px;
        margin-top: 16px;
    }
    
    .firma-acciones button {
        width: 100%;
        padding: 12px 16px;
    }
    
    .canvas-container {
        margin: 12px 0;
    }
    
    /* Geo y Device info en modal */
    .geo-container,
    .device-info-container {
        padding: 10px;
        margin-bottom: 10px;
    }
    
    .geo-header,
    .device-header {
        margin-bottom: 8px;
    }
    
    .geo-title,
    .device-title {
        font-size: 0.9rem;
    }
    
    .geo-mini-map {
        height: 100px;
    }
    
    .device-info {
        grid-template-columns: 1fr 1fr;
        gap: 6px;
    }
    
    .device-item {
        padding: 6px 8px;
    }
    
    .device-label {
        font-size: 0.6rem;
    }
    
    .device-value {
        font-size: 0.75rem;
    }
    
    .descripcion-proceso {
        margin-bottom: 10px;
    }
    
    .descripcion-proceso textarea {
        min-height: 40px;
    }
    
    /* Trazabilidad */
    .trazabilidad-timeline {
        padding-left: 25px;
    }
    
    .trazabilidad-timeline::before {
        left: 8px;
    }
    
    .traza-item::before {
        left: -21px;
        width: 10px;
        height: 10px;
    }
    
    .traza-item {
        padding: 14px;
    }
    
    .trazabilidad-geo-grid {
        grid-template-columns: 1fr;
    }
    
    .mapa-container {
        height: 220px;
    }
    
    /* Mensajes */
    .mensaje {
        max-width: calc(100% - 40px);
        right: 20px;
        left: 20px;
        font-size: 0.9rem;
        padding: 14px 18px;
    }
    
    /* Blockchain */
    .bloque-item {
        padding: 14px 16px;
    }
    
    .hash {
        font-size: 0.7rem;
        padding: 6px 10px;
    }
}

/* ============================================
   RESPONSIVE - MÓVILES PEQUEÑOS
   ============================================ */
@media (max-width: 480px) {
    body {
        padding: 8px;
    }
    
    header h1 {
        font-size: 1.2rem;
    }
    
    .stats-container {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    
    .stat-card {
        padding: 14px 10px;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .stat-label {
        font-size: 0.7rem;
    }
    
    .card {
        padding: 16px 14px;
    }
    
    .contrato-item {
        padding: 14px;
    }
    
    .info-firma {
        padding: 12px;
        gap: 10px;
    }
    
    .firma-status-icon {
        width: 32px;
        height: 32px;
        font-size: 0.9rem;
    }
    
    .firma-nombre {
        font-size: 0.9rem;
    }
    
    .firma-label {
        font-size: 0.65rem;
    }
    
    .firma-estado-text {
        font-size: 0.75rem;
    }
    
    .device-info {
        grid-template-columns: 1fr;
    }
    
    .modal-content,
    .modal-firma-content {
        padding: 16px;
        width: 98%;
        margin: 5px;
    }
    
    .modal-header h2 {
        font-size: 1rem;
    }
    
    #canvasFirma {
        height: 130px !important;
    }
    
    .btn-print {
        padding: 6px 12px;
        font-size: 0.8rem;
    }
    
    .trazabilidad-entry {
        padding: 12px;
    }
    
    .mapa-container {
        height: 180px;
    }
}

/* ============================================
   SCROLLBAR PERSONALIZADO
   ============================================ */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ============================================
   SELECCIÓN DE TEXTO
   ============================================ */
::selection {
    background: var(--text-primary);
    color: var(--bg-primary);
}

/* ============================================
   GEOLOCALIZACIÓN Y MAPA
   ============================================ */
.geo-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
}

.geo-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}

.geo-icon {
    font-size: 1rem;
}

.geo-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.geo-status {
    padding: 8px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    margin-bottom: 8px;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.geo-loading {
    display: flex;
    align-items: center;
    gap: 8px;
}

.geo-success {
    color: var(--firma-ok);
}

.geo-error {
    color: var(--firma-pending);
}

.geo-warning {
    color: var(--warning);
    font-size: 0.8rem;
}

.geo-status span {
    display: inline-block;
    margin-right: 8px;
}

.geo-mini-map {
    width: 100%;
    height: 100px;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 8px;
    display: none;
}

.geo-mini-map.active {
    display: block;
}

/* Leyenda del mapa */
.map-legend {
    display: flex;
    gap: 12px;
    font-size: 0.7rem;
    margin-top: 4px;
    color: var(--text-secondary);
}

.map-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.legend-marker-gps {
    width: 10px;
    height: 10px;
    background: #22c55e;
    border-radius: 50%;
}

.legend-marker-ip {
    width: 10px;
    height: 10px;
    background: #3b82f6;
    border-radius: 50%;
}

.geo-address {
    font-size: 0.75rem;
    color: var(--text-secondary);
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    display: none;
}

.geo-address.active {
    display: block;
}

/* ============================================
   INFORMACIÓN DEL DISPOSITIVO
   ============================================ */
.device-info-container {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 10px;
}

.device-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.device-icon {
    font-size: 1rem;
}

.device-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.device-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
}

.device-item {
    background: var(--bg-tertiary);
    padding: 6px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
}

.device-label {
    color: var(--text-muted);
    font-size: 0.65rem;
    text-transform: uppercase;
    margin-bottom: 1px;
}

.device-value {
    color: var(--text-primary);
    word-break: break-all;
    font-size: 0.75rem;
}

/* ============================================
   MAPA DE FIRMAS EN TRAZABILIDAD
   ============================================ */
.mapa-firmas-section {
    margin-top: 24px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

.mapa-container {
    width: 100%;
    height: 300px;
    border-radius: 12px;
    overflow: hidden;
    margin-top: 12px;
}

.section-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ============================================
   MODAL MEJORADO PARA TRAZABILIDAD
   ============================================ */
.modal-content-large {
    max-width: 900px;
}

.modal-header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.btn-print {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-print:hover {
    background: var(--bg-secondary);
    box-shadow: var(--shadow-sm);
}

.contrato-detalles-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 24px;
}

/* ============================================
   FIRMA ALMACENADA BOX
   ============================================ */
.firma-almacenada-box {
    margin-bottom: 15px;
    padding: 15px;
    background: var(--firma-ok-bg);
    border: 2px solid var(--firma-ok-border);
    border-radius: 8px;
}

.firma-almacenada-text {
    margin-bottom: 10px;
    color: var(--firma-ok);
    font-weight: 600;
}

.btn-full {
    width: 100%;
}

/* ============================================
   TRAZABILIDAD CON INFO EXTENDIDA
   ============================================ */
.trazabilidad-entry {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
}

.trazabilidad-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.trazabilidad-estado {
    font-weight: 600;
    color: var(--text-primary);
}

.trazabilidad-fecha {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.trazabilidad-descripcion {
    color: var(--text-secondary);
    margin-bottom: 12px;
    font-size: 0.9rem;
}

.trazabilidad-geo-info {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 12px;
    margin-top: 12px;
}

.trazabilidad-geo-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
}

.trazabilidad-geo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px;
}

.trazabilidad-geo-item {
    background: var(--bg-primary);
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
}

.trazabilidad-geo-item strong {
    color: var(--text-muted);
    display: block;
    font-size: 0.7rem;
    margin-bottom: 2px;
}

/* Responsive para geo/device info */
@media (max-width: 600px) {
    .device-info {
        grid-template-columns: 1fr;
    }
    
    .trazabilidad-geo-grid {
        grid-template-columns: 1fr;
    }
    
    .modal-header-actions {
        flex-direction: column;
        gap: 8px;
        width: 100%;
    }
    
    .modal-header-actions .btn-print {
        width: 100%;
    }
    
    .contrato-info-grid-modal {
        grid-template-columns: 1fr;
    }
}

/* ============================================
   ESTILOS ADICIONALES TRAZABILIDAD
   ============================================ */
.contrato-titulo {
    margin-bottom: 12px;
    color: var(--text-primary);
    font-size: 1.25rem;
}

.contrato-info-grid-modal {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
}

.info-item {
    padding: 8px 0;
    border-bottom: 1px solid var(--border-light);
}

.info-item:last-child {
    border-bottom: none;
}

.info-item .mono {
    font-family: 'Courier New', monospace;
    font-size: 0.85rem;
    word-break: break-all;
}

.trazabilidad-firmante {
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.firma-imagen-container {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: 8px;
    border: 2px solid var(--border-color);
}

.firma-imagen {
    max-width: 100%;
    height: auto;
    margin-top: 8px;
    border: 1px solid var(--border-light);
    border-radius: 4px;
}

/* Mapbox overrides para tema oscuro */
[data-theme="dark"] .mapboxgl-popup-content {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

[data-theme="dark"] .mapboxgl-popup-tip {
    border-top-color: var(--bg-secondary);
}

[data-theme="dark"] .mapboxgl-ctrl-group {
    background: var(--bg-secondary);
}

[data-theme="dark"] .mapboxgl-ctrl-group button {
    background-color: var(--bg-secondary);
}

[data-theme="dark"] .mapboxgl-ctrl-group button + button {
    border-top-color: var(--border-color);
}

/* ============================================
   CAPTURA DE FOTO DEL FIRMANTE
   ============================================ */
.foto-firmante-container {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    border: 1px solid #f59e0b;
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
}

.dark-theme .foto-firmante-container,
[data-theme="dark"] .foto-firmante-container {
    background: linear-gradient(135deg, #451a03 0%, #78350f 100%);
    border-color: #b45309;
}

.foto-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.foto-icon {
    font-size: 1.1rem;
}

.foto-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.9rem;
}

.foto-badge {
    font-size: 0.7rem;
    color: #92400e;
    background: rgba(255, 255, 255, 0.5);
    padding: 2px 8px;
    border-radius: 10px;
}

.dark-theme .foto-badge,
[data-theme="dark"] .foto-badge {
    color: #fcd34d;
    background: rgba(0, 0, 0, 0.3);
}

.foto-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.camera-preview {
    width: 180px;
    height: 180px;
    border-radius: 50%;
    overflow: hidden;
    background: #000;
    position: relative;
    border: 4px solid var(--bg-primary);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.camera-preview video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1); /* Espejo para cámara frontal */
}

.camera-placeholder {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #374151 0%, #1f2937 100%);
    color: #9ca3af;
    font-size: 0.75rem;
    text-align: center;
    padding: 10px;
}

.camera-icon-big {
    font-size: 2.5rem;
    margin-bottom: 8px;
    opacity: 0.7;
}

.foto-capturada {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.foto-capturada img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

.foto-overlay {
    position: absolute;
    bottom: 5px;
    right: 5px;
    background: #22c55e;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.foto-check {
    color: white;
    font-size: 1.1rem;
    font-weight: bold;
}

.foto-actions {
    display: flex;
    gap: 10px;
}

.btn-capturar-foto,
.btn-retomar-foto {
    padding: 8px 16px;
    border-radius: 20px;
    border: none;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 5px;
}

.btn-capturar-foto {
    background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
    color: white;
}

.btn-capturar-foto:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.4);
}

.btn-capturar-foto:disabled {
    background: #9ca3af;
    cursor: not-allowed;
    transform: none;
}

.btn-retomar-foto {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-retomar-foto:hover {
    background: var(--bg-secondary);
}

.foto-hint {
    font-size: 0.7rem;
    color: #92400e;
    text-align: center;
    margin: 0;
    opacity: 0.8;
}

.dark-theme .foto-hint,
[data-theme="dark"] .foto-hint {
    color: #fcd34d;
}

/* Animación de flash al capturar */
@keyframes camera-flash {
    0% { opacity: 0; }
    50% { opacity: 1; }
    100% { opacity: 0; }
}

.camera-flash {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: white;
    pointer-events: none;
    animation: camera-flash 0.3s ease-out;
}

/* Indicador de grabación */
.recording-indicator {
    position: absolute;
    top: 10px;
    left: 10px;
    width: 12px;
    height: 12px;
    background: #ef4444;
    border-radius: 50%;
    animation: pulse-recording 1s infinite;
}

@keyframes pulse-recording {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

/* Responsive para móviles */
@media (max-width: 600px) {
    .camera-preview {
        width: 140px;
        height: 140px;
    }
    
    .foto-actions {
        flex-direction: column;
        width: 100%;
    }
    
    .btn-capturar-foto,
    .btn-retomar-foto {
        width: 100%;
        justify-content: center;
    }
}

