*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:    #C8102E;
  --primary-dk: #9e0b24;
  --green:      #2E7D32;
  --green-bg:   #E8F5E9;
  --red-bg:     #FFEBEE;
  --yellow:     #E65100;
  --yellow-bg:  #FFF3E0;
  --gray-50:    #FAFAFA;
  --gray-100:   #F5F5F5;
  --gray-200:   #EEEEEE;
  --gray-400:   #BDBDBD;
  --gray-600:   #757575;
  --gray-800:   #424242;
  --text:       #212121;
  --white:      #FFFFFF;
  --sh-sm:  0 1px 3px rgba(0,0,0,0.12);
  --sh:     0 2px 8px rgba(0,0,0,0.12);
  --sh-lg:  0 4px 16px rgba(0,0,0,0.18);
  --r-sm: 8px;
  --r:    12px;
  --r-lg: 16px;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
  font-size: 16px;
  color: var(--text);
  background: var(--gray-100);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

/* ── SCREENS ──────────────────────────────────────────────────────────────── */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  background: var(--gray-100);
  overflow: hidden;
}
.screen.active { display: flex; }

/* ── LOGIN ────────────────────────────────────────────────────────────────── */
#screen-login {
  background: linear-gradient(160deg, #C8102E 60%, #9e0b24 100%);
  align-items: center;
  justify-content: center;
}
.login-box {
  width: 100%;
  max-width: 340px;
  padding: 32px 24px;
  display: flex;
  flex-direction: column;
  gap: 36px;
}
.login-logo { text-align: center; color: var(--white); }
.logo-img {
  width: 160px;
  height: auto;
  display: block;
  margin: 0 auto 16px;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.25));
}
.login-logo p  { font-size: 14px; opacity: .75; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-form input {
  padding: 14px 16px;
  border-radius: var(--r);
  border: none;
  font-size: 16px;
  background: rgba(255,255,255,0.18);
  color: white;
  outline: none;
  width: 100%;
}
.login-form input::placeholder { color: rgba(255,255,255,.65); }
.login-form input:focus { background: rgba(255,255,255,.28); }

/* ── BUTTONS ──────────────────────────────────────────────────────────────── */
.btn-primary {
  width: 100%;
  padding: 14px 24px;
  background: var(--white);
  color: var(--primary);
  border: none;
  border-radius: var(--r);
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .15s;
}
.btn-primary:active { opacity: .82; }
.btn-primary.red { background: var(--primary); color: var(--white); }

/* ── APP HEADER ───────────────────────────────────────────────────────────── */
.app-header {
  background: var(--primary);
  color: var(--white);
  padding: 0 12px;
  height: 52px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  box-shadow: var(--sh);
}
.header-title { font-size: 17px; font-weight: 700; flex: 1; text-align: center; }
.btn-back, .btn-icon {
  background: none;
  border: none;
  color: white;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  white-space: nowrap;
  transition: background .15s;
}
.btn-back:active, .btn-icon:active { background: rgba(255,255,255,.2); }

/* ── HOME ─────────────────────────────────────────────────────────────────── */
.home-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.btn-nueva {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--r-lg);
  padding: 22px 24px;
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--sh-lg);
  transition: opacity .15s;
  width: 100%;
}
.btn-nueva:active { opacity: .85; }
.btn-nueva-icon { font-size: 26px; line-height: 1; }

/* ── TABS ─────────────────────────────────────────────────────────────────── */
.home-tabs {
  display: flex;
  background: var(--gray-200);
  border-radius: var(--r);
  padding: 3px;
  gap: 3px;
}
.tab-btn {
  flex: 1;
  padding: 10px;
  border: none;
  border-radius: var(--r-sm);
  background: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-600);
  cursor: pointer;
  transition: all .15s;
}
.tab-btn.active { background: var(--white); color: var(--primary); box-shadow: var(--sh-sm); }
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ── HISTORIAL ────────────────────────────────────────────────────────────── */
.historial-list { display: flex; flex-direction: column; gap: 10px; }
.historial-item {
  background: var(--white);
  border-radius: var(--r);
  padding: 14px;
  box-shadow: var(--sh-sm);
  display: flex;
  align-items: center;
  gap: 12px;
}
.h-score {
  width: 50px;
  height: 50px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 800;
  flex-shrink: 0;
}
.sc-hi  { background: var(--green-bg);  color: var(--green);   }
.sc-mid { background: var(--yellow-bg); color: var(--yellow);  }
.sc-lo  { background: var(--red-bg);    color: var(--primary); }
.h-info { flex: 1; min-width: 0; }
.h-cliente {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.h-meta { font-size: 12px; color: var(--gray-600); margin-top: 3px; }
.badge-canal {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  background: var(--red-bg);
  color: var(--primary);
  margin-right: 4px;
}

/* ── CANAL SELECTOR ───────────────────────────────────────────────────────── */
.selector-content {
  flex: 1;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
}
.selector-title { font-size: 17px; font-weight: 600; color: var(--gray-800); }
.canal-grid { display: flex; flex-direction: column; gap: 12px; }
.canal-card {
  background: var(--white);
  border: 2px solid var(--gray-200);
  border-radius: var(--r-lg);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  text-align: left;
  transition: all .15s;
  box-shadow: var(--sh-sm);
  width: 100%;
}
.canal-card:active { border-color: var(--primary); background: var(--red-bg); }
.canal-icon  { font-size: 32px; }
.canal-label { font-size: 18px; font-weight: 700; flex: 1; }
.canal-count { font-size: 13px; color: var(--gray-600); }

/* ── CLIENTE SELECTOR ─────────────────────────────────────────────────────── */
.cliente-search-wrap {
  background: var(--white);
  padding: 10px 14px;
  border-bottom: 1px solid var(--gray-200);
  flex-shrink: 0;
}
.search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-200);
  border-radius: var(--r);
  font-size: 15px;
  outline: none;
  background: var(--gray-50);
}
.search-input:focus { border-color: var(--primary); background: white; }
.cliente-list { flex: 1; overflow-y: auto; background: var(--white); }
.cliente-item {
  padding: 16px 18px;
  border-bottom: 1px solid var(--gray-100);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 10px;
  transition: background .1s;
}
.cliente-item:active { background: var(--gray-100); }
.cliente-item::before { content: '👤'; font-size: 16px; }

/* ── FORM HEADER ──────────────────────────────────────────────────────────── */
.form-header {
  background: var(--primary);
  color: white;
  padding: 10px 14px 8px;
  flex-shrink: 0;
  box-shadow: var(--sh);
}
.form-header-top {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.form-header-info { flex: 1; min-width: 0; }
.form-canal-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  background: rgba(255,255,255,.2);
  border-radius: 20px;
  padding: 2px 8px;
  margin-bottom: 2px;
  letter-spacing: .3px;
}
.form-cliente-name {
  display: block;
  font-size: 15px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.progress-wrap { display: flex; align-items: center; gap: 10px; }
.progress-bar {
  flex: 1;
  height: 5px;
  background: rgba(255,255,255,.3);
  border-radius: 3px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: white;
  border-radius: 3px;
  transition: width .3s;
}
.progress-text { font-size: 12px; opacity: .85; white-space: nowrap; }

/* ── FORM BODY ────────────────────────────────────────────────────────────── */
.form-body { flex: 1; overflow-y: auto; padding-bottom: 80px; }
.form-seccion { padding: 14px 12px 0; }
.seccion-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: .6px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--primary);
  margin-bottom: 10px;
}
.req-card {
  background: var(--white);
  border-radius: var(--r);
  padding: 13px;
  margin-bottom: 9px;
  box-shadow: var(--sh-sm);
  border: 2px solid transparent;
  transition: border-color .2s;
}
.req-card.cumple   { border-color: var(--green);   }
.req-card.nocumple { border-color: var(--primary); }

.req-head { display: flex; align-items: flex-start; gap: 9px; margin-bottom: 11px; }
.req-num {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--gray-200);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 800;
  color: var(--gray-600);
  flex-shrink: 0;
  margin-top: 1px;
}
.req-texto { font-size: 14px; line-height: 1.45; font-weight: 500; }

.req-btns { display: flex; gap: 8px; }
.btn-c, .btn-nc {
  flex: 1;
  padding: 10px 6px;
  border-radius: var(--r-sm);
  border: 2px solid;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
  background: none;
}
.btn-c  { border-color: var(--green);   color: var(--green);   }
.btn-nc { border-color: var(--primary); color: var(--primary); }
.btn-c.sel  { background: var(--green);   color: white; }
.btn-nc.sel { background: var(--primary); color: white; }
.btn-c:active  { opacity: .8; }
.btn-nc:active { opacity: .8; }

.req-extras { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.req-comentario {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--gray-200);
  border-radius: var(--r-sm);
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 56px;
  outline: none;
  background: var(--gray-50);
}
.req-comentario:focus { border-color: var(--primary); background: white; }

.req-foto-row { display: flex; align-items: center; gap: 10px; }
.btn-foto {
  padding: 7px 13px;
  border: 1px dashed var(--gray-400);
  border-radius: var(--r-sm);
  background: none;
  color: var(--gray-600);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s;
}
.btn-foto.con-foto { border-color: var(--green); color: var(--green); background: var(--green-bg); border-style: solid; }
.foto-thumb {
  width: 46px;
  height: 46px;
  object-fit: cover;
  border-radius: 6px;
  cursor: pointer;
  display: none;
}
.foto-thumb.visible { display: block; }

/* ── FORM FOOTER ──────────────────────────────────────────────────────────── */
.form-footer {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  padding: 10px 14px;
  background: white;
  border-top: 1px solid var(--gray-200);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.08);
}
.btn-guardar { background: var(--primary); color: white; }
.btn-guardar:disabled { opacity: .5; }

/* ── RESULTADO ────────────────────────────────────────────────────────────── */
.resultado-body {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px 32px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}
.score-circle {
  width: 120px;
  height: 120px;
  border-radius: 50%;
  border: 5px solid var(--green);
  background: var(--green-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.score-circle.mid { border-color: var(--yellow); background: var(--yellow-bg); }
.score-circle.lo  { border-color: var(--primary); background: var(--red-bg);  }
.score-pct {
  font-size: 30px;
  font-weight: 900;
  color: var(--green);
}
.score-circle.mid .score-pct { color: var(--yellow);  }
.score-circle.lo  .score-pct { color: var(--primary); }

.res-info { text-align: center; }
.res-info h2 { font-size: 19px; font-weight: 700; }
.res-info p  { font-size: 13px; color: var(--gray-600); margin-top: 4px; }

.res-detalle { width: 100%; display: flex; flex-direction: column; gap: 8px; }
.res-sec-row {
  background: var(--white);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--sh-sm);
}
.res-sec-nombre { font-size: 13px; font-weight: 600; }
.res-sec-score  { font-size: 14px; font-weight: 800; }

/* ── DASHBOARD ────────────────────────────────────────────────────────────── */
.dash-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.stat-card {
  background: var(--white);
  border-radius: var(--r);
  padding: 14px 8px;
  text-align: center;
  box-shadow: var(--sh-sm);
}
.stat-val   { font-size: 24px; font-weight: 900; color: var(--primary); }
.stat-label { font-size: 11px; color: var(--gray-600); margin-top: 3px; }

.dash-bars {
  background: var(--white);
  border-radius: var(--r);
  padding: 14px;
  box-shadow: var(--sh-sm);
}
.dash-sec-title {
  font-size: 11px;
  font-weight: 800;
  color: var(--gray-600);
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 14px;
}
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.bar-label { font-size: 13px; font-weight: 600; width: 95px; flex-shrink: 0; }
.bar-track {
  flex: 1;
  height: 20px;
  background: var(--gray-200);
  border-radius: 10px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 7px;
  min-width: 32px;
  transition: width .5s;
}
.bar-pct { font-size: 11px; font-weight: 800; color: white; }

/* ── MODAL FOTO ───────────────────────────────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal.hidden { display: none; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.75); }
.modal-inner {
  position: relative;
  z-index: 1;
  max-width: 92vw;
  max-height: 82vh;
}
.modal-inner img {
  max-width: 100%;
  max-height: 82vh;
  border-radius: var(--r);
  object-fit: contain;
}
.modal-close {
  position: absolute;
  top: -10px; right: -10px;
  width: 32px; height: 32px;
  border-radius: 50%;
  background: white;
  border: none;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--sh);
}

/* ── TOAST ────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-800);
  color: white;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  z-index: 999;
  white-space: nowrap;
  box-shadow: var(--sh-lg);
  pointer-events: none;
}
.toast.hidden { display: none; }

/* ── MISC ─────────────────────────────────────────────────────────────────── */
.empty-msg {
  text-align: center;
  color: var(--gray-400);
  padding: 44px 20px;
  font-size: 15px;
}
.error-msg {
  color: rgba(255,255,255,.88);
  font-size: 14px;
  text-align: center;
}
.hidden { display: none !important; }

/* ── REVISIÓN — req pendiente ─────────────────────────────────────────────── */
.req-card.pendiente {
  border-left: 4px solid #E65100;
  background: #FFF8F5;
}
.req-card.pendiente .req-num { background: #FFE0B2; color: #E65100; }

/* ── HISTORIAL — badge revisión y cambios ─────────────────────────────────── */
.badge-revision {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
  background: #FFF3E0;
  color: #E65100;
  margin-right: 4px;
}
.historial-item { align-items: flex-start; }
.btn-rev {
  flex-shrink: 0;
  padding: 7px 11px;
  border: 1.5px solid var(--primary);
  border-radius: var(--r-sm);
  background: none;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 2px;
  white-space: nowrap;
  transition: all .15s;
}
.btn-rev:active { background: var(--red-bg); }
.h-cambios { font-size: 11px; margin-top: 4px; }
.ch-ok  { color: var(--green);   font-weight: 700; }
.ch-no  { color: var(--primary); font-weight: 700; }

/* ── RESULTADO — bloque cambios ───────────────────────────────────────────── */
.res-cambios { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.cambios-bloque {
  border-radius: var(--r);
  padding: 12px 14px;
  box-shadow: var(--sh-sm);
}
.cambios-bloque.verde { background: var(--green-bg); }
.cambios-bloque.rojo  { background: var(--red-bg);   }
.cambios-tit {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .4px;
  margin-bottom: 7px;
}
.cambios-bloque.verde .cambios-tit { color: var(--green);   }
.cambios-bloque.rojo  .cambios-tit { color: var(--primary); }
.cambios-item { font-size: 13px; line-height: 1.4; padding: 3px 0; color: var(--gray-800); }

/* ── MATRIZ — pantalla propia ─────────────────────────────────────────────── */
.mzoom-controls { display: flex; gap: 4px; }
.btn-mzoom {
  width: 32px; height: 32px;
  background: rgba(255,255,255,0.2);
  border: none; border-radius: 6px;
  color: white; font-size: 20px; font-weight: 700;
  cursor: pointer; line-height: 1;
}
.btn-mzoom:active { background: rgba(255,255,255,0.35); }
.msel-wrap {
  flex: 1; overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.mdata-wrap {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
#mdata-inner { display: inline-block; min-width: 100%; }

/* ── MATRIZ — selector de canal ───────────────────────────────────────────── */
.mcanal-hint {
  font-size: 14px;
  color: var(--gray-600);
  margin-bottom: 12px;
  margin-top: 4px;
}
.mcanal-btns { display: flex; flex-direction: column; gap: 9px; }
.btn-mcanal {
  width: 100%;
  padding: 14px 16px;
  background: var(--white);
  border: 2px solid var(--gray-200);
  border-radius: var(--r);
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  box-shadow: var(--sh-sm);
  transition: all .15s;
}
.btn-mcanal:active, .btn-mcanal.active {
  border-color: var(--primary);
  background: var(--red-bg);
  color: var(--primary);
}
.btn-mcanal-back {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  padding: 6px 0 10px;
  display: block;
}

/* ── MATRIZ — tabla ───────────────────────────────────────────────────────── */
.matriz-scroll { overflow: visible; }  /* legacy, no usado */
.matriz-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 11px;
  min-width: 900px;
  table-layout: auto;
}
.mth-req {
  text-align: left;
  background: var(--gray-100);
  font-weight: 700;
  padding: 6px 8px;
  position: sticky;
  left: 0;
  z-index: 2;
  min-width: 130px;
  max-width: 160px;
  border-bottom: 2px solid var(--gray-200);
}
.mth-cliente {
  text-align: center;
  background: var(--gray-100);
  padding: 4px 3px 6px;
  border-bottom: 2px solid var(--gray-200);
  min-width: 46px;
  max-width: 64px;
  vertical-align: bottom;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.3;
  word-break: break-word;
}
.mth-fecha {
  display: block;
  font-size: 9px;
  font-weight: 400;
  color: var(--gray-600);
  margin-top: 2px;
}
.mtr-section td {
  background: var(--gray-200);
  font-weight: 800;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--gray-600);
  padding: 4px 8px;
  position: sticky;
  left: 0;
  z-index: 1;
}
.mtd-req {
  background: var(--white);
  padding: 5px 8px;
  font-size: 11px;
  color: var(--gray-800);
  position: sticky;
  left: 0;
  z-index: 1;
  max-width: 160px;
  border-bottom: 1px solid var(--gray-100);
}
.mtd-ok, .mtd-no, .mtd-nd {
  text-align: center;
  padding: 5px 2px;
  font-size: 13px;
  font-weight: 800;
  border-bottom: 1px solid var(--gray-100);
  border-left: 1px solid var(--gray-100);
}
.mtd-ok { background: var(--green-bg);  color: var(--green);   }
.mtd-no { background: var(--red-bg);    color: var(--primary); }
.mtd-nd { background: var(--gray-50);   color: var(--gray-400); font-weight: 400; font-size: 11px; }

/* ── OFFLINE BANNER ───────────────────────────────────────────────────────── */
.offline-banner {
  background: var(--yellow);
  color: white;
  text-align: center;
  padding: 6px;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
