/* =========================================================
   Consentimientos · Puentepiedra Dental
   Estética: relieve suave sobre piedra cálida (neumorfismo ligero),
   etiquetas en mayúsculas espaciadas, cifras grandes y finas,
   acento cobre del logo.
   ========================================================= */
:root {
  --bg: #ECE9E4;
  --surface: #F1EEEA;
  --paper: #FFFFFF;
  --ink: #2B2420;
  --text: #4A413B;
  --muted: #8C827B;
  --faint: #B5ABA3;
  --line: rgba(43, 36, 32, 0.09);
  --accent: #94502C;        /* cobre oscuro: botones y textos de acento (contraste AA) */
  --accent-strong: #7A4123;
  --copper: #B8673C;
  --logo: #CD8302;
  --accent-soft: #F3E4D8;
  --sand: #F7F3EE;
  --ok: #3E8E5A;
  --ok-soft: #DDEFE2;
  --warn: #A86A00;
  --warn-soft: #F8EBCF;
  --info: #5A6FA8;
  --info-soft: #E3E8F6;
  --danger: #B3402F;
  --danger-soft: #F7E1DC;

  --sh-hi: rgba(255, 255, 255, 0.85);
  --sh-lo: rgba(158, 147, 135, 0.38);
  --neo: 9px 9px 22px var(--sh-lo), -9px -9px 22px var(--sh-hi);
  --neo-sm: 5px 5px 12px var(--sh-lo), -5px -5px 12px var(--sh-hi);
  --neo-in: inset 4px 4px 10px var(--sh-lo), inset -4px -4px 10px var(--sh-hi);
  --radius: 26px;
  --font: "DM Sans", "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --display: "DM Sans", "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
/* brillo cálido arriba a la derecha */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 520px at 88% -8%, rgba(205, 131, 2, 0.10), transparent 60%),
    radial-gradient(700px 420px at 62% 0%, rgba(184, 103, 60, 0.08), transparent 65%),
    var(--bg);
}
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 500; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--copper); outline-offset: 3px; }
code { font: 12.5px ui-monospace, Consolas, monospace; background: rgba(43,36,32,.06); padding: 1px 6px; border-radius: 6px; }

.neo { background: var(--surface); border-radius: var(--radius); box-shadow: var(--neo); }
.neo-sm { background: var(--surface); border-radius: 16px; box-shadow: var(--neo-sm); }
.neo-in { background: var(--surface); box-shadow: var(--neo-in); }
.eyebrow, .side-label, .card-title, .stat-label, .mini-label, .ring-label, th, .date-month {
  text-transform: uppercase; letter-spacing: 0.14em; font-size: 11px; font-weight: 600; color: var(--muted);
}
.eyebrow { color: var(--copper); }
.muted { color: var(--muted); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--warn); display: inline-block; flex: none; }
.dot.ok { background: var(--ok); }
.dot.dim { background: var(--faint); }
.dot.info { background: var(--info); }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 20px;
  border: 0; border-radius: 14px;
  background: var(--surface); box-shadow: var(--neo-sm);
  cursor: pointer; font-weight: 600; font-size: 14px; color: var(--ink); text-decoration: none;
  transition: box-shadow .18s, transform .06s, background .18s, color .18s;
}
.btn:hover { color: var(--accent); }
.btn:active { box-shadow: var(--neo-in); transform: translateY(1px); }
.btn[disabled] { opacity: .45; cursor: not-allowed; box-shadow: none; }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 6px 6px 14px rgba(122, 65, 35, .28), -5px -5px 12px var(--sh-hi); }
.btn.primary:hover:not([disabled]) { background: var(--accent-strong); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { background: var(--danger-soft); }
.btn.ghost { box-shadow: none; background: transparent; color: var(--muted); }
.btn.ghost:hover { background: rgba(43,36,32,.05); color: var(--ink); }
.btn.sm { min-height: 34px; padding: 0 14px; font-size: 13px; border-radius: 11px; }
.pill-btn { text-transform: uppercase; letter-spacing: .12em; font-size: 12px; min-height: 46px; padding: 0 24px; border-radius: 16px; }
.pill-btn span { font-size: 17px; letter-spacing: 0; font-weight: 400; }
.link { border: 0; background: none; color: var(--muted); font-size: 13px; cursor: pointer; padding: 4px 2px; }
.link:hover { color: var(--accent); }

/* ---------- formularios ---------- */
label.field { display: grid; gap: 7px; font-size: 13px; font-weight: 600; color: var(--text); }
label.field .hint, .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; margin: 0; }
.input {
  width: 100%; min-height: 44px; padding: 10px 14px;
  border: 0; border-radius: 13px; background: var(--surface);
  box-shadow: var(--neo-in); color: var(--ink);
}
.input::placeholder { color: var(--faint); }
.input:focus { outline: none; box-shadow: var(--neo-in), 0 0 0 2px rgba(184, 103, 60, .45); }
select.input { appearance: none; padding-right: 36px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238C827B' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M7 10l5 5 5-5'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; background-size: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.grid-2:empty { display: none; }
.stack { display: grid; gap: 16px; }
.card-pad { padding: 26px; }
.error-box { background: var(--danger-soft); color: var(--danger); border-radius: 12px; padding: 10px 14px; font-size: 14px; }
.warn-box { background: var(--warn-soft); color: #6E4A00; border-radius: 14px; padding: 12px 16px; font-size: 13.5px; }
.warn-box ul { margin: 6px 0 0; padding-left: 18px; }
.form-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 4px; }
.form-actions .primary { flex: 1; min-width: 190px; }

/* ---------- login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(410px, 100%); padding: 36px 34px; display: grid; gap: 18px; }
.login-logo { width: 132px; margin: 0 auto 6px; }
.login-title { font-size: 22px; font-weight: 500; margin-top: 2px; }
.demo-hint { font-size: 13px; background: var(--accent-soft); color: var(--accent-strong); padding: 10px 14px; border-radius: 12px; }

/* ---------- estructura ---------- */
.shell { display: grid; grid-template-columns: 250px 1fr; gap: 34px; padding: 22px 28px 22px 22px; min-height: 100dvh; }
.side {
  position: sticky; top: 22px; height: calc(100dvh - 44px);
  display: flex; flex-direction: column; padding: 26px 16px 16px; overflow: hidden auto;
}
.side-brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 22px; }
.side-brand img { width: 26px; height: auto; }
.side-brand span { text-transform: uppercase; letter-spacing: .2em; font-weight: 600; font-size: 13px; color: var(--ink); }
.side-label { padding: 18px 10px 8px; font-size: 10.5px; }
.side-nav { display: grid; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 12px; width: 100%;
  border: 0; background: transparent; border-radius: 14px; padding: 11px 12px;
  font-size: 14.5px; color: var(--text); cursor: pointer; text-align: left;
  transition: background .18s, box-shadow .18s, color .18s;
}
.nav-item svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; color: var(--muted); flex: none; }
.nav-item:hover { color: var(--ink); background: rgba(255,255,255,.35); }
.nav-item[aria-current="page"] { background: var(--surface); box-shadow: var(--neo-sm); color: var(--ink); font-weight: 500; }
.nav-item[aria-current="page"] svg { color: var(--copper); }
.nav-count { margin-left: auto; font-size: 12px; color: var(--muted); }
.side-spacer { flex: 1; min-height: 20px; }
.side-widgets { display: grid; grid-template-columns: 84px 1fr; gap: 12px; align-items: center; margin-bottom: 12px; }
.clock { width: 84px; height: 84px; border-radius: 50%; display: grid; place-items: center; }
.clock svg { width: 72px; height: 72px; }
.clock line { stroke: var(--ink); stroke-linecap: round; }
#clockH { stroke-width: 2.4; }
#clockM { stroke-width: 1.4; }
.clock circle { fill: var(--copper); }
.clock .ticks line { stroke: var(--faint); stroke-width: 1; }
.mini { padding: 10px 12px; display: grid; gap: 4px; min-width: 0; }
.mini-label { font-size: 9.5px; }
.mini-row { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-logout { display: flex; align-items: center; gap: 10px; border: 0; padding: 9px 12px; cursor: pointer; font-size: 13.5px; color: var(--text); text-align: left; }
.side-logout .logout-txt { margin-left: auto; font-size: 12px; color: var(--muted); }
.side-logout:hover .logout-txt { color: var(--danger); }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }

.main { min-width: 0; padding: 26px 4px 40px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 30px; }
.page-head h1 { font-family: var(--display); font-size: clamp(30px, 3.2vw, 40px); font-weight: 400; letter-spacing: -0.02em; }
.page-head p { margin: 6px 0 0; color: var(--muted); font-size: 15px; }
.head-actions { display: flex; gap: 12px; align-items: center; }

/* ---------- inicio ---------- */
.dash-top { display: grid; grid-template-columns: 1.25fr .72fr 1.6fr; gap: 26px; margin-bottom: 26px; }
.date-card {
  justify-content: flex-end;
  min-height: 196px; position: relative; overflow: hidden; padding: 16px;
  background: #ddd url("/brand/recepcion.webp") 0% 27% / 104% auto;
  display: flex; align-items: flex-end;
}
.date-card::after { content: ""; position: absolute; inset: 0; background: linear-gradient(160deg, rgba(255,255,255,0) 40%, rgba(43,36,32,.12)); pointer-events: none; }
.date-tile { position: relative; z-index: 1; background: rgba(250, 248, 245, .92); backdrop-filter: blur(6px); border-radius: 18px; padding: 12px 20px 12px; box-shadow: 0 6px 20px rgba(43,36,32,.12); }
.date-day { font-family: var(--display); font-size: 50px; font-weight: 300; line-height: 1; letter-spacing: -0.03em; }
.date-month { font-size: 10px; margin-top: 6px; color: var(--text); }
.ring-card { display: grid; place-items: center; padding: 18px; }
.ring { position: relative; width: 158px; height: 158px; border-radius: 50%; display: grid; place-items: center; align-content: center; }
.ring svg { position: absolute; inset: 7px; width: calc(100% - 14px); height: calc(100% - 14px); transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: rgba(43,36,32,.05); stroke-width: 5; }
.ring-fg { fill: none; stroke: var(--copper); stroke-width: 5; stroke-linecap: round; stroke-dasharray: 326.7; stroke-dashoffset: 326.7; transition: stroke-dashoffset .8s cubic-bezier(.22,1,.36,1); }
.ring-num { font-family: var(--display); font-size: 52px; font-weight: 300; line-height: 1; letter-spacing: -0.03em; position: relative; }
.ring-label { font-size: 9.5px; margin-top: 8px; position: relative; }
.stats-card { display: grid; grid-template-columns: repeat(3, 1fr); padding: 24px 18px; gap: 10px; }
.stat { display: grid; justify-items: center; gap: 12px; text-align: center; }
.stat-label { font-size: 10.5px; }
.stat-num { width: 92px; height: 92px; border-radius: 20px; display: grid; place-items: center; font-family: var(--display); font-size: 46px; font-weight: 300; letter-spacing: -0.03em; }
.stat-sub { font-size: 12.5px; color: var(--muted); }
.dash-bottom { display: grid; grid-template-columns: 1.3fr 1fr; gap: 26px; }
.panel-card { padding: 22px 24px; min-height: 300px; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.card-title { display: inline-flex; align-items: center; gap: 9px; }
.recent { display: grid; gap: 10px; }
.recent-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 14px; align-items: center;
  padding: 12px 16px; border-radius: 16px; background: var(--surface); box-shadow: var(--neo-sm);
  cursor: pointer; border: 0; text-align: left; width: 100%;
}
.recent-item:hover .r-name { color: var(--accent); }
.r-name { font-weight: 500; }
.r-sub { font-size: 12.5px; color: var(--muted); grid-column: 1; }
.r-time { font-size: 12px; color: var(--muted); grid-row: 1 / span 2; grid-column: 2; text-align: right; }
.empty-mini { padding: 30px 10px; text-align: center; color: var(--muted); font-size: 14px; }
.dash-tablet { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: 16px; box-shadow: var(--neo-in); }
.dash-tablet .t1 { font-weight: 500; }
.dash-tablet .t2 { font-size: 12.5px; color: var(--muted); }
.top-tpl { display: grid; gap: 10px; }
.top-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; font-size: 13.5px; align-items: center; }
.bar { grid-column: 1 / -1; height: 6px; border-radius: 6px; box-shadow: var(--neo-in); overflow: hidden; }
.bar span { display: block; height: 100%; background: linear-gradient(90deg, var(--copper), var(--logo)); border-radius: 6px; }

/* ---------- nuevo consentimiento ---------- */
.new-layout { display: grid; grid-template-columns: minmax(340px, 430px) 1fr; gap: 28px; align-items: start; }
.step-title { display: flex; align-items: center; gap: 12px; font-size: 17px; font-weight: 500; }
.step-num { width: 28px; height: 28px; border-radius: 50%; background: var(--surface); box-shadow: var(--neo-sm); color: var(--copper); font-size: 13px; font-weight: 700; display: grid; place-items: center; flex: none; }
.tablet-card { padding: 16px 20px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; border-radius: 20px; }
.tablet-card .info { flex: 1; min-width: 200px; }
.tablet-card .title { font-weight: 600; }
.tablet-card .sub { font-size: 13.5px; color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--warn-soft); color: var(--warn); white-space: nowrap; }
.pill .dot { background: currentColor; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pulse { width: 12px; height: 12px; border-radius: 50%; background: var(--copper); position: relative; flex: none; }
.pulse::after { content: ""; position: absolute; inset: -6px; border-radius: 50%; border: 2px solid var(--copper); animation: pulse 1.6s ease-out infinite; }
@keyframes pulse { from { transform: scale(.5); opacity: 1; } to { transform: scale(1.5); opacity: 0; } }
.pair-help { font-size: 13px; border-radius: 12px; padding: 10px 14px; width: 100%; box-shadow: var(--neo-in); }
.preview-label { font-size: 12px; color: var(--muted); margin: 0 4px 10px; display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.legend { display: flex; gap: 6px; }
.legend mark { font-size: 11px; padding: 1px 6px; border-radius: 5px; background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.legend mark.empty { background: var(--warn-soft); color: var(--warn); }

/* ---------- hoja del documento (vista previa, editor y tablet) ---------- */
.sheet {
  background: var(--paper); border-radius: 6px; color: #3A322D;
  box-shadow: 0 1px 2px rgba(43,36,32,.06), 0 18px 40px -18px rgba(43,36,32,.28);
  padding: 44px 52px 34px; font: 14.5px/1.65 var(--font); max-width: 820px; margin: 0 auto;
}
.sh-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 20px; padding-bottom: 18px; border-bottom: 1px solid #E6DFD7; margin-bottom: 26px; }
.sh-logo { width: 104px; height: auto; display: block; }
.sh-addr { text-align: right; font-size: 11.5px; color: var(--muted); display: grid; line-height: 1.45; }
.sh-addr b { color: var(--ink); font-weight: 600; }
.sh-eyebrow { text-transform: uppercase; letter-spacing: .16em; font-size: 10.5px; font-weight: 700; color: var(--copper); }
.sh-title { font-size: 27px; font-weight: 600; color: var(--ink); margin: 6px 0 18px; letter-spacing: -0.01em; }
.sh-ficha { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 24px; margin: 0 0 24px; padding: 16px 20px; background: var(--sand); border-radius: 12px; }
.sh-ficha dt { text-transform: uppercase; letter-spacing: .1em; font-size: 9.5px; font-weight: 700; color: var(--muted); }
.sh-ficha dd { margin: 2px 0 0; font-size: 14.5px; color: var(--ink); font-weight: 500; }
.sh-body p { margin: 0 0 12px; }
.sh-body h3 { font-size: 15.5px; font-weight: 700; color: var(--accent); margin: 20px 0 6px; }
.sh-body ul, .sh-body ol { margin: 0 0 14px; padding-left: 22px; }
.sh-body li { margin: 0 0 8px; padding-left: 4px; }
.sh-body ul li::marker { color: var(--copper); font-size: 1.1em; }
.sh-body ol li::marker { color: var(--copper); font-weight: 700; }
.sh-body blockquote { margin: 18px 0 6px; padding: 14px 18px 14px 20px; background: #F6EDE4; border-left: 3px solid var(--copper); border-radius: 0 10px 10px 0; font-weight: 700; color: var(--ink); }
.sh-body strong { color: var(--ink); }
.sh-place { font-style: italic; margin: 18px 0 0; }
.sh-signs { margin-top: 18px; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 300px)); gap: 18px 28px; }
.sh-sign { width: 100%; }
.sh-sign-box .sig-svg, .sh-sign-box .sig-img { position: absolute; left: 14px; right: 14px; top: 20px; bottom: 16px; width: calc(100% - 28px); height: calc(100% - 36px); color: var(--ink); }
.sig-img { object-fit: contain; }
.sh-sign-box.pro.signed { border-style: solid; background: #fff; }
.sh-nosig { position: absolute; left: 14px; right: 14px; top: 42px; text-align: center; font-size: 12px; color: #B0533B; font-style: normal; }
.sh-sign-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.sh-sign-box { height: 96px; border: 1px dashed #D9CFC5; border-radius: 10px; position: relative; }
.sh-sign-box span { position: absolute; left: 14px; top: 9px; text-transform: uppercase; letter-spacing: .12em; font-size: 9.5px; font-weight: 700; color: var(--copper); }
.sh-sign-box::after { content: ""; position: absolute; left: 14px; right: 14px; bottom: 20px; border-bottom: 1px solid #E6DFD7; }
.sh-sign-name { margin-top: 8px; font-weight: 600; font-size: 13.5px; color: var(--ink); }
.sh-foot { margin-top: 26px; padding-top: 12px; border-top: 1px solid #E6DFD7; font-size: 11px; color: var(--muted); }
.sheet mark { background: var(--accent-soft); color: var(--accent-strong); padding: 0 3px; border-radius: 4px; font-weight: 600; }
.sheet mark.empty { background: var(--warn-soft); color: var(--warn); font-weight: 500; }
.sheet .sh-intro { font-family: var(--font); color: var(--muted); }

/* ---------- histórico ---------- */
.filters { display: grid; grid-template-columns: 2fr 1.3fr 1fr 1fr auto; gap: 14px; align-items: end; padding: 20px 22px; margin-bottom: 18px; }
.count-line { font-size: 13px; color: var(--muted); margin: 0 8px 12px; }
.table-wrap { overflow-x: auto; padding: 8px 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 10.5px; padding: 14px 16px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 13px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .15s; }
tbody tr:hover { background: rgba(255,255,255,.45); }
tbody tr:last-child td { border-bottom: 0; }
.cell-main { font-weight: 500; }
.cell-sub { font-size: 12.5px; color: var(--muted); }
.tag { display: inline-block; padding: 3px 11px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.empty-state { padding: 54px 16px; text-align: center; color: var(--muted); }

/* diálogos */
dialog { border: 0; padding: 0; border-radius: 24px; width: min(1060px, 94vw); max-height: 92dvh; box-shadow: 0 30px 80px rgba(43,36,32,.35); color: var(--ink); background: var(--surface); }
dialog::backdrop { background: rgba(43, 36, 32, .42); backdrop-filter: blur(3px); }
.dlg { display: grid; grid-template-columns: 320px 1fr; height: min(780px, 90dvh); }
.dlg-side { padding: 26px; overflow-y: auto; display: grid; gap: 16px; align-content: start; }
.dlg-side dl { margin: 0; display: grid; gap: 12px; }
.dlg-side dt { font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 600; }
.dlg-side dd { margin: 2px 0 0; font-size: 14px; word-break: break-word; }
.dlg-side .hash { font: 11.5px/1.4 ui-monospace, Consolas, monospace; color: var(--text); }
.dlg-pdf { width: 100%; height: 100%; border: 0; background: #DCD7D0; }

/* ---------- plantillas ---------- */
.tpl-intro { display: flex; justify-content: space-between; align-items: center; gap: 20px; flex-wrap: wrap; padding: 22px 26px; margin-bottom: 26px; }
.tpl-intro p { margin: 8px 0 0; max-width: 620px; font-size: 14px; }
.tpl-actions { display: flex; gap: 12px; flex-wrap: wrap; }
.drop-zone { border: 2px dashed var(--copper); border-radius: 22px; padding: 40px; text-align: center; color: var(--accent); font-weight: 600; margin-bottom: 22px; background: rgba(255,255,255,.4); }
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 24px; }
/* Tarjetas de la misma fila con la misma altura: título reservado a dos líneas, etiquetas que crecen
   y el botón Editar siempre al pie, alineado entre tarjetas. */
.tpl-card { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.tpl-card .tpl-head { min-height: 68px; }
.tpl-card h3 { font-size: 17px; font-weight: 500; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.tpl-card .chips { flex: 1; align-content: flex-start; }
.tpl-meta { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
.tpl-thumb { height: 150px; overflow: hidden; border-radius: 14px; box-shadow: var(--neo-in); padding: 10px; position: relative; cursor: pointer; }
.tpl-thumb .sheet { transform: scale(.36); transform-origin: top left; width: 278%; max-width: none; pointer-events: none; padding: 34px 40px; }
.tpl-thumb::after { content: ""; position: absolute; inset: 0; background: linear-gradient(transparent 55%, var(--surface)); border-radius: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font: 12px ui-monospace, Consolas, monospace; background: var(--accent-soft); color: var(--accent-strong); padding: 3px 9px; border-radius: 8px; border: 0; }
button.chip { cursor: pointer; }
button.chip:hover { background: #ECD6C4; }
.chip.std { background: rgba(43,36,32,.06); color: var(--text); }
.tpl-card .form-actions { margin-top: 0; }
.archived { margin-top: 30px; }
.archived summary { cursor: pointer; color: var(--muted); font-size: 13.5px; }
.arch-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }

/* editor */
.tpl-dlg { width: min(1320px, 96vw); max-height: 94dvh; }
.tpl-edit { display: grid; grid-template-columns: minmax(380px, 520px) 1fr; height: min(900px, 92dvh); }
.tpl-edit-side { padding: 24px 26px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.tpl-edit-head { display: flex; justify-content: space-between; align-items: flex-start; }
.tpl-edit-head h2 { font-size: 21px; margin-top: 4px; }
.tpl-edit-preview { overflow-y: auto; padding: 24px 28px; background: #E4E0DA; border-radius: 0 24px 24px 0; }
.tpl-edit-preview .sheet { padding: 38px 44px 30px; }
.field-block { display: grid; gap: 10px; }
.field-block.grow { flex: 1; grid-template-rows: auto auto 1fr auto; min-height: 380px; }
.block-head { display: flex; justify-content: space-between; align-items: center; font-size: 13px; font-weight: 600; color: var(--text); }
.tpl-fields { display: grid; gap: 10px; }
.tpl-fields:empty { display: none; }
.frow { display: grid; grid-template-columns: 1fr 110px auto auto; gap: 8px; align-items: center; padding: 10px; border-radius: 14px; box-shadow: var(--neo-in); }
.frow .input { min-height: 38px; padding: 7px 11px; font-size: 13.5px; border-radius: 10px; box-shadow: var(--neo-sm); }
.frow .opts { grid-column: 1 / -1; }
.frow .req { display: flex; gap: 5px; align-items: center; font-size: 12px; color: var(--muted); white-space: nowrap; }
.frow .fkey { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--muted); }
.toolbar { display: flex; flex-wrap: wrap; gap: 6px; }
.toolbar .sep { width: 1px; background: var(--line); margin: 0 4px; }
.tb { border: 0; border-radius: 9px; padding: 5px 10px; font-size: 12.5px; background: var(--surface); box-shadow: var(--neo-sm); cursor: pointer; color: var(--text); }
.tb:hover { color: var(--accent); }
.tb.var { font-family: ui-monospace, Consolas, monospace; font-size: 12px; color: var(--accent-strong); }
textarea.input { resize: vertical; min-height: 300px; line-height: 1.55; padding: 14px 16px; }
textarea.mono { font: 13px/1.6 ui-monospace, "Cascadia Mono", Consolas, monospace; }
.help summary { cursor: pointer; font-size: 13px; color: var(--accent); font-weight: 600; }
.help ul { margin: 8px 0 0; padding-left: 18px; font-size: 13px; color: var(--text); display: grid; gap: 4px; }

.steps { margin: 0; padding-left: 20px; display: grid; gap: 8px; }
.pair-code { letter-spacing: .2em; color: var(--ink); font-size: 16px; }

/* ---------- toasts ---------- */
.toasts { position: fixed; right: 22px; bottom: 22px; display: grid; gap: 10px; z-index: 50; }
.toast { background: var(--ink); color: #fff; padding: 14px 18px; border-radius: 16px; box-shadow: 0 12px 30px rgba(43,36,32,.3); display: flex; align-items: center; gap: 14px; max-width: 440px; animation: toast-in .25s ease-out; font-size: 14px; }
.toast.ok { background: #2F6B45; }
.toast .btn { background: rgba(255,255,255,.16); box-shadow: none; color: #fff; min-height: 32px; font-size: 13px; padding: 0 12px; }
@keyframes toast-in { from { transform: translateY(12px); opacity: 0; } }

/* =========================================================
   Tablet
   ========================================================= */
body.tablet { min-height: 100dvh; overflow: hidden; user-select: none; -webkit-user-select: none; }
.t-screen { position: fixed; inset: 0; display: flex; flex-direction: column; }
.t-center { flex: 1; display: grid; place-items: center; text-align: center; padding: 32px; }
.t-center .big { font-family: var(--display); font-size: clamp(28px, 4.4vw, 44px); font-weight: 400; letter-spacing: -0.02em; }
.t-center .lead { font-size: clamp(17px, 2.1vw, 21px); color: var(--muted); margin-top: 10px; }
.t-logo { width: clamp(150px, 22vw, 220px); margin: 0 auto 34px; display: block; -webkit-user-drag: none; }
.t-breathe { animation: breathe 4s ease-in-out infinite; }
@keyframes breathe { 50% { transform: scale(1.03); opacity: .92; } }
.t-corner { position: absolute; bottom: 16px; left: 20px; right: 20px; display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); }
.conn-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); margin-right: 7px; }
.conn-dot.off { background: var(--warn); }

.t-sign-head { padding: 12px 24px; display: flex; justify-content: space-between; gap: 16px; align-items: center; flex-wrap: wrap; }
.t-sign-head .t-brand { display: flex; align-items: center; gap: 12px; }
.t-sign-head .t-brand img { width: 30px; }
.t-sign-head h2 { font-size: clamp(17px, 2.2vw, 21px); font-weight: 500; }
.t-sign-head .who { color: var(--muted); font-size: 15px; }
.t-doc { flex: 1; overflow-y: auto; padding: 8px 24px 20px; -webkit-overflow-scrolling: touch; user-select: text; -webkit-user-select: text; }
.t-doc .sheet { font-size: clamp(16.5px, 1.95vw, 19px); line-height: 1.7; padding: 34px 40px 28px; }
.t-doc .sheet .sh-title { font-size: 1.6em; }
.t-scroll-hint { text-align: center; color: var(--accent); font-weight: 600; font-size: 15px; padding: 14px 0 0; }
.t-sign { margin: 0 16px 16px; padding: 16px 22px 18px; display: grid; gap: 12px; border-radius: 26px; background: var(--surface); box-shadow: var(--neo); }
.t-check { display: flex; gap: 12px; align-items: center; font-size: clamp(16px, 1.9vw, 18.5px); font-weight: 600; cursor: pointer; }
.t-check input { width: 28px; height: 28px; accent-color: var(--accent); flex: none; }
.t-check.disabled { color: var(--faint); cursor: not-allowed; }
.sig-wrap { position: relative; height: clamp(130px, 22dvh, 220px); border-radius: 18px; background: #FDFCFA; box-shadow: var(--neo-in); }
.sig-wrap.active { box-shadow: var(--neo-in), 0 0 0 2px rgba(184,103,60,.5); }
.sig-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; border-radius: 18px; }
.sig-wrap .sig-label { position: absolute; left: 20px; top: 12px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; font-weight: 600; color: var(--faint); pointer-events: none; }
.sig-wrap .sig-line { position: absolute; left: 20px; right: 20px; bottom: 34px; border-bottom: 1.5px solid #E2D9CF; pointer-events: none; }
.sig-wrap .sig-x { position: absolute; left: 22px; bottom: 38px; font-size: 20px; color: #CDBFB2; pointer-events: none; }
.sig-wrap.signed .sig-label, .sig-wrap.signed .sig-x { display: none; }
.t-buttons { display: flex; gap: 14px; }
.t-buttons .btn { min-height: 58px; font-size: 17px; border-radius: 18px; }
.t-buttons .primary { flex: 1; }
.t-err { color: var(--danger); font-weight: 600; text-align: center; }
.t-done .check { width: 116px; height: 116px; border-radius: 50%; background: var(--surface); box-shadow: var(--neo); color: var(--ok); display: grid; place-items: center; margin: 0 auto 28px; animation: pop .4s ease-out; }
.t-done .check svg { width: 58px; height: 58px; }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }
.pair-card { width: min(450px, 92vw); padding: 34px; display: grid; gap: 18px; text-align: left; }
.pair-card .login-logo { width: 120px; }
.code-input { text-align: center; font-size: 30px; letter-spacing: .4em; font-weight: 600; min-height: 62px; }

/* Modo kiosco de la tablet */
html, body.tablet { overscroll-behavior: none; touch-action: manipulation; }
body.tablet { padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.net-banner { position: fixed; top: 0; left: 0; right: 0; z-index: 30; background: var(--warn); color: #fff; text-align: center; padding: 10px 16px; font-weight: 600; }
.t-install { font-size: 13px; color: var(--muted); text-align: right; }
.t-tip { font-size: 13px; background: var(--accent-soft); color: var(--accent-strong); padding: 10px 14px; border-radius: 12px; }
dialog.settings { width: min(420px, 92vw); }
.settings-body { padding: 26px; display: grid; gap: 12px; }
#logo { touch-action: none; -webkit-touch-callout: none; }

@media (max-height: 720px) {
  .sig-wrap { height: 120px; }
  .t-sign { padding: 10px 18px 12px; gap: 8px; }
  .t-buttons .btn { min-height: 50px; }
}

/* ---------- responsive ---------- */
@media (max-width: 1280px) {
  .dash-top { grid-template-columns: 1fr 1fr; }
  .stats-card { grid-column: 1 / -1; }
}
@media (max-width: 1100px) {
  .new-layout { grid-template-columns: 1fr; }
  .tpl-edit { grid-template-columns: 1fr; height: auto; max-height: 92dvh; overflow-y: auto; }
  .tpl-edit-side { overflow: visible; }
  .tpl-edit-preview { border-radius: 0 0 24px 24px; overflow: visible; }
  .dash-bottom { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; padding: 12px 16px; gap: 16px; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 12px; gap: 4px; }
  .side-brand { padding: 0 10px 0 6px; }
  .side-label, .side-spacer, .side-widgets { display: none; }
  .side-nav { display: flex; gap: 4px; }
  .nav-item { padding: 9px 11px; font-size: 13.5px; width: auto; }
  .side-logout { margin-left: auto; box-shadow: none; background: transparent; }
  .main { padding-top: 8px; }
  .filters { grid-template-columns: 1fr 1fr; }
  .dlg { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .dlg-side { max-height: 36dvh; }
  .sheet { padding: 26px 22px; }
}
@media (max-width: 600px) {
  .grid-2, .filters, .dash-top, .stats-card { grid-template-columns: 1fr; }
  .stats-card { grid-template-columns: repeat(3, 1fr); padding: 18px 10px; }
  .stat-num { width: 70px; height: 70px; font-size: 34px; }
  .nav-item svg { display: none; }
  .side-logout #userName { display: none; }
  .sh-ficha { grid-template-columns: 1fr; }
  .sh-head { flex-direction: column; align-items: flex-start; }
  .sh-addr { text-align: left; }
  .frow { grid-template-columns: 1fr 1fr; }
  /* tablet en un móvil */
  .t-sign-head { padding: 8px 14px; }
  .t-doc { padding: 6px 10px; }
  .t-doc .sheet { padding: 20px 18px; font-size: 16px; line-height: 1.6; }
  .t-sign { margin: 0 8px 8px; padding: 10px 14px 12px; gap: 8px; border-radius: 20px; }
  .t-check { font-size: 14px; gap: 10px; }
  .t-check input { width: 24px; height: 24px; }
  .sig-wrap { height: 118px; }
  .t-buttons .btn { min-height: 48px; font-size: 15px; padding: 0 10px; }
  .t-buttons .primary { flex: 1.4; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.tpl-card .chip { font-family: var(--font); font-size: 12px; }

/* ---------- barras de desplazamiento: finas, en el tono de la piedra, sin flechas ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-button { display: none; width: 0; height: 0; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-corner { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(43, 36, 32, 0.16);
  border-radius: 999px;
  border: 3px solid transparent;
  background-clip: padding-box;
  min-height: 40px;
}
::-webkit-scrollbar-thumb:hover { background-color: rgba(148, 80, 44, 0.55); }
::-webkit-scrollbar-thumb:active { background-color: rgba(148, 80, 44, 0.75); }
/* dentro de los cuadros de texto, un poco más estrecha y separada del borde redondeado */
textarea::-webkit-scrollbar { width: 12px; }
textarea::-webkit-scrollbar-thumb { border-width: 4px; }
textarea::-webkit-scrollbar-track { margin: 10px 0; }
.tpl-edit-preview::-webkit-scrollbar-track, .tpl-edit-side::-webkit-scrollbar-track, dialog::-webkit-scrollbar-track { margin: 18px 0; }
/* Firefox */
@supports not selector(::-webkit-scrollbar) {
  * { scrollbar-width: thin; scrollbar-color: rgba(43, 36, 32, 0.2) transparent; }
}

/* ---------- idiomas ---------- */
.flag { width: 20px; height: 14px; border-radius: 3px; object-fit: cover; box-shadow: 0 0 0 1px rgba(43,36,32,.12); flex: none; vertical-align: -2px; }
.step-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.lang-toggle, .lang-tabs { display: inline-flex; padding: 4px; gap: 4px; border-radius: 14px; box-shadow: var(--neo-in); }
.lang-toggle button, .lang-tabs button {
  display: inline-flex; align-items: center; gap: 7px; border: 0; background: transparent; cursor: pointer;
  padding: 7px 12px; border-radius: 10px; font-size: 13px; font-weight: 600; color: var(--muted);
  transition: background .18s, box-shadow .18s, color .18s;
}
.lang-toggle img, .lang-tabs img { width: 20px; height: 14px; border-radius: 3px; object-fit: cover; box-shadow: 0 0 0 1px rgba(43,36,32,.12); }
.lang-toggle button[aria-checked="true"], .lang-tabs button[aria-selected="true"] { background: var(--surface); box-shadow: var(--neo-sm); color: var(--ink); }
.lang-toggle button:disabled { opacity: .4; cursor: not-allowed; }
.lang-toggle button:disabled img { filter: grayscale(1); }
.lang-tabs { align-self: flex-start; }
.tab-note { font-size: 11px; font-weight: 500; color: var(--warn); }
.doc-type { display: flex; gap: 14px; font-size: 13px; font-weight: 600; color: var(--text); }
.doc-type label { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; }
.doc-type input { accent-color: var(--accent); margin: 0; }
.lang-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600; color: var(--muted); }
.lang-chip.off { opacity: .45; }
.lang-chip.off img { filter: grayscale(1); }
/* tablet: botón de idioma */
.t-lang { display: inline-flex; align-items: center; gap: 9px; border: 0; cursor: pointer; padding: 9px 16px; border-radius: 14px; background: var(--surface); box-shadow: var(--neo-sm); font-size: 15px; font-weight: 600; color: var(--ink); }
.t-lang img { width: 26px; height: 18px; border-radius: 3px; object-fit: cover; box-shadow: 0 0 0 1px rgba(43,36,32,.12); }
.t-lang:active { box-shadow: var(--neo-in); }
.t-head-right { display: flex; align-items: center; gap: 14px; }
@media (max-width: 600px) { .t-sign-head .who { display: none; } .t-lang { padding: 7px 11px; font-size: 13px; } }

/* ---------- Profesionales: firma del doctor, una sola vez ---------- */
.nav-count.warn { color: #fff; background: var(--danger); border-radius: 999px; min-width: 18px; height: 18px; display: inline-grid; place-items: center; font-weight: 700; font-size: 11px; }
.nav-count.warn:empty { display: none; }
.pro-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 24px; margin-bottom: 24px; }
.pro-card { padding: 22px; display: flex; flex-direction: column; gap: 14px; }
.pro-fields { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; }
.pro-sig-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pro-sig-head .field-label { font-size: 13px; font-weight: 600; color: var(--text); }
.pro-state { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; }
.pro-state.ok { background: rgba(62, 140, 90, .12); color: #2F7A4C; }
.pro-state.warn { background: var(--danger-soft); color: var(--danger); }
.pro-pad { position: relative; height: 170px; border-radius: 14px; background: #fff; box-shadow: var(--neo-in); overflow: hidden; touch-action: none; }
.pro-pad canvas { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; touch-action: none; }
.pro-saved { position: absolute; inset: 16px 22px 30px; color: var(--ink); pointer-events: none; }
.pro-saved svg, .pro-saved img { width: 100%; height: 100%; }
.pro-pad.uploaded .pro-saved { inset: 10px 22px 30px; }
.pro-pad.uploaded canvas { cursor: default; }
.pro-note { font-size: 12px; color: var(--muted); margin: -6px 2px 0; }
.pro-pad.drawing .pro-saved, .pro-pad.drawing .pro-hint { display: none; }
.pro-hint { position: absolute; left: 16px; top: 12px; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; font-weight: 700; color: var(--copper); pointer-events: none; }
.pro-pad.has-saved .pro-hint { color: var(--muted); font-weight: 600; }
.pro-line { position: absolute; left: 22px; right: 22px; bottom: 26px; border-bottom: 1px solid #E6DFD7; pointer-events: none; }
.pro-actions { display: flex; gap: 10px; align-items: center; }
.pro-actions .spacer { flex: 1; }
.pro-add-row { display: grid; grid-template-columns: 1.4fr 1fr auto; gap: 12px; margin-top: 12px; }
@media (max-width: 640px) {
  .pro-grid { grid-template-columns: 1fr; }
  .pro-fields, .pro-add-row { grid-template-columns: 1fr; }
}

/* ---------- Firma del profesional desde el móvil ---------- */
dialog.qr-dlg { width: min(440px, 94vw); }
.qr-body { padding: 24px; display: grid; gap: 16px; }
.qr-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.qr-head h2 { font-size: 20px; font-weight: 500; margin: 2px 0 0; }
.qr-code { background: #fff; border-radius: 16px; padding: 14px; box-shadow: var(--neo-in); width: min(260px, 100%); margin: 0 auto; }
.qr-code svg { display: block; width: 100%; height: auto; }
.qr-steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 14px; }
.qr-wait { margin: 0; font-size: 14px; font-weight: 600; color: var(--copper); text-align: center; }

body.phone-sign { min-height: 100dvh; background: var(--bg, #ECE9E4); }
.ps-wrap { max-width: 460px; margin: 0 auto; padding: max(24px, env(safe-area-inset-top)) 16px 32px; display: grid; gap: 18px; }
.ps-wrap .login-logo { margin-top: 8px; }
.ps-card { padding: 22px; display: grid; gap: 14px; }
.ps-title { font-size: 22px; font-weight: 500; margin: 4px 0 0; }
.ps-steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; font-size: 15px; }
.ps-big { min-height: 54px; font-size: 17px; width: 100%; }
.ps-preview { background: #fff; border-radius: 14px; box-shadow: var(--neo-in); padding: 18px; min-height: 140px; display: grid; place-items: center; }
.ps-preview img { max-width: 100%; max-height: 220px; }

/* ---------- Copia en el Google Drive de la clínica ---------- */
.drive-card { display: flex; align-items: center; justify-content: space-between; gap: 18px; flex-wrap: wrap; margin-bottom: 22px; }
.drive-text { flex: 1 1 320px; display: grid; gap: 4px; }
.drive-text p { margin: 0; font-size: 14px; }
.drive-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Usuarios, recuperar contraseña y copia por email ---------- */
.ok-box { background: var(--ok-soft); color: #245A36; border-radius: 12px; padding: 10px 14px; font-size: 14px; line-height: 1.45; }
.invite-row { display: grid; grid-template-columns: 1.4fr 1fr 170px auto; gap: 12px; }
.input.sm { min-height: 36px; padding: 6px 10px; font-size: 13.5px; border-radius: 10px; }
.row-actions { white-space: nowrap; text-align: right; }
.copy-row { display: flex; gap: 8px; margin-top: 8px; }
.copy-row .input { flex: 1; min-width: 0; }
.detail-email dt { font-size: 10.5px; text-transform: uppercase; letter-spacing: .12em; color: var(--muted); font-weight: 600; }
.detail-email dd { margin: 2px 0 0; font-size: 14px; word-break: break-word; }
.t-email { display: grid; gap: 6px; }
.t-email label { font-size: 14px; color: var(--muted); }
.t-email .input { font-size: 16px; }
@media (max-width: 760px) { .invite-row { grid-template-columns: 1fr; } }
