:root {
  --lav: #9275A8; --lav-deep: #6B5280; --lav-soft: #E9DFF5; --sage: #DDEBDD; --blue: #DFE6F5; --rose: #F2DFE8;
  --cream: #FAF7F2; --text: #34323B; --muted: #6A6672; --line: #DCD4E3; --card: #FFFFFF;
  --radius: 16px; --nav-h: 64px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--cream); color: var(--text);
  font: 17px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
}
body.modal-open { overflow: hidden; }
.app-header { display: flex; align-items: center; gap: 12px; padding: calc(env(safe-area-inset-top) + 12px) 20px 4px; max-width: 680px; margin: 0 auto; }
.logo { font-weight: 700; letter-spacing: .18em; color: var(--lav-deep); }
.tagline { color: var(--muted); font-size: 14px; }
main { max-width: 680px; margin: 0 auto; padding: 8px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 28px); outline: none; }
h1 { font-size: 26px; line-height: 1.2; margin: 12px 0 6px; font-weight: 650; }
h2 { font-size: 19px; margin: 24px 0 8px; font-weight: 650; }
h3 { font-size: 16px; margin: 14px 0 4px; }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
:focus-visible { outline: 3px solid var(--lav-deep); outline-offset: 2px; border-radius: 8px; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.btn {
  min-height: 48px; padding: 10px 18px; border-radius: 14px; border: 1.5px solid var(--lav-deep);
  background: var(--card); color: var(--lav-deep); font-weight: 600;
}
.btn.primary { background: var(--lav-deep); color: #fff; }
.btn.danger { border-color: #8A3B4F; color: #8A3B4F; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
button.card { width: 100%; text-align: left; display: block; }
.notice { background: var(--lav-soft); border-radius: var(--radius); padding: 12px 14px; font-size: 15px; margin: 12px 0; }

.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=search], input[type=date], input[type=datetime-local], select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 12px; background: #fff;
}
textarea { min-height: 76px; resize: vertical; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 8px 14px;
  border: 1.5px solid var(--line); border-radius: 999px; background: #fff;
}
.chip[aria-pressed=true] { background: var(--lav-soft); border-color: var(--lav-deep); font-weight: 600; }
.chip[hidden] { display: none; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; border: 1px solid rgba(0,0,0,.12); }

.sel-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.sel-row:first-child { border-top: 0; }
.sel-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.scale-wrap { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.scale { display: flex; gap: 4px; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.scale button { width: 44px; height: 44px; border: 0; background: none; padding: 0; display: grid; place-items: center; cursor: pointer; }
.scale button i { width: 26px; height: 26px; border-radius: 50%; border: 2px solid var(--lav-deep); background: #fff; display: block; transition: background .12s, transform .12s; }
.scale button.on i { background: var(--lav-deep); }
.scale button[aria-checked=true] i { transform: scale(1.12); box-shadow: 0 0 0 3px var(--lav-soft); }
.scale-txt { font-size: 13px; color: var(--muted); min-height: 16px; padding-right: 6px; }
@media (prefers-reduced-motion: reduce) { .scale button i { transition: none; } }
.x { border: 0; background: none; font-size: 22px; width: 44px; height: 44px; color: var(--muted); }

details.details { margin: 12px 0; border: 1px solid var(--line); border-radius: var(--radius); padding: 4px 14px 10px; background: #fff; }
details.details > summary { cursor: pointer; min-height: 44px; display: flex; align-items: center; font-weight: 600; color: var(--lav-deep); }

.seg { display: flex; gap: 4px; background: var(--lav-soft); padding: 4px; border-radius: 14px; margin: 8px 0; overflow-x: auto; }
.seg button { flex: 1 1 auto; min-height: 42px; padding: 6px 8px; font-size: 15px; border: 0; background: transparent; border-radius: 10px; white-space: nowrap; }
.seg button[aria-pressed=true] { background: #fff; font-weight: 650; box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.period { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; margin: 8px 0 12px; }
.period > *, .period .field { min-width: 0; }
.period select, .period input { max-width: 100%; min-width: 0; }
.period .nav { display: flex; align-items: center; gap: 8px; }
.period .nav .label { flex: 1; text-align: center; font-weight: 600; }
.period .nav button { width: 48px; height: 48px; border-radius: 12px; border: 1.5px solid var(--line); background: #fff; font-size: 20px; }
.period .nav button:disabled { opacity: .35; }
.period .dates { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 8px; }
.period .dates .field { margin: 0; }

.day-head { margin: 18px 0 4px; font-size: 15px; color: var(--muted); font-weight: 600; text-transform: capitalize; }
.entry-top { display: flex; justify-content: space-between; margin-bottom: 6px; color: var(--muted); font-size: 14px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill { padding: 3px 10px; border-radius: 999px; font-size: 14px; color: var(--text); border: 1px solid rgba(0,0,0,.08); }
.pill.tag { background: var(--blue); }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; margin: 8px 0; }
.cal-dow { text-align: center; font-size: 12px; color: var(--muted); text-transform: capitalize; }
.cal-cell { aspect-ratio: 1; border-radius: 10px; border: 1.5px solid transparent; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 15px; padding: 0; }
.cal-cell.empty { background: transparent; }
.cal-cell.none { color: var(--muted); border-color: var(--line); }
.cal-cell small { font-size: 11px; }
.cal-cell[aria-pressed=true] { border-color: var(--lav-deep); box-shadow: 0 0 0 2px var(--lav-deep) inset; }

.matrix-wrap { overflow: auto; max-height: 70vh; border: 1px solid var(--line); border-radius: 12px; background: #fff; }
table.matrix { border-collapse: separate; border-spacing: 0; font-size: 13px; }
table.matrix th, table.matrix td { padding: 0; min-width: 30px; height: 30px; text-align: center; border-right: 1px solid #F0EBF4; border-bottom: 1px solid #F0EBF4; }
table.matrix thead th { position: sticky; top: 0; background: var(--lav-soft); z-index: 2; font-weight: 600; }
table.matrix th[scope=row] { position: sticky; left: 0; background: #fff; text-align: left; padding: 0 8px; min-width: 150px; white-space: nowrap; z-index: 1; font-weight: 500; }
table.matrix thead th.corner { left: 0; z-index: 3; text-align: left; padding: 0 8px; }

.bar-row { display: grid; grid-template-columns: 1fr; gap: 3px; margin: 10px 0; }
.bar-label { display: flex; justify-content: space-between; font-size: 15px; gap: 8px; }
.bar { height: 10px; background: var(--lav-soft); border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--lav); border-radius: 6px; }
.evo { display: flex; align-items: flex-end; gap: 2px; height: 90px; padding: 6px 0; border-bottom: 1px solid var(--line); }
.evo > i { flex: 1; background: var(--lav); border-radius: 3px 3px 0 0; min-height: 2px; }
.evo > i.zero { background: var(--line); }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-num { font-size: 30px; font-weight: 700; color: var(--lav-deep); }
ul.obs { padding-left: 20px; margin: 8px 0; }
ul.obs li { margin: 8px 0; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; display: flex; background: rgba(250,247,242,.97); backdrop-filter: blur(8px);
  border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); z-index: 20;
}
.tabbar button { flex: 1; height: var(--nav-h); border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px; color: var(--muted); }
.tabbar button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tabbar button[aria-current=page] { color: var(--lav-deep); font-weight: 700; }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 16px); transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; }

.overlay { position: fixed; inset: 0; background: rgba(52,50,59,.45); z-index: 30; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--cream); width: 100%; max-width: 680px; max-height: 92vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 16px 16px calc(env(safe-area-inset-bottom) + 20px); outline: none; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.modal-head h2 { margin: 6px 0; }
.big-timer { font-size: 56px; font-weight: 700; text-align: center; color: var(--lav-deep); margin: 16px 0 4px; }
.guide { text-align: center; font-size: 22px; margin: 4px 0 16px; }
.ficha-sec { margin: 12px 0; padding: 10px 12px; background: #fff; border: 1px dashed var(--line); border-radius: 12px; }
.ficha-sec h3 { margin-top: 0; }

.report { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin: 12px 0; }
.report h1 { font-size: 22px; }
.report table { width: 100%; border-collapse: collapse; font-size: 15px; }
.report th, .report td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.report .entry-r { border-top: 1px solid var(--line); padding: 8px 0; font-size: 15px; }
.checks { display: grid; gap: 4px; }
.checks label { display: flex; gap: 10px; align-items: center; min-height: 40px; }
.checks input { width: 22px; height: 22px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media print {
  body { background: #fff; }
  .no-print, .tabbar, .app-header, .toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .report { border: 0; padding: 0; }
}

.overlay.dlg { z-index: 50; align-items: center; }
.dlg-box { border-radius: 18px; max-width: 420px; margin: 16px; padding-bottom: 16px; }
.dlg-text { font-size: 17px; margin: 4px 0 14px; }

/* Familias de emociones (acordeón) y recientes */
.fams { margin: 10px 0; }
details.fam { border: 1px solid var(--line); border-left: 6px solid var(--fam); border-radius: 14px; background: #fff; margin: 8px 0; padding: 0 12px; }
details.fam[hidden] { display: none; }
details.fam > summary { list-style: none; cursor: pointer; min-height: 52px; display: flex; align-items: center; gap: 10px; font-weight: 600; }
details.fam > summary::-webkit-details-marker { display: none; }
details.fam > summary::after { content: '›'; margin-left: auto; font-size: 22px; color: var(--muted); transition: transform .15s; }
details.fam[open] > summary::after { transform: rotate(90deg); }
.fam-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--fam); flex: none; }
.fam-count { font-size: 13px; font-weight: 600; color: var(--lav-deep); background: var(--lav-soft); border-radius: 999px; padding: 2px 10px; }
.fam-count[hidden] { display: none; }
.fam .chips { margin: 4px 0 12px; }
.recent h3 { margin: 12px 0 0; font-size: 15px; }
.qchip { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; padding: 8px 14px; border: 1.5px solid var(--line); border-radius: 999px; background: #fff; font: inherit; }
.qchip[aria-pressed=true] { background: var(--lav-soft); border-color: var(--lav-deep); font-weight: 600; }
.fam-hint { margin: 12px 0 0; }
@media (prefers-reduced-motion: reduce) { details.fam > summary::after { transition: none; } }

.logo-img { height: 40px; width: auto; display: block; }

.brand-mark { width: 46px; height: 46px; display: block; flex: none; }
.brand-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.brand-word { height: 28px; width: auto; display: block; }
.brand-text .tagline { font-size: 12.5px; line-height: 1.2; }
.face { font-size: 20px; line-height: 1; flex: none; }
.pill .face { font-size: 15px; margin-right: 4px; vertical-align: -1px; }
.textarea::placeholder, textarea::placeholder { color: #7a7585; font-size: 14px; }
