:root {
  --pink: #e0178a;
  --pink-2: #f3dca0;
  --fuchsia: #a60e60;
  --bg: #fbe7f0;
  --purple: #7a0e45;
  --ink: #3a0a22;
  --muted: #8a5a72;
  --line: #f0d9e6;
  --white: #ffffff;
  --danger: #e5395f;
  --radius: 16px;
  --shadow: 0 14px 34px rgba(122, 14, 69, 0.16);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: "Poppins", system-ui, sans-serif; color: var(--ink); background: var(--bg); }
a { text-decoration: none; color: inherit; }
.hidden { display: none !important; }

/* ---------- Botones ---------- */
.btn { border: none; cursor: pointer; border-radius: 999px; font-weight: 600; font-family: inherit;
  padding: 11px 22px; font-size: 14px; transition: transform .12s ease, box-shadow .12s ease, background .2s; }
.btn-primary { background: linear-gradient(135deg, var(--pink), var(--fuchsia)); color: #fff;
  box-shadow: 0 8px 20px rgba(255,79,157,.35); }
.btn-primary:hover { transform: translateY(-2px); }
.btn-ghost { background: transparent; color: var(--purple); border: 1.5px solid var(--line); }
.btn-ghost:hover { background: rgba(185,103,255,.08); }
.btn-sm { padding: 8px 16px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-danger { background: transparent; color: var(--danger); border: 1.5px solid rgba(229,57,95,.3); }
.btn-danger:hover { background: rgba(229,57,95,.08); }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(900px 500px at 80% -10%, rgba(185,103,255,.2), transparent),
              radial-gradient(700px 400px at -10% 20%, rgba(255,79,157,.18), transparent), var(--bg); }
.login-card { background: #fff; width: 100%; max-width: 380px; padding: 38px 34px; border-radius: 24px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 12px; }
.login-logo { width: 64px; height: 64px; border-radius: 18px; object-fit: cover; margin: 0 auto 6px; }
.login-card h1 { font-size: 22px; text-align: center; }
.login-sub { text-align: center; color: var(--muted); margin-bottom: 12px; font-size: 14px; }
.login-card label { font-size: 13px; font-weight: 600; color: var(--muted); }
.login-card input { padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 12px; font-family: inherit; font-size: 14px; }
.login-card input:focus { outline: none; border-color: var(--pink); }
.login-card .btn { margin-top: 8px; }
.login-error { color: var(--danger); font-size: 13px; text-align: center; min-height: 18px; }
.login-back { text-align: center; color: var(--purple); font-size: 13px; margin-top: 6px; }

/* ---------- App layout ---------- */
.app { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { background: #fff; border-bottom: 1px solid var(--line); padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 20; }
.topbar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
.topbar-brand b { color: var(--pink); }
.topbar-brand img { width: 36px; height: 36px; border-radius: 10px; object-fit: cover; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.current-user { font-size: 13px; color: var(--muted); }

.layout { display: grid; grid-template-columns: 230px 1fr; flex: 1; }
.sidebar { background: #fff; border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 6px; }
.nav-item { text-align: left; background: transparent; border: none; cursor: pointer; font-family: inherit;
  padding: 12px 16px; border-radius: 12px; font-size: 15px; font-weight: 500; color: var(--muted); transition: .15s; }
.nav-item:hover { background: var(--bg); color: var(--ink); }
.nav-item.active { background: linear-gradient(135deg, rgba(255,79,157,.14), rgba(185,103,255,.14)); color: var(--purple); font-weight: 600; }

.content { padding: 26px 30px; }
.content-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.content-head h2 { font-size: 26px; }

/* ---------- Tabla ---------- */
.table-wrap { background: #fff; border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
th, td { text-align: left; padding: 14px 18px; font-size: 14px; border-bottom: 1px solid var(--line); }
th { background: #faf7fc; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
tr:last-child td { border-bottom: none; }
td .row-actions { display: flex; gap: 8px; }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill-on { background: rgba(46,183,120,.14); color: #1f9d63; }
.pill-off { background: rgba(150,150,160,.16); color: #777; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.cell-sub { color: var(--muted); font-size: 12px; }

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(45,36,56,.5); display: grid; place-items: center;
  padding: 20px; z-index: 100; backdrop-filter: blur(3px); }
.modal { background: #fff; width: 100%; max-width: 560px; border-radius: 20px; box-shadow: var(--shadow);
  max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.modal-head h3 { font-size: 20px; }
.modal-close { background: transparent; border: none; font-size: 26px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 22px 24px; overflow-y: auto; display: grid; gap: 14px; }
.modal-body label { font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: -8px; }
.modal-body input, .modal-body textarea, .modal-body select {
  padding: 11px 13px; border: 1.5px solid var(--line); border-radius: 11px; font-family: inherit; font-size: 14px; width: 100%; }
.modal-body input:focus, .modal-body textarea:focus, .modal-body select:focus { outline: none; border-color: var(--pink); }
.modal-body textarea { resize: vertical; min-height: 70px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.checkbox-row { display: flex; align-items: center; gap: 10px; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: 12px; padding: 18px 24px; border-top: 1px solid var(--line); }

/* ---------- Toast ---------- */
.toast { position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff;
  padding: 13px 24px; border-radius: 12px; font-size: 14px; z-index: 200; box-shadow: var(--shadow); }
.toast.error { background: var(--danger); }

/* ---------- Ajustes QR / Flyer ---------- */
.settings { padding: 26px 28px; max-width: 640px; }
.settings .field { margin-bottom: 16px; }
.settings .field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.settings .field input {
  width: 100%; padding: 11px 13px; border: 1.5px solid var(--line); border-radius: 11px;
  font-family: inherit; font-size: 14px; color: var(--ink); background: #fff;
}
.settings .field input:focus { outline: none; border-color: var(--pink); box-shadow: 0 0 0 3px rgba(224, 23, 138, 0.12); }
.settings .actions { display: flex; gap: 12px; flex-wrap: wrap; margin: 6px 0 14px; }
.settings .hint { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.settings .qrurl {
  word-break: break-all; background: #faf7fc; border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; font-size: 12.5px; color: var(--purple); margin-top: 12px;
}
.settings .qrurl b { color: var(--ink); }
.settings .status { margin-top: 14px; font-size: 13px; font-weight: 600; }
.settings .status.ok { color: #1f9d63; }
.settings .status.err { color: var(--danger); }

/* ---------- Fotos (subida al servidor) ---------- */
.photos-field { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.photo-tile { position: relative; width: 72px; height: 72px; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); background: #faf7fc; }
.photo-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-tile .ph-local { width: 100%; height: 100%; display: grid; place-items: center; font-size: 10px; color: var(--muted); text-align: center; padding: 4px; }
.photo-tile .ph-del { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; border-radius: 50%; border: none; cursor: pointer;
  background: rgba(0,0,0,.6); color: #fff; font-size: 13px; line-height: 1; display: grid; place-items: center; }
.photo-add { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; padding: 9px 14px; border-radius: 999px;
  border: 1.5px dashed var(--pink); color: var(--pink); font-size: 13px; font-weight: 600; background: #fff; }
.photo-add input { display: none; }
.photo-uploading { font-size: 12px; color: var(--muted); }

/* ---------- Historias clínicas ---------- */
.clinical { padding: 4px 2px; }
.clinical-top { display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end; margin-bottom: 18px; }
.clinical-top .field { flex: 1 1 240px; display: flex; flex-direction: column; gap: 6px; }
.clinical-top label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.clinical-top input, .clinical-top select { padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; font-family: inherit; font-size: 14px; }
.clinical-top input:focus, .clinical-top select:focus { outline: none; border-color: var(--pink); }
.clinical-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.records-list { display: grid; gap: 10px; margin-bottom: 8px; }
.record-card { display: flex; align-items: center; justify-content: space-between; gap: 12px; background: #fff;
  border: 1px solid var(--line); border-radius: 14px; padding: 12px 16px; box-shadow: var(--shadow); }
.record-card .rc-info { display: flex; align-items: center; gap: 12px; }
.record-card .rc-type { padding: 4px 12px; border-radius: 999px; font-size: 12px; font-weight: 700; color: #fff;
  background: linear-gradient(135deg, var(--pink), var(--fuchsia)); }
.record-card .rc-type.facial { background: linear-gradient(135deg, var(--fuchsia), var(--purple)); }
.record-card .rc-date { font-size: 13px; color: var(--muted); }
.record-card .rc-actions { display: flex; gap: 8px; }
.clinical-empty { color: var(--muted); font-size: 13px; padding: 6px 2px 16px; }

/* Libro con paso de página */
.book-wrap { margin-top: 10px; }
.book-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; gap: 12px; flex-wrap: wrap; }
.book-head h3 { font-size: 18px; color: var(--purple); }
.book-head .pager { font-size: 13px; color: var(--muted); font-weight: 600; }
.book { perspective: 2200px; position: relative; }
.page {
  background: #fff; border: 1px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  padding: 26px 28px; min-height: 360px; max-height: 64vh; overflow-y: auto;
  transform-origin: left center; transition: transform .42s cubic-bezier(.4,.0,.2,1), opacity .32s ease;
  backface-visibility: hidden;
}
.page.hidden-page { display: none; }
.page.flip-next-out { transform: rotateY(-92deg); opacity: 0; }
.page.flip-next-in  { transform: rotateY(92deg);  opacity: 0; }
.page.flip-prev-out { transform: rotateY(92deg);  opacity: 0; }
.page.flip-prev-in  { transform: rotateY(-92deg); opacity: 0; }
.page-title { font-family: "Georgia", serif; font-size: 22px; color: var(--pink); margin-bottom: 4px; }
.page-rule { height: 2px; background: linear-gradient(90deg, var(--gold), transparent); border-radius: 2px; margin-bottom: 18px; }
.page .field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.page .field > label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
.page input[type=text], .page input[type=number], .page input[type=date], .page textarea, .page select {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; font-family: inherit; font-size: 14px; color: var(--ink); background: #fff;
}
.page input:focus, .page textarea:focus, .page select:focus { outline: none; border-color: var(--pink); box-shadow: 0 0 0 3px rgba(224,23,138,.10); }
.page textarea { resize: vertical; min-height: 64px; }
.page .row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Sí/No */
.yn-table { width: 100%; border-collapse: collapse; }
.yn-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
.yn-table td:first-child { color: var(--ink); }
.yn-table td.yn-cell { width: 56px; text-align: center; }
.yn-table th { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; padding: 4px 8px; text-align: center; }
.yn-table th:first-child { text-align: left; }

/* Check group */
.check-grid { display: flex; flex-wrap: wrap; gap: 8px 16px; }
.check-grid label { display: inline-flex; align-items: center; gap: 7px; font-size: 13.5px; color: var(--ink); cursor: pointer; }
.check-grid input { width: auto; accent-color: var(--pink); }

/* Radio */
.radio-row { display: flex; gap: 18px; }
.radio-row label { display: inline-flex; align-items: center; gap: 7px; font-size: 14px; cursor: pointer; }
.radio-row input { accent-color: var(--pink); }

/* Medidas */
.measures-table { width: 100%; border-collapse: collapse; }
.measures-table th, .measures-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); font-size: 13px; text-align: center; }
.measures-table th:first-child, .measures-table td:first-child { text-align: left; color: var(--ink); font-weight: 500; }
.measures-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .4px; }
.measures-table input { width: 80px; padding: 6px 8px; border: 1.5px solid var(--line); border-radius: 8px; text-align: center; font-family: inherit; }
.measures-table input:focus { outline: none; border-color: var(--pink); }

/* Sesiones */
.sessions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 18px; }
.session-row { display: flex; align-items: center; gap: 10px; }
.session-row .snum { font-weight: 700; color: var(--purple); font-size: 13px; min-width: 78px; }
.session-row input { flex: 1; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 8px; font-family: inherit; }
.session-row input:focus { outline: none; border-color: var(--pink); }

/* Grupo (protocolo) */
.group-block { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 12px; background: #fdfaff; }
.group-block h4 { font-size: 13px; color: var(--fuchsia); margin-bottom: 8px; text-transform: uppercase; letter-spacing: .4px; }

.book-nav { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; gap: 12px; }
.book-nav .dots { display: flex; gap: 6px; }
.book-nav .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--line); cursor: pointer; transition: .2s; }
.book-nav .dot.active { background: var(--pink); transform: scale(1.25); }

@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; overflow-x: auto; border-right: none; border-bottom: 1px solid var(--line); }
  .nav-item { white-space: nowrap; }
  .field-row { grid-template-columns: 1fr; }
}
