/* =========================================================================
   Mi Control Financiero del Hogar — Design System
   ========================================================================= */
:root {
  /* Brand */
  --brand: #6d28d9;
  --brand-2: #8b5cf6;
  --brand-soft: #ede9fe;
  --brand-grad: linear-gradient(135deg, #7c3aed 0%, #6d28d9 45%, #4f46e5 100%);

  /* Semantic */
  --income: #16a34a;
  --income-soft: #dcfce7;
  --expense: #dc2626;
  --expense-soft: #fee2e2;
  --saving: #2563eb;
  --saving-soft: #dbeafe;
  --balance: #7c3aed;
  --warn: #d97706;
  --warn-soft: #fef3c7;

  /* Neutrals (light) */
  --bg: #f4f5fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6e8f0;
  --text: #1e2233;
  --text-2: #5b6178;
  --text-3: #949bb3;
  --shadow-sm: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.05);
  --shadow: 0 4px 14px rgba(16,24,40,.08);
  --shadow-lg: 0 18px 45px rgba(16,24,40,.16);

  --radius: 16px;
  --radius-sm: 10px;
  --radius-lg: 22px;
  --sidebar-w: 250px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0e1017;
  --surface: #171a25;
  --surface-2: #1e2230;
  --border: #2a2f42;
  --text: #eef1f8;
  --text-2: #a9b0c6;
  --text-3: #6b7288;
  --brand-soft: #2a2148;
  --income-soft: #10281a;
  --expense-soft: #2c1416;
  --saving-soft: #101f38;
  --warn-soft: #2c2210;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.4);
  --shadow: 0 6px 20px rgba(0,0,0,.5);
  --shadow-lg: 0 20px 50px rgba(0,0,0,.6);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
/* 16px evita el zoom automático de iOS al enfocar un campo */
input, select, textarea { font-family: inherit; font-size: 16px; }
a { color: inherit; text-decoration: none; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ============================ Layout ============================ */
.app { display: flex; height: 100vh; height: 100dvh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 40;
  transition: transform .25s ease;
}
.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 20px 20px 16px;
}
.brand .logo {
  width: 40px; height: 40px; border-radius: 12px;
  background: var(--brand-grad);
  display: grid; place-items: center;
  color: #fff; font-size: 20px; flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(124,58,237,.4);
}
.brand h1 { font-size: 15px; font-weight: 800; letter-spacing: -.2px; line-height: 1.15; }
.brand span { font-size: 11.5px; color: var(--text-3); font-weight: 600; }

.nav { flex: 1; overflow-y: auto; padding: 8px 12px; }
.nav-group-label {
  font-size: 10.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-3);
  padding: 14px 12px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 11px;
  color: var(--text-2); font-weight: 600; font-size: 14px;
  width: 100%; text-align: left; transition: background .15s, color .15s;
  position: relative;
}
.nav-item .ic { width: 20px; text-align: center; font-size: 16px; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); }
[data-theme="dark"] .nav-item.active { color: var(--brand-2); }
.nav-item.active::before {
  content: ""; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
  width: 4px; height: 22px; background: var(--brand); border-radius: 0 4px 4px 0;
}
.nav-badge {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--expense); color:#fff; border-radius: 20px; padding: 1px 7px;
}
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border); }

/* ============================ Main ============================ */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 64px; flex-shrink: 0;
  display: flex; align-items: center; gap: 14px;
  padding: 0 24px; background: var(--surface);
  border-bottom: 1px solid var(--border); z-index: 30;
}
.topbar h2 { font-size: 19px; font-weight: 800; letter-spacing: -.3px; }
.topbar .sub { font-size: 12.5px; color: var(--text-3); font-weight: 500; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.hamburger { display: none; font-size: 22px; padding: 6px; border-radius: 8px; }
.hamburger:hover { background: var(--surface-2); }

.icon-btn {
  width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center; font-size: 17px;
  color: var(--text-2); border: 1px solid var(--border); background: var(--surface);
  transition: all .15s;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--text-3); }

.view { flex: 1; overflow-y: auto; padding: 24px; }
.view-inner { max-width: 1200px; margin: 0 auto; }

/* ============================ Buttons ============================ */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-radius: 11px; font-weight: 700; font-size: 14px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  transition: all .15s; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--text-3); }
.btn-primary {
  background: var(--brand-grad); color: #fff; border: none;
  box-shadow: 0 6px 16px rgba(124,58,237,.35);
}
.btn-primary:hover { filter: brightness(1.07); }
.btn-ghost { border: none; background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { color: var(--expense); }
.btn-danger:hover { background: var(--expense-soft); border-color: var(--expense); }
.btn-sm { padding: 6px 11px; font-size: 13px; border-radius: 9px; }
.btn-block { width: 100%; justify-content: center; }

/* ============================ Cards ============================ */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-pad { padding: 20px; }
.card-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-head h3 { font-size: 15px; font-weight: 800; letter-spacing: -.2px; }
.card-head .card-sub { font-size: 12px; color: var(--text-3); font-weight: 500; }
.card-head .head-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }

.grid { display: grid; gap: 18px; }
.g-kpi { grid-template-columns: repeat(4, 1fr); }
.g-2 { grid-template-columns: 1fr 1fr; }
.g-3 { grid-template-columns: repeat(3, 1fr); }
.g-dash { grid-template-columns: 1.5fr 1fr; align-items: start; }

/* KPI cards */
.kpi {
  position: relative; overflow: hidden;
  padding: 18px 20px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi .kpi-label { font-size: 12.5px; color: var(--text-2); font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.kpi .kpi-ic {
  width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; font-size: 18px;
}
.kpi .kpi-value { font-size: 27px; font-weight: 800; letter-spacing: -.6px; margin-top: 12px; }
.kpi .kpi-foot { font-size: 12px; color: var(--text-3); margin-top: 4px; font-weight: 600; }
.kpi.income .kpi-ic { background: var(--income-soft); color: var(--income); }
.kpi.expense .kpi-ic { background: var(--expense-soft); color: var(--expense); }
.kpi.saving .kpi-ic { background: var(--saving-soft); color: var(--saving); }
.kpi.balance .kpi-ic { background: var(--brand-soft); color: var(--brand); }
.kpi.income .kpi-value { color: var(--income); }
.kpi.expense .kpi-value { color: var(--expense); }
.kpi.saving .kpi-value { color: var(--saving); }
.kpi.balance .kpi-value { color: var(--balance); }
.trend { font-size: 12px; font-weight: 700; display: inline-flex; align-items: center; gap: 3px; }
.trend.up { color: var(--income); }
.trend.down { color: var(--expense); }
.trend.flat { color: var(--text-3); }

/* ============================ Tables ============================ */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 11.5px; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--text-3); padding: 11px 14px;
  border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface);
  position: sticky; top: 0; z-index: 1;
}
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--text); }
td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: middle; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }
.num { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.row-actions { display: flex; gap: 4px; justify-content: flex-end; opacity: 0; transition: opacity .12s; }
tr:hover .row-actions { opacity: 1; }
.mini-btn {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  color: var(--text-3); font-size: 14px;
}
.mini-btn:hover { background: var(--surface); color: var(--text); }
.mini-btn.del:hover { background: var(--expense-soft); color: var(--expense); }

/* Chips / badges */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 700;
}
.chip-dot { width: 8px; height: 8px; border-radius: 50%; }
.chip.t-Ingreso { background: var(--income-soft); color: var(--income); }
.chip.t-Gasto { background: var(--expense-soft); color: var(--expense); }
.chip.t-Ahorro { background: var(--saving-soft); color: var(--saving); }
.tag { display:inline-block; padding: 2px 9px; border-radius: 7px; font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--text-2); border:1px solid var(--border); }

/* Amount colors */
.amt-Ingreso { color: var(--income); }
.amt-Gasto { color: var(--expense); }
.amt-Ahorro { color: var(--saving); }

/* ============================ Forms ============================ */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12.5px; font-weight: 700; color: var(--text-2); }
.field .hint { font-size: 11.5px; color: var(--text-3); font-weight: 500; }
.control {
  width: 100%; padding: 11px 13px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
.control:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea.control { resize: vertical; min-height: 70px; }
select.control { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23949bb3' stroke-width='2.5'><polyline points='6 9 12 15 18 9'/></svg>"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-grid .full { grid-column: 1 / -1; }

.input-group { position: relative; }
.input-group .prefix {
  position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); font-weight: 700; pointer-events: none;
}
.input-group .control { padding-left: 28px; }

.search {
  position: relative; flex: 1; max-width: 320px;
}
.search input { width: 100%; padding: 9px 12px 9px 36px; border-radius: 11px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.search input:focus { outline: none; border-color: var(--brand-2); box-shadow: 0 0 0 3px var(--brand-soft); }
.search .s-ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-3); }

.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 3px; gap: 2px; }
.seg button { padding: 7px 13px; border-radius: 8px; font-size: 13px; font-weight: 700; color: var(--text-2); }
.seg button.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow-sm); }
[data-theme="dark"] .seg button.active { color: var(--brand-2); }

/* ============================ Progress ============================ */
.pbar { height: 9px; border-radius: 20px; background: var(--surface-2); overflow: hidden; border:1px solid var(--border); }
.pbar > span { display: block; height: 100%; border-radius: 20px; transition: width .5s ease; }
.pbar.income > span { background: var(--income); }
.pbar.expense > span { background: var(--expense); }
.pbar.saving > span { background: var(--saving); }
.pbar.brand > span { background: var(--brand-grad); }
.pbar.over > span { background: var(--expense); }

/* ============================ Modal ============================ */
.overlay {
  position: fixed; inset: 0; background: rgba(15,18,30,.55); backdrop-filter: blur(3px);
  display: none; align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.overlay.open { display: flex; animation: fade .18s ease; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px; max-height: 90vh; display: flex; flex-direction: column;
  animation: pop .2s cubic-bezier(.2,.8,.3,1.2); border: 1px solid var(--border);
}
.modal.narrow { max-width: 440px; }
.modal-head { display: flex; align-items: center; padding: 20px 22px 12px; }
.modal-head h3 { font-size: 18px; font-weight: 800; }
.modal-head .close { margin-left: auto; font-size: 20px; color: var(--text-3); width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; }
.modal-head .close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 8px 22px 4px; overflow-y: auto; }
.modal-foot { padding: 16px 22px 20px; display: flex; gap: 10px; justify-content: flex-end; }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.97); } }

/* ============================ Toast ============================ */
.toasts { position: fixed; bottom: 22px; right: 22px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast {
  display: flex; align-items: center; gap: 11px; padding: 13px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 13px;
  box-shadow: var(--shadow-lg); font-weight: 600; font-size: 14px; min-width: 240px;
  animation: slidein .25s ease;
}
.toast .t-ic { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: 14px; color: #fff; flex-shrink: 0; }
.toast.ok .t-ic { background: var(--income); }
.toast.err .t-ic { background: var(--expense); }
.toast.info .t-ic { background: var(--brand); }
@keyframes slidein { from { opacity: 0; transform: translateX(30px); } }

/* ============================ Misc ============================ */
.empty { text-align: center; padding: 48px 20px; color: var(--text-3); }
.empty .em-ic { font-size: 44px; margin-bottom: 12px; opacity: .5; }
.empty h4 { font-size: 16px; font-weight: 700; color: var(--text-2); margin-bottom: 4px; }
.legend { display: flex; flex-direction: column; gap: 10px; }
.legend-item { display: flex; align-items: center; gap: 10px; font-size: 13.5px; }
.legend-item .lg-dot { width: 11px; height: 11px; border-radius: 4px; flex-shrink: 0; }
.legend-item .lg-name { color: var(--text-2); font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-item .lg-val { font-weight: 800; font-variant-numeric: tabular-nums; }
.legend-item .lg-pct { color: var(--text-3); font-size: 12px; width: 42px; text-align: right; }

.donut-wrap { display: flex; align-items: center; gap: 24px; flex-wrap: wrap; }
.donut-center { text-align: center; }
.donut-center .dc-label { font-size: 11px; color: var(--text-3); text-transform: uppercase; font-weight: 700; letter-spacing: .05em; }
.donut-center .dc-val { font-size: 22px; font-weight: 800; }

.stat-line { display: flex; justify-content: space-between; align-items: center; padding: 9px 0; border-bottom: 1px dashed var(--border); font-size: 14px; }
.stat-line:last-child { border-bottom: none; }
.stat-line .sl-label { color: var(--text-2); font-weight: 600; }
.stat-line .sl-val { font-weight: 800; font-variant-numeric: tabular-nums; }

.section-title { font-size: 13px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); margin: 4px 0 12px; }
.pill-select { display:flex; gap:8px; align-items:center; }

.goal-card { padding: 18px; border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 12px; }
.goal-card .gc-top { display: flex; align-items: flex-start; gap: 12px; }
.goal-card .gc-ic { width: 42px; height: 42px; border-radius: 12px; background: var(--saving-soft); color: var(--saving); display: grid; place-items: center; font-size: 20px; flex-shrink: 0; }
.goal-card .gc-name { font-weight: 800; font-size: 15px; }
.goal-card .gc-meta { font-size: 12px; color: var(--text-3); font-weight: 600; }
.goal-card .gc-nums { display: flex; justify-content: space-between; font-size: 13px; }
.goal-card .gc-nums b { font-variant-numeric: tabular-nums; }
.pct-big { font-size: 15px; font-weight: 800; color: var(--saving); }

.mini-stat { display:flex; flex-direction:column; gap:2px; }
.mini-stat .ms-label { font-size: 11px; color: var(--text-3); font-weight:700; text-transform:uppercase; letter-spacing:.04em; }
.mini-stat .ms-val { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }

.hidden { display: none !important; }

/* ============================ Auth / Login ============================ */
.auth-screen {
  position: fixed; inset: 0; z-index: 300;
  display: flex; align-items: center; justify-content: center; padding: 20px;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(124,58,237,.35), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(79,70,229,.30), transparent 55%),
    var(--bg);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  padding: 34px 30px 28px; animation: pop .25s cubic-bezier(.2,.8,.3,1.2);
}
.auth-brand { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; margin-bottom: 22px; }
.auth-brand .logo {
  width: 60px; height: 60px; border-radius: 18px; background: var(--brand-grad);
  display: grid; place-items: center; color: #fff; font-size: 30px;
  box-shadow: 0 10px 26px rgba(124,58,237,.45);
}
.auth-brand h1 { font-size: 20px; font-weight: 800; letter-spacing: -.3px; }
.auth-brand p { font-size: 13px; color: var(--text-3); font-weight: 500; margin-top: -6px; }
.auth-card .field { margin-bottom: 14px; }
.auth-msg { font-size: 12.5px; font-weight: 600; min-height: 18px; margin: 2px 0 10px; }
.auth-msg.err { color: var(--expense); }
.auth-msg.ok { color: var(--income); }
.auth-foot { text-align: center; font-size: 11.5px; color: var(--text-3); margin-top: 18px; line-height: 1.5; }
.pw-wrap { position: relative; }
.pw-wrap .toggle-eye {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  width: 34px; height: 34px; border-radius: 8px; color: var(--text-3); font-size: 15px;
  display: grid; place-items: center;
}
.pw-wrap .toggle-eye:hover { background: var(--surface-2); color: var(--text); }
.pw-wrap .control { padding-right: 42px; }
.remember { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); font-weight: 600; cursor: pointer; margin-bottom: 4px; }
.remember input { width: 17px; height: 17px; accent-color: var(--brand); }
.overlay-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 35; display: none; }
.overlay-backdrop.open { display: block; }

/* Bars chart */
.bars { display: flex; align-items: flex-end; gap: 10px; height: 200px; padding-top: 10px; }
.bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; min-width: 0; }
.bar-stack { width: 100%; max-width: 46px; display: flex; flex-direction: column-reverse; gap: 2px; }
.bar-seg { width: 100%; border-radius: 3px; min-height: 2px; transition: height .4s ease; }
.bar-label { font-size: 11px; color: var(--text-3); font-weight: 700; white-space: nowrap; }

/* ============================ Responsive ============================ */
@media (max-width: 1080px) {
  .g-kpi { grid-template-columns: repeat(2, 1fr); }
  .g-dash { grid-template-columns: 1fr; }
  .g-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 820px) {
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100%;
    transform: translateX(-100%); box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: grid; place-items: center; }
  .g-2 { grid-template-columns: 1fr; }
  .view { padding: 16px; }
  .topbar { padding: 0 16px; }
  .topbar .sub { display: none; }
}
@media (max-width: 560px) {
  .g-kpi { grid-template-columns: 1fr 1fr; gap: 12px; }
  .g-3 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .kpi .kpi-value { font-size: 22px; }
  .topbar h2 { font-size: 16px; }
  .view { padding: 12px; }
  .toasts { left: 12px; right: 12px; bottom: 12px; }
  .toast { min-width: 0; }
  .hide-sm { display: none !important; }
}

/* ============================ iPhone: safe areas (notch / home) ============================ */
@supports (padding: env(safe-area-inset-top)) {
  .topbar {
    height: auto;
    min-height: calc(64px + env(safe-area-inset-top));
    padding-top: env(safe-area-inset-top);
    padding-left: calc(24px + env(safe-area-inset-left));
    padding-right: calc(24px + env(safe-area-inset-right));
  }
  .sidebar { padding-left: env(safe-area-inset-left); }
  .view {
    padding-left: calc(24px + env(safe-area-inset-left));
    padding-right: calc(24px + env(safe-area-inset-right));
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
  .sidebar-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .auth-screen {
    padding-top: calc(20px + env(safe-area-inset-top));
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
  }
  .toasts { bottom: calc(22px + env(safe-area-inset-bottom)); }
  .overlay { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

/* ============================ Ajustes finos móvil ============================ */
@media (max-width: 820px) {
  @supports (padding: env(safe-area-inset-top)) {
    .topbar { padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(16px + env(safe-area-inset-right)); }
    .view { padding-left: calc(16px + env(safe-area-inset-left)); padding-right: calc(16px + env(safe-area-inset-right)); padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
  }
  /* botones de la barra superior más compactos y con buen área táctil */
  .topbar-actions { gap: 8px; }
  .icon-btn { width: 42px; height: 42px; }
}
@media (max-width: 560px) {
  th, td { padding: 10px 10px; }
  .card-head { padding: 14px 16px; }
  .card-pad { padding: 16px; }
  /* filtros y selects ocupan buen ancho para tocar cómodo */
  .toolbar .control { flex: 1 1 44%; min-width: 0; }
  .search { max-width: none; width: 100%; }
  .modal-foot { flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; justify-content: center; }
  .btn { padding: 11px 15px; }   /* área táctil mínima cómoda */
  .seg button { padding: 9px 12px; }
}

/* ============================ Actualizar / Pull-to-refresh ============================ */
@keyframes spin { to { transform: rotate(360deg); } }
#topRefresh.spinning { animation: spin .8s linear infinite; }
.ptr-ind {
  position: fixed; top: calc(env(safe-area-inset-top, 0px) + 6px); left: 50%;
  transform: translateX(-50%) translateY(-60px); opacity: 0;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow);
  border-radius: 22px; padding: 8px 16px; font-size: 13px; font-weight: 700;
  color: var(--brand); z-index: 60; pointer-events: none;
  transition: opacity .15s ease;
}
[data-theme="dark"] .ptr-ind { color: var(--brand-2); }
