/* =========================================================
   Nova jornada — visual "Painel de Gestão" MB Logística
   Mobile first, com ajustes para tablet e computador.
   ========================================================= */

:root {
  --brand: #0A5A85;          /* barra do topo */
  --primary: #0B4F7C;        /* botão principal / avatar */
  --primary-light: #3C83B5;  /* ícones / destaques */
  --primary-soft: #E1EEF7;   /* avatar pequeno / chips */
  --bg: #FFFFFF;             /* fundo branco */
  --surface: #FFFFFF;
  --field: #F4F7FA;
  --field-line: #C9D6E2;
  --ink: #0F2235;
  --text: #2A3A4B;
  --muted: #5B6B7C;          /* contraste ≥ 4.5:1 no branco */
  --line: #D9E3EC;
  --tabs-bg: #EEF3F8;
  --ok: #16A34A;
  --ok-soft: #ECFDF3;
  --ok-line: #BBF0CF;
  --warn: #B45309;
  --warn-soft: #FFF6E5;
  --warn-line: #F6D9A6;
  --danger: #DC2626;
  --danger-soft: #FEF0F0;
  --focus: #2E86C1;
  --shadow: 0 1px 2px rgba(10, 60, 100, .06), 0 4px 12px rgba(10, 60, 100, .05);

  --radius: 14px;
  --radius-sm: 9px;
  --font: "Poppins", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  --topbar-h: 60px;
  --steps-h: 52px;

  color-scheme: only light; /* sempre claro, mesmo com o celular no modo escuro */
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
}

*, *::before, *::after { box-sizing: inherit; }

html {
  scroll-padding-top: calc(var(--topbar-h) + 16px + env(safe-area-inset-top, 0px));
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

.ico {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ico--xs { width: 12px; height: 12px; }

/* ===== Barra do topo ===== */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: env(safe-area-inset-top, 0px);
  background: var(--brand);
  z-index: 31;
}

.topbar {
  position: sticky;
  top: env(safe-area-inset-top, 0px);
  z-index: 30;
  height: var(--topbar-h);
  background: var(--brand);
  color: #fff;
}
.topbar__inner {
  height: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
  padding-left: 10px;
  border-left: 1px solid rgba(255,255,255,.55);
}
.brand__name { font-size: 0.78rem; font-weight: 600; letter-spacing: .02em; }
.brand__sub { font-size: 0.68rem; color: rgba(255,255,255,.7); }

.user { display: flex; align-items: center; gap: 10px; }
.user__text { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; }
.user__name { font-weight: 600; font-size: 0.9rem; }
.user__role {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.8);
}

.avatar {
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-weight: 700;
  flex: none;
}
.avatar--sm {
  width: 38px;
  height: 38px;
  font-size: 0.8rem;
  background: var(--primary-soft);
  color: var(--primary);
}
.avatar--lg {
  width: 56px;
  height: 56px;
  font-size: 1.05rem;
  background: var(--primary);
  color: #fff;
}

/* ===== Página ===== */
.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 18px 12px calc(104px + env(safe-area-inset-bottom, 0px));
}

.page-head {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 16px;
}

.hello { display: flex; align-items: center; gap: 14px; padding: 0 4px; }
.hello__text { min-width: 0; }
.hello__title {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1.25;
}
.hello__meta {
  margin: 4px 0 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  font-size: 0.85rem;
}
.hello__meta strong { color: var(--text); font-weight: 600; }
.hello__sep { color: var(--muted); }
.hello__sep::before { content: "| "; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: .05em;
}
.pill__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill--ok { color: var(--ok); background: var(--ok-soft); border-color: var(--ok-line); }
.pill--off { color: var(--warn); background: var(--warn-soft); border-color: var(--warn-line); }

/* Abas das etapas — sempre cabem na largura da tela (sem rolagem lateral)
   celular: 8 números · tablet: 4 × 2 com nome · computador: 8 com nome */
.steps {
  display: grid;
  grid-template-columns: repeat(8, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  background: var(--tabs-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}

.steps__item {
  min-width: 0;
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 4px;
  border-radius: 9px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  text-decoration: none;
  transition: background-color .15s, color .15s;
}
.steps__num {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--field-line);
}
.steps__label {
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  /* no celular o nome fica oculto, mas continua acessível */
  position: absolute;
  width: 1px;
  height: 1px;
  clip: rect(0 0 0 0);
}

.steps__item.is-active {
  background: var(--surface);
  color: var(--brand);
  box-shadow: var(--shadow);
}
.steps__item.is-active .steps__num {
  color: #fff;
  background: var(--primary);
  border-color: var(--primary);
}
.steps__item.is-done:not(.is-active) { color: var(--primary); }
.steps__item.is-done:not(.is-active) .steps__num {
  font-size: 0;
  color: #fff;
  background: var(--primary-light);
  border-color: var(--primary-light);
}
.steps__item.is-done:not(.is-active) .steps__num::before { content: "✓"; font-size: 0.75rem; }
.steps__item.has-error:not(.is-active) { color: var(--danger); }
.steps__item.has-error:not(.is-active) .steps__num {
  font-size: 0;
  color: #fff;
  background: var(--danger);
  border-color: var(--danger);
}
.steps__item.has-error:not(.is-active) .steps__num::before { content: "!"; font-size: 0.8rem; }

/* Título "Localização e Rastreio" */
.title-block { padding: 18px 4px 12px; }
.title-block__title {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink);
}
.title-block__title .ico { width: 22px; height: 22px; color: var(--primary-light); }
.title-block__meta {
  margin: 2px 0 0;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--muted);
}

/* ===== Barra de progresso ===== */
.progress {
  height: 4px;
  background: var(--tabs-bg);
  border-radius: 999px;
  overflow: hidden;
}
.progress__bar {
  display: block;
  height: 100%;
  width: 12.5%;
  background: var(--primary);
  border-radius: inherit;
  transition: width .25s ease;
}


.title-block__dot { color: var(--muted); }
#stepInfo { font-weight: 600; color: var(--primary); }

/* ===== Formulário / cards ===== */
.form {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.section {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  border-top: 4px solid var(--primary);
  box-shadow: var(--shadow);
  min-width: 0;
}
.section[hidden] { display: none; }
.section.is-entering { animation: open .2s ease-out; }

.plate {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 18px 0;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--ink);
}
.plate__num {
  flex: none;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}

.section__body {
  padding: 14px 18px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px 14px;
}

.group {
  margin: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
}
.group legend {
  padding: 0 6px;
  margin-left: -6px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink);
}
.group--start { background: color-mix(in srgb, var(--primary-soft) 45%, var(--surface)); }

/* ===== Campos ===== */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }

.field label {
  min-height: 22px;
  display: flex;
  align-items: center;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}
.field.is-required label::after { content: "\00a0*"; color: var(--danger); }

input[type="text"],
input[type="number"],
input[type="date"],
input[type="time"],
select,
textarea {
  display: block;
  width: 100%;
  min-width: 0;
  min-height: 48px;
  padding: 11px 14px;
  font: inherit;
  font-size: 16px; /* evita zoom automático no iOS */
  color: var(--ink);
  background-color: var(--field);
  border: 1px solid var(--field-line);
  border-radius: var(--radius-sm);
  appearance: none;
  -webkit-appearance: none;
  transition: border-color .15s, background-color .15s;
}
input[type="date"], input[type="time"] { line-height: 1.2; max-width: 100%; padding-left: 12px; padding-right: 10px; }
input[type="date"]::-webkit-calendar-picker-indicator,
input[type="time"]::-webkit-calendar-picker-indicator { margin-left: 4px; }
input::-webkit-date-and-time-value { text-align: left; }

select {
  padding-right: 38px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 19px) 50%, calc(100% - 14px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}

textarea { resize: vertical; min-height: 76px; }

input::placeholder, textarea::placeholder { color: var(--muted); opacity: 1; }

input:disabled, select:disabled, textarea:disabled {
  cursor: not-allowed;
  opacity: .55;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--focus);
  background-color: var(--surface);
  box-shadow: 0 0 0 3px rgba(46, 134, 193, .15);
}
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; }

.was-validated input:invalid,
.was-validated select:invalid,
.was-validated textarea:invalid {
  border-color: var(--danger);
  background-color: var(--danger-soft);
}

/* Botão "Agora" ao lado do rótulo */
.field__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  min-height: 22px;
}
.btn-now {
  flex: none;
  padding: 3px 9px;
  min-height: 24px;
  font: inherit;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}
.btn-now:disabled { opacity: .35; cursor: not-allowed; }

/* ===== Botões ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 22px;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: filter .15s, background-color .15s;
}
.btn:active { filter: brightness(.92); }
.btn:disabled { opacity: .6; cursor: progress; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--outline {
  background: var(--surface);
  color: var(--primary);
  box-shadow: inset 0 0 0 2px var(--primary);
}
.btn--outline:active { background: var(--primary-soft); }
.btn [hidden] { display: none; }

.btn-add {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding: 0 16px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border: 0;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.btn-add[hidden] { display: none; }

.btn-remove {
  align-self: flex-end;
  min-height: 34px;
  padding: 0 14px;
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--danger);
  background: var(--danger-soft);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
}

.optional[hidden] { display: none; }
.optional:not([hidden]) { animation: open .18s ease-out; }
@keyframes open { from { opacity: 0; transform: translateY(-4px); } }

/* ===== Ocorrências ===== */
.occ {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 2px 14px;
  transition: background-color .15s, border-color .15s;
}
.occ.is-on {
  background: var(--warn-soft);
  border-color: var(--warn-line);
  padding-bottom: 14px;
}
.occ__toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink);
  cursor: pointer;
}
.occ__toggle input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--primary);
}
.occ textarea { background-color: var(--surface); border-color: var(--warn-line); }
.occ textarea[hidden] { display: none; }

/* ===== Anexo ===== */
.drop {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 2px;
  padding: 24px 16px;
  background: var(--field);
  border: 2px dashed var(--field-line);
  border-radius: 12px;
  cursor: pointer;
  transition: border-color .15s;
}
.drop:hover, .drop:focus-within { border-color: var(--primary-light); }
.drop[hidden] { display: none; }
.drop__icon, .file__icon, .file__remove svg {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.drop__icon { width: 34px; height: 34px; color: var(--primary-light); margin-bottom: 6px; }
.drop__title { font-weight: 600; color: var(--ink); }
.drop__hint { font-size: 0.78rem; color: var(--muted); }

.file {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: var(--field);
  border-radius: 12px;
}
.file[hidden] { display: none; }
.file__icon { width: 28px; height: 28px; color: var(--primary); flex: none; }
.file__info { flex: 1; min-width: 0; }
.file__name {
  margin: 0;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file__meta {
  margin: 4px 0 0;
  display: inline-block;
  padding: 1px 9px;
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--ok);
  background: var(--ok-soft);
  border: 1px solid var(--ok-line);
  border-radius: 999px;
}
.file__remove {
  flex: none;
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  background: none;
  border: 0;
  border-radius: 50%;
  color: var(--danger);
  cursor: pointer;
}
.file__remove:hover { background: var(--danger-soft); }
.file__remove svg { width: 20px; height: 20px; }

/* ===== Barra de ações ===== */
.savebar {
  position: fixed;
  inset: auto 0 0;
  z-index: 25;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0px));
}
.savebar__inner {
  max-width: 1280px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(86px + env(safe-area-inset-bottom, 0px));
  z-index: 40;
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--ok-line);
  background: var(--ok-soft);
  color: var(--ok);
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(16, 42, 67, .14);
}
.toast[hidden] { display: none; }
.toast--error { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ===== Celular pequeno ===== */
@media (max-width: 359px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .user__text { display: none; }
  .page { padding-left: 10px; padding-right: 10px; }
  .section__body { padding-left: 14px; padding-right: 14px; }
  .plate { padding-left: 14px; padding-right: 14px; }
  .group { padding: 12px 10px; }
  .steps { gap: 2px; padding: 3px; }
  .steps__num { width: 22px; height: 22px; }
  .savebar .btn { padding: 0 14px; }
  .hello { gap: 10px; }
  .avatar--lg { width: 48px; height: 48px; font-size: 0.95rem; }
}

/* Celular: data e hora do broker uma embaixo da outra (a data não cabe ao lado) */
@media (max-width: 479px) {
  #s3 .grid { grid-template-columns: minmax(0, 1fr); }
}

/* ===== Tablet: abas em 4 × 2 com o nome ===== */
@media (min-width: 600px) {
  .steps { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .steps__item { justify-content: flex-start; padding: 6px 10px; }
  .steps__label { position: static; width: auto; height: auto; clip: auto; }
}
@media (min-width: 600px) and (max-width: 719px) {
  .steps__item { font-size: 0.74rem; gap: 5px; padding: 6px 6px; }
}

@media (min-width: 640px) {
  .page { padding: 24px 24px calc(104px + env(safe-area-inset-bottom, 0px)); }
  .topbar__inner { padding: 0 24px; }
  #s5 .section__body { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px 14px; }
  #s5 .section__body .grid { display: contents; }
  #s4 .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  #s7 .section__body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  .savebar { padding-left: 24px; padding-right: 24px; }
  .savebar__inner { display: flex; justify-content: space-between; max-width: 1232px; }
  .savebar .btn { min-width: 160px; }
  .savebar .btn--primary { min-width: 220px; }
  .toast { left: auto; right: 24px; width: min(380px, calc(100vw - 48px)); }
  .hello__title { font-size: 1.35rem; }
  .avatar--lg { width: 60px; height: 60px; }
}

/* ===== Computador ===== */
@media (min-width: 1024px) {
  .page { padding: 32px 40px calc(110px + env(safe-area-inset-bottom, 0px)); }
  .topbar__inner { padding: 0 40px; }
  .savebar { padding-left: 40px; padding-right: 40px; }
  .savebar__inner { max-width: 1200px; }
  .hello__title { font-size: 1.45rem; }
  .avatar--lg { width: 64px; height: 64px; font-size: 1.15rem; }

  /* uma etapa por vez: organiza o conteúdo de cada uma em colunas */
  #s1 .section__body { display: grid; grid-template-columns: 2fr 1fr; align-items: end; }
  #s1 .btn-add { align-self: end; width: 100%; justify-content: center; min-height: 48px; }
  #s2 .section__body,
  #s3 .section__body,
  #s4 .section__body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
  #s2 .btn-add { grid-column: 1; }
  #s4 .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #s6 .section__body { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); align-items: start; }
  #s6 .btn-add { align-self: center; justify-self: start; }
  .section__body { padding: 16px 22px 22px; }
  .plate { padding: 18px 22px 0; }
}

/* ===== Tela larga: abas em uma linha só ===== */
@media (min-width: 1280px) {
  .steps { grid-template-columns: repeat(8, minmax(0, 1fr)); }
  .steps__item { justify-content: center; padding: 6px 8px; }
}

@media (min-width: 1280px) {
  #s4 .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (hover: hover) {
  .btn-add:hover, .btn-now:hover { filter: brightness(.96); }
  .btn:hover { filter: brightness(1.06); }
  .steps__item:not(.is-active):hover { background: color-mix(in srgb, var(--surface) 60%, transparent); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}