:root {
    color-scheme: light;
    --primary: #1d4ed8;
    --primary-dark: #1e3a8a;
    --surface: #ffffff;
    --background: #f1f5f9;
    --text: #172033;
    --muted: #64748b;
    --border: #dbe3ee;
    --danger: #b91c1c;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--background);
}

.login-page {
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at top left, rgba(37, 99, 235, .18), transparent 38%),
        linear-gradient(145deg, #eff6ff, #f8fafc 52%, #e2e8f0);
}

.login-card {
    width: min(100%, 430px);
    padding: 38px;
    background: rgba(255, 255, 255, .96);
    border: 1px solid rgba(255, 255, 255, .8);
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(30, 58, 138, .16);
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 48px;
    height: 48px;
    margin-bottom: 18px;
    color: #fff;
    font-size: 18px;
    font-weight: 800;
    letter-spacing: .04em;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    border-radius: 13px;
}

h1 { margin: 0 0 8px; font-size: 27px; line-height: 1.2; }
.subtitle { margin: 0 0 28px; color: var(--muted); }

.field { margin-bottom: 18px; }
.field label { display: block; margin-bottom: 7px; font-size: 14px; font-weight: 650; }
.field input {
    width: 100%;
    padding: 12px 13px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font: inherit;
    outline: none;
    transition: border-color .2s, box-shadow .2s;
}
.field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }

.button {
    width: 100%;
    padding: 12px 18px;
    color: #fff;
    font: inherit;
    font-weight: 700;
    background: var(--primary);
    border: 0;
    border-radius: 10px;
    cursor: pointer;
}
.button:hover { background: var(--primary-dark); }

.alert { margin-bottom: 18px; padding: 12px 14px; border-radius: 9px; font-size: 14px; }
.alert-error { color: #7f1d1d; background: #fee2e2; border: 1px solid #fecaca; }
.alert-info { color: #1e3a8a; background: #dbeafe; border: 1px solid #bfdbfe; }
.alert-success { color: #14532d; background: #dcfce7; border: 1px solid #bbf7d0; }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 28px;
    color: #fff;
    background: #0f172a;
}
.brand-link { color: #fff; font-weight: 800; text-decoration: none; }
.main-nav { display: flex; gap: 20px; margin-right: auto; margin-left: 36px; }
.main-nav a, .user-menu a { color: #cbd5e1; text-decoration: none; }
.main-nav a:hover, .user-menu a:hover { color: #fff; }
.user-menu { display: flex; align-items: center; gap: 13px; font-size: 14px; }
.topbar form, .user-menu form { margin: 0; }
.link-button { color: #bfdbfe; background: none; border: 0; cursor: pointer; font: inherit; }
.content { width: min(1180px, calc(100% - 40px)); margin: 42px auto; }
.panel { padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; }
.form-panel { width: min(100%, 540px); margin-inline: auto; }
.form-actions { margin-top: 22px; }
.help { margin-top: 6px; color: var(--muted); font-size: 13px; }

.flash-wrap { width: min(1180px, calc(100% - 40px)); margin: 18px auto -20px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.page-heading h1 { margin-top: 5px; }
.page-heading p { margin: 7px 0 0; color: var(--muted); }
.eyebrow { color: var(--primary); font-size: 12px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.back-link { display: inline-block; margin-bottom: 10px; color: var(--primary); text-decoration: none; }
.button-auto { display: inline-block; width: auto; text-decoration: none; }
.button-secondary { display: inline-block; padding: 11px 17px; color: #334155; text-decoration: none; background: #fff; border: 1px solid var(--border); border-radius: 10px; }

.card-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.module-card { display: flex; gap: 18px; padding: 26px; color: inherit; text-decoration: none; background: #fff; border: 1px solid var(--border); border-radius: 14px; transition: transform .2s, box-shadow .2s; }
.module-card:hover { transform: translateY(-2px); box-shadow: 0 15px 32px rgba(15, 23, 42, .08); }
.module-card h2 { margin: 0 0 7px; font-size: 19px; }
.module-card p { margin: 0; color: var(--muted); }
.module-icon { display: grid; place-items: center; flex: 0 0 48px; height: 48px; color: #fff; font-weight: 800; background: var(--primary); border-radius: 12px; }

.form-section { margin-bottom: 24px; }
.form-section h2 { margin-top: 0; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 20px; }
.field-wide { grid-column: 1 / -1; }
.field select { width: 100%; padding: 12px 13px; border: 1px solid var(--border); border-radius: 10px; color: var(--text); background: #fff; font: inherit; }
.check-field { display: flex; align-items: center; gap: 9px; min-height: 46px; font-weight: 650; }
.check-field input { width: 17px; height: 17px; accent-color: var(--primary); }
.form-actions-inline { display: flex; align-items: center; gap: 10px; }

.table-panel { padding: 0; overflow: hidden; }
.table-responsive { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 15px 17px; text-align: left; border-bottom: 1px solid #e8edf4; vertical-align: middle; }
th { color: #475569; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; background: #f8fafc; }
tbody tr:last-child td { border-bottom: 0; }
td small { display: block; margin-top: 4px; color: var(--muted); }
.actions-column { text-align: right; }
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 13px; white-space: nowrap; }
.actions a { color: var(--primary); text-decoration: none; }
.actions form { margin: 0; }
.danger-link { padding: 0; color: var(--danger); background: none; border: 0; cursor: pointer; font: inherit; }
.company-dot { display: inline-block; width: 10px; height: 10px; margin-right: 9px; background: var(--company-color); border-radius: 50%; }
.badge { display: inline-block; padding: 5px 9px; color: #fff; font-size: 12px; font-weight: 800; background: var(--badge-color); border-radius: 999px; }
.status { display: inline-block; padding: 4px 8px; font-size: 12px; font-weight: 700; border-radius: 999px; }
.status-active { color: #166534; background: #dcfce7; }
.status-inactive { color: #475569; background: #e2e8f0; }
.money { font-variant-numeric: tabular-nums; font-weight: 700; }
.debt { color: #b91c1c; }
.empty-state { padding: 35px; color: var(--muted); text-align: center; }

.summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 24px; }
.summary-card { padding: 22px; background: #fff; border: 1px solid var(--border); border-left: 4px solid #16a34a; border-radius: 12px; }
.summary-card span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; }
.summary-card strong { font-size: 25px; font-variant-numeric: tabular-nums; }
.summary-card-debt { border-left-color: #dc2626; }
.summary-grid-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.summary-card-net { border-left-color: #2563eb; }

.filter-panel { margin-bottom: 24px; padding-bottom: 10px; }
.filter-grid { display: grid; grid-template-columns: repeat(5, minmax(120px, 1fr)); gap: 0 14px; align-items: end; }
.field-search { grid-column: span 2; }
.filter-actions { display: flex; gap: 8px; margin-bottom: 18px; }
.row-link { color: var(--primary); font-weight: 700; text-decoration: none; white-space: nowrap; }
.movement-type { display: inline-block; padding: 4px 8px; font-size: 11px; font-weight: 800; border-radius: 6px; }
.movement-ingreso { color: #166534; background: #dcfce7; }
.movement-egreso { color: #991b1b; background: #fee2e2; }
.movement-transferencia { color: #1e40af; background: #dbeafe; }
.movement-ajuste { color: #854d0e; background: #fef3c7; }
.status-pendiente { color: #92400e; background: #fef3c7; }
.status-parcial { color: #1e40af; background: #dbeafe; }
.status-pagado { color: #166534; background: #dcfce7; }
.status-anulado { color: #475569; background: #e2e8f0; }
.pagination { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin-top: 22px; }
.pagination a { display: grid; place-items: center; min-width: 36px; height: 36px; color: #334155; text-decoration: none; background: #fff; border: 1px solid var(--border); border-radius: 8px; }
.pagination a.active { color: #fff; background: var(--primary); border-color: var(--primary); }

.movement-form { padding-top: 12px; }
.form-grid-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-section-title { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; margin: 18px 0; padding-bottom: 10px; border-bottom: 1px solid var(--border); }
.form-section-title:first-child { margin-top: 0; }
.form-section-title h2 { margin: 0; font-size: 17px; }
.form-section-title span { color: var(--muted); font-size: 13px; }
.field textarea { width: 100%; padding: 12px 13px; resize: vertical; border: 1px solid var(--border); border-radius: 10px; font: inherit; }
.field input[readonly] { color: #475569; background: #f8fafc; }

.heading-actions { display: flex; gap: 9px; }
.heading-actions form { margin: 0; }
.button-danger { padding: 11px 17px; color: #fff; background: #b91c1c; border: 0; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 700; }
.detail-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 22px; margin-bottom: 24px; }
.detail-title { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.details-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; margin: 0; }
.details-list div { min-width: 0; }
.details-list dt { margin-bottom: 5px; color: var(--muted); font-size: 12px; font-weight: 700; text-transform: uppercase; }
.details-list dd { margin: 0; overflow-wrap: anywhere; }
.notes { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
.notes p { margin-bottom: 0; color: #475569; }
.amount-card { align-self: start; padding: 23px; color: #e2e8f0; background: #0f172a; border-radius: 14px; }
.amount-card > div { display: flex; justify-content: space-between; gap: 18px; padding: 11px 0; border-bottom: 1px solid #334155; }
.amount-card > div:last-child { border-bottom: 0; }
.amount-card span { font-size: 13px; }
.amount-card strong { color: #fff; font-variant-numeric: tabular-nums; }
.amount-card .amount-total { margin-top: 4px; padding: 16px 0; }
.amount-card .amount-total strong { font-size: 22px; }
.amount-card .amount-pending strong { color: #fbbf24; }
.payments-section { margin-bottom: 40px; }
.section-heading h2 { margin: 0 0 5px; }
.section-heading p { margin: 0; color: var(--muted); }
.payment-form { margin-top: 24px; padding: 20px; background: #f8fafc; border: 1px solid var(--border); border-radius: 12px; }
.payments-table { margin: 26px -28px -28px; }

.dashboard-heading { align-items: center; }
.period-filter { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.period-filter input, .period-filter select, .inline-filter select { padding: 10px 11px; color: var(--text); background: #fff; border: 1px solid var(--border); border-radius: 9px; font: inherit; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.kpi-card { position: relative; overflow: hidden; padding: 22px; background: #fff; border: 1px solid var(--border); border-radius: 14px; }
.kpi-card::before { position: absolute; inset: 0 auto 0 0; width: 4px; content: ''; background: var(--kpi-color); }
.kpi-card > span { display: block; margin-bottom: 10px; color: var(--muted); font-size: 13px; }
.kpi-card > strong { display: block; margin-bottom: 7px; font-size: clamp(21px, 2vw, 29px); font-variant-numeric: tabular-nums; }
.kpi-card small { color: var(--muted); }
.kpi-income { --kpi-color: #16a34a; }
.kpi-expense { --kpi-color: #dc2626; }
.kpi-flow { --kpi-color: #2563eb; }
.kpi-bank { --kpi-color: #7c3aed; }
.negative { color: #dc2626 !important; }
.dashboard-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, .8fr); gap: 22px; margin-bottom: 22px; }
.section-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 15px; }
.section-heading a { color: var(--primary); text-decoration: none; }
.section-heading-padded { padding: 22px 24px 16px; }
.comparison-legend { display: flex; justify-content: flex-end; gap: 16px; margin: -5px 0 18px; color: var(--muted); font-size: 12px; }
.comparison-legend span { display: flex; align-items: center; gap: 6px; }
.comparison-legend i { width: 9px; height: 9px; border-radius: 2px; }
.legend-income { background: #22c55e; }
.legend-expense { background: #ef4444; }
.company-row { display: grid; grid-template-columns: minmax(160px, .8fr) minmax(220px, 1.4fr) minmax(160px, .8fr); gap: 18px; align-items: center; padding: 18px 0; border-top: 1px solid var(--border); }
.company-label { display: flex; align-items: center; gap: 9px; min-width: 0; }
.company-label > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-stack { display: grid; gap: 8px; }
.bar-line { position: relative; height: 16px; background: #f1f5f9; border-radius: 4px; }
.bar-line .bar { min-width: 0; height: 100%; border-radius: 4px; }
.bar-income { background: #22c55e; }
.bar-expense { background: #ef4444; }
.bar-line strong { position: absolute; top: 50%; right: 5px; color: #334155; font-size: 10px; transform: translateY(-50%); }
.company-pending { display: grid; gap: 5px; color: var(--muted); font-size: 12px; }
.pending-panel { align-self: stretch; }
.pending-metric { padding: 18px 0; border-bottom: 1px solid var(--border); }
.pending-metric span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 12px; }
.pending-metric strong { color: #15803d; font-size: 22px; }
.pending-pay strong { color: #dc2626; }
.pending-bank strong { color: #1d4ed8; }
.full-link { display: block; margin-top: 20px; text-align: center; }
.dashboard-bottom { align-items: start; }
.dashboard-table { min-width: 0; }
.planned-panel { padding-bottom: 12px; }
.planned-list { margin: 16px -10px 0; }
.planned-list a { display: flex; gap: 12px; padding: 11px 10px; color: inherit; text-decoration: none; border-top: 1px solid var(--border); }
.week-chip { align-self: center; padding: 5px 7px; color: #1e40af; font-size: 11px; font-weight: 800; background: #dbeafe; border-radius: 6px; }
.planned-detail { min-width: 0; }
.planned-detail strong, .planned-detail small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.planned-detail small { margin-top: 4px; color: var(--muted); }
.empty-copy { color: var(--muted); }

.inline-filter { display: flex; gap: 7px; }
.bank-hero { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); margin-bottom: 22px; color: #e2e8f0; background: linear-gradient(125deg, #0f172a, #1e3a8a); border-radius: 16px; }
.bank-hero > div { padding: 26px; border-right: 1px solid rgba(255,255,255,.13); }
.bank-hero > div:last-child { border-right: 0; }
.bank-hero span, .bank-hero small { display: block; color: #cbd5e1; }
.bank-hero strong { display: block; margin: 8px 0; color: #fff; font-size: clamp(23px, 3vw, 34px); font-variant-numeric: tabular-nums; }
.bank-company-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; margin-bottom: 22px; }
.bank-company-card { padding: 20px; background: #fff; border: 1px solid var(--border); border-top: 3px solid var(--company-color); border-radius: 12px; }
.bank-company-title { display: flex; align-items: center; gap: 9px; margin-bottom: 17px; }
.bank-company-card dl { display: grid; gap: 8px; margin: 0; }
.bank-company-card dl div { display: flex; justify-content: space-between; gap: 15px; }
.bank-company-card dt { color: var(--muted); }
.bank-company-card dd { margin: 0; font-weight: 700; font-variant-numeric: tabular-nums; }
.bank-breakdown { grid-template-columns: minmax(0, 2.4fr) minmax(260px, .7fr); }
.bank-list-panel { padding-bottom: 10px; }
.bank-list-row { display: flex; justify-content: space-between; gap: 20px; padding: 16px 0; border-top: 1px solid var(--border); }
.bank-list-row:first-of-type { margin-top: 15px; }
.bank-list-row > div:last-child { text-align: right; }
.bank-list-row small { display: block; margin-top: 3px; color: var(--muted); }
.history-panel { margin-bottom: 40px; }

.audit-count { display: grid; text-align: right; }
.audit-count strong { font-size: 26px; }
.audit-count span { color: var(--muted); font-size: 12px; }
.audit-filter-grid { grid-template-columns: repeat(5, minmax(120px, 1fr)); }
.audit-list { display: grid; gap: 12px; }
.audit-event { display: grid; grid-template-columns: 5px 1fr; overflow: hidden; background: #fff; border: 1px solid var(--border); border-radius: 12px; }
.audit-marker { background: #64748b; }
.audit-crear, .audit-restaurar { background: #16a34a; }
.audit-editar { background: #2563eb; }
.audit-borrar { background: #dc2626; }
.audit-login, .audit-logout { background: #7c3aed; }
.audit-importar, .audit-exportar { background: #0891b2; }
.audit-body { min-width: 0; padding: 17px 20px; }
.audit-header { display: flex; align-items: center; justify-content: space-between; gap: 15px; }
.audit-header > div { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.audit-header time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.audit-action { padding: 3px 7px; color: #334155; font-size: 10px; font-weight: 800; background: #e2e8f0; border-radius: 5px; }
.audit-body > p { margin: 11px 0; }
.audit-meta { display: flex; flex-wrap: wrap; gap: 15px; color: var(--muted); font-size: 12px; }
.audit-details { margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.audit-details summary { color: var(--primary); font-size: 13px; font-weight: 700; cursor: pointer; }
.audit-json-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 12px; }
.audit-json-grid pre { max-height: 340px; overflow: auto; padding: 13px; color: #dbeafe; font-size: 11px; white-space: pre-wrap; overflow-wrap: anywhere; background: #0f172a; border-radius: 8px; }

.upload-panel { margin-bottom: 24px; }
.upload-panel h2 { margin-top: 0; }
.upload-panel form { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 20px; }
.file-field { position: relative; }
.file-field input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.file-field label { display: inline-block; padding: 11px 16px; color: #1e40af; font-weight: 700; background: #eff6ff; border: 1px dashed #60a5fa; border-radius: 9px; cursor: pointer; }
.file-field input:focus + label { outline: 3px solid rgba(37,99,235,.2); }
.import-history { margin-bottom: 40px; }
.import-status { color: #1e40af; background: #dbeafe; }
.import-help { line-height: 1.55; }
.import-summary { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 20px; margin-bottom: 20px; }
.import-summary div { min-width: 0; }
.import-summary span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.import-summary strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.import-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 16px 0; }
.import-toolbar label { display: flex; align-items: center; gap: 8px; }
.import-table { min-width: 1260px; }
.import-table select { padding: 8px; border: 1px solid var(--border); border-radius: 7px; }
.row-warning { background: #fffbeb; }
.warning-cell { max-width: 240px; color: #92400e; font-size: 12px; }
.import-class { display: inline-block; margin-bottom: 4px; padding: 4px 7px; font-size: 10px; font-weight: 800; border-radius: 5px; }
.import-class-nuevo { color: #166534; background: #dcfce7; }
.import-class-duplicado { color: #475569; background: #e2e8f0; }
.import-class-posible_actualizacion { color: #1e40af; background: #dbeafe; }
.import-class-conflicto { color: #991b1b; background: #fee2e2; }
.import-table td:nth-child(2) { min-width: 210px; }
.import-table td:nth-child(2) .row-link { display: block; margin-top: 5px; font-size: 12px; }
.import-back { margin: 22px 0 40px; }

@media (max-width: 520px) {
    .login-card { padding: 28px 22px; }
    .topbar { padding: 14px 18px; }
}

@media (max-width: 760px) {
    .topbar { flex-wrap: wrap; gap: 12px; }
    .main-nav { order: 3; flex-wrap: wrap; width: 100%; margin: 0; gap: 12px 18px; }
    .user-menu > span { display: none; }
    .page-heading { align-items: flex-start; flex-direction: column; }
    .card-grid, .form-grid, .summary-grid, .summary-grid-three, .form-grid-three, .detail-grid, .details-list, .kpi-grid, .dashboard-grid, .bank-hero, .bank-company-grid, .audit-json-grid, .import-summary { grid-template-columns: 1fr; }
    .field-wide { grid-column: auto; }
    .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .field-search { grid-column: span 2; }
    .heading-actions { width: 100%; }
    .period-filter { justify-content: flex-start; }
    .company-row { grid-template-columns: 1fr; }
    .bank-hero > div { border-right: 0; border-bottom: 1px solid rgba(255,255,255,.13); }
    .bank-hero > div:last-child { border-bottom: 0; }
    .audit-header { align-items: flex-start; flex-direction: column; }
    .audit-count { text-align: left; }
    .import-toolbar { align-items: flex-start; flex-direction: column; }
}
