/* ---------------------------------------------------------------------------
   Mis Gastos - hoja de estilos unica.
   Pensada primero para el telefono; en pantallas grandes se ensancha.
   --------------------------------------------------------------------------- */

:root {
    --brand:        #0f766e;
    --brand-dark:   #115e59;
    --brand-soft:   #ccfbf1;
    --ink:          #14202b;
    --ink-soft:     #5b6b7a;
    --line:         #e2e8f0;
    --bg:           #f4f6f8;
    --card:         #ffffff;
    --ok:           #166534;
    --ok-bg:        #dcfce7;
    --err:          #9f1239;
    --err-bg:       #ffe4e6;
    --warn:         #92400e;
    --warn-bg:      #fef3c7;
    --usd:          #1d4ed8;
    --radius:       14px;
    --shadow:       0 1px 2px rgba(16, 32, 48, .06), 0 8px 24px rgba(16, 32, 48, .06);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--brand-dark); }

h1 { font-size: 1.4rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }

/* --- Barra superior y menu ------------------------------------------------ */

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--brand);
    color: #fff;
    box-shadow: 0 2px 10px rgba(15, 118, 110, .25);
    padding-top: env(safe-area-inset-top);
}

.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    max-width: 1100px;
    margin: 0 auto;
    padding: .7rem 1rem;
}

.brand {
    color: #fff;
    font-weight: 700;
    text-decoration: none;
    font-size: 1.05rem;
}

.topbar-user {
    display: flex;
    align-items: center;
    gap: .75rem;
    font-size: .9rem;
    color: #d3f5f0;
}

.btn-link {
    color: #fff;
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, .5);
    border-radius: 999px;
    padding: .3rem .8rem;
    font-size: .85rem;
}
.btn-link:hover { background: rgba(255, 255, 255, .15); }

.mainnav {
    display: flex;
    gap: .25rem;
    overflow-x: auto;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 .5rem .5rem;
    scrollbar-width: none;
}
.mainnav::-webkit-scrollbar { display: none; }

.mainnav a {
    color: #d3f5f0;
    text-decoration: none;
    white-space: nowrap;
    padding: .5rem .8rem;
    border-radius: 999px;
    font-size: .92rem;
}
.mainnav a:hover  { background: rgba(255, 255, 255, .12); color: #fff; }
.mainnav a.active { background: #fff; color: var(--brand-dark); font-weight: 600; }

/* --- Contenedor ----------------------------------------------------------- */

.page {
    max-width: 1100px;
    margin: 0 auto;
    padding: 1rem 1rem 3rem;
}

.pagefoot {
    text-align: center;
    color: var(--ink-soft);
    font-size: .8rem;
    padding: 0 1rem 2rem;
}

.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 1rem;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
    flex-wrap: wrap;
    margin-bottom: .75rem;
}
.card-head h2 { margin: 0; }

.muted     { color: var(--ink-soft); }
.small     { font-size: .85rem; }
.nowrap    { white-space: nowrap; }
.right     { text-align: right; }
.empty     { color: var(--ink-soft); text-align: center; padding: 1.5rem .5rem; }

/* --- Mensajes ------------------------------------------------------------- */

.flash {
    border-radius: var(--radius);
    padding: .8rem 1rem;
    margin-bottom: 1rem;
    font-weight: 500;
}
.flash-ok    { background: var(--ok-bg);   color: var(--ok); }
.flash-error { background: var(--err-bg);  color: var(--err); }
.flash-warn  { background: var(--warn-bg); color: var(--warn); }

.errors {
    background: var(--err-bg);
    color: var(--err);
    border-radius: var(--radius);
    padding: .8rem 1rem .8rem 2rem;
    margin-bottom: 1rem;
}
.errors li { margin: .15rem 0; }

/* --- Botones -------------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    background: var(--brand);
    color: #fff;
    border: 0;
    border-radius: 999px;
    padding: .7rem 1.1rem;
    font-size: 1rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    min-height: 44px;
}
.btn:hover    { background: var(--brand-dark); }
.btn-block    { width: 100%; }
.btn-ghost    { background: #fff; color: var(--brand-dark); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--brand-soft); }
.btn-danger   { background: #be123c; }
.btn-danger:hover { background: #9f1239; }
.btn-sm       { padding: .35rem .75rem; font-size: .85rem; min-height: 36px; }

.actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* --- Formularios ---------------------------------------------------------- */

.field { margin-bottom: 1rem; }

.field label,
.field > .label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    color: var(--ink-soft);
    margin-bottom: .3rem;
}

input[type=text],
input[type=password],
input[type=date],
input[type=number],
input[type=search],
select,
textarea {
    width: 100%;
    padding: .7rem .8rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    color: var(--ink);
    font-size: 1rem;
    font-family: inherit;
    min-height: 46px;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--brand);
    outline-offset: 1px;
    border-color: var(--brand);
}
textarea { min-height: 80px; resize: vertical; }

input[type=file] {
    width: 100%;
    padding: .6rem;
    border: 1px dashed var(--line);
    border-radius: 10px;
    background: #fff;
    font-size: .9rem;
}

.hint { font-size: .8rem; color: var(--ink-soft); margin-top: .25rem; }

.field-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0 1rem;
}

.check {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .95rem;
}
.check input { width: 20px; height: 20px; min-height: 0; }

/* --- Filtros -------------------------------------------------------------- */

/* En el telefono, un filtro por linea: los campos de fecha tienen un ancho
   minimo propio (unos 170 px) y en dos columnas se saldrian de la tarjeta. */
.filters {
    display: grid;
    grid-template-columns: 1fr;
    gap: .5rem .75rem;
    align-items: end;
}
.filters .field { margin-bottom: .25rem; min-width: 0; }
.filters input, .filters select { min-width: 0; }
.filters .filters-actions { grid-column: 1 / -1; display: flex; gap: .5rem; }

.quick-range {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
    margin-bottom: .75rem;
}
.quick-range a {
    font-size: .82rem;
    text-decoration: none;
    color: var(--brand-dark);
    background: var(--brand-soft);
    border-radius: 999px;
    padding: .35rem .75rem;
}
.quick-range a.active { background: var(--brand); color: #fff; }

/* --- Totales -------------------------------------------------------------- */

.totals {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .75rem;
}

.total-box {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: .9rem 1rem;
}
.total-box .label { font-size: .78rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: .03em; }
.total-box .value { font-size: 1.35rem; font-weight: 700; margin-top: .2rem; }
.total-box.bs  .value { color: var(--brand-dark); }
.total-box.usd .value { color: var(--usd); }

/* --- Tablas (en el telefono se ven como tarjetas) ------------------------- */

.table-wrap { overflow-x: auto; }

table.data {
    width: 100%;
    border-collapse: collapse;
    font-size: .93rem;
}
table.data th {
    text-align: left;
    font-size: .78rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--ink-soft);
    border-bottom: 1px solid var(--line);
    padding: .5rem .6rem;
    white-space: nowrap;
}
table.data td {
    padding: .6rem;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tfoot td {
    font-weight: 700;
    border-top: 2px solid var(--line);
    background: #fbfdfe;
}

.thumb {
    display: block;
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #fff;
}

.pill {
    display: inline-block;
    background: var(--brand-soft);
    color: var(--brand-dark);
    border-radius: 999px;
    padding: .12rem .6rem;
    font-size: .8rem;
    white-space: nowrap;
}
.pill-off { background: var(--line); color: var(--ink-soft); }

/* --- Grafico de barras ---------------------------------------------------- */

.chart { display: grid; gap: .55rem; }

.chart-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: .15rem;
}
.chart-row .chart-label {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
    font-size: .85rem;
}
.chart-row .chart-label .amount { color: var(--ink-soft); white-space: nowrap; }
.chart-track {
    background: var(--line);
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}
.chart-fill {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--brand), #14b8a6);
}
.chart-fill.usd { background: linear-gradient(90deg, #1d4ed8, #3b82f6); }

.bar-cell { min-width: 90px; }
.bar-cell .chart-track { height: 8px; }

/* --- Login ---------------------------------------------------------------- */

.login-wrap {
    min-height: 82vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.login-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    width: 100%;
    max-width: 360px;
}
.login-card h1 { text-align: center; }
.login-logo { text-align: center; font-size: 2.5rem; margin-bottom: .25rem; }

/* --- Recibo a pantalla completa ------------------------------------------ */

.receipt-view {
    text-align: center;
}
.receipt-view img {
    max-width: 100%;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

/* --- Pantallas grandes ---------------------------------------------------- */

@media (min-width: 640px) {
    h1 { font-size: 1.7rem; }
    .card { padding: 1.25rem; }
    .field-row { grid-template-columns: 1fr 1fr; }
    .filters { grid-template-columns: repeat(4, 1fr); }
    .filters .filters-actions { grid-column: auto; }
    .totals { grid-template-columns: repeat(4, 1fr); }
    .form-narrow { max-width: 620px; }
}

/* En pantallas angostas cada fila de la tabla se convierte en una tarjeta. */
@media (max-width: 639px) {
    table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
    table.data thead { display: none; }
    table.data tbody tr {
        border: 1px solid var(--line);
        border-radius: 12px;
        padding: .35rem .1rem;
        margin-bottom: .6rem;
    }
    table.data td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        border: 0;
        padding: .35rem .75rem;
        text-align: right;
    }
    table.data td::before {
        content: attr(data-label);
        font-size: .78rem;
        text-transform: uppercase;
        letter-spacing: .03em;
        color: var(--ink-soft);
        text-align: left;
        flex: 0 0 auto;
    }
    table.data td:empty { display: none; }
    table.data tfoot { display: block; }
    table.data tfoot tr { border: 0; background: #fbfdfe; border-radius: 12px; }
    .hide-phone { display: none; }
}
