:root {
    --bg-primary: #080c14;
    --bg-secondary: #0f172a;
    --bg-card: rgba(15, 23, 42, 0.65);
    --bg-card-hover: rgba(30, 41, 59, 0.8);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(99, 102, 241, 0.3);
    --border-focus: rgba(99, 102, 241, 0.6);
    
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --accent-violet: #6366f1;
    --accent-violet-glow: rgba(99, 102, 241, 0.35);
    --accent-cyan: #06b6d4;
    --accent-cyan-glow: rgba(6, 182, 212, 0.4);
    --accent-pink: #ec4899;
    
    --income-color: #10b981;
    --income-bg: rgba(16, 185, 129, 0.14);
    --income-border: rgba(16, 185, 129, 0.35);
    
    --expense-color: #f43f5e;
    --expense-bg: rgba(244, 63, 94, 0.14);
    --expense-border: rgba(244, 63, 94, 0.35);

    --warning-color: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.14);

    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 24px;
    --radius-full: 9999px;
    
    --shadow-soft: 0 15px 35px -10px rgba(0, 0, 0, 0.6);
    --shadow-glow: 0 0 30px var(--accent-cyan-glow);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
    background-color: var(--bg-primary);
    background-image: 
        radial-gradient(circle at 10% 15%, rgba(99, 102, 241, 0.18) 0%, transparent 45%),
        radial-gradient(circle at 90% 85%, rgba(6, 182, 212, 0.15) 0%, transparent 45%),
        radial-gradient(circle at 50% 50%, rgba(236, 72, 153, 0.05) 0%, transparent 60%);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    padding: 1.5rem;
    display: flex;
    justify-content: center;
}

.app-container {
    width: 100%;
    max-width: 960px;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.2rem 1.8rem;
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-soft);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    /* Permite que el bloque se encoja y no empuje los botones fuera de la pantalla */
    min-width: 0;
    flex: 1 1 auto;
}

.brand-icon {
    font-size: 2.2rem;
    background: rgba(255, 255, 255, 0.04);
    padding: 0.6rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
}

.header-logo-img {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    object-fit: cover;
    border: 1px solid var(--border-color);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.header h1 {
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, #ffffff, #cbd5e1);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.45rem 0.9rem;
    border-radius: var(--radius-full);
    background: rgba(16, 185, 129, 0.1);
    border: 1px solid rgba(16, 185, 129, 0.25);
    color: var(--income-color);
    font-size: 0.8rem;
    font-weight: 600;
    /* Puede partirse en dos líneas y centrarse: antes se salía del borde derecho
       y el texto quedaba cortado en pantallas estrechas. */
    line-height: 1.2;
    text-align: center;
    max-width: 100%;
    white-space: normal;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot.green {
    background-color: var(--income-color);
    box-shadow: 0 0 10px var(--income-color);
}

/* Glassmorphism Cards */
.card {
    background: var(--bg-card);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.6rem;
    box-shadow: var(--shadow-soft);
    transition: var(--transition);
}

.card:hover {
    border-color: rgba(255, 255, 255, 0.14);
}

/* Month Selector Card */
.month-selector-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.9rem 1.4rem;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.85), rgba(30, 41, 59, 0.65));
    border: 1px solid var(--border-glow);
}

.month-display {
    display: flex;
    align-items: center;
    gap: 0.7rem;
}

.month-icon {
    font-size: 1.4rem;
}

.month-display h3 {
    font-size: 1.2rem;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.month-nav-btn {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.month-nav-btn:hover {
    background: var(--accent-violet);
    border-color: var(--accent-violet);
    color: white;
    transform: scale(1.08);
}

.month-nav-btn:active {
    transform: scale(0.95);
}

/* Dashboard Summary Cards */
.dashboard-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.2rem;
}

.metric-card {
    display: flex;
    align-items: center;
    gap: 1.2rem;
    padding: 1.4rem 1.6rem;
    position: relative;
    overflow: hidden;
}

.metric-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
}

.metric-card.income::before { background: linear-gradient(90deg, var(--income-color), #34d399); }
.metric-card.expense::before { background: linear-gradient(90deg, var(--expense-color), #fb7185); }
.metric-card.balance::before { background: linear-gradient(90deg, var(--accent-violet), var(--accent-cyan)); }

.metric-icon {
    font-size: 2rem;
    padding: 0.85rem;
    border-radius: var(--radius-md);
    background: rgba(255, 255, 255, 0.04);
}

.metric-card.income .metric-icon { background: var(--income-bg); }
.metric-card.expense .metric-icon { background: var(--expense-bg); }
.metric-card.balance .metric-icon { background: rgba(99, 102, 241, 0.14); }

.metric-info {
    display: flex;
    flex-direction: column;
}

.metric-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 600;
}

.metric-value {
    font-size: 1.55rem;
    font-weight: 700;
    margin-top: 0.25rem;
    letter-spacing: -0.02em;
}

.metric-card.income .metric-value { color: var(--income-color); }
.metric-card.expense .metric-value { color: var(--expense-color); }

/* Health & Savings Progress */
.health-card {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    background: linear-gradient(135deg, rgba(15, 23, 42, 0.75), rgba(30, 41, 59, 0.5));
    border: 1px solid rgba(255, 255, 255, 0.1);
}

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

.health-title-group {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.health-icon {
    font-size: 1.5rem;
}

.health-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.health-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.health-percentage-badge {
    font-size: 0.85rem;
    font-weight: 700;
    padding: 0.35rem 0.8rem;
    border-radius: var(--radius-full);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--border-color);
}

.progress-bar-container {
    width: 100%;
    height: 12px;
    background: rgba(0, 0, 0, 0.35);
    border-radius: var(--radius-full);
    overflow: hidden;
    padding: 2px;
    border: 1px solid var(--border-color);
}

.progress-bar-fill {
    height: 100%;
    border-radius: var(--radius-full);
    background: linear-gradient(90deg, var(--income-color), #34d399);
    transition: width 0.8s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.3s;
}

.progress-bar-fill.warning { background: linear-gradient(90deg, var(--warning-color), #fbbf24); }
.progress-bar-fill.danger { background: linear-gradient(90deg, var(--expense-color), #e11d48); }

.health-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.status-tag {
    font-weight: 600;
    font-size: 0.75rem;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius-sm);
    text-transform: uppercase;
}

.status-tag.good { background: var(--income-bg); color: var(--income-color); }
.status-tag.warn { background: var(--warning-bg); color: var(--warning-color); }
.status-tag.alert { background: var(--expense-bg); color: var(--expense-color); }

/* Interactive Charts Section */
.charts-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.2rem;
}

.chart-card {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

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

.chart-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.chart-period {
    font-size: 0.75rem;
    color: var(--text-muted);
    background: rgba(255, 255, 255, 0.05);
    padding: 0.25rem 0.6rem;
    border-radius: var(--radius-full);
}

.chart-wrapper {
    position: relative;
    width: 100%;
    height: 240px;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Voice Dictation Card */
.voice-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 1.5rem;
    padding: 2.8rem 1.8rem;
    background: linear-gradient(145deg, rgba(15, 23, 42, 0.85), rgba(30, 41, 59, 0.7));
    border: 1px solid rgba(99, 102, 241, 0.25);
    position: relative;
    overflow: hidden;
}

.voice-header h2 {
    font-size: 1.6rem;
    font-weight: 700;
}

.voice-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 0.4rem;
}

.mic-wrapper {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.2rem;
    margin: 1.2rem 0;
}

.mic-button {
    position: relative;
    width: 96px;
    height: 96px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--accent-violet), var(--accent-cyan));
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 12px 30px rgba(99, 102, 241, 0.45);
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.25s;
    outline: none;
    z-index: 2;
}

.mic-button:hover {
    transform: scale(1.08);
    box-shadow: 0 15px 35px rgba(6, 182, 212, 0.6);
}

.mic-button.recording {
    background: linear-gradient(135deg, #f43f5e, #e11d48);
    box-shadow: 0 0 40px rgba(244, 63, 94, 0.7);
    animation: micPulse 1.2s infinite ease-in-out;
}

.wave-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 96px;
    height: 96px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
    border: 2px solid var(--accent-cyan);
    opacity: 0;
    pointer-events: none;
}

.mic-button.recording .wave-1 {
    animation: waveExpand 2s infinite cubic-bezier(0, 0.2, 0.8, 1);
}

.mic-button.recording .wave-2 {
    animation: waveExpand 2s infinite cubic-bezier(0, 0.2, 0.8, 1) 0.6s;
}

@keyframes waveExpand {
    0% { transform: translate(-50%, -50%) scale(1); opacity: 0.9; }
    100% { transform: translate(-50%, -50%) scale(2.2); opacity: 0; }
}

@keyframes micPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.mic-hint {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.transcript-box {
    width: 100%;
    max-width: 620px;
    background: rgba(0, 0, 0, 0.35);
    border: 1px dashed var(--accent-cyan);
    border-radius: var(--radius-md);
    padding: 1.2rem;
    text-align: left;
}

.transcript-label {
    font-size: 0.75rem;
    color: var(--accent-cyan);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
}

.transcript-box p {
    font-size: 1.05rem;
    color: var(--text-primary);
    margin-top: 0.4rem;
    line-height: 1.4;
}

.voice-examples {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.8rem;
    width: 100%;
}

.examples-title {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.chips-container {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.6rem;
}

.chip {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 0.55rem 1rem;
    border-radius: var(--radius-full);
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
}

.chip:hover {
    background: rgba(99, 102, 241, 0.18);
    border-color: var(--accent-violet);
    color: var(--text-primary);
}

/* History Card & Filters */
.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.2rem;
    flex-wrap: wrap;
    gap: 0.8rem;
}

.history-header h3 {
    font-size: 1.15rem;
    font-weight: 600;
}

.history-filters {
    display: flex;
    gap: 0.4rem;
    background: rgba(0, 0, 0, 0.25);
    padding: 0.25rem;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-color);
}

.filter-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    padding: 0.35rem 0.8rem;
    border-radius: var(--radius-full);
    font-size: 0.78rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.filter-btn.active {
    background: var(--accent-violet);
    color: white;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.9rem 1.2rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-color);
    transition: var(--transition);
}

.history-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
}

.history-left {
    display: flex;
    align-items: center;
    gap: 0.9rem;
}

.history-badge {
    width: 42px;
    height: 42px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
}

.history-badge.gasto { background: var(--expense-bg); border: 1px solid var(--expense-border); }
.history-badge.ingreso { background: var(--income-bg); border: 1px solid var(--income-border); }

.history-details {
    display: flex;
    flex-direction: column;
}

.history-concept {
    font-weight: 600;
    font-size: 0.98rem;
}

.history-meta {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.history-amount {
    font-weight: 700;
    font-size: 1.1rem;
}

.history-amount.gasto { color: var(--expense-color); }
.history-amount.ingreso { color: var(--income-color); }

.empty-state {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    padding: 2rem 0;
}

/* Form Controls & Segmented */
.preview-card {
    border: 1px solid var(--border-glow);
    background: linear-gradient(160deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.98));
}

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

.preview-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.badge-type {
    padding: 0.35rem 0.9rem;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
}

.badge-type.gasto { background: var(--expense-bg); color: var(--expense-color); border: 1px solid var(--expense-border); }
.badge-type.ingreso { background: var(--income-bg); color: var(--income-color); border: 1px solid var(--income-border); }

.entry-form {
    display: flex;
    flex-direction: column;
    gap: 1.2rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1.1rem;
}

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

.form-group.full-width {
    grid-column: span 2;
}

label {
    font-size: 0.82rem;
    color: var(--text-secondary);
    font-weight: 500;
}

input, select {
    background: rgba(15, 23, 42, 0.85);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.75rem 1rem;
    color: var(--text-primary);
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
}

input:focus, select:focus {
    border-color: var(--accent-violet);
    box-shadow: 0 0 15px var(--accent-violet-glow);
}

.input-with-symbol {
    position: relative;
    display: flex;
    align-items: center;
}

.input-with-symbol input {
    width: 100%;
    padding-right: 2.2rem;
}

.input-with-symbol .symbol {
    position: absolute;
    right: 1rem;
    color: var(--text-muted);
    font-weight: 600;
}

.segmented-control {
    display: flex;
    background: rgba(15, 23, 42, 0.85);
    padding: 0.3rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-color);
}

.segment {
    flex: 1;
    padding: 0.65rem;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-weight: 600;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
}

.segment.active {
    background: var(--accent-violet);
    color: white;
    box-shadow: 0 2px 12px var(--accent-violet-glow);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 0.8rem;
}

.btn {
    padding: 0.8rem 1.6rem;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.92rem;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent-violet), #4f46e5);
    color: white;
    box-shadow: 0 4px 18px var(--accent-violet-glow);
}

.btn-primary:hover {
    opacity: 0.95;
    transform: translateY(-2px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    z-index: 100;
    /* IMPORTANTE: los avisos se ven, pero NO deben bloquear los toques.
       Sin esto, al aparecer un aviso encima del botón "Guardar Registro" el botón
       dejaba de responder durante unos segundos y parecía que la app no guardaba. */
    pointer-events: none;
    max-width: min(92vw, 30rem);
}

.toast {
    /* Los avisos tampoco capturan los toques: son solo información */
    pointer-events: none;
    padding: 1rem 1.4rem;
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
    font-size: 0.92rem;
    font-weight: 500;
    animation: toastIn 0.3s ease-out;
    overflow-wrap: anywhere;
}

.toast.success { border-color: var(--income-color); }
.toast.error { border-color: var(--expense-color); }

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

.hidden { display: none !important; }

.header-status {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-shrink: 0;
    flex-wrap: wrap;
    justify-content: center;
}

.settings-icon-btn {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
}

.settings-icon-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: var(--accent-violet);
    transform: rotate(30deg);
}

/* Modal Overlay & Card */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(8, 12, 20, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.2rem;
    animation: fadeIn 0.25s ease-out;
}

.modal-card {
    background: #0f172a;
    border: 1px solid var(--border-glow);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 540px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8), var(--shadow-glow);
    overflow: hidden;
    animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.4rem 1.6rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text-primary);
}

.modal-close-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.8rem;
    cursor: pointer;
    line-height: 1;
    transition: var(--transition);
}

.modal-close-btn:hover {
    color: var(--expense-color);
}

.modal-body {
    padding: 1.6rem;
}

.modal-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 1.4rem;
    line-height: 1.5;
}

.input-help {
    display: block;
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-top: 0.35rem;
}

.advanced-settings {
    margin-top: 1rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.8rem 1rem;
}

.advanced-settings summary {
    font-size: 0.85rem;
    color: var(--text-secondary);
    cursor: pointer;
    font-weight: 500;
    user-select: none;
}

.advanced-settings summary:hover {
    color: var(--accent-violet);
}

.test-result {
    margin-top: 1rem;
    padding: 0.8rem 1rem;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-weight: 500;
}

.test-result.success {
    background: var(--income-bg);
    border: 1px solid var(--income-border);
    color: var(--income-color);
}

.test-result.error {
    background: var(--expense-bg);
    border: 1px solid var(--expense-border);
    color: var(--expense-color);
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
    justify-content: flex-end;
    margin-top: 1.6rem;
    flex-wrap: wrap;
}

.danger-text {
    color: var(--expense-color) !important;
}

.danger-text:hover {
    border-color: var(--expense-color) !important;
    background: var(--expense-bg) !important;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 640px) {
    body { padding: 0.8rem; }
    .form-grid { grid-template-columns: 1fr; }
    .form-group.full-width { grid-column: span 1; }
    .dashboard-cards { grid-template-columns: 1fr; }
    .charts-section { grid-template-columns: 1fr; }
    .modal-actions { flex-direction: column; }
    .modal-actions .btn { width: 100%; justify-content: center; }

    /* Cabecera en dos filas: título arriba y botones debajo, para que el
       distintivo "Conectado a la Nube" se vea entero y sin cortarse. */
    .header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.9rem;
        padding: 1rem 1.1rem;
    }
    .header-brand {
        gap: 0.8rem;
        flex: 0 0 auto;
    }
    .header-brand h1 { font-size: 1.15rem; line-height: 1.2; }
    .header-brand .subtitle { font-size: 0.78rem; }
    .header-logo-img { width: 44px; height: 44px; }
    .header-status {
        justify-content: center;
        gap: 0.6rem;
        flex-wrap: wrap;
    }
    .status-badge {
        font-size: 0.78rem;
        padding: 0.45rem 0.8rem;
    }
}

/* Pantallas muy estrechas: el distintivo pasa a ocupar su propia línea completa */
@media (max-width: 380px) {
    .header-status { flex-direction: column; }
    .header-status .status-badge { width: 100%; }
}

/* Resumen dentro de la lista de movimientos: cuántos hay y sus totales */
.history-summary {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.6rem;
    padding: 0.6rem 0.85rem;
    background: rgba(99, 102, 241, 0.08);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: var(--radius-sm);
    font-size: 0.82rem;
    color: var(--text-secondary);
    flex-wrap: wrap;
}

.history-summary-amounts {
    font-weight: 700;
    color: var(--text-main);
    white-space: nowrap;
}

.history-subtitle {
    margin: 0.2rem 0 0;
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.35;
    max-width: 32rem;
}

/* La lista puede ser larga: se limita la altura y se permite desplazarse dentro */
.history-list {
    max-height: 34rem;
    overflow-y: auto;
}

@media (max-width: 640px) {
    .history-header { flex-direction: column; align-items: flex-start; gap: 0.6rem; }
    .history-subtitle { font-size: 0.75rem; }
    .history-list { max-height: 26rem; }
}

/* Los importes no deben partirse en dos líneas dentro de la lista */
.history-amount {
    white-space: nowrap;
    flex-shrink: 0;
}
.history-details { min-width: 0; }
.history-concept { overflow-wrap: anywhere; }

/* ==========================================================================
   Panel de avisos: cosas que el usuario debería revisar en su hoja de cálculo
   ========================================================================== */
.incidencias {
    background: rgba(234, 179, 8, 0.08);
    border: 1px solid rgba(234, 179, 8, 0.35);
    border-radius: var(--radius-lg);
    padding: 1rem 1.1rem;
    margin-bottom: 1.2rem;
    animation: slideUp 0.3s ease;
}

.incidencia-cabecera {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.6rem;
    color: #facc15;
    font-size: 0.95rem;
    margin-bottom: 0.6rem;
}

.incidencia-cerrar {
    background: none;
    border: none;
    color: #facc15;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.2rem;
    opacity: 0.8;
}

.incidencia-cerrar:hover { opacity: 1; }

.incidencia-lista {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.incidencia {
    font-size: 0.85rem;
    line-height: 1.5;
    padding: 0.5rem 0.7rem;
    border-radius: var(--radius-sm);
    background: rgba(15, 23, 42, 0.5);
    border-left: 3px solid #facc15;
    color: var(--text-secondary);
}

.incidencia.alta {
    border-left-color: var(--expense-color);
    color: #fecdd3;
}

.incidencia-resto,
.incidencia-pie {
    margin: 0.6rem 0 0;
    font-size: 0.78rem;
    color: var(--text-secondary);
    line-height: 1.45;
}

/* Botón para que la app arregle sola las columnas Año/Mes que faltan */
.incidencia-arreglar {
    display: block;
    width: 100%;
    margin: 0.7rem 0 0;
    padding: 0.6rem 0.9rem;
    border: 1px solid rgba(234, 179, 8, 0.45);
    border-radius: var(--radius-sm);
    background: rgba(234, 179, 8, 0.14);
    color: #fde68a;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease, opacity 0.2s ease;
}

.incidencia-arreglar:hover { background: rgba(234, 179, 8, 0.24); }

.incidencia-arreglar:disabled {
    cursor: default;
    opacity: 0.65;
}

/* Aviso dentro de «Opciones avanzadas» cuando falta el Apps Script: sin él la app no guarda */
.aviso-config {
    margin-top: 0.8rem;
    padding: 0.6rem 0.8rem;
    border-radius: var(--radius-sm);
    background: rgba(239, 68, 68, 0.12);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #fecdd3;
    font-size: 0.8rem;
    line-height: 1.5;
}

@media (max-width: 640px) {
    .incidencias { padding: 0.85rem 0.9rem; }
    .incidencia { font-size: 0.8rem; }
    .incidencia-arreglar { font-size: 0.8rem; }
}


.toast.warning { border-color: #facc15; }
.toast.warning::before { content: '⚠️ '; }
.toast.info { border-color: var(--primary-light); }
.toast.error::before { content: '❌ '; }
.toast.success::before { content: '✅ '; }


/* ==========================================================================
   Aviso destacado de presupuesto (aparece SOLO al guardar un gasto)
   ========================================================================== */
.presupuesto {
    background: transparent;
    border: none;
    padding: 0;
}

.alerta-presupuesto {
    border-radius: var(--radius-lg);
    padding: 1rem 1.1rem;
    border: 2px solid var(--expense-color);
    background: rgba(244, 63, 94, 0.12);
    animation: slideUp 0.35s ease;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.alerta-presupuesto.cerca {
    border-color: #facc15;
    background: rgba(250, 204, 21, 0.12);
}

.alerta-cabecera {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

.alerta-icono { font-size: 1.3rem; line-height: 1; }

.alerta-titulo {
    flex: 1;
    font-size: 1.02rem;
    font-weight: 700;
    color: var(--expense-color);
}

.alerta-presupuesto.cerca .alerta-titulo { color: #facc15; }

.alerta-cerrar {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 0.2rem;
}

.alerta-cerrar:hover { color: var(--text-main); }

.alerta-categoria {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 0.5rem;
    overflow-wrap: anywhere;
}

.alerta-cifras {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-main);
    margin-bottom: 0.3rem;
    flex-wrap: wrap;
}

.alerta-porcentaje {
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--expense-color);
}

.alerta-presupuesto.cerca .alerta-porcentaje { color: #facc15; }

.alerta-detalle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.alerta-detalle strong { color: var(--text-main); }

@media (max-width: 640px) {
    .alerta-presupuesto { padding: 0.9rem 0.95rem; }
    .alerta-titulo { font-size: 0.95rem; }
    .alerta-categoria { font-size: 1.05rem; }
}

/* Barra de progreso del aviso de presupuesto */
.presupuesto-barra {
    height: 9px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    overflow: hidden;
    margin: 0.2rem 0 0.6rem;
}

.presupuesto-relleno {
    height: 100%;
    border-radius: 999px;
    transition: width 0.5s ease;
}

.presupuesto-relleno.superado { background: linear-gradient(90deg, #f43f5e, #fb7185); }
.presupuesto-relleno.cerca { background: linear-gradient(90deg, #facc15, #fbbf24); }
