* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

main,
section,
article,
div,
header,
nav {
  min-width: 0;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 16px;
  background: var(--surface);
  border-right: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
  font-weight: 800;
}

.brand-mark {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--primary);
  color: #fff;
  font-size: 13px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav-link {
  padding: 12px 14px;
  border-radius: var(--radius);
  color: var(--muted);
  font-weight: 650;
}

.nav-link:hover,
.nav-link.active {
  background: var(--primary-soft);
  color: var(--primary);
}

.main-area {
  min-width: 0;
}

.topbar {
  position: sticky;
  z-index: 5;
  top: 0;
  display: flex;
  align-items: center;
  gap: 14px;
  justify-content: space-between;
  padding: 16px 28px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}

.search-box {
  display: flex;
  align-items: center;
  width: min(520px, 100%);
  min-width: 0;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
}

.search-box span {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.global-search-results {
  position: absolute;
  top: calc(100% + 8px);
  left: 28px;
  z-index: 40;
  width: min(520px, calc(100vw - 56px));
  max-height: min(460px, calc(100vh - 110px));
  overflow: auto;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.global-search-results[hidden] {
  display: none;
}

.search-result {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 10px;
  align-items: center;
  padding: 10px;
  color: var(--text);
  text-decoration: none;
  border-radius: 8px;
}

.search-result:hover {
  background: var(--surface-soft);
}

.search-result strong,
.search-result small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.search-result small {
  grid-column: 2;
  color: var(--muted);
}

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

.page {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 30px 28px 96px;
}

.page-header,
.profile-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 24px;
}

.profile-hero {
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  justify-content: flex-start;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 8px;
  font-size: clamp(28px, 4vw, 40px);
  line-height: 1.05;
}

h2 {
  margin-bottom: 14px;
  font-size: 18px;
}

.eyebrow {
  margin-bottom: 8px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 750;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.button:hover,
.icon-button:hover {
  transform: translateY(-1px);
  border-color: var(--primary);
}

.button.primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.button.secondary {
  background: var(--surface-soft);
}

.button.secondary.active {
  background: var(--primary-soft);
  color: var(--primary);
  border-color: var(--primary);
}

.button.danger {
  background: color-mix(in srgb, var(--danger) 10%, var(--surface));
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, var(--border));
}

.button.full {
  width: 100%;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.metric-card,
.panel,
.pet-card,
.record-card,
.alert-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 18px;
}

.metric-card strong {
  display: block;
  margin: 8px 0;
  font-size: 28px;
}

.metric-label,
dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.metric-card small {
  color: var(--muted);
}

.accent-blue {
  border-top: 4px solid var(--primary);
}

.accent-teal {
  border-top: 4px solid var(--secondary);
}

.accent-amber {
  border-top: 4px solid var(--warning);
}

.content-grid,
.calendar-layout {
  display: grid;
  grid-template-columns: 1.25fr 0.85fr;
  gap: 18px;
  margin-bottom: 18px;
}

.panel {
  padding: 20px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-title h2 {
  margin-bottom: 0;
}

.panel-title a {
  color: var(--primary);
  font-weight: 750;
}

.timeline {
  display: grid;
  gap: 12px;
}

.timeline-item {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 12px;
  padding: 12px;
  background: var(--surface-soft);
  border-radius: var(--radius);
}

.timeline-item span {
  color: var(--primary);
  font-weight: 800;
}

.timeline-item.urgent span {
  color: var(--danger);
}

.timeline-item p,
.record-card p {
  margin-bottom: 0;
  color: var(--muted);
}

.attachment-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.attachment-list a {
  padding: 6px 8px;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 800;
  text-decoration: none;
}

.expense-list,
.records,
.form-grid,
.member-list {
  display: grid;
  gap: 12px;
}

.expense-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.expense-row span {
  display: grid;
  gap: 4px;
}

.expense-row small {
  color: var(--muted);
}

.action-row,
.mini-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}

.mini-actions button,
.mini-actions a {
  border: 0;
  background: transparent;
  color: var(--primary);
  cursor: pointer;
  font-weight: 800;
  padding: 0;
  text-decoration: none;
}

.compact-field {
  display: grid;
  gap: 4px;
  min-width: 150px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.compact-field select {
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text);
}

.expense-row:last-child {
  border-bottom: 0;
}

.alert-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.alert-card {
  padding: 14px;
  background: var(--surface-soft);
  box-shadow: none;
}

.alert-card.is-read {
  opacity: 0.62;
}

.alert-actions {
  justify-content: flex-end;
}

.alert-card strong {
  display: block;
  margin: 8px 0 4px;
}

.alert-card p {
  margin-bottom: 0;
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.badge.success {
  background: color-mix(in srgb, var(--success) 18%, transparent);
  color: var(--success);
}

.badge.warning {
  background: color-mix(in srgb, var(--warning) 20%, transparent);
  color: var(--warning);
}

.badge.info {
  background: color-mix(in srgb, var(--info) 20%, transparent);
  color: var(--info);
}

.pet-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
}

.pet-card {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.pet-card h2 {
  margin-bottom: 4px;
}

.pet-card p {
  color: var(--muted);
}

.pet-card dl,
.detail-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.pet-card dl div,
.detail-list div {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

dd {
  margin: 0;
  font-weight: 700;
}

.pet-photo {
  display: grid;
  width: 72px;
  height: 72px;
  flex: 0 0 72px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  font-size: 28px;
  font-weight: 900;
}

.pet-photo:is(img) {
  object-fit: cover;
}

.pet-photo.large {
  width: 96px;
  height: 96px;
  flex-basis: 96px;
  font-size: 38px;
}

.luna {
  background: linear-gradient(135deg, #2563eb, #14b8a6);
}

.milo {
  background: linear-gradient(135deg, #f59e0b, #ef4444);
}

.roma {
  background: linear-gradient(135deg, #7c3aed, #38bdf8);
}

.hero-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab-list {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
}

.tab {
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

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

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.chart-bars {
  display: flex;
  align-items: end;
  gap: 12px;
  height: 220px;
  padding: 18px;
  background: var(--surface-soft);
  border-radius: var(--radius);
}

.chart-bars span {
  flex: 1;
  min-height: 24px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: linear-gradient(180deg, var(--primary), var(--secondary));
}

.chart-bars.horizontal {
  display: grid;
  align-items: center;
  height: auto;
}

.chart-bars.horizontal span {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding-left: 12px;
  color: #fff;
  border-radius: var(--radius);
  font-weight: 800;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 8px;
}

.calendar-title {
  margin-bottom: 16px;
}

.calendar-grid strong {
  display: grid;
  min-height: 30px;
  place-items: center;
  color: var(--muted);
}

.calendar-day {
  display: grid;
  align-content: start;
  min-height: 92px;
  padding: 10px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: border-color 0.2s ease, transform 0.2s ease, background 0.2s ease;
}

.calendar-day:hover {
  border-color: var(--primary);
  transform: translateY(-1px);
}

.calendar-day strong {
  display: block;
  min-height: auto;
  color: inherit;
  font-size: 0.95rem;
  margin-bottom: 7px;
}

.calendar-day.muted {
  opacity: 0.52;
}

.calendar-grid .today {
  border-color: var(--primary);
  color: var(--primary);
}

.calendar-grid .selected {
  box-shadow: 0 0 0 2px var(--primary);
}

.calendar-grid .has-event {
  background: var(--primary-soft);
}

.calendar-events {
  display: grid;
  gap: 4px;
}

.calendar-event {
  overflow: hidden;
  padding: 4px 6px;
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.calendar-event.vacuna {
  color: var(--primary);
}

.calendar-event.desparasitacion {
  color: var(--success);
}

.calendar-event.medicamento {
  color: var(--danger);
}

.calendar-event.cumpleanos {
  color: var(--warning);
}

.form-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 750;
}

.export-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
}

.export-grid .action-row {
  grid-column: 1 / -1;
}

.form-fieldset {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.form-fieldset legend {
  padding: 0 6px;
  color: var(--text);
  font-weight: 800;
}

.form-fieldset p {
  margin: 0;
}

.check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.check-pill {
  display: inline-flex !important;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px !important;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text) !important;
  cursor: pointer;
}

.check-pill input {
  min-height: auto;
  padding: 0;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
  min-height: 42px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--text);
}

.form-grid textarea {
  min-height: 90px;
  padding: 10px 12px;
  resize: vertical;
}

.empty-state {
  grid-column: 1 / -1;
}

.modal-backdrop {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.42);
}

.modal-panel {
  width: min(560px, 100%);
  max-height: min(760px, 92vh);
  overflow: auto;
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.family-card,
.member-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.family-card {
  margin-bottom: 14px;
}

.family-card strong {
  display: block;
  margin: 6px 0;
  font-size: 22px;
}

.member-row {
  justify-content: flex-start;
}

.member-row > div:nth-child(2) {
  flex: 1;
}

.member-row p {
  margin: 4px 0 0;
  color: var(--muted);
}

.member-avatar {
  display: grid;
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  place-items: center;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 900;
}

.member-avatar.teal {
  background: var(--secondary);
}

.member-avatar.amber {
  background: var(--warning);
}

.switch-row {
  display: flex !important;
  grid-template-columns: auto 1fr;
  align-items: center;
}

.auth-page {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  width: min(440px, 100%);
  padding: 26px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-panel .brand {
  margin-bottom: 22px;
}

.auth-link {
  margin: 18px 0 0;
  color: var(--muted);
}

.auth-link a {
  color: var(--primary);
  font-weight: 800;
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
}

.form-message.error {
  color: var(--danger);
}

.form-message.success {
  color: var(--success);
}

.mobile-nav {
  display: none;
}

@media (max-width: 1023px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .summary-grid,
  .pet-grid,
  .alert-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .content-grid,
  .calendar-layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 767px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

  .topbar {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 12px 14px;
  }

  .search-box {
    width: auto;
  }

  .global-search-results {
    right: 14px;
    left: 14px;
    width: auto;
  }

  .topbar .icon-button {
    min-height: 42px;
    padding: 0 10px;
    font-size: 12px;
    white-space: nowrap;
  }

  .topbar-actions {
    justify-content: flex-end;
  }

  .page {
    width: 100%;
    max-width: 100vw;
    padding: 20px 14px 92px;
    overflow-x: hidden;
  }

  .page-header,
  .profile-hero {
    align-items: stretch;
    flex-direction: column;
  }

  .page-header .button,
  .profile-hero .button {
    width: 100%;
  }

  .family-card,
  .member-row {
    align-items: stretch;
    flex-direction: column;
  }

  .summary-grid,
  .pet-grid,
  .alert-grid {
    grid-template-columns: 1fr;
  }

  .export-grid {
    grid-template-columns: 1fr;
  }

  .modal-backdrop {
    align-items: start;
    justify-items: center;
    padding: 10px;
    overflow-y: auto;
  }

  .modal-panel {
    width: 100%;
    max-width: calc(100vw - 20px);
    max-height: calc(100vh - 20px);
    padding: 14px;
    overflow-x: hidden;
  }

  .modal-panel .panel-title {
    align-items: stretch;
    flex-direction: column;
    gap: 10px;
  }

  .form-grid,
  .form-fieldset,
  .check-grid,
  .action-row {
    max-width: 100%;
    min-width: 0;
  }

  .form-grid input,
  .form-grid select,
  .form-grid textarea {
    width: 100%;
    max-width: 100%;
  }

  .metric-card strong {
    font-size: 24px;
  }

  .timeline-item {
    grid-template-columns: 62px 1fr;
  }

  .calendar-grid {
    gap: 6px;
  }

  .calendar-day {
    min-height: 66px;
    padding: 7px;
  }

  .calendar-event {
    font-size: 0.66rem;
  }

  .mobile-nav {
    position: fixed;
    z-index: 20;
    right: 10px;
    bottom: 10px;
    left: 10px;
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 4px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
  }

  .mobile-nav a {
    display: grid;
    min-width: 0;
    min-height: 38px;
    place-items: center;
    border-radius: var(--radius);
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

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