:root {
  --bg: #f6f2ec;
  --card: #ffffff;
  --text: #111114;
  --muted: #6e6e78;
  --line: rgba(60, 60, 67, 0.14);
  --accent: #c26a14;
  --accent-soft: rgba(194, 106, 20, 0.14);
  --danger: #e5484d;
  --green: #34c759;
  --orange: #ff9500;
  --red: #ff3b30;
  --nolotil: #14b8a6;
  --suma: #6366f1;
  --tab-h: 58px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f5f5f7;
    --muted: #9a9aa3;
    --line: rgba(235, 235, 245, 0.16);
    --accent: #f0a050;
    --accent-soft: rgba(240, 160, 80, 0.2);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 12px);
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
h1 { margin: 0; font-size: 34px; font-weight: 800; letter-spacing: -0.5px; }
h2 { margin: 22px 16px 6px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: none; }
.foot { margin: 6px 16px 0; font-size: 12.5px; color: var(--muted); }

/* Estructura */
.page { padding: calc(env(safe-area-inset-top) + 14px) 16px 8px; max-width: 640px; margin: 0 auto; }
.page > h2, .page > .foot { margin-left: 4px; margin-right: 4px; }
.head { display: flex; align-items: center; justify-content: space-between; padding: 6px 0 12px; }
.fab {
  width: 44px; height: 44px; border-radius: 50%; background: var(--card); color: var(--text);
  font-size: 26px; line-height: 1; box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12);
}
.card { background: var(--card); border-radius: 18px; overflow: hidden; }
.card + .card { margin-top: 12px; }
.pad { padding: 14px; }
.empty { text-align: center; color: var(--muted); padding: 80px 24px; }
.empty b { display: block; color: var(--text); font-size: 18px; margin: 8px 0 4px; }

.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; text-align: left; }
.row + .row { border-top: 1px solid var(--line); }
.row .grow { flex: 1; min-width: 0; }
.row .sub { color: var(--muted); font-size: 13px; }
.row .val { color: var(--muted); text-align: right; }
.badge {
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 800; font-size: 20px; flex: none;
}
.chev { color: var(--muted); flex: none; }

/* Pestañas */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; justify-content: space-around;
  padding: 6px 8px calc(env(safe-area-inset-bottom) + 4px);
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  border-top: 1px solid var(--line);
}
.tab { flex: 1; display: grid; justify-items: center; gap: 2px; padding: 4px 0; color: var(--muted); font-size: 11px; }
.tab svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { color: var(--accent); }

/* Controles */
.seg { display: flex; background: var(--line); border-radius: 10px; padding: 2px; gap: 2px; }
.seg button { flex: 1; padding: 7px 6px; border-radius: 8px; font-size: 14px; text-align: center; }
.seg button.on { background: var(--card); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.14); }
.navbar { display: flex; align-items: center; justify-content: space-between; margin: 12px 0 4px; font-weight: 700; }
.navbar button { color: var(--accent); font-size: 22px; padding: 2px 10px; }

.btn { display: block; width: 100%; padding: 13px; border-radius: 12px; text-align: center; font-weight: 600; background: var(--card); color: var(--accent); }
.btn.primary { background: var(--accent); color: #fff; }
.btn.danger { color: var(--danger); }
.btn + .btn { margin-top: 10px; }
.link { color: var(--accent); font-weight: 600; }

input[type="datetime-local"], input[type="time"], select, textarea {
  background: var(--bg); border: 0; border-radius: 8px; padding: 7px 10px; max-width: 100%;
}
textarea { width: 100%; min-height: 92px; resize: vertical; background: transparent; padding: 0; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.field { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 14px; }
.field + .field { border-top: 1px solid var(--line); }

.opt { display: flex; width: 100%; justify-content: space-between; align-items: center; padding: 12px 14px; text-align: left; }
.opt + .opt { border-top: 1px solid var(--line); }
.opt .check { color: var(--accent); font-weight: 800; opacity: 0; }
.opt.on .check { opacity: 1; }

/* Calendario */
.weekdays, .days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px 2px; text-align: center; }
.weekdays span { font-size: 12px; font-weight: 600; color: var(--muted); padding-bottom: 4px; }
.day { min-height: 46px; display: grid; justify-items: center; align-content: start; gap: 2px; padding-top: 3px; border-radius: 10px; }
.day.sel { background: var(--accent-soft); }
.day .n { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 50%; font-size: 15px; }
.day.today .n { box-shadow: inset 0 0 0 2px var(--accent); font-weight: 700; }
.day .dots { display: flex; gap: 3px; height: 6px; }
.dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; }
.legend { display: flex; gap: 14px; justify-content: center; margin-top: 10px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.legend .dot { width: 8px; height: 8px; margin-right: 4px; }

/* Gráficos */
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--muted); font-size: 9px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.keys { display: flex; gap: 14px; font-size: 12px; color: var(--muted); padding: 0 14px 12px; }
.keys .dot { margin-right: 4px; }

/* Editor y ventanas */
.overlay { position: fixed; inset: 0; z-index: 40; background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.overlay[hidden] { display: none; }
.sheetbar {
  position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; align-items: center;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px; background: color-mix(in srgb, var(--bg) 90%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.sheetbar b { font-size: 17px; }
.sheetbar button { color: var(--accent); font-weight: 600; padding: 6px 4px; }
.sheetbar .save { font-weight: 800; }
.editor { padding: 0 16px 40px; max-width: 640px; margin: 0 auto; }
.editor h2 { margin-left: 4px; }
.modal { background: rgba(0, 0, 0, 0.4); display: grid; align-items: end; }
.modal .sheet { background: var(--bg); border-radius: 22px 22px 0 0; padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px); max-width: 640px; width: 100%; margin: 0 auto; }
.stepper { display: flex; align-items: center; gap: 14px; }
.stepper button { width: 36px; height: 36px; border-radius: 10px; background: var(--bg); font-size: 20px; }
.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 20px); transform: translateX(-50%);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 60; font-size: 14px; max-width: 90%;
}
.toast[hidden] { display: none; }
.note { color: var(--muted); font-size: 13px; }

/* Mapa de la cabeza */
.headcard {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px; background: #232538; border-radius: 18px;
  padding: 12px; color: rgba(255, 255, 255, 0.85); font-size: 12px;
}
.headcol { min-width: 0; }
.sides { display: flex; justify-content: space-between; padding: 0 2px 4px; }
.cap { text-align: center; color: rgba(255, 255, 255, 0.55); padding-top: 2px; }
.headsvg { width: 100%; height: auto; display: block; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.headsvg .torso { fill: #996b5c; }
.headsvg .ear { fill: #d69e7f; stroke: #f2c7a9; stroke-width: .6; stroke-opacity: .7; }
.headsvg .halo { fill: #f2c7a9; opacity: .3; }
.headsvg .outline { fill: none; stroke: #f2c7a9; stroke-width: 1.6; stroke-linejoin: round; }
.headsvg .outline.soft { stroke-width: .6; stroke-opacity: .45; }
.headsvg .zone {
  fill: rgba(0, 0, 0, 0.001); stroke: #5c3329; stroke-opacity: .55; stroke-width: 1;
  stroke-dasharray: .1 3; stroke-linecap: round; cursor: pointer;
}
.headsvg .zone.sel { fill: #e5484d; fill-opacity: .93; stroke: #fff; stroke-opacity: .9; stroke-dasharray: none; stroke-width: .8; }
.headsvg .brow { fill: none; stroke: #5c3329; stroke-opacity: .75; stroke-width: 1.2; stroke-linecap: round; pointer-events: none; }
.headsvg .eye { fill: #fff; fill-opacity: .92; stroke: #5c3329; stroke-opacity: .8; stroke-width: .7; pointer-events: none; }
.headsvg .lips { fill: #db6671; fill-opacity: .85; stroke: #9e3848; stroke-width: .7; pointer-events: none; }
.headsvg .mouth { fill: none; stroke: #9e3848; stroke-width: .7; pointer-events: none; }
.headsvg .face { pointer-events: none; }
.tooth { cursor: pointer; }
.tooth-bg { fill: #232538; stroke: #f2c7a9; stroke-opacity: .6; stroke-width: .9; }
.tooth-icon { fill: #f2c7a9; fill-opacity: .9; }
.tooth.sel .tooth-bg { fill: #e5484d; stroke: #fff; stroke-opacity: .9; }
.tooth.sel .tooth-icon { fill: #fff; }
.zones-text { padding: 12px 4px 0; font-size: 15px; }


/* Cova */
.dogcard { grid-template-columns: 1fr; gap: 6px; }
.dogcard .sides { display: none; }
.dogsvg { width: 100%; }
.dogsvg.ro .zone { pointer-events: none; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 7px 13px; border-radius: 999px; background: var(--bg); font-size: 15px; border: 1px solid var(--line); white-space: nowrap; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.filters { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 12px; -webkit-overflow-scrolling: touch; }
.filters::-webkit-scrollbar { display: none; }
.addrow { display: flex; gap: 8px; margin-top: 14px; align-items: center; }
.ico { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; flex: none; }
.pill { padding: 4px 10px; border-radius: 999px; font-size: 13px; font-weight: 600; white-space: nowrap; }
.pill.ok { background: color-mix(in srgb, var(--green) 20%, transparent); color: var(--green); }
.pill.soon { background: color-mix(in srgb, var(--orange) 22%, transparent); color: var(--orange); }
.pill.late { background: color-mix(in srgb, var(--red) 20%, transparent); color: var(--red); }
.pill.none { background: var(--line); color: var(--muted); }
.typegrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.typegrid button { background: var(--card); border-radius: 16px; padding: 16px 8px; display: grid; justify-items: center; gap: 6px; font-weight: 600; }
.typegrid .ico { width: 52px; height: 52px; font-size: 26px; }
input[type="text"], input[type="date"], select { background: var(--bg); border: 0; border-radius: 8px; padding: 8px 10px; max-width: 100%; }
.field input[type="text"] { text-align: right; flex: 1; min-width: 0; }
.hello { color: var(--muted); font-size: 15px; margin: -6px 0 8px; }


/* Avisos */
.row.alert.soon { background: color-mix(in srgb, var(--orange) 14%, transparent); }
.row.alert.late { background: color-mix(in srgb, var(--red) 16%, transparent); box-shadow: inset 4px 0 0 var(--red); }
.row.alert.soon { box-shadow: inset 4px 0 0 var(--orange); }

/* Peso y alimentación */
.wopen { text-align: left; }
.wbig { font-size: 26px; font-weight: 800; letter-spacing: -.5px; }
.spark { width: 90px; height: 36px; flex: none; fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.addpill { cursor: pointer; }
.chart .wline { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .wdot { fill: var(--accent); }

/* Nube y contraseña */
.gate { position: fixed; inset: 0; z-index: 90; background: var(--bg); display: grid; place-items: center; padding: 24px; overflow-y: auto; }
.gate[hidden] { display: none; }
.gatebox { width: 100%; max-width: 360px; text-align: center; }
.gatebox h1 { margin-bottom: 6px; }
.gatebox form { margin-top: 18px; }
.gatebox .btn + .btn { margin-top: 10px; }
.gatebox input, .sheet input[type="password"] { width: 100%; background: var(--bg); border: 0; border-radius: 10px; padding: 13px 14px; font-size: 17px; }
.gatebox input { background: var(--card); }
.sheet .card .btn { margin-top: 4px; }
.btn[disabled] { opacity: .5; }
.reckey { font: 700 20px ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: 1px; text-align: center; padding: 16px 8px; margin: 12px 0; border-radius: 12px; background: var(--bg); word-break: break-all; user-select: all; -webkit-user-select: all; }
.gatebox .link { margin-top: 6px; }
