/* ============================================================
   Gastos Casa — estilos generales
   Mobile-first, sin dependencias externas.
   ============================================================ */

:root {
    --bg: #f4f6f9;
    --card-bg: #ffffff;
    --text: #1f2733;
    --muted: #6b7684;
    --border: #e2e6ec;
    --primary: #3d6bd6;
    --primary-dark: #2c52ab;
    --danger: #c0392b;
    --success-bg: #e6f6ea;
    --success-text: #1e7a3a;
    --error-bg: #fbe8e6;
    --error-text: #a4271f;
    --info-bg: #eaf1fd;
    --info-text: #2c52ab;
    --radius: 10px;
}

* { box-sizing: border-box; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; }
h2 { font-size: 1.1rem; }

.container {
    max-width: 640px;
    margin: 0 auto;
    padding: .55rem .65rem calc(4.5rem + env(safe-area-inset-bottom));
}

/* ---------- Barra superior (minima) ---------- */
.topbar-mini {
    background: var(--primary);
    padding: .4rem 1rem;
    text-align: center;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 2rem;
}
.brand-mini { color: #fff; font-weight: 700; font-size: 1rem; letter-spacing: .02em; }
.topbar-back {
    position: absolute;
    left: .3rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: #fff;
    font-weight: 600;
    font-size: .85rem;
    padding: .4rem .6rem;
    min-height: auto;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}
.topbar-back:hover { background: rgba(255,255,255,.12); }
.topbar-back:active { background: rgba(255,255,255,.22); }

/* ---------- Barra inferior de pestañas ---------- */
.bottomnav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    display: flex;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    box-shadow: 0 -2px 10px rgba(0,0,0,.06);
    padding-bottom: env(safe-area-inset-bottom);
    z-index: 50;
}
.bottomnav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .1rem;
    padding: .5rem 0 .4rem;
    color: var(--muted);
    text-decoration: none;
    min-height: 56px;
    -webkit-tap-highlight-color: transparent;
}
.bottomnav a:active { background: var(--bg); }
.bottomnav a.active { color: var(--primary); }
.bottomnav-icon { font-size: 1.5rem; line-height: 1; }
.bottomnav-label { font-size: .7rem; font-weight: 600; }

/* ---------- Tarjetas ---------- */
.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .8rem .95rem;
    margin: .5rem 0;
}

.muted { color: var(--muted); font-size: .92rem; }
.big-total { font-size: 1.25rem; margin: .3rem 0 .6rem; }
.big-total.is-settled { color: var(--success-text); }
.summary-list { margin: 0; padding-left: 1.2rem; }
.tag {
    display: inline-block;
    background: var(--info-bg);
    color: var(--info-text);
    font-size: .75rem;
    padding: .1rem .5rem;
    border-radius: 999px;
    margin-left: .3rem;
}

/* ---------- Mensajes flash ---------- */
.flash { padding: .6rem .9rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: .92rem; }
.flash-success { background: var(--success-bg); color: var(--success-text); }
.flash-error { background: var(--error-bg); color: var(--error-text); }
.flash-info { background: var(--info-bg); color: var(--info-text); }

/* ---------- Formularios ---------- */
label { display: flex; flex-direction: column; gap: .15rem; font-size: .82rem; color: var(--muted); font-weight: 600; }
input, select, button {
    font: inherit;
    padding: .4rem .55rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    min-height: 42px;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

button {
    cursor: pointer;
    background: var(--primary);
    color: #fff;
    border: none;
    font-weight: 700;
    padding: .55rem 1.1rem;
}
button:hover { background: var(--primary-dark); }
.btn-secondary, a.btn-secondary {
    display: inline-block;
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    padding: .55rem 1.1rem;
    border-radius: 8px;
    font-weight: 600;
}
.btn-secondary:hover { color: var(--text); text-decoration: none; }

.link-action, .link-danger {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 600;
    font-size: .85rem;
    padding: 0;
    text-decoration: underline;
}
.link-danger { color: var(--danger); }
.link-action:hover, .link-danger:hover { background: none; }

.inline-form { display: inline-block; margin: 0; }
.inline-add { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; }
.inline-add input[type=text] { flex: 1; min-width: 200px; }

/* Alta rapida de gasto: grid de 2 columnas, fecha e importe comparten
   fila para no malgastar alto; el resto de campos ocupan toda la
   anchura. Pensado para que quepa sin scroll en un movil. */
.quickadd-card { border-color: var(--primary); }
.qa-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .45rem .6rem;
    align-items: end;
}
.qa-field { min-width: 0; }
.qa-category,
.qa-owner,
.qa-split,
.qa-custom,
.qa-trip,
.qa-photo,
.qa-note,
.qa-checkbox,
.qa-submit { grid-column: 1 / -1; }
.qa-new-category { margin-top: .3rem; }
.qa-submit { height: 2.35rem; width: 100%; }
.qa-row-secondary { margin-top: .45rem; align-items: center; }
.qa-checkbox {
    flex-direction: row;
    align-items: center;
    gap: .4rem;
    font-weight: 500;
    color: var(--text);
}
.qa-checkbox input { width: auto; }

/* ---------- Foto de ticket ---------- */
.qa-photo input[type=file] { padding: .4rem .5rem; }
.receipt-preview-current {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-top: .3rem;
    font-size: .85rem;
    color: var(--muted);
}
.receipt-thumb {
    width: 36px;
    height: 36px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
}
.receipt-link { font-size: 1.1rem; text-decoration: none; }

.filters { display: flex; flex-wrap: wrap; gap: .8rem; align-items: flex-end; }
.editform { display: flex; flex-wrap: wrap; gap: .9rem; }
.editform label { flex: 1 1 200px; }
.formactions { flex-basis: 100%; display: flex; gap: .6rem; margin-top: .4rem; }

.period-label { font-weight: 600; margin: .6rem 0 0; }

/* Encabezado de agrupacion de varias tarjetas (p.ej. "Gastos del dia
   a dia" por encima de Comunes + Privados en Informes) */
.section-title {
    margin: 1.6rem 0 -.3rem;
    font-size: 1rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--muted);
}

/* ---------- Tablas ---------- */
.table-scroll { overflow-x: auto; }
.table-simple { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table-simple th, .table-simple td { padding: .5rem .55rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.table-simple th.num, .table-simple td.num { text-align: right; }
.table-simple tbody tr:hover { background: #fafbfd; }
.row-inactive { opacity: .55; }
.row-settlement { background: var(--info-bg); }
.row-settlement:hover { background: var(--info-bg); }
.total-row td { border-top: 2px solid var(--border); border-bottom: none; font-weight: 700; }
.row-actions { display: flex; gap: .6rem; align-items: center; white-space: nowrap; }
.num-input input { width: 4.5em; }

.chart { max-width: 100%; margin-top: 1rem; }

/* ---------- Grafico "de toda la vida" sin JS/CDN externo: barras
   horizontales de puro CSS, para que nunca se quede en blanco ---------- */
.barchart { display: flex; flex-direction: column; gap: .55rem; margin-top: .6rem; }
.barchart-row { display: flex; flex-direction: column; gap: .15rem; }
.barchart-row-head { display: flex; justify-content: space-between; gap: .5rem; font-size: .85rem; }
.barchart-row-name { font-weight: 600; }
.barchart-track { background: var(--bg); border-radius: 999px; height: 10px; overflow: hidden; }
.barchart-fill { background: var(--primary); height: 100%; border-radius: 999px; }

/* ---------- Campo bloqueado (de solo lectura, ya decidido por el
   contexto: p.ej. la categoria al saldar un viaje concreto) ---------- */
.locked-field {
    display: flex;
    align-items: center;
    min-height: 42px;
    padding: .4rem .55rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-weight: 600;
}

/* ---------- Tablas que se convierten en tarjetas apiladas en movil,
   para que nunca haga falta scroll lateral ---------- */
@media (max-width: 640px) {
    .table-responsive-stack thead { display: none; }
    .table-responsive-stack, .table-responsive-stack tbody,
    .table-responsive-stack tr, .table-responsive-stack td { display: block; width: 100%; }
    .table-responsive-stack tr {
        border-bottom: 1px solid var(--border);
        padding: .5rem 0;
    }
    .table-responsive-stack tr:last-child { border-bottom: none; }
    .table-responsive-stack td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: .6rem;
        padding: .2rem 0;
        border-bottom: none;
        white-space: normal;
        text-align: right;
    }
    .table-responsive-stack td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--muted);
        text-align: left;
        margin-right: .5rem;
    }
    .table-responsive-stack td:empty,
    .table-responsive-stack td[data-label=""]:not(:has(*)) { display: none; }
    .table-responsive-stack td.row-actions,
    .table-responsive-stack td.num { justify-content: flex-end; }
    .table-responsive-stack .table-scroll { overflow-x: visible; }
}

/* ---------- Login ---------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(160deg, #3d6bd6, #22336b);
}
.login-box {
    background: #fff;
    padding: 2rem 1.8rem;
    border-radius: 14px;
    width: 100%;
    max-width: 340px;
    box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.login-box h1 { font-size: 1.3rem; text-align: center; margin-bottom: 1.2rem; }
.login-box form { display: flex; flex-direction: column; gap: .9rem; }
.login-box button { margin-top: .3rem; }

/* ---------- Añadir Gasto: botones grandes ---------- */
.addgasto-buttons {
    display: flex;
    gap: .9rem;
    margin: .75rem 0;
}
.big-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    padding: 2.2rem .5rem;
    border-radius: 22px;
    text-decoration: none;
    color: var(--text);
    border: 2px solid var(--border);
    min-height: 34vh;
    box-shadow: 0 4px 14px rgba(0,0,0,.08);
    -webkit-tap-highlight-color: transparent;
    transition: transform .1s ease;
}
.big-btn:hover { text-decoration: none; }
.big-btn:active { transform: scale(.96); }
.big-btn-hipo { background: #f1e9d8; border-color: #e3d2a4; }
.big-btn-personal { background: #e3ecfb; border-color: #b9cdf3; }
.big-btn-icon { font-size: 5rem; line-height: 1; }
.big-btn-label { font-size: 1.3rem; font-weight: 800; letter-spacing: .01em; }

/* ---------- Saldos (lista compacta) ---------- */
.balance-lines-card { padding-bottom: .6rem; }
.balance-lines { list-style: none; margin: 0; padding: 0; }
.balance-lines li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .6rem;
    padding: .6rem 0;
    border-bottom: 1px solid var(--border);
    font-size: .92rem;
}
.balance-lines li:last-child { border-bottom: none; }
.balance-lines-label { font-weight: 600; }
.balance-lines-value { color: var(--text); text-align: right; }

/* ---------- Alta de gasto dedicada (Hipopotamo / Personal) ---------- */
.big-quickadd .qa-submit.big-submit {
    width: 100%;
    height: 3rem;
    font-size: 1.05rem;
    margin-top: .3rem;
}

/* ---------- Icono de tipo de viaje ---------- */
.trip-icon { font-size: 1.3rem; text-align: center; width: 2rem; white-space: nowrap; }

/* ---------- Tarjetas de viaje (sin tabla ancha: todo se ve sin
   scroll lateral en movil) ---------- */
.trip-cards { display: flex; flex-direction: column; gap: .7rem; }
.trip-card { border-bottom: 1px solid var(--border); padding-bottom: .7rem; }
.trip-card:last-child { border-bottom: none; padding-bottom: 0; }
.trip-card-head {
    display: flex;
    align-items: baseline;
    gap: .4rem;
    flex-wrap: wrap;
}
.trip-card-name { font-weight: 700; font-size: 1.02rem; flex: 1 1 auto; }
.trip-card-total { font-weight: 700; white-space: nowrap; }
.trip-card-meta { color: var(--muted); font-size: .85rem; margin: .15rem 0 .5rem; display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; }
.trip-solo-picker { margin-top: .4rem; }
.trip-solo-picker label { flex-direction: row; align-items: center; gap: .4rem; font-size: .8rem; }
.trip-solo-picker select { min-height: 34px; padding: .25rem .4rem; font-size: .82rem; }

/* ---------- Desplegables (cerrados / nuevo viaje) ---------- */
details.closed-trips summary,
details.new-trip-toggle summary,
details.collapsible-section summary {
    cursor: pointer;
    font-weight: 700;
    list-style: none;
}
details.closed-trips summary::-webkit-details-marker,
details.new-trip-toggle summary::-webkit-details-marker,
details.collapsible-section summary::-webkit-details-marker { display: none; }
details.closed-trips summary::before,
details.new-trip-toggle summary::before,
details.collapsible-section summary::before { content: "▸ "; }
details.closed-trips[open] summary::before,
details.new-trip-toggle[open] summary::before,
details.collapsible-section[open] summary::before { content: "▾ "; }
details.closed-trips[open] summary,
details.new-trip-toggle[open] summary,
details.collapsible-section[open] summary { margin-bottom: .6rem; }
details.new-trip-toggle form,
details.collapsible-section form { margin-top: .4rem; }
details.collapsible-section h3:first-of-type { margin-top: .6rem; }

/* ---------- Lista de conceptos, con subir/bajar ---------- */
.concept-list { display: flex; flex-direction: column; }
.concept-row {
    display: flex;
    align-items: center;
    gap: .5rem;
    padding: .55rem 0;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}
.concept-row:last-child { border-bottom: none; }
.concept-move { display: flex; flex-direction: column; gap: 0; }
.concept-move .link-action { padding: 0 .3rem; font-size: .8rem; line-height: 1.5; }
.concept-move .link-action:disabled { opacity: .3; text-decoration: none; cursor: default; }
.concept-rename { flex: 1 1 160px; display: flex; gap: .4rem; align-items: center; }
.concept-rename input[type=text] { flex: 1; min-height: 38px; }
.concept-status { font-size: .8rem; flex: 0 0 auto; }

/* ---------- Saldo por categorias, con boton "Saldar" ---------- */
.balance-cat-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .6rem;
    padding: .6rem 0;
    border-bottom: 1px solid var(--border);
}
.balance-cat-row:last-child { border-bottom: none; }
.balance-cat-row .btn-secondary { flex: 0 0 auto; padding: .4rem .8rem; font-size: .85rem; }

/* ---------- Menu "Mas" ---------- */
.more-menu { padding: 0; overflow: hidden; }
.more-item {
    display: flex;
    align-items: center;
    gap: .8rem;
    padding: .95rem 1.1rem;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
.more-item:last-child { border-bottom: none; }
.more-item:hover { background: #fafbfd; text-decoration: none; }
.more-item-icon { font-size: 1.3rem; width: 1.6rem; text-align: center; }
.more-item-label { flex: 1; font-weight: 600; }
.more-item-arrow { color: var(--border); }

.sitefooter { text-align: center; color: var(--muted); font-size: .8rem; padding: 1rem; }

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
    .editform label { flex: 1 1 100%; }
    .row-actions { flex-wrap: wrap; }
}
