:root {
  --bg: #f4f5f7; --surface: #ffffff; --text: #1d2330; --muted: #667085; --border: #dfe3ea;
  --primary: #1f5eff; --primary-text: #ffffff; --danger: #c62828; --ok: #1b7f3a; --warn: #a15c00;
  --chip: #eef1f6; --sidebar: #f8f9fb;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --surface: #1b2029; --text: #e7eaf0; --muted: #98a2b3; --border: #2c3340;
    --primary: #5b8cff; --primary-text: #0b0e14; --danger: #ff6b6b; --ok: #4fc777; --warn: #f0a642;
    --chip: #262d39; --sidebar: #161a21;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.error { color: var(--danger); min-height: 1.2em; }
h1 { font-size: 22px; margin: 0 0 4px; } h2 { font-size: 17px; margin: 0 0 8px; }
input, select { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; width: 100%; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.btn { font: inherit; border: 1px solid var(--border); background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 14px; cursor: pointer; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); font-weight: 600; }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: .5; cursor: wait; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin: 16px; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; margin: 0; }

/* ---- estructura: menú lateral + contenido ---- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar { --sb-w: 264px; width: var(--sb-w); flex: 0 0 var(--sb-w); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 4px; padding: 10px 8px; background: var(--sidebar);
  border-right: 1px solid var(--border); overflow: hidden; transition: width .18s ease, flex-basis .18s ease; z-index: 30; }
.sb-head { display: flex; align-items: center; gap: 8px; min-height: 40px; }
.sb-title { font-size: 13px; font-weight: 600; white-space: nowrap; }
/* marca LEXID */
.brand { display: flex; align-items: center; gap: 10px; }
.wordmark { font-weight: 800; letter-spacing: .06em; color: var(--text); margin: 0; }
.wordmark span { color: var(--primary); }
.sb-title.brand { gap: 8px; }
.sb-title .wordmark { font-size: 17px; }
.brand-login { flex-direction: column; gap: 10px; margin-bottom: 6px; }
.brand-login .wordmark { font-size: 30px; }
.sep { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; margin: 2px 0; }
.sep::before, .sep::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.btn.google { display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; font-weight: 500; }
.chip.google { color: var(--ok); }
.sb-toggle { flex: 0 0 40px; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 6px;
  background: none; color: var(--text); cursor: pointer; }
.sb-toggle:hover, .tab:hover, .sb-logout:hover { background: var(--chip); }
.sb-user { display: flex; align-items: center; gap: 12px; padding: 14px 6px 18px; white-space: nowrap; }
.avatar { flex: 0 0 44px; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  background: var(--chip); color: var(--text); font-weight: 700; font-size: 17px; }
.sb-user-text { display: flex; flex-direction: column; min-width: 0; }
.sb-user-text strong { font-size: 14px; overflow: hidden; text-overflow: ellipsis; }
.sb-user-text span { font-size: 12px; color: var(--muted); }
.sb-nav { display: flex; flex-direction: column; gap: 2px; }
.tab, .sb-logout { position: relative; display: flex; align-items: center; gap: 14px; width: 100%; padding: 9px 12px;
  border: 0; border-radius: 6px; background: none; color: var(--text); font: inherit; font-size: 14px; text-align: left;
  text-decoration: none; cursor: pointer; white-space: nowrap; }
.tab svg, .sb-logout svg, .sb-toggle svg { width: 20px; height: 20px; flex: 0 0 20px; fill: none; stroke: currentColor;
  stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tab.active { background: var(--chip); font-weight: 600; }
.tab.active::before { content: ""; position: absolute; left: 0; top: 25%; height: 50%; width: 3px; border-radius: 3px; background: var(--primary); }
.sb-logout { margin-top: auto; color: var(--danger); }
.content { flex: 1; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 8px; padding: 18px 16px 0; }
.page-head h1 { font-size: 26px; font-weight: 600; margin: 0; }
.sb-open { display: none; }
.sb-backdrop { display: none; }

/* contraído: solo íconos */
.app-shell.collapsed .sidebar { --sb-w: 56px; }
.app-shell.collapsed .lbl, .app-shell.collapsed .sb-title, .app-shell.collapsed .sb-user-text { display: none; }
.app-shell.collapsed .sb-user { padding: 14px 0 18px; justify-content: center; }
.app-shell.collapsed .avatar { flex-basis: 36px; width: 36px; height: 36px; font-size: 14px; }
.app-shell.collapsed .tab, .app-shell.collapsed .sb-logout { justify-content: center; padding: 9px 0; }

/* celular: el menú se abre como panel sobre el contenido */
@media (max-width: 720px) {
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 0 0 24px rgba(0,0,0,.25); }
  .app-shell.open .sidebar { transform: none; }
  .app-shell.collapsed .sidebar { --sb-w: 264px; }
  .app-shell.collapsed .lbl, .app-shell.collapsed .sb-title, .app-shell.collapsed .sb-user-text { display: initial; }
  .app-shell.collapsed .sb-user-text { display: flex; }
  .app-shell.collapsed .tab, .app-shell.collapsed .sb-logout { justify-content: flex-start; padding: 9px 12px; }
  .app-shell.open .sb-backdrop { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 20; }
  .sb-open { display: grid; }
  .page-head h1 { font-size: 22px; }
}

.upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.drop { border: 2px dashed var(--border); border-radius: 12px; padding: 18px; text-align: center; cursor: pointer; position: relative; min-height: 150px; justify-content: center; align-items: center; }
.drop.over { border-color: var(--primary); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-title { font-weight: 600; color: var(--text); font-size: 15px; }
.preview { max-width: 100%; max-height: 160px; border-radius: 6px; margin-top: 8px; }
.upload-actions { grid-column: 1 / -1; display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }

.list-head { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.filters input { width: 220px; } .filters select { width: auto; }
.export { position: relative; }
.export > summary { list-style: none; user-select: none; }
.export > summary::-webkit-details-marker { display: none; }
.export-menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 10; width: 290px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.15); }
.export-menu a { display: flex; flex-direction: column; padding: 8px 10px; border-radius: 6px; color: var(--text); text-decoration: none; }
.export-menu a:hover, .export-menu a:focus { background: var(--chip); outline: none; }
.export-menu a span { font-size: 12px; color: var(--muted); }
.export-menu p { margin: 6px 10px 4px; }
a.btn { display: inline-block; text-decoration: none; }
.cam-row { grid-column: 1 / -1; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cam-row .btn { display: inline-flex; align-items: center; gap: 6px; }
.drop.camara { border-style: solid; border-color: var(--ok); }
#camara { width: min(760px, calc(100vw - 16px)); }
.cam-body { padding: 12px 16px 16px; display: flex; flex-direction: column; gap: 10px; }
.cam-view { position: relative; background: #000; border-radius: 10px; overflow: hidden; aspect-ratio: 4 / 3; }
.cam-view video, .cam-view img { width: 100%; height: 100%; object-fit: contain; display: block; }
.cam-view img { position: absolute; inset: 0; background: #000; }
.cam-guia { position: absolute; border: 3px solid rgba(255,255,255,.95); border-radius: 12px;
  box-shadow: 0 0 0 9999px rgba(0,0,0,.45); pointer-events: none; transition: border-color .2s; }
.cam-guia.bien { border-color: #4fc777; }
.cam-live { display: flex; gap: 6px; flex-wrap: wrap; }
.cam-live .chip.ok { color: var(--ok); } .cam-live .chip.mal { color: var(--danger); }
.cam-nota { font-size: 30px; font-weight: 700; }
.cam-nota small { font-size: 14px; color: var(--muted); font-weight: 400; }
.cam-nota .ok { color: var(--ok); font-size: 16px; } .cam-nota .mal { color: var(--danger); font-size: 16px; }
.cam-barras { display: grid; grid-template-columns: 110px 1fr 36px; gap: 4px 8px; align-items: center; font-size: 13px; }
.cam-barras .barra { height: 8px; background: var(--chip); border-radius: 4px; overflow: hidden; }
.cam-barras .barra i { display: block; height: 100%; background: var(--ok); }
.cam-barras .barra i.bajo { background: var(--danger); }
.cam-motivos { margin: 0; padding-left: 18px; color: var(--danger); font-size: 14px; }
.cam-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.spinner { display: inline-block; width: 13px; height: 13px; margin-right: 6px; vertical-align: -2px;
  border: 2px solid var(--chip); border-top-color: var(--primary); border-radius: 50%; animation: girar .8s linear infinite; }
@keyframes girar { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
tbody tr.en-proceso { cursor: progress; opacity: .75; }
tbody tr.en-proceso:hover { background: none; }
tbody tr.recien-listo { animation: resaltar 2.5s ease-out; }
@keyframes resaltar { from { background: rgba(79, 199, 119, .35); } to { background: transparent; } }
.table-wrap { overflow-x: auto; margin-top: 10px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tbody tr { cursor: pointer; } tbody tr:hover { background: var(--chip); }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 10px; }

.chip { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; background: var(--chip); }
.chip.procesado { color: var(--ok); } .chip.error { color: var(--danger); } .chip.pendiente, .chip.procesando { color: var(--warn); }
.chip.revisado { color: var(--primary); }
.v-ok { color: var(--ok); } .v-bad { color: var(--danger); }

dialog { width: min(1100px, calc(100vw - 32px)); max-height: calc(100vh - 32px); border: 1px solid var(--border); border-radius: 14px; padding: 0; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgba(0,0,0,.45); }
.det-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--surface); }
.det-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 16px; padding: 16px; }
.det-imgs img, .det-imgs iframe { width: 100%; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px; background: #fff; }
.det-imgs iframe { height: 520px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 10px 0; }
.form-grid .wide { grid-column: 1 / -1; }
.det-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
pre { white-space: pre-wrap; word-break: break-word; background: var(--chip); padding: 10px; border-radius: 8px; font-size: 12px; max-height: 320px; overflow: auto; }
details { margin-top: 8px; } summary { cursor: pointer; color: var(--muted); }

@media (max-width: 720px) {
  .upload-grid, .det-body, .form-grid { grid-template-columns: 1fr; }
  .card { margin: 12px 0; border-radius: 0; border-left: 0; border-right: 0; }
  .filters input { width: 100%; }
}
