:root {
  color-scheme: light;
  --navy: #102d4b;
  --navy-deep: #0b2238;
  --blue: #006a72;
  --cyan: #00cbd4;
  --yellow: #ffd43b;
  --ink: #1d2b3a;
  --muted: #657587;
  --line: #dce4ec;
  --surface: #ffffff;
  --page: #f3f6f9;
  --green: #1d7b55;
  --red: #a63c3c;
  font-family: "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; color: var(--ink); background: var(--page); }
button, input, select { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.page-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { background: var(--navy); border-bottom: 4px solid var(--yellow); color: white; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 0.55rem max(1.25rem, calc((100% - 1440px) / 2)); }
.brand { color: white; display: flex; gap: 0.8rem; align-items: center; text-decoration: none; }
.brand img { display: block; width: clamp(112px, 15vw, 150px); height: auto; aspect-ratio: 2 / 1; object-fit: contain; border-radius: 0.3rem; background: white; }
.brand span { display: grid; gap: 0.1rem; }
.brand small { color: #d8e6f4; font-size: 0.75rem; }
.account-bar { display: flex; gap: 0.7rem; align-items: center; flex-wrap: wrap; }
.account-bar > span { font-size: 0.9rem; }
main { width: min(1440px, 100%); margin: 0 auto; padding: 1.5rem; flex: 1; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 0.8rem; box-shadow: 0 3px 14px #183a5b0a; padding: 1.25rem; margin-bottom: 1.25rem; }
.login-panel { max-width: 470px; margin: 5vh auto; padding: 2rem; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.6rem, 3vw, 2.2rem); margin-bottom: 0.35rem; }
h2 { font-size: 1.35rem; margin-bottom: 0.25rem; }
h3 { font-size: 1.1rem; margin-bottom: 1rem; }
.eyebrow { color: var(--blue); text-transform: uppercase; letter-spacing: 0.09em; font-weight: 700; font-size: 0.72rem; margin-bottom: 0.3rem; }
.muted { color: var(--muted); line-height: 1.45; }
.welcome-row, .panel-heading { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.panel-actions { display: flex; align-items: center; gap: 0.5rem; }
.welcome-row { padding: 0 0.2rem; }
.panel-heading { margin-bottom: 1rem; }
.panel-heading h2 { margin: 0; }
.app-navigation { display: flex; gap: 0.5rem; flex-wrap: wrap; margin: 0 0 1.25rem; border-bottom: 1px solid var(--line); }
.nav-button { border: 0; border-bottom: 3px solid transparent; padding: 0.7rem 0.9rem; color: var(--muted); background: transparent; font-weight: 650; }
.nav-button:hover, .nav-button.active { color: var(--navy); }
.nav-button.active { border-bottom-color: var(--cyan); }
.button { border: 1px solid transparent; border-radius: 0.5rem; padding: 0.65rem 0.9rem; font-weight: 650; transition: background 0.15s ease, border-color 0.15s ease; }
.button-primary { background: var(--navy); color: white; }
.button-primary:hover { background: var(--navy-deep); }
.button-secondary { background: #e8f1f9; color: var(--navy); border-color: #d0e0ef; }
.button-secondary:hover { background: #dcebf7; }
.button-danger { color: #a32929; background: #fff3f2; border-color: #e8c4c0; }
.button-danger:hover { background: #ffe5e2; }
.button-quiet { color: inherit; background: transparent; border-color: #bfcbd7; }
.button-quiet:hover { background: #f0f4f8; }
.button-small { padding: 0.45rem 0.6rem; font-size: 0.8rem; white-space: nowrap; }
.topbar .button-quiet { border-color: #ffffff70; color: white; }
.topbar .button-quiet:hover { background: #ffffff18; }
label { display: grid; gap: 0.35rem; color: #33475b; font-size: 0.86rem; font-weight: 600; }
input, select { width: 100%; min-width: 0; color: var(--ink); background: white; border: 1px solid #c8d3df; border-radius: 0.45rem; padding: 0.62rem 0.68rem; }
input:focus, select:focus, button:focus-visible { outline: 3px solid #6da9df78; outline-offset: 1px; border-color: var(--blue); }
input[readonly] { background: #f3f6f9; color: var(--muted); }
.form-grid { display: grid; gap: 1rem; }
.form-grid .button { justify-self: start; }
.trip-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.form-actions { display: flex; align-items: end; }
.inline-form { display: flex; align-items: end; gap: 1rem; flex-wrap: wrap; }
.inline-form label { flex: 1 1 220px; }
.filter-card { background: #f8fafc; border: 1px solid var(--line); border-radius: 0.7rem; padding: 0.9rem; margin: 0 0 1rem; }
.filter-primary { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.75rem; }
.filter-primary label, .filter-search { min-width: 0; }
.filter-primary input, .filter-primary select, .filter-search input { height: 44px; }
.filter-search { margin-top: 0.75rem; }
.filter-actions { display: flex; gap: 0.55rem; margin-top: 0.75rem; }
.filter-actions .button { min-height: 42px; }
.filter-note { color: #33475b; }
.filter-note-aguardando { color: #7C3AED; font-weight: 700; }
.filter-note-agendado { color: #2563EB; font-weight: 700; }
.filter-note-ok { color: #16A34A; font-weight: 700; }
.filter-note-enviar-ordem { color: #EA580C; font-weight: 700; }
.filter-note-cancelada { color: #DC2626; font-weight: 700; }
.option-aguardando { color: #7C3AED; }
.option-agendado { color: #2563EB; }
.option-ok { color: #16A34A; }
.option-enviar-ordem { color: #EA580C; }
.option-cancelada { color: #DC2626; }
.trip-result-row { display: flex; align-items: center; margin: 0 0 0.65rem; }
.trip-result-count { color: #526579; font-size: 0.88rem; font-weight: 700; }
.table-wrap { overflow-x: auto; width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
th, td { padding: 0.75rem 0.65rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { color: #526579; background: #f8fafc; font-size: 0.74rem; font-weight: 700; text-transform: none; letter-spacing: 0; white-space: nowrap; }
.trip-table { min-width: 980px; table-layout: fixed; }
.trip-table th, .trip-table td { height: 52px; padding: 0.55rem 0.6rem; }
.trip-table tbody tr:nth-child(even) { background: #f8fafc; }
.trip-table tbody tr:nth-child(odd) { background: #ffffff; }
.trip-table tbody tr:hover,
.trip-table tbody tr.waiting-duplicate:hover { background: #eef6ff !important; transition: background 0.2s ease; }
.trip-table tbody tr.waiting-duplicate { background: #ffe6e6; }
.col-date { width: 78px; white-space: nowrap; }
.col-operation { width: 190px; }
.col-route { width: 220px; }
.col-details { width: 180px; text-align: center; }
.col-status { width: 112px; text-align: center; }
.col-updated-by { width: 150px; }
.col-actions { width: 92px; text-align: center; }
.operation-plate { display: block; color: #0f2f4f; font-size: 1.02rem; line-height: 1.15; letter-spacing: 0.02em; }
.operation-driver { display: block; margin-top: 0.18rem; color: #33475b; font-size: 0.82rem; }
.route-loading, .route-destination { display: block; color: #33475b; text-align: center; }
.route-loading { font-size: 0.84rem; }
.route-destination { font-size: 0.82rem; }
.route-arrow { display: block; margin: 0.16rem 0; color: #006a72; font-size: 1.2rem; font-weight: 700; line-height: 1; text-align: center; }
.detail-product { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #33475b; font-size: 0.82rem; text-align: right; }
.detail-block { width: fit-content; max-width: 100%; margin: 0 auto; }
.detail-meta { display: flex; align-items: center; justify-content: flex-start; gap: 0.3rem; width: max-content; max-width: 100%; min-width: 0; }
.detail-separator { flex: 0 0 auto; color: #718096; }
.detail-transport { display: inline-flex; flex: 0 1 auto; align-items: center; justify-content: center; width: fit-content; min-width: 0; max-width: 100%; height: 30px; min-height: 30px; box-sizing: border-box; line-height: 0.9; text-align: center; white-space: normal; overflow-wrap: anywhere; border: 1px solid #b9d8e8; border-radius: 999px; background: #edf7fb; color: #164d70; padding: 0.2rem 0.48rem; font-size: 0.7rem; }
.detail-weight { display: block; margin-top: 0.12rem; color: #102d4b; font-size: 0.98rem; font-weight: 800; text-align: left; white-space: nowrap; }
.status-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 92px; min-height: 28px; border-radius: 999px; padding: 0.32rem 0.6rem; color: #ffffff; font-size: 0.72rem; font-weight: 700; white-space: nowrap; }
.status-badge-aguardando { background: #7C3AED; }
.status-badge-agendado { background: #2563EB; }
.status-badge-ok { background: #16A34A; }
.status-badge-enviar-ordem { background: #EA580C; }
.status-badge-cancelada { background: #DC2626; }
.action-button { width: 38px; height: 38px; border: 1px solid #d6e0ea; border-radius: 0.45rem; background: #ffffff; font-size: 1rem; line-height: 1; }
.action-button:hover { background: #eef6ff; border-color: #9bc0df; }
.trip-table .col-actions { position: sticky; right: 0; background: inherit; z-index: 2; border-bottom: 1px solid var(--line); }
.trip-table thead .col-actions { background: #f8fafc; z-index: 3; }
.waiting-duplicate,
.waiting-duplicate:hover { background: #ffe6e6 !important; }
.waiting-duplicate td { border-bottom-color: #dfaaa8; }
.status { font-weight: 700; white-space: nowrap; }
.status-ok { color: var(--green); }
.status-cancelada { color: var(--red); }
.status-enviar-ordem { color: #916612; }
.status-aguardando { color: #7251a3; }
.status-agendado { color: #176b8a; }
.updated-by { color: var(--muted); font-size: 0.8rem; }
.updated-by span { display: block; }
.created-at { color: #526579; font-weight: 600; white-space: nowrap; }
.updated-by-name { margin-top: 0.1rem; color: var(--ink); font-weight: 700; }
.app-tooltip { position: fixed; z-index: 20; width: max-content; padding: 0.4rem 0.58rem; border: 1px solid #29445f; border-radius: 0.4rem; background: #102d4b; color: #fff; font-size: 0.75rem; line-height: 1.3; overflow-wrap: anywhere; box-shadow: 0 3px 10px #00000026; pointer-events: none; }
.app-tooltip[hidden] { display: none; }
.empty-state { text-align: center; padding: 2rem; color: var(--muted); }
.trip-actions { display: flex; align-items: center; justify-content: center; gap: 0.35rem; min-height: 38px; }
.table-footer { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding-top: 0.9rem; }
.pagination-actions { display: flex; gap: 0.5rem; }
.admin-title { margin-top: 2rem; }
.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.compact-form { margin-bottom: 1.2rem; padding-bottom: 1.2rem; border-bottom: 1px solid var(--line); }
.record-list { display: grid; gap: 0.55rem; }
.record-row { display: grid; grid-template-columns: minmax(100px, 0.7fr) minmax(140px, 1.5fr) auto auto; align-items: center; gap: 0.5rem; border: 1px solid var(--line); border-radius: 0.55rem; padding: 0.55rem; }
.record-row input, .record-row select { padding: 0.5rem; }
.record-row.inactive { opacity: 0.62; }
.user-label { display: grid; gap: 0.15rem; overflow: hidden; }
.user-label small { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.notice { position: sticky; top: 0.5rem; z-index: 3; margin-bottom: 1rem; border-radius: 0.55rem; padding: 0.85rem 1rem; box-shadow: 0 3px 10px #00000014; }
.notice.success { background: #e8f5ee; color: #14583d; border: 1px solid #b8dfc9; }
.notice.error { background: #fff0ef; color: #7d2424; border: 1px solid #ecc4c1; }
footer { display: flex; justify-content: space-between; gap: 1rem; padding: 1rem max(1.25rem, calc((100% - 1440px) / 2)); color: var(--muted); background: #e8edf2; font-size: 0.8rem; }

@media (max-width: 900px) {
  .trip-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-grid { grid-template-columns: 1fr; }
  .trip-table { min-width: 760px; }
  .filter-primary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-primary label:last-child { grid-column: 1 / -1; }
}
@media (max-width: 620px) {
  main { padding: 1rem; }
  .topbar { align-items: center; flex-wrap: wrap; padding: 0.7rem 1rem; }
  .account-bar { justify-content: flex-end; gap: 0.35rem; }
  .account-bar > span { width: 100%; text-align: right; font-size: 0.77rem; }
  .account-bar .button { padding: 0.45rem 0.55rem; font-size: 0.78rem; }
  .brand img { width: clamp(96px, 28vw, 130px); }
  .brand small { display: none; }
  .trip-grid { grid-template-columns: 1fr; }
  .welcome-row { align-items: flex-start; }
  .panel { padding: 1rem; }
  .panel-heading { align-items: flex-start; }
  .record-row { grid-template-columns: 1fr auto; }
  .record-row input, .record-row select { grid-column: 1 / -1; }
  .filter-primary { grid-template-columns: 1fr; }
  .filter-primary label:last-child { grid-column: auto; }
  .filter-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-actions .button { width: 100%; }
  .trip-table { min-width: 660px; }
  .trip-table .col-date,
  .trip-table .col-details,
  .trip-table .col-updated-by { display: none; }
  footer { padding: 0.8rem 1rem; flex-direction: column; gap: 0.3rem; }
}

.print-report { display: none; }
.print-logo { display: block; width: 110px; height: auto; margin-bottom: 0.6rem; }

@media print {
  @page { size: landscape; margin: 12mm; }
  body { color: #111; background: white; font-family: Arial, sans-serif; }
  body > .page-shell > .topbar,
  body > .page-shell > footer,
  main > #login-view,
  main > #notice { display: none !important; }
  main { width: auto; margin: 0; padding: 0; }
  #app-view { display: block !important; }
  #app-view > #app-navigation { display: none !important; }
  #app-view > #trips-view > :not(#print-report) { display: none !important; }
  #app-view > :not(#trips-view) { display: none !important; }
  #print-report,
  #print-report[hidden] { display: block !important; }
  .print-report-header { margin-bottom: 1rem; }
  .print-report-header h1 { margin-bottom: 0.25rem; font-size: 20pt; }
  .print-report-header p { margin: 0.25rem 0; }
  .print-report-filters { display: grid; grid-template-columns: auto 1fr auto 1fr; gap: 0.2rem 0.6rem; margin: 0.8rem 0; }
  .print-report-filters dt { font-weight: bold; }
  .print-report-filters dd { margin: 0; }
  .print-report-total { font-weight: bold; }
  .print-table { width: 100%; border-collapse: collapse; font-size: 9pt; }
  .print-table th, .print-table td { padding: 5px 6px; border: 1px solid #888; text-align: left; vertical-align: top; }
  .print-table th { color: #111; background: #e9edf1 !important; text-transform: none; letter-spacing: 0; }
  .print-table tr { break-inside: avoid; }
  .print-table thead { display: table-header-group; }
}
