*, *::before, *::after { box-sizing: border-box; }

:root {
  --navy: #173647;
  --navy-deep: #0f2533;
  --green: #248348;
  --green-soft: #e3f1e7;
  --orange: #ee781d;
  --orange-soft: #fde8d6;
  --red: #b83a2e;
  --red-soft: #f9e1de;
  --amber: #b77a06;
  --amber-soft: #fbefcf;
  --lime: #b6ca42;
  --paper: #f3f6f5;
  --white: #fff;
  --ink: #13232e;
  --muted: #5a6b76;
  --line: rgba(23, 54, 71, .13);
  --display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --sans: "Source Sans 3", "Segoe UI", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

html, body { overflow-x: clip; }
body { margin: 0; background: var(--paper); color: var(--ink); font-family: var(--sans); font-size: 16px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; border-radius: 6px; }
h1, h2, h3 { font-family: var(--display); letter-spacing: -.02em; line-height: 1.1; margin: 0; }
p { margin: 0; }

.skip-link { position: fixed; top: 10px; left: -9999px; z-index: 100; padding: 8px 12px; border-radius: 8px; background: var(--orange); color: var(--navy-deep); font-weight: 700; text-decoration: none; }
.skip-link:focus { left: 10px; }

/* ---------- App bar ---------- */
.appbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 14px 24px; padding: 14px 24px; background: var(--navy-deep); color: #fff; }
.appbar-brand { display: flex; align-items: center; gap: 14px; }
.appbar-brand strong { display: block; font-family: var(--display); font-size: 19px; }
.appbar-brand span { font-size: 13.5px; color: rgba(255,255,255,.6); }
.logo-chip { display: inline-flex; padding: 5px 9px; border-radius: 9px; background: #fff; }
.logo-chip img { display: block; width: 96px; height: 32px; }
.appbar-controls { display: flex; flex-wrap: wrap; gap: 10px; }
.segmented { display: inline-flex; padding: 4px; border-radius: 999px; background: rgba(255,255,255,.09); }
.segmented button { min-height: 38px; padding: 0 16px; border: 0; border-radius: 999px; background: none; color: rgba(255,255,255,.75); font-size: 14.5px; font-weight: 600; }
.segmented button[aria-checked="true"] { background: #fff; color: var(--navy-deep); }
.plan-switch button[aria-checked="true"] { background: var(--orange); color: var(--navy-deep); }

.synthetic { margin: 0; padding: 8px 24px; background: var(--orange-soft); color: #6b3306; font-size: 13.5px; font-weight: 600; text-align: center; }

.eyebrow { display: inline-block; margin-bottom: 12px; font-family: var(--mono); font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--green); }

/* ---------- Portal ---------- */
.portal-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 56px; align-items: center; max-width: 1080px; margin: 0 auto; padding: 48px 24px 64px; }
.portal-copy h1 { font-size: clamp(34px, 4vw, 48px); font-weight: 800; }
.portal-copy > p { margin-top: 14px; font-size: 18px; color: var(--muted); max-width: 52ch; }
.portal-notes { margin: 24px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; }
.portal-notes li { padding: 12px 16px; border-radius: 12px; background: #fff; border: 1px solid var(--line); font-size: 15.5px; }
.portal-notes li b { color: var(--green); }
.link-button { margin-top: 18px; padding: 0; border: 0; background: none; color: var(--navy); font-weight: 700; text-decoration: underline; text-underline-offset: 3px; }

.phone { position: relative; width: 100%; max-width: 380px; margin-inline: auto; padding: 14px; border-radius: 46px; background: var(--navy-deep); box-shadow: 0 30px 80px rgba(15,37,51,.3); }
.phone-notch { position: absolute; top: 14px; left: 50%; z-index: 2; width: 110px; height: 24px; border-radius: 0 0 16px 16px; background: var(--navy-deep); transform: translateX(-50%); }
.phone-screen { display: flex; flex-direction: column; min-height: 680px; padding: 48px 22px 24px; border-radius: 34px; background: #fff; }
.ps-step { font-family: var(--mono); font-size: 12px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.ps-title { margin-top: 10px; font-family: var(--display); font-size: 30px; font-weight: 800; line-height: 1.1; }
.ps-text { margin-top: 12px; font-size: 19px; color: var(--ink); }
.ps-muted { margin-top: 10px; font-size: 16px; color: var(--muted); }
.ps-spacer { flex: 1; }
.ps-actions { display: grid; gap: 10px; margin-top: 20px; }
.big-btn { min-height: 60px; padding: 0 20px; border: 0; border-radius: 16px; background: var(--green); color: #fff; font-size: 20px; font-weight: 700; }
.big-btn:disabled { opacity: .45; cursor: not-allowed; }
.big-btn.secondary { background: var(--paper); color: var(--navy); }
.field { display: grid; gap: 6px; margin-top: 18px; }
.field label { font-size: 17px; font-weight: 700; }
.field input { min-height: 58px; padding: 0 16px; border: 2px solid var(--line); border-radius: 14px; font-size: 21px; font-family: var(--mono); letter-spacing: .03em; }
.field input:focus { border-color: var(--green); outline: none; }
.hint { font-size: 14px; color: var(--muted); }

.camera { position: relative; display: grid; place-items: center; height: 330px; margin-top: 16px; border-radius: 22px; background: radial-gradient(circle at 50% 40%, #33505f, #0f2533 70%); overflow: hidden; }
.oval { position: relative; width: 190px; height: 250px; border-radius: 50%; border: 4px dashed rgba(255,255,255,.55); transition: border-color .3s; }
.oval.ok { border-style: solid; border-color: var(--lime); }
.face { position: absolute; inset: 34px 38px 24px; border-radius: 48% 48% 44% 44%; background: #d9b89a; transition: transform .6s; }
.face::before, .face::after { content: ""; position: absolute; top: 38%; width: 16px; height: 9px; border-radius: 50%; background: #3b2a20; transition: height .12s; }
.face::before { left: 24%; } .face::after { right: 24%; }
.face.blink::before, .face.blink::after { height: 2px; }
.face.turn { transform: translateX(-14px) rotateY(30deg); }
.face .mouth { position: absolute; left: 36%; right: 36%; bottom: 22%; height: 8px; border-bottom: 3px solid #8a4f3a; border-radius: 0 0 50% 50%; }
.cam-instruction { position: absolute; left: 12px; right: 12px; bottom: 12px; padding: 10px 12px; border-radius: 12px; background: rgba(0,0,0,.55); color: #fff; font-size: 18px; font-weight: 700; text-align: center; }
.rec { position: absolute; top: 12px; left: 14px; display: flex; align-items: center; gap: 6px; font-family: var(--mono); font-size: 12px; color: #fff; }
.rec::before { content: ""; width: 9px; height: 9px; border-radius: 50%; background: #ff4d3d; }
.progress { height: 8px; margin-top: 14px; border-radius: 4px; background: var(--paper); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--green); transition: width .4s; }

.result { margin-top: 18px; padding: 18px; border-radius: 16px; background: var(--green-soft); }
.result.review { background: var(--amber-soft); }
.result strong { display: block; font-family: var(--display); font-size: 22px; }
.result p { margin-top: 6px; font-size: 16px; }
.const-card { margin-top: 16px; padding: 18px; border: 2px solid var(--line); border-radius: 16px; }
.const-card .row { display: flex; justify-content: space-between; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.const-card .row:last-child { border-bottom: 0; }
.const-card .row span { color: var(--muted); }
.qr { display: grid; grid-template-columns: repeat(9, 1fr); gap: 2px; width: 90px; margin: 12px auto 0; }
.qr i { aspect-ratio: 1; background: var(--navy-deep); }
.qr i.w { background: transparent; }
.choice { display: grid; gap: 4px; padding: 16px; border: 2px solid var(--line); border-radius: 16px; background: #fff; text-align: left; }
.choice strong { font-size: 18px; }
.choice span { font-size: 15px; color: var(--muted); }
.choice:hover { border-color: var(--green); }
.choice[disabled] { opacity: .5; cursor: not-allowed; }
.choice .tag { justify-self: start; }

/* ---------- Panel ---------- */
.panel-layout { display: grid; grid-template-columns: 230px minmax(0, 1fr); min-height: calc(100vh - 110px); }
.side { display: flex; flex-direction: column; gap: 2px; padding: 20px 12px; background: #fff; border-right: 1px solid var(--line); }
.side button { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 42px; padding: 0 14px; border: 0; border-radius: 10px; background: none; font-weight: 600; text-align: left; color: var(--ink); }
.side button:hover { background: var(--paper); }
.side button[aria-current="page"] { background: var(--navy); color: #fff; }
.side button.locked { color: var(--muted); }
.side button.locked::after { content: attr(data-plan); font-family: var(--mono); font-size: 10.5px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--orange-soft); color: #8d4308; }
.count:empty { display: none; }
.count { padding: 1px 8px; border-radius: 999px; background: var(--orange); color: var(--navy-deep); font-family: var(--mono); font-size: 12px; }

.module { padding: 28px clamp(16px, 3vw, 36px) 56px; min-width: 0; }
.mod-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 22px; }
.mod-head h2 { font-size: 30px; }
.mod-head p { margin-top: 6px; color: var(--muted); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 12px; }
.kpi { padding: 18px; border-radius: 16px; background: #fff; border: 1px solid var(--line); text-align: left; }
button.kpi:hover { border-color: var(--navy); }
.kpi span { display: block; font-size: 14px; color: var(--muted); font-weight: 600; }
.kpi strong { display: block; margin-top: 6px; font-family: var(--display); font-size: 38px; font-weight: 800; line-height: 1; }
.kpi small { display: block; margin-top: 6px; font-size: 13px; color: var(--muted); }
.kpi.warn strong { color: var(--amber); }
.kpi.bad strong { color: var(--red); }
.kpi.good strong { color: var(--green); }

.grid-2 { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; margin-top: 16px; }
.card { padding: 20px; border-radius: 16px; background: #fff; border: 1px solid var(--line); min-width: 0; }
.card h3 { font-size: 19px; margin-bottom: 12px; }

.bars { display: grid; gap: 10px; }
.bar-row { display: grid; grid-template-columns: 110px minmax(0,1fr) 36px; gap: 10px; align-items: center; font-size: 14.5px; }
.bar-track { height: 12px; border-radius: 6px; background: var(--paper); overflow: hidden; }
.bar-track i { display: block; height: 100%; border-radius: 6px; }
.bar-row b { text-align: right; font-family: var(--mono); font-size: 13px; }

.list { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.list li { display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.list li:last-child { border-bottom: 0; }
.list li span { color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
.toolbar input { flex: 1 1 220px; min-height: 42px; padding: 0 14px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; }
.chip { min-height: 38px; padding: 0 14px; border: 1.5px solid var(--line); border-radius: 999px; background: #fff; font-size: 14px; font-weight: 600; }
.chip[aria-pressed="true"] { background: var(--navy); border-color: var(--navy); color: #fff; }

.table-wrap { overflow-x: auto; border-radius: 16px; border: 1px solid var(--line); background: #fff; }
table { width: 100%; border-collapse: collapse; font-size: 15px; }
th { padding: 12px 14px; text-align: left; font-family: var(--mono); font-size: 11.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); background: var(--paper); white-space: nowrap; }
td { padding: 12px 14px; border-top: 1px solid var(--line); vertical-align: middle; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8faf9; }
td .name { font-weight: 700; }
td .sub { display: block; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.num { font-family: var(--mono); font-size: 13.5px; white-space: nowrap; }

.tag { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 700; white-space: nowrap; }
.tag.vigente { background: var(--green-soft); color: var(--green); }
.tag.por_vencer { background: var(--amber-soft); color: var(--amber); }
.tag.vencida { background: var(--red-soft); color: var(--red); }
.tag.revision { background: var(--orange-soft); color: #9a4a08; }
.tag.fallecido { background: #e3e7ea; color: #3e4c55; }
.tag.pendiente { background: #e6ecf7; color: #2e4b85; }
.tag.plan { background: var(--orange-soft); color: #8d4308; font-family: var(--mono); font-size: 11px; }

.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 40px; padding: 0 16px; border: 1.5px solid transparent; border-radius: 10px; background: var(--navy); color: #fff; font-size: 14.5px; font-weight: 700; }
.btn.green { background: var(--green); }
.btn.ghost { background: #fff; border-color: var(--line); color: var(--ink); }
.btn.danger { background: #fff; border-color: var(--red); color: var(--red); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.review-card { display: grid; grid-template-columns: 130px minmax(0,1fr) auto; gap: 18px; align-items: center; padding: 18px; border-radius: 16px; background: #fff; border: 1px solid var(--line); }
.review-card + .review-card { margin-top: 12px; }
.snap-pair { display: flex; gap: 6px; }
.snap { width: 62px; height: 78px; border-radius: 10px; background: linear-gradient(160deg, #d9b89a, #b89274); position: relative; }
.snap::after { content: attr(data-l); position: absolute; bottom: 4px; left: 0; right: 0; text-align: center; font-family: var(--mono); font-size: 9px; color: #fff; }
.score { font-family: var(--display); font-size: 26px; font-weight: 800; }

.locked-panel { max-width: 620px; margin: 40px auto; padding: 36px; border-radius: 20px; background: #fff; border: 1.5px dashed var(--line); text-align: center; }
.locked-panel h2 { font-size: 26px; }
.locked-panel p { margin-top: 10px; color: var(--muted); }
.locked-panel ul { margin: 18px auto 22px; padding: 0; list-style: none; display: grid; gap: 6px; text-align: left; max-width: 420px; }
.locked-panel li::before { content: "→ "; color: var(--green); font-weight: 700; }

.alert { display: grid; grid-template-columns: auto minmax(0,1fr) auto; gap: 14px; align-items: center; padding: 14px 16px; border-radius: 14px; background: #fff; border: 1px solid var(--line); }
.alert + .alert { margin-top: 10px; }
.alert .dot { width: 12px; height: 12px; border-radius: 50%; }
.alert strong { display: block; }
.alert span { font-size: 14px; color: var(--muted); }

.matrix td:last-child { white-space: nowrap; }

.log { margin: 0; padding: 0; list-style: none; }
.log li { display: grid; grid-template-columns: 150px minmax(0,1fr); gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.log time { font-family: var(--mono); font-size: 12.5px; color: var(--muted); }
.log .who { font-weight: 700; }

/* ---------- Drawer ---------- */
.drawer { position: fixed; inset: 0; z-index: 50; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(15,37,51,.45); }
.drawer-panel { position: absolute; top: 0; right: 0; bottom: 0; width: min(520px, 100%); padding: 28px; background: #fff; overflow-y: auto; box-shadow: -20px 0 60px rgba(0,0,0,.2); }
.drawer-close { position: absolute; top: 14px; right: 14px; width: 40px; height: 40px; border: 0; border-radius: 50%; background: var(--paper); font-size: 24px; line-height: 1; }
.drawer h2 { font-size: 28px; padding-right: 40px; }
.drawer h3 { margin: 24px 0 8px; font-size: 17px; }
.drawer .field input, .drawer .field select { min-height: 46px; padding: 0 12px; border: 1.5px solid var(--line); border-radius: 10px; font-size: 16px; font-family: var(--sans); letter-spacing: 0; }
.drawer .field label { font-size: 15px; }

.toast { position: fixed; left: 50%; bottom: 24px; z-index: 60; max-width: calc(100% - 32px); padding: 14px 20px; border-radius: 14px; background: var(--navy-deep); color: #fff; font-weight: 600; transform: translate(-50%, 200%); visibility: hidden; transition: transform .3s, visibility .3s; }
.toast.show { transform: translate(-50%, 0); visibility: visible; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .portal-layout { grid-template-columns: 1fr; gap: 32px; padding-top: 32px; }
  .panel-layout { grid-template-columns: 1fr; }
  .side { flex-direction: row; overflow-x: auto; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); }
  .side button { flex: none; }
  .review-card { grid-template-columns: 1fr; }
}
@media (max-width: 620px) {
  .appbar { padding: 12px 16px; }
  .appbar-controls, .segmented { width: 100%; }
  .segmented button { flex: 1; padding: 0 8px; font-size: 13.5px; }
  .synthetic { padding: 8px 16px; }
  .portal-layout { padding: 24px 16px 48px; }
  .phone { padding: 8px; border-radius: 36px; }
  .phone-screen { min-height: 620px; border-radius: 30px; padding: 44px 16px 20px; }
  .kpi strong { font-size: 30px; }
  .log li { grid-template-columns: 1fr; gap: 2px; }
  .bar-row { grid-template-columns: 90px minmax(0,1fr) 30px; }
  .alert { grid-template-columns: auto minmax(0,1fr); }
  .alert .btn { grid-column: 1 / -1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
