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

:root {
  --green-50: #f0fdf4;
  --green-100: #dcfce7;
  --green-200: #bbf7d0;
  --green-400: #4ade80;
  --green-500: #22c55e;
  --green-600: #16a34a;
  --green-700: #15803d;
  --green-800: #166534;
  --emerald-500: #10b981;
  --emerald-600: #059669;
  --emerald-700: #047857;
  --stone-50: #fafaf9;
  --stone-100: #f5f5f4;
  --stone-200: #e7e5e4;
  --stone-300: #d6d3d1;
  --stone-400: #a8a29e;
  --stone-600: #57534e;
  --stone-700: #44403c;
  --stone-800: #292524;
  --amber-500: #f59e0b;
  --amber-600: #d97706;
  --red-500: #ef4444;
  --red-600: #dc2626;
  --blue-500: #3b82f6;
  --shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,.15);
  --radius: 12px;
}

html { font-size: 16px; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--stone-100);
  color: var(--stone-800);
  min-height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  padding: 0;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

header {
  background: var(--emerald-600);
  color: #fff;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}
header h1 { font-size: 1.2rem; font-weight: 700; }
.header-actions { display: flex; gap: 4px; align-items: center; }
#btn-export, #btn-install {
  background: none; border: none; color: #fff; font-size: 1.3rem;
  cursor: pointer; padding: 4px 8px; border-radius: 8px;
}
#btn-export:active, #btn-install:active { background: rgba(255,255,255,.2); }
.btn-install { display: none; }
.btn-install.visible { display: block; }
.hidden { display: none !important; }
.sync-status { font-size: .7rem; color: rgba(255,255,255,.8); margin-right: 4px; }
.sync-ok { color: #86efac; }
.sync-error { color: #fca5a5; }
.syncing { color: #fde68a; }

#tabs {
  display: flex;
  background: #fff;
  border-bottom: 1px solid var(--stone-200);
  position: sticky;
  top: 48px;
  z-index: 10;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.tab {
  flex: 1;
  min-width: 60px;
  padding: 10px 6px;
  border: none;
  background: none;
  font-size: .7rem;
  color: var(--stone-600);
  cursor: pointer;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: all .15s;
}
.tab.active {
  color: var(--emerald-700);
  border-bottom-color: var(--emerald-600);
  font-weight: 600;
}
.tab:active { background: var(--stone-100); }

main {
  flex: 1;
  padding: 16px;
  padding-bottom: 100px;
}

.tab-content { display: none; }
.tab-content.active { display: block; }

h2 {
  font-size: 1.1rem;
  color: var(--stone-700);
  margin-bottom: 8px;
}
.subtitle {
  font-size: .85rem;
  color: var(--stone-400);
  margin-bottom: 16px;
}

/* Forms */
form {
  background: #fff;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
form h2 { margin-bottom: 12px; }

.field { margin-bottom: 12px; }
.field label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--stone-600);
  margin-bottom: 4px;
}
.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

input[type="text"],
input[type="number"],
input[type="date"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--stone-200);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--stone-800);
  background: var(--stone-50);
  transition: border-color .15s;
  outline: none;
}
input:focus, select:focus { border-color: var(--emerald-500); }

select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2357534e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
}

.btn-primary {
  width: 100%;
  padding: 12px;
  background: var(--emerald-600);
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s;
}
.btn-primary:active { background: var(--emerald-700); }
.btn-danger {
  background: var(--red-500);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 6px 12px;
  font-size: .8rem;
  cursor: pointer;
}
.btn-danger:active { background: var(--red-600); }
.btn-sm {
  background: var(--stone-200);
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: .75rem;
  cursor: pointer;
  color: var(--stone-700);
}
.btn-sm:active { background: var(--stone-300); }
.btn-secondary {
  background: var(--emerald-500);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 10px;
  font-size: .75rem;
  cursor: pointer;
}
.btn-secondary:active { background: var(--emerald-600); }

/* Type options */
.type-options {
  display: flex;
  gap: 8px;
}
.type-opt {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding: 10px 6px;
  border: 2px solid var(--stone-200);
  border-radius: 8px;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  color: var(--stone-600);
  transition: all .15s;
}
.type-opt:has(input:checked) {
  border-color: var(--emerald-500);
  background: var(--green-50);
  color: var(--emerald-700);
}
.type-opt input { display: none; }
.type-icon { font-size: 1.5rem; margin-bottom: 2px; }

/* Info Box */
.info-box {
  background: var(--green-100);
  border: 1px solid var(--green-200);
  border-radius: 8px;
  padding: 10px;
  text-align: center;
  font-size: .9rem;
  margin-bottom: 12px;
  color: var(--green-800);
}

/* Lists */
.list { display: flex; flex-direction: column; gap: 8px; }

.card {
  background: #fff;
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 12px;
}
.card-body { flex: 1; }
.card-name { font-weight: 600; font-size: .95rem; }
.card-detail { font-size: .8rem; color: var(--stone-400); margin-top: 2px; }
.card-amount { font-size: 1.1rem; font-weight: 700; color: var(--emerald-600); }
.card-actions { display: flex; gap: 6px; align-items: center; }
.card-status {
  font-size: .7rem;
  padding: 2px 8px;
  border-radius: 99px;
  font-weight: 600;
}
.card-status.ok { background: var(--green-500); color: #fff; }
.card-status.warning { background: var(--amber-500); color: #fff; }
.card-status.urgent { background: var(--red-500); color: #fff; }

/* Horse card */
.horse-card {
  cursor: pointer;
  transition: transform .1s;
}
.horse-card:active { transform: scale(.98); }
.horse-icon { font-size: 2rem; }
.horse-type {
  font-size: .7rem;
  color: var(--stone-400);
  text-transform: uppercase;
  letter-spacing: .5px;
}

/* Add card */
.add-card {
  border: 2px dashed var(--stone-300);
  background: var(--stone-50);
  color: var(--stone-600);
}
.add-card:hover {
  border-color: var(--emerald-500);
  background: var(--green-50);
}
.add-card .horse-icon {
  color: var(--emerald-600);
}
.add-card .card-name {
  color: var(--emerald-700);
}

/* Treatment card */
.treatment-card {
  align-items: flex-start;
  flex-direction: column;
  gap: 6px;
}
.treatment-card .card-row {
  display: flex;
  justify-content: space-between;
  width: 100%;
  align-items: center;
}
.treatment-card .card-detail { font-size: .75rem; }
.treatment-badge {
  font-size: .65rem;
  padding: 2px 6px;
  border-radius: 4px;
  font-weight: 600;
}
.treatment-badge.vacuna { background: #dbeafe; color: #1d4ed8; }
.treatment-badge.desparasitacion { background: #fef3c7; color: #b45309; }
.treatment-badge.curacion { background: #fce7f3; color: #be185d; }
.treatment-badge.suplemento { background: #d1fae5; color: #047857; }
.treatment-badge.revision { background: #e0e7ff; color: #4338ca; }
.treatment-badge.otro { background: var(--stone-200); color: var(--stone-600); }

/* Alert card */
.alert-card {
  border-left: 4px solid var(--amber-500);
}
.alert-card.urgent {
  border-left-color: var(--red-500);
  background: #fef2f2;
}
.alert-days {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--amber-600);
}
.alert-card.urgent .alert-days {
  color: var(--red-600);
}

/* Empty state */
.empty-msg {
  text-align: center;
  color: var(--stone-400);
  padding: 40px 16px;
  font-size: .9rem;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal.hidden { display: none; }
.modal-content {
  background: #fff;
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 340px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}
.modal-content p { margin-bottom: 20px; font-size: 1.05rem; font-weight: 500; }
.modal-large {
  max-width: 400px;
  text-align: left;
}
.modal-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.modal-actions .btn-primary { flex: 1; }
.modal-actions .btn-sm { flex: 1; }

/* Horse detail in modal */
.horse-detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--stone-200);
}
.horse-detail-icon { font-size: 3rem; }
.horse-detail-name { font-size: 1.3rem; font-weight: 700; }
.horse-detail-type { font-size: .85rem; color: var(--stone-400); }
.horse-detail-notes { font-size: .85rem; color: var(--stone-600); margin-top: 4px; }
.horse-detail-section {
  margin-top: 12px;
}
.horse-detail-section h3 {
  font-size: .9rem;
  color: var(--stone-600);
  margin-bottom: 8px;
}

/* Date display */
.date-display {
  font-size: .75rem;
  color: var(--stone-400);
}

@media (min-width: 481px) {
  body { border-left: 1px solid var(--stone-200); border-right: 1px solid var(--stone-200); }
}