:root {
    --bg-dark: #111827;
    --bg-light: #F9FAFB;
    --primary-color: #4F46E5;
    --primary-hover: #4338CA;
    --primary-light: #EEF2FF;
    --border-color: #E5E7EB;
    --text-light: #D1D5DB;
    --text-dark: #374151;
    --text-heading: #111827;
    --white: #FFFFFF;
    --status-paid-bg: #D1FAE5;
    --status-paid-text: #065F46;
    --status-pending-bg: #FEF3C7;
    --status-pending-text: #92400E;
    --status-overdue-bg: #FEE2E2;
    --status-overdue-text: #991B1B;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-light);
    color: var(--text-dark);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

.dashboard-container {
    min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
    width: 260px;
    background-color: var(--bg-dark);
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    padding: 1.5rem;
    gap: 0.75rem;
}

.sidebar-header-text {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--white);
}

.sidebar-nav {
    padding: 0 1rem;
    flex-grow: 1;
}

.sidebar-nav ul {
    list-style: none;
}

.sidebar-nav li a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-light);
    font-weight: 500;
    transition: background-color 0.2s, color 0.2s;
}

.sidebar-nav li a:hover {
    background-color: #374151;
    color: var(--white);
}

.sidebar-nav li.active a {
    background-color: var(--primary-color);
    color: var(--white);
}

/* --- Main Content --- */
.main-content {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.main-header {
    display: flex;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--white);
}

.header-title {
    flex: 1;
}

.header-actions {
    flex: 1;
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
}

.main-header h1 {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-heading);
}

.content {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

/* --- Stats --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}

@media (max-width: 1200px) {
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 640px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
}

.stat-card {
    background-color: var(--white);
    border-radius: 12px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: all 0.2s ease-in-out;
    border: 1px solid var(--border-color);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0,0,0,0.08);
}

.stat-card-icon-container {
    flex-shrink: 0;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--primary-light);
    color: var(--primary-color);
}

.stat-card-icon-container i {
    width: 24px;
    height: 24px;
}

.stat-card-info {
    min-width: 0;
}

.stat-card-title {
    font-size: 0.875rem;
    color: #6B7280;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.stat-card-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-heading);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    font-size: 0.875rem;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease-in-out;
    text-decoration: none;
    background-color: var(--white);
    color: var(--text-dark);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.06);
}

.btn:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

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

.btn-primary:hover {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
    box-shadow: 0 4px 10px rgba(79, 70, 229, 0.25);
}

.btn-primary:active {
    background-color: var(--primary-hover);
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.icon-sm {
    width: 1.125rem;
    height: 1.125rem;
}

/* --- Card --- */
.card {
    background-color: var(--white);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.06);
    overflow: hidden;
}

.card-header {
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.card-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-heading);
}

.card-body {
    padding: 1.5rem;
}

.filter-container {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.filter-input {
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--white);
    transition: border-color 0.2s, box-shadow 0.2s;
    height: 42px; /* Match button height */
}

.filter-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}

#search-input {
    flex: 1 1 250px;
}

#date-from-filter, #date-to-filter, #status-filter {
    flex: 0 1 180px;
    color: #6B7280; /* Lighter text for placeholder feel */
}

#date-from-filter:focus, #date-to-filter:focus, #status-filter:focus,
#date-from-filter:valid, #date-to-filter:valid, #status-filter:valid {
     color: var(--text-dark); /* Darker text when a value is selected */
}
/* This selector keeps the date picker's placeholder text gray until a date is chosen */
input[type="date"]:not(:valid) {
    color: #6B7280;
}

/* --- Invoice Table --- */
.invoice-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.invoice-table th, .invoice-table td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    vertical-align: middle;
}

.invoice-table th {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    color: #6B7280;
    letter-spacing: 0.05em;
}

.invoice-table td {
    font-size: 0.875rem;
}

.invoice-table td .inline-status-edit {
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background-color: var(--white);
    width: 100%;
    cursor: pointer;
}

.invoice-table td .inline-status-edit:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
    text-transform: capitalize;
    cursor: pointer;
    transition: filter 0.2s ease-in-out;
}

.status-badge:hover {
    filter: brightness(0.95);
}

.status-Pagada {
    background-color: var(--status-paid-bg);
    color: var(--status-paid-text);
}
.status-Pendiente {
    background-color: var(--status-pending-bg);
    color: var(--status-pending-text);
}
.status-Vencida {
    background-color: var(--status-overdue-bg);
    color: var(--status-overdue-text);
}

.action-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: #9CA3AF;
    padding: 0.4rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease-in-out;
}
.action-btn:hover {
    color: var(--primary-color);
    background-color: var(--primary-light);
}

.action-btn:active {
    transform: scale(0.95);
    background-color: #E0E7FF;
}

.action-buttons {
    display: flex;
    gap: 0.25rem;
}

.aeat-status {
    text-align: center;
}

.icon-success {
    color: var(--status-paid-text);
}

/* --- Modal --- */
.hidden {
    display: none !important;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(17, 24, 39, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background-color: var(--white);
    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);
    width: 100%;
    max-width: 500px;
    animation: slide-down 0.3s ease-out;
}

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

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

.modal-header h2 {
    font-size: 1.25rem;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #9CA3AF;
}

.modal-body {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group label {
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.form-group input, .form-group select {
    font-family: 'Inter', sans-serif;
    font-size: 0.875rem;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input:focus, .form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(79, 70, 229, 0.2);
}

.form-row {
    display: flex;
    gap: 1rem;
}

.form-row .form-group {
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    background-color: #F9FAFB;
    border-top: 1px solid var(--border-color);
    border-bottom-left-radius: 8px;
    border-bottom-right-radius: 8px;
}

/* --- Toast Notifications --- */
#toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toast {
    width: 350px;
    max-width: 90vw;
    padding: 1rem;
    border-radius: 8px;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    font-weight: 500;
    font-size: 0.875rem;
    color: var(--white);
    animation: toast-in 0.5s ease;
}

.toast.toast-out {
    animation: toast-out 0.5s ease forwards;
}

.toast-success {
    background-color: #059669; /* Green 600 */
}

.toast-error {
    background-color: #DC2626; /* Red 600 */
}

.toast-info {
     background-color: var(--primary-color);
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}