:root {
    --bg: #0f1115;
    --surface: #1a1d24;
    --surface-2: #242833;
    --accent: #ffb02e;
    --accent-d: #e09415;
    --text: #f2f3f5;
    --muted: #9aa0ac;
    --ok: #34c759;
    --err: #ff453a;
    --radius: 16px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

body {
    font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    min-height: 100dvh;
}

/* --- Top bar --- */
.topbar {
    padding: 18px 20px 14px;
    background: linear-gradient(180deg, #181b22, var(--bg));
    border-bottom: 1px solid #00000040;
}
.topbar h1 { font-size: 20px; letter-spacing: .3px; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.modelo-sel { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.modelo-sel span { font-size: 12px; color: var(--muted); white-space: nowrap; }
.modelo-sel select {
    flex: 1; min-width: 0;
    background: var(--surface-2); color: var(--text);
    border: 1px solid #ffffff14; border-radius: 10px;
    padding: 9px 12px; font-size: 14px; cursor: pointer;
}

.topbar { position: relative; }
.btn-config {
    position: absolute; top: 16px; right: 16px;
    width: 40px; height: 40px; border-radius: 50%;
    background: var(--surface-2); border: none; font-size: 18px; cursor: pointer;
}
.btn-config:active { background: #2e333f; }

/* --- Configurar campos --- */
.campos-lista { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.campo-row { display: flex; gap: 8px; align-items: stretch; }
.campo-row input {
    background: var(--surface); color: var(--text);
    border: 1px solid #ffffff14; border-radius: 10px;
    padding: 11px 12px; font-size: 14px; min-width: 0;
}
.campo-row .campo-nombre { flex: 0 0 34%; }
.campo-row .campo-pistas { flex: 1; }
.campo-row .campo-del {
    flex: 0 0 42px; background: var(--surface-2); color: var(--err);
    border: none; border-radius: 10px; font-size: 16px; cursor: pointer;
}
.btn-guardar {
    width: 100%; margin-top: 12px; padding: 14px;
    background: var(--accent); color: #1a1206; border: none;
    border-radius: 12px; font-size: 16px; font-weight: 700; cursor: pointer;
}
.btn-guardar:active { background: var(--accent-d); }
.config-estado { margin-top: 12px; text-align: center; font-size: 14px; min-height: 20px; }
.config-estado.ok { color: var(--ok); }
.config-estado.error { color: var(--err); }

/* --- Vistas (pantallas) --- */
.vista { display: none; padding: 18px 16px 32px; }
.vista.activa { display: block; }

.hint { color: var(--muted); font-size: 14px; margin-bottom: 16px; }

/* --- Grid de maquinas --- */
.grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 520px) { .grid { grid-template-columns: repeat(3, 1fr); } }

.card {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 20px;
    background: var(--surface);
    border: 1px solid #ffffff10;
    border-radius: var(--radius);
    color: var(--text);
    cursor: pointer;
    text-align: left;
    transition: transform .08s ease, background .15s ease;
}
.card:active { transform: scale(.98); background: var(--surface-2); }
.card-icon { font-size: 32px; }
.card-nombre { font-size: 17px; font-weight: 600; }
.card-id { font-size: 12px; color: var(--muted); letter-spacing: 1px; }

/* --- Cabecera de camara / resultado --- */
.cam-header { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.btn-volver {
    background: var(--surface-2);
    color: var(--text);
    border: none;
    border-radius: 10px;
    padding: 8px 14px;
    font-size: 15px;
    cursor: pointer;
}
.cam-titulo { font-size: 16px; font-weight: 600; }

/* --- Camara --- */
.cam-stage {
    position: relative;
    width: 100%;
    aspect-ratio: 3 / 4;
    background: #000;
    border-radius: var(--radius);
    overflow: hidden;
}
#video { width: 100%; height: 100%; object-fit: cover; }
.cam-guia {
    position: absolute; inset: 10%;
    border: 2px dashed #ffffff66;
    border-radius: 12px;
    pointer-events: none;
}
.cam-msg {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    text-align: center; padding: 28px;
    color: var(--muted); font-size: 15px; line-height: 1.4; background: #000;
}
/* El atributo hidden debe ganarle al display:flex de arriba. */
.cam-msg[hidden] { display: none; }
.cam-controls { display: flex; align-items: center; justify-content: center; gap: 30px; padding: 22px 0; }
.btn-mini {
    width: 52px; height: 52px; border-radius: 50%;
    background: var(--surface-2); border: none; color: var(--text);
    font-size: 22px; cursor: pointer;
}
.btn-mini:active { background: #2e333f; }
.btn-mini-spacer { visibility: hidden; pointer-events: none; }
.btn-capturar {
    width: 72px; height: 72px;
    border-radius: 50%;
    background: var(--accent);
    border: 5px solid #ffffff22;
    cursor: pointer;
    transition: transform .08s ease;
}
.btn-capturar:active { transform: scale(.92); }

/* --- Resultado --- */
.res-body { display: flex; flex-direction: column; gap: 16px; }
.res-foto {
    width: 100%; max-height: 240px; object-fit: contain;
    background: #000; border-radius: var(--radius);
}
.res-estado { font-size: 15px; color: var(--muted); text-align: center; min-height: 22px; }
.res-estado.cargando { color: var(--accent); }
.res-estado.error { color: var(--err); }
.res-estado.ok { color: var(--ok); }

.spinner {
    display: inline-block; width: 16px; height: 16px;
    border: 2px solid #ffffff33; border-top-color: var(--accent);
    border-radius: 50%; animation: giro .8s linear infinite;
    vertical-align: -3px; margin-right: 8px;
}
@keyframes giro { to { transform: rotate(360deg); } }

.res-tablas { display: flex; flex-direction: column; gap: 18px; }
.sec-titulo { font-size: 12px; font-weight: 700; color: var(--accent); letter-spacing: .6px; text-transform: uppercase; margin-bottom: -10px; }
.unidad { display: inline-block; margin-left: 8px; font-size: 10px; color: var(--muted); background: var(--surface-2); padding: 1px 6px; border-radius: 6px; vertical-align: middle; text-transform: uppercase; letter-spacing: .3px; }

.res-tabla { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; }
.res-tabla th, .res-tabla td { padding: 12px 14px; text-align: left; font-size: 14px; border-bottom: 1px solid #ffffff10; }
.res-tabla th { background: var(--surface-2); color: var(--muted); font-weight: 600; }
.res-tabla td:first-child { color: var(--muted); }
.res-tabla tr:last-child td { border-bottom: none; }

.res-crudo { background: var(--surface); border-radius: 12px; padding: 12px 14px; font-size: 13px; color: var(--muted); }
.res-crudo pre { white-space: pre-wrap; word-break: break-word; margin-top: 8px; color: var(--text); }

.btn-secundario {
    background: var(--surface-2); color: var(--text); border: none;
    border-radius: 12px; padding: 14px; font-size: 15px; cursor: pointer;
}
.btn-secundario:active { background: #2e333f; }
