/* =====================================================================
   HISTORIAL MÉDICO — estilos
   Estética: "diario de salud" cálido · verde pino + papel · serif Fraunces
   ===================================================================== */
:root {
  --paper:      #f4f1ea;
  --paper-2:    #ece7db;
  --surface:    #ffffff;
  --ink:        #1c2421;
  --ink-soft:   #5d6661;
  --line:       #e3ddd0;
  --pine:       #0e4f45;
  --pine-2:     #146356;
  --pine-soft:  #e3efe9;
  --coral:      #e0654c;
  --ok:         #2e9e6b;
  --warn:       #d99a2b;
  --bad:        #d6533c;
  --shadow:     0 1px 2px rgba(28,36,33,.04), 0 8px 24px -12px rgba(28,36,33,.18);
  --shadow-lg:  0 24px 60px -20px rgba(28,36,33,.35);
  --r:          18px;
  --r-sm:       12px;
  --safe-b:     env(safe-area-inset-bottom, 0px);
  --safe-t:     env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Hanken Grotesk", system-ui, sans-serif;
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
  overscroll-behavior-y: none;
}
.hidden { display: none !important; }
.muted { color: var(--ink-soft); font-size: .9rem; }
.display { font-family: "Fraunces", serif; font-weight: 500; letter-spacing: -.01em; }
h1, h2, h3 { font-family: "Fraunces", serif; font-weight: 500; letter-spacing: -.01em; }
code { background: var(--paper-2); padding: .1em .4em; border-radius: 6px; font-size: .85em; }

/* ---------- Botones ---------- */
.btn {
  font: inherit; font-weight: 600; border: 0; cursor: pointer;
  border-radius: 999px; padding: .72rem 1.25rem; transition: transform .12s, filter .2s;
}
.btn:active { transform: scale(.97); }
.btn.sm { padding: .5rem .9rem; font-size: .88rem; }
.btn-primary { background: var(--pine); color: #fff; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--paper-2); color: var(--ink); }
.btn-danger { background: transparent; color: var(--bad); box-shadow: inset 0 0 0 1.5px var(--bad); }
.linkbtn { background: none; border: 0; color: var(--pine); font: inherit; font-weight: 600;
  font-size: .85rem; cursor: pointer; padding: .2rem; }
.iconbtn { background: none; border: 0; font-size: 1.25rem; cursor: pointer; color: var(--ink-soft);
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; }
.iconbtn:hover { background: var(--paper-2); }

/* =====================================================================
   ACCESO
   ===================================================================== */
.auth {
  min-height: 100%; display: grid; place-content: center; gap: 1.4rem; padding: 2rem 1.3rem;
  background:
    radial-gradient(120% 80% at 80% -10%, var(--pine-soft), transparent 60%),
    radial-gradient(100% 70% at -10% 110%, #efe7d6, transparent 55%),
    var(--paper);
}
.auth-card {
  width: min(420px, 92vw); background: var(--surface); border-radius: 26px;
  padding: 2rem 1.6rem; box-shadow: var(--shadow-lg); border: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .85rem; margin-bottom: 1.6rem; }
.brand h1 { font-size: 1.45rem; }
.brand-mark {
  display: grid; place-items: center; width: 46px; height: 46px; border-radius: 14px;
  background: var(--pine); color: #fff; font-size: 1.3rem; font-weight: 700; flex: none;
  box-shadow: 0 6px 16px -6px var(--pine);
}
.brand-mark.sm { width: 26px; height: 26px; border-radius: 8px; font-size: .8rem; }
form label { display: block; font-size: .82rem; font-weight: 600; color: var(--ink-soft); margin-bottom: .9rem; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); margin-top: .35rem;
  padding: .72rem .85rem; border: 1.5px solid var(--line); border-radius: var(--r-sm);
  background: var(--paper); transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: 0; border-color: var(--pine); box-shadow: 0 0 0 3px var(--pine-soft); background: #fff;
}
#auth-form .btn { width: 100%; margin-top: .4rem; }
.auth-msg { font-size: .85rem; min-height: 1.2em; margin-top: .7rem; color: var(--coral); text-align: center; }
#auth-toggle { display: block; width: 100%; text-align: center; margin-top: 1.1rem; }
.auth-foot { text-align: center; font-size: .8rem; }

/* =====================================================================
   ARMAZÓN APP
   ===================================================================== */
.app { min-height: 100%; padding-top: calc(54px + var(--safe-t)); padding-bottom: calc(74px + var(--safe-b)); }
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 30;
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); border-bottom: 1px solid var(--line);
  padding-top: var(--safe-t);
}
.topbar-in { height: 54px; display: flex; align-items: center; justify-content: space-between;
  max-width: 720px; margin: 0 auto; padding: 0 1.1rem; }
.logo { display: flex; align-items: center; gap: .5rem; font-family: "Fraunces", serif; font-size: 1.1rem; }

main#views { max-width: 720px; margin: 0 auto; padding: 1.2rem 1.1rem; }
.view-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.view-head h2 { font-size: 1.7rem; }
.hello { margin-bottom: 1.1rem; }
.hello h2 { font-size: 1.9rem; }

/* ---------- Tarjetas ---------- */
.card, .stack > .item {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow);
}
.stack { display: flex; flex-direction: column; gap: .7rem; }
.stack > .item { padding: .95rem 1.05rem; display: flex; gap: .85rem; align-items: flex-start; }
.item .ic {
  flex: none; width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center;
  background: var(--pine-soft); color: var(--pine); font-size: 1.15rem;
}
.item .body { flex: 1; min-width: 0; }
.item .body .t { font-weight: 600; }
.item .body .s { font-size: .85rem; color: var(--ink-soft); margin-top: .12rem; }
.item .body .meta { display: flex; flex-wrap: wrap; gap: .35rem .7rem; margin-top: .4rem; font-size: .8rem; color: var(--ink-soft); }
.item .end { display: flex; flex-direction: column; align-items: flex-end; gap: .4rem; }

.block { margin-top: 1.6rem; }
.block-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .7rem; }
.block-head h3 { font-size: 1.05rem; }

/* ---------- Stats inicio ---------- */
.stat-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: .65rem; }
.stat {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: .85rem .8rem; box-shadow: var(--shadow);
}
.stat .n { font-family: "Fraunces", serif; font-size: 1.7rem; line-height: 1; }
.stat .l { font-size: .72rem; color: var(--ink-soft); margin-top: .35rem; }
.stat.accent { background: var(--pine); border-color: var(--pine); color: #fff; }
.stat.accent .l { color: #cfe6dd; }

/* ---------- Chips ---------- */
.chips { display: flex; flex-wrap: wrap; gap: .5rem; }
.chip {
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: .5rem .9rem; font-size: .85rem; font-weight: 600; box-shadow: var(--shadow);
}
.chip small { color: var(--ink-soft); font-weight: 500; }

/* ---------- Badges / semáforo ---------- */
.badge { font-size: .72rem; font-weight: 700; padding: .22rem .55rem; border-radius: 999px; white-space: nowrap; }
.b-ok   { background: #e4f3ec; color: var(--ok); }
.b-warn { background: #f8efda; color: #a9760f; }
.b-bad  { background: #f8e3df; color: var(--bad); }
.b-info { background: var(--pine-soft); color: var(--pine); }
.b-mute { background: var(--paper-2); color: var(--ink-soft); }
.dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.dot.ok { background: var(--ok); } .dot.warn { background: var(--warn); } .dot.bad { background: var(--bad); }

.val { font-family: "Fraunces", serif; font-size: 1.15rem; font-weight: 600; }

/* ---------- Segmentos / filtros ---------- */
.seg { display: inline-flex; background: var(--paper-2); border-radius: 999px; padding: 4px; margin-bottom: 1rem; }
.seg-b { border: 0; background: none; font: inherit; font-weight: 600; font-size: .85rem; color: var(--ink-soft);
  padding: .4rem .95rem; border-radius: 999px; cursor: pointer; }
.seg-b.active { background: var(--surface); color: var(--pine); box-shadow: var(--shadow); }

.field.inline { margin-bottom: 1rem; }
.field.inline label { font-size: .82rem; font-weight: 600; color: var(--ink-soft); }
.chartcard { padding: 1rem; margin-bottom: 1.1rem; }

/* ---------- Tabbar ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--paper) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
}
.tab { border: 0; background: none; cursor: pointer; font: inherit; font-size: .68rem; font-weight: 600;
  color: var(--ink-soft); display: flex; flex-direction: column; align-items: center; gap: 3px; padding: .6rem 0 .55rem; }
.tab span { font-size: 1.3rem; line-height: 1; }
.tab.active { color: var(--pine); }

/* ---------- Empty ---------- */
.empty { text-align: center; color: var(--ink-soft); padding: 1.6rem 1rem; font-size: .9rem; }
.empty .e-ic { font-size: 1.8rem; display: block; margin-bottom: .4rem; opacity: .6; }

/* =====================================================================
   MODAL
   ===================================================================== */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; align-items: end; justify-items: center; }
.modal-bg { position: absolute; inset: 0; background: rgba(20,26,24,.45); backdrop-filter: blur(2px); }
.modal-card {
  position: relative; width: min(560px, 100vw); max-height: 92vh; overflow: auto;
  background: var(--surface); border-radius: 24px 24px 0 0; box-shadow: var(--shadow-lg);
  padding: 1.1rem 1.2rem calc(1.4rem + var(--safe-b)); animation: up .28s cubic-bezier(.2,.8,.2,1);
}
@media (min-width: 600px){ .modal { align-items: center; } .modal-card { border-radius: 24px; } }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .9rem; }
.modal-head h3 { font-size: 1.25rem; }
.modal-body .row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.modal-body textarea { min-height: 70px; resize: vertical; }
.modal-actions { display: flex; gap: .6rem; margin-top: 1rem; }
.modal-actions .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(86px + var(--safe-b)); transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: #fff; padding: .7rem 1.1rem; border-radius: 999px; font-size: .88rem;
  font-weight: 600; opacity: 0; pointer-events: none; transition: .3s; z-index: 60; box-shadow: var(--shadow-lg);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Setup pendiente ---------- */
.setup { position: fixed; inset: 0; z-index: 80; display: grid; place-content: center; padding: 2rem; background: var(--paper); }
.setup-card { max-width: 460px; background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 1.8rem; box-shadow: var(--shadow); }
.setup-card h2 { font-size: 1.3rem; margin-bottom: .6rem; }
.setup-card p { color: var(--ink-soft); }

/* Animación de entrada de listas */
.stack > .item { animation: fade .35s ease both; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
