/* Paleta de marca "KokoKid" (logo del koala) — tonos muestreados
   directamente del logo: crema de fondo, coral/verde salvia/ámbar como
   colores de acento (las tres letras de "Kid" y sus marcas decorativas),
   y un marrón cálido oscuro para el texto en vez de un gris/negro neutro. */
:root {
  --bg: #faf6ec;
  --panel: #ffffff;
  --text: #4b3f3a;
  --text-muted: #8a7b72;
  --border: #ede2d2;
  --accent: #eb9881;
  --accent-dark: #c8816e;
  --accent-soft: #f8ded2;
  --blue: #6b8fb0;
  --green: #8a9c86;
  --red: #c1574a;
  --yellow: #f2b463;
  --radius: 16px;
  --shadow: 0 2px 10px rgba(75, 60, 50, 0.08);
  font-size: 15px;
}

* { box-sizing: border-box; }

/* El atributo HTML "hidden" debe ganar siempre a cualquier "display"
   declarado por una clase (p.ej. .lock-screen/.onboarding usan display:flex).
   Sin esto, un elemento oculto con `el.hidden = true` seguiría pintándose
   y podría interceptar clics de la pantalla que hay debajo. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", -apple-system, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, select, textarea { font-family: inherit; font-size: inherit; }

h1, h2, h3, h4 { font-weight: 600; margin: 0 0 8px; }

.app-shell {
  display: flex;
  height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 18px; position: relative; }
.brand-logo-sm { width: 34px; height: 34px; border-radius: 10px; display: block; flex-shrink: 0; }
.brand-title { font-weight: 700; font-size: 15px; }
.brand-subtitle { color: var(--text-muted); font-size: 12px; }
.sidebar-close { display: none; }

/* Barra superior y botón de menú: solo se muestran en pantallas estrechas
   (tablet/móvil), donde el menú lateral pasa a ser un panel deslizante en
   vez de ocupar espacio fijo permanentemente. En escritorio no se ven. */
.topbar { display: none; }
.menu-toggle {
  background: none; border: 1px solid var(--border); border-radius: 10px;
  font-size: 20px; line-height: 1; padding: 8px 12px; cursor: pointer; color: var(--text);
}
.sidebar-backdrop { display: none; }

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  background: none; border: none; text-align: left;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  color: var(--text); font-size: 14px;
}
.nav-item span { font-size: 16px; width: 20px; text-align: center; }
.nav-item:hover { background: var(--accent-soft); }
.nav-item.active { background: var(--accent); color: white; }

.sidebar-footer { padding-top: 10px; border-top: 1px solid var(--border); }
.child-switcher { width: 100%; padding: 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg); }

.content { flex: 1; overflow-y: auto; padding: 28px 36px; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.card-header h2 { display: flex; align-items: center; gap: 8px; font-size: 16px; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 900px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 500;
}
.btn:hover { background: var(--bg); }
.btn-primary { background: var(--accent); color: white; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { color: var(--red); border-color: var(--red); background: white; }
.btn-danger:hover { background: #fdeeec; }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); margin-bottom: 12px; }
input, select, textarea {
  padding: 9px 10px; border-radius: 8px; border: 1px solid var(--border);
  background: white; color: var(--text);
}
textarea { resize: vertical; min-height: 60px; }
form .btn { margin-top: 4px; }

.hint { font-size: 12.5px; color: var(--text-muted); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); font-size: 13.5px; }
th { color: var(--text-muted); font-weight: 600; }

.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge-green { background: #e6f0e7; color: var(--green); }
.badge-yellow { background: #fbf1dc; color: #a8802e; }
.badge-red { background: #fbe6e3; color: var(--red); }
.badge-blue { background: #e7eef4; color: var(--blue); }
.badge-gray { background: #eeece7; color: var(--text-muted); }

.empty-state { text-align: center; padding: 30px 10px; color: var(--text-muted); }
.empty-state .emoji { font-size: 32px; display: block; margin-bottom: 8px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab-btn { background: none; border: none; padding: 10px 14px; cursor: pointer; color: var(--text-muted); border-bottom: 2px solid transparent; font-weight: 500; }
.tab-btn.active { color: var(--accent-dark); border-bottom-color: var(--accent); }

.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 4px; border-bottom: 1px solid var(--border);
}
.list-item:last-child { border-bottom: none; }
.list-item .icon { font-size: 20px; width: 28px; text-align: center; }
.list-item .main { flex: 1; }
.list-item .main .title { font-weight: 600; font-size: 14px; }
.list-item .main .subtitle { color: var(--text-muted); font-size: 12.5px; }
.list-item .meta { text-align: right; font-size: 12.5px; color: var(--text-muted); }

.dashboard-hero { display: flex; align-items: center; gap: 18px; margin-bottom: 20px; }
.hero-avatar {
  width: 72px; height: 72px; border-radius: 50%; background: var(--accent-soft);
  display: flex; align-items: center; justify-content: center; font-size: 34px; overflow: hidden;
}
.hero-avatar img { width: 100%; height: 100%; object-fit: cover; }
.hero-name { font-size: 22px; font-weight: 700; }
.hero-age { color: var(--text-muted); }

.stat-tile { text-align: center; padding: 14px; }
.stat-tile .value { font-size: 26px; font-weight: 700; }
.stat-tile .label { color: var(--text-muted); font-size: 12.5px; }

.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 10px; }
.photo-thumb { position: relative; border-radius: 10px; overflow: hidden; aspect-ratio: 1; background: var(--accent-soft); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb .cap { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,.55); color: white; font-size: 11px; padding: 4px 6px; }

/* Marcos decorativos (solo estilo visual, no tocan el archivo original). */
.photo-thumb.frame-rounded { border-radius: 24px; }
.photo-thumb.frame-polaroid { background: #fffdf8; padding: 8px 8px 20px 8px; box-shadow: 0 4px 14px rgba(0,0,0,.2); border-radius: 6px; }
.photo-thumb.frame-polaroid img { border-radius: 2px; }
.photo-thumb.frame-pink { border: 6px solid #e7a8b8; border-radius: 14px; }
.photo-thumb.frame-blue { border: 6px solid #8fb4d9; border-radius: 14px; }
.photo-thumb.frame-yellow { border: 6px solid #e8cf7a; border-radius: 14px; }
.photo-detail-preview { width: 100%; }

.swatch-row { display: flex; gap: 10px; flex-wrap: wrap; }
.swatch { display: flex; flex-direction: column; align-items: center; gap: 4px; background: none; border: 2px solid transparent; border-radius: 10px; padding: 4px; cursor: pointer; font-size: 11px; color: var(--text-muted); }
.swatch img { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; display: block; }
.swatch.swatch-active { border-color: var(--accent); color: var(--accent-dark); font-weight: 600; }
.frame-preview { width: 46px; height: 46px; border-radius: 8px; background: var(--accent-soft); }
.frame-preview.frame-none { border: 2px dashed var(--border); background: transparent; }
.frame-preview.frame-rounded { border-radius: 20px; background: var(--accent-soft); }
.frame-preview.frame-polaroid { background: #fffdf8; box-shadow: 0 2px 6px rgba(0,0,0,.2); border-radius: 3px; }
.frame-preview.frame-pink { border: 5px solid #e7a8b8; }
.frame-preview.frame-blue { border: 5px solid #8fb4d9; }
.frame-preview.frame-yellow { border: 5px solid #e8cf7a; }

.timeline { border-left: 2px solid var(--border); margin-left: 10px; padding-left: 20px; }
.timeline-entry { position: relative; padding-bottom: 20px; }
.timeline-entry::before { content: ""; position: absolute; left: -26px; top: 4px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); }
.timeline-entry .date { font-size: 12px; color: var(--text-muted); }
.timeline-entry .title { font-weight: 600; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(30,25,20,0.35);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal {
  background: white; border-radius: var(--radius); padding: 22px 24px;
  width: min(560px, 92vw); max-height: 88vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.modal-close { float: right; background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); }

.lock-screen {
  position: fixed; inset: 0; background: var(--bg);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.lock-card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 34px 36px; text-align: center; width: 320px; }
.lock-icon { font-size: 34px; margin-bottom: 6px; }
.brand-logo { width: 120px; height: 120px; border-radius: 22px; margin-bottom: 10px; }
.lock-card input { width: 100%; margin: 14px 0 10px; text-align: center; letter-spacing: 4px; }
/* [Versión web] #login-form mete usuario/contraseña dentro de <label>
   (no un input suelto como el PIN), así que aquí se sobreescribe el
   centrado/letter-spacing pensado para el PIN por un formulario normal. */
#login-form { text-align: left; }
#login-form label { margin-bottom: 10px; }
#login-form input { width: 100%; margin: 0; text-align: left; letter-spacing: normal; }
#login-form .btn { width: 100%; margin-top: 6px; }

.onboarding { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 90; }
.onboarding-card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 30px 34px; width: min(480px, 92vw); }

.error-text { color: var(--red); font-size: 13px; }
.success-text { color: var(--green); font-size: 13px; }

.section-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }

.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--accent-soft); color: var(--accent-dark); border-radius: 999px; padding: 3px 10px; font-size: 12px; margin-right: 6px; }

canvas.chart { width: 100%; height: 260px; }

/* Tablas envueltas en un contenedor con scroll horizontal propio, para que
   una tabla ancha (p.ej. historial de mediciones) nunca obligue a toda la
   página a desplazarse hacia los lados en una pantalla estrecha. */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-scroll table { min-width: 480px; }

img, svg, canvas { max-width: 100%; }

/* ============================================================
   Adaptación a tablets y móviles (pantallas táctiles y estrechas)
   ============================================================
   Por debajo de 900px, el menú lateral fijo dejaría muy poco espacio
   para el contenido, así que se convierte en un panel deslizante que se
   abre con el botón ☰ de la barra superior, en vez de estar siempre
   visible. A partir de aquí también se agrandan las zonas táctiles
   (botones, campos, elementos de lista) para que sean cómodas con el
   dedo, no solo con ratón.
*/
@media (max-width: 900px) {
  html, body { overflow-x: hidden; }

  .app-shell { flex-direction: column; height: 100vh; overflow: hidden; }

  .topbar {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; background: var(--panel);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
  }
  .topbar .brand-logo-sm { width: 28px; height: 28px; }
  .topbar-title { min-width: 0; }
  .topbar-title .brand-title { font-size: 14px; }
  .topbar-title .brand-subtitle { font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 41;
    width: min(280px, 82vw);
    box-shadow: 6px 0 24px rgba(20, 15, 10, 0.25);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close {
    display: block; position: absolute; right: 0; top: 0;
    background: none; border: none; font-size: 18px; cursor: pointer;
    color: var(--text-muted); padding: 6px 10px;
  }

  .sidebar-backdrop.visible {
    display: block; position: fixed; inset: 0;
    background: rgba(20, 15, 10, 0.4); z-index: 40;
  }

  .content { flex: 1; padding: 18px 16px; overflow-x: hidden; }

  /* Zonas táctiles más grandes: botones, campos y elementos de lista. */
  .nav-item { padding: 13px 14px; font-size: 15px; }
  .btn { padding: 11px 16px; min-height: 42px; }
  .btn-sm { padding: 8px 12px; min-height: 36px; }
  input, select, textarea { padding: 11px 12px; min-height: 42px; }
  textarea { min-height: 80px; }
  .list-item { padding: 12px 4px; }
  .tab-btn { padding: 12px 14px; }
  .modal-close { font-size: 22px; padding: 6px; }

  .dashboard-hero { flex-wrap: wrap; gap: 12px; }
  .hero-avatar { width: 56px; height: 56px; font-size: 26px; }
  .hero-name { font-size: 19px; }

  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }

  .modal { padding: 18px 16px; width: min(560px, 94vw); }
  .lock-card, .onboarding-card { width: min(360px, 92vw); padding: 26px 22px; }
  .brand-logo { width: 96px; height: 96px; }
}

/* Móviles pequeños: un poco más compacto todavía. */
@media (max-width: 480px) {
  .content { padding: 14px 12px; }
  .card { padding: 14px 14px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .dashboard-hero { justify-content: center; text-align: center; }
  .card-header { flex-wrap: wrap; gap: 8px; }
  .section-title-row { flex-wrap: wrap; gap: 10px; }
}
