/* ============================================================================
   BOTIQUÍN FAMILIAR v4 - Diseño Moderno, Minimalista y Responsivo
   Modo Oscuro Moderno (Default) y Modo Claro Limpio con color-scheme estricto
   ============================================================================ */

@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&family=Plus+Jakarta+Sans:wght@400;500;600;700;800&display=swap');

:root {
  color-scheme: light;

  --bg-app: #f4f6fb;
  --bg-surface: #ffffff;
  --bg-surface-alt: #eef2f8;
  --bg-surface-hover: #e5ebf4;
  --bg-elevated: #ffffff;
  --bg-input: #ffffff;
  --bg-nav-track: #e7ecf5;

  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;

  --border-subtle: rgba(15, 23, 42, 0.10);
  --border-strong: rgba(15, 23, 42, 0.18);

  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: rgba(79, 70, 229, 0.12);
  --primary-text: #4338ca;

  --status-green-bg: rgba(16, 185, 129, 0.13);
  --status-green-text: #047857;
  --status-green-border: rgba(16, 185, 129, 0.35);

  --status-yellow-bg: rgba(245, 158, 11, 0.14);
  --status-yellow-text: #b45309;
  --status-yellow-border: rgba(245, 158, 11, 0.38);

  --status-red-bg: rgba(239, 68, 68, 0.12);
  --status-red-text: #b91c1c;
  --status-red-border: rgba(239, 68, 68, 0.34);

  --currency-bg: rgba(14, 165, 233, 0.12);
  --currency-text: #0369a1;
  --currency-border: rgba(14, 165, 233, 0.32);

  --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
  --shadow-sm: 0 4px 12px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 12px 28px -6px rgba(15, 23, 42, 0.10);
  --shadow-lg: 0 24px 48px -12px rgba(15, 23, 42, 0.18);

  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  --header-height: 64px;
  --bottom-nav-height: 66px;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg-app: #0b0f19;
  --bg-surface: #131a2a;
  --bg-surface-alt: #1a2338;
  --bg-surface-hover: #222d46;
  --bg-elevated: #172033;
  --bg-input: #0e1422;
  --bg-nav-track: #141c2e;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --border-subtle: rgba(148, 163, 184, 0.14);
  --border-strong: rgba(148, 163, 184, 0.24);

  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-soft: rgba(99, 102, 241, 0.18);
  --primary-text: #a5b4fc;

  --status-green-bg: rgba(16, 185, 129, 0.16);
  --status-green-text: #6ee7b7;
  --status-green-border: rgba(16, 185, 129, 0.34);

  --status-yellow-bg: rgba(245, 158, 11, 0.16);
  --status-yellow-text: #fcd34d;
  --status-yellow-border: rgba(245, 158, 11, 0.34);

  --status-red-bg: rgba(244, 63, 94, 0.16);
  --status-red-text: #fda4af;
  --status-red-border: rgba(244, 63, 94, 0.34);

  --currency-bg: rgba(56, 189, 248, 0.14);
  --currency-text: #7dd3fc;
  --currency-border: rgba(56, 189, 248, 0.30);

  --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.28);
  --shadow-sm: 0 4px 14px rgba(0, 0, 0, 0.35);
  --shadow-md: 0 12px 30px -6px rgba(0, 0, 0, 0.50);
  --shadow-lg: 0 24px 54px -10px rgba(0, 0, 0, 0.65);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: var(--font-sans);
  font-size: 16px;
  color: var(--text-primary);
  background-color: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.5;
  padding-bottom: calc(var(--bottom-nav-height) + 18px);
  transition: background-color 0.2s ease, color 0.2s ease;
}

@media (min-width: 900px) {
  body {
    padding-bottom: 36px;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.hide-on-mobile {
  display: none;
}

.mobile-only-hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

@media (min-width: 640px) {
  .hide-on-mobile {
    display: inline;
  }
  .mobile-only-hint {
    display: none;
  }
}

/* ============================================================================
   PANTALLA DE BLOQUEO Y AUTENTICACIÓN
   ============================================================================ */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background-color: var(--bg-app);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.auth-overlay.hidden {
  display: none !important;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 30px 26px;
  box-shadow: var(--shadow-lg);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.auth-logo {
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: linear-gradient(135deg, #4f46e5, #0284c7);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.auth-title {
  font-size: 1.32rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.auth-subtitle {
  font-size: 0.84rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.auth-desc {
  font-size: 0.88rem;
  color: var(--text-secondary);
  margin-bottom: 18px;
  padding: 12px 14px;
  background: var(--bg-surface-alt);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.auth-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--status-red-bg);
  color: var(--status-red-text);
  border: 1px solid var(--status-red-border);
  font-size: 0.85rem;
  font-weight: 600;
}

/* ============================================================================
   BARRA SUPERIOR MODERNA Y SELECTOR DE TEMA SOL/LUNA
   ============================================================================ */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-xs);
}

.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  min-height: var(--header-height);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text-primary);
}

.brand-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
}

.brand-text h1 {
  font-size: 1.04rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.brand-meta {
  font-size: 0.74rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.offline-indicator {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  border-radius: var(--radius-full);
  background: var(--status-yellow-bg);
  color: var(--status-yellow-text);
  border: 1px solid var(--status-yellow-border);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.offline-indicator.hidden {
  display: none !important;
}

.offline-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.sync-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-alt);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  font-family: var(--font-sans);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease;
}

.sync-badge:hover {
  background: var(--bg-surface-hover);
}

.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
}

/* Switch Píldora Sol / Luna (como referencia moderna) */
.theme-switch-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-full);
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
}

.theme-opt {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: background-color 0.15s ease, color 0.15s ease;
}

:root:not([data-theme="dark"]) .theme-opt-light {
  background: var(--primary);
  color: #ffffff;
}

[data-theme="dark"] .theme-opt-dark {
  background: var(--primary);
  color: #ffffff;
}

/* ============================================================================
   NAVEGACIÓN TIPO PÍLDORA (ESCRITORIO) Y BARRA INFERIOR (MÓVIL)
   ============================================================================ */
.desktop-nav {
  display: none;
  padding: 14px 16px 0;
}

.desktop-nav-inner {
  max-width: 1280px;
  margin: 0 auto;
}

.nav-pill-track {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px;
  background: var(--bg-nav-track);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
}

.nav-tab {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.nav-tab:hover {
  color: var(--text-primary);
}

.nav-tab.active {
  background: var(--primary);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
}

.nav-tab-badge {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 7px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.18);
  color: inherit;
}

.nav-tab:not(.active) .nav-tab-badge {
  background: var(--primary-soft);
  color: var(--primary-text);
}

.mobile-bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--bottom-nav-height);
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  z-index: 100;
  box-shadow: 0 -4px 18px rgba(0, 0, 0, 0.12);
}

.mobile-nav-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-family: var(--font-sans);
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 4px;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.mobile-nav-btn.active {
  color: var(--primary-text);
  background: var(--primary-soft);
}

@media (min-width: 900px) {
  .desktop-nav {
    display: block;
  }
  .mobile-bottom-nav {
    display: none;
  }
}

/* ============================================================================
   CONTENEDOR PRINCIPAL Y HERO DEGRADADO MODERNO
   ============================================================================ */
.app-container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 16px;
}

.view-section {
  display: none;
}

.view-section.active {
  display: block;
}

.botiquin-hero {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-lg);
  padding: 22px 22px 18px;
  margin-bottom: 16px;
  color: #ffffff;
  background: linear-gradient(135deg, #312e81 0%, #4f46e5 52%, #0284c7 100%);
  box-shadow: var(--shadow-md);
}

.botiquin-hero::after {
  content: '';
  position: absolute;
  top: -40px;
  right: -40px;
  width: 210px;
  height: 210px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  pointer-events: none;
}

.hero-top {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 18px;
}

@media (min-width: 720px) {
  .hero-top {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.hero-eyebrow {
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.78);
  margin-bottom: 2px;
}

.hero-title {
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: #ffffff;
}

.hero-subtitle {
  font-size: 0.88rem;
  color: rgba(255, 255, 255, 0.85);
  margin-top: 4px;
}

.btn-hero-cta {
  background: #ffffff;
  color: #312e81;
  border: none;
  font-weight: 800;
  padding: 11px 18px;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.22);
}

.btn-hero-cta:hover {
  background: #f8fafc;
}

/* 4 Píldoras de Filtro Rápido dentro del Hero */
.quick-filter-grid {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

@media (min-width: 820px) {
  .quick-filter-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px;
  }
}

.quick-filter-card {
  text-align: left;
  font-family: var(--font-sans);
  background: rgba(15, 23, 42, 0.24);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: var(--radius-md);
  padding: 10px 10px;
  min-width: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 9px;
  cursor: pointer;
  color: #ffffff;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.quick-filter-card:hover {
  background: rgba(15, 23, 42, 0.36);
  border-color: rgba(255, 255, 255, 0.34);
}

.quick-filter-card.active {
  background: rgba(255, 255, 255, 0.22);
  border-color: #ffffff;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.22);
}

.quick-filter-card.alert-yellow:not(.active) {
  border-color: rgba(251, 191, 36, 0.55);
}

.quick-filter-card.alert-red:not(.active) {
  border-color: rgba(251, 113, 133, 0.65);
}

.qf-icon-box {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.16);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: #ffffff;
}

.qf-icon-amber {
  background: rgba(245, 158, 11, 0.32);
  color: #fde68a;
}

.qf-icon-red {
  background: rgba(244, 63, 94, 0.34);
  color: #fecdd3;
}

.qf-icon-sky {
  background: rgba(56, 189, 248, 0.28);
  color: #bae6fd;
}

.qf-body {
  min-width: 0;
}

.qf-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: rgba(255, 255, 255, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.qf-value {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 800;
  color: #ffffff !important;
  line-height: 1.2;
}

.qf-sub {
  font-size: 0.73rem;
  color: rgba(255, 255, 255, 0.74);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ============================================================================
   BARRA DE BÚSQUEDA Y FILTROS SIMÉTRICA (CERO DESCOMPAGINACIÓN)
   ============================================================================ */
.search-toolbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
  background: var(--bg-surface);
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-xs);
}

.search-box {
  position: relative;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  display: inline-flex;
  align-items: center;
}

.filter-controls-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

@media (min-width: 540px) {
  .filter-controls-row {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 920px) {
  .filter-controls-row {
    grid-template-columns: 1.1fr 1fr 1.15fr auto;
    align-items: center;
  }
}

.toolbar-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 18px;
  background: var(--bg-surface);
  padding: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-xs);
}

@media (min-width: 820px) {
  .toolbar-panel {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.input, .select, .textarea {
  width: 100%;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background-color: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.94rem;
  min-height: 44px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.select option {
  background-color: var(--bg-surface);
  color: var(--text-primary);
}

.search-box .input {
  padding-left: 40px;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}

.filter-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

/* ============================================================================
   BOTONES MODERNOS
   ============================================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 15px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  transition: background-color 0.15s ease, transform 0.08s ease, border-color 0.15s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-lg {
  padding: 13px 18px;
  min-height: 48px;
  font-size: 1rem;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-surface-alt);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

.btn-secondary:hover {
  background: var(--bg-surface-hover);
}

.btn-danger {
  background: var(--status-red-bg);
  color: var(--status-red-text);
  border-color: var(--status-red-border);
}

.btn-danger:hover {
  filter: brightness(1.06);
}

.btn-sm {
  padding: 7px 12px;
  min-height: 36px;
  font-size: 0.81rem;
}

.multi-select-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px 14px;
  margin-bottom: 16px;
  background: var(--status-red-bg);
  border: 1px solid var(--status-red-border);
  border-radius: var(--radius-md);
}

.multi-select-bar.hidden {
  display: none !important;
}

.discrete-valuation-details {
  margin-top: 22px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 13px 16px;
}

.discrete-valuation-details summary {
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  list-style: none;
}

.discrete-valuation-content {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
}

.adv-subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.adv-tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface-alt);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  flex: 1 1 auto;
  justify-content: center;
}

.adv-tab-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.adv-subview {
  display: none;
}

.adv-subview.active {
  display: block;
}

.subsection-heading {
  font-size: 0.88rem;
  font-weight: 800;
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-secondary);
}

/* ============================================================================
   GRILLA DE MEDICAMENTOS Y TARJETAS MODERNAS
   ============================================================================ */
.meds-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

@media (min-width: 680px) {
  .meds-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1080px) {
  .meds-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.med-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}

.med-card:hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}

.med-card.selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-soft);
}

.med-card.expired {
  border-left: 4px solid var(--status-red-text);
}

.med-card.expiring-soon {
  border-left: 4px solid var(--status-yellow-text);
}

.med-card.valid-expiry {
  border-left: 4px solid var(--status-green-text);
}

.med-expiry-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 10px;
}

.med-expiry-pill {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--radius-full);
}

.med-select-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--primary-text);
  cursor: pointer;
}

.med-select-checkbox {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
  cursor: pointer;
}

.med-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.med-brand {
  font-size: 1.12rem;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.25;
}

.med-generic {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--primary-text);
  margin-top: 2px;
}

.med-format-pill {
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--bg-surface-alt);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.med-stock-box {
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.stock-breakdown {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 500;
}

.stock-total-pill {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-surface);
  padding: 4px 10px;
  border-radius: 7px;
  border: 1px solid var(--border-subtle);
}

.med-badges {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: var(--radius-full);
  font-size: 0.74rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.badge-green {
  background: var(--status-green-bg);
  color: var(--status-green-text);
  border-color: var(--status-green-border);
}

.badge-yellow {
  background: var(--status-yellow-bg);
  color: var(--status-yellow-text);
  border-color: var(--status-yellow-border);
}

.badge-red {
  background: var(--status-red-bg);
  color: var(--status-red-text);
  border-color: var(--status-red-border);
}

.badge-currency {
  background: var(--currency-bg);
  color: var(--currency-text);
  border-color: var(--currency-border);
  font-family: var(--font-mono);
}

.med-valuation-box {
  font-size: 0.8rem;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--currency-bg);
  color: var(--currency-text);
  border: 1px solid var(--currency-border);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.valuation-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.valuation-homogenea {
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.9rem;
}

.med-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-subtle);
}

.med-footer-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.med-footer-actions .btn {
  padding: 8px 6px;
  font-size: 0.8rem;
  min-height: 38px;
}

.med-location {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.78rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================================
   MÓDULO FAMILIAR: PERFILES, TRATAMIENTOS Y TOMAS SIMULTÁNEAS
   ============================================================================ */
.family-chips-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.member-chip-group {
  display: inline-flex;
  align-items: center;
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
  overflow: hidden;
  transition: all 0.15s ease;
}

.member-chip-group.active {
  background: var(--primary);
  border-color: var(--primary);
}

.member-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.86rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

.member-chip-group.active .member-chip {
  color: #fff;
}

.member-chip.standalone {
  border-radius: var(--radius-full);
  border: 1px solid var(--border-strong);
  background: var(--bg-surface);
}

.member-chip.standalone.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.member-delete-x {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 36px;
  border: none;
  border-left: 1px solid var(--border-subtle);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.member-delete-x:hover {
  background: var(--status-red-bg);
  color: var(--status-red-text);
}

.member-chip-group.active .member-delete-x {
  color: rgba(255, 255, 255, 0.85);
  border-left-color: rgba(255, 255, 255, 0.25);
}

.member-chip-group.active .member-delete-x:hover {
  background: rgba(0, 0, 0, 0.18);
  color: #fff;
}

.member-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.72rem;
  font-weight: 800;
  color: #fff;
}

.member-modal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
}

.treatments-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 980px) {
  .treatments-layout {
    grid-template-columns: 1.35fr 1fr;
  }
}

.treatment-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-xs);
}

.treatment-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}

.treatment-title {
  font-size: 1.02rem;
  font-weight: 800;
}

.simultaneous-pills-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
  padding: 10px 12px;
  background: var(--bg-surface-alt);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

.simultaneous-pill-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.86rem;
}

.pill-dose-tag {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.8rem;
  padding: 2px 8px;
  border-radius: 6px;
  background: var(--primary-soft);
  color: var(--primary-text);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.85rem;
}

/* ============================================================================
   CARGA MASIVA / TABLAS / MODALES / TOASTS
   ============================================================================ */
.bulk-banner {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

@media (min-width: 860px) {
  .bulk-banner {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
  }
}

.bulk-table-wrapper {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  overflow-x: auto;
  box-shadow: var(--shadow-xs);
}

.bulk-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 1050px;
  font-size: 0.84rem;
}

.bulk-table th {
  background: var(--bg-surface-alt);
  color: var(--text-secondary);
  font-weight: 700;
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border-strong);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.bulk-table td {
  padding: 6px 6px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}

.bulk-input {
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-input);
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 0.83rem;
}

.bulk-input.mono {
  font-family: var(--font-mono);
}

.bulk-input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--bg-surface);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(2, 6, 23, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-backdrop.hidden {
  display: none !important;
}

.modal-dialog {
  width: 100%;
  max-width: 620px;
  max-height: 90vh;
  overflow-y: auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg);
  padding: 22px;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-subtle);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 560px) {
  .form-grid-2 {
    grid-template-columns: repeat(2, 1fr);
  }
  .form-grid-3 {
    grid-template-columns: repeat(3, 1fr);
  }
}

.form-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.catalog-picker-box {
  margin-bottom: 14px;
  padding: 12px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
}

.catalog-suggestions {
  max-height: 195px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-surface);
}

.catalog-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.85rem;
}

.catalog-item:hover {
  background: var(--primary-soft);
}

.widget-config-layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 20px;
}

@media (min-width: 900px) {
  .widget-config-layout {
    grid-template-columns: 1.05fr 0.95fr;
  }
}

.section-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--shadow-xs);
}

.url-output-box {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  padding: 12px;
  background: var(--bg-surface-alt);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  word-break: break-all;
  margin: 10px 0;
}

.toast-container {
  position: fixed;
  bottom: 78px;
  right: 16px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

@media (min-width: 900px) {
  .toast-container {
    bottom: 24px;
  }
}

.toast {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
  padding: 11px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  max-width: 360px;
}

@media (max-width: 520px) {
  .brand-icon {
    width: 32px;
    height: 32px;
  }
  .brand-text h1 {
    font-size: 0.96rem;
  }
  .header-actions {
    gap: 6px;
  }
  .sync-badge {
    padding: 5px 9px;
    font-size: 0.72rem;
  }
  .app-container {
    padding: 14px 12px;
  }
  .botiquin-hero {
    padding: 16px 14px 14px;
  }
  .hero-title {
    font-size: 1.35rem;
  }
  .quick-filter-card {
    padding: 10px 10px;
    gap: 8px;
  }
  .qf-icon-box {
    width: 30px;
    height: 30px;
  }
  .qf-value {
    font-size: 0.98rem;
  }
  .modal-dialog {
    padding: 16px;
  }
}
