/* --- Reset y Variables Globales --- */
:root {
    --primary-color: #673AB7; /* Un morado estilo Google Material Design */
    --primary-color-dark: #512DA8;
    --secondary-color: #f4f5f7;
    --text-color: #333;
    --text-color-light: #777;
    --border-color: #e0e0e0;
    --background-color: #ffffff;
    --status-processed: #4CAF50; /* Verde */
    --status-pending: #FFC107;   /* Ámbar */
    --status-error: #F44336;     /* Rojo */
    --font-family: 'Roboto', sans-serif;
}

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

body {
    font-family: var(--font-family);
    background-color: var(--secondary-color);
    color: var(--text-color);
    line-height: 1.6;
}

/* --- Layout y Contenedores --- */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.main-header {
    background-color: var(--background-color);
    padding: 15px 0;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

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

.main-header h1 {
    color: var(--primary-color);
    font-weight: 500;
}

.main-header nav span {
    margin-right: 15px;
    color: var(--text-color-light);
}

footer {
    text-align: center;
    padding: 20px;
    margin-top: 40px;
    color: var(--text-color-light);
    font-size: 0.9em;
}

/* --- Componentes UI --- */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 1em;
    font-weight: 500;
    text-decoration: none;
    display: inline-block;
    transition: background-color 0.3s ease;
}

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

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

.btn-secondary {
    background-color: #e0e0e0;
    color: var(--text-color);
}

.btn-secondary:hover {
    background-color: #bdbdbd;
}

.btn-google {
    display: flex;
    align-items: center;
    gap: 10px;
    background-color: white;
    color: #444;
    border: 1px solid var(--border-color);
    width: 100%;
    justify-content: center;
}

.btn-google:hover {
    background-color: #f5f5f5;
}

.btn-google img {
    width: 20px;
    height: 20px;
}

/* --- Dashboard --- */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.invoice-list table {
    width: 100%;
    border-collapse: collapse;
    background-color: white;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
    border-radius: 8px;
    overflow: hidden;
}

.invoice-list th, .invoice-list td {
    padding: 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}

.invoice-list th {
    background-color: #f9f9f9;
    font-weight: 500;
}

.invoice-list .empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-color-light);
}

.status-badge {
    padding: 5px 10px;
    border-radius: 15px;
    font-size: 0.8em;
    color: white;
    font-weight: 500;
}

.status-procesado { background-color: var(--status-processed); }
.status-pendiente, .status-en_proceso { background-color: var(--status-pending); color: #333; }
.status-error { background-color: var(--status-error); }


/* --- Modal --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
}

.modal-content h3 {
    margin-bottom: 20px;
}

.modal-actions {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

#invoice-file-input {
    width: 100%;
    padding: 10px;
    border: 2px dashed var(--border-color);
    border-radius: 5px;
    cursor: pointer;
}

.spinner {
    border: 4px solid rgba(0, 0, 0, 0.1);
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border-left-color: var(--primary-color);
    animation: spin 1s ease infinite;
    margin: 20px auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* --- Responsividad --- */
@media (max-width: 768px) {
    .main-header .container {
        flex-direction: column;
        gap: 10px;
    }
    
    .invoice-list table thead {
        display: none; /* Oculta encabezados */
    }
    
    .invoice-list table, .invoice-list table tbody, .invoice-list table tr, .invoice-list table td {
        display: block;
        width: 100%;
    }
    
    .invoice-list table tr {
        margin-bottom: 15px;
        border: 1px solid var(--border-color);
        border-radius: 5px;
    }
    
    .invoice-list table td {
        text-align: right;
        padding-left: 50%;
        position: relative;
        border-bottom: 1px solid #f0f0f0;
    }
    
    .invoice-list table td::before {
        content: attr(data-label);
        position: absolute;
        left: 15px;
        width: calc(50% - 30px);
        padding-right: 10px;
        text-align: left;
        font-weight: 500;
    }
    
    /* Añade el atributo data-label en el HTML/PHP */
    /* <td data-label="Nº Documento">...</td> */
}

/* --- Mejoras de UX y Estética (HU6) --- */
.btn {
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.btn-google {
    border: 1px solid #444; /* Borde más oscuro */
    background: #1a1a1a; /* Fondo negro */
    color: #fff; /* Texto blanco */
}
.btn-google:hover {
    background: #333;
    border-color: var(--primary-color);
}
/* -- Fin mejoras HU6 -- */

/* --- NUEVO LAYOUT Y HEADER (Épica 3 y 4) --- */
.app-layout {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    background-color: #ffffff;
    padding: 0 20px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
    height: 64px;
}

.logo a {
    text-decoration: none;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--primary-color);
}

.app-main-content {
    flex-grow: 1;
    padding: 20px;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
}


/* --- MENÚ DE PERFIL DE USUARIO (HU-010, HU-011, HU-012) --- */
.user-profile-menu {
    position: relative;
}

.profile-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.3s ease;
}

.profile-avatar:hover {
    border-color: var(--primary-color);
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
    width: 240px;
    z-index: 101;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
}

.dropdown-menu.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.dropdown-header {
    padding: 15px;
    border-bottom: 1px solid var(--border-color);
}
.dropdown-header strong { display: block; }
.dropdown-header span { font-size: 0.8em; color: var(--text-color-light); }

.dropdown-item {
    display: block;
    padding: 12px 15px;
    text-decoration: none;
    color: var(--text-color);
    font-size: 0.9em;
}

.dropdown-item:hover {
    background-color: var(--secondary-color);
}

.dropdown-item.logout {
    color: var(--status-error);
}


/* --- REDISEÑO DEL DASHBOARD: GRID DE TARJETAS (HU-008, HU-009) --- */
.dashboard-container {
    width: 100%;
}

.invoice-grid {
    display: grid;
    grid-template-columns: 1fr; /* Mobile First: 1 columna */
    gap: 20px;
}

.invoice-card {
    background: #ffffff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    flex-direction: column;
}

.invoice-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 15px;
}

.invoice-number {
    font-weight: 500;
    color: var(--text-color);
}

.card-body .issuer-name {
    font-weight: 500;
    font-size: 1.1em;
    margin-bottom: 5px;
}
.card-body .invoice-date {
    font-size: 0.9em;
    color: var(--text-color-light);
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: auto; /* Empuja el footer hacia abajo */
    padding-top: 15px;
}

.invoice-amount {
    font-size: 1.2em;
    font-weight: 700;
    color: var(--primary-color);
}

.btn-action {
    text-decoration: none;
    color: var(--primary-color);
    font-weight: 500;
    font-size: 0.9em;
}

.empty-state-card {
    background: #ffffff;
    border-radius: 8px;
    padding: 40px;
    text-align: center;
    color: var(--text-color-light);
    border: 2px dashed var(--border-color);
}

/* Breakpoints para Desktop (2+ columnas) */
@media (min-width: 768px) {
    .invoice-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 1024px) {
    .invoice-grid {
        /* Crea columnas automáticas que tengan un mínimo de 320px */
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    }
}

/* --- Estilos Módulo ECHO --- */
.card {
    background: #fff;
    padding: 25px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.07);
    margin-bottom: 20px;
}
.echo-container .subtitle {
    color: var(--text-color-light);
    margin-bottom: 20px;
}
.form-group { margin-bottom: 15px; }
.form-group label { display: block; margin-bottom: 5px; font-weight: 500; }
.select-wrapper { position: relative; }
.select-wrapper::after {
    content: '▼';
    font-size: 12px;
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}
#workflow-select {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 5px;
    background-color: #fff;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    font-size: 1em;
}
#workflow-select:disabled {
    background-color: #f5f5f5;
    cursor: not-allowed;
}
.result-box .url-display {
    display: flex;
    margin-top: 10px;
    margin-bottom: 5px;
}
#webhook-url-display {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 5px 0 0 5px;
    background-color: #f9f9f9;
    font-family: monospace;
}
#copy-url-btn {
    padding: 0 15px;
    border: 1px solid var(--border-color);
    border-left: none;
    background: var(--secondary-color);
    cursor: pointer;
    border-radius: 0 5px 5px 0;
}
#webhook-type-info {
    color: var(--text-color-light);
    font-style: italic;
}
.error-message {
    background-color: #fff0f0;
    border-left: 4px solid var(--status-error);
    color: #c0392b;
    padding: 15px;
}


/* --- ESTILOS PARA LA NUEVA PÁGINA DE LOGIN (Épica 1 y 2) --- */

/* Reseteo del body para un fondo limpio */
.login-page-body {
    background-color: #ffffff; /* Fondo blanco como base */
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    margin: 0;
}

.login-screen-container {
    width: 100%;
    max-width: 450px; /* Ancho máximo para el contenido en móviles */
    padding: 20px;
    text-align: center;
    display: flex;
    flex-direction: column;
}

/* Contenedor de la animación */
.login-animation-wrapper {
    width: 100%;
    max-width: 300px;
    margin: 0 auto 20px auto;
}

/* Contenedor del texto y botón */
.login-content-wrapper {
    width: 100%;
}

/* HU-001: Estilo del Título */
.login-title {
    font-size: 3rem; /* 48px */
    font-weight: 700;
    color: #6C63FF; /* Azul morado principal */
    margin-bottom: 10px;
}

/* HU-002: Estilo de la Descripción */
.login-description {
    font-size: 1rem; /* 16px */
    color: #777;
    margin-bottom: 40px;
    line-height: 1.5;
}

/* HU-004: Nuevo estilo del botón de Google */
.btn-google-rebranded {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    width: 100%;
    max-width: 320px;
    padding: 12px 20px;
    border-radius: 50px; /* Bordes bien redondeados */
    border: 1px solid #e0e0e0;
    background-color: #ffffff;
    color: #333;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.btn-google-rebranded:hover {
    box-shadow: 0 6px 16px rgba(0,0,0,0.12);
    transform: translateY(-2px);
    border-color: #cccccc;
}

.btn-google-rebranded img {
    width: 22px;
    height: 22px;
}

/* --- HU-005 y HU-006: Diseño Responsive y Adaptativo --- */

/* Estilos base (Mobile First) ya están definidos arriba */

/* Tablet (768px y más) */
@media (min-width: 768px) {
    .login-screen-container {
        max-width: 600px; /* Más espacio en tablets */
    }

    .login-animation-wrapper {
        max-width: 400px; /* Animación más grande */
        margin-bottom: 30px;
    }

    .login-title {
        font-size: 4rem; /* 64px */
    }

    .login-description {
        font-size: 1.125rem; /* 18px */
    }
}

/* Desktop (1024px y más) - Diseño de dos columnas */
@media (min-width: 1024px) {
    .login-screen-container {
        flex-direction: row; /* Cambiamos a layout horizontal */
        align-items: center;
        justify-content: center;
        max-width: 1000px;
        gap: 5%; /* Espacio entre animación y contenido */
    }

    .login-animation-wrapper, .login-content-wrapper {
        flex: 1; /* Cada uno toma la mitad del espacio */
        max-width: 450px;
    }

    .login-content-wrapper {
        text-align: left; /* Alineamos el texto a la izquierda en desktop */
    }

    .btn-google-rebranded {
        margin: 0; /* Quitamos el centrado automático */
    }
}


/* --- ESTILOS PARA EL MODAL DE CARGA MEJORADO --- */

.modal-view {
    display: none; /* Ocultamos todas las vistas por defecto */
}
.modal-view.active {
    display: block; /* Mostramos solo la activa */
}

.upload-options-buttons {
    display: flex;
    gap: 15px;
    margin-top: 20px;
}

.btn-upload-option {
    flex: 1;
    padding: 20px;
    border: 2px dashed var(--border-color);
    background-color: var(--secondary-color);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    font-size: 1em;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
}

.btn-upload-option:hover {
    border-color: var(--primary-color);
    background-color: #e8eaf6; /* Un azul/morado muy claro */
}

.btn-upload-option span {
    font-size: 2em;
}

#camera-feed, #camera-preview {
    width: 100%;
    max-height: 400px;
    border-radius: 8px;
    background-color: #000;
    margin: 15px 0;
}

.modal-footer {
    margin-top: 20px;
    text-align: center;
}
.btn-link {
    background: none;
    border: none;
    color: var(--text-color-light);
    cursor: pointer;
    text-decoration: underline;
}

/* --- ESTILOS PARA LA PÁGINA DE DETALLE DE FACTURA --- */

.invoice-detail-container {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

.detail-page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.btn-back {
    text-decoration: none;
    color: var(--text-color-light);
    font-weight: 500;
}
.btn-back:hover {
    color: var(--primary-color);
}

.detail-card {
    background: #ffffff;
    border-radius: 8px;
    padding: 25px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

.detail-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 15px;
    margin-bottom: 20px;
}
.detail-card-header h2 .doc-number {
    color: var(--primary-color);
    font-weight: 500;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
}
.detail-grid div {
    line-height: 1.4;
}
.detail-grid strong {
    display: block;
    margin-bottom: 5px;
    font-size: 0.9em;
    color: var(--text-color-light);
}
.detail-grid p {
    font-size: 1.1em;
    font-weight: 500;
}
.detail-grid .total-amount {
    font-size: 1.5em;
    font-weight: 700;
    color: var(--primary-color);
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
}
.items-table {
    width: 100%;
    border-collapse: collapse;
}
.items-table th, .items-table td {
    padding: 12px 15px;
    text-align: left;
    border-bottom: 1px solid var(--border-color);
}
.items-table th {
    background-color: #f9f9f9;
}
.items-table td {
    vertical-align: top;
}

.raw-json-box {
    background-color: #f5f5f5;
    border-radius: 5px;
    padding: 15px;
    white-space: pre-wrap;
    word-wrap: break-word;
    max-height: 400px;
    overflow-y: auto;
    font-family: monospace;
}
details > summary {
    cursor: pointer;
    font-weight: 500;
}
.empty-state-text {
    color: var(--text-color-light);
    padding: 20px 0;
}

/* Responsividad para la tabla de ítems */
@media (max-width: 768px) {
    .items-table thead {
        display: none;
    }
    .items-table, .items-table tbody, .items-table tr, .items-table td {
        display: block;
        width: 100%;
    }
    .items-table tr {
        margin-bottom: 15px;
        border: 1px solid var(--border-color);
        border-radius: 5px;
    }
    .items-table td {
        text-align: right;
        padding-left: 50%;
        position: relative;
    }
    .items-table td::before {
        content: attr(data-label);
        position: absolute;
        left: 15px;
        width: calc(50% - 30px);
        padding-right: 10px;
        text-align: left;
        font-weight: bold;
    }
}