/* =====================================================
   GastosPersonales — Tema oscuro minimalista
   ===================================================== */

:root {
    --bg:          #0e1013;
    --surface:     #16191e;
    --surface-2:   #1d2126;
    --border:      #23272e;
    --border-soft: #1b1f25;
    --border-mid:  #3a4048;

    --text:        #e6e8eb;
    --text-dim:    #8b929c;
    --text-faint:  #5f666f;

    --accent:      #4ade80;
    --accent-dim:  #22c55e;
    --danger:      #f87171;
    --warning:     #fbbf24;
    --info:        #60a5fa;
    --purple:      #a78bfa;

    --radius:      8px;
}

/* ── Base ─────────────────────────────────────────── */

html, body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
}

body { min-height: 100vh; }

.num {
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.2px;
}

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

::selection { background: var(--accent); color: var(--bg); }

/* ── Scrollbar ────────────────────────────────────── */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb {
    background: var(--surface-2);
    border-radius: 5px;
    border: 2px solid var(--bg);
}
::-webkit-scrollbar-thumb:hover { background: var(--border-mid); }

/* ── Layout ───────────────────────────────────────── */

.app-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    height: 56px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);
    position: sticky;
    top: 0;
    z-index: 100;
}

.app-nav-brand {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    margin-right: 28px;
    white-space: nowrap;
}

.app-nav-links { display: flex; align-items: center; gap: 22px; }

.app-nav-links a {
    font-size: 13px;
    color: var(--text-dim);
    padding: 4px 0;
    border-bottom: 1.5px solid transparent;
    transition: color .12s;
    white-space: nowrap;
}
.app-nav-links a:hover { color: var(--text); }
.app-nav-links a.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}

.app-main {
    max-width: 1180px;
    margin: 0 auto;
    padding: 0 28px 64px;
}

/* ── Secciones ────────────────────────────────────── */

.section-label {
    font-size: 12px;
    color: var(--text-faint);
    letter-spacing: .4px;
    margin-bottom: 10px;
}

.hero-value {
    font-size: 44px;
    font-weight: 500;
    letter-spacing: -1.2px;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.divider {
    border: 0;
    border-top: 1px solid var(--border);
    margin: 0;
}

/* ── Métricas ─────────────────────────────────────── */

.metric-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.metric {
    padding: 18px 24px;
    border-right: 1px solid var(--border);
}
.metric:last-child { border-right: 0; }

.metric-label {
    font-size: 12px;
    color: var(--text-faint);
    margin-bottom: 6px;
}

.metric-value {
    font-size: 21px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    letter-spacing: -.4px;
}

.metric-value.editable {
    background: none;
    border: 0;
    border-bottom: 1px dashed var(--border-mid);
    color: var(--text);
    padding: 0;
    width: 100%;
    font: inherit;
    font-variant-numeric: tabular-nums;
}
.metric-value.editable:focus {
    outline: none;
    border-bottom-color: var(--accent);
}

.t-accent  { color: var(--accent); }
.t-danger  { color: var(--danger); }
.t-warning { color: var(--warning); }
.t-info    { color: var(--info); }
.t-dim     { color: var(--text-dim); }
.t-faint   { color: var(--text-faint); }

/* ── Barra de progreso ────────────────────────────── */

.bar {
    height: 5px;
    background: var(--surface-2);
    border-radius: 3px;
    overflow: hidden;
    display: flex;
}
.bar > span { display: block; height: 100%; }
.bar-accent  { background: var(--accent); }
.bar-info    { background: var(--info); }
.bar-warning { background: var(--warning); }

/* ── Lista de items ───────────────────────────────── */

.item-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 11px 0;
    border-bottom: 1px solid var(--border-soft);
}
.item-row:last-child { border-bottom: 0; }
.item-row:hover { background: rgba(255,255,255,.018); }

.item-row.is-paid .item-name { text-decoration: line-through; }
.item-row.is-paid { opacity: .45; }

.item-check {
    width: 20px; height: 20px;
    border-radius: 50%;
    border: 1.5px solid var(--border-mid);
    background: none;
    flex-shrink: 0;
    padding: 0;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: border-color .12s, background .12s;
}
.item-check:hover { border-color: var(--accent); }
.item-check.checked {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
    font-size: 11px;
}

.item-body { flex: 1; min-width: 0; }
.item-name { font-size: 14px; color: var(--text); }
.item-meta {
    font-size: 11px;
    color: var(--text-faint);
    margin-top: 2px;
}

.item-amount {
    font-size: 15px;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

.item-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity .12s;
}
.item-row:hover .item-actions { opacity: 1; }

/* ── Botones ──────────────────────────────────────── */

.btn-flat {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-dim);
    font-size: 12px;
    padding: 5px 11px;
    border-radius: 6px;
    cursor: pointer;
    white-space: nowrap;
    transition: all .12s;
}
.btn-flat:hover {
    color: var(--text);
    border-color: var(--border-mid);
}
.btn-flat.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--bg);
    font-weight: 500;
}
.btn-flat.primary:hover { background: var(--accent-dim); border-color: var(--accent-dim); }
.btn-flat.danger { color: var(--danger); border-color: transparent; }
.btn-flat.danger:hover { border-color: var(--danger); }
.btn-flat:disabled { opacity: .4; cursor: default; }

.btn-icon {
    background: none;
    border: 0;
    color: var(--text-faint);
    font-size: 12px;
    padding: 4px 6px;
    border-radius: 4px;
    cursor: pointer;
}
.btn-icon:hover { color: var(--text); background: var(--surface-2); }
.btn-icon.danger:hover { color: var(--danger); }

/* ── Controles de formulario ──────────────────────── */

.inp, .sel {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 6px;
    font-family: inherit;
}
.inp:focus, .sel:focus {
    outline: none;
    border-color: var(--border-mid);
}
.inp::placeholder { color: var(--text-faint); }
.sel { cursor: pointer; }
.sel option { background: var(--surface); color: var(--text); }

.inp-amount {
    text-align: right;
    font-variant-numeric: tabular-nums;
    width: 120px;
}

textarea.inp {
    font-family: 'Consolas', 'Courier New', monospace;
    font-size: 12.5px;
    line-height: 1.6;
    resize: vertical;
}

/* ── Filtros ──────────────────────────────────────── */

.filter-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    padding: 14px 0;
}

.seg {
    display: inline-flex;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow: hidden;
}
.seg button {
    background: none;
    border: 0;
    color: var(--text-dim);
    font-size: 12px;
    padding: 5px 12px;
    cursor: pointer;
    white-space: nowrap;
}
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--surface-2); color: var(--text); }

/* ── Tablas ───────────────────────────────────────── */

.tbl {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
.tbl th {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-faint);
    letter-spacing: .3px;
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.tbl td {
    padding: 9px 12px;
    border-bottom: 1px solid var(--border-soft);
    color: var(--text);
}
.tbl tbody tr:hover td { background: rgba(255,255,255,.018); }
.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
.tbl tfoot td {
    border-top: 1px solid var(--border);
    border-bottom: 0;
    font-weight: 500;
    color: var(--text);
}

.tbl-sticky thead th {
    position: sticky;
    top: 56px;
    background: var(--bg);
    z-index: 10;
}

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

/* ── Chips de estado ──────────────────────────────── */

.chip {
    display: inline-block;
    font-size: 11px;
    padding: 2px 7px;
    border-radius: 4px;
    background: var(--surface-2);
    color: var(--text-dim);
    white-space: nowrap;
}
.chip.accent  { color: var(--accent); }
.chip.info    { color: var(--info); }
.chip.warning { color: var(--warning); }
.chip.danger  { color: var(--danger); }
.chip.purple  { color: var(--purple); }

/* ── Avisos ───────────────────────────────────────── */

.notice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 13px;
    margin: 14px 0;
    border: 1px solid var(--border);
    background: var(--surface);
}
.notice.ok    { border-color: rgba(74,222,128,.3);  color: var(--accent); }
.notice.err   { border-color: rgba(248,113,113,.3); color: var(--danger); }
.notice.warn  { border-color: rgba(251,191,36,.3);  color: var(--warning); }

/* ── Panel plegable ───────────────────────────────── */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin: 14px 0;
}

/* ── Estado vacío ─────────────────────────────────── */

.empty {
    text-align: center;
    padding: 72px 24px;
    color: var(--text-faint);
}
.empty-title {
    font-size: 16px;
    color: var(--text);
    margin-bottom: 6px;
}
.empty-sub { font-size: 13px; margin-bottom: 20px; }

/* ── Spinner ──────────────────────────────────────── */

.spin {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid var(--border-mid);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .6s linear infinite;
}
.spin-lg { width: 26px; height: 26px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.loading { text-align: center; padding: 64px 0; }

/* ── Utilidades ───────────────────────────────────── */

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.row-gap { display: flex; align-items: center; gap: 8px; }
.grid-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}
.lbl {
    display: block;
    font-size: 11px;
    color: var(--text-faint);
    margin-bottom: 4px;
}
.pt-4 { padding-top: 28px; }
.pb-3 { padding-bottom: 18px; }
.mt-3 { margin-top: 18px; }
.mb-2 { margin-bottom: 12px; }

/* ── Responsive ───────────────────────────────────── */

@media (max-width: 820px) {
    .app-nav { padding: 0 16px; height: auto; flex-wrap: wrap; gap: 10px; padding-top: 10px; padding-bottom: 10px; }
    .app-nav-links { gap: 16px; overflow-x: auto; }
    .app-main { padding: 0 16px 48px; }
    .hero-value { font-size: 34px; }
    .metric { padding: 14px 16px; }
    .metric-value { font-size: 18px; }
    .tbl-sticky thead th { position: static; }
}

/* ── Vencimientos ─────────────────────────────────── */

.mes-titulo {
    font-size: 20px;
    font-weight: 500;
    letter-spacing: -.3px;
    min-width: 170px;
    text-align: center;
}

.metric-sub {
    font-size: 12px;
    color: var(--text-dim);
    margin-top: 4px;
    font-variant-numeric: tabular-nums;
}

.venc-fecha {
    width: 38px;
    flex-shrink: 0;
    text-align: center;
    line-height: 1.1;
}
.venc-dia {
    font-size: 17px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}
.venc-dow {
    font-size: 10px;
    color: var(--text-faint);
    text-transform: uppercase;
    letter-spacing: .4px;
}

.venc-row { padding-left: 10px; border-left: 3px solid transparent; }
.venc-vencido  { border-left-color: var(--danger); }
.venc-vencido  .venc-estado, .venc-vencido .venc-dia { color: var(--danger); }
.venc-proximo  { border-left-color: var(--warning); }
.venc-proximo  .venc-estado, .venc-proximo .venc-dia { color: var(--warning); }
.item-row.venc-pagado .item-name { text-decoration: none; }
.item-row.venc-pagado { opacity: .6; }

.venc-acciones {
    width: 76px;
    display: flex;
    justify-content: flex-end;
    flex-shrink: 0;
}

.venc-vacio { font-size: 13px; padding: 10px 0 10px 13px; }

.pago-panel { margin: 4px 0 12px 13px; }

.auto-head {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    background: none;
    border: 0;
    border-top: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    color: var(--text-dim);
    font: inherit;
    font-size: 13px;
    padding: 12px 10px;
    cursor: pointer;
    text-align: left;
}
.auto-head:hover { color: var(--text); background: rgba(255,255,255,.018); }

.proximo {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    color: inherit;
    font: inherit;
    text-align: left;
    cursor: pointer;
    margin-top: 28px;
}
.proximo:hover { border-color: var(--border-mid); }

@media (max-width: 820px) {
    .mes-titulo { min-width: 0; font-size: 17px; }
    .venc-acciones { width: auto; }
}

/* ── Grupos ───────────────────────────────────────── */

.grupo-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 22px 10px 8px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
}
.grupo-head .btn-icon { opacity: .5; }
.grupo-head:hover .btn-icon { opacity: 1; }
.grupo-dot {
    width: 10px; height: 10px;
    border-radius: 3px;
    flex-shrink: 0;
}
.grupo-nombre { font-weight: 500; color: var(--text); font-size: 14px; }
.grupo-tag { font-size: 11px; }
.grupo-row { padding-left: 10px; }

/* ── Datos de referencia (copiables) ──────────────── */

.datos {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 6px;
}
.dato {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 2px 8px;
    font: inherit;
    font-size: 11.5px;
    color: var(--text);
    cursor: pointer;
}
.dato:hover { border-color: var(--border-mid); }
.dato .dato-clave { color: var(--text-faint); }
.dato .dato-valor { font-variant-numeric: tabular-nums; }
.dato i { font-size: 10px; color: var(--text-faint); }
.dato.copiado { border-color: rgba(74,222,128,.4); }
.dato.copiado i { color: var(--accent); }

textarea.inp.datos-inp {
    font-family: inherit;
    font-size: 13px;
    line-height: 1.5;
}

/* ── Meses en que se paga ─────────────────────────── */

.meses {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
}
.mes-chip {
    min-width: 44px;
    padding: 5px 0;
    border-radius: 5px;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    border: 1px solid var(--border);
    background: none;
    color: var(--text-faint);
}
.mes-chip.on  { background: rgba(74,222,128,.12); border-color: rgba(74,222,128,.35); color: var(--accent); }
.mes-chip.off { text-decoration: line-through; color: var(--danger); border-color: rgba(248,113,113,.3); }
.mes-chip.na  { opacity: .35; cursor: default; }
.mes-chip:not(.na):hover { border-color: var(--border-mid); }

/* ── Edición en línea ─────────────────────────────── */

.item-row.editando { background: var(--surface); border-left: 3px solid var(--accent); }
.form-edicion {
    margin: 2px 0 14px 10px;
    border-color: var(--border-mid);
}

/* ── Apertura por medio de pago ───────────────────── */

.t-purple { color: var(--purple); }

.apertura {
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px dashed var(--border);
    display: grid;
    gap: 3px;
}
.apertura-fila {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    font-size: 12px;
    color: var(--text-dim);
}
.apertura-fila .num { font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ── Login ────────────────────────────────────────── */

.login-wrap {
    min-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 0;
}
.login-card {
    width: 100%;
    max-width: 360px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    display: flex;
    flex-direction: column;
}
.login-card .inp { width: 100%; font-size: 15px; padding: 9px 12px; }
.login-card h1 { font-size: 18px; font-weight: 500; margin: 0 0 6px; }
.login-sub { font-size: 13px; color: var(--text-dim); margin: 6px 0 18px; line-height: 1.5; }
.login-btn { margin-top: 20px; padding: 9px; font-size: 14px; justify-content: center; }
.login-card .notice { margin: 0 0 14px; }

/* ── Cartel de reconexión ─────────────────────────── */

.reconnect-modal { display: none; }
#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected {
    display: flex !important;
    position: fixed; inset: 0; z-index: 3000;
    align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .6);
    backdrop-filter: blur(3px);
}
.reconnect-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 32px;
    text-align: center;
    max-width: 340px;
    box-shadow: 0 16px 50px rgba(0, 0, 0, .45);
}
.reconnect-spinner {
    width: 32px; height: 32px; margin: 0 auto 14px;
    border: 3px solid var(--border-mid);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
.reconnect-title { font-size: 15px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.reconnect-text  { font-size: 13px; color: var(--text-dim); margin-bottom: 18px; }
#components-reconnect-modal.components-reconnect-failed .reconnect-spinner,
#components-reconnect-modal.components-reconnect-rejected .reconnect-spinner { display: none; }
#components-reconnect-modal.components-reconnect-failed .reconnect-title::after,
#components-reconnect-modal.components-reconnect-rejected .reconnect-title::after { content: " sin éxito"; }
