:root {
  --primary: #0f766e;
  --primary-dark: #115e59;
  --primary-soft: #ccfbf1;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #b91c1c;
  --radius: 14px;
  --med: #2563eb;
  --bp: #dc2626;
  --head: #9333ea;
  --diarrhea: #b45309;
  --vomit: #65a30d;
  --vertigo: #0891b2;
  --note: #475569;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
}
a { color: var(--primary); }
h1 { font-size: 1.4rem; margin: .4rem 0 1rem; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
small, .muted { color: var(--muted); }
.center { text-align: center; }
.empty { text-align: center; padding: 1.5rem 0; }

.container { max-width: 760px; margin: 0 auto; padding: 1rem 16px 3rem; }

/* Barra superior */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  padding: .6rem 16px;
  background: var(--primary); color: #fff;
}
.topbar a, .topbar .link { color: #fff; text-decoration: none; }
.brand { font-weight: 700; white-space: nowrap; }
.topbar nav { display: flex; align-items: center; gap: .15rem; flex-wrap: wrap; justify-content: flex-end; }
.topbar nav a, .topbar nav .link { padding: .35rem .6rem; border-radius: 999px; font-size: .95rem; }
.topbar nav a.active { background: rgba(255,255,255,.2); }
.topbar form { display: inline; margin: 0; }

.subnav { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.subnav a { padding: .4rem .8rem; border-radius: 999px; background: var(--card); border: 1px solid var(--border); text-decoration: none; color: var(--text); font-size: .95rem; }
.subnav a.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }

/* Mensajes */
.flash { padding: .75rem 1rem; border-radius: var(--radius); margin: 0 0 1rem; transition: opacity .6s; }
.flash.notice { background: var(--primary-soft); color: var(--primary-dark); }
.flash.alert, .errors { background: #fee2e2; color: var(--danger); }
.flash.fade { opacity: 0; }
.errors { padding: .6rem 1rem; border-radius: var(--radius); }
.errors p { margin: .2rem 0; }

/* Botones */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 46px; padding: .55rem 1.1rem;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-dark); }
.btn.danger { color: var(--danger); border-color: #fecaca; background: #fff; }
.btn.block { display: flex; width: 100%; }
.btn.big { min-height: 56px; font-size: 1.15rem; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--primary); cursor: pointer; text-decoration: underline; }
.link.danger { color: var(--danger); }
form.button_to { display: inline; margin: 0; }
main > form.button_to { display: block; margin-top: 1.5rem; }

/* Tarjetas y formularios */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem; }
.form { display: flex; flex-direction: column; gap: 1rem; }
.form label { display: block; font-weight: 600; }
.form label > input, .form label > textarea, .form label > select, .form label > .autocomplete { display: block; margin-top: .3rem; }
.form label.inline { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.form label.inline > input { display: inline-block; flex: none; margin: 0; }
.optional { font-weight: 400; color: var(--muted); font-size: .9rem; }
input[type=text], input[type=password], input[type=number], input[type=date], input[type=datetime-local], textarea, select {
  width: 100%; min-height: 48px; padding: .6rem .8rem;
  border: 1px solid #cbd5e1; border-radius: 10px;
  font: inherit; font-weight: 400; color: var(--text); background: #fff;
}
input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; border-color: var(--primary); }
textarea { resize: vertical; }
.hint { margin: 0 0 .4rem; color: var(--muted); font-size: .95rem; }
.new-medication { color: var(--primary-dark); margin: -.6rem 0 0; }
.med-fields { display: flex; flex-direction: column; gap: 1rem; }

.login { max-width: 420px; margin: 2rem auto; }
.login h1 { text-align: center; }
.login > .muted { text-align: center; }
.steps ol, .share ol { padding-left: 1.2rem; margin: 0; }
.steps li, .share li { margin-bottom: .5rem; }

/* Pantalla principal */
.greeting { font-size: 1.2rem; font-weight: 600; }
.kind-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .75rem; }
.kind-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .3rem;
  min-height: 100px; padding: .7rem;
  border-radius: 18px; background: var(--card); border: 2px solid var(--border);
  color: var(--text); text-decoration: none; font-weight: 700; text-align: center;
  box-shadow: 0 1px 2px rgba(0,0,0,.05);
}
.kind-btn:active { transform: scale(.97); }
.kind-icon { font-size: 2.3rem; line-height: 1; }
.kind-btn.kind-medication { border-color: color-mix(in srgb, var(--med) 35%, white); }
.kind-btn.kind-blood_pressure { border-color: color-mix(in srgb, var(--bp) 35%, white); }
.kind-btn.kind-headache { border-color: color-mix(in srgb, var(--head) 35%, white); }
.kind-btn.kind-diarrhea { border-color: color-mix(in srgb, var(--diarrhea) 35%, white); }
.kind-btn.kind-vomit { border-color: color-mix(in srgb, var(--vomit) 35%, white); }
.kind-btn.kind-vertigo { border-color: color-mix(in srgb, var(--vertigo) 35%, white); }
.kind-btn.kind-note { border-color: color-mix(in srgb, var(--note) 30%, white); }
.kind-grid .kind-btn:last-child:nth-child(odd) { grid-column: span 2; min-height: 72px; flex-direction: row; }
.kind-grid .kind-btn:last-child:nth-child(odd) .kind-icon { font-size: 1.6rem; }

.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.section-head h1, .section-head h2 { margin-bottom: .6rem; }

/* Favoritos */
.favorites .section-head h2 { margin: 0 0 .5rem; }
.favorites .section-head h2 small { font-weight: 400; }
.favorites { padding-bottom: .2rem; border-bottom: 1px solid var(--border); }
.undo-bar { display: flex; justify-content: flex-end; gap: 1.2rem; margin: -.6rem 0 .8rem; font-size: .95rem; }
.undo-bar form.button_to { display: inline; }
.star { background: none; border: 0; padding: 0 .2rem; font-size: 1.35rem; line-height: 1.1; color: #9ca3af; cursor: pointer; }
.star.on { color: #f59e0b; }
.favorite-check { margin-top: -.3rem; }
.favorite-check input { width: 22px; height: 22px; }
.btn.small { min-height: 36px; padding: .3rem .8rem; font-size: .9rem; }
.tip { margin-top: .8rem; }

/* Perfil */
.password-change summary { cursor: pointer; color: var(--primary); font-weight: 600; }
.password-change[open] summary { margin-bottom: .8rem; }
.password-change label + label { margin-top: 1rem; }
.add-medications { margin-top: 1rem; }

/* Catálogo en la pantalla de favoritos */
.catalog-search { margin-bottom: .6rem; }
input[type=search] { width: 100%; min-height: 48px; padding: .6rem .8rem; border: 1px solid #cbd5e1; border-radius: 10px; font: inherit; background: #fff; }
.catalog-list { list-style: none; margin: 0 0 1rem; padding: 0; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.catalog-item { border-bottom: 1px solid var(--border); }
.catalog-item:last-child { border-bottom: 0; }
.catalog-item summary { display: flex; align-items: center; gap: .6rem; min-height: 52px; padding: .5rem .8rem; cursor: pointer; list-style: none; }
.catalog-item summary::-webkit-details-marker { display: none; }
.catalog-name { flex: 1; }
.catalog-doses { color: var(--muted); font-size: .85rem; text-align: right; }
.catalog-item details[open] { background: #f8fafc; }
.catalog-form { display: flex; gap: .5rem; padding: 0 .8rem .7rem; }
.catalog-form input[type=text] { flex: 1; min-width: 0; }
.catalog-favs { display: flex; flex-wrap: wrap; gap: .4rem; padding: 0 .8rem .8rem; }
.chip.removable { border-color: #fcd34d; background: #fffbeb; color: #92400e; }
.catalog-new p { margin-top: 0; }

/* Lista de eventos */
.event-list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.event-row { display: flex; align-items: flex-start; gap: .6rem; padding: .7rem .8rem; border-bottom: 1px solid var(--border); border-left: 4px solid var(--border); }
.event-row:last-child { border-bottom: 0; }
.event-row.kind-medication { border-left-color: var(--med); }
.event-row.kind-blood_pressure { border-left-color: var(--bp); }
.event-row.kind-headache { border-left-color: var(--head); }
.event-row.kind-diarrhea { border-left-color: var(--diarrhea); }
.event-row.kind-vomit { border-left-color: var(--vomit); }
.event-row.kind-vertigo { border-left-color: var(--vertigo); }
.event-row.kind-note { border-left-color: var(--note); }
.event-icon { font-size: 1.3rem; line-height: 1.3; }
.event-main { flex: 1; min-width: 0; }
.event-details { display: block; color: var(--text); }
.event-notes { color: var(--muted); font-size: .92rem; white-space: pre-line; }
.event-time { color: var(--muted); font-size: .9rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.event-edit { text-decoration: none; padding: 0 .2rem; }

/* Formulario de evento */
.form-head { display: flex; align-items: center; gap: .6rem; }
.form-head h1 { margin: .4rem 0; }
.back { font-size: 1.6rem; text-decoration: none; padding: 0 .4rem; }
.chips, .quick-ranges { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.chip {
  min-height: 40px; padding: .4rem .9rem; border-radius: 999px;
  border: 1px solid #93c5fd; background: #eff6ff; color: #1e3a8a;
  font: inherit; font-size: .95rem; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center;
}
.chip.other { border-style: dashed; border-color: #94a3b8; background: #fff; color: var(--text); }
.chip:active { background: var(--med); color: #fff; border-color: var(--med); }
.autocomplete { position: relative; }
.suggestions {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px);
  margin: 0; padding: .3rem 0; list-style: none;
  background: #fff; border: 1px solid #cbd5e1; border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 280px; overflow-y: auto;
}
.suggestions li { padding: .7rem .9rem; font-weight: 400; cursor: pointer; }
.suggestions li:hover, .suggestions li.active { background: var(--primary-soft); }

.bp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.bp-grid input { font-size: 1.4rem; text-align: center; font-weight: 600; }
.bp-grid small { font-weight: 400; display: block; }

.scale { border: 0; padding: 0; margin: 0; }
.scale legend { font-weight: 600; margin-bottom: .5rem; }
.scale-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: .5rem; }
.form .scale-option { position: relative; }
.scale-option input { position: absolute; opacity: 0; inset: 0; }
.scale-option span {
  display: flex; align-items: center; justify-content: center;
  height: 56px; border-radius: 14px; font-size: 1.3rem; font-weight: 700;
  border: 2px solid transparent; background: hsl(calc(130 - var(--lvl) * 13) 70% 92%); color: hsl(calc(130 - var(--lvl) * 13) 60% 25%);
}
.scale-option input:checked + span { background: hsl(calc(130 - var(--lvl) * 13) 65% 42%); color: #fff; border-color: rgba(0,0,0,.25); }
.scale-option input:focus-visible + span { outline: 2px solid var(--primary); }
.level-1 { --lvl: 1; } .level-2 { --lvl: 2; } .level-3 { --lvl: 3; } .level-4 { --lvl: 4; } .level-5 { --lvl: 5; }
.level-6 { --lvl: 6; } .level-7 { --lvl: 7; } .level-8 { --lvl: 8; } .level-9 { --lvl: 9; } .level-10 { --lvl: 10; }

/* Informe */
.filters { display: flex; flex-direction: column; gap: .8rem; }
.filters label { display: flex; flex-direction: column; font-weight: 600; font-size: .95rem; gap: .2rem; }
.filter-dates { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; }
.filter-dates label, .filter-dates input { min-width: 0; }
.filter-dates input { padding: .5rem; }
.filters .quick-ranges { margin: 0; }
.filter-kinds { display: flex; flex-wrap: wrap; gap: .4rem; }
.filters .check-chip { flex-direction: row; font-weight: 400; }
.check-chip input { position: absolute; opacity: 0; }
.check-chip span { padding: .35rem .75rem; border-radius: 999px; border: 1px solid var(--border); background: #f8fafc; color: var(--muted); cursor: pointer; }
.check-chip input:checked + span { background: var(--primary-soft); border-color: var(--primary); color: var(--primary-dark); }
.filter-actions { display: flex; gap: .6rem; flex-wrap: wrap; }

.report-head h1 { margin-bottom: .2rem; }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .6rem; }
.summary-card { background: var(--card); border: 1px solid var(--border); border-top: 4px solid var(--border); border-radius: var(--radius); padding: .7rem .9rem; }
.summary-card p { margin: .15rem 0; font-size: .95rem; }
.summary-card .count { float: right; background: var(--bg); border-radius: 999px; padding: 0 .55rem; font-size: .9rem; }
.summary-card.kind-medication { border-top-color: var(--med); }
.summary-card.kind-blood_pressure { border-top-color: var(--bp); }
.summary-card.kind-headache { border-top-color: var(--head); }
.summary-card.kind-diarrhea { border-top-color: var(--diarrhea); }
.summary-card.kind-vomit { border-top-color: var(--vomit); }
.summary-card.kind-vertigo { border-top-color: var(--vertigo); }
.summary-card.kind-note { border-top-color: var(--note); }

.chart-section { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem .8rem .6rem; margin-top: 1rem; }
.chart-section h2 { margin: .5rem 0; }
.legend { font-weight: 400; font-size: .85rem; margin-left: .4rem; }
.legend .s0 { color: var(--bp); } .legend .s1 { color: #f97316; } .legend .ref { color: var(--muted); }
.chart { width: 100%; height: auto; display: block; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .reference { stroke: #9ca3af; stroke-width: 1; stroke-dasharray: 4 4; }
.chart .tick { font-size: 15px; fill: var(--muted); }
.chart .line { fill: none; stroke-width: 2; }
.chart .line.s0, .chart .dot.s0 { stroke: var(--bp); }
.chart .line.s1, .chart .dot.s1 { stroke: #f97316; }
.chart .dot { fill: #fff; stroke-width: 2; }
.chart.headache .line.s0, .chart.headache .dot.s0 { stroke: var(--head); }
.chart.vertigo .line.s0, .chart.vertigo .dot.s0 { stroke: var(--vertigo); }

.day { margin-bottom: 1rem; }
.day h3 { font-size: .95rem; color: var(--muted); margin: .8rem 0 .4rem; }
.report-foot { margin-top: 2rem; font-size: .8rem; color: var(--muted); }

/* Admin */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 1rem; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th, .table td { padding: .6rem .8rem; border-bottom: 1px solid var(--border); text-align: left; }
.table th { background: #f8fafc; font-weight: 600; color: var(--muted); }
.table tr:last-child td { border-bottom: 0; }
.table .actions { text-align: right; white-space: nowrap; }
.table .actions > * { margin-left: .6rem; }
.badge { font-size: .75rem; background: var(--primary-soft); color: var(--primary-dark); padding: .05rem .45rem; border-radius: 999px; }

.print-only { display: none; }

@media (max-width: 400px) {
  .topbar { padding: .5rem 12px; }
  .topbar nav { gap: 0; flex-wrap: nowrap; }
  .topbar nav a, .topbar nav .link { padding: .35rem .5rem; font-size: .92rem; }
  .brand-text { display: none; }
}

@media (min-width: 640px) {
  .kind-grid { grid-template-columns: repeat(3, 1fr); }
  .kind-grid .kind-btn:last-child:nth-child(odd) { grid-column: auto; min-height: 112px; flex-direction: column; }
  .kind-grid .kind-btn:last-child:nth-child(odd) .kind-icon { font-size: 2.3rem; }
  .scale-grid { grid-template-columns: repeat(10, 1fr); }
}

@media print {
  body { background: #fff; font-size: 12pt; }
  .no-print, .event-edit { display: none !important; }
  .print-only { display: block; }
  .container { max-width: none; padding: 0; }
  .event-list, .summary-card, .chart-section { break-inside: avoid; }
  .day { break-inside: avoid; }
  a { color: inherit; text-decoration: none; }
}
