/* ============ Digitalizador Dental — estilos ============ */
:root {
  --bg: #f4f7f7;
  --panel: #ffffff;
  --panel-2: #f8fafa;
  --borde: #dfe7e7;
  --texto: #0f1d1d;
  --texto-2: #4b5d5d;
  --texto-3: #7a8b8b;
  --acento: #0f766e;
  --acento-2: #115e59;
  --acento-suave: #e3f4f1;
  --ok: #15803d;      --ok-bg: #e7f6ec;
  --aviso: #b45309;   --aviso-bg: #fdf3e2;
  --error: #b91c1c;   --error-bg: #fdecec;
  --info: #1d4ed8;    --info-bg: #e8eefd;
  --sombra: 0 1px 2px rgba(15, 40, 40, .06), 0 4px 16px rgba(15, 40, 40, .05);
  --radio: 12px;
  --fuente: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1414; --panel: #121d1d; --panel-2: #172424; --borde: #233434;
    --texto: #e6f0ef; --texto-2: #a9bcbb; --texto-3: #7a908f;
    --acento: #2dd4bf; --acento-2: #5eead4; --acento-suave: #123331;
    --ok: #4ade80; --ok-bg: #12301f; --aviso: #fbbf24; --aviso-bg: #33270e;
    --error: #f87171; --error-bg: #3a1717; --info: #93b4ff; --info-bg: #17223d;
    --sombra: 0 1px 2px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--fuente); background: var(--bg); color: var(--texto); font-size: 15px; line-height: 1.5; }
a { color: var(--acento); }
h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; letter-spacing: -.01em; }
h1 { font-size: 1.5rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .8em; }
.muted { color: var(--texto-2); } .tenue { color: var(--texto-3); font-size: .85rem; }
.mono { font-family: var(--mono); }
.oculto { display: none !important; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }
.app > * { min-width: 0; }
.r-visor { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@media (max-width: 900px) { .r-visor { grid-template-columns: minmax(0, 1fr); } }
.lateral { background: var(--panel); border-right: 1px solid var(--borde); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.marca { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.marca img { width: 34px; height: 34px; }
.marca b { display: block; font-size: .98rem; }
.marca span { font-size: .75rem; color: var(--texto-3); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 9px; color: var(--texto-2); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--panel-2); color: var(--texto); }
.nav a.activo { background: var(--acento-suave); color: var(--acento-2); font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; }
.lateral .pie { margin-top: auto; border-top: 1px solid var(--borde); padding: 12px 8px 0; font-size: .85rem; }
.contenido { padding: 28px clamp(16px, 3vw, 40px) 60px; max-width: 1280px; width: 100%; }
.cabecera { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.cabecera p { margin: 0; }
.barra-movil { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .lateral { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; box-shadow: var(--sombra); }
  .lateral.abierto { transform: none; }
  .barra-movil { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--borde); position: sticky; top: 0; z-index: 40; }
  .barra-movil img { width: 28px; }
  .contenido { padding-top: 18px; }
}

/* ---------- Componentes ---------- */
.tarjeta { background: var(--panel); border: 1px solid var(--borde); border-radius: var(--radio); padding: 18px; box-shadow: var(--sombra); min-width: 0; }
.tarjeta + .tarjeta { margin-top: 16px; }
.rejilla > .tarjeta + .tarjeta, .pila > .tarjeta + .tarjeta { margin-top: 0; }
.pila > .tarjeta + .tarjeta { margin-top: 12px; }
.tarjeta > h2:first-child, .tarjeta > h3:first-child { margin-bottom: 12px; }
.rejilla { display: grid; gap: 16px; }
.r2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.r3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.r4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 1000px) { .r4 { grid-template-columns: repeat(2, minmax(0, 1fr)); } .r3 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 640px) { .r2, .r3, .r4 { grid-template-columns: 1fr; } }
.fila { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.fila.entre { justify-content: space-between; }
.pila > * + * { margin-top: 12px; }

.kpi { padding: 16px 18px; }
.kpi .etq { color: var(--texto-2); font-size: .82rem; font-weight: 500; }
.kpi .val { font-size: 1.8rem; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi .sub { font-size: .8rem; color: var(--texto-3); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid var(--borde); background: var(--panel); color: var(--texto); font: inherit; font-weight: 600; font-size: .9rem; padding: 9px 15px; border-radius: 9px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.prim { background: var(--acento); border-color: var(--acento); color: #fff; }
@media (prefers-color-scheme: dark) { .btn.prim { color: #04201d; } }
.btn.prim:hover { filter: brightness(1.08); }
.btn.peligro { color: var(--error); border-color: color-mix(in srgb, var(--error) 35%, var(--borde)); }
.btn.peligro:hover { background: var(--error-bg); }
.btn.peq { padding: 5px 10px; font-size: .82rem; }
.btn.grande { padding: 13px 20px; font-size: 1rem; }
.btn svg { width: 16px; height: 16px; }

label { display: block; font-size: .83rem; font-weight: 600; color: var(--texto-2); margin-bottom: 5px; }
input, select, textarea { width: 100%; font: inherit; color: var(--texto); background: var(--panel); border: 1px solid var(--borde); border-radius: 9px; padding: 9px 11px; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--acento) 45%, transparent); outline-offset: 0; border-color: var(--acento); }
input[type=range] { padding: 0; accent-color: var(--acento); }
input[type=checkbox] { width: auto; accent-color: var(--acento); }
textarea { min-height: 80px; resize: vertical; }
.campo { margin-bottom: 12px; }
.campos { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
@media (max-width: 640px) { .campos { grid-template-columns: 1fr; } }
.ayuda { font-size: .78rem; color: var(--texto-3); margin-top: 4px; }

.tabla-cont { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th { text-align: left; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--texto-3); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--borde); white-space: nowrap; }
td { padding: 10px; border-bottom: 1px solid var(--borde); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr.clic { cursor: pointer; } tr.clic:hover td { background: var(--panel-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.chip { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px; font-size: .76rem; font-weight: 600; background: var(--panel-2); color: var(--texto-2); border: 1px solid var(--borde); white-space: nowrap; }
.chip.ok { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.chip.aviso { background: var(--aviso-bg); color: var(--aviso); border-color: transparent; }
.chip.error { background: var(--error-bg); color: var(--error); border-color: transparent; }
.chip.info { background: var(--info-bg); color: var(--info); border-color: transparent; }
.punto { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }

.vacio { text-align: center; padding: 30px 10px; color: var(--texto-3); }
.alerta { padding: 10px 14px; border-radius: 9px; font-size: .88rem; margin-bottom: 12px; }
.alerta.info { background: var(--info-bg); color: var(--info); }
.alerta.aviso { background: var(--aviso-bg); color: var(--aviso); }
.alerta.error { background: var(--error-bg); color: var(--error); }
.alerta.ok { background: var(--ok-bg); color: var(--ok); }

/* ---------- Pasos (asistente de escaneo) ---------- */
.pasos { display: flex; gap: 6px; margin-bottom: 18px; overflow-x: auto; padding-bottom: 2px; }
.paso { flex: 1; min-width: 110px; padding: 10px 12px; border-radius: 10px; background: var(--panel); border: 1px solid var(--borde); font-size: .82rem; color: var(--texto-3); }
.paso b { display: block; font-size: .9rem; color: var(--texto-2); }
.paso.activo { border-color: var(--acento); background: var(--acento-suave); }
.paso.activo b { color: var(--acento-2); }
.paso.hecho b { color: var(--ok); }

/* ---------- Video / visor ---------- */
.marco-video { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 16/9; }
.marco-video video { width: 100%; height: 100%; object-fit: contain; display: block; }
.marco-video .rec { position: absolute; top: 10px; left: 10px; background: #dc2626; color: #fff; padding: 3px 10px; border-radius: 99px; font-size: .8rem; font-weight: 700; }
.visor3d { width: 100%; height: min(70vh, 560px); border-radius: 10px; background: radial-gradient(circle at 50% 40%, #24393a, #0b1414); position: relative; overflow: hidden; }
.visor3d canvas { display: block; }
.visor3d .info { position: absolute; left: 12px; bottom: 10px; color: #cfe; font-size: .78rem; opacity: .85; }

.recorte { position: relative; height: 34px; margin: 12px 0 4px; }
.recorte .pista { position: absolute; inset: 14px 0; height: 6px; background: var(--borde); border-radius: 3px; }
.recorte .sel { position: absolute; top: 14px; height: 6px; background: var(--acento); border-radius: 3px; }
.recorte input[type=range] { position: absolute; inset: 0; width: 100%; pointer-events: none; background: transparent; -webkit-appearance: none; appearance: none; }
.recorte input[type=range]::-webkit-slider-thumb { pointer-events: auto; -webkit-appearance: none; width: 18px; height: 26px; border-radius: 5px; background: var(--panel); border: 2px solid var(--acento); cursor: ew-resize; }
.recorte input[type=range]::-moz-range-thumb { pointer-events: auto; width: 16px; height: 24px; border-radius: 5px; background: var(--panel); border: 2px solid var(--acento); cursor: ew-resize; }

.log { background: #0b1414; color: #b7d7d3; font-family: var(--mono); font-size: .76rem; padding: 12px; border-radius: 9px; max-height: 320px; overflow: auto; white-space: pre-wrap; word-break: break-all; }
.barra-prog { height: 8px; background: var(--borde); border-radius: 4px; overflow: hidden; }
.barra-prog > div { height: 100%; background: var(--acento); width: 30%; animation: indet 1.4s infinite ease-in-out; }
@keyframes indet { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }

/* ---------- Equipo (técnico) ---------- */
.medidor { display: flex; align-items: baseline; gap: 6px; }
.medidor .val { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.medidor .u { color: var(--texto-3); font-size: .85rem; }
canvas.grafica { width: 100%; height: 180px; display: block; }
.leyenda { display: flex; gap: 14px; font-size: .8rem; color: var(--texto-2); }
.leyenda i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 5px; }
.eventos { max-height: 230px; overflow: auto; font-size: .84rem; }
.eventos div { padding: 6px 0; border-bottom: 1px solid var(--borde); display: flex; justify-content: space-between; gap: 10px; }

/* ---------- Modal y avisos ---------- */
.fondo-modal { position: fixed; inset: 0; background: rgba(5, 15, 15, .55); display: grid; place-items: center; z-index: 100; padding: 16px; }
.modal { background: var(--panel); border-radius: 14px; width: min(620px, 100%); max-height: 92vh; overflow: auto; padding: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal.ancho { width: min(1000px, 100%); }
.modal .pie-modal { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast { background: var(--texto); color: var(--bg); padding: 10px 16px; border-radius: 9px; font-size: .9rem; box-shadow: var(--sombra); max-width: 360px; }
.toast.error { background: var(--error); color: #fff; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login .lado { background: linear-gradient(160deg, #0f766e, #134e4a 70%); color: #e6fffb; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.login .lado h1 { font-size: 2rem; color: #fff; max-width: 14ch; }
.login .lado ul { padding-left: 18px; color: #b7efe6; }
.login .form { display: grid; place-items: center; padding: 24px 16px; }
.login form { width: min(380px, 100%); }
.roles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 18px; }
.roles button { border: 1px solid var(--borde); background: var(--panel); border-radius: 10px; padding: 10px 6px; font: inherit; font-size: .8rem; color: var(--texto-2); cursor: pointer; }
.roles button.sel { border-color: var(--acento); background: var(--acento-suave); color: var(--acento-2); font-weight: 600; }
@media (max-width: 800px) { .login { grid-template-columns: 1fr; } .login .lado { padding: 28px 20px; } .login .lado ul { display: none; } }

/* ---------- Flujo de escaneo ---------- */
.flujo { display: grid; gap: 16px; }
.flujo.con-panel { grid-template-columns: minmax(0, 1fr) 270px; align-items: start; }
@media (max-width: 1000px) { .flujo.con-panel { grid-template-columns: minmax(0, 1fr); } .flujo.con-panel aside { order: -1; } }
.flujo aside { position: sticky; top: 16px; }
.panel-equipo label { font-size: .8rem; }
.pe-fila { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--borde); font-size: .9rem; }
.pe-lux b { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.barra-lux { height: 6px; background: var(--borde); border-radius: 3px; overflow: hidden; margin: 2px 0 6px; }
.barra-lux div { height: 100%; width: 0; border-radius: 3px; transition: width .4s; }
.estado-grande { display: flex; gap: 14px; align-items: center; padding: 14px 16px; border-radius: 12px; background: var(--panel-2); border: 1px solid var(--borde); }
.estado-grande > span { font-size: 1.6rem; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none; font-weight: 700; }
.estado-grande b { font-size: 1.05rem; }
.estado-grande.ok { background: var(--ok-bg); border-color: transparent; } .estado-grande.ok > span { background: var(--ok); color: #fff; }
.estado-grande.error { background: var(--error-bg); border-color: transparent; } .estado-grande.error > span { color: var(--error); }
.giro { display: inline-block; width: 26px; height: 26px; border: 3px solid var(--borde); border-top-color: var(--acento); border-radius: 50%; animation: girar 0.9s linear infinite; }
.estado-grande > span.giro { width: 30px; height: 30px; margin: 7px; }
.giro.grande { width: 54px; height: 54px; border-width: 5px; }
@keyframes girar { to { transform: rotate(360deg); } }
.guia-plato { width: min(340px, 100%); height: auto; filter: drop-shadow(0 6px 18px rgba(15,40,40,.15)); }
.guia-plato.peq { width: 200px; }
.qr { width: min(240px, 80%); margin: 6px auto 0; background: #fff; padding: 6px; border-radius: 10px; }
.qr svg { display: block; width: 100%; height: auto; }
.codigo { font-family: var(--mono); font-size: 2rem; font-weight: 700; letter-spacing: .12em; margin-bottom: 12px; }
.marco-video img { width: 100%; height: 100%; object-fit: contain; display: block; }
.marco-video .vacio { position: absolute; inset: 0; display: grid; place-items: center; }
.marco-video.grande { aspect-ratio: 16/9; max-height: 62vh; }
.sep { border: 0; border-top: 1px solid var(--borde); margin: 14px 0; }
.generacion { text-align: center; padding: 34px clamp(16px, 5vw, 60px); }
.gen-icono { height: 64px; display: grid; place-items: center; margin-bottom: 10px; }
.barra-carga { height: 16px; background: var(--borde); border-radius: 8px; overflow: hidden; margin-top: 18px; }
.barra-carga div { height: 100%; width: 0; border-radius: 8px; transition: width .8s ease;
  background: repeating-linear-gradient(-45deg, var(--acento) 0 14px, color-mix(in srgb, var(--acento) 80%, #fff) 14px 28px);
  background-size: 40px 40px; animation: rayas 1s linear infinite; }
@keyframes rayas { to { background-position: 40px 0; } }
.portada { display: flex; gap: 28px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.portada > div { flex: 1; min-width: 240px; }
.lista-pasos { padding-left: 20px; margin: 0 0 18px; line-height: 1.9; }
.rutina-tabla td, .rutina-tabla th { padding: 6px 8px; }

/* Botón de cerrar sesión */
.btn-salir { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn-salir svg { width: 18px; height: 18px; }
.lateral .btn-salir:hover { border-color: var(--error); color: var(--error); }

/* ---------- Ajuste de video: recuadro de la muestra (ROI) ---------- */
.roi-cont { position: relative; width: 100%; margin: 0 auto; background: #000; border-radius: 10px; overflow: hidden;
            aspect-ratio: 16 / 9; touch-action: none; user-select: none; cursor: crosshair; }
.roi-cont video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: fill; pointer-events: none; }
.roi { position: absolute; border: 2px solid var(--acento); box-shadow: 0 0 0 9999px rgba(0, 0, 0, .55); cursor: move; border-radius: 4px; }
.roi::after { content: "muestra"; position: absolute; top: 4px; left: 50%; transform: translateX(-50%); background: var(--acento);
              color: #04201d; font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 4px; pointer-events: none; }
.roi .h { position: absolute; width: 18px; height: 18px; background: var(--acento); border: 2px solid #04201d; border-radius: 4px; }
.roi .h[data-h="nw"] { left: -10px; top: -10px; cursor: nwse-resize; }
.roi .h[data-h="ne"] { right: -10px; top: -10px; cursor: nesw-resize; }
.roi .h[data-h="sw"] { left: -10px; bottom: -10px; cursor: nesw-resize; }
.roi .h[data-h="se"] { right: -10px; bottom: -10px; cursor: nwse-resize; }
.toma-item { padding: 8px 10px; border: 1px solid var(--borde); border-radius: 10px; cursor: pointer; }
.toma-item.activa { border-color: var(--acento); background: color-mix(in srgb, var(--acento) 10%, transparent); }

/* ---------- Toma de video controlada desde el celular ---------- */
.toma-estado .estado-grande { padding: 22px; }
.punto-rec { width: 22px; height: 22px; border-radius: 50%; background: #ef4444; flex: none; animation: latir 1s ease-in-out infinite; }
@keyframes latir { 50% { opacity: .35; } }
.estado-grande > .punto-rec { width: 22px; height: 22px; }

/* ---------- Visor 3D: barra de vistas ---------- */
.visor-barra { position: absolute; top: 10px; right: 10px; display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.visor-barra button { background: rgba(0, 0, 0, .45); color: #e6f0ef; border: 1px solid rgba(255, 255, 255, .15); border-radius: 8px;
                      padding: 5px 9px; font: inherit; font-size: .78rem; cursor: pointer; }
.visor-barra button:hover { background: rgba(45, 212, 191, .25); }
.editor-final .campo { margin-bottom: 10px; }
.editor-final .val { float: right; font-weight: 700; color: var(--acento); }
