/* Los componentes con display: flex ganarían al atributo hidden */
[hidden] { display: none !important; }

/*
 * PWA con barra de estado translúcida: iOS recorta las capas fijas y lo que html/body ocultan al viewport (812 pt
 * en una pantalla de 874), lo que dejaba una franja abajo. Por eso el contenedor mide 100vh dentro del propio
 * documento y el menú y su fondo oscuro son absolutos dentro de él.
 */
@media (display-mode: standalone) {
    html, body { height: auto; min-height: 100vh; overflow: visible; overscroll-behavior: none; }
    .container { position: relative; height: 100vh; padding-bottom: 0; }
    .views-container { padding-bottom: calc(1px + env(safe-area-inset-bottom)); }
}

@media (display-mode: standalone) and (max-width: 768px) {
    .sidebar { position: absolute; top: 0; bottom: auto; height: 100vh; }
    .sidebar-overlay { position: absolute; inset: 0 auto auto 0; width: 100%; height: 100vh; }
    .sidebar-footer { padding-bottom: calc(env(safe-area-inset-bottom) - 20px); }
}

.section-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px 12px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.section-toolbar h3 { flex: 1 1 auto; min-width: 0; margin: 0; }

.section-toolbar .btn { flex: 0 0 auto; margin-left: auto; white-space: nowrap; }

[data-fit] {
    display: block;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.empty-state {
    color: var(--text-secondary);
    text-align: center;
    padding: 28px 12px;
}

.badge-auto {
    font-size: 11px;
    padding: 3px 8px;
    border-radius: 10px;
    background: var(--warning-light);
    color: #92400e;
    white-space: nowrap;
}

.btn-block { width: 100%; }

.modal-hint {
    color: var(--text-secondary);
    font-size: 12px;
    line-height: 1.4;
}

.modal-input-group { display: flex; gap: 8px; }

.modal-input-group input { flex: 1 1 auto; min-width: 0; }

.sign-toggle {
    flex: 0 0 auto;
    width: 48px;
    font-size: 22px;
    font-weight: 700;
    line-height: 1;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.sign-toggle:active { transform: scale(0.95); }

.sign-toggle:disabled { opacity: 0.5; cursor: default; }

.sign-toggle.active {
    color: var(--danger);
    background: var(--danger-light);
    border-color: var(--danger);
}

.modal-field input.is-negative { color: var(--danger); }

.modal-error {
    margin: 4px 0 0;
    padding: 8px 10px;
    border-radius: 6px;
    background: var(--danger-light);
    color: var(--danger);
    font-size: 13px;
}

.modal-card .modal-note strong { color: var(--text-primary); }

.accounts-kpis,
.savings-kpis { margin-bottom: 24px; }

.accounts-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.account-item .account-main {
    display: flex;
    flex: 1 1 100%;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.account-main > :first-child { flex: 1 1 0; min-width: 0; }

.account-main > .account-balance { flex: 0 1 auto; max-width: 55%; text-align: right; }

.category-item > :first-child { flex: 1 1 120px; min-width: 0; }

.category-item .category-budget { flex: 0 1 auto; max-width: 100%; }

.account-balance.negative { color: var(--danger); }

.account-item.credit-card {
    border-left-color: #8b5cf6;
    background: linear-gradient(135deg, rgba(102,126,234,0.08), rgba(118,75,162,0.08));
}

.cc-usage { flex: 1 1 100%; }

.cc-usage-bar {
    height: 8px;
    border-radius: 4px;
    background: var(--border);
    overflow: hidden;
}

.cc-usage-fill {
    height: 100%;
    background: #8b5cf6;
    transition: width 0.3s ease;
}

.cc-usage-fill.high { background: var(--danger); }

.cc-usage-legend {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-secondary);
}

.cc-details {
    flex: 1 1 100%;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr));
    gap: 8px 16px;
    font-size: 13px;
}

.cc-details dt { color: var(--text-secondary); font-size: 12px; }

.cc-details dd { font-weight: 600; }

.cc-details .urgent dd { color: var(--danger); }

.transaction-row.transferencia { border-left-color: var(--text-secondary); }

.tx-title { font-weight: 500; }

.tx-meta { font-size: 12px; color: var(--text-secondary); }

.tx-amount { font-weight: 600; }

.debt-amount { font-weight: 600; color: var(--warning); }

.goal-card {
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    padding: 20px;
    margin-bottom: 15px;
    background: var(--bg-secondary);
    border-radius: 8px;
    min-width: 0;
}

.goal-card-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; flex-wrap: wrap; }

.goal-card-info { flex: 1 1 200px; }

.goal-card-info h4 { margin: 0 0 10px; font-size: 16px; }

.goal-card-info p { margin: 6px 0; color: var(--text-secondary); font-size: 14px; }

.goal-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.goal-card .goal-progress { width: 100%; height: 8px; margin-top: 14px; background: var(--dark-light); border-radius: 4px; overflow: hidden; }

.goal-card .goal-progress > div { height: 100%; }

.goal-card-percent { margin: 10px 0 0; text-align: right; color: var(--text-secondary); font-size: 12px; }

.plan-card-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }

.plan-card-head h3 { margin: 0; }

.sync-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 15px;
    margin-bottom: 20px;
    padding: 15px;
    background: var(--bg-secondary);
    border-radius: 8px;
}

.sync-box-info { flex: 1; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }

.sync-box-info small { color: var(--text-secondary); font-size: 12px; }

.provider-panel { margin-top: 16px; }

.provider-help { display: block; color: var(--text-secondary); font-size: 13px; margin: 8px 0 12px; }

.provider-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

.provider-actions .btn { text-decoration: none; text-align: center; }

.provider-status {
    margin-top: 15px;
    padding: 10px;
    border-radius: 6px;
}

.provider-status.success { background: var(--secondary-light); color: var(--secondary); }

.provider-status.error { background: var(--danger-light); color: var(--danger); }

.config-danger {
    border: 2px solid var(--danger);
    background: rgba(255, 76, 76, 0.05);
}

.config-danger h3 { color: var(--danger); }

.danger-text { color: var(--text-secondary); font-size: 14px; margin-bottom: 12px; }

ul.danger-text { margin-left: 20px; }

@media (max-width: 768px) {
    .config-grid { grid-template-columns: minmax(0, 1fr); }
    .section-toolbar { flex-wrap: wrap; }
}

.sidebar-header h1 {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.brand-icon {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    border-radius: 9px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.25);
}

.loading-icon {
    width: 72px;
    height: 72px;
    margin-bottom: 20px;
    border-radius: 18px;
    box-shadow: 0 6px 18px rgba(102,126,234,0.35);
}

@media (max-height: 700px) {
    .brand-icon { width: 30px; height: 30px; border-radius: 8px; }
}

@media (max-width: 768px) {
    .sidebar-header { padding-left: 16px; padding-right: 14px; gap: 8px; }
    .sidebar-header h1 { font-size: 23px; gap: 8px; justify-content: flex-start; }
    .brand-icon { width: 32px; height: 32px; border-radius: 8px; }
}

.top-header {
    background: #5b5fcf url('../assets/header-art.svg') center / cover no-repeat;
    border-bottom: none;
    box-shadow: 0 4px 16px rgba(80, 60, 160, 0.25);
    color: #fff;
}

.header-left h2 {
    color: #fff;
    text-shadow: 0 1px 6px rgba(0, 0, 0, 0.25);
}

.date-filter label {
    color: rgba(255, 255, 255, 0.9);
}

.date-filter input {
    color: #fff;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.4);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
}

.date-filter input::-webkit-calendar-picker-indicator { filter: invert(1); }

.top-header .btn-export {
    background: rgba(255, 255, 255, 0.95);
    color: #4f46c8;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
}

.top-header .btn-export:hover { background: #fff; color: #3730a3; }

.mobile-menu-toggle {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.45);
    -webkit-backdrop-filter: blur(6px);
    backdrop-filter: blur(6px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.sidebar-header {
    background: url('../assets/header-art.svg') center / cover no-repeat;
    padding-top: calc(env(safe-area-inset-top) + 22px);
    border-bottom: none;
}

@media (max-width: 768px) {
    .sidebar { top: 0; height: 100dvh; }
    .top-header { padding-bottom: 14px; }
}

:root { --loading-bg: rgba(255, 255, 255, 0.95); }

:root[data-theme="dark"] {
    color-scheme: dark;
    --primary: #60a5fa;
    --primary-light: rgba(96, 165, 250, 0.18);
    --secondary: #34d399;
    --secondary-light: rgba(52, 211, 153, 0.16);
    --danger: #f87171;
    --danger-light: rgba(248, 113, 113, 0.16);
    --warning: #fbbf24;
    --warning-light: rgba(251, 191, 36, 0.16);
    --dark-light: #1f2735;
    --border: #36425a;
    --text-primary: #e6e9ef;
    --text-secondary: #98a2b3;
    --bg-primary: #151a24;
    --bg-secondary: #0c1017;
    --loading-bg: rgba(12, 16, 23, 0.96);
}

:where(:root[data-theme="dark"]) :where(input, select, textarea) {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border-color: var(--border);
}

:root[data-theme="dark"] .badge-auto { color: #fbbf24; }

:root[data-theme="dark"] .modal-card,
:root[data-theme="dark"] .kpi-card,
:root[data-theme="dark"] .chart-card { box-shadow: 0 2px 14px rgba(0, 0, 0, 0.45); }

:root[data-theme="dark"] .account-item.credit-card {
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.16), rgba(118, 75, 162, 0.16));
}

.theme-options {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.theme-option {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px 8px;
    text-align: center;
    background: var(--bg-secondary);
    border: 2px solid var(--border);
    border-radius: 12px;
    cursor: pointer;
    transition: border-color 0.2s ease, background 0.2s ease, transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
}

.theme-option:active { transform: scale(0.97); }

.theme-option input { position: absolute; opacity: 0; pointer-events: none; }

.theme-option-icon { font-size: 26px; line-height: 1; }

.theme-option-label { font-weight: 600; font-size: 14px; color: var(--text-primary); }

.theme-option small { font-size: 11px; color: var(--text-secondary); line-height: 1.3; }

.theme-option:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
}

.theme-option:has(input:focus-visible) { outline: 2px solid var(--primary); outline-offset: 2px; }

@media (max-width: 480px) {
    .theme-options { grid-template-columns: minmax(0, 1fr); }
    .theme-option { flex-direction: row; justify-content: flex-start; text-align: left; gap: 12px; padding: 12px 14px; }
    .theme-option small { margin-left: auto; text-align: right; }
}
