/* 
 * AISLAME APP - Estilos principales
 * Diseño moderno y profesional para comerciales
 */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@400;500;600;700&display=swap');

:root {
    /* Colores principales - Basados en el logo de AislaMe */
    --color-primary: #f97316;
    --color-primary-dark: #ea580c;
    --color-primary-light: #fdba74;
    --color-secondary: #0891b2;
    --color-secondary-light: #22d3ee;
    
    /* Fondos */
    --bg-main: #fff7ed;
    --bg-card: #ffffff;
    --bg-input: #f8fafc;
    
    /* Textos */
    --text-primary: #0f172a;
    --text-secondary: #475569;
    --text-muted: #94a3b8;
    
    /* Estados */
    --color-success: #10b981;
    --color-error: #ef4444;
    --color-warning: #f59e0b;
    
    /* Sombras */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    
    /* Bordes */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
}

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

body {
    font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* ===== LAYOUT ===== */
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    padding-bottom: 40px;
}

.container-wide {
    max-width: 1000px;
}

/* ===== HEADER ===== */
.header {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-secondary) 100%);
    color: white;
    padding: 16px 20px;
    position: sticky;
    top: 0;
    z-index: 100;
    will-change: padding;
}

.header-main {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.header-brand {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.header-logo {
    background: rgba(255,255,255,0.95);
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    will-change: padding;
    transition: padding 0.4s ease;
}

.logo-img {
    height: 36px;
    width: auto;
    will-change: height;
    transition: height 0.4s ease;
}

.header-user-name {
    font-weight: 500;
    font-size: 0.85rem;
    opacity: 1;
    max-height: 30px;
    overflow: hidden;
    will-change: opacity, max-height;
    transition: opacity 0.4s ease, max-height 0.4s ease;
}

.header-user {
    display: flex;
    align-items: center;
    gap: 8px;
}

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

.header-subtitle {
    font-size: 0.9rem;
    opacity: 1;
    font-weight: 500;
    text-align: center;
    padding: 8px 0 0 0;
    border-top: 1px solid rgba(255,255,255,0.2);
    max-height: 50px;
    overflow: hidden;
    will-change: opacity, max-height, padding;
    transition: opacity 0.4s ease, max-height 0.4s ease, padding 0.4s ease;
}

/* Header compacto al hacer scroll */
.header.header-compact {
    padding: 10px 16px;
}

.header.header-compact .header-logo {
    padding: 4px 8px;
}

.header.header-compact .logo-img {
    height: 26px;
}

.header.header-compact .header-user-name {
    opacity: 0;
    max-height: 0;
}

.header.header-compact .header-subtitle {
    opacity: 0;
    max-height: 0;
    padding: 0;
    border-top: none;
}

.btn-header {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.btn-header:hover {
    background: rgba(255,255,255,0.3);
}

.btn-logout {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    cursor: pointer;
    transition: background 0.2s;
    text-decoration: none;
}

.btn-logout:hover {
    background: rgba(255,255,255,0.3);
}

/* ===== CARDS ===== */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 24px;
    margin-bottom: 20px;
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 20px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--color-primary-light);
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-title-icon {
    width: 28px;
    height: 28px;
    background: var(--color-primary);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.9rem;
}

/* ===== FORMULARIOS ===== */
.form-group {
    margin-bottom: 18px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

@media (max-width: 500px) {
    .form-row {
        grid-template-columns: 1fr;
    }
}

label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

label .required {
    color: var(--color-error);
    margin-left: 2px;
}

input[type="text"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="password"],
select,
textarea {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid #e2e8f0;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-family: inherit;
    background: var(--bg-input);
    color: var(--text-primary);
    transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.1);
}

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

input:invalid:not(:placeholder-shown) {
    border-color: var(--color-error);
}

textarea {
    resize: vertical;
    min-height: 100px;
}

select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 40px;
}

/* ===== RADIO Y CHECKBOX ===== */
.radio-option,
.checkbox-option {
    flex: 1;
    min-width: 140px;
}

.radio-option input,
.checkbox-option input {
    display: none;
}

.radio-option label,
.checkbox-option label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 14px 16px;
    min-height: 56px;
    height: 100%;
    background: var(--bg-input);
    border: 2px solid #e2e8f0;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
    text-align: center;
    line-height: 1.3;
}

.radio-group,
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: stretch;
}

.radio-option input:checked + label,
.checkbox-option input:checked + label {
    background: var(--color-primary);
    border-color: var(--color-primary);
    color: white;
}

.radio-option label:hover,
.checkbox-option label:hover {
    border-color: var(--color-primary);
}

/* ===== UPLOAD DE FOTOS ===== */
.upload-area {
    border: 2px dashed #cbd5e1;
    border-radius: var(--radius-md);
    padding: 30px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-input);
}

.upload-area:hover {
    border-color: var(--color-primary);
    background: rgba(249, 115, 22, 0.05);
}

.upload-area.dragover {
    border-color: var(--color-primary);
    background: rgba(249, 115, 22, 0.1);
}

.upload-icon {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.upload-text {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.upload-text strong {
    color: var(--color-primary);
}

.upload-input {
    display: none;
}

.preview-container {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 10px;
    margin-top: 15px;
}

.preview-item {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    background: var(--color-error);
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ===== BOTONES ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 28px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--color-primary) 0%, var(--color-primary-dark) 100%);
    color: white;
    box-shadow: 0 4px 14px rgba(249, 115, 22, 0.4);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(249, 115, 22, 0.5);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 2px solid #e2e8f0;
}

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

.btn-block {
    width: 100%;
}

.btn-lg {
    padding: 16px 32px;
    font-size: 1.1rem;
}

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

/* ===== MENSAJES ===== */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 10px;
}

.alert-success {
    background: #ecfdf5;
    color: #065f46;
    border: 1px solid #a7f3d0;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

.alert-info {
    background: #f0f9ff;
    color: #075985;
    border: 1px solid #bae6fd;
}

/* ===== LOGIN ===== */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #f97316 0%, #0891b2 100%);
}

.login-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 40px;
    width: 100%;
    max-width: 400px;
}

.login-logo {
    text-align: center;
    margin-bottom: 30px;
}

.login-logo img {
    height: 80px;
    width: auto;
}

.login-logo p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 10px;
}

/* ===== TABLA DE CLIENTES ===== */
.table-container {
    overflow-x: auto;
    margin: -24px;
    margin-top: 0;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.table th,
.table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid #e2e8f0;
}

.table th {
    background: var(--bg-input);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.table tr:hover {
    background: #f8fafc;
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-pendiente {
    background: #fef3c7;
    color: #92400e;
}

.badge-en_proceso {
    background: #dbeafe;
    color: #1e40af;
}

.badge-completado {
    background: #d1fae5;
    color: #065f46;
}

/* ===== UTILIDADES ===== */
.text-center {
    text-align: center;
}

.text-muted {
    color: var(--text-muted);
}

.mt-20 {
    margin-top: 20px;
}

.mb-20 {
    margin-bottom: 20px;
}

/* ===== ANIMACIONES ===== */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.card {
    animation: fadeIn 0.3s ease-out;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 480px) {
    .container {
        padding: 15px;
    }
    
    .card {
        padding: 18px;
    }
    
    .header {
        padding: 15px;
    }
    
    .logo-img {
        height: 40px;
    }
}

/* ===== LOADING SPINNER ===== */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255,255,255,0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.btn-loading {
    pointer-events: none;
}

.btn-loading .btn-text {
    visibility: hidden;
}

.btn-loading .spinner {
    position: absolute;
}

/* ===== SUGERENCIAS LOCALIDADES ===== */
.sugerencias-container {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 2px solid var(--color-primary);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    max-height: 200px;
    overflow-y: auto;
    z-index: 1000;
    box-shadow: var(--shadow-md);
}

.form-group {
    position: relative;
}

.sugerencia-item {
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid #e2e8f0;
    transition: background 0.2s;
}

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

.sugerencia-item:hover {
    background: var(--color-primary-light);
}

/* ===== CAMPO ERROR ===== */
.campo-error {
    border-color: var(--color-error) !important;
    animation: shake 0.5s ease-in-out;
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.2) !important;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

/* ===== DNI/NIE CONTAINER ===== */
.dni-container {
    display: flex;
    gap: 10px;
}

.tipo-doc-select {
    width: 85px;
    flex-shrink: 0;
    padding: 12px 10px;
    text-align: left;
}

.dni-input {
    flex: 1;
    text-transform: uppercase;
    font-family: 'Courier New', monospace;
    font-size: 1.05rem;
    letter-spacing: 1px;
}

.dni-feedback {
    display: block;
    margin-top: 4px;
    font-size: 0.75rem;
}

.dni-feedback.valid {
    color: var(--color-success);
}

.dni-feedback.invalid {
    color: var(--color-error);
}

/* Toggle WhatsApp */
.whatsapp-toggle {
    display: inline-flex;
    cursor: pointer;
}

.whatsapp-toggle input {
    display: none;
}

.whatsapp-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: #e2e8f0;
    border: 2px solid #cbd5e1;
    border-radius: 10px;
    font-size: 0.9rem;
    font-weight: 500;
    color: #64748b;
    transition: all 0.2s;
}

.whatsapp-toggle input:checked + .whatsapp-btn {
    background: #25D366;
    border-color: #25D366;
    color: white;
}

/* ===== LOPD/RGPD ===== */
.card-lopd {
    background: #fffbeb;
    border: 2px solid #fcd34d;
}

.lopd-container {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.lopd-checkbox {
    position: relative;
    flex-shrink: 0;
    cursor: pointer;
}

.lopd-checkbox input {
    position: absolute;
    opacity: 0;
    cursor: pointer;
    height: 0;
    width: 0;
}

.lopd-checkmark {
    display: block;
    width: 24px;
    height: 24px;
    background: white;
    border: 2px solid #d97706;
    border-radius: 6px;
    transition: all 0.2s;
}

.lopd-checkbox input:checked + .lopd-checkmark {
    background: #10b981;
    border-color: #10b981;
}

.lopd-checkbox input:checked + .lopd-checkmark::after {
    content: '✓';
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 14px;
    font-weight: bold;
    height: 100%;
}

.lopd-texto {
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.lopd-texto a {
    color: var(--color-primary);
    text-decoration: underline;
}

.lopd-texto .required {
    color: var(--color-error);
}

.lopd-aviso {
    margin-top: 12px;
    padding: 10px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #dc2626;
    font-size: 0.85rem;
    font-weight: 500;
}

/* ===== BOTONES ENVÍO ===== */
.botones-envio {
    margin-bottom: 40px;
}

#btnForzar {
    font-size: 0.9rem;
    opacity: 0.7;
}

#btnForzar:hover {
    opacity: 1;
}

/* ===== FILAS CLICABLES ===== */
.cliente-row {
    transition: background 0.2s, transform 0.1s;
}

.cliente-row:hover {
    background: #fff7ed !important;
}

.cliente-row:active {
    transform: scale(0.99);
}

/* ===== MODAL DE ERRORES ===== */
.modal-errores {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-errores.active {
    display: flex;
}

.modal-errores-content {
    background: white;
    border-radius: 16px;
    max-width: 400px;
    width: 100%;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    animation: modalSlide 0.3s ease;
}

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

.modal-errores-header {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    padding: 16px 20px;
    font-size: 1.1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.modal-errores-header span {
    font-size: 1.3rem;
}

.modal-errores-body {
    padding: 20px;
    max-height: 300px;
    overflow-y: auto;
}

.modal-errores-body ul {
    margin: 0;
    padding-left: 20px;
}

.modal-errores-body li {
    padding: 6px 0;
    color: var(--text-secondary);
}

.modal-errores-footer {
    padding: 16px 20px;
    border-top: 1px solid #e2e8f0;
    text-align: center;
}
