:root {
  color-scheme: light;
  --bg: #f3f6f9;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #64748b;
  --line: #d8dee8;
  --brand-blue: #123f68;
  --brand-blue-dark: #0d3357;
  --brand-orange: #ef4f2f;
  --brand-orange-dark: #c93e24;
  --blue: var(--brand-blue);
  --green: #148a5a;
  --amber: #b7791f;
  --red: #b42318;
}

* { box-sizing: border-box; }
html {
  max-width: 100%;
  overflow-x: hidden;
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
  max-width: 100%;
  overflow-x: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: var(--brand-blue);
  color: #fff;
  border-bottom: 4px solid var(--brand-orange);
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  color: #fff;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}
.brand img {
  display: block;
  height: 42px;
  width: 112px;
  object-fit: contain;
  background: #fff;
  border-radius: 6px;
  padding: 3px 6px;
}
.brand span {
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
}
.topbar nav a {
  color: #fff;
  text-decoration: none;
  font-size: 13px;
  padding: 8px 10px;
  border-radius: 6px;
  background: rgba(255,255,255,.12);
  white-space: nowrap;
}
.topbar nav a:hover {
  background: var(--brand-orange);
}
.topbar nav a.locked {
  opacity: .55;
}
.home-page .topbar nav {
  display: none;
}

.page {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 16px;
}
h1, h2, p { margin-top: 0; }
h1 { font-size: 28px; margin-bottom: 4px; }
h2 { font-size: 18px; }

.home h1 { margin: 12px 0 18px; }
.launcher {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}
.launch {
  display: flex;
  align-items: center;
  min-height: 76px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  text-decoration: none;
}
.launch.primary { background: var(--brand-blue); color: #fff; border-color: var(--brand-blue); }
.launch.export { border-color: var(--brand-orange); }

.flow-home .screen-head {
  margin-bottom: 16px;
}
.flow-board {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.flow-card {
  position: relative;
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 126px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  text-decoration: none;
  box-shadow: 0 8px 22px rgba(18, 63, 104, .07);
}
.flow-card strong {
  display: block;
  font-size: 17px;
  margin-bottom: 6px;
}
.flow-card small {
  display: block;
  color: var(--muted);
  line-height: 1.35;
}
.flow-card em {
  grid-column: 1 / -1;
  justify-self: start;
  padding: 5px 9px;
  border-radius: 999px;
  background: #eef2f6;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  font-weight: 800;
}
.flow-step {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #e9f1f7;
  color: var(--brand-blue);
  font-size: 22px;
  font-weight: 900;
}
.flow-card.ready {
  border-color: #b9cede;
}
.flow-card.ready .flow-step,
.flow-card.ready em {
  background: var(--brand-blue);
  color: #fff;
}
.flow-card.review {
  border-color: #ffd0c4;
}
.flow-card.review .flow-step,
.flow-card.review em {
  background: var(--brand-orange);
  color: #fff;
}
.flow-card.blocked {
  background: #f8fafc;
}
.flow-card.blocked .flow-step {
  background: #e5e7eb;
  color: #667085;
}
.flow-card.export.ready {
  border-color: var(--brand-orange);
}
.offline-card {
  max-width: 520px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 8px 22px rgba(18, 63, 104, .07);
}
.offline-card p {
  color: var(--muted);
}

.screen-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.screen-head p { color: var(--muted); margin-bottom: 0; }
.head-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}
.head-action-form {
  margin: 0;
}
.head-action-form button {
  cursor: pointer;
}
.ghost-btn, .filters button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--brand-blue);
  text-decoration: none;
  border-radius: 6px;
  padding: 11px 14px;
  font-weight: 700;
}
.ghost-btn.primary-action {
  background: var(--brand-orange);
  border-color: var(--brand-orange);
  color: #fff;
}

.field-form {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  gap: 12px;
  width: 100%;
  max-width: 100%;
}
.mobile-first { max-width: 760px; }
.grid { display: grid; gap: 10px; }
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 700;
  color: #344054;
}
input, select, textarea, button {
  font: inherit;
}
input, select, textarea {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
}
select {
  appearance: auto;
}
select[multiple] {
  min-height: 210px;
  padding: 6px;
}
select[multiple] option {
  padding: 10px 8px;
  border-bottom: 1px solid #eef2f6;
}
textarea { resize: vertical; }
.field-note {
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}

.worker-dropdown {
  position: relative;
  display: grid;
  gap: 6px;
  min-width: 0;
}
.worker-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  text-align: left;
  min-width: 0;
}
.worker-trigger span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.worker-trigger strong {
  flex: 0 0 auto;
  border-radius: 999px;
  background: #e9f1f7;
  color: var(--brand-blue);
  padding: 4px 8px;
  font-size: 12px;
}
.worker-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 20;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 12px 28px rgba(15, 23, 42, .16);
  overflow: hidden;
  max-width: calc(100vw - 24px);
}
.worker-dropdown.open .worker-menu {
  display: block;
}
.worker-menu.inline {
  display: block;
  position: static;
  box-shadow: none;
}
.worker-dropdown.static-list {
  position: static;
}
.worker-menu-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 10px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}
.mini-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
}
.worker-menu-head span {
  color: var(--muted);
  font-size: 12px;
}
.worker-menu-head button,
.mini-actions button {
  min-height: 32px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 8px;
}
.worker-list {
  max-height: 300px;
  overflow: auto;
  padding: 6px;
}
.worker-menu-footer {
  padding: 8px 10px;
  border-top: 1px solid var(--line);
  background: #f8fafc;
}
.save-selection-btn {
  width: 100%;
  min-height: 36px;
  border: none;
  border-radius: 6px;
  background: var(--accent, #2563eb);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.worker-check {
  display: grid;
  grid-template-columns: 24px 1fr;
  align-items: center;
  gap: 8px;
  min-height: 42px;
  padding: 6px 8px;
  border-radius: 6px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 500;
}
.absent-check {
  grid-template-columns: 24px minmax(0, 1fr);
}
.absent-check select {
  grid-column: 2;
  min-height: 38px;
  padding: 7px 9px;
  font-size: 13px;
}
.absent-check:not(:has(input:checked)) select {
  display: none;
}
.worker-check:hover {
  background: #f3f7fb;
}
.worker-check input {
  width: 18px;
  min-height: 18px;
}
.worker-check:has(input:checked) {
  background: #e9f1f7;
  color: var(--brand-blue);
  font-weight: 800;
}
.check {
  grid-template-columns: 24px 1fr;
  align-items: center;
  min-height: 44px;
}
.check input { min-height: 20px; }

.quickbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.quick, .timechips button {
  min-height: 46px;
  border: 1px solid #b9cede;
  border-radius: 6px;
  background: #e9f1f7;
  color: var(--brand-blue);
  font-weight: 700;
}
.timechips button {
  min-height: 34px;
  font-size: 13px;
  font-weight: 800;
  padding: 4px 2px;
}
.quick.danger { background: #fff1ee; color: var(--brand-orange-dark); border-color: #ffc7ba; }
.timechips {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}
.partial-box {
  display: none;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 10px;
  background: #fff8e6;
  border: 1px solid #f6d58a;
  border-radius: 8px;
}
.partial-box.show { display: grid; }

.prep-box {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #c7e5d3;
  border-radius: 8px;
  background: #f0fbf4;
  color: #17633a;
  font-size: 13px;
}
.prep-box span {
  color: #17633a;
}

.worker-picker {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: #f8fafc;
}
.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.picker-head div:first-child {
  display: grid;
  gap: 2px;
}
.picker-head span {
  color: var(--muted);
  font-size: 12px;
}
.picker-actions {
  display: flex;
  gap: 6px;
}
.picker-actions button {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  font-weight: 700;
}
.worker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 8px;
  max-height: 260px;
  overflow: auto;
  padding-right: 2px;
}
.worker-chip {
  position: relative;
  display: block;
  min-height: 44px;
}
.worker-chip input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.worker-chip span {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 13px;
}
.worker-chip input:checked + span {
  border-color: #79b8e8;
  background: #eaf5ff;
  color: #0b4f7f;
  font-weight: 800;
}

.summary, .metric-strip, .metric-grid, .breakdown {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}
.summary {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
}
.summary div, .metric-strip div, .metric-grid div {
  display: grid;
  gap: 4px;
}
.summary span, .metric-strip span, .metric-grid span {
  color: var(--muted);
  font-size: 12px;
}
.summary strong, .metric-strip strong, .metric-grid strong {
  font-size: 22px;
}
.summary p {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
}
.submit-btn {
  min-height: 52px;
  border: 0;
  border-radius: 8px;
  background: var(--brand-orange);
  color: #fff;
  font-weight: 800;
  font-size: 18px;
}
.form-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.submit-btn.secondary {
  background: var(--brand-blue);
}

.alert {
  background: #fff1f0;
  border: 1px solid #ffccc7;
  color: var(--red);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
}
.success {
  background: #edf8f3;
  border: 1px solid #b7e3ce;
  color: var(--green);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 10px;
  font-weight: 700;
}
.inline-action {
  margin-top: 10px;
}
.inline-action button {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: var(--brand-blue);
  color: #fff;
  font-weight: 800;
  padding: 8px 12px;
}
.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.filters input, .filters select, .filters button { min-height: 44px; }

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  padding: 12px;
  margin-bottom: 12px;
}
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  padding: 12px;
  margin-bottom: 12px;
}
.breakdown {
  padding: 14px;
  margin-bottom: 12px;
}
.bar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  border-top: 1px solid var(--line);
}
.bar-row:first-of-type { border-top: 0; }
.status {
  padding: 9px 12px;
  border-radius: 6px;
  font-weight: 800;
  background: #eef2f6;
}
.status.verde { color: var(--green); background: #e7f6ee; }
.status.amarillo { color: var(--amber); background: #fff8e6; }
.status.rojo { color: var(--red); background: #fff1f0; }
.status.gris { color: #475467; background: #eef2f6; }

.list-section { margin-top: 16px; }
.record-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}
.record-card div {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.record-card p { margin: 7px 0; color: #344054; }
.record-card small, .record-card em {
  display: block;
  color: var(--muted);
  font-style: normal;
}
.record-card em { color: var(--amber); margin-top: 6px; }
.record-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  margin-top: 9px;
  padding: 7px 10px;
  border-radius: 6px;
  background: #e9f1f7;
  color: var(--brand-blue);
  font-size: 13px;
  font-weight: 800;
  text-decoration: none;
}
.edit-alert {
  display: grid;
  gap: 6px;
  background: #fff8e6;
  border-color: #f6d58a;
  color: var(--amber);
}
.edit-alert a {
  color: var(--brand-blue);
  font-weight: 800;
}
.empty { color: var(--muted); }
.table-wrap {
  overflow-x: auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 14px;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}
th, td {
  text-align: left;
  border-bottom: 1px solid var(--line);
  padding: 10px;
  font-size: 14px;
}
th { background: #eef2f6; }

@media (max-width: 680px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 10px;
  }
  .brand img {
    height: 38px;
    width: 104px;
  }
  .page { padding: 12px; }
  h1 { font-size: 23px; }
  .screen-head { align-items: stretch; }
  .head-actions { justify-content: stretch; }
  .head-actions .ghost-btn { flex: 1 1 auto; text-align: center; }
  .grid.two, .partial-box, .summary, .metric-strip {
    grid-template-columns: 1fr;
  }
  .form-actions { grid-template-columns: 1fr; gap: 8px; }
  .quickbar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .timechips { grid-template-columns: repeat(7, minmax(0, 1fr)); }
  .worker-grid { grid-template-columns: 1fr; max-height: 310px; }
  .picker-head { align-items: stretch; flex-direction: column; }
  .prep-box { flex-direction: column; }
  .filters { display: grid; grid-template-columns: 1fr 1fr auto; }
  .field-form { border-left: 0; border-right: 0; border-radius: 0; margin-left: -12px; margin-right: -12px; }
  input, select, textarea { font-size: 16px; }
  .submit-btn { min-height: 46px; font-size: 15px; border-radius: 6px; }
  .worker-trigger { min-height: 44px; padding: 9px 10px; }
  .worker-trigger span {
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }
  .worker-menu {
    position: fixed;
    top: 120px;
    left: 12px;
    right: 12px;
    max-width: none;
    max-height: calc(100vh - 150px);
  }
  .worker-list { max-height: calc(100vh - 235px); }
  .worker-menu-head { align-items: stretch; flex-direction: column; }
  .mini-actions { justify-content: stretch; }
  .mini-actions button { flex: 1 1 auto; }
  .launch { min-height: 64px; font-size: 16px; }
  .flow-board { grid-template-columns: 1fr; }
  .flow-card { min-height: 106px; }
}

@media (max-width: 430px) {
  .screen-head { display: grid; }
  .ghost-btn { text-align: center; }
  .filters { grid-template-columns: 1fr; }
  .quickbar { grid-template-columns: 1fr; }
  .timechips { grid-template-columns: repeat(5, minmax(0, 1fr)); }
}

/* User Menu and Logout */
.user-menu {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
}

.user-info {
  color: #fff;
  font-size: 13px;
  padding: 6px 10px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
}

.logout-btn {
  color: #fff;
  text-decoration: none;
  font-size: 13px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--brand-orange);
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
}

.logout-btn:hover {
  background: var(--brand-orange-dark);
  transform: scale(1.05);
}

.user-icon, .logout-icon {
  font-size: 14px;
}

/* Session countdown timer */
.session-timer {
  color: rgba(255, 255, 255, 0.75);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  padding: 4px 8px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  white-space: nowrap;
  letter-spacing: 0.02em;
  transition: background 0.3s, color 0.3s;
}

.session-timer--warning {
  color: #fff;
  background: rgba(231, 76, 60, 0.75);
  animation: session-pulse 1.5s ease-in-out infinite;
}

.session-timer--danger {
  color: #fff;
  background: #c0392b;
}

@keyframes session-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.65; }
}

/* Session expiry warning modal */
.session-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.session-modal-box {
  background: var(--panel);
  border-radius: 12px;
  padding: 2rem 2.2rem;
  max-width: 380px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25);
}

.session-modal-icon {
  font-size: 2.4rem;
  margin-bottom: .6rem;
}

.session-modal-box h3 {
  margin: 0 0 .6rem;
  font-size: 1.1rem;
  color: var(--ink);
}

.session-modal-box p {
  margin: 0 0 1.2rem;
  font-size: .95rem;
  color: var(--muted);
}

.session-modal-actions {
  display: flex;
  gap: .75rem;
  justify-content: center;
  flex-wrap: wrap;
}
