:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --ink: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --income: #087f5b;
  --expense: #d9480f;
  --radius: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.empty { color: var(--muted); text-align: center; padding: 24px; }

/* Login */
#login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #0f766e 0%, #134e4a 100%);
}
.login-card {
  background: var(--card); border-radius: 20px; padding: 48px 56px; text-align: center;
  box-shadow: 0 24px 60px rgba(0,0,0,0.25);
}
.login-card h1 { margin: 16px 0 4px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }

/* Header */
header {
  display: flex; align-items: center; gap: 24px;
  background: var(--card); border-bottom: 1px solid var(--line);
  padding: 10px 24px; position: sticky; top: 0; z-index: 20;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; }
nav { display: flex; gap: 4px; flex: 1; }
.nav-btn {
  border: none; background: transparent; padding: 8px 14px; border-radius: 8px;
  cursor: pointer; font-size: 14px; color: var(--muted); font-weight: 500;
}
.nav-btn:hover { background: var(--bg); }
.nav-btn.active { background: #e6f2f1; color: var(--primary-dark); }
.user-area { display: flex; align-items: center; gap: 12px; }
#user-name { font-size: 13px; color: var(--muted); }

/* Banner pendientes */
.banner {
  background: #fff7ed; border-bottom: 1px solid #fed7aa; color: #9a3412;
  padding: 10px 24px; display: flex; align-items: center; gap: 16px; font-size: 14px;
}

/* Botones */
.btn {
  border: none; border-radius: 9px; padding: 8px 16px; cursor: pointer;
  font-size: 14px; font-weight: 600; display: inline-block; text-decoration: none;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--muted); border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--bg); }
.btn-small { padding: 4px 12px; font-size: 13px; background: #9a3412; color: white; }
.btn-lg { padding: 12px 28px; font-size: 16px; }
.link-btn {
  border: none; background: none; color: var(--primary); cursor: pointer;
  font-size: 12px; text-decoration: underline; padding: 0;
}
.icon-btn {
  border: none; background: transparent; cursor: pointer; color: var(--muted);
  font-size: 15px; padding: 2px 8px; border-radius: 6px;
}
.icon-btn:hover { background: var(--bg); color: var(--expense); }

/* Layout */
.view { padding: 24px; max-width: 1200px; margin: 0 auto; }
.toolbar { display: flex; gap: 12px; margin-bottom: 20px; align-items: center; flex-wrap: wrap; }
.toolbar select, .toolbar input[type="search"] {
  padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--card); font-size: 14px;
}
.toolbar input[type="search"] { min-width: 240px; }
.check { display: flex; align-items: center; gap: 6px; font-size: 14px; color: var(--muted); cursor: pointer; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 20px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border-radius: var(--radius); padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.card h3 { margin: 0 0 14px; font-size: 15px; color: var(--ink); }

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat-label { font-size: 13px; color: var(--muted); }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-value.income { color: var(--income); }
.stat-value.expense { color: var(--expense); }
.stat-sub { font-size: 13px; color: var(--muted); }

.goal-bar { height: 10px; background: var(--line); border-radius: 6px; overflow: hidden; margin-top: 6px; }
#goal-fill { height: 100%; background: var(--primary); border-radius: 6px; width: 0; transition: width .4s; }

/* Tablas */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid #f1f3f5; vertical-align: middle; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: #fafbfc; }
.amount-pos { color: var(--income); font-weight: 600; }
.amount-neg { color: var(--ink); font-weight: 600; }

.cat-chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px;
  border-radius: 999px; font-size: 12px; font-weight: 600; cursor: pointer;
  background: var(--bg); border: 1px solid var(--line);
}
.cat-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.cat-chip.pending { background: #fff7ed; border-color: #fed7aa; color: #9a3412; }

.top-list { list-style: none; margin: 0; padding: 0; }
.top-list li { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid #f1f3f5; font-size: 14px; }
.top-list .desc { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-list .amt { font-weight: 700; color: var(--expense); white-space: nowrap; }

#month-compare .cmp-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; border-bottom: 1px solid #f1f3f5; }
.delta-up { color: var(--expense); font-weight: 600; }
.delta-down { color: var(--income); font-weight: 600; }

/* Importar */
.import-zone { text-align: center; padding: 48px 24px; border: 2px dashed var(--line); }
.import-zone.dragover { border-color: var(--primary); background: #e6f2f1; }
.table-scroll { overflow-x: auto; max-height: 320px; overflow-y: auto; margin: 12px 0; border: 1px solid var(--line); border-radius: 8px; }
.mapping-row { display: flex; gap: 12px; flex-wrap: wrap; margin: 12px 0; align-items: center; }
.mapping-row label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.mapping-row select, .mapping-row input[type="text"] {
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px;
}
.actions { display: flex; gap: 10px; margin-top: 16px; }

/* Modales */
.modal-bg {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: var(--card); border-radius: 16px; padding: 28px; width: 420px; max-width: 92vw;
  box-shadow: 0 24px 60px rgba(0,0,0,0.3);
}
.modal h3 { margin: 0 0 16px; }
.modal label { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.modal label.check { flex-direction: row; align-items: center; }
.modal input, .modal select {
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; color: var(--ink);
}

/* Toast */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: white; padding: 12px 22px; border-radius: 10px;
  font-size: 14px; z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}

canvas { max-height: 300px; }

/* Presupuesto y previsión */
.budget-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.budget-head h3 { margin: 0; }
#budget-table td, #budget-proj-table td, #budget-proj-table th { vertical-align: middle; }
.budget-base-input { width: 110px; padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; text-align: right; color: var(--ink); }
.season-link { background: none; border: none; color: var(--primary); cursor: pointer; font-size: 13px; font-family: inherit; padding: 0; text-decoration: underline; }
.season-badge { font-size: 11px; background: #eef6f4; color: var(--primary-dark); border-radius: 999px; padding: 2px 9px; }
.mini-suggest { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 12px; font-family: inherit; text-decoration: underline; }
.bud-row { padding: 9px 0; border-bottom: 1px solid var(--line); }
.bud-row:last-child { border-bottom: none; }
.bud-row-top { display: flex; justify-content: space-between; font-size: 14px; margin-bottom: 5px; }
.bud-bar { height: 9px; background: var(--line); border-radius: 6px; overflow: hidden; }
.bud-fill { height: 100%; border-radius: 6px; transition: width .4s; }
.bud-fill.ok { background: var(--primary); }
.bud-fill.over { background: var(--expense); }
.bud-fill.inc { background: var(--income); }
.modal-wide { width: 560px; }
.season-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; margin: 6px 0 16px; }
.season-grid label { font-size: 11px; color: var(--muted); gap: 3px; margin-bottom: 0; }
.season-grid input { width: 100%; padding: 6px; text-align: center; border: 1px solid var(--line); border-radius: 7px; font-size: 13px; }
.proj-savings-pos { color: var(--income); font-weight: 600; }
.proj-savings-neg { color: var(--expense); font-weight: 600; }
#budget-proj-table th, #budget-proj-table td { padding: 5px 8px; font-size: 13px; text-align: right; }
#budget-proj-table th:first-child, #budget-proj-table td:first-child { text-align: left; }
.save-target { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); margin: 0; }
.save-target input { width: 60px; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; text-align: right; font-size: 14px; color: var(--ink); }
.target-ok { color: var(--income); font-weight: 600; }
.target-bad { color: var(--expense); font-weight: 600; }

/* Login con Google */
#gbtn { display: flex; justify-content: center; min-height: 44px; }
.login-err { color: var(--expense); font-size: 13px; min-height: 18px; margin: 12px 0 0 !important; }

/* Hogares (workspaces) */
.ws-area { display: flex; align-items: center; gap: 8px; }
#ws-select {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: var(--card);
  font-size: 14px; font-weight: 600; color: var(--ink); max-width: 200px;
}
.ro-badge { font-size: 11px; background: #fff7ed; color: #9a3412; border: 1px solid #fed7aa; border-radius: 999px; padding: 2px 9px; white-space: nowrap; }
body.readonly .edit-only { display: none !important; }
body:not(.owner) .owner-only { display: none !important; }
body.owner .not-owner { display: none !important; }
.share-h { margin: 14px 0 6px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.member-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #f1f3f5; font-size: 14px; }
.member-row:last-child { border-bottom: none; }
.member-row img { width: 28px; height: 28px; border-radius: 50%; }
.member-row .avatar-fallback { width: 28px; height: 28px; border-radius: 50%; background: #e6f2f1; color: var(--primary-dark); display: inline-flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; }
.member-row .who { flex: 1; min-width: 0; }
.member-row .who .email { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-row select { padding: 5px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; }
.role-pill { font-size: 11px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 2px 9px; color: var(--muted); }
.role-pill.owner { background: #e6f2f1; color: var(--primary-dark); border-color: #cfe7e3; }
.btn.danger { color: var(--expense); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.modal input[type="email"] { padding: 9px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; }

/* Flexibilidad (presupuesto) */
.flex-select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; color: var(--ink); background: var(--card); }

/* Llegar a fin de mes */
.fit-form { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 8px 0 16px; }
.fit-form select { padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 14px; background: var(--card); }
.fit-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 14px; }
.fit-summary .stat { background: var(--bg); border-radius: 10px; padding: 12px 14px; }
.fit-summary .stat-value { font-size: 20px; }
.fit-verdict { padding: 12px 14px; border-radius: 10px; margin-bottom: 14px; font-size: 14px; }
.fit-verdict.ok { background: #ecfdf5; color: #065f46; }
.fit-verdict.warn { background: #fff7ed; color: #9a3412; }
.fit-verdict.bad { background: #fef2f2; color: #991b1b; }
#fit-table th, #fit-table td { padding: 6px 8px; font-size: 13px; }
#fit-table td.num { font-variant-numeric: tabular-nums; }
.cut-bar { height: 6px; background: var(--line); border-radius: 4px; overflow: hidden; width: 90px; display: inline-block; vertical-align: middle; margin-left: 6px; }
.cut-bar > div { height: 100%; background: var(--expense); }
.flex-tag { font-size: 11px; border-radius: 999px; padding: 1px 8px; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }

@media (max-width: 900px) {
  header { gap: 12px; }
  nav { order: 3; width: 100%; overflow-x: auto; }
}
