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

:root {
    --primary-color: #2563eb;
    --primary-dark: #1e40af;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --error-color: #ef4444;
    --bg-overlay: rgba(15, 23, 42, 0);
    --card-bg: rgba(255, 255, 255, 0.98);
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    min-height: 100vh;
    background-image: url('../images/background.jpg');
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    background-attachment: fixed;
    position: relative;
}

body .logo-top-left,
img.logo-top-left {
    position: fixed !important;
    top: 20px !important;
    left: 20px !important;
    height: 80px !important;
    width: auto !important;
    max-width: 280px !important;
    z-index: 1000 !important;
    background: transparent !important;
    padding: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    transition: transform 0.3s ease !important;
    display: block !important;
    object-fit: contain !important;
    margin: 0 !important;
}

body .logo-top-left:hover,
img.logo-top-left:hover {
    transform: scale(1.05) !important;
}

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    padding-top: 100px; 
}

.login-container {
    width: 100%;
    max-width: 450px;
    animation: fadeInUp 0.6s ease-out;
}

.login-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.logo-section {
    text-align: center;
    margin-bottom: 35px;
}

.logo-section h1 {
    font-size: 28px;
    color: var(--primary-color);
    margin-bottom: 8px;
    font-weight: 700;
}

.logo-section img {
    display: none !important;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 600;
    color: var(--text-primary);
    font-size: 14px;
}

.form-control {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    font-size: 15px;
    transition: all 0.3s ease;
    background: white;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-text {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.form-control-file {
    width: 100%;
    padding: 10px;
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    background: #f8fafc;
    transition: all 0.3s ease;
}

.form-control-file:hover {
    border-color: var(--primary-color);
    background: #eff6ff;
}

/* Buttons */
.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

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

.btn-primary:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
}

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

.btn-secondary:hover {
    background: #475569;
}

.btn-block {
    width: 100%;
    display: block;
}

.btn-large {
    padding: 16px 24px;
    font-size: 16px;
}

/* Alerts */
.alert {
    padding: 14px 16px;
    border-radius: 8px;
    margin-bottom: 20px;
    font-size: 14px;
}

.alert-error {
    background: #fee;
    color: var(--error-color);
    border: 1px solid #fcc;
}

/* Footer Info */
.footer-info {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid var(--border-color);
}

.footer-info p {
    color: var(--text-secondary);
    font-size: 13px;
    margin: 4px 0;
}

.small-text {
    font-size: 11px !important;
}

.dashboard-page {
    padding: 20px;
    min-height: 100vh;
    padding-top: 100px; 
}

.dashboard-container {
    max-width: 900px;
    margin: 0 auto;
    animation: fadeInUp 0.6s ease-out;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--card-bg);
    padding: 20px 30px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.dashboard-header h1 {
    font-size: 24px;
    color: var(--primary-color);
}

.welcome-section {
    background: linear-gradient(135deg, var(--primary-color), var(--primary-dark));
    color: white;
    padding: 24px 30px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.welcome-section h2 {
    font-size: 22px;
    font-weight: 600;
}

.balance-card {
    background: var(--card-bg);
    padding: 30px;
    border-radius: 12px;
    text-align: center;
    margin-bottom: 30px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.balance-label {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.balance-amount {
    font-size: 48px;
    font-weight: 700;
    color: var(--success-color);
    margin: 10px 0;
}

.balance-rut {
    font-size: 14px;
    color: var(--text-secondary);
    margin-top: 10px;
}

.compra-form {
    background: var(--card-bg);
    padding: 35px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

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

.search-results {
    position: absolute;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    margin-top: 4px;
    max-height: 250px;
    overflow-y: auto;
    z-index: 1000;
    width: calc(100% - 4px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: none;
}

.search-results.active {
    display: block;
}

.search-result-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s ease;
}

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

.search-result-item:hover {
    background: #f1f5f9;
}

.search-result-item strong {
    display: block;
    color: var(--text-primary);
}

.search-result-item small {
    color: var(--text-secondary);
    font-size: 12px;
}

.total-section {
    background: #f8fafc;
    padding: 20px;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 20px 0;
    font-size: 18px;
    font-weight: 600;
}

.total-amount {
    color: var(--primary-color);
    font-size: 24px;
}

.radio-group {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.radio-label {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-weight: 500;
}

.radio-label:hover {
    background: #f8fafc;
    border-color: var(--primary-color);
}

.radio-label input[type="radio"] {
    margin-right: 12px;
    width: 18px;
    height: 18px;
    cursor: pointer;
}

.radio-label input[type="radio"]:checked + span {
    color: var(--primary-color);
}

.success-page,
.error-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    padding-top: 100px; 
}

.success-container,
.error-container {
    width: 100%;
    max-width: 500px;
}

.success-card,
.error-card {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 50px 40px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: fadeInUp 0.6s ease-out;
}

.success-icon {
    width: 80px;
    height: 80px;
    background: var(--success-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 30px;
    font-size: 48px;
    color: white;
    animation: scaleIn 0.5s ease-out 0.2s both;
}

.error-icon {
    width: 80px;
    height: 80px;
    background: var(--error-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 30px;
    font-size: 48px;
    color: white;
    animation: scaleIn 0.5s ease-out 0.2s both;
}

.success-card h1,
.error-card h1 {
    font-size: 26px;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.redirect-text {
    color: var(--text-secondary);
    margin: 20px 0;
    font-size: 14px;
}

#countdown {
    font-weight: 700;
    color: var(--primary-color);
}

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

@keyframes scaleIn {
    from {
        transform: scale(0);
    }
    to {
        transform: scale(1);
    }
}

@media (max-width: 768px) {
    .login-card,
    .compra-form {
        padding: 25px;
    }
    
    .dashboard-header {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .form-row {
        grid-template-columns: 1fr;
    }
    
    .balance-amount {
        font-size: 36px;
    }
    
    .welcome-section h2 {
        font-size: 18px;
    }
    
    body .logo-top-left,
    img.logo-top-left {
        height: 60px !important;
        top: 15px !important;
        left: 15px !important;
        padding: 0 !important;
        max-width: 220px !important;
    }
    
    .login-page,
    .dashboard-page,
    .success-page,
    .error-page {
        padding-top: 80px !important;
    }
}

#comercio_resultados {
    position: absolute !important;
    width: calc(100% - 4px) !important;
    max-width: calc(100% - 4px) !important;
    box-sizing: border-box !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    max-height: 300px !important;
    z-index: 1000 !important;
    left: 0 !important;
    right: 0 !important;
}

#comercio_resultados div,
#comercio_resultados .search-result-item {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
}

.reset-section {
    background: #fef3c7;
    border: 2px solid #fbbf24;
    padding: 20px;
    border-radius: 8px;
    margin-top: 30px;
}

.reset-section h3 {
    color: #92400e;
    margin-bottom: 15px;
}

.reset-form {
    display: flex;
    gap: 10px;
    align-items: end;
}

.reset-form .form-group {
    flex: 1;
    margin-bottom: 0;
}

.btn-warning {
    background: #f59e0b;
    color: white;
}

.btn-warning:hover {
    background: #d97706;
}

.btn-danger {
    background: #ef4444;
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

.log-section {
    background: #f8fafc;
    padding: 20px;
    border-radius: 8px;
    margin-top: 20px;
    border: 1px solid #e2e8f0;
}

.log-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
    font-size: 14px;
}

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

.log-table th {
    background: #f1f5f9;
    font-weight: 600;
    color: #1e293b;
}

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