:root {
  --navy: #5EEAD4;
  --navy-light: #2DD4BF;
  --bg: #0A0F1A;
  --white: #111826;
  --surface: #1B2438;
  --surface-2: #243049;
  --on-accent: #06201C;
  --danger: #F87171;
  --danger-soft: #3A1B1B;
  --warn-bg: #3A1B1B;
  --warn-soft: #2A1F14;
  --warn-line: #5A3A12;
  --warn-text: #FBBF24;
  --ok: #4ADE80;
  --ok-soft: #163226;
  --border: #2A3752;
  --text: #E8EEF7;
  --muted: #A5B3C7;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  padding-bottom: 40px;
}
.hidden { display: none !important; }

/* LOGIN */
#view-login {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 20px;
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 16px;
  padding: 28px 24px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.08);
  text-align: center;
}
.auth-card h1 { color: var(--navy); margin-bottom: 4px; font-size: 26px; }
.auth-card h2 { color: var(--navy); margin-top: 0; }
.subtitle { color: var(--muted); margin-top: 0; margin-bottom: 20px; font-size: 14px; }

form { display: flex; flex-direction: column; gap: 6px; text-align: left; }
label { font-size: 13px; font-weight: 600; color: var(--navy); margin-top: 8px; }
input[type=text], input[type=password], input[type=number] {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 16px;
}
.btn-primary {
  margin-top: 16px;
  background: var(--navy);
  color: var(--on-accent);
  border: none;
  padding: 13px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary {
  background: var(--surface);
  color: var(--navy);
  border: 1px solid var(--navy);
  padding: 13px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger {
  background: var(--danger);
  color: var(--on-accent);
  border: none;
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
}
.btn-block { width: 100%; }
.btn-link {
  background: none;
  border: none;
  color: var(--navy);
  text-decoration: underline;
  margin-top: 14px;
  cursor: pointer;
  font-size: 14px;
}
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin: 6px 0 0; }

/* APP SHELL */
.topbar {
  background: var(--navy);
  color: var(--on-accent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  position: sticky;
  top: 0;
  z-index: 5;
}
.topbar h1 { font-size: 19px; margin: 0; }
.btn-icon {
  background: rgba(255,255,255,0.15);
  border: none;
  color: var(--on-accent);
  width: 36px; height: 36px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
}
.btn-logout {
  background: rgba(255,255,255,0.15);
  border: none;
  color: var(--on-accent);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.patient-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.patient-bar label { margin: 0; font-size: 13px; color: var(--navy); white-space: nowrap; }
.patient-buttons {
  flex: 1;
  display: flex;
  gap: 8px;
  overflow-x: auto;
}
.patient-btn {
  padding: 8px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.patient-btn.active {
  background: var(--navy);
  color: var(--on-accent);
  border-color: var(--navy);
}
select {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
}
.patient-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  margin-bottom: 8px;
}
.patient-row .name { font-weight: 600; }
.patient-row .btn-remove-row { font-size: 15px; }

.photo-input-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}
.photo-preview {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
}
.photo-input-row input[type=file] {
  flex: 1;
  font-size: 12px;
}

.dose-thumb {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.stock-thumb {
  width: 52px;
  height: 52px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.stock-card-top {
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.dose-row { align-items: center; }

.dose-thumb, .stock-thumb {
  cursor: pointer;
}
.lightbox-modal {
  background: rgba(0,0,0,0.85);
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.lightbox-modal img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 12px;
  object-fit: contain;
}

/* Módulos */
.module-bar {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.module-btn {
  flex: 1;
  min-width: 90px;
  padding: 10px 6px;
  background: none;
  border: none;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.module-btn.active { color: var(--navy); border-bottom-color: var(--navy); background: var(--surface-2); }
.module-view { }

.low-stock-banner {
  background: var(--warn-soft);
  border: 1px solid var(--warn-line);
  border-radius: 14px;
  padding: 12px 14px;
  margin-bottom: 12px;
}
.low-stock-title {
  font-weight: 700;
  color: var(--warn-text);
  font-size: 13px;
  margin-bottom: 8px;
}
.low-stock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13px;
}
.btn-quick-add {
  background: var(--navy);
  color: var(--on-accent);
  border: none;
  border-radius: 16px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.btn-quick-add:disabled { opacity: 0.4; }

.quickadd-section {
  background: var(--surface);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.category-btns {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  gap: 10px;
  margin-bottom: 10px;
  padding-bottom: 4px;
}
.category-btn {
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  white-space: nowrap;
}
.category-btn.active {
  background: var(--navy);
  color: var(--on-accent);
  border-color: var(--navy);
}
.category-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  width: 76px;
  padding: 12px 6px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
}
.category-tile-icon { font-size: 28px; line-height: 1; }
.category-tile-label { font-size: 11px; font-weight: 700; text-align: center; }
.category-tile.active {
  background: var(--navy);
  color: var(--on-accent);
  border-color: var(--navy);
}
.frequent-products {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.product-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
}
.product-chip:active { background: var(--surface-2); }
.product-chip .emoji { font-size: 16px; }
.product-chip.already-added {
  opacity: 0.5;
}

.btn-toggle-filters {
  display: block;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--navy);
  padding: 10px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  margin: 10px 0;
}
#expense-filter-count {
  background: var(--navy);
  color: var(--on-accent);
  border-radius: 10px;
  padding: 1px 7px;
  font-size: 11px;
  margin-left: 4px;
}

.date-presets {
  display: flex;
  gap: 6px;
}
.date-preset-btn {
  flex: 1;
  padding: 8px 4px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--navy);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.date-preset-btn.active {
  background: var(--navy);
  color: var(--on-accent);
  border-color: var(--navy);
}

.expenses-summary {
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-radius: 14px;
  padding: 14px;
  margin-top: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.expenses-summary-item { text-align: center; }
.expenses-summary-value { font-size: 18px; font-weight: 700; color: var(--navy); }
.expenses-summary-label { font-size: 11px; color: var(--muted); text-transform: uppercase; margin-top: 2px; }

.filter-bar {
  background: var(--surface);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filter-field label {
  font-size: 12px;
  font-weight: 700;
  color: var(--navy);
}
.filter-field select,
.filter-field input {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  background: var(--surface);
  padding: 12px;
  border-radius: 12px;
  margin-bottom: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.inline-form input {
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 13px;
}
.inline-form input[type=text]:first-child { flex: 2 1 140px; }
.inline-form input[type=number] { flex: 0 1 70px; }
.inline-form input#shop-item-unit { flex: 0 1 70px; }
.inline-form input#shop-item-category { flex: 1 1 120px; }
.inline-form button { flex: 0 0 auto; }

/* Formulario de carga manual de mercadería: grilla prolija en vez de
   que el nombre quede gigante solo en una fila */
#form-add-shopping-item {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  align-items: stretch;
}
#form-add-shopping-item input {
  width: 100%;
  box-sizing: border-box;
  padding: 8px;
  font-size: 13px;
}
#form-add-shopping-item #shop-item-name { grid-column: 1 / -1; }
#form-add-shopping-item #shop-item-category { grid-column: 1 / -1; }
#form-add-shopping-item button { grid-column: 1 / -1; }

.category-header {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  margin: 14px 4px 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.btn-link-small {
  background: none;
  border: none;
  color: var(--navy);
  text-decoration: underline;
  font-size: 11px;
  text-transform: none;
  font-weight: 600;
  cursor: pointer;
}
.shop-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.shop-row.bought { opacity: 0.55; }
.shop-row.bought .shop-name { text-decoration: line-through; }
.shop-check {
  width: 26px; height: 26px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  flex-shrink: 0;
}
.shop-check.checked { background: var(--ok); border-color: var(--ok); color: var(--on-accent); }
.shop-info { flex: 1; }
.shop-name { font-weight: 700; font-size: 14px; }
.shop-meta { color: var(--muted); font-size: 12px; }
.btn-x { background: none; border: none; color: var(--danger); font-size: 16px; cursor: pointer; }

.pantry-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.pantry-row.low { border-left: 5px solid var(--danger); }
.pantry-row input[type=number] {
  width: 70px;
  padding: 7px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.pantry-row-v2 {
  background: var(--surface);
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.pantry-row-v2.low { border-left: 5px solid var(--danger); }
.pantry-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pantry-row-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
}
.pantry-actions { display: flex; gap: 4px; }
.btn-icon-xs {
  background: var(--surface-2);
  border: none;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  font-size: 13px;
  color: var(--navy);
  cursor: pointer;
}
.btn-icon-xs.danger { color: var(--danger); }
.pantry-qty-edit {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pantry-qty-edit input[type=number] {
  width: 64px;
  padding: 6px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.history-row {
  background: var(--surface);
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 13px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.history-row .when { color: var(--muted); font-size: 11px; }
.activity-details {
  white-space: pre-line;
  font-size: 12px;
  color: var(--muted);
  margin-top: 4px;
  padding-left: 8px;
  border-left: 2px solid var(--border);
}
.activity-module-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--navy);
  margin-left: 6px;
}

.expense-row {
  background: var(--surface);
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.expense-row .top-line { display: flex; justify-content: space-between; align-items: center; font-weight: 700; }
.expense-row-right { display: flex; align-items: center; gap: 6px; }
.expense-row .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.expense-menu-wrap { position: relative; }
.btn-dots {
  background: none;
  border: none;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 8px;
}
.btn-dots:active { background: var(--surface-2); }
.expense-menu {
  position: absolute;
  top: 30px;
  right: 0;
  background: var(--surface);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  padding: 6px;
  min-width: 150px;
  z-index: 15;
}

.balance-card {
  background: var(--surface);
  padding: 14px;
  border-radius: 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.balance-card .name { font-weight: 700; }
.balance-card .amount.positive { color: var(--ok); }
.balance-card .amount.negative { color: var(--danger); }

.balance-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 6px;
}

.external-balances-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 6px;
}
.external-balance-card {
  background: linear-gradient(135deg, var(--warn-soft), var(--warn-soft));
  border-radius: 8px;
  padding: 16px 12px;
  text-align: center;
  border: 1px solid var(--warn-line);
}
.external-balance-icon { font-size: 24px; margin-bottom: 4px; }
.external-balance-owner { font-weight: 700; font-size: 13px; color: var(--warn-text); }
.external-balance-amount { font-size: 19px; font-weight: 700; color: var(--warn-text); margin-top: 4px; }
.external-balance-count { font-size: 11px; color: var(--warn-text); margin-top: 2px; }
.balance-card-v2 {
  background: var(--surface);
  border-radius: 16px;
  padding: 16px 10px;
  text-align: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  border-top: 4px solid var(--border);
}
.balance-card-v2.positive { border-top-color: var(--ok); }
.balance-card-v2.negative { border-top-color: var(--danger); }
.balance-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 18px;
  margin: 0 auto 8px;
}
.balance-card-v2.positive .balance-avatar { background: var(--ok-soft); color: var(--ok); }
.balance-card-v2.negative .balance-avatar { background: var(--warn-bg); color: var(--danger); }
.balance-name { font-weight: 700; font-size: 13px; }
.balance-amount { font-size: 20px; font-weight: 700; margin-top: 4px; }
.balance-card-v2.positive .balance-amount { color: var(--ok); }
.balance-card-v2.negative .balance-amount { color: var(--danger); }
.balance-status { font-size: 11px; color: var(--muted); text-transform: uppercase; margin-top: 2px; }

.debt-row {
  background: var(--warn-soft);
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 6px;
  font-size: 13px;
}
.section-title { color: var(--navy); font-size: 15px; margin: 16px 0 8px; }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  color: var(--text);
  margin-top: 10px;
}
.checkbox-label input { width: auto; }

.segmented {
  display: flex;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--border);
  margin-top: 4px;
}
.segmented-btn {
  flex: 1;
  padding: 10px 6px;
  background: var(--surface);
  border: none;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.segmented-btn + .segmented-btn { border-left: 1px solid var(--border); }
.segmented-btn.active {
  background: var(--navy);
  color: var(--on-accent);
}

.account-row, .category-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 8px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.account-row .owner { font-size: 12px; color: var(--muted); font-weight: 600; }
.account-row .label, .category-row .label { font-weight: 700; }
.fixed-badge {
  display: inline-block;
  background: var(--warn-soft);
  color: var(--warn-text);
  padding: 1px 6px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 700;
}
.category-edit-input {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  margin-right: 8px;
}

.participant-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
  margin: 4px 6px 4px 0;
  font-size: 13px;
  cursor: pointer;
}
.participant-chip.selected { background: var(--navy); color: var(--on-accent); border-color: var(--navy); }

.user-perm-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.user-perm-card .uname { font-weight: 700; font-size: 15px; }
.user-perm-card .admin-badge {
  display: inline-block;
  background: var(--navy);
  color: var(--on-accent);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 10px;
  margin-left: 8px;
}
.perm-grid {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 6px 10px;
  align-items: center;
  margin-top: 10px;
  font-size: 13px;
}
.perm-grid .perm-label { color: var(--muted); font-weight: 600; }

/* Menú desplegable (módulos + cuenta + salir) */
.menu-wrap { position: relative; }
.btn-menu-toggle {
  background: rgba(255,255,255,0.15);
  border: none;
  color: var(--on-accent);
  width: 38px; height: 38px;
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
}
.menu-dropdown {
  position: absolute;
  top: 46px;
  right: 0;
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.22);
  min-width: 220px;
  padding: 8px;
  z-index: 30;
}
.menu-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.menu-item:active, .menu-item:hover { background: var(--surface-2); }
.menu-item.active { background: var(--surface-2); color: var(--navy); }
.menu-item-danger { color: var(--danger); }
.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 4px;
}

.tabs {
  display: flex;
  flex-wrap: nowrap;
  overflow-x: auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 60px;
  z-index: 4;
}
.tab {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 14px;
  background: none;
  border: none;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}
.tab-icon { font-size: 18px; line-height: 1; }
.tab.active { color: var(--navy); border-bottom-color: var(--navy); }

.update-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--navy);
  color: var(--on-accent);
  padding: 12px 20px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,0.3);
  z-index: 100;
  animation: update-banner-in 0.25s ease-out;
}
@keyframes update-banner-in {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.alerts-banner {
  background: var(--warn-bg);
  color: var(--danger);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
}

.tab-content { padding: 14px; }

/* Itinerario */
.time-group {
  background: var(--surface);
  border-radius: 14px;
  margin-bottom: 14px;
  overflow: hidden;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.time-group-header {
  background: var(--surface-2);
  color: var(--navy);
  font-weight: 700;
  padding: 10px 14px;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.reorder-btns {
  display: flex;
  gap: 4px;
}
.btn-move {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--navy);
  font-size: 13px;
  cursor: pointer;
}
.btn-move:disabled {
  opacity: 0.3;
  cursor: default;
}
.dose-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  gap: 10px;
}
.dose-info { flex: 1; }
.dose-name { font-weight: 700; font-size: 15px; }
.dose-sub { color: var(--muted); font-size: 13px; }
.dose-amount { color: var(--muted); font-size: 13px; margin-top: 2px; }
.check-btn {
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 2px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
}
.check-btn.checked {
  background: var(--ok);
  border-color: var(--ok);
  color: var(--on-accent);
}

/* Stock */
.stock-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  border-left: 6px solid var(--ok);
}
.stock-card.low { border-left-color: var(--danger); }
.stock-card .name { font-weight: 700; font-size: 15px; }
.stock-card .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.stock-card .zero-date { font-size: 13px; margin-top: 6px; font-weight: 600; }
.stock-card.low .zero-date { color: var(--danger); }

/* Gestión medicamentos */
.med-manage-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  cursor: pointer;
}
.med-manage-card .name { font-weight: 700; }
.med-manage-card .sub { color: var(--muted); font-size: 13px; }
.chevron { color: var(--muted); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 40;
}
.modal-content {
  background: var(--surface);
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  border-radius: 18px 18px 0 0;
  padding: 20px;
}
.modal-content h2 { color: var(--navy); margin-top: 0; }
.modal-content h3 { color: var(--navy); font-size: 15px; margin-bottom: 6px; }
.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 20px;
  align-items: center;
}
.spacer { flex: 1; }

.schedule-row {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
  align-items: center;
}
.schedule-row .si-label { flex: 2; min-width: 0; }
.schedule-row .si-dose { flex: 0 0 64px; min-width: 64px; }
.schedule-row .si-unit { flex: 1.2; min-width: 0; }
.schedule-row input {
  padding: 9px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  min-width: 0;
}
.hint { font-size: 12px; color: var(--muted); margin: 2px 0 8px; }
.btn-remove-row {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 16px;
  cursor: pointer;
  width: 26px;
}

/* Toggle lista/calendario */
.view-toggle {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.view-toggle-btn {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.view-toggle-btn.active {
  background: var(--navy);
  color: var(--on-accent);
  border-color: var(--navy);
}

/* Calendario de stock */
.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.calendar-month-label {
  font-weight: 700;
  color: var(--navy);
  text-transform: capitalize;
}
.btn-icon-small {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--navy);
  width: 32px; height: 32px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  background: var(--surface);
  padding: 10px;
  border-radius: 14px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.calendar-dow {
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  padding-bottom: 4px;
}
.calendar-cell {
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  font-size: 12px;
  position: relative;
}
.calendar-cell.empty { visibility: hidden; }
.calendar-cell.is-today { background: var(--surface-2); font-weight: 700; }
.calendar-cell.has-event { background: var(--warn-bg); }
.calendar-cell.selected { outline: 2px solid var(--navy); }
.cal-amount {
  font-size: 9px;
  font-weight: 700;
  color: var(--navy);
  background: var(--surface);
  border-radius: 6px;
  padding: 1px 3px;
  margin-top: 2px;
}
.cal-daynum { font-size: 12px; }
.cal-dot {
  background: var(--danger);
  color: var(--on-accent);
  font-size: 9px;
  font-weight: 700;
  width: 15px; height: 15px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: 2px;
}
.calendar-events-list { margin-top: 14px; }
.calendar-event-row {
  background: var(--surface);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 13px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

@media (min-width: 600px) {
  .modal { align-items: center; }
  .modal-content { border-radius: 18px; }
}

/* ===== BETA · Dirección B (Panel oscuro) ===== */
html { color-scheme: dark; }
body { padding-bottom: 96px; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=email], textarea, select {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
input::placeholder, textarea::placeholder { color: #7889A6; }
.topbar {
  background: #0D1422;
  color: var(--text);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 20px; font-weight: 800; letter-spacing: -0.2px; }
.btn-menu-toggle { background: var(--surface); color: var(--text); }
.tabs { background: #0D1422; top: 63px; }
.tab.active { color: var(--navy); border-bottom-color: var(--navy); }
.menu-item-danger { color: var(--danger); }
.btn-danger { background: var(--danger); color: var(--on-accent); font-weight: 700; }
.modal-content, .auth-card { border: 1px solid var(--border); }
.modal { background: rgba(3,6,12,0.7); }
hr, .menu-divider { border-color: var(--border); }

/* Navegación inferior por módulo */
.bottom-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 20;
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 70px;
  padding-bottom: env(safe-area-inset-bottom);
  background: #0D1422;
  border-top: 1px solid var(--border);
}
.bottom-nav.hidden { display: none; }
.bottom-nav button {
  flex: 1;
  background: none;
  border: none;
  color: #7889A6;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-family: inherit;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 0;
}
.bottom-nav button.active { color: var(--navy); font-weight: 800; }
.bottom-nav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* los módulos ya están en la barra de abajo */
#menu-modules-list { display: none; }
.beta-badge {
  font-size: 10px; font-weight: 800; letter-spacing: 0.6px;
  background: #FBBF24; color: #2A1F14; border-radius: 6px; padding: 2px 6px; margin-left: 8px; vertical-align: middle;
}

body:has(#view-app.hidden) .bottom-nav { display: none; }

/* ===== BETA etapa 2 · Remedios ===== */
.resumen-row { display: flex; gap: 10px; padding: 14px 14px 0; }
.resumen-card { flex: 1; background: var(--surface); border-radius: 18px; padding: 14px; display: flex; align-items: center; gap: 12px; }
.resumen-card.warn { background: var(--warn-soft); border: 1px solid var(--warn-line); }
.resumen-big { font-size: 22px; font-weight: 800; }
.resumen-card.warn .resumen-big { color: var(--warn-text); }
.resumen-sub { font-size: 12px; color: var(--muted); }
.group-status { margin-left: 10px; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 10px; }
.group-status.done { background: var(--ok-soft); color: var(--ok); }
.group-status.pending { background: var(--surface-2); color: var(--muted); }
.stock-bar { height: 8px; border-radius: 4px; background: var(--surface-2); overflow: hidden; margin-top: 10px; }
.stock-bar-fill { height: 8px; background: var(--navy); border-radius: 4px; }
.stock-bar-fill.low { background: var(--warn-text); }
.stock-bar-label { font-size: 12px; color: var(--muted); margin-top: 4px; }
.check-btn { border-radius: 8px; }

/* ===== BETA etapa 3 · Balances ===== */
.month-card { background: linear-gradient(135deg, #17324A, #1B2438); border: 1px solid #2B4A66; border-radius: 22px; padding: 18px; margin-bottom: 14px; }
.month-label { font-size: 13px; color: var(--muted); }
.month-amount { font-size: 32px; font-weight: 800; letter-spacing: -0.5px; margin: 2px 0; }
.month-sub { font-size: 13px; color: var(--navy); }
.balance-list { display: flex; flex-direction: column; gap: 8px; }
.balance-row { background: var(--surface); border-radius: 16px; padding: 12px 14px; }
.balance-row-top { display: flex; justify-content: space-between; align-items: baseline; font-size: 15px; }
.balance-row-name { font-weight: 800; }
.balance-row-name small { font-weight: 600; font-size: 11px; color: var(--muted); text-transform: uppercase; margin-left: 6px; }
.balance-row-amount { font-weight: 800; }
.balance-row.positive .balance-row-amount { color: var(--navy); }
.balance-row.negative .balance-row-amount { color: var(--warn-text); }
.balance-track { height: 6px; border-radius: 3px; background: var(--surface-2); position: relative; margin-top: 8px; }
.balance-fill { position: absolute; top: 0; height: 6px; border-radius: 3px; }
.balance-row.positive .balance-fill { left: 50%; background: var(--navy); }
.balance-row.negative .balance-fill { right: 50%; background: var(--warn-text); }
.debt-row { display: flex; align-items: center; gap: 10px; background: var(--surface); border-radius: 14px; padding: 10px 14px; margin-bottom: 8px; font-size: 14px; }
.debt-text { flex: 1; }
.btn-pay { height: 30px; padding: 0 12px; border-radius: 15px; border: 0; background: var(--surface-2); color: var(--navy); font-family: inherit; font-size: 12px; font-weight: 800; cursor: pointer; }

/* ===== BETA etapa 3 · Compras ===== */
.low-stock-banner { background: var(--warn-soft); }
.shop-row { border-radius: 16px; box-shadow: none; }
.category-tile { background: var(--surface); border-radius: 18px; color: var(--navy); }
.category-header { letter-spacing: 0.6px; }

/* ===== BETA etapa 4 · solapas en píldoras y tarjetas de gastos ===== */
.tabs { gap: 8px; padding: 10px 14px; top: 63px; border-bottom: 1px solid var(--border); scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex-direction: row;
  gap: 6px;
  height: 36px;
  padding: 0 14px;
  border-radius: 18px;
  background: var(--surface);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.tab-icon { font-size: 15px; }
.tab.active { background: var(--navy); color: var(--on-accent); border-color: var(--navy); font-weight: 800; }
.expense-row { border-radius: 16px; box-shadow: none; padding: 14px; }
.expense-row .top-line { font-size: 15px; gap: 10px; }
.expense-amount { font-size: 17px; font-weight: 800; white-space: nowrap; }
.expense-row .meta { font-size: 12.5px; line-height: 1.4; }
.fixed-badge { color: var(--warn-text); font-weight: 700; }

/* ===== BETA · detalle del mes (ventana desde abajo) ===== */
.month-card { cursor: pointer; }
.month-card:active { filter: brightness(1.15); }
.month-more { float: right; color: var(--navy); font-weight: 700; }
.month-sheet { max-height: 80vh; display: flex; flex-direction: column; }
.month-sheet-nav { display: flex; align-items: center; justify-content: space-between; }
.month-sheet-title { font-size: 18px; font-weight: 800; }
.month-sheet-total { font-size: 28px; font-weight: 800; margin: 6px 0 10px; }
.month-sheet-total small { display: block; font-size: 13px; font-weight: 600; color: var(--muted); }
.month-sheet-list { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 8px; }
.month-item { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 14px; padding: 10px 12px; }
.month-item-main { flex: 1; min-width: 0; }
.month-item-title { font-weight: 700; font-size: 14px; }
.month-item-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.month-item-amount { font-weight: 800; font-size: 15px; white-space: nowrap; }

/* ===== BETA · Gastos fijos ===== */
.fijos-alert { display: block; width: 100%; text-align: left; border: 0; background: var(--warn-soft); color: var(--warn-text); border-bottom: 1px solid var(--warn-line); padding: 10px 16px; font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer; }
.fijos-alert.overdue { background: var(--danger-soft); color: var(--danger); }
.fijos-alert.hidden { display: none; }
.fijos-summary { background: var(--surface); border-radius: 18px; padding: 14px; margin-bottom: 12px; }
.fijos-summary-top { display: flex; align-items: baseline; gap: 8px; }
.fijos-summary-big { font-size: 24px; font-weight: 800; }
.fijos-summary-label { font-size: 13px; color: var(--muted); }
.fijos-progress { height: 8px; border-radius: 4px; background: var(--surface-2); margin: 10px 0 8px; overflow: hidden; }
.fijos-progress div { height: 8px; background: var(--navy); border-radius: 4px; }
.fijos-summary-sub { font-size: 13px; color: var(--warn-text); font-weight: 600; }
.fijo-card { display: flex; gap: 10px; align-items: center; background: var(--surface); border-radius: 16px; padding: 12px 14px; margin-top: 8px; border-left: 5px solid var(--surface-2); }
.fijo-card.paid { border-left-color: var(--ok); }
.fijo-card.overdue { border-left-color: var(--danger); }
.fijo-card.soon { border-left-color: var(--warn-text); }
.fijo-main { flex: 1; min-width: 0; }
.fijo-title { font-weight: 800; font-size: 15px; }
.fijo-status { font-size: 13px; font-weight: 700; margin-top: 2px; color: var(--muted); }
.fijo-status.paid { color: var(--ok); }
.fijo-status.overdue { color: var(--danger); }
.fijo-status.soon { color: var(--warn-text); }
.fijo-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.batch-list { display: flex; flex-direction: column; gap: 10px; margin: 10px 0; max-height: 50vh; overflow-y: auto; }
.batch-row { background: var(--surface-2); border-radius: 14px; padding: 10px 12px; }
.batch-check { display: flex; align-items: center; gap: 10px; margin: 0; font-size: 15px; font-weight: 800; color: var(--text); }
.batch-check input { width: 20px; height: 20px; accent-color: var(--navy); }
.batch-fields { display: flex; gap: 8px; margin-top: 8px; }
.batch-fields input { flex: 1; min-width: 0; padding: 9px 10px; font-size: 15px; }
.batch-meta { font-size: 12px; color: var(--muted); margin-top: 6px; }
.batch-total { font-weight: 800; font-size: 15px; margin-top: 10px; color: var(--navy); }

.fijo-card.skip { opacity: .65; }
.fijo-period { font-size: 11px; font-weight: 700; color: var(--navy); background: var(--surface-2); border-radius: 8px; padding: 2px 7px; margin-left: 6px; vertical-align: middle; }

/* Categorías: edición en línea más compacta */
.category-row input.category-edit-input {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  padding: 6px 10px;
  font-size: 14px;
  line-height: 1.2;
  border-radius: 8px;
  margin: 0 8px 0 0;
}
.category-row:has(.category-edit-input) { padding: 8px 12px; }

/* Botones de acción más grandes (editar, borrar, cargar) */
.btn-icon-xs { width: 40px; height: 40px; border-radius: 10px; font-size: 18px; display: inline-flex; align-items: center; justify-content: center; padding: 0; }
.btn-pay { height: 40px; padding: 0 16px; border-radius: 20px; font-size: 14px; }
.pantry-actions, .fijo-actions { gap: 6px; }
.category-row .label, .account-row .label { font-size: 15px; }

.btn-link { background: none; border: 0; color: var(--navy); font-family: inherit; font-size: 14px; font-weight: 700; padding: 12px 0 0; width: 100%; cursor: pointer; text-decoration: underline; }
input[type=email] { padding: 12px; border-radius: 10px; border: 1px solid var(--border); font-size: 16px; width: 100%; background: var(--surface); color: var(--text); }
