/* --- Variables de Colores --- */
:root {
    --primary-blue: #4f40eb; 
    --primary-blue-hover: #3e32bc;
    --light-blue: #eef2ff;
    --dark-text: #0f172a;
    --medium-grey: #64748b;
    --light-grey: #e2e8f0;
    --bg-light: #f8fafc;
    --white: #ffffff;
    --success-green: #10b981;
    --danger-red: #ef4444;
    --warning-orange: #f59e0b;
}

/* --- Globales y Tipografía --- */
body {
    font-family: 'Inter', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
    margin: 0;
    padding: 0;
    background-color: var(--bg-light);
    color: var(--dark-text);
    line-height: 1.6;
    font-size: 16px;
}

h1, h2, h3, h4, h5, h6 {
    color: var(--dark-text);
    margin-top: 0;
    margin-bottom: 1em;
    font-weight: 600; /* Semi-bold for headings */
}

h1 { font-size: 2.5em; border-bottom: 2px solid var(--light-blue); padding-bottom: 0.5em; margin-bottom: 1em;}
h2 { font-size: 2em; border-bottom: 1px solid var(--light-blue); padding-bottom: 0.5em; margin-bottom: 1em;}
h3 { font-size: 1.5em; margin-bottom: 0.8em;}
p { margin-bottom: 1em; }

a {
    color: var(--primary-blue);
    text-decoration: none;
    transition: color 0.3s ease;
}

a:hover {
    color: #3830c1; /* Ligeramente más oscuro que primary-blue */
}

/* --- Header y Navegación (Overhauled) --- */
.app-header {
    background-color: var(--white);
    padding: 0 24px;
    height: 70px;
    box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-left, .header-right {
    display: flex;
    align-items: center;
    gap: 24px;
}

.brand-logo {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--dark-text);
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 4px;
}
.brand-logo strong {
    color: var(--primary-blue);
}

.header-nav-links {
    display: flex;
    gap: 16px;
    margin-left: 16px;
    border-left: 1px solid var(--light-grey);
    padding-left: 24px;
}

.header-nav-links a {
    color: var(--medium-grey);
    font-weight: 500;
    font-size: 0.95rem;
    text-decoration: none;
    transition: color 0.2s;
}

.header-nav-links a:hover, .header-nav-links a.active {
    color: var(--primary-blue);
}

.company-btn, .user-btn {
    background: transparent;
    color: var(--dark-text);
    font-weight: 500;
    font-size: 0.95rem;
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background-color 0.2s;
    font-family: inherit;
}
.company-btn:hover, .user-btn:hover {
    background-color: var(--bg-light);
    border-color: var(--light-grey);
}

.company-logo {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    object-fit: contain;
    background: var(--bg-light);
    border: 1px solid var(--light-grey);
}

.dropdown-divider {
    height: 1px;
    background-color: var(--light-grey);
    margin: 4px 0;
}
.dropdown-content-right {
    right: 0;
    left: auto;
}

/* --- Contenido Principal y System Design Layout --- */
main {
    padding: 0 24px 40px 24px;
    max-width: 1200px;
    margin: 0 auto;
    background-color: transparent;
    border-radius: 0;
    box-shadow: none;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 32px 0 24px 0;
}
.page-header-text h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    border: none;
    padding: 0;
    color: var(--dark-text);
}
.page-header-text p {
    color: var(--medium-grey);
    margin: 4px 0 0 0;
    font-size: 0.95rem;
}

.content-card {
    background-color: var(--white);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
    padding: 24px;
    margin-bottom: 24px;
    border: 1px solid var(--light-grey);
}

/* --- Botones Generales --- */
.primary-btn {
    background-color: var(--primary-blue);
    color: var(--white);
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition: background-color 0.2s ease, transform 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}
.primary-btn:hover {
    background-color: var(--primary-blue-hover);
    color: var(--white);
}

.action-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2em; /* Iconos un poco más grandes */
    margin: 0 8px;
    padding: 6px;
    border-radius: 50%; /* Redondos */
    transition: background-color 0.2s ease, color 0.2s ease;
    color: var(--medium-grey);
    display: inline-flex; /* Para centrar el icono */
    align-items: center;
    justify-content: center;
    width: 38px; /* Tamaño fijo para el botón */
    height: 38px;
}

.action-btn:hover {
    background-color: var(--light-blue); /* Fondo sutil al hacer hover */
    color: var(--primary-blue);
}

/* Colores específicos para iconos de acción */
.delete-account-btn, .delete-business-unit-btn, .delete-supplier-btn {
    color: var(--danger-red);
}
.delete-account-btn:hover, .delete-business-unit-btn:hover, .delete-supplier-btn:hover {
    background-color: rgba(220, 53, 69, 0.1);
}

.save-account-btn, .save-type-edit-btn {
    color: var(--success-green);
}
.save-account-btn:hover, .save-type-edit-btn:hover {
    background-color: rgba(40, 167, 69, 0.1);
}

.cancel-add-account-btn, .cancel-type-edit-btn, .cancel-account-edit-btn {
    color: var(--warning-orange);
}
.cancel-add-account-btn:hover, .cancel-type-edit-btn:hover, .cancel-account-edit-btn:hover {
    background-color: rgba(255, 193, 7, 0.1);
}

/* --- Secciones de Gestión de Cuentas y Proveedores --- */
.account-management-container {
    padding: 20px 0;
}

/* Sección Añadir Tipo de Cuenta, Gestión de Unidades de Negocio y Añadir Proveedor */
.add-type-section, .business-unit-section {
    margin-bottom: 40px;
    padding-bottom: 30px;
    border-bottom: 1px solid var(--light-grey);
    background-color: var(--white);
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    padding: 25px;
}

.form-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    align-items: center;
    margin-bottom: 20px;
}

.form-row input,
.form-row select {
    flex: 1;
    min-width: 200px;
    padding: 12px 15px;
    border: 1px solid var(--light-grey);
    border-radius: 8px;
    font-size: 1em;
    color: var(--dark-text);
    background-color: var(--bg-light);
    transition: border-color 0.3s ease, box-shadow 0.3s ease;
}

.form-row input::placeholder {
    color: var(--medium-grey);
    opacity: 0.8;
}

.form-row input:focus,
.form-row select:focus {
    border-color: var(--primary-blue);
    outline: none;
    box-shadow: 0 0 0 3px rgba(72, 64, 244, 0.2);
}

.form-row .primary-btn {
    flex-shrink: 0;
}

/* --- Business Units List --- */
.business-units-list {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px dashed var(--light-grey);
}

.business-unit-item {
    background-color: var(--light-blue);
    color: var(--dark-text);
    padding: 8px 15px;
    border-radius: 25px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95em;
    font-weight: 500;
    border: 1px solid var(--primary-blue);
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.business-unit-item .action-btn {
    color: var(--danger-red);
    font-size: 0.8em;
    width: 25px;
    height: 25px;
    background-color: var(--white);
    border-radius: 50%;
}

.business-unit-item .action-btn:hover {
    background-color: var(--danger-red);
    color: var(--white);
}

/* Lista de Cuentas y Proveedores */
.accounts-list, .suppliers-list {
    border: 1px solid var(--light-grey);
    border-radius: 10px;
    margin-bottom: 30px;
    background-color: var(--white);
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.accounts-list .account-type-group {
    border: none;
    border-radius: 0;
    margin-bottom: 0;
    background-color: transparent;
    overflow: visible;
    box-shadow: none;
}
.accounts-list .account-type-group + .account-type-group {
    border-top: 1px solid var(--light-grey);
}

/* Encabezado de tipo de cuenta */
.accounts-list .type-header {
    background-color: var(--white);
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--light-grey);
}

.accounts-list .type-header h3 {
    margin: 0;
    font-size: 1.2em;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;}

.accounts-list .category-tag {
    background-color: var(--light-blue);
    color: var(--primary-blue);
    font-size: 0.75em;
    padding: 3px 8px;
    border-radius: 4px;
    font-weight: 500;
}

.code-range {
    font-size: 0.9em;
    color: var(--medium-grey);
    font-weight: 400;
    background-color: rgba(255, 255, 255, 0.5);
    padding: 4px 8px;
    border-radius: 5px;
}

.category-tag {
    background-color: var(--primary-blue);
    color: var(--white);
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 0.8em;
    text-transform: uppercase;
    font-weight: 600;
    letter-spacing: 0.5px;
}

.accounts-list .accounts-table,
.suppliers-list .accounts-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    margin-top: 0;
}

.accounts-list .accounts-table th,
.accounts-list .accounts-table td,
.suppliers-list .accounts-table th,
.suppliers-list .accounts-table td {
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--light-grey);
    vertical-align: middle;
}

.accounts-list .accounts-table tbody tr:hover {
    background-color: #fdfdfd;
}

.accounts-list .accounts-table th,
.suppliers-list .accounts-table th {
    background-color: var(--bg-light);
    font-weight: 600;
    color: var(--medium-grey);
    text-transform: uppercase;
    font-size: 0.9em;
}

.accounts-list .accounts-table tbody tr:last-child td,
.suppliers-list .accounts-table tbody tr:last-child td {
    border-bottom: none;
}

/* Estilos para la fila de añadir cuenta en línea y fila de añadir proveedor */
.add-account-row, .add-supplier-row {
    background-color: var(--light-blue);
    transition: background-color 0.3s ease;
}

.add-account-row:hover, .add-supplier-row:hover {
    background-color: #dcdbff;
}

.add-account-row input, .add-supplier-row input {
    width: calc(100% - 20px);
    padding: 10px 12px;
    border: 1px solid var(--primary-blue);
    border-radius: 6px;
    font-size: 0.95em;
    box-sizing: border-box;
    background-color: var(--white);
    color: var(--dark-text);
}

.add-account-row input:focus, .add-supplier-row input:focus {
    border-color: #3830c1;
    box-shadow: 0 0 0 3px rgba(72, 64, 244, 0.3);
}

/* --- Inline Editing Styles (for all editable cells) --- */
.editable-cell {
    cursor: pointer;
    position: relative;
    padding: 0;
}

.editable-cell .inline-edit-input {
    width: 100%;
    padding: 15px 25px;
    box-sizing: border-box;
    border: 1px solid var(--primary-blue);
    border-radius: 4px;
    font-family: inherit;
    font-size: inherit;
    color: var(--dark-text);
    background-color: var(--white);
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

/* Specific styling for different input types in inline edit mode */
.editable-cell .code-edit-input,
.editable-cell .name-edit-input,
.editable-cell .rut-edit-input,
.editable-cell .description-edit-input,
.editable-cell .address-edit-input,
.editable-cell .contact_name-edit-input,
.editable-cell .contact_email-edit-input,
.editable-cell .contact_phone-edit-input {
    text-align: left;
}

.editable-cell .distribution-edit-input {
    text-align: center;
    padding: 15px 15px;
}

/* Style for the temporary total percentage display when editing a row (for accounting) */
.inline-edit-total-percentage {
    font-size: 0.9em;
    font-weight: 600;
    margin-right: 10px;
    white-space: nowrap;
}

/* Adjust the positioning of save/cancel buttons in the add row (for accounting) */
.add-account-row td:last-child {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 5px;
}

/* Style for inputs in the add account row (accounting) */
.add-account-row input.new-account-code-input,
.add-account-row input.new-account-name-input,
.add-account-row input.new-account-distribution-percentage-input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--light-grey);
    border-radius: 8px;
    font-size: 0.95em;
    box-sizing: border-box;
    background-color: var(--bg-light);
    color: var(--dark-text);
}

.add-account-row input.new-account-distribution-percentage-input {
    text-align: center;
}

/* --- Edit Type Form Styling --- */
.edit-type-form {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.edit-type-form input,
.edit-type-form select {
    flex: 1;
    min-width: 150px;
    padding: 8px 12px;
    border-radius: 6px;
    border: 1px solid var(--light-grey);
    background-color: var(--white);
    font-size: 0.95em;
}

.edit-type-form .action-btn {
    margin: 0 2px;
}

/* --- Footer --- */
footer {
    text-align: center;
    padding: 2em 0;
    margin-top: 50px;
    background-color: var(--dark-text);
    color: var(--white);
    font-size: 0.85em;
    box-shadow: 0 -4px 10px rgba(0, 0, 0, 0.1);
}

/* --- Responsive Adjustments --- */
@media (max-width: 900px) {
    main {
        margin: 20px 15px;
        padding: 20px;
    }
    h1 { font-size: 2em; }
    h2 { font-size: 1.7em; }
    h3 { font-size: 1.3em; }

    .form-row {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }
    .form-row input,
    .form-row select,
    .form-row .primary-btn {
        width: 100%;
        min-width: unset;
    }
    .accounts-list .type-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        padding: 15px 20px;
    }
    .accounts-list .type-header h3 {
        width: 100%;
        text-align: center;
    }
    .accounts-list .add-account-btn {
        width: 100%;
        justify-content: center;
        margin-top: 10px;
    }
    .accounts-list .accounts-table th,
    .accounts-list .accounts-table td,
    .suppliers-list .accounts-table th,
    .suppliers-list .accounts-table td {
        padding: 12px 18px;
    }
    .add-account-row td, .add-supplier-row td {
        padding: 10px 18px;
    }

    /* Responsive for Distribution Inputs (Accounting) */
    .distribution-cell {
        min-width: 100px;
    }
    .editable-cell .distribution-edit-input {
        padding: 8px 5px;
        font-size: 0.85em;
    }

    /* Total percentage for add row (accounting) */
    .add-account-row td:last-child {
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 10px 18px;
    }
    #addRowTotalPercentage {
        margin-bottom: 5px;
    }

    .edit-type-form {
        flex-direction: column;
        align-items: stretch;
    }
    .edit-type-form input,
    .edit-type-form select {
        width: 100%;
        min-width: unset;
    }
    .edit-type-form .action-btn {
        width: 100%;
        margin: 5px 0;
    }
}

@media (max-width: 600px) {
    header nav a {
        margin: 0 10px;
        font-size: 1em;
    }
    .accounts-list .accounts-table th,
    .accounts-list .accounts-table td,
    .suppliers-list .accounts-table th,
    .suppliers-list .accounts-table td {
        font-size: 0.9em;
        padding: 10px;
    }
    .add-account-row input, .add-supplier-row input {
        padding: 8px 10px;
    }
    .action-btn {
        font-size: 1em;
        width: 32px;
        height: 32px;
    }
    .business-unit-item {
        padding: 6px 12px;
        font-size: 0.85em;
    }
    /* Contact cells for suppliers on small screens */
    .contact-cell {
        font-size: 0.85em;
        white-space: nowrap;
    }
    .editable-cell .inline-edit-input {
        padding: 10px;
        font-size: 0.85em;
    }
}

/* General clean up for table cells where inputs might go */
.accounts-table td, .suppliers-list .accounts-table td {
    overflow: hidden;
}

/* --- NEW: Editable Expense Table & Controls --- */

.editable-expense-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 20px;
}

.editable-expense-table th,
.editable-expense-table td {
    /* Set a consistent vertical padding for all table cells to control row height */
    padding-top: 10px; /* NEW: Unified top padding */
    padding-bottom: 10px; /* NEW: Unified bottom padding */
    padding-left: 15px;
    padding-right: 15px;
    border: 1px solid var(--light-grey);
    text-align: left;
    vertical-align: middle;
    box-sizing: border-box; /* Crucial for all cells to handle padding/border uniformly */
}

.editable-expense-table th {
    background-color: var(--bg-light);
    color: var(--dark-text);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 1;
}

.editable-expense-table td {
    background-color: var(--white);
    color: var(--dark-text);
}

.editable-expense-table .cell-input {
    width: 100%;
    padding: 8px; /* Consistent padding for inputs */
    box-sizing: border-box; /* Critical: Includes padding and border in element's total size */
    border: 1px solid var(--medium-grey);
    border-radius: 4px;
    font-size: 0.9em;
    font-family: inherit;
    color: inherit;
    background-color: var(--white);
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    /* Removed fixed height. Let padding and content define it, and parent td controls overall row height. */
    height: auto; /* Ensure no fixed height is overriding */
    min-height: 36px; /* NEW: A slight min-height for inputs to ensure consistency */
}

.editable-expense-table .cell-input:focus {
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 2px rgba(72, 64, 244, 0.15);
    outline: none;
}

/* Specific input adjustments */
.editable-expense-table input[type="date"],
.editable-expense-table input[type="number"] {
    min-width: 100px;
}


.editable-expense-table .supplier-rut-input {
    width: 100%;
    padding: 6px 8px; /* Slightly less padding for RUT input to save vertical space */
    font-size: 0.88em; /* Slightly smaller font to fit better */
    min-height: unset; /* Ensure no conflicting min-height */
}
.editable-expense-table .supplier-name-display {
    font-size: 0.8em; /* Slightly smaller font for name display */
    color: var(--medium-grey);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    padding-left: 2px;
    line-height: 1.1; /* More compact line height for the name */
    margin-top: 0; /* Ensure no extra margin pushes it down */
    margin-bottom: 0; /* Ensure no extra margin pushes it up */
}
.editable-expense-table .quick-create-supplier-btn {
    padding: 3px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    background-color: var(--success-green);
    color: var(--white);
    border: none;
    cursor: pointer;
    font-size: 0.7em;
    line-height: 1;
    z-index: 2;
    margin-left: 4px; /* Añade el margen que necesitas */
}
.editable-expense-table .quick-create-supplier-btn i {
    font-size: 0.9em; /* Adjust icon size */
}

/* Group Name input hide/show */
.editable-expense-table .group-name-input.hidden {
    display: none;
}

/* Status coloring for rows */
.editable-expense-table .status-cell {
    font-weight: 600;
    text-align: center;
}
.editable-expense-table tr.status-pending td { background-color: #f7f7f7; }
.editable-expense-table tr.status-error td { background-color: #ffeaea; } /* This is likely the one causing the pink background */
.editable-expense-table tr.status-warning td { background-color: #fffbe6; }
.editable-expense-table tr.status-saved td { background-color: #e6ffe6; opacity: 0.8; }

/* Input error highlighting */
.editable-expense-table .input-error {
    border-color: var(--danger-red);
    box-shadow: 0 0 0 2px rgba(220, 53, 69, 0.25);
}

/* Distribution summary in cell */
.editable-expense-table .distribution-summary {
    display: block;
    font-size: 0.85em;
    font-weight: 600;
    margin-bottom: 5px;
}
.editable-expense-table .distribution-summary.status-ok { color: var(--success-green); }
.editable-expense-table .distribution-summary.status-warning { color: var(--warning-orange); }
.editable-expense-table .distribution-summary.status-pending { color: var(--medium-grey); }

/* Remove row button */
.editable-expense-table .remove-row-btn {
    background: none;
    border: none;
    color: var(--danger-red);
    cursor: pointer;
    font-size: 1.2em;
    padding: 5px;
    opacity: 0.8;
}
.editable-expense-table .remove-row-btn:hover {
    opacity: 1;
    transform: scale(1.1);
}

/* Table controls for new design */
.table-controls {
    display: flex;
    justify-content: flex-start;
    gap: 15px;
    margin-top: 20px;
    padding-top: 15px;
    border-top: 1px solid var(--light-grey);
}
.table-controls .primary-btn,
.table-controls .secondary-btn {
    padding: 10px 20px;
    font-size: 1em;
    border-radius: 6px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

/* --- Modal for Distribution Editing (similar to supplier modal) --- */
#distributionModal .modal-content {
    max-width: 600px;
}
#modalDistributionContainer {
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    padding: 15px;
    border: 1px solid var(--light-grey);
    border-radius: 8px;
    background-color: var(--bg-light);
    margin-top: 10px;
}

#modalDistributionContainer .distribution-item {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 0.95em;
    color: var(--dark-text);
}

#modalDistributionContainer .distribution-item input {
    width: 60px;
    padding: 6px 8px;
    text-align: center;
    border: 1px solid var(--light-grey);
    border-radius: 5px;
    background-color: var(--white);
    color: var(--dark-text);
}
/* Ensure consistency with existing modal styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0,0,0,0.5);
    display: flex;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background-color: var(--white);
    margin: auto;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.3);
    position: relative;
    max-width: 500px;
    width: 90%;
    animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-content h4 {
    margin-top: 0;
    margin-bottom: 20px;
    color: var(--dark-text);
    font-size: 1.5em;
}

.close-button {
    color: var(--medium-grey);
    position: absolute;
    top: 15px;
    right: 20px;
    font-size: 2em;
    font-weight: bold;
    cursor: pointer;
    transition: color 0.2s ease;
}

.close-button:hover,
.close-button:focus {
    color: var(--danger-red);
    text-decoration: none;
}

.modal .form-row {
    flex-direction: column;
    align-items: stretch;
}

.modal .form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 25px;
    padding-top: 15px;
    border-top: 1px solid var(--light-grey);
}
/* Media queries */
@media (max-width: 768px) {
    .editable-expense-table td {
        padding: 8px 10px;
    }
    .editable-expense-table .cell-input {
        padding: 6px;
        font-size: 0.85em;
    }
    .editable-expense-table .quick-create-supplier-btn {
        width: 26px;
        height: 26px;
    }
    .table-controls {
        flex-direction: column;
    }
    .table-controls button {
        width: 100%;
    }
}

.search-results-container {
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #ccc;
    margin-top: 10px;
}
.search-result-item {
    padding: 10px;
    cursor: pointer;
    border-bottom: 1px solid #eee;
}
.search-result-item:hover {
    background-color: #f0f0f0;
}
.search-result-item:last-child {
    border-bottom: none;
}

.supplier-info {
    display: flex;
    align-items: center; /* Alinea verticalmente los items al centro (muy útil) */
    gap: 5px;          /* Añade un pequeño espacio entre el input y los botones */
}

.notification {
    transition: all 0.3s ease;
    cursor: pointer;
}

.rut-with-button {
    display: flex;
    align-items: center;
}
.rut-with-button input {
    flex: 1;
}

.danger-btn {
    background: transparent;
    border: none;
    color: #e74c3c;
    cursor: pointer;
}
.danger-btn:hover {
    color: #c0392b;
}

.account-type-group.collapsed .accounts-table {
    display: none;
}
.toggle-type-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 14px;
    margin-right: 6px;}

/* Subgrupo */
.subgroup-header {
    background-color: #fafafa;
    font-weight: 500;
    color: var(--dark-text);
}

.subgroup-count {
    font-size: 0.8em;
    color: var(--medium-grey);
}
.subgrouped td {
    padding-left: 24px;
    background-color: #fafafa;
}
.toggle-subgroup-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    margin-right: 4px;
}


.category-header {
    background-color: var(--bg-light);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 2px solid var(--light-grey);
    cursor: pointer;
}

.category-title {
    font-size: 1.6em;
    font-weight: 700;
    margin: 0;
    color: var(--dark-text);
}

.toggle-category-btn {
    background: none;
    border: none;
    font-size: 1em;
    cursor: pointer;
    color: var(--medium-grey);
}

/* Bloque de categoría */
.category-group {
    margin-bottom: 32px; /* espacio entre categorías */
    padding: 16px 20px;
    background-color: #fff; /* fondo blanco para que se vea como tarjeta */
    border: 1px solid var(--light-grey);
    border-radius: 6px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

/* Encabezado de categoría */
.category-header {
    background-color: transparent; /* sin bloque de color fuerte */
    padding: 0 0 12px 0; /* espacio inferior para separar del contenido */
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--light-grey);
}

.category-title {
    font-size: 1.6em;
    font-weight: 700;
    margin: 0;
    color: var(--dark-text);
}

.accounts-list {
    border: none;              /* sin borde */
    border-radius: 0;           /* esquinas rectas */
    background-color: transparent; /* sin fondo */
    box-shadow: none;           /* sin sombra */
    margin-bottom: 30px;        /* mantengo el espacio inferior */
    overflow: visible;
    }

    .subtle-btn {
    background-color: #f5f5f5; /* gris claro */
    color: #555; /* texto gris */
    border: 1px solid #ddd;
    font-size: 0.85rem;
    padding: 4px 8px;
    opacity: 0.8;
    transition: opacity 0.2s ease, background-color 0.2s ease;
}

.subtle-btn:hover {
    opacity: 1;
    background-color: #eee;
}

.template-link {
    font-size: 0.85rem;
    color: #555;
    text-decoration: underline;
    cursor: pointer;
    opacity: 0.8;
}

.template-link:hover {
    opacity: 1;
    color: #333;
}


.dropdown {
  position: relative;
  display: inline-block;
}

.dropbtn {
  background-color: transparent;
  border: none;
  color: #333;
  font-size: 16px;
  cursor: pointer;
}

.dropbtn i {
  margin-left: 5px;
}

.dropdown-content {
  display: none;
  position: absolute;
  background-color: white;
  min-width: 180px;
  box-shadow: 0px 8px 16px rgba(0,0,0,0.2);
  z-index: 1;
}

.dropdown-content a {
  color: #333;
  padding: 10px 14px;
  text-decoration: none;
  display: block;
}

.dropdown-content a:hover {
  background-color: #f1f1f1;
}

.dropdown:hover .dropdown-content {
  display: block;
}

/* --- UX Overhaul: Toasts, Editable Tables & Toggles --- */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    z-index: 9999;
}

.toast {
    min-width: 280px;
    background: var(--white);
    color: var(--dark-text);
    padding: 16px 20px;
    border-radius: 8px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.95rem;
    font-weight: 500;
    transform: translateY(100%);
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
    border-left: 4px solid var(--primary-blue);
}
.toast.toast-show {
    transform: translateY(0);
    opacity: 1;
}
.toast-success { border-left-color: var(--success-green); }
.toast-error { border-left-color: var(--danger-red); }
.toast-warning { border-left-color: var(--warning-orange); }

.toast i { font-size: 1.1rem; }
.toast-success i { color: var(--success-green); }
.toast-error i { color: var(--danger-red); }
.toast-warning i { color: var(--warning-orange); }

/* --- Notion-style Editable Grid --- */
.editable-expense-table {
    border-collapse: collapse;
    width: 100%;
}
.editable-expense-table th, 
.editable-expense-table td {
    border: none;
    border-bottom: 1px solid var(--light-grey);
    padding: 8px 12px;
    vertical-align: middle;
}
.editable-expense-table th {
    color: var(--medium-grey);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
    background: transparent;
}
.editable-expense-table tbody tr {
    transition: background-color 0.15s ease;
}
.editable-expense-table tbody tr:hover {
    background-color: #f1f5f9; /* Slate 100 */
}
.editable-expense-table .cell-input {
    border: 1px solid transparent;
    background: transparent;
    border-radius: 4px;
    padding: 8px;
    width: 100%;
    box-sizing: border-box;
    transition: all 0.2s ease;
    font-size: 0.9rem;
    color: var(--dark-text);
}
.editable-expense-table .cell-input:hover {
    background: rgba(0,0,0,0.02);
}
.editable-expense-table .cell-input:focus {
    background: var(--white);
    border-color: var(--primary-blue);
    box-shadow: 0 0 0 2px rgba(79, 64, 235, 0.1);
    outline: none;
}
.editable-expense-table .input-error-soft {
    border-color: #fca5a5 !important;
    background-color: #fef2f2 !important;
    color: #991b1b;
}

/* Modern Toggle Switch */
.modern-toggle-label {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
    vertical-align: middle;
}
.modern-toggle-label input {
    opacity: 0;
    width: 0;
    height: 0;
}
.modern-toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #cbd5e1;
    transition: .3s;
    border-radius: 20px;
}
.modern-toggle-slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .3s;
    border-radius: 50%;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
input:checked + .modern-toggle-slider {
    background-color: var(--primary-blue);
}
input:checked + .modern-toggle-slider:before {
    transform: translateX(16px);
}

/* Inline Popover */
.inline-popover {
    position: absolute;
    background: var(--white);
    border: 1px solid var(--light-grey);
    border-radius: 8px;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    padding: 16px;
    z-index: 1000;
    display: none;
    min-width: 250px;
    top: 100%;
    left: 0;
    margin-top: 8px;
}
.inline-popover-active { display: block; }

.inline-popover .distribution-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.inline-popover .distribution-item span {
    font-size: 0.9rem;
    color: var(--dark-text);
}
.inline-popover .modal-distribution-percentage-input {
    width: 60px;
    padding: 6px;
    border: 1px solid var(--light-grey);
    border-radius: 4px;
    text-align: right;
}

/* Error icon in status cell */
.error-container-icon {
    display: inline-block;
    cursor: pointer;
    color: var(--warning-orange);
    font-size: 1.1rem;
    margin-top: 2px;
    vertical-align: middle;
}

/* Global Error Tooltip (position:fixed, floats over table, never expands rows) */
#globalErrorTooltip {
    display: none;
    position: fixed;
    z-index: 99999;
    background-color: #1e293b;
    color: #fff;
    font-size: 0.82rem;
    line-height: 1.6;
    padding: 8px 14px;
    border-radius: 6px;
    max-width: 270px;
    white-space: pre-wrap;
    box-shadow: 0 6px 16px rgba(0,0,0,0.3);
    pointer-events: none;
}
#globalErrorTooltip::before {
    content: "";
    position: absolute;
    bottom: 100%;
    left: 50%;
    margin-left: -5px;
    border-width: 5px;
    border-style: solid;
    border-color: transparent transparent #1e293b transparent;
}
.editable-expense-table tr.has-soft-errors td {
    background-color: #fff8f8;
}

.account-combobox {
    text-overflow: ellipsis;
    white-space: nowrap;
    overflow: hidden;
}

/* Account dropdown single-line item layout (code – name, wraps naturally) */
.account-dropdown-item {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 8px 12px;
    cursor: pointer;
    transition: background-color 0.1s;
    line-height: 1.4;
}
.account-dropdown-item:hover,
.account-dropdown-item.active {
    background-color: var(--light-blue);
}
.account-dropdown-item.selected-account {
    background-color: #eff6ff;
}
.acct-label {
    font-size: 0.87rem;
    color: var(--dark-text);
    white-space: normal;
    word-break: break-word;
    flex: 1;
}
.acct-count {
    font-size: 0.72rem;
    color: var(--primary-blue);
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}