/* =====================================================================
   PetCare · Componentes reutilizables (tema «Cuidado Animal»)
   Botones, formularios, tarjetas, insignias, avisos, diálogos, pestañas,
   listas, línea de tiempo, estados vacíos y de carga.
   ===================================================================== */

/* ---------- Marca ---------- */
.brand { display: inline-flex; align-items: center; gap: var(--space-2); text-decoration: none; color: var(--primary); }
.brand:hover { text-decoration: none; }
.brand-logo { width: 38px; height: 38px; }
.brand-name { font-size: 1.5rem; font-weight: 900; letter-spacing: -0.02em; color: var(--primary); }
.brand-name span { color: var(--secondary); }

/* ---------- Botones (píldora, con elevación al pasar el cursor) ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: 44px; padding: 0 1.6rem;
  border: none; border-radius: var(--radius-full);
  font-weight: 800; font-size: var(--text-sm); line-height: 1; text-decoration: none;
  cursor: pointer; white-space: nowrap;
  transition: transform var(--transition), background var(--transition), color var(--transition), box-shadow var(--transition);
}
.btn:hover:not(:disabled) { transform: translateY(-3px) scale(1.03); text-decoration: none; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: var(--on-primary); box-shadow: var(--shadow); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); color: var(--on-primary); }
.btn-secondary { background: var(--secondary); color: var(--on-secondary); box-shadow: var(--shadow); }
.btn-secondary:hover:not(:disabled) { background: var(--secondary-hover); color: var(--on-secondary); }
.btn-ghost { background: transparent; color: var(--ink); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-alt); color: var(--ink); transform: none; }
.btn-danger { background: var(--accent); color: var(--on-accent); box-shadow: var(--shadow); }
.btn-danger:hover:not(:disabled) { background: var(--accent-hover); color: var(--on-accent); }
.btn-warm { background: var(--accent-2); color: var(--on-accent-2); box-shadow: var(--shadow); }
.btn-warm:hover:not(:disabled) { background: var(--accent-2-hover); color: var(--on-accent-2); }
.btn-sm { min-height: 36px; padding: 0 var(--space-4); font-size: var(--text-xs); }
.btn-lg { min-height: 54px; padding: 0 2rem; font-size: var(--text-md); }
.btn-block { width: 100%; }
.btn-icon { width: 44px; padding: 0; }
.btn-icon.btn-sm { width: 36px; }
.btn .spinner { width: 16px; height: 16px; border-width: 2px; }

.btn-row { display: flex; flex-wrap: wrap; gap: var(--space-2); align-items: center; }
.btn-row.end { justify-content: flex-end; }

/* ---------- Formularios ---------- */
.form { display: grid; gap: var(--space-4); }
.form-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.field { display: grid; gap: var(--space-1); min-width: 0; }
.field-full { grid-column: 1 / -1; }
.label { font-weight: 700; font-size: var(--text-sm); color: var(--ink); }
.label .optional { font-weight: 500; color: var(--muted); }
.hint { font-size: var(--text-xs); color: var(--muted); }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 0.7rem 1rem;
  color: var(--ink); background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius-sm);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.textarea { min-height: 100px; resize: vertical; line-height: 1.5; }
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-strong); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--secondary); box-shadow: var(--focus); }
.input[aria-invalid="true"], .select[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--accent); }
.input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-alt); cursor: not-allowed; }
.field-error { font-size: var(--text-xs); color: var(--accent); font-weight: 700; }
.field-error:empty { display: none; }
.input-group { display: flex; align-items: stretch; }
.input-group .input { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.input-group .addon {
  display: grid; place-items: center; padding: 0 var(--space-3); background: var(--surface-alt);
  border: 2px solid var(--line); border-left: 0; border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: var(--text-sm); color: var(--muted); font-weight: 700;
}
.check { display: flex; gap: var(--space-2); align-items: flex-start; font-size: var(--text-sm); cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); flex-shrink: 0; }
.segmented { display: inline-flex; flex-wrap: wrap; gap: var(--space-2); }
.segmented label {
  display: inline-flex; align-items: center; gap: var(--space-2); padding: var(--space-2) var(--space-4);
  border: 2px solid var(--line); border-radius: var(--radius-full); cursor: pointer; font-weight: 700;
  font-size: var(--text-sm); background: var(--surface); transition: all var(--transition);
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label:has(input:checked) { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.segmented label:has(input:focus-visible) { box-shadow: var(--focus); }
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
legend { padding: 0; margin-bottom: var(--space-2); }

/* ---------- Tarjetas (borde superior de color; en cuadrículas los colores se alternan) ---------- */
.card {
  background: var(--surface); border: 2px solid var(--line); border-top: 6px solid var(--primary);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: var(--space-5);
  transition: transform var(--transition), border-color var(--transition);
}
.grid > .card:nth-child(4n+2), .grid > .stat:nth-child(4n+2) { border-top-color: var(--secondary); }
.grid > .card:nth-child(4n+3), .grid > .stat:nth-child(4n+3) { border-top-color: var(--accent); }
.grid > .card:nth-child(4n+4), .grid > .stat:nth-child(4n+4) { border-top-color: var(--accent-2); }
.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.card-header h2, .card-header h3 { margin: 0; }
.card-title { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-lg); font-weight: 800; color: var(--primary); margin: 0; }
.card-title .icon { color: var(--secondary); }
.card-link { font-size: var(--text-sm); font-weight: 800; }
.card-flat { box-shadow: none; }
.card-muted { background: var(--surface-alt); }

/* ---------- Insignias de estado (etiquetas) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px; padding: 0.15rem 0.8rem; border-radius: var(--radius-full);
  font-size: var(--text-xs); font-weight: 800; line-height: 1.6; white-space: nowrap;
}
.badge .icon { width: 14px; height: 14px; }
.badge-aplicada, .badge-ok { background: var(--ok-bg); color: var(--ok-fg); }
.badge-proxima, .badge-warn { background: var(--warn-bg); color: var(--warn-fg); }
.badge-vencida, .badge-danger { background: var(--danger-bg); color: var(--danger-fg); }
.badge-pendiente, .badge-info { background: var(--info-bg); color: var(--info-fg); }
.badge-neutral { background: var(--neutral-bg); color: var(--neutral-fg); }
.badge-demo { background: var(--accent-2-soft); color: var(--ink); border: 1px solid var(--accent-2); }

/* ---------- Avisos ---------- */
.alert {
  display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm); border: 2px solid transparent; font-size: var(--text-sm); color: var(--ink);
}
.alert .icon { margin-top: 2px; flex-shrink: 0; }
.alert p { color: var(--ink); }
.alert p:last-child { margin-bottom: 0; }
.alert-info { background: var(--secondary-soft); border-color: var(--secondary); }
.alert-info .icon { color: var(--secondary); }
.alert-warn { background: var(--accent-2-soft); border-color: var(--accent-2); }
.alert-warn .icon { color: var(--accent-2); }
.alert-danger { background: var(--accent-soft); border-color: var(--accent); }
.alert-danger .icon { color: var(--accent); }
.alert-ok { background: var(--success-soft); border-color: var(--success); }
.alert-ok .icon { color: var(--success); }
.alert-title { font-weight: 800; margin-bottom: 2px; }

/* ---------- Avisos flotantes (toasts) ---------- */
.toast-region {
  position: fixed; z-index: 900; right: var(--space-4); bottom: calc(var(--space-4) + env(safe-area-inset-bottom));
  display: grid; gap: var(--space-2); width: min(380px, calc(100vw - 2rem));
}
.toast {
  display: flex; gap: var(--space-3); align-items: center; padding: var(--space-3) var(--space-4);
  background: var(--surface); color: var(--ink); border: 2px solid var(--line); border-left: 6px solid var(--secondary);
  border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: var(--text-sm); font-weight: 700;
  animation: toast-in 200ms ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--accent); }
.toast button { margin-left: auto; background: none; border: 0; color: inherit; cursor: pointer; padding: 0; opacity: 0.7; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Diálogos ---------- */
dialog.modal {
  width: min(560px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); padding: 0;
  border: 2px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
  color: var(--ink); background: var(--surface);
}
dialog.modal.modal-wide { width: min(760px, calc(100vw - 2rem)); }
dialog.modal::backdrop { background: var(--backdrop); }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 2px solid var(--line); }
.modal-header h2 { margin: 0; font-size: var(--text-lg); }
.modal-body { padding: var(--space-5); overflow-y: auto; max-height: calc(100vh - 12rem); }
.modal-footer { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: var(--space-2); padding: var(--space-4) var(--space-5); border-top: 2px solid var(--line); background: var(--surface-alt); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

/* ---------- Pestañas ---------- */
.tabs { display: flex; gap: var(--space-1); border-bottom: 2px solid var(--line); overflow-x: auto; scrollbar-width: thin; margin-bottom: var(--space-5); }
.tab {
  display: inline-flex; align-items: center; gap: var(--space-2); padding: var(--space-3) var(--space-4);
  background: none; border: 0; border-bottom: 3px solid transparent; margin-bottom: -2px; color: var(--muted);
  font-weight: 800; font-size: var(--text-sm); cursor: pointer; white-space: nowrap; transition: color var(--transition), border-color var(--transition);
}
.tab:hover { color: var(--secondary); border-bottom-color: var(--secondary); }
.tab[aria-selected="true"] { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- Listas de registros ---------- */
.list { display: grid; gap: var(--space-3); list-style: none; padding: 0; margin: 0; }
.list-item {
  display: flex; gap: var(--space-4); align-items: flex-start; padding: var(--space-4);
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius-sm);
}
.list-item-main { flex: 1; min-width: 0; }
.list-item-title { font-weight: 800; color: var(--ink); margin: 0 0 2px; overflow-wrap: anywhere; }
.list-item-meta { display: flex; flex-wrap: wrap; gap: var(--space-1) var(--space-3); font-size: var(--text-sm); color: var(--muted); }
.list-item-meta span { display: inline-flex; align-items: center; gap: 4px; }
.list-item-actions { display: flex; gap: var(--space-1); flex-wrap: wrap; justify-content: flex-end; }
.list-item.is-vencida { border-left: 6px solid var(--accent); }
.list-item.is-proxima { border-left: 6px solid var(--accent-2); }
.list-item.is-unread { background: var(--secondary-soft); border-color: var(--secondary); }

/* Tabla adaptable: en pantallas pequeñas cada fila se muestra como tarjeta */
.table-wrap { overflow-x: auto; border: 2px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th, .table td { padding: var(--space-3) var(--space-4); text-align: left; border-bottom: 1px solid var(--line); vertical-align: top; }
.table th { background: var(--surface-alt); color: var(--ink-soft); font-weight: 800; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.04em; }
.table tr:last-child td { border-bottom: 0; }
@media (max-width: 720px) {
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: var(--space-3) 0; border-bottom: 1px solid var(--line); }
  .table td { border: 0; padding: var(--space-1) var(--space-4); }
  .table td[data-label]::before { content: attr(data-label) ": "; font-weight: 800; color: var(--ink-soft); }
}

/* ---------- Avatar de mascota ---------- */
.avatar {
  width: 56px; height: 56px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  display: grid; place-items: center; background: var(--primary-soft); color: var(--primary);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.gato { background: var(--secondary-soft); color: var(--secondary); }
.avatar .icon { width: 28px; height: 28px; }
.avatar-lg { width: 112px; height: 112px; }
.avatar-lg .icon { width: 52px; height: 52px; }
.avatar-sm { width: 40px; height: 40px; }
.avatar-sm .icon { width: 20px; height: 20px; }

/* ---------- Línea de tiempo (historial) ---------- */
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline::before { content: ""; position: absolute; left: 19px; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--line); }
.timeline-item { position: relative; display: flex; gap: var(--space-4); padding-bottom: var(--space-5); }
.timeline-dot {
  position: relative; z-index: 1; width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  display: grid; place-items: center; background: var(--surface); border: 3px solid var(--line);
}
.timeline-dot.vacuna { border-color: var(--success); color: var(--success); background: var(--success-soft); }
.timeline-dot.visita { border-color: var(--secondary); color: var(--secondary); background: var(--secondary-soft); }
.timeline-dot.medicion { border-color: var(--accent-2); color: var(--on-accent-2); background: var(--accent-2-soft); }
.timeline-dot.registro { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.timeline-dot.alta { border-color: var(--line-strong); color: var(--muted); }
.timeline-body { flex: 1; min-width: 0; padding: var(--space-3) var(--space-4); background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius-sm); }
.timeline-date { font-size: var(--text-xs); font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.timeline-title { font-weight: 800; color: var(--ink); margin: 2px 0 var(--space-1); overflow-wrap: anywhere; }
.timeline-details { margin: 0; padding: 0; list-style: none; font-size: var(--text-sm); color: var(--ink-soft); overflow-wrap: anywhere; }

/* ---------- Estados vacíos, carga y errores ---------- */
.empty {
  display: grid; justify-items: center; text-align: center; gap: var(--space-2);
  padding: var(--space-7) var(--space-4); background: var(--surface); border: 2px dashed var(--line-strong); border-radius: var(--radius);
}
.empty h3 { margin: 0; color: var(--primary); }
.empty p { max-width: 46ch; color: var(--muted); margin: 0 0 var(--space-2); }

.spinner {
  width: 28px; height: 28px; border: 3px solid var(--surface-alt); border-top-color: var(--primary);
  border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading { display: grid; justify-items: center; gap: var(--space-3); padding: var(--space-7) 0; color: var(--muted); }

.skeleton {
  background: linear-gradient(90deg, var(--surface-alt) 0%, var(--surface) 50%, var(--surface-alt) 100%);
  background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: var(--radius-sm);
}
.skeleton-card { height: 120px; border-radius: var(--radius); }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Estadísticas ---------- */
.stat {
  display: flex; gap: var(--space-4); align-items: center; padding: var(--space-4) var(--space-5);
  background: var(--surface); border: 2px solid var(--line); border-top: 6px solid var(--primary); border-radius: var(--radius); box-shadow: var(--shadow);
  text-decoration: none; color: inherit; transition: transform var(--transition), box-shadow var(--transition);
}
a.stat:hover { transform: translateY(-6px); color: inherit; text-decoration: none; }
.stat-icon { width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; flex-shrink: 0; }
.stat-icon .icon { width: 24px; height: 24px; }
.stat-icon.green { background: var(--primary-soft); color: var(--primary); }
.stat-icon.blue { background: var(--secondary-soft); color: var(--secondary); }
.stat-icon.warm { background: var(--accent-2-soft); color: var(--on-accent-2); }
.stat-icon.red { background: var(--accent-soft); color: var(--accent); }
.stat-value { font-size: var(--text-2xl); font-weight: 900; line-height: 1.1; color: var(--ink); }
.stat-label { font-size: var(--text-sm); color: var(--muted); font-weight: 700; }

/* ---------- Varios ---------- */
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 12px; border-radius: var(--radius-full); background: var(--surface-alt); color: var(--ink-soft); font-size: var(--text-xs); font-weight: 800; }
.divider-text { display: flex; align-items: center; gap: var(--space-3); color: var(--muted); font-size: var(--text-sm); }
.divider-text::before, .divider-text::after { content: ""; flex: 1; border-top: 2px solid var(--line); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: var(--space-2) var(--space-4); margin: 0; font-size: var(--text-sm); }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 700; color: var(--ink); overflow-wrap: anywhere; }
.disclaimer { display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4); border-radius: var(--radius-sm); background: var(--accent-2-soft); color: var(--ink); font-size: var(--text-sm); border: 2px solid var(--accent-2); }
.disclaimer .icon { color: var(--on-accent-2); margin-top: 2px; flex-shrink: 0; }
.disclaimer p { margin: 0; color: var(--ink); }

/* Selector de archivos accesible: el <input> está oculto visualmente y su <label> actúa como botón */
.file-trigger:focus-visible + .btn { box-shadow: var(--focus); }
.file-trigger + .btn { width: fit-content; }

/* Insignias que funcionan como filtros (botones) */
button.badge { border: 0; cursor: pointer; font-family: inherit; padding: 4px 12px; }
button.badge:hover { filter: brightness(0.96); }
button.badge[aria-pressed="true"] { box-shadow: inset 0 0 0 2px currentColor; }
details summary { cursor: pointer; color: var(--secondary); font-weight: 800; }

/* ---------- Mascota de PetCare (ver js/mascot.js) ---------- */
.mascota { display: inline-block; border-radius: 50%; flex-shrink: 0; object-fit: contain; vertical-align: middle; }
.mascota-xs { width: 32px; height: 32px; }
.mascota-sm { width: 56px; height: 56px; }
.mascota-md { width: 96px; height: 96px; }
.mascota-lg { width: 150px; height: 150px; }
.mascota-xl { width: min(280px, 70vw); height: auto; }
.toast .mascota { margin: -4px 0; }
.confirm-body { display: flex; gap: var(--space-4); align-items: flex-start; }
.confirm-body p { margin: 0; }
.empty .mascota { margin-bottom: var(--space-2); }
.page-title-row { display: flex; gap: var(--space-3); align-items: center; min-width: 0; }

/* ---------- Selector de tema (claro / oscuro / sistema) ---------- */
.theme-options { display: flex; flex-wrap: wrap; gap: var(--space-2); }
