:root {
  color-scheme: light;
  --surface-max: 1560px;
  --touch-target: 44px;
  --focus-ring: 0 0 0 3px rgba(217, 0, 0, 0.2);
}

html {
  text-size-adjust: 100%;
  -webkit-text-size-adjust: 100%;
}

body[data-surface] {
  min-width: 280px;
  background:
    radial-gradient(circle at 15% -10%, rgba(217, 0, 0, 0.05), transparent 30rem),
    #f3f4f6;
}

body[data-surface] .topnav,
body[data-surface] .diag {
  display: none !important;
}

body[data-surface] .header {
  min-height: 76px;
  padding: 12px max(18px, env(safe-area-inset-right)) 12px max(18px, env(safe-area-inset-left));
  box-shadow: 0 1px 0 rgba(31, 36, 43, 0.06);
}

body[data-surface] .brand img {
  width: 150px;
  height: 44px;
  object-fit: contain;
  object-position: center;
  border: 0;
  padding: 0;
  border-radius: 0;
}

body[data-surface] .login-brand img {
  object-fit: contain;
  object-position: center;
}

body[data-surface] .brand h1 {
  font-size: clamp(16px, 1.7vw, 22px);
  letter-spacing: -0.02em;
}

body[data-surface] .brand p {
  margin-top: 4px;
  font-size: 11px;
}

body[data-surface] .badges {
  align-items: center;
}

body[data-surface] .badges .badge:first-child,
body[data-surface] .badges .badge:nth-child(2) {
  display: none;
}

body[data-surface="erp"] #sessionBadge {
  display: none;
}

body[data-surface] .view {
  width: 100%;
  max-width: var(--surface-max);
  margin: 0 auto;
  padding: 18px;
}

body[data-surface] .integrated,
body[data-surface] .integrated.erp-only,
body[data-surface] .integrated.app-only {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  min-height: calc(100dvh - 112px);
}

body[data-surface="erp"] .app-pane,
body[data-surface="worker"] .erp-pane {
  display: none !important;
}

body[data-surface] .pane {
  border-radius: 18px;
  border-color: #e1e4e8;
  box-shadow: 0 14px 45px rgba(31, 36, 43, 0.06);
}

body[data-surface] .pane-head {
  min-height: 52px;
  padding: 12px 16px;
  background: linear-gradient(180deg, #fff, #fbfbfc);
}

body[data-surface] .erp-pane .pane-body,
body[data-surface] .app-pane .pane-body {
  height: auto;
  min-height: calc(100dvh - 190px);
  overflow: visible;
  padding: 14px;
}

body[data-surface="worker"] .integrated {
  max-width: 920px;
  margin: 0 auto;
}

body[data-surface="worker"] .app-shell {
  width: 100%;
  max-width: 820px;
}

.login-card {
  width: min(440px, 100%);
  margin: clamp(20px, 7vh, 78px) auto;
  padding: clamp(20px, 4vw, 30px);
  border: 0;
  box-shadow: 0 22px 60px rgba(31, 36, 43, 0.11);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
}

.login-brand img {
  width: 150px;
  height: 44px;
  object-fit: contain;
  object-position: center;
}

.login-brand span,
.session-eyebrow {
  display: block;
  color: #8a9099;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.login-brand h2 {
  margin: 2px 0 0;
  font-size: 24px;
}

.login-message {
  min-height: 20px;
  margin-top: 10px;
  color: #a00000;
  font-size: 12px;
  font-weight: 700;
}

.login-help {
  margin-top: 8px;
  padding-top: 10px;
  border-top: 1px solid #eceef1;
}

/* Portada de app.nexuz.cl: los accesos NEXUZ y externo permanecen separados. */
.app-login.worker-entry-hub {
  width: 100%;
  max-width: 820px;
  margin: clamp(18px, 4vh, 46px) auto;
}

.worker-entry-heading {
  max-width: 650px;
  margin: 0 auto 20px;
  text-align: center;
}

.worker-entry-heading > span,
.worker-entry-type {
  color: #a00000;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.worker-entry-heading h2 {
  margin: 4px 0 6px;
  color: #252525;
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.15;
}

.worker-entry-heading p {
  margin: 0;
  color: #656b74;
  font-size: 14px;
}

.worker-entry-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  align-items: stretch;
}

.worker-entry-card.card {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 440px;
  margin: 0;
  padding: clamp(20px, 3vw, 28px);
  border: 1px solid #dfe2e6;
  border-top: 4px solid #d90000;
  border-radius: 16px;
  box-shadow: 0 16px 42px rgba(31, 36, 43, 0.09);
}

.worker-entry-card-external.card {
  border-top-color: #343434;
  background: linear-gradient(180deg, #fff 0%, #fafafa 100%);
}

.worker-entry-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.worker-entry-icon {
  display: grid;
  flex: 0 0 42px;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 12px;
  background: #d90000;
  color: #fff;
  font-size: 19px;
  font-weight: 900;
}

.worker-entry-icon.external {
  background: #343434;
}

.worker-entry-card h3 {
  margin: 0 0 7px;
  color: #252525;
  font-size: 20px;
  line-height: 1.25;
}

.worker-entry-description {
  min-height: 48px;
  margin: 0 0 12px;
  color: #656b74;
  font-size: 13px;
  line-height: 1.5;
}

.worker-entry-points {
  display: grid;
  gap: 10px;
  margin: 10px 0 20px;
}

.worker-entry-points span {
  display: flex;
  align-items: center;
  gap: 9px;
  color: #444a52;
  font-size: 12px;
  font-weight: 700;
}

.worker-entry-points span::before {
  content: "";
  flex: 0 0 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d90000;
}

.worker-entry-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: var(--touch-target);
  margin-top: auto;
  padding: 12px 14px;
  border: 1px solid #343434;
  border-radius: 9px;
  background: #343434;
  color: #fff;
  font-size: 13px;
  font-weight: 900;
  text-decoration: none;
  touch-action: manipulation;
}

.worker-entry-link:hover {
  border-color: #d90000;
  background: #d90000;
}

.worker-entry-help {
  margin: 11px 0 0;
  padding-top: 11px;
  border-top: 1px solid #e1e4e8;
  color: #656b74;
  font-size: 11px;
  line-height: 1.45;
}

.session-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  padding: 8px 10px;
  border: 1px solid #e4e7eb;
  border-radius: 10px;
  background: #fafbfc;
}

button,
.btn,
input,
select,
textarea {
  max-width: 100%;
}

button:focus-visible,
.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible {
  outline: 2px solid #d90000;
  outline-offset: 2px;
  box-shadow: var(--focus-ring);
}

.btn,
.erp-nav button,
.app-nav button {
  min-height: var(--touch-target);
  touch-action: manipulation;
}

.field input,
.field select,
.field textarea {
  min-height: var(--touch-target);
}

.scroll {
  max-width: 100%;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

.scroll table {
  min-width: 720px;
}

.erp-nav,
.app-nav,
.doc-sidebar {
  scrollbar-width: thin;
  -webkit-overflow-scrolling: touch;
}

.erp-nav button,
.app-nav button,
.doc-folder-btn {
  scroll-snap-align: start;
}

.sign-placement,
.signature-pad {
  touch-action: none;
}

.modal-box {
  max-height: calc(100dvh - 24px);
}

.modal-body {
  overscroll-behavior: contain;
}

@media (max-width: 900px) {
  body[data-surface] .view {
    padding: 12px;
  }

  body[data-surface] .erp-nav,
  body[data-surface] .app-nav {
    scroll-snap-type: x proximity;
  }

  .doc-workspace {
    display: block !important;
  }

  .doc-sidebar {
    display: flex !important;
    gap: 6px;
    width: 100% !important;
    margin-bottom: 10px;
    overflow-x: auto;
    border-right: 0 !important;
    padding: 4px 0 9px !important;
  }

  .doc-sidebar-title {
    display: none;
  }

  .doc-folder-btn {
    flex: 0 0 auto;
    min-height: var(--touch-target);
    white-space: nowrap;
  }

  .doc-main {
    min-width: 0;
  }

  .doc-toolbar,
  .filterbar {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: end;
  }

  .doc-toolbar .field,
  .filterbar .field,
  .filterbar .field.searchwide {
    min-width: 0 !important;
  }

  .worker-doc-control .scroll table {
    min-width: 1180px;
  }

  .google-map-shell,
  .no-key-map,
  .fast-map-shell {
    height: min(420px, 58dvh) !important;
    min-height: 300px;
  }
}

@media (max-width: 640px) {
  :root {
    --touch-target: 46px;
  }

  body[data-surface] .header {
    position: sticky;
    top: 0;
    min-height: 66px;
    padding-top: max(9px, env(safe-area-inset-top));
    z-index: 1000;
  }

  body[data-surface] .brand {
    gap: 8px;
  }

  body[data-surface] .brand img {
    width: 122px;
    height: 35px;
  }

  body[data-surface] .brand h1 {
    font-size: 14px;
  }

  body[data-surface] .brand p,
  body[data-surface] .badges {
    display: none;
  }

  body[data-surface] .view {
    padding: 0;
  }

  body[data-surface] .pane {
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  body[data-surface] .pane-head {
    min-height: 46px;
    padding: 9px 12px;
  }

  body[data-surface] .erp-pane .pane-body,
  body[data-surface] .app-pane .pane-body {
    min-height: calc(100dvh - 112px);
    padding: 10px;
  }

  .login-card {
    margin: 18px auto;
    padding: 20px;
  }

  .app-login.worker-entry-hub {
    margin: 14px auto 22px;
  }

  .worker-entry-heading {
    margin-bottom: 14px;
    padding: 0 6px;
  }

  .worker-entry-heading p {
    font-size: 13px;
  }

  .worker-entry-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .worker-entry-card.card {
    min-height: 0;
    padding: 20px;
  }

  .worker-entry-description {
    min-height: 0;
  }

  .login-brand img {
    width: 132px;
    height: 38px;
  }

  .login-brand h2 {
    font-size: 21px;
  }

  input,
  select,
  textarea,
  .field input,
  .field select,
  .field textarea {
    font-size: 16px;
  }

  .erp-nav,
  .app-nav {
    position: sticky;
    top: 65px;
    z-index: 45;
    margin: -2px -10px 10px;
    padding: 8px 10px;
    overflow-x: auto;
    background: rgba(255, 255, 255, 0.97);
    border-bottom: 1px solid #e4e7eb;
    backdrop-filter: blur(12px);
  }

  .erp-nav button,
  .app-nav button {
    flex: 0 0 auto;
    padding: 9px 12px;
  }

  .card {
    padding: 11px;
    border-radius: 11px;
  }

  .grid2,
  .grid3,
  .grid4,
  .size-grid,
  .evidence-grid-pro,
  .sign-manager-grid,
  .ref-kpis,
  .ref-main-grid,
  .ref-lower,
  .folder-grid,
  .folder-history {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .portal-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .portal-card {
    min-height: 0;
    gap: 12px;
  }

  .doc-toolbar,
  .filterbar {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .doc-row-card {
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 8px;
  }

  .doc-row-actions,
  .doc-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .doc-row-actions .btn,
  .doc-actions .btn {
    width: 100%;
  }

  .att-cal-top {
    padding: 10px;
  }

  .att-cal-title {
    font-size: 17px !important;
  }

  .att-cal-week div {
    padding: 7px 1px;
    font-size: 9px;
  }

  .att-cal-day {
    min-height: 66px !important;
    padding: 3px !important;
  }

  .att-day-num {
    font-size: 12px !important;
  }

  .att-hours {
    margin-top: 4px !important;
    font-size: 8px !important;
  }

  .att-entry-exit,
  .att-more {
    display: none;
  }

  .sign-placement {
    min-height: 210px;
  }

  .modal {
    align-items: end;
    padding: 0;
  }

  .modal-box {
    width: 100% !important;
    max-height: calc(100dvh - env(safe-area-inset-top));
    border-radius: 18px 18px 0 0;
  }

  .modal-head {
    flex-wrap: wrap;
    gap: 8px;
  }

  .doc-frame {
    height: 68dvh;
  }

  .toast {
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 10px;
    max-width: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@media print {
  .header,
  .pane-head,
  .erp-nav,
  .app-nav,
  .session-bar,
  button,
  .btn {
    display: none !important;
  }

  body,
  body[data-surface],
  .pane,
  .card {
    background: #fff !important;
    box-shadow: none !important;
  }
}

/* 3.7.0 · eventos en lote */
.ev-bulk-bar{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:0 0 10px;padding:9px 12px;border:1px solid #d0d5dd;border-radius:10px;background:#f9fafb}
.ev-bulk-bar .ev-bulk-all{display:flex;align-items:center;gap:6px;font-weight:700;font-size:13px}
.ev-bulk-bar .ev-bulk-count{font-size:12.5px;color:#475467;margin-right:auto}
.ev-select{display:inline-flex;align-items:center;gap:6px;font-size:12px;color:#475467;margin-bottom:4px;cursor:pointer}
.ev-select input,.ev-bulk-all input{width:18px;height:18px}
#eventsList .card.ev-selected{outline:2px solid #2e90fa;outline-offset:-2px}

/* 3.7.1 · búsqueda, filtros, paginación y CSV en listas */
.lt-bar{display:flex;flex-wrap:wrap;align-items:center;gap:8px;margin:6px 0 10px}
.lt-bar .lt-search{flex:1 1 260px;min-width:200px}
.lt-bar input[type=search]{width:100%;min-height:40px;padding:8px 12px;border:1px solid #d0d5dd;border-radius:10px;font:inherit}
.lt-bar select,.lt-pager select{min-height:40px;padding:6px 10px;border:1px solid #d0d5dd;border-radius:10px;background:#fff;font:inherit}
.lt-bar .lt-count{font-size:12.5px;color:#475467;margin-right:auto}
.lt-pager{display:flex;flex-wrap:wrap;align-items:center;justify-content:flex-end;gap:8px;margin:10px 0 2px;font-size:13px;color:#344054}
.lt-sr{position:absolute;width:1px;height:1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap}

/* 3.7.2 · importación de trabajadores y siguientes pasos */
.wi-card .wi-file{display:grid;gap:4px;margin:10px 0 4px;font-size:13px;font-weight:700}
.wi-card .wi-file input{padding:10px;border:1px dashed #98a2b3;border-radius:10px;background:#f9fafb}
.wi-card .wi-summary{margin:8px 0}
.wi-card .wi-bad-text{color:#b42318;font-weight:700}
.wi-card tr.wi-bad td{background:#fef3f2}
.wi-card .wi-errors{color:#b42318}
.wi-card .wi-table{max-height:420px;overflow:auto}
.wi-card .wi-actions{gap:8px;flex-wrap:wrap;margin-top:10px;align-items:center}
.wi-card .wi-skip{display:flex;gap:6px;align-items:center;font-size:13px;margin-right:auto}
.wi-card .wi-message.error{color:#b42318}
.wi-card code{font-size:13px;letter-spacing:.5px}
.wi-next{border:1px solid #abefc6;background:#f6fef9}
.wi-next .wi-steps{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:10px;margin-top:10px}
.wi-next .wi-step{display:grid;gap:4px;text-align:left;padding:12px;border:1px solid #d0d5dd;border-radius:12px;background:#fff;cursor:pointer;font:inherit;min-height:72px}
.wi-next .wi-step:hover{border-color:#2e90fa;box-shadow:0 1px 3px rgba(16,24,40,.1)}
.wi-next .wi-step span{font-size:12.5px;color:#475467}

/* 3.7.3 · menú por áreas y envío a varios trabajadores */
.erp-nav.erp-nav-grouped{align-items:center}
.erp-nav .erp-nav-group{flex:0 0 auto;margin:0 0 0 10px;padding:0 2px 0 8px;border-left:1px solid var(--line,#e4e7ec);font-size:9.5px;font-weight:800;letter-spacing:.06em;text-transform:uppercase;color:#98a2b3;white-space:nowrap}
.sm-multi{margin:6px 0 10px;border:1px solid #d0d5dd;border-radius:10px;background:#fcfcfd}
.sm-multi > summary{cursor:pointer;padding:10px 12px;list-style-position:inside}
.sm-multi .sm-body{padding:0 12px 12px}
.sm-multi .sm-tools{gap:8px;margin:8px 0;flex-wrap:wrap}
.sm-multi .sm-tools input{flex:1 1 240px;min-height:38px;padding:7px 10px;border:1px solid #d0d5dd;border-radius:8px}
.sm-multi .sm-list{display:grid;grid-template-columns:repeat(auto-fill,minmax(250px,1fr));gap:6px;max-height:260px;overflow:auto}
.sm-multi .sm-item{display:flex;gap:8px;align-items:flex-start;padding:7px 9px;border:1px solid #eaecf0;border-radius:8px;background:#fff;cursor:pointer}
.sm-multi .sm-item input{width:18px;height:18px;margin-top:1px}
