/* ============================================================
   Bonsái — sistema de diseño (móvil-nativo)
   Paleta: verdes de follaje + neutros cálidos tipo papel/barro
   ============================================================ */

:root {
    --bg: #f3f6f2;          /* fondo general (verde papel muy tenue) */
    --surface: #ffffff;      /* tarjetas / hojas */
    --surface-2: #eef2ec;    /* campos, chips */
    --primary: #2f7d4f;      /* verde bonsái */
    --primary-dark: #276843;
    --primary-050: #e7f3ea;  /* verde muy claro (estados activos) */
    --accent: #c47a3d;       /* barro / ámbar (calidez) */
    --text: #1e2a23;         /* verde-gris oscuro */
    --text-muted: #6b7a71;
    --border: #e3e8e0;
    --expense: #c0392b;
    --income: #2f7d4f;
    --danger-bg: #fdecea;
    --radius: 14px;
    --appbar-h: 56px;
    --tabbar-h: 64px;
    --shadow-card: 0 1px 3px rgba(30, 42, 35, .06), 0 1px 2px rgba(30, 42, 35, .04);
}

* { -webkit-tap-highlight-color: transparent; box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { color: var(--text); }

/* ===== Chasis móvil (app shell) ===== */
.app-shell {
    max-width: 480px;
    margin: 0 auto;
    min-height: 100vh;
    background: var(--bg);
    position: relative;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 60px rgba(30, 42, 35, .07);
}

.app-bar {
    position: sticky;
    top: 0;
    z-index: 50;
    height: var(--appbar-h);
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: 0 1rem;
    font-weight: 600;
    font-size: 1.15rem;
    box-shadow: 0 2px 10px rgba(30, 42, 35, .15);
}

.app-bar-logout {
    margin-left: auto; background: rgba(255, 255, 255, .18); color: #fff;
    border: none; border-radius: 8px; padding: .35rem .75rem; font-weight: 600; cursor: pointer;
}
.app-bar-logout:hover { background: rgba(255, 255, 255, .28); }

.app-content {
    flex: 1;
    padding: 1rem 1rem calc(var(--tabbar-h) + 1.25rem);
}

.tab-bar {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: var(--tabbar-h);
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    z-index: 50;
    padding-bottom: env(safe-area-inset-bottom);
}

.tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text-muted);
    font-size: .72rem;
    font-weight: 600;
}

.tab-icon { font-size: 1.35rem; opacity: .55; transition: opacity .15s; }
.tab.active { color: var(--primary); }
.tab.active .tab-icon { opacity: 1; }

/* ===== Login / registro ===== */
.auth-card {
    background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
    padding: 1.75rem 1.5rem; box-shadow: 0 8px 30px rgba(30, 42, 35, .08);
}
.auth-brand { font-size: 1.5rem; font-weight: 700; text-align: center; margin-bottom: .5rem; }
.auth-card h2 { margin: 0 0 1rem; text-align: center; font-size: 1.25rem; }
.auth-card label { display: block; font-size: .82rem; color: var(--text-muted); margin: .7rem 0 .25rem; font-weight: 600; }
.auth-btn { width: 100%; margin-top: 1.1rem; padding: .7rem; font-size: 1rem; }
.auth-alt { text-align: center; margin: 1rem 0 0; font-size: .9rem; color: var(--text-muted); }

/* ===== Encabezados de página ===== */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; gap: 1rem; }
.page-header h1 { margin: 0; font-size: 1.45rem; }
.muted { color: var(--text-muted); }
.empty { text-align: center; padding: 3rem 1rem; border: 2px dashed var(--border); border-radius: var(--radius); color: var(--text-muted); }
.back-link { color: var(--primary); font-size: .9rem; font-weight: 500; display: inline-block; margin-bottom: .5rem; }
.back-link:hover { text-decoration: underline; }

/* ===== Botones ===== */
.btn-primary {
    background: var(--primary); color: #fff; border: none; border-radius: 10px;
    padding: .6rem 1rem; cursor: pointer; font-weight: 600; font-size: .95rem;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled { opacity: .6; cursor: default; }
.btn-secondary { background: var(--surface-2); color: var(--text); border: none; border-radius: 10px; padding: .6rem 1rem; cursor: pointer; font-weight: 500; }
.btn-mini { border: none; background: var(--surface-2); border-radius: 8px; padding: .3rem .55rem; cursor: pointer; font-size: .9rem; color: var(--text); }
.btn-mini:hover { background: #e2e7dd; }
.btn-mini.danger:hover { background: var(--danger-bg); }

.alert-error { background: var(--danger-bg); color: #a5271b; border: 1px solid #f5c6c0; padding: .55rem .75rem; border-radius: 10px; margin: .5rem 0; font-size: .9rem; }

/* ===== Árbol ===== */
.node-tree, .node-children { list-style: none; margin: 0; padding: 0; }
.node-children { margin-left: 1rem; border-left: 2px solid var(--border); padding-left: .75rem; }
.node-item { margin: .4rem 0; }
.node-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: .7rem .8rem; background: var(--surface); border: 1px solid var(--border);
    border-radius: 12px; box-shadow: var(--shadow-card);
}
.node-label { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.node-icon { font-size: 1.3rem; }
.node-name { font-weight: 600; background: none; border: none; padding: 0; cursor: pointer; color: var(--text); font-size: 1rem; text-align: left; }
.node-name:active { color: var(--primary); }
.node-actions { display: flex; gap: .3rem; }

/* ===== Modal tipo bottom-sheet (nativo) ===== */
.modal-backdrop-b { position: fixed; inset: 0; background: rgba(20, 30, 24, .45); z-index: 100; }
.modal-b {
    position: fixed; left: 50%; bottom: 0; transform: translateX(-50%);
    width: 100%; max-width: 480px;
    background: var(--surface); border-radius: 20px 20px 0 0;
    padding: 1.25rem 1.25rem calc(1.5rem + env(safe-area-inset-bottom));
    z-index: 101; box-shadow: 0 -10px 40px rgba(20, 30, 24, .22);
    max-height: 88vh; overflow-y: auto;
    animation: sheet-up .22s ease-out;
}
@keyframes sheet-up { from { transform: translate(-50%, 100%); } to { transform: translate(-50%, 0); } }
.modal-b::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: -.4rem auto .8rem; }
.modal-b h3 { margin-top: 0; }
.modal-b label { display: block; font-size: .82rem; color: var(--text-muted); margin-top: .7rem; margin-bottom: .25rem; font-weight: 600; }
.fld { width: 100%; padding: .65rem .7rem; border: 1px solid var(--border); border-radius: 10px; font-size: 1rem; background: var(--surface); color: var(--text); }
.fld:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-050); }
.row-2 { display: flex; gap: .75rem; }
.row-2 > div { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1.3rem; }

/* ===== Selector de plantillas ===== */
.tpl-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin-top: .8rem; }
.tpl-card {
    display: flex; flex-direction: column; align-items: flex-start; gap: .15rem;
    text-align: left; padding: .8rem; border: 1px solid var(--border); border-radius: 12px;
    background: var(--surface); cursor: pointer;
}
.tpl-card:hover { border-color: var(--primary); background: var(--primary-050); }
.tpl-icon { font-size: 1.6rem; }
.tpl-label { font-weight: 700; font-size: .92rem; }
.tpl-hint { font-size: .74rem; color: var(--text-muted); }

/* ===== Toggle gasto / ingreso ===== */
.type-toggle { display: flex; gap: .5rem; }
.type-toggle button { flex: 1; padding: .6rem; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; color: var(--text-muted); }
.type-toggle button.active-expense { background: var(--danger-bg); border-color: var(--expense); color: #a5271b; }
.type-toggle button.active-income { background: var(--primary-050); border-color: var(--income); color: var(--primary-dark); }

/* ===== Tarjetas de resumen ===== */
.summary-grid { display: flex; flex-wrap: wrap; gap: .7rem; margin: .75rem 0; }
.summary-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .85rem 1rem; min-width: 150px; flex: 1; box-shadow: var(--shadow-card); }
.summary-card .cur { font-size: .72rem; color: var(--text-muted); font-weight: 700; letter-spacing: .04em; }
.summary-card .net { font-size: 1.35rem; font-weight: 800; margin: .2rem 0; }
.summary-card .net.pos { color: var(--income); }
.summary-card .net.neg { color: var(--expense); }
.summary-card .io { font-size: .78rem; color: var(--text-muted); }
.summary-card .io .in { color: var(--income); }
.summary-card .io .out { color: var(--expense); }

/* ===== Lista de movimientos ===== */
.mov-list { list-style: none; margin: 0; padding: 0; }
.mov-item { display: flex; align-items: center; justify-content: space-between; padding: .75rem .25rem; border-bottom: 1px solid var(--border); }
.mov-left { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.mov-cat-icon { font-size: 1.3rem; width: 2.2rem; height: 2.2rem; display: flex; align-items: center; justify-content: center; background: var(--surface-2); border-radius: 50%; flex-shrink: 0; }
.mov-meta { display: flex; flex-direction: column; min-width: 0; }
.mov-title { font-weight: 600; font-size: .95rem; }
.mov-sub { font-size: .78rem; color: var(--text-muted); }
.mov-right { display: flex; align-items: center; gap: .5rem; white-space: nowrap; }
.mov-amount { font-weight: 800; font-size: .95rem; }
.mov-amount.expense { color: var(--expense); }
.mov-amount.income { color: var(--income); }
.mov-attach { display: flex; gap: .4rem; margin-top: .4rem; flex-wrap: wrap; align-items: center; }
.mov-thumb { width: 42px; height: 42px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); display: block; }
.mov-doc { font-size: .78rem; color: var(--primary); font-weight: 600; }

/* ===== Agenda (eventos) ===== */
.section-head { display: flex; align-items: center; justify-content: space-between; margin-top: 1.5rem; }
.section-head h3 { margin: 0; }
.ev-list { list-style: none; margin: .5rem 0 0; padding: 0; }
.ev-item {
    display: flex; align-items: center; justify-content: space-between; gap: .5rem;
    padding: .7rem .8rem; margin: .4rem 0; background: var(--surface);
    border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-card);
    border-left: 4px solid var(--primary);
}
.ev-item.overdue { border-left-color: var(--expense); background: #fdf4f3; }
.ev-item.done { border-left-color: var(--border); opacity: .8; }
.ev-left { display: flex; align-items: center; gap: .7rem; min-width: 0; }
.ev-icon { font-size: 1.25rem; }
.ev-meta { display: flex; flex-direction: column; min-width: 0; }
.ev-title { font-weight: 600; font-size: .95rem; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.ev-sub { font-size: .8rem; color: var(--text-muted); }
.ev-badge { font-size: .68rem; font-weight: 700; color: var(--primary-dark); background: var(--primary-050); padding: .1rem .45rem; border-radius: 20px; }
.ev-actions { display: flex; gap: .3rem; flex-shrink: 0; }
.ev-history { margin-top: .75rem; }
.ev-history summary { cursor: pointer; color: var(--text-muted); font-size: .85rem; font-weight: 600; }
