/*
 * Estilo basado en las Human Interface Guidelines de Apple:
 * - Colores del sistema (systemBlue, systemRed…) y fondos agrupados, con sus valores claros y oscuros.
 * - Tipografía San Francisco (fuente del sistema) con la escala de Dynamic Type de iOS.
 * - Materiales translúcidos en las barras, listas agrupadas con esquinas redondeadas.
 * - Objetivos táctiles de al menos 44 pt, foco visible, movimiento reducido y contraste aumentado.
 */

:root {
  color-scheme: light dark;

  /* Fondos (systemGroupedBackground y derivados) */
  --bg: #f2f2f7;
  --surface: #ffffff;
  --surface-2: #f2f2f7;
  /* Texto (label, secondaryLabel, tertiaryLabel) */
  --label: #000000;
  --label-2: rgba(60, 60, 67, 0.6);
  --label-3: rgba(60, 60, 67, 0.3);
  --separator: rgba(60, 60, 67, 0.29);
  /* Rellenos de controles (tertiarySystemFill / secondarySystemFill) */
  --fill: rgba(118, 118, 128, 0.12);
  --fill-2: rgba(120, 120, 128, 0.16);
  /* Colores del sistema */
  --blue: #007aff;
  --red: #ff3b30;
  --green: #34c759;
  --orange: #ff9500;
  /* Variantes de contraste aumentado: texto sobre fondos teñidos y la alerta principal */
  --blue-text: #0040dd;
  --red-text: #d70015;
  --green-text: #248a3d;
  --orange-text: #c93400;
  --alert: #d70015;
  /* Material de barras (regular / thick) */
  --material: rgba(249, 249, 249, 0.8);
  --hud: rgba(30, 30, 30, 0.86);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 16px;
  --tap: 44px;
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro", system-ui, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro", system-ui, "Segoe UI",
    Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --tabbar-h: 0px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --surface: #1c1c1e;
    --surface-2: #2c2c2e;
    --label: #ffffff;
    --label-2: rgba(235, 235, 245, 0.6);
    --label-3: rgba(235, 235, 245, 0.3);
    --separator: rgba(84, 84, 88, 0.6);
    --fill: rgba(118, 118, 128, 0.24);
    --fill-2: rgba(120, 120, 128, 0.32);
    --blue: #0a84ff;
    --red: #ff453a;
    --green: #30d158;
    --orange: #ff9f0a;
    --blue-text: #409cff;
    --red-text: #ff6961;
    --green-text: #30d158;
    --orange-text: #ffb340;
    --material: rgba(29, 29, 31, 0.78);
    --hud: rgba(58, 58, 60, 0.9);
  }
}

@media (prefers-contrast: more) {
  :root {
    --label-2: rgba(60, 60, 67, 0.85);
    --separator: rgba(60, 60, 67, 0.6);
    --blue: #0040dd;
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --label-2: rgba(235, 235, 245, 0.85);
      --separator: rgba(140, 140, 145, 0.8);
      --blue: #409cff;
    }
  }
}

/* ------------------------------------------------------------------ base */

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font-family: var(--font);
  font-size: 17px;            /* Body */
  line-height: 1.29;
  letter-spacing: -0.024em;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 8px 16px calc(32px + var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
}

h1, h2, h3, h4 { font-family: var(--font-display); margin: 0 0 12px; letter-spacing: -0.02em; }
.large-title { font-size: 34px; line-height: 41px; font-weight: 700; letter-spacing: 0.011em; margin: 12px 4px 16px; }
h2 { font-size: 22px; line-height: 28px; font-weight: 700; }          /* Title 2 */
h3 { font-size: 20px; line-height: 25px; font-weight: 600; }          /* Title 3 */
h4 { font-size: 17px; line-height: 22px; font-weight: 600; margin: 16px 0 6px; }  /* Headline */
p { margin: 0 0 12px; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

.muted { color: var(--label-2); }
.small { font-size: 13px; line-height: 18px; letter-spacing: -0.006em; }   /* Footnote */
.error-text { color: var(--red-text); }
.score { font-variant-numeric: tabular-nums; }

.icon { width: 1.2em; height: 1.2em; flex: none; }

:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 55%, transparent); outline-offset: 2px; }

/* ------------------------------------------------------------------ barras (material translúcido) */

.chrome { position: sticky; top: 0; z-index: 20; }
.topbar {
  display: flex; align-items: center; gap: 12px;
  min-height: 52px;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right)) 0 max(16px, env(safe-area-inset-left));
  background: var(--material);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}
.brand { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user { display: flex; align-items: center; gap: 4px; color: var(--label-2); font-size: 15px; }
.user #user-name { max-width: 30vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Pestañas: barra inferior (iPhone) */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex;
  padding: 0 max(8px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(8px, env(safe-area-inset-left));
  background: var(--material);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-top: 0.5px solid var(--separator);
}
.tabbar:empty { display: none; }
body:has(.tabbar:not(:empty)) { --tabbar-h: 50px; }
.tabbar button {
  flex: 1; min-height: 50px; min-width: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; background: none; color: var(--label-2);
  font: 500 10px/12px var(--font); letter-spacing: 0.01em; cursor: pointer;
}
.tabbar button .icon { width: 26px; height: 26px; stroke-width: 1.7; }
.tabbar button.active { color: var(--blue); }
.tabbar button.active .icon { stroke-width: 2.2; }

/* Pestañas: control segmentado en pantallas anchas (iPad / Mac) */
@media (min-width: 980px) {
  body:has(.tabbar:not(:empty)) { --tabbar-h: 0px; }
  .tabbar {
    position: absolute; bottom: auto; left: 50%; right: auto;
    top: calc(env(safe-area-inset-top) + 9px);
    transform: translateX(-50%);
    padding: 2px; gap: 2px;
    background: var(--fill); border: 0; border-radius: 9px;
    -webkit-backdrop-filter: none; backdrop-filter: none;
  }
  .tabbar button {
    flex: none; flex-direction: row; min-height: 30px; padding: 0 16px; border-radius: 7px;
    color: var(--label); font: 500 13px/18px var(--font);
  }
  .tabbar button .icon { display: none; }
  .tabbar button.active {
    background: var(--surface); color: var(--label); font-weight: 600;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
  }
}

/* ------------------------------------------------------------------ botones */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: var(--tap); padding: 0 18px; margin: 0;
  border: 0; border-radius: var(--radius);
  background: var(--blue); color: #fff;
  font: 600 17px/22px var(--font); letter-spacing: -0.024em;
  cursor: pointer; user-select: none; text-decoration: none;
  transition: opacity 0.15s var(--ease), transform 0.15s var(--ease), background-color 0.15s var(--ease);
}
.btn:hover { text-decoration: none; filter: brightness(1.05); }
.btn:active { opacity: 0.65; transform: scale(0.98); }
.btn:disabled { background: var(--fill); color: var(--label-3); cursor: default; filter: none; transform: none; opacity: 1; }
/* Gris teñido (secundario) */
.btn.secondary { background: var(--fill); color: var(--blue); }
/* Sin fondo (terciario) */
.btn.ghost { background: transparent; color: var(--blue); padding: 0 10px; }
/* Destructivo teñido */
.btn.danger { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red-text); }
.btn.small { min-height: 34px; padding: 0 12px; border-radius: var(--radius-sm); font-size: 15px; font-weight: 500; }
.btn.huge { width: 100%; min-height: 56px; border-radius: 14px; font-size: 19px; }
.btn.huge .icon { width: 24px; height: 24px; }
@media (pointer: coarse) { .btn.small { min-height: var(--tap); } }

/* Botón circular de cierre de hojas */
.close-btn {
  width: 30px; height: 30px; flex: none; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%; background: var(--fill); color: var(--label-2); cursor: pointer;
  position: relative;
}
.close-btn::after { content: ""; position: absolute; inset: -7px; } /* área táctil de 44 pt */
.close-btn .icon { width: 16px; height: 16px; stroke-width: 2.4; }

/* Quitar elemento (sobre miniaturas) */
.remove-btn {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface); border-radius: 50%;
  background: var(--red); color: #fff; cursor: pointer;
}
.remove-btn::after { content: ""; position: absolute; inset: -10px; }
.remove-btn .icon { width: 12px; height: 12px; stroke-width: 3; }

/* ------------------------------------------------------------------ formularios */

label { display: block; font-size: 13px; line-height: 18px; color: var(--label-2); margin: 0 0 6px 4px; }
input, textarea, select {
  width: 100%; min-height: var(--tap);
  padding: 10px 14px;
  border: 0; border-radius: 10px;
  background: var(--fill); color: var(--label);
  font: 17px/22px var(--font); letter-spacing: -0.024em;
  transition: box-shadow 0.15s var(--ease), background-color 0.15s var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--label-3); }
input:focus, textarea:focus, select:focus {
  outline: none; background: var(--surface);
  box-shadow: 0 0 0 2px var(--blue);
}
input:disabled { color: var(--label-3); }
textarea { min-height: 88px; resize: vertical; }
select {
  -webkit-appearance: none; appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238e8e93' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 10l4-4 4 4M8 14l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; background-size: 18px;
}
input[type="file"] { padding: 9px 10px; font-size: 15px; }
input[type="file"]::file-selector-button {
  border: 0; border-radius: var(--radius-sm); padding: 6px 12px; margin-right: 10px;
  background: var(--surface); color: var(--blue); font: 500 15px var(--font); cursor: pointer;
}

/* Interruptor (UISwitch) para opciones sí/no */
input[type="checkbox"] {
  -webkit-appearance: none; appearance: none;
  width: 51px; min-width: 51px; height: 31px; min-height: 31px; padding: 0;
  border-radius: 31px; background: var(--fill-2); position: relative; cursor: pointer;
  transition: background-color 0.2s var(--ease);
}
input[type="checkbox"]::before {
  content: ""; position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 3px 1px rgba(0, 0, 0, 0.06);
  transition: transform 0.2s var(--ease);
}
input[type="checkbox"]:checked { background: var(--green); }
input[type="checkbox"]:checked::before { transform: translateX(20px); }
input[type="checkbox"]:focus { box-shadow: none; }
input[type="checkbox"]:focus-visible { outline: 3px solid color-mix(in srgb, var(--blue) 55%, transparent); outline-offset: 2px; }

.field { margin-bottom: 14px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { flex: 1; min-width: 180px; }
.row > .shrink { flex: 0 0 auto; min-width: 0; }
/* Fila con interruptor: texto a la izquierda, interruptor a la derecha (como en Ajustes) */
.check {
  display: flex; flex-direction: row-reverse; align-items: center; justify-content: space-between; gap: 12px;
  min-height: var(--tap); margin: 4px 0; color: var(--label); font-size: 17px; cursor: pointer;
}
.row .check { justify-content: flex-end; margin: 0 0 6px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 20px; }

/* ------------------------------------------------------------------ superficies */

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 20px;
}
.card > :last-child { margin-bottom: 0; }

.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  background: var(--fill); color: var(--label-2);
  font-size: 12px; line-height: 16px; font-weight: 600; letter-spacing: 0;
  white-space: nowrap; vertical-align: middle;
}
.badge.danger { background: color-mix(in srgb, var(--red) 15%, transparent); color: var(--red-text); }
.badge.warn { background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--orange-text); }
.badge.ok { background: color-mix(in srgb, var(--green) 16%, transparent); color: var(--green-text); }

.spinner {
  width: 36px; height: 36px; margin: 20px auto 12px; border-radius: 50%;
  border: 3px solid var(--fill-2); border-top-color: var(--label-2);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.progress { height: 6px; background: var(--fill); border-radius: 3px; overflow: hidden; margin: 8px 0 12px; }
.progress > div { height: 100%; background: var(--blue); border-radius: 3px; transition: width 0.3s var(--ease); }

.pager { display: flex; gap: 12px; align-items: center; justify-content: center; margin-top: 16px; }

/* Tablas como listas agrupadas: separadores finos, sin rejilla */
.table-wrap { overflow-x: auto; padding: 4px 0; }
table { width: 100%; border-collapse: collapse; font-size: 15px; line-height: 20px; }
th, td { text-align: left; padding: 11px 16px; vertical-align: top; }
th { color: var(--label-2); font-size: 13px; font-weight: 400; padding-top: 8px; padding-bottom: 6px; }
td { border-top: 0.5px solid var(--separator); }
.cell-actions { white-space: nowrap; }

/* En el celular las tablas se muestran como lista: una celda por fila, valores con su etiqueta */
@media (max-width: 640px) {
  .table-wrap { padding: 0; }
  .table-wrap table, .table-wrap tbody, .table-wrap tr, .table-wrap td { display: block; }
  .table-wrap thead { display: none; }
  .table-wrap tr { padding: 10px 0; border-top: 0.5px solid var(--separator); }
  .table-wrap tr:first-child { border-top: 0; }
  .table-wrap td { border: 0; padding: 3px 0; display: flex; gap: 16px; justify-content: space-between; align-items: baseline; text-align: right; }
  .table-wrap td[data-label]::before { content: attr(data-label); color: var(--label-2); text-align: left; flex: none; }
  .table-wrap td .log-match { white-space: normal; }
  .cell-actions { justify-content: flex-start; flex-wrap: wrap; padding-top: 8px; white-space: normal; }
}

/* ------------------------------------------------------------------ inicio de sesión */

.login { max-width: 400px; margin: 12vh auto 0; text-align: center; background: transparent; padding: 0 8px; }
.login .logo { display: block; width: 88px; height: 88px; margin: 0 auto 18px; border-radius: 20px; }
.login h1 { font-size: 34px; line-height: 41px; font-weight: 700; margin-bottom: 28px; }
.login form { text-align: left; }
.login .btn.huge { margin-top: 8px; }

/* ------------------------------------------------------------------ búsqueda */

.search-view { max-width: 560px; margin: 0 auto; }
.search-actions { display: grid; gap: 12px; }
.search-actions .muted { text-align: center; margin: 4px 0 0; }

.result-banner {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border-radius: var(--radius-lg); padding: 20px 16px; margin-bottom: 16px; text-align: center;
  font: 700 22px/28px var(--font-display); letter-spacing: -0.02em;
  --icon-cut: var(--alert);
}
.result-banner .icon { width: 34px; height: 34px; }
.result-banner .sub { display: block; font: 400 15px/20px var(--font); letter-spacing: -0.016em; opacity: 0.9; }
.result-match { background: var(--alert); color: #fff; }
.result-possible { background: color-mix(in srgb, var(--orange) 18%, var(--surface)); color: var(--orange-text); }
.result-no_match { background: color-mix(in srgb, var(--green) 16%, var(--surface)); color: var(--green-text); }
.result-no_face { background: var(--surface); color: var(--label); }

.compare { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
.compare figure { margin: 0; }
.compare img { width: 100%; aspect-ratio: 3 / 4; object-fit: cover; border-radius: var(--radius); background: var(--fill); display: block; }
.compare figcaption, .dup-row figcaption { font-size: 12px; line-height: 16px; color: var(--label-2); text-align: center; margin-top: 6px; }

/* Lista de datos con separadores (como celdas de valor) */
.data-list { display: grid; grid-template-columns: auto 1fr; margin: 0; }
.data-list dt, .data-list dd { padding: 10px 0; border-top: 0.5px solid var(--separator); }
.data-list dt { color: var(--label-2); padding-right: 16px; }
.data-list dd { margin: 0; font-weight: 600; text-align: right; word-break: break-word; }
.data-list dt:first-of-type, .data-list dd:first-of-type { border-top: 0; }
.comment {
  white-space: pre-wrap; margin-top: 12px; padding: 12px 14px; border-radius: var(--radius);
  background: color-mix(in srgb, var(--orange) 14%, transparent); color: var(--label); font-size: 15px; line-height: 20px;
}

.candidate { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 0.5px solid var(--separator); }
.candidate img { width: 52px; height: 52px; object-fit: cover; border-radius: 10px; flex: none; }

/* Foto con rostros numerados */
.annotated { position: relative; line-height: 0; overflow: hidden; border-radius: var(--radius); }
.annotated img { width: 100%; }
.face-box { position: absolute; border: 2.5px solid; border-radius: 8px; }
.face-box span {
  position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font: 700 13px/1 var(--font); color: #fff;
}
.fb-match { border-color: var(--red); } .fb-match span { background: var(--alert); }
.fb-possible { border-color: var(--orange); } .fb-possible span { background: #c93400; }
.fb-no_match { border-color: var(--green); } .fb-no_match span { background: #248a3d; }
.face-card h3 { display: flex; gap: 8px; align-items: center; }
.face-card.face-match { box-shadow: inset 0 0 0 2px var(--red); }
.face-card.face-possible { box-shadow: inset 0 0 0 2px var(--orange); }

.webcam { width: 100%; border-radius: var(--radius); background: #000; transform: scaleX(-1); display: block; }
.webcam.flash { animation: flash 0.35s ease-out; }
@keyframes flash { from { filter: brightness(2.5); } to { filter: none; } }

/* ------------------------------------------------------------------ personas */

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border-radius: var(--radius-lg); padding: 14px 16px; }
.stat .n { font: 700 28px/34px var(--font-display); font-variant-numeric: tabular-nums; letter-spacing: 0.01em; }
.stat .l { color: var(--label-2); font-size: 13px; line-height: 18px; }

.person-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.person-card {
  background: var(--surface); border: 0; border-radius: var(--radius-lg); overflow: hidden; padding: 0;
  text-align: left; color: inherit; font: inherit; cursor: pointer;
  transition: transform 0.15s var(--ease);
}
.person-card:active { transform: scale(0.97); }
.person-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--fill); }
.person-card .info { padding: 10px 12px 12px; display: grid; gap: 4px; }
.person-card .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.person-card.inactive { opacity: 0.5; }
.card .person-card { background: var(--surface-2); }

.photos-strip { display: flex; gap: 8px; flex-wrap: wrap; }
.photos-strip .ph { position: relative; }
.photos-strip img { width: 104px; height: 104px; object-fit: cover; border-radius: var(--radius); display: block; }

.similar { background: color-mix(in srgb, var(--orange) 14%, transparent); border-radius: var(--radius); padding: 12px 14px; margin: 14px 0; }
.similar h3 { margin: 0 0 2px; font-size: 15px; line-height: 20px; color: var(--orange-text); }
.similar p { margin: 0 0 6px; }
.pick-list { margin-top: 12px; max-height: 50vh; overflow-y: auto; }
.pick-row { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-top: 0.5px solid var(--separator); }
.similar .pick-row:first-of-type, .pick-list .pick-row:first-child { border-top: 0; }
.pick-row img { width: 46px; height: 46px; object-fit: cover; border-radius: 10px; flex: none; }
.pick-info { flex: 1; min-width: 0; }

.log-match { white-space: nowrap; }
.log-match + .log-match { margin-top: 4px; }

/* ------------------------------------------------------------------ importar */

.dropzone {
  border: 1.5px dashed var(--separator); border-radius: var(--radius-lg); padding: 24px 16px;
  text-align: center; background: var(--surface-2);
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease);
}
.dropzone.over { border-color: var(--blue); background: color-mix(in srgb, var(--blue) 10%, var(--surface)); }
.dropzone p { margin: 4px 0; }
.dropzone-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 12px 0; }
.selection-summary { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 14px 0 0; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-top: 12px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; background: var(--fill); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: 10px; }
.thumb span {
  display: flex; align-items: center; justify-content: center; height: 100%; padding: 4px;
  font-size: 11px; text-align: center; word-break: break-all; color: var(--label-2);
}

.meta-list { display: grid; gap: 10px; margin-top: 10px; }
.meta-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px; border-radius: var(--radius); background: var(--surface-2); }
.meta-row .thumb { flex: 0 0 84px; width: 84px; }
.meta-row p { margin: 0; align-self: center; }
.meta-fields { flex: 1; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
.meta-field { margin: 0; display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--label-2); }
.meta-field input { min-height: 40px; padding: 8px 12px; font-size: 15px; background: var(--surface); }

.dup-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; padding: 14px 0; border-top: 0.5px solid var(--separator); }
.dup-row figure { margin: 0; }
.dup-row img { width: 100%; max-width: 160px; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); display: block; margin: 0 auto; }
.dup-score { text-align: center; font: 700 22px/28px var(--font-display); display: flex; flex-direction: column; font-variant-numeric: tabular-nums; }
.dup-score span { font-weight: 400; }
.dup-actions { grid-column: 1 / -1; display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ------------------------------------------------------------------ hojas (sheets) */

dialog {
  border: 0; padding: 0; width: min(580px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  border-radius: 14px; background: var(--surface); color: var(--label);
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.3);
}
dialog[open] { animation: sheet-in 0.25s var(--ease); }
dialog::backdrop { background: rgba(0, 0, 0, 0.4); }
@keyframes sheet-in { from { opacity: 0; transform: scale(0.97); } }
#modal-body { padding: 20px; }
#modal-body:focus { outline: none; }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.modal-head h2 { margin: 0; font-size: 20px; line-height: 25px; font-weight: 600; }

/* En el celular las hojas salen desde abajo, con el indicador de arrastre */
@media (max-width: 640px) {
  dialog {
    width: 100%; max-width: 100%; margin: auto 0 0; max-height: calc(100% - env(safe-area-inset-top) - 12px);
    border-radius: 14px 14px 0 0; box-shadow: none;
  }
  dialog[open] { animation: sheet-up 0.3s var(--ease); }
  #modal-body { padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); }
  #modal-body::before {
    content: ""; display: block; width: 36px; height: 5px; border-radius: 3px;
    background: var(--label-3); margin: 0 auto 14px;
  }
  .actions { justify-content: stretch; }
  .actions .btn { flex: 1; }
  .actions > span[style] { display: none; }
}
@keyframes sheet-up { from { transform: translateY(100%); } }

/* Aviso tipo HUD */
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 100;
  bottom: calc(20px + var(--tabbar-h) + env(safe-area-inset-bottom));
  max-width: min(90vw, 420px); padding: 12px 20px; border-radius: 999px;
  background: var(--hud); color: #fff; font-size: 15px; font-weight: 600; text-align: center;
  -webkit-backdrop-filter: blur(20px); backdrop-filter: blur(20px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  animation: toast-in 0.25s var(--ease);
}
.toast.error { background: var(--alert); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ------------------------------------------------------------------ pantallas angostas */

@media (max-width: 640px) {
  .large-title { margin-top: 8px; }
  .user #user-name { display: none; }
  .row > * { min-width: 100%; }
  .row > .shrink { min-width: 0; }
  .card { padding: 14px; }
  .dup-row { grid-template-columns: 1fr 64px 1fr; }
  .dropzone-actions .btn { flex: 1 1 100%; }
}

/* ------------------------------------------------------------------ accesibilidad: movimiento reducido */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important; animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .spinner { animation: spin 1.6s linear infinite !important; }
}

/* Cambio de rol dentro de la lista de usuarios */
.role-select { min-height: 34px; padding: 4px 32px 4px 10px; font-size: 15px; width: auto; }
@media (pointer: coarse) { .role-select { min-height: var(--tap); } }
