:root {
    color-scheme: light dark;
    --color-bg: #f5f6f8;
    --color-surface: #ffffff;
    --color-text: #1a1d23;
    --color-text-muted: #6b7280;
    --color-primary: #2563eb;
    --color-primary-hover: #1d4ed8;
    --color-danger: #dc2626;
    --color-success: #16a34a;
    --color-warning: #d97706;
    --color-border: #e5e7eb;
    --color-danger-bg: #fee2e2;
    --color-warning-bg: #fef3c7;
    --color-success-bg: #dcfce7;
    --color-muted-bg: #eef0f3;
    --color-track-bg: #eef0f3;
    --radius: 10px;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 16px;
    --space-4: 24px;
    --space-5: 32px;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --color-bg: #14161a;
        --color-surface: #1c1f26;
        --color-text: #e8eaed;
        --color-text-muted: #9aa1ac;
        --color-primary: #5b8def;
        --color-primary-hover: #7ea3f2;
        --color-danger: #f87171;
        --color-success: #4ade80;
        --color-warning: #fbbf24;
        --color-border: #2c303a;
        --color-danger-bg: #3a1f22;
        --color-warning-bg: #3a2f16;
        --color-success-bg: #16301f;
        --color-muted-bg: #262a33;
        --color-track-bg: #262a33;
    }
}

:root[data-theme="dark"] {
    --color-bg: #14161a;
    --color-surface: #1c1f26;
    --color-text: #e8eaed;
    --color-text-muted: #9aa1ac;
    --color-primary: #5b8def;
    --color-primary-hover: #7ea3f2;
    --color-danger: #f87171;
    --color-success: #4ade80;
    --color-warning: #fbbf24;
    --color-border: #2c303a;
    --color-danger-bg: #3a1f22;
    --color-warning-bg: #3a2f16;
    --color-success-bg: #16301f;
    --color-muted-bg: #262a33;
    --color-track-bg: #262a33;
}

/* Estilo especial por módulo: cada uno acenta con un color propio.
   Se pone en <body data-modulo="..."> desde layout.php, y al ser una
   variable heredada, sustituye al color por defecto en botones, enlaces,
   focos, etc. sin tocar el resto de la hoja de estilos. */








* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
}

a {
    color: var(--color-primary);
}

input[type="text"],
input[type="date"],
input[type="number"],
input[type="email"],
input[type="password"] {
    background: var(--color-surface);
    color: var(--color-text);
}

.app-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-3) var(--space-4);
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    flex-wrap: wrap;
    gap: var(--space-2);
}

.app-header__start {
    display: flex;
    align-items: center;
    gap: var(--space-4);
    min-width: 0;
}

.hamburger-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    color: var(--color-text);
    padding: 0;
}

.app-header__brand {
    font-weight: 700;
    font-size: 1.125rem;
    color: var(--color-text);
    text-decoration: none;
}

.app-nav {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    overflow-x: auto;
    max-width: 100%;
    -webkit-overflow-scrolling: touch;
}

.app-nav a,
.app-nav__btn {
    color: var(--color-text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    font-family: inherit;
}

.app-nav a:hover,
.app-nav__btn:hover {
    color: var(--color-primary);
}

.app-header__end {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-shrink: 0;
}

.icon-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--color-muted-bg);
    font-size: 1.1rem;
    text-decoration: none;
    flex-shrink: 0;
    border: none;
    padding: 0;
    cursor: pointer;
    color: var(--color-text);
    font-family: inherit;
}

.icon-button:hover {
    background: var(--color-border);
}

.profile-menu {
    position: relative;
    flex-shrink: 0;
}

.profile-menu__trigger {
    display: inline-flex;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    border-radius: 50%;
}

.profile-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
    display: flex;
    align-items: center;
    justify-content: center;
}

.friend-avatar {
    border-radius: 50%;
    object-fit: cover;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.friend-avatar--placeholder {
    background: var(--color-primary);
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
}

.profile-avatar--placeholder {
    background: var(--color-primary);
    color: #fff;
    font-weight: 700;
    font-size: 0.95rem;
}

.profile-menu__dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
    min-width: 190px;
    padding: var(--space-2);
    z-index: 100;
}

.profile-menu__dropdown[hidden] {
    display: none;
}

.profile-menu__dropdown a,
.profile-menu__dropdown button {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: var(--space-2);
    border-radius: calc(var(--radius) - 2px);
    color: var(--color-text);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}

.profile-menu__dropdown a:hover,
.profile-menu__dropdown button:hover {
    background: var(--color-muted-bg);
}

.profile-menu__dropdown form {
    margin: 0;
}

.apps-menu {
    position: relative;
    flex-shrink: 0;
}

.apps-menu__panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
    padding: var(--space-3);
    z-index: 100;
    width: 250px;
}

.apps-menu__panel[hidden] {
    display: none;
}

.apps-menu__grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-1);
}

.apps-menu__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: var(--space-2) var(--space-1);
    border-radius: 8px;
    text-decoration: none;
    color: var(--color-text);
    text-align: center;
}

.apps-menu__item:hover {
    background: var(--color-muted-bg);
}

.apps-menu__item-icon {
    font-size: 1.6rem;
    line-height: 1;
}

.apps-menu__item-label {
    font-size: 0.75rem;
    font-weight: 600;
}

@media (max-width: 720px) {
    .hamburger-btn {
        display: inline-flex;
    }

    .app-nav {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        gap: 0;
        overflow-x: visible;
        background: var(--color-surface);
        border-bottom: 1px solid var(--color-border);
        box-shadow: 0 8px 16px rgba(0, 0, 0, 0.15);
        padding: var(--space-2) var(--space-4) var(--space-3);
        z-index: 90;
    }

    .app-nav.is-open {
        display: flex;
    }

    .app-nav a,
    .app-nav__btn {
        width: 100%;
        padding: var(--space-2) 0;
        white-space: normal;
        text-align: left;
        border-bottom: 1px solid var(--color-border);
    }

}

.app-main {
    max-width: 960px;
    margin: 0 auto;
    padding: var(--space-4);
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-bottom: var(--space-4);
}

.page-header h1 {
    margin: 0;
    font-size: 1.375rem;
}

.section-title {
    font-size: 1rem;
    color: var(--color-text-muted);
    margin: var(--space-5) 0 var(--space-2);
}

.list-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    overflow: hidden;
}

.list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-3);
    border-bottom: 1px solid var(--color-border);
    flex-wrap: wrap;
}

.list-row:last-child {
    border-bottom: none;
}

.list-row__main {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    min-width: 0;
}

.list-row__swatch {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--color-border);
}

.list-row__name {
    font-weight: 600;
}

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

.list-row__actions {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    font-size: 0.85rem;
}

.amount {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

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

.amount--positive {
    color: var(--color-success);
}

.amount--neutral {
    color: var(--color-text-muted);
}

.filter-form {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-3);
    margin-bottom: var(--space-4);
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-2) var(--space-3);
    align-items: end;
}

.filter-form .form-group {
    margin-bottom: 0;
}

.filter-form__actions {
    display: flex;
    gap: var(--space-2);
    grid-column: 1 / -1;
}

.filter-form__actions .btn {
    width: auto;
}

.progress-bar {
    height: 8px;
    background: var(--color-track-bg);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 8px;
}

.progress-bar__fill {
    height: 100%;
    border-radius: 999px;
    background: var(--color-success);
    transition: width 0.2s ease;
}

.progress-bar__fill--warning {
    background: var(--color-warning);
}

.progress-bar__fill--over {
    background: var(--color-danger);
}

.badge--warning {
    background: var(--color-warning-bg);
    color: var(--color-warning);
}

.badge--success {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.stat-grid--compact {
    grid-template-columns: repeat(3, 1fr);
    margin-bottom: 0;
}

@media (max-width: 480px) {
    .stat-grid--compact {
        grid-template-columns: 1fr;
    }
}

/* Para grids de exactamente 6 tarjetas (2 filas de 3): en escritorio
   fuerza 3 columnas para que no quede una suelta sola en su fila —
   auto-fit puede encajar 4 o 5 columnas según el ancho disponible, y con
   6 elementos eso deja un resto impar. En móvil se queda con el
   auto-fit normal de .stat-grid (2 por fila). */
@media (min-width: 640px) {
    .stat-grid--3col {
        grid-template-columns: repeat(3, 1fr);
    }
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-3);
}

.stat-card__label {
    font-size: 0.8rem;
    color: var(--color-text-muted);
    margin-bottom: 4px;
}

.stat-card__value {
    font-size: 1.4rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.stat-card__value--negative {
    color: var(--color-danger);
}

.stat-card__value--positive {
    color: var(--color-success);
}

.stat-card__delta {
    font-size: 0.8rem;
    margin-top: 4px;
}

.stat-card__delta--up {
    color: var(--color-success);
}

.stat-card__delta--down {
    color: var(--color-danger);
}

.chart-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--space-3);
    margin-bottom: var(--space-4);
}

.chart-card h2 {
    margin: 0 0 var(--space-2);
    font-size: 1rem;
}

.chart-container {
    position: relative;
    height: 260px;
}

.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}

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

.period-form {
    display: flex;
    gap: var(--space-2);
    margin-bottom: var(--space-3);
    flex-wrap: wrap;
}

.period-form select {
    width: auto;
}

.legend-list {
    list-style: none;
    margin: var(--space-2) 0 0;
    padding: 0;
    font-size: 0.85rem;
}

.legend-list li {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    padding: 4px 0;
}

.legend-list__label {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
}

.legend-list__swatch {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.badge {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--color-danger-bg);
    color: var(--color-danger);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.badge--muted {
    background: var(--color-muted-bg);
    color: var(--color-text-muted);
}

.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
    margin-top: var(--space-2);
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--color-muted-bg);
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.8rem;
}

.chip button {
    background: none;
    border: none;
    color: var(--color-text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    line-height: 1;
    padding: 0;
}

.chip button:hover {
    color: var(--color-danger);
}

.form-page {
    max-width: 480px;
    margin: 0 auto;
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-bg);
}

.btn-danger {
    background: var(--color-danger);
}

.btn-danger:hover {
    background: #b91c1c;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-danger-link {
    background: none;
    border: none;
    color: var(--color-danger);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 0;
    text-decoration: underline;
}

.form-row {
    display: flex;
    gap: var(--space-2);
}

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

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

.inline-form {
    display: inline;
}

select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--color-surface);
    color: var(--color-text);
}

input[type="color"] {
    padding: 4px;
    height: 42px;
    width: 100%;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 8px;
}

.fab {
    position: fixed;
    bottom: var(--space-4);
    right: var(--space-4);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--color-primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    line-height: 1;
    text-decoration: none;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    z-index: 100;
}

.fab:hover {
    background: var(--color-primary-hover);
}

.btn-link {
    background: none;
    border: none;
    color: var(--color-text-muted);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0;
}

.btn-link:hover {
    color: var(--color-text);
}

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-4);
}

.card {
    background: var(--color-surface);
    border-radius: var(--radius);
    border: 1px solid var(--color-border);
    padding: var(--space-5);
    width: 100%;
    max-width: 380px;
}

.card__title {
    margin: 0 0 var(--space-4);
    font-size: 1.25rem;
}

.form-group {
    margin-bottom: var(--space-3);
}

/* Para poner varios .form-group en fila en pantallas anchas (formularios
   largos como el de rutina) — en móvil siempre se apilan en una columna. */
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0 var(--space-3);
}

@media (min-width: 640px) {
    .form-grid--2col {
        grid-template-columns: 1fr 1fr;
    }
}

    font-weight: 600;
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    background: var(--color-surface);
    color: var(--color-text);
}

.form-group textarea {
    resize: vertical;
    min-height: 70px;
}

.form-group input:focus,
.form-group textarea:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 1px;
}

.btn {
    display: inline-block;
    width: 100%;
    padding: 10px 16px;
    background: var(--color-primary);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    text-decoration: none;
}

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

.alert {
    padding: var(--space-2) var(--space-3);
    border-radius: 8px;
    margin-bottom: var(--space-3);
    font-size: 0.9rem;
}

.alert--error {
    background: var(--color-danger-bg);
    color: var(--color-danger);
}

.alert--success {
    background: var(--color-success-bg);
    color: var(--color-success);
}

.auth-switch {
    text-align: center;
    margin-top: var(--space-3);
    font-size: 0.9rem;
    color: var(--color-text-muted);
}

