/* Centro de Mando — tema oscuro profesional, mobile-first */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
:root {
  --bg: #0b0f14;
  --bg2: #0f141b;
  --card: #151c26;
  --card2: #1a2230;
  --line: rgba(255, 255, 255, 0.09);
  --txt: #e9eef5;
  --mut: #9aa7b6;
  --dim: #6b7684;
  --amber: #f59e0b;
  --amber-dk: #b45309;
  --green: #22c55e;
  --red: #ef4444;
  --blue: #3b82f6;
  --violet: #a78bfa;
  --radius: 14px;
  --tap: 44px;
  --nav-h: 64px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  min-height: 100dvh;
}

#app {
  padding: 16px 16px calc(var(--nav-h) + 24px);
  max-width: 720px;
  margin: 0 auto;
}

/* ---------- encabezados ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 16px;
}
.topbar > div { min-width: 0; }
.topbar h1 { overflow-wrap: anywhere; }
.topbar h1 {
  font-size: 1.35rem;
  margin: 0;
  letter-spacing: -0.01em;
}
.topbar .sub { color: var(--mut); font-size: 0.9rem; margin: 2px 0 0; }
.back {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: var(--tap); min-height: var(--tap);
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--card); color: var(--txt);
  font-size: 1.25rem; text-decoration: none; cursor: pointer;
}

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}
.card h2, .card h3 { margin: 0 0 8px; font-size: 1.05rem; }
.card .row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.muted { color: var(--mut); }
.small { font-size: 0.85rem; }
.big-num { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; }

/* ---------- badges ---------- */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: 999px;
  font-size: 0.78rem; font-weight: 600; line-height: 1.4;
  border: 1px solid transparent; white-space: nowrap;
}
.b-green { background: rgba(34,197,94,.15); color: #4ade80; border-color: rgba(34,197,94,.35); }
.b-red   { background: rgba(239,68,68,.15);  color: #f87171; border-color: rgba(239,68,68,.35); }
.b-amber { background: rgba(245,158,11,.15); color: #fbbf24; border-color: rgba(245,158,11,.4); }
.b-blue  { background: rgba(59,130,246,.15); color: #60a5fa; border-color: rgba(59,130,246,.35); }
.b-violet{ background: rgba(167,139,250,.15);color: #c4b5fd; border-color: rgba(167,139,250,.35); }
.b-gray  { background: rgba(148,163,184,.12);color: #b6c0cc; border-color: rgba(148,163,184,.3); }

/* ---------- barras de progreso ---------- */
.bar {
  height: 10px; border-radius: 999px;
  background: rgba(255,255,255,.08);
  overflow: hidden; margin: 8px 0 4px;
}
.bar > i { display: block; height: 100%; border-radius: 999px; background: var(--amber); transition: width .3s; }
.bar.green > i { background: var(--green); }
.bar.red > i { background: var(--red); }
.bar.blue > i { background: var(--blue); }
.stackbar { display: flex; height: 12px; border-radius: 999px; overflow: hidden; background: rgba(255,255,255,.07); margin: 8px 0 4px; }
.stackbar > i { display: block; height: 100%; }
.tier-a { background: var(--blue); }
.tier-b { background: var(--amber); }
.tier-c { background: var(--violet); }

/* ---------- listas ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.lote-card {
  display: block; text-decoration: none; color: inherit;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px;
}
.lote-card:active { background: var(--card2); }
.lote-card .t { font-weight: 700; font-size: 1.05rem; }
.lote-card .meta { color: var(--mut); font-size: 0.88rem; margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- piezas ---------- */
.pieza {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin-bottom: 10px;
}
.pieza .ph { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 6px; }
.pieza .fname { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; color: var(--mut); word-break: break-all; }
.pieza .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.pieza .links { margin-top: 10px; display: flex; gap: 8px; flex-wrap: wrap; }
.chip-link {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap); padding: 6px 12px; border-radius: 999px;
  background: rgba(59,130,246,.12); border: 1px solid rgba(59,130,246,.35);
  color: #93c5fd; text-decoration: none; font-size: 0.85rem; font-weight: 600;
}
.nota { background: rgba(255,255,255,.04); border-left: 3px solid var(--amber); padding: 8px 10px; border-radius: 0 8px 8px 0; margin-top: 8px; font-size: 0.9rem; }

/* ---------- botones ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 10px 18px;
  border-radius: 12px; border: 1px solid var(--line);
  background: var(--card2); color: var(--txt);
  font-size: 1rem; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--amber); border-color: var(--amber); color: #1a1207; }
.btn.danger { background: rgba(239,68,68,.14); border-color: rgba(239,68,68,.5); color: #f87171; }
.btn.ok { background: rgba(34,197,94,.14); border-color: rgba(34,197,94,.5); color: #4ade80; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: var(--tap); padding: 6px 14px; font-size: 0.9rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }

/* ---------- formularios ---------- */
label { display: block; font-weight: 600; margin: 12px 0 6px; }
input[type="text"], input[type="password"], input[type="number"], input[type="url"], input[type="date"], textarea {
  width: 100%; min-height: var(--tap);
  background: var(--bg2); border: 1px solid var(--line); border-radius: 12px;
  color: var(--txt); font-size: 1rem; padding: 10px 14px;
}
textarea { min-height: 84px; resize: vertical; }
input:focus-visible, textarea:focus-visible, button:focus-visible, .btn:focus-visible, a:focus-visible, .switch:focus-visible {
  outline: 2px solid var(--amber); outline-offset: 2px;
}
.hint { color: var(--mut); font-size: 0.85rem; margin-top: 6px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; margin: 12px 0 16px; overflow-x: auto; }
.tab {
  flex: 1; min-height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  padding: 10px 14px; border-radius: 12px; white-space: nowrap;
  background: var(--card); border: 1px solid var(--line);
  color: var(--mut); font-weight: 600; text-decoration: none; font-size: 0.95rem;
}
.tab.active { background: rgba(245,158,11,.14); border-color: rgba(245,158,11,.5); color: var(--amber); }

/* ---------- breadcrumb / archivos ---------- */
.crumb { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-bottom: 10px; font-size: 0.92rem; }
.crumb a { color: var(--amber); text-decoration: none; padding: 12px 8px; }
.fila {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 4px; border-bottom: 1px solid var(--line);
  min-height: var(--tap); text-decoration: none; color: inherit; width: 100%;
  background: none; border-left: 0; border-right: 0; border-top: 0; text-align: left; font-size: 1rem;
}
button.fila { cursor: pointer; }
.fila .ico { font-size: 1.2rem; width: 28px; text-align: center; flex: none; }
.fila .grow { flex: 1; min-width: 0; }
.fila .nm { word-break: break-all; }
.fila .dt { color: var(--mut); font-size: 0.82rem; white-space: nowrap; }

/* ---------- modal ---------- */
#modal-root:empty { display: none; }
.modal-back {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.65);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 18px 18px 0 0; width: 100%; max-width: 560px;
  max-height: 88dvh; overflow-y: auto; padding: 20px 18px calc(20px + env(safe-area-inset-bottom));
}
.modal h2 { margin: 0 0 4px; font-size: 1.15rem; }
.modal .mrow { display: flex; gap: 10px; margin-top: 18px; }
.modal .mrow .btn { flex: 1; }
@media (min-width: 600px) {
  .modal-back { align-items: center; padding: 24px; }
  .modal { border-radius: 18px; }
}

/* ---------- toast ---------- */
#toast-root {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--nav-h) + 16px);
  z-index: 80; display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  background: #1f2937; border: 1px solid var(--line); border-left: 4px solid var(--amber);
  color: var(--txt); border-radius: 12px; padding: 12px 14px; font-size: 0.95rem;
  box-shadow: 0 8px 24px rgba(0,0,0,.5); animation: tin .25s ease-out;
}
.toast.err { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
@keyframes tin { from { transform: translateY(8px); opacity: 0; } }

/* ---------- bottom nav ---------- */
#bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  display: flex; background: rgba(15,20,27,.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
#bottomnav[hidden] { display: none; }
#bottomnav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px;
  min-height: var(--nav-h); justify-content: center;
  color: var(--mut); text-decoration: none; font-size: 0.72rem; font-weight: 600;
}
#bottomnav a.active { color: var(--amber); }
#bottomnav .nav-ico { font-size: 1.35rem; line-height: 1; }

/* ---------- switch ---------- */
.switch {
  position: relative; width: 64px; height: 36px; flex: none;
  border-radius: 999px; border: 1px solid var(--line);
  background: rgba(255,255,255,.1); cursor: pointer; padding: 0;
}
.switch::after {
  content: ""; position: absolute; top: 3px; left: 4px;
  width: 28px; height: 28px; border-radius: 50%;
  background: #94a3b8; transition: left .2s, background .2s;
}
.switch[aria-checked="true"] { background: rgba(245,158,11,.35); border-color: var(--amber); }
.switch[aria-checked="true"]::after { left: 30px; background: var(--amber); }
.switch:disabled { opacity: .5; cursor: wait; }

/* ---------- login ---------- */
.login-wrap { max-width: 420px; margin: 12dvh auto 0; }
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo img { width: 88px; height: 88px; border-radius: 22px; }

/* ---------- tabla ---------- */
table.data { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data th, table.data td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { color: var(--mut); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: .04em; }
.tbl-scroll { overflow-x: auto; margin: 0 -16px; padding: 0 16px; }

/* ---------- varios ---------- */
.center { text-align: center; }
.empty {
  text-align: center; color: var(--mut); padding: 36px 20px;
  background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius);
}
.empty .big { font-size: 2.2rem; margin-bottom: 8px; }
.spinner { text-align: center; padding: 48px 0; color: var(--mut); }
.spin { display: inline-block; width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--amber); border-radius: 50%; animation: sp 0.8s linear infinite; vertical-align: middle; }
@keyframes sp { to { transform: rotate(360deg); } }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 12px; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; font-size: 0.93rem; }
.kv .k { color: var(--mut); }
.alert { border-radius: 12px; padding: 12px 14px; margin: 12px 0; font-size: 0.92rem; }
.alert.warn { background: rgba(245,158,11,.12); border: 1px solid rgba(245,158,11,.45); color: #fcd34d; }
.alert.crit { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.5); color: #fca5a5; }

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  #app { max-width: 1200px; padding: 28px 32px 48px 232px; margin: 0 auto; }
  #bottomnav {
    top: 0; bottom: 0; right: auto; width: 200px;
    flex-direction: column; justify-content: flex-start;
    border-top: 0; border-right: 1px solid var(--line);
    padding: 24px 12px; gap: 4px;
  }
  #bottomnav a {
    flex: none; flex-direction: row; gap: 12px; justify-content: flex-start;
    min-height: var(--tap); padding: 10px 14px; border-radius: 12px; font-size: 0.95rem;
  }
  #bottomnav a.active { background: rgba(245,158,11,.12); }
  #bottomnav .nav-ico { font-size: 1.2rem; }
  #toast-root { left: auto; right: 24px; bottom: 24px; width: 360px; }
  .grid2 { grid-template-columns: 1fr 1fr; }
  .cards3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
  .cards3 .card, .cards3 .lote-card { margin-bottom: 0; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ---------- Fase 1b ---------- */
[hidden] { display: none !important; }

/* tooltips ⓘ: área táctil 44px, glifo ~18px, nunca hover */
.tipbtn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px; padding: 0; margin: -8px -6px;
  border: 0; background: none; color: var(--dim);
  font-size: 18px; line-height: 1; cursor: pointer; vertical-align: middle;
}
.tipbtn:active { color: var(--amber); }
h1 .tipbtn, h2 .tipbtn, h3 .tipbtn { font-size: 18px; }

/* título de caso: máx 2 líneas con ellipsis */
.vtitle {
  font-weight: 700; font-size: 1.05rem; line-height: 1.35;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; overflow-wrap: anywhere;
}
.vlinea { color: var(--mut); font-size: 0.92rem; margin: 4px 0 0; }

/* agarradera del bottom sheet (arrastrar para cerrar) */
.grip {
  width: 44px; height: 5px; border-radius: 99px;
  background: rgba(255,255,255,.18); margin: 0 auto 12px;
  touch-action: none; cursor: grab;
}
.modal.sheet-video { max-height: 92dvh; }
.sheet-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 1.1rem; }
.xbtn { flex: none; }

/* reproductor */
.vwrap { position: relative; border-radius: 12px; overflow: hidden; background: #000; }
.vwrap video { display: block; width: 100%; aspect-ratio: 16/9; background: #000; }
.vload {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  gap: 8px; align-items: center; justify-content: center;
  color: var(--mut); background: #000;
}
.verr { padding: 28px 20px; text-align: center; }
.verr .btn { margin-top: 10px; }

/* miniaturas 16:9 */
.thumbbtn { padding: 0; border: 0; background: none; cursor: pointer; display: block; width: 100%; text-align: left; }
.thumb {
  position: relative; display: block; width: 100%; aspect-ratio: 16/9;
  border-radius: 10px; overflow: hidden;
  background: #0a0e13; border: 1px solid var(--line);
}
.thumb img.thumb-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .play {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%,-50%);
  width: 52px; height: 52px; border-radius: 50%;
  background: rgba(0,0,0,.55); border: 1.5px solid rgba(255,255,255,.85);
  color: #fff; font-size: 19px;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
.thumb-fallback {
  width: 100%; height: 100%; display: flex; align-items: center; justify-content: center;
  font-size: 2rem; background: #0a0e13;
}

/* timeline del plan */
.seccion { margin: 22px 0 6px; font-size: 1.15rem; }
.seccion:first-of-type { margin-top: 6px; }
.pgroup { margin: 14px 0 4px; }
.pgroup > h3 { margin: 0 0 8px; font-size: 1rem; color: var(--mut); font-weight: 700; }
.tl { margin: 4px 0 0 6px; padding: 0 0 0 18px; border-left: 2px solid var(--line); }
.tl-item { position: relative; padding-bottom: 12px; }
.tl-item:last-child { padding-bottom: 2px; }
.tl-dot {
  position: absolute; left: -25px; top: 20px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--amber); box-shadow: 0 0 0 2px var(--amber);
}
.tl-dot.info { background: var(--blue); box-shadow: 0 0 0 2px var(--blue); }
.tl-dot.done { background: var(--green); box-shadow: 0 0 0 2px var(--green); }
.tl-empty-ok { color: #4ade80; padding: 4px 0 10px; font-size: 0.95rem; }
.plan-item {
  display: flex; gap: 12px; align-items: center;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px;
}
.plan-item .thumbbtn { flex: 0 0 132px; width: 132px; }
.plan-item .grow { flex: 1; min-width: 0; }
.plan-item .cta { flex: none; }
.bar.thin { height: 6px; margin: 6px 0 2px; }

/* filas de resultados */
.res-row {
  display: flex; gap: 12px; align-items: flex-start;
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px; margin-bottom: 10px;
}
.res-row .thumbbtn { flex: 0 0 132px; width: 132px; }
.res-info { flex: 1; min-width: 0; }

/* franja de conservación en el detalle */
.cons {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 14px; font-size: 0.92rem; color: var(--mut); margin: 0 0 4px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}

/* toast con acción (Deshacer) */
.toast { display: flex; align-items: center; gap: 12px; justify-content: space-between; pointer-events: auto; }
.toast-act {
  flex: none; min-height: 44px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--amber); background: transparent;
  color: var(--amber); font-weight: 700; font-size: 0.95rem; cursor: pointer;
}

@media (min-width: 900px) {
  .modal.sheet-video { max-width: 720px; }
  .plan-item .thumbbtn, .res-row .thumbbtn { flex-basis: 180px; width: 180px; }
}
