/* ===== shell ===== */
.sidebar { position: fixed; left: calc(16px + env(safe-area-inset-left)); top: calc(16px + env(safe-area-inset-top)); z-index: 20; width: 224px; height: calc(100dvh - 32px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); background: var(--sidebar); border: 1px solid var(--sidebar-border); border-radius: var(--r-card); box-shadow: var(--shadow-sidebar); display: flex; flex-direction: column; }
.side-head { height: 85px; flex: none; padding: 0 22px; border-bottom: 1px solid var(--sep); display: flex; align-items: center; gap: 8px; font-weight: 600; color: var(--nav); }
.logo { width: 32px; height: 32px; border-radius: 50%; background: #010617; flex: none; display: block; object-fit: cover; }
.nav { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 12px; display: flex; flex-direction: column; gap: 4px; }
.nav-item { height: 40px; flex: none; border-radius: var(--r-nav); padding: 0 12px; display: flex; align-items: center; gap: 12px; color: var(--nav); font-weight: 500; }
.nav-item:hover { background: var(--hover); color: var(--nav-active); }
.nav-item.active { background: var(--card); color: var(--nav-active); }
.nav-badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--primary); color: var(--on-primary); font-size: 12px; line-height: 20px; text-align: center; font-weight: 500; }
.nav-dot { margin-left: auto; width: 8px; height: 8px; border-radius: 50%; background: var(--primary); }
.side-foot { flex: none; padding: 16px 12px; border-top: 1px solid var(--sep); }
.main { margin-left: calc(248px + env(safe-area-inset-left)); min-height: 100dvh; }
.page { padding: 48px 40px 96px; }
.page-dashboard { padding: 80px 80px 96px; }
.page-plantillas { padding: 56px 40px 96px; }
.page-narrow { max-width: 720px; margin: 0 auto; padding: 32px 16px 96px; }

.bottom-bar { display: none; }

/* ===== encabezado de página ===== */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; }
.h1 { font-size: 36px; line-height: 40px; font-weight: 700; letter-spacing: -0.025em; color: var(--fg); margin: 0; }
.h1-sm { font-size: 30px; line-height: 36px; }
.sub { font-size: 14px; line-height: 20px; color: var(--muted); font-weight: 400; }
.h1 + .sub { margin-top: 4px; }
.h1-sm + .sub { margin-top: 0; }
.head-actions { display: flex; gap: 8px; flex: none; }
.head-stack { display: flex; flex-direction: column; gap: 8px; flex: none; }

/* ===== botones ===== */
.btn { height: 48px; flex: none; border-radius: var(--r-pill); background: var(--primary-fill); color: var(--on-primary); font-size: 14px; line-height: 20px; font-weight: 500; display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 0 24px; box-shadow: var(--shadow-button); cursor: pointer; white-space: nowrap; }
.btn-44 { height: 44px; }
.btn-wide-gap { gap: 16px; }
.btn-240 { width: 240px; padding: 0; }
.btn-outline { background: transparent; color: var(--fg); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--hover); }
.btn-ghost { background: transparent; color: var(--muted); box-shadow: none; }
.btn-ghost:hover { color: var(--fg); }
.btn-danger { background: transparent; color: var(--red); border: 1px solid var(--border); }
.btn[disabled], .btn.is-disabled { opacity: .5; cursor: default; pointer-events: none; }
.btn-block { width: 100%; }
.btn-sm { height: 36px; padding: 0 16px; }
.icon-btn { width: 36px; height: 36px; flex: none; border-radius: var(--r-pill); display: inline-flex; align-items: center; justify-content: center; color: var(--muted); }
.icon-btn:hover { background: var(--hover); color: var(--fg); }

/* ===== pestañas y píldoras ===== */
.tabs { display: inline-flex; height: 46px; padding: 4px; gap: 4px; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-pill); }
.tab { height: 36px; padding: 0 24px; border-radius: var(--r-pill); display: flex; align-items: center; color: var(--muted); font-weight: 500; cursor: pointer; }
.tab.on { background: var(--bg); color: var(--primary); }
.pills { display: flex; flex-wrap: wrap; gap: 8px; }
.pill { height: 40px; padding: 0 20px; border-radius: var(--r-pill); display: inline-flex; align-items: center; gap: 6px; font-weight: 500; background: var(--card); color: var(--fg); cursor: pointer; white-space: nowrap; }
.pill.on { background: var(--primary); color: var(--on-primary); }
.pill .chev { opacity: .7; }
.pill-count { opacity: .7; }

/* ===== tarjetas y estados vacíos ===== */
.card { background: var(--card); border-radius: var(--r-card); }
.card-pad { padding: 16px; }
.card-title { font-size: 12px; line-height: 16px; color: var(--muted); }
.placeholder { font-size: 12px; line-height: 16px; color: var(--muted); opacity: .7; }
.empty { color: var(--muted); font-size: 16px; line-height: 24px; text-align: center; }
.empty-block { display: flex; flex-direction: column; align-items: center; gap: 16px; color: var(--muted); text-align: center; }
.dash { height: 400px; border: 2px dashed var(--dash); background: var(--sidebar); border-radius: var(--r-card); display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); text-align: center; padding: 16px; }
.dash-title { margin-top: 12px; font-size: 18px; line-height: 28px; font-weight: 500; }

/* ===== medidor ===== */
.meter { width: 320px; max-width: 100%; }
.meter-top { display: flex; justify-content: space-between; align-items: center; height: 20px; }
.meter-label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.meter-label .icon { color: var(--muted); }
.meter-value { color: var(--muted); }
.meter-track { height: 8px; background: var(--meter); border-radius: var(--r-pill); margin-top: 8px; overflow: hidden; }
.meter-fill { height: 100%; width: calc(var(--p, 0) * 1%); background: var(--primary); border-radius: var(--r-pill); }
.meter-fill.warn { background: var(--amber); }
.meter-fill.over { background: var(--red); }
.meter-bottom { display: flex; justify-content: space-between; font-size: 12px; line-height: 16px; color: var(--muted); margin-top: 8px; }

/* ===== estado ===== */
.st { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: var(--r-pill); font-size: 12px; line-height: 16px; font-weight: 500; white-space: nowrap; }
.st-falta { color: var(--amber); background: rgba(232, 184, 74, .14); }
.st-corregir, .st-vencida, .st-rechazado { color: var(--red); background: rgba(240, 120, 127, .14); }
.st-en_revision, .st-por_revisar { color: var(--sent); background: rgba(157, 155, 240, .14); }
.st-aprobada, .st-aprobado, .st-completada { color: var(--green); background: rgba(76, 195, 138, .14); }
.st-cancelada, .st-programada, .st-neutro { color: var(--muted); background: rgba(138, 144, 157, .14); }

/* ===== formularios ===== */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: 16px; }
.label { font-size: 12px; line-height: 16px; color: var(--muted); }
.input, .select, .textarea { width: 100%; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-nav); padding: 0 12px; height: 44px; color: var(--fg); font-size: 14px; }
.textarea { height: auto; min-height: 96px; padding: 10px 12px; line-height: 20px; resize: vertical; }
.input:focus-visible, .select:focus-visible, .textarea:focus-visible { outline: 2px solid var(--primary); outline-offset: 0; }
.hint { font-size: 12px; line-height: 16px; color: var(--muted); }
.err { font-size: 14px; line-height: 20px; color: var(--red); }
.input-wrap { position: relative; }
.input-wrap .input { padding-right: 44px; }
.input-wrap .icon-btn { position: absolute; right: 4px; top: 4px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { height: 36px; padding: 0 14px; border-radius: var(--r-pill); background: var(--card); color: var(--fg); display: inline-flex; align-items: center; cursor: pointer; font-weight: 500; }
.chip.on { background: var(--primary); color: var(--on-primary); }

/* ===== modal, toast, cargando, error ===== */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { width: 100%; max-width: 560px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--sidebar); border: 1px solid var(--sidebar-border); border-radius: var(--r-card); box-shadow: var(--shadow-sidebar); }
.modal-lg { max-width: 960px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 20px 24px; border-bottom: 1px solid var(--sep); font-size: 18px; line-height: 28px; font-weight: 500; }
.modal-body { padding: 24px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; padding: 16px 24px; border-top: 1px solid var(--sep); }
/* Un toast nunca se come un toque: lo de abajo sigue andando. Solo su botón recibe clics. */
.toasts { position: fixed; z-index: 60; right: calc(24px + env(safe-area-inset-right)); bottom: calc(24px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 8px; align-items: flex-end; pointer-events: none; }
.toast { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 8px 16px; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-nav); box-shadow: var(--shadow-sidebar); }
.toast-error { border-color: var(--red); }
.toast-action { color: var(--nav-active); font-weight: 500; cursor: pointer; pointer-events: auto; }
.page-msg { padding: 48px 16px; text-align: center; color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 16px; }

/* ===== bandeja de subidas ===== */
.tray { position: fixed; z-index: 40; right: calc(24px + env(safe-area-inset-right)); bottom: calc(24px + env(safe-area-inset-bottom)); width: 360px; background: var(--sidebar); border: 1px solid var(--sidebar-border); border-radius: var(--r-card); box-shadow: var(--shadow-sidebar); padding: 12px 16px; max-height: calc(100dvh - 176px); overflow-y: auto; }
body:has(.tray:not([hidden])) .page-narrow { padding-bottom: max(calc(240px + env(safe-area-inset-bottom)), var(--tray-h, 0px)); }
.tray-line { font-weight: 500; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.tray-note { font-size: 12px; line-height: 16px; color: var(--muted); margin-top: 8px; }
.tray-row { display: flex; align-items: center; gap: 8px; padding: 8px 0; border-top: 1px solid var(--sep); }
.tray-thumb { width: 40px; height: 40px; flex: none; border-radius: 8px; background: var(--card); object-fit: cover; display: flex; align-items: center; justify-content: center; color: var(--muted); }
.tray-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ===== lectura de guías: la usan la modelo y la agencia ===== */
.m-hello { font-size: 28px; line-height: 34px; font-weight: 700; letter-spacing: -0.025em; }
.guide-body { font-size: 16px; line-height: 24px; margin-top: 16px; }
.guide-media { margin-top: 16px; }
.guide-media video, .guide-media img { display: block; width: 100%; border-radius: var(--r-nav); background: #000; }

/* ===== instalar como app ===== */
.install-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 36px; }
.install-title { font-weight: 600; }
.install-text { margin-top: 4px; color: var(--nav); }
.install-steps { margin: 8px 0 0; padding-left: 24px; color: var(--nav); }
.install-steps li + li { margin-top: 4px; }
.install-btn { margin-top: 12px; }

/* ===== visor ===== */
.viewer-media { display: block; width: 100%; max-height: calc(100dvh - 240px); object-fit: contain; background: #000; border-radius: var(--r-nav); }
.viewer-fallback { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 48px 16px; color: var(--muted); text-align: center; }

/* ===== texto de guías e instrucciones ===== */
.txt-p { margin: 0 0 8px; }
.txt-h { margin: 16px 0 8px; font-size: 18px; line-height: 28px; font-weight: 500; }
.txt-list { list-style: disc; padding-left: 20px; margin: 0 0 8px; }
.txt-p a, .txt-list a { color: var(--nav-active); text-decoration: underline; word-break: break-all; }

/* ===== teléfono ===== */
@media (max-width: 899.98px) {
  .sidebar { display: none; }
  .main { margin-left: 0; }
  .page, .page-dashboard, .page-plantillas, .page-narrow { padding: calc(16px + env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) calc(96px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); max-width: none; }
  .page-head { flex-direction: column; gap: 16px; }
  .head-actions, .head-stack { width: 100%; flex-direction: column; }
  .h1, .h1-sm { font-size: 28px; line-height: 34px; }
  .btn { width: 100%; }
  .btn.btn-sm { width: auto; }
  .tabs { max-width: 100%; overflow-x: auto; }
  .tab { padding: 0 16px; flex: none; }
  .meter { width: 100%; }
  .dash { height: 280px; }
  .input, .select, .textarea { font-size: 16px; height: 48px; } /* menos de 16 px hace que iOS haga zoom */
  .textarea { height: auto; }
  .bottom-bar { display: flex; position: fixed; z-index: 30; left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); bottom: calc(8px + env(safe-area-inset-bottom)); height: 64px; background: var(--sidebar); border: 1px solid var(--sidebar-border); border-radius: var(--r-card); box-shadow: var(--shadow-sidebar); }
  .bb-item { position: relative; flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; color: var(--nav); font-size: 11px; line-height: 14px; font-weight: 500; }
  .bb-item.active { color: var(--nav-active); }
  .bb-item .nav-dot { position: absolute; top: 10px; left: calc(50% + 8px); margin: 0; }
  .bb-badge { position: absolute; top: 6px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: var(--r-pill); background: var(--primary); color: var(--on-primary); font-size: 10px; line-height: 16px; text-align: center; }
  .modal-back { padding: 0; align-items: stretch; }
  .modal, .modal-lg { max-width: none; max-height: none; height: 100dvh; border-radius: 0; border: 0; }
  .modal-head { padding: calc(20px + env(safe-area-inset-top)) max(24px, env(safe-area-inset-right)) 20px max(24px, env(safe-area-inset-left)); }
  .modal-body { flex: 1; padding-left: max(24px, env(safe-area-inset-left)); padding-right: max(24px, env(safe-area-inset-right)); }
  .modal-body:last-child { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .modal-foot { padding: 16px max(24px, env(safe-area-inset-right)) calc(16px + env(safe-area-inset-bottom)) max(24px, env(safe-area-inset-left)); }
  .modal-foot .btn { flex: 1; }
  .toasts { left: 16px; right: 16px; bottom: calc(88px + env(safe-area-inset-bottom)); align-items: stretch; }
  /* Sobre los botones de un modal a pantalla completa, el toast va arriba para no taparlos. */
  body:has(.modal-back) .toasts { top: calc(8px + env(safe-area-inset-top)); bottom: auto; }
  body:has(.tray:not([hidden])) .page, body:has(.tray:not([hidden])) .page-dashboard, body:has(.tray:not([hidden])) .page-plantillas { padding-bottom: max(calc(96px + env(safe-area-inset-bottom)), var(--tray-h, 0px)); }
  .tray { left: max(8px, env(safe-area-inset-left)); right: max(8px, env(safe-area-inset-right)); bottom: calc(80px + env(safe-area-inset-bottom)); width: auto; }
}

/* ===== utilidades ===== */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.more-list { display: flex; flex-direction: column; gap: 4px; }
.more { display: flex; justify-content: center; margin-top: 16px; }

/* ===== píldora con selector nativo: "Filtrar por tipo", "Modelo". Nativo a propósito: en el teléfono abre el selector del sistema ===== */
.pill-select { position: relative; padding: 0; }
.pill-select select { appearance: none; -webkit-appearance: none; background: transparent; border: 0; height: 40px; padding: 0 42px 0 20px; color: inherit; font-weight: 500; cursor: pointer; border-radius: var(--r-pill); max-width: 240px; }
.pill-select .chev { position: absolute; right: 20px; top: 12px; pointer-events: none; }
