:root {
  --green: #5BA552;
  --green-d: #43853b;
  --green-l: #e9f5e7;
  --blue: #009FE3;
  --blue-l: #e3f4fc;
  --bg: #f4f7f5;
  --card: #ffffff;
  --text: #1d2a22;
  --muted: #6b7a70;
  --line: #e2e8e4;
  --red: #d64545;
  --red-l: #fdecec;
  --amber: #c98a12;
  --amber-l: #fdf3e0;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20,40,25,.06), 0 4px 14px rgba(20,40,25,.05);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101512; --card: #19201b; --text: #e7efe9; --muted: #93a398; --line: #2a342d;
    --green-l: #1f3320; --blue-l: #12303e; --red-l: #3a1d1d; --amber-l: #3a2e14;
    --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
}
img { max-width: 100%; }
[hidden] { display: none !important; }
a { color: var(--blue); }
h1, h2, h3 { margin: 0; line-height: 1.25; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.08rem; }
h3 { font-size: .98rem; }

/* Top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top, 0px)) 16px 8px;
  background: linear-gradient(110deg, var(--green) 0%, #2fa27f 55%, var(--blue) 100%);
  color: #fff; box-shadow: 0 2px 10px rgba(0,120,120,.18);
}
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: #fff; font-weight: 800; font-size: 1.12rem; letter-spacing: .02em; }
.brand img { width: 36px; height: 36px; object-fit: contain; background: #fff; border-radius: 10px; padding: 2px; }
.brand b { background: #fff; color: var(--green-d); border-radius: 6px; padding: 0 5px; margin-left: 2px; }
.brand em { font-style: normal; margin-left: 5px; padding: 0 6px; border-radius: 6px; background: rgba(255,255,255,.22); border: 1px solid rgba(255,255,255,.55); font-size: .85rem; }
.topbar .icon-btn { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.4); color: #fff; }
.topbar-right { display: flex; gap: 6px; }

.app { max-width: 680px; margin: 0 auto; padding: 14px 16px 24px; }

/* Bottom nav */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 7px; text-decoration: none; color: var(--muted); font-size: .7rem;
}
.bottomnav svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.bottomnav a.active { color: var(--green); font-weight: 600; }

/* Cards, lists */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 14px; margin-bottom: 12px; }
.card-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.section-title { display: flex; align-items: center; justify-content: space-between; margin: 18px 2px 8px; }
.muted { color: var(--muted); }
.small { font-size: .84rem; }
.row { display: flex; align-items: center; gap: 10px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 8px; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: 11px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.item-link { display: flex; align-items: center; gap: 12px; text-decoration: none; color: inherit; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 22px 10px; }

.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--green), var(--blue));
}

.stats { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow); }
.stat .v { font-size: 1.3rem; font-weight: 700; }
.stat .l { font-size: .78rem; color: var(--muted); }
.stat { border-top: 3px solid var(--green); }
.stat.b { border-top-color: var(--blue); }
.stat.r { border-top-color: var(--red); }
.stat.g .v { color: var(--green); }
.hero {
  border-radius: var(--radius); padding: 16px; margin-bottom: 14px; color: #fff;
  background: linear-gradient(120deg, var(--green) 0%, #2fa27f 50%, var(--blue) 100%);
  box-shadow: 0 6px 18px rgba(0,140,140,.2);
}
.hero p { margin: 4px 0 0; opacity: .92; }
.stat.b .v { color: var(--blue); }
.stat.r .v { color: var(--red); }

.hello { margin: 2px 2px 14px; }
.hello p { margin: 2px 0 0; color: var(--muted); }

/* Chips & badges */
.chip { display: inline-flex; align-items: center; gap: 4px; font-size: .74rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--line); color: var(--text); white-space: nowrap; }
.chip.g { background: var(--green-l); color: var(--green-d); }
.chip.b { background: var(--blue-l); color: #0378ab; }
.chip.r { background: var(--red-l); color: var(--red); }
.chip.a { background: var(--amber-l); color: var(--amber); }
@media (prefers-color-scheme: dark) {
  .chip.g { color: #8fd486; } .chip.b { color: #6cc8f0; }
}

.notice { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border-radius: 12px; margin-bottom: 8px; font-size: .9rem; }
.notice.g { background: var(--green-l); }
.notice.b { background: var(--blue-l); }
.notice.a { background: var(--amber-l); }
.notice.r { background: var(--red-l); }
.notice .ic { font-size: 1.15rem; line-height: 1.2; }

/* Buttons */
.btn {
  appearance: none; border: 0; cursor: pointer; font: inherit; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 0 16px; border-radius: 12px;
  background: var(--green); color: #fff; text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn.sec { background: var(--green-l); color: var(--green-d); }
.btn.blue { background: var(--blue); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--red-l); color: var(--red); }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: .85rem; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; pointer-events: none; }
@media (prefers-color-scheme: dark) { .btn.sec { color: #8fd486; } }
.icon-btn { appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text); width: 38px; height: 38px; border-radius: 10px; font-size: 1.05rem; cursor: pointer; }
.fab {
  position: fixed; right: 18px; bottom: calc(84px + env(safe-area-inset-bottom, 0px)); z-index: 15;
  width: 56px; height: 56px; border-radius: 18px; border: 0; cursor: pointer;
  background: linear-gradient(135deg, var(--green), var(--blue)); color: #fff; font-size: 1.8rem; box-shadow: 0 6px 18px rgba(0,140,140,.4);
}

/* Forms */
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: -1px; }
label.f { display: block; margin-bottom: 12px; }
label.f > span { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
.f2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.search { margin-bottom: 12px; }
input[type=range] { padding: 0; min-height: 32px; accent-color: var(--green); border: 0; background: transparent; }
input[type=checkbox] { width: 22px; height: 22px; min-height: 0; accent-color: var(--green); flex: none; }
.days { display: flex; flex-wrap: wrap; gap: 6px; }
.days label { display: flex; align-items: center; gap: 4px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; font-size: .88rem; }
.days input { width: 18px; height: 18px; }

/* Tabs */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin: 0 -16px 12px; padding-left: 16px; padding-right: 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; text-decoration: none; color: var(--muted); padding: 7px 13px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); font-size: .86rem; font-weight: 600; }
.tabs a.active { background: linear-gradient(120deg, var(--green), var(--blue)); border-color: transparent; color: #fff; }

/* Progress */
.bar { height: 8px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--green), var(--blue)); border-radius: 99px; }
.bar.blue > i { background: var(--blue); }

/* Week view */
.weeknav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.day { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.day-h { display: flex; justify-content: space-between; align-items: center; padding: 9px 12px; background: var(--green-l); }
.day.today .day-h { background: linear-gradient(120deg, var(--green), var(--blue)); color: #fff; }
.day.today .day-h .muted { color: #e8f7e5; }
.day-b { padding: 4px 12px; }
.sess { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed var(--line); cursor: pointer; }
.sess:last-child { border-bottom: 0; }
.sess .t { font-weight: 700; width: 46px; flex: none; color: var(--blue); }

/* Sheet */
.sheet-bg { position: fixed; inset: 0; z-index: 50; background: rgba(10,20,14,.45); display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  width: 100%; max-width: 680px; max-height: 92vh; overflow: auto; background: var(--card);
  border-radius: 20px 20px 0 0; padding: 8px 16px calc(16px + env(safe-area-inset-bottom, 0px));
  animation: up .2s ease-out;
}
.sheet-grip { width: 42px; height: 5px; border-radius: 9px; background: var(--line); margin: 4px auto 10px; }
.sheet-h { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 6px; position: sticky; bottom: 0; background: var(--card); padding-top: 8px; }
.sheet-actions .btn { flex: 1; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom, 0px)); z-index: 60; background: #1d2a22; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: .9rem; max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25); }

/* Lock */
.lock { position: fixed; inset: 0; z-index: 100; background: var(--bg); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 24px; }
.lock img { width: 120px; }
.lock input { max-width: 220px; text-align: center; font-size: 1.4rem; letter-spacing: .4em; }

/* AI output */
.md { font-size: .93rem; }
.md h1, .md h2, .md h3 { margin: 14px 0 6px; font-size: 1rem; color: var(--green-d); }
.md p { margin: 6px 0; }
.md ul, .md ol { padding-left: 20px; margin: 6px 0; }
@media (prefers-color-scheme: dark) { .md h1, .md h2, .md h3 { color: #8fd486; } }
.draft { border-left: 4px solid var(--amber); }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Patient (hasta) view */
.pv-hero { text-align: center; padding: 6px 0 14px; }
.pv-hero img { width: 110px; }
.ex { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--line); }
.ex:last-child { border-bottom: 0; }
.ex input { width: 28px; height: 28px; margin-top: 2px; }
.ex.done .ex-n { text-decoration: line-through; color: var(--muted); }
.pain-val { font-size: 1.6rem; font-weight: 800; color: var(--blue); text-align: center; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal div { aspect-ratio: 1; border-radius: 8px; background: var(--line); display: grid; place-items: center; font-size: .72rem; }
.cal div.full { background: var(--green); color: #fff; }
.cal div.part { background: var(--green-l); }

.chart { width: 100%; height: 120px; display: block; }
.months { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.months .m { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 4px; }
.months .m i { display: block; width: 100%; background: var(--green); border-radius: 6px 6px 2px 2px; min-height: 2px; }
.months .m span { font-size: .7rem; color: var(--muted); }

.menu a { display: flex; align-items: center; gap: 14px; padding: 14px 4px; text-decoration: none; color: inherit; border-bottom: 1px solid var(--line); }
.menu a:last-child { border-bottom: 0; }
.menu .mi { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 1.25rem; background: var(--green-l); flex: none; }
.menu .mi.b { background: var(--blue-l); }

.hide-nav .bottomnav, .hide-nav .fab { display: none; }
.hide-nav { padding-bottom: 0; }

@media (min-width: 560px) {
  .stats { grid-template-columns: repeat(4, 1fr); }
}
