/* ============================================================
   Gl Transportes — Mobile-first / PWA overrides
   Loaded AFTER style.css so everything wins the cascade.
   Target: iPhone-like devices (320px → 430px) primarily.
   ============================================================ */

:root {
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);
}

html, body {
  overscroll-behavior-y: none;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body {
  overflow-x: hidden;
}

/* Drawer backdrop (mobile) */
.nav-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 290;
  opacity: 0;
  transition: opacity .22s ease;
}
.nav-backdrop.show {
  display: block;
  opacity: 1;
}

/* Smooth drawer slide */
#navSidebar {
  transition: transform .26s cubic-bezier(.4,0,.2,1);
}

/* =====================================================
   MOBILE (≤ 768px)
   ===================================================== */
@media (max-width: 768px) {
  html, body, #app {
    max-width: 100vw;
    overflow-x: hidden;
  }

  #app {
    grid-template-columns: 1fr !important;
    grid-template-rows: 52px 1fr !important;
    height: 100vh;
    height: 100dvh;
  }

  /* ——— Drawer sidebar ——— */
  #navSidebar {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    width: 78vw;
    max-width: 300px;
    height: 100vh;
    height: 100dvh;
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
    transform: translateX(-105%);
    z-index: 300;
    box-shadow: 6px 0 36px rgba(0, 0, 0, 0.6);
  }
  #navSidebar.mobile-open {
    transform: translateX(0);
  }
  .nav-logo { padding: 14px 10px; }
  .nav-logo-img { width: 130px; }
  .nav-menu { padding: 10px 8px; gap: 4px; }
  .nav-item {
    min-height: 48px;
    font-size: 14px;
    padding: 10px 14px;
    border-radius: 12px;
  }
  .nav-label { display: inline !important; font-size: 14px; }

  /* ——— Header ——— */
  #header {
    grid-column: 1 / -1 !important;
    grid-row: 1 !important;
    height: 52px;
    padding: 0 10px !important;
    padding-top: var(--safe-top);
    gap: 8px !important;
    border-bottom: 1px solid rgba(255,255,255,0.06);
    background: rgba(8, 6, 20, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    position: sticky;
    top: 0;
    z-index: 100;
  }
  .btn-hamburger {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    color: var(--text-primary);
  }
  .header-filter,
  .header-search-wrap,
  #btnNewAccount {
    display: none !important;
  }
  .header-spacer { flex: 1; }
  .op-switch-wrap { flex-shrink: 0; }
  .op-switch-btn {
    height: 40px !important;
    padding: 0 12px !important;
    font-size: 13px !important;
    border-radius: 10px !important;
  }
  .btn-bell {
    width: 42px;
    height: 42px;
    border-radius: 12px;
  }
  .notif-dropdown {
    position: fixed !important;
    top: 58px !important;
    left: 8px !important;
    right: 8px !important;
    width: auto !important;
    max-width: none !important;
  }

  /* ——— Content containers ——— */
  /* Old "acessos" module pattern hid #main on mobile unless .main-visible
     was set. The fleet app has no #sidebar content, so force the opposite. */
  #sidebar {
    display: none !important;
  }
  #main,
  #main.main-visible {
    display: flex !important;
    flex-direction: column;
    grid-column: 1 / -1 !important;
    grid-row: 2 !important;
    width: 100%;
    min-width: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: var(--safe-bottom);
  }

  /* Every main content block — kill horizontal overflow,
     force width, shrink default paddings from inline styles. */
  #main > div,
  #main > section {
    max-width: 100% !important;
    width: 100% !important;
  }
  #main [style*="padding:20px 28px"],
  #main [style*="padding:18px 24px"],
  #main [style*="padding:14px 24px"],
  #main [style*="padding:22px 28px"] {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  /* ——— Manutenção itens row → stacked mobile layout ——— */
  .manu-item-row {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
    padding: 12px !important;
  }
  .manu-item-row .manu-item-tipo {
    grid-column: 1 / -1;
    font-size: 14px !important;
    min-height: 44px;
  }
  .manu-item-row .manu-item-nome {
    grid-column: 1 / -1;
    font-size: 14px !important;
    min-height: 44px;
  }
  .manu-item-row .manu-item-qty,
  .manu-item-row .manu-item-valor {
    font-size: 14px !important;
    min-height: 44px;
  }
  .manu-item-row > div[style*="color:#f0b429"] {
    grid-column: 1;
    font-size: 14px !important;
    display: flex;
    align-items: center;
    padding-left: 4px;
  }
  .manu-item-row > button[id^="btnRemItem"] {
    grid-column: 2;
    justify-self: end;
    width: 44px;
    height: 44px;
    padding: 0 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(225,112,85,0.10);
    border: 1px solid rgba(225,112,85,0.28) !important;
    border-radius: 10px !important;
  }

  /* ——— Viagens cards: simplified for mobile ——— */
  .viagem-card {
    padding: 12px 14px !important;
    border-radius: 14px;
  }
  /* Hide the bottom stats strip entirely */
  .viagem-card .viagem-card-stats { display: none !important; }
  /* Hide transportadora inline, motorista chip, price column, delete button */
  .viagem-card [data-del-viagem] { display: none !important; }
  .viagem-card > div:first-child > div[style*="text-align:right"] { display: none !important; }
  .viagem-card > div:first-child > div[style*="flex:1"] > div:first-child > span { display: none !important; }
  .viagem-card > div:first-child > div[style*="flex:1"] > div:nth-child(2) > span:not([style*="rgba(240,180,41"]):not([style*="color:var(--text-muted)"]) {
    display: none !important;
  }
  /* Make icon+content+buttons fit nicely */
  .viagem-card > div:first-child { gap: 10px !important; }
  .viagem-card > div:first-child > div:first-child { width: 38px !important; height: 38px !important; }
  .viagem-card [data-view-viagem],
  .viagem-card [data-edit-viagem] {
    min-width: 40px;
    min-height: 40px;
    padding: 8px !important;
    color: #f0b429 !important;
  }
  .viagem-card [data-view-viagem] { color: #60a5fa !important; }

  /* ——— Modais de lançamento: limpeza mobile ——— */
  .modal-subtitle { display: none !important; }
  .lancamento-modal input::placeholder,
  .lancamento-modal textarea::placeholder,
  .lancamento-modal input::-webkit-input-placeholder,
  .lancamento-modal textarea::-webkit-input-placeholder,
  .modal-overlay-full input::placeholder,
  .modal-overlay-full textarea::placeholder,
  .modal-overlay-full input::-webkit-input-placeholder,
  .modal-overlay-full textarea::-webkit-input-placeholder {
    color: transparent !important;
  }

  /* ——— Fechamento cards simplificados ——— */
  .fech-card { padding: 12px 14px !important; }
  .fech-card .fech-card-icon,
  .fech-card .fech-card-chips,
  .fech-card .fech-card-lucro-hint,
  .fech-card .fech-del-btn,
  .fech-card .fech-card-stats { display: none !important; }
  .fech-card .fech-motorista { display: none !important; }
  .fech-card .fech-card-head { gap: 10px !important; }
  .fech-card .fech-card-lucro > div:first-child { font-size: 14px !important; }
  .fech-group-head .fech-group-count,
  .fech-group-head .fech-group-total { display: none !important; }

  /* ——— Manutenção cards simplificados ——— */
  .manu-card { padding: 12px 14px !important; }
  .manu-card .manu-card-icon,
  .manu-card .manu-card-desc,
  .manu-card .manu-meta-km,
  .manu-card .manu-meta-itens,
  .manu-card .manu-tipo-chip,
  .manu-card .manu-del-btn { display: none !important; }
  .manu-card .manu-card-meta { margin-bottom: 6px !important; }
  .manu-card .manu-card-total { font-size: 14px !important; }

  /* ——— Estrada Financeiro: match Adubo layout ——— */
  .fin-hero,
  .fin-topbar { display: none !important; }
  .fin-container {
    padding: 0 !important;
    gap: 0 !important;
    background: transparent !important;
  }
  .fin-content { padding: 12px !important; }

  /* ——— KPI grids → single column ——— */
  .fin-dash-wrap { padding: 14px !important; gap: 18px !important; }
  .fin-dash-kpis {
    grid-template-columns: 1fr 1fr !important;
    gap: 14px !important;
  }
  .fin-dash-kpi {
    padding: 18px 16px !important;
    min-height: 120px !important;
    border-radius: 14px;
  }
  .fin-dash-kpi-top { margin-bottom: 14px !important; }
  .fin-dash-kpi-label { font-size: 11px !important; line-height: 1.35 !important; letter-spacing: 0.3px !important; }
  .fin-dash-kpi-value { font-size: 19px !important; font-weight: 800; line-height: 1.2 !important; }
  .fin-dash-kpi-hint  { font-size: 11px !important; margin-top: 8px !important; line-height: 1.35 !important; }

  .fin-dash-bottom,
  .fin-dash-wrap > div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
    gap: 16px !important;
  }
  .fin-dash-block {
    padding: 18px 16px !important;
    border-radius: 16px;
  }
  .fin-dash-block-head { margin-bottom: 14px !important; gap: 10px !important; }
  .fin-dash-block-title { font-size: 14px !important; line-height: 1.3 !important; }
  .fin-dash-block-sub { font-size: 11px !important; margin-top: 4px !important; line-height: 1.35 !important; }
  .fin-dash-main-chart { padding: 16px 14px 10px !important; }
  .fin-dash-main-chart canvas { max-height: 220px; }

  /* Listas dentro dos blocos do resumo: respirar mais */
  .fin-rank-list { gap: 16px !important; }
  .fin-rank-item { padding: 6px 0 !important; gap: 12px !important; }
  .fin-rank-top { margin-bottom: 8px !important; gap: 12px !important; }
  .fin-rank-name { font-size: 13px !important; }
  .fin-rank-val  { font-size: 13px !important; }
  .fin-rank-placa { display: block; margin-left: 0 !important; margin-top: 2px; }

  .fin-cost-list { gap: 18px !important; }
  .fin-cost-item { gap: 12px !important; }
  .fin-cost-row  { margin-bottom: 8px !important; gap: 10px !important; }
  .fin-cost-label { font-size: 12px !important; line-height: 1.35 !important; }
  .fin-cost-value { font-size: 13px !important; }
  .fin-cost-pct   { font-size: 11px !important; margin-top: 6px !important; }

  /* Filter bar wraps */
  .fin-dash-filterbar {
    flex-wrap: wrap !important;
    gap: 8px !important;
  }
  .fin-dash-select { flex: 1; min-width: 0; }

  /* ——— List toolbars ——— */
  .list-toolbar {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 10px !important;
    padding: 10px 2px 4px !important;
  }
  .list-view-toggle {
    width: 100%;
    display: flex;
    gap: 6px;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 12px;
    padding: 4px;
  }
  .list-view-toggle .list-view-btn {
    flex: 1;
    min-height: 40px;
    font-size: 12px;
    justify-content: center;
    border: none !important;
    background: transparent !important;
    border-radius: 9px !important;
  }
  .list-view-toggle .list-view-btn.active {
    background: rgba(240,180,41,0.14) !important;
    color: #f0b429 !important;
  }
  /* Hide "Tabela" view on mobile everywhere */
  .list-view-toggle [data-view="table"],
  .list-view-toggle [data-fview="table"],
  .list-view-toggle [data-mview="table"],
  .list-view-toggle [data-vview="table"] { display: none !important; }

  /* Truck select — full width, clean */
  .list-toolbar-ctrl:not([type="date"]) {
    width: 100% !important;
    flex: none !important;
    min-height: 44px;
  }

  /* Date preset group — neat 2-row grid */
  .date-preset-group {
    width: 100%;
    display: grid !important;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px !important;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
    border-radius: 12px;
    padding: 8px !important;
  }
  .date-preset-group > span:first-child { display: none !important; }
  .date-preset-group .list-view-btn {
    min-height: 38px;
    font-size: 11px;
    padding: 0 4px !important;
    border-radius: 9px !important;
    justify-content: center;
    white-space: nowrap;
  }
  /* "Personalizado" occupies the full second row */
  .date-preset-group .list-view-btn[data-_fl-preset="custom"],
  .date-preset-group .list-view-btn[data-_mfl-preset="custom"],
  .date-preset-group .list-view-btn[data-_fech-preset="custom"] {
    grid-column: 1 / -1;
  }
  .date-preset-group input[type="date"] {
    grid-column: 1 / -1;
    width: 100% !important;
    margin: 0 !important;
    min-height: 44px;
  }

  .list-toolbar-count {
    width: 100%;
    text-align: right;
    font-size: 11px;
    color: var(--text-muted);
    padding: 0 4px;
  }

  /* ——— Tables → horizontal scroll, no cramped cells ——— */
  .grid-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
    border-radius: 12px;
  }
  .grid-table {
    min-width: 640px;
    font-size: 12px;
  }
  .grid-table th,
  .grid-table td {
    padding: 10px 8px !important;
    white-space: nowrap;
  }
  .grid-row-del {
    min-width: 36px;
    min-height: 36px;
  }

  /* ——— Cards empilhados ——— */
  #main .card,
  #main [style*="grid-template-columns"]:not([style*="1fr 1fr"]) {
    grid-template-columns: 1fr !important;
  }

  /* Buttons — bigger tap targets */
  .btn, button.btn, .btn-primary, .btn-secondary, .btn-danger {
    min-height: 44px;
    font-size: 14px;
    border-radius: 12px;
  }
  .btn-sm { min-height: 36px; font-size: 12px; }

  /* Header "Nova X" buttons (inline-style, generated) */
  #main button[id^="btnNew"] {
    height: 44px !important;
    padding: 0 16px !important;
    font-size: 13px !important;
  }

  /* Page header strips (renderViagens/Manutenções/Fechamentos) */
  #main > div > div:first-child[style*="padding:20px 28px"],
  #main > div > div:first-child[style*="linear-gradient"] {
    padding: 14px 14px !important;
    gap: 10px !important;
    flex-wrap: wrap !important;
  }
  #main > div > div:first-child[style*="linear-gradient"] > div[style*="font-size:18px"] {
    font-size: 15px !important;
  }

  /* ——— Modais fullscreen ——— */
  body > div[style*="position:fixed"][style*="inset:0"][style*="z-index:9000"] {
    padding: 0 !important;
    align-items: stretch !important;
  }
  body > div[style*="position:fixed"][style*="inset:0"][style*="z-index:9000"] > div {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: 100vh !important;
    max-height: 100dvh !important;
    border-radius: 0 !important;
    padding-top: var(--safe-top) !important;
    padding-bottom: var(--safe-bottom) !important;
  }
  /* Modal internal 2-col grids → stack */
  body > div[style*="z-index:9000"] div[style*="grid-template-columns:1fr 320px"],
  body > div[style*="z-index:9000"] div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
  /* Hide live calc preview panel — form + "Total Líquido" card at bottom is enough */
  .calc-preview-panel { display: none !important; }
  /* Modal 2-col grids → single column form only */
  .modal-2col {
    display: block !important;
  }
  .modal-2col > div:first-child {
    width: 100% !important;
    border-right: none !important;
    padding: 16px 14px !important;
    overflow-y: auto;
  }

  /* ——— Inputs — bigger, no zoom on iOS ——— */
  .form-input, .form-select, input, select, textarea {
    font-size: 16px !important; /* prevents iOS zoom on focus */
    min-height: 44px;
    border-radius: 12px;
    padding: 10px 12px;
  }
  .form-group { margin-bottom: 14px; }
  .form-label { font-size: 12px; margin-bottom: 6px; }

  /* ——— Toolbars com filtros ——— */
  .date-presets {
    display: flex !important;
    flex-wrap: wrap;
    gap: 6px;
  }
  .date-presets button {
    flex: 1 1 calc(33% - 6px);
    min-height: 38px;
    font-size: 11px;
  }

  /* ——— Toasts ——— */
  #toastContainer {
    left: 10px !important;
    right: 10px !important;
    bottom: calc(12px + var(--safe-bottom)) !important;
    max-width: none !important;
  }

  /* ——— Auth overlay ——— */
  #authOverlay .auth-box {
    width: 92vw !important;
    max-width: 420px;
    padding: 20px !important;
  }

  /* ——— Fin cost items ——— */
  .fin-cost-item { padding: 10px 8px !important; }
  .fin-cost-label { font-size: 12px !important; }
  .fin-cost-value { font-size: 12px !important; }
}

/* =====================================================
   EXTRA SMALL (≤ 380px)  — iPhone SE / mini
   ===================================================== */
@media (max-width: 380px) {
  .fin-dash-kpis { grid-template-columns: 1fr !important; }
  .fin-dash-kpi-value { font-size: 20px !important; }
  .nav-logo-img { width: 110px; }
  .op-switch-btn { font-size: 12px !important; padding: 0 10px !important; }
}

/* =====================================================
   PWA standalone — hide browser UI artifacts
   ===================================================== */
@media all and (display-mode: standalone) {
  body {
    overscroll-behavior-y: contain;
  }
  #header {
    padding-top: calc(var(--safe-top) + 6px) !important;
    height: calc(52px + var(--safe-top));
  }
}

/* =====================================================
   Compact date filter + bottom sheet (all viewports)
   ===================================================== */
.date-filter-btn {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(240,180,41,0.22);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.date-filter-btn:hover {
  background: rgba(240,180,41,0.08);
  border-color: rgba(240,180,41,0.45);
}
.date-filter-btn:active { transform: scale(0.98); }
.date-filter-label { color: #f0b429; }
.date-filter-caret { color: rgba(240,180,41,0.7); font-size: 12px; }

@media (max-width: 768px) {
  .date-filter-btn {
    width: 100%;
    justify-content: space-between;
  }
}

/* Bottom sheet overlay */
.date-sheet-overlay {
  position: fixed;
  inset: 0;
  z-index: 9500;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  transition: opacity .22s ease;
}
.date-sheet-overlay.show { opacity: 1; }

.date-sheet {
  width: 100%;
  max-width: 460px;
  background: linear-gradient(160deg, rgba(16,22,42,0.99), rgba(10,14,30,0.99));
  border: 1px solid rgba(255,255,255,0.08);
  border-bottom: none;
  border-radius: 22px 22px 0 0;
  padding: 14px 18px calc(22px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -24px 60px rgba(0,0,0,0.55);
  transform: translateY(100%);
  transition: transform .28s cubic-bezier(.4,0,.2,1);
}
.date-sheet-overlay.show .date-sheet { transform: translateY(0); }

.date-sheet-handle {
  width: 42px;
  height: 4px;
  background: rgba(255,255,255,0.18);
  border-radius: 3px;
  margin: 2px auto 14px;
}
.date-sheet-title {
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: rgba(240,180,41,0.8);
  margin-bottom: 12px;
  padding-left: 4px;
}
.date-sheet-list { display: flex; flex-direction: column; gap: 4px; }
.date-sheet-opt {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-height: 50px;
  padding: 12px 16px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  -webkit-tap-highlight-color: transparent;
}
.date-sheet-opt:hover {
  background: rgba(240,180,41,0.06);
  border-color: rgba(240,180,41,0.22);
}
.date-sheet-opt.active {
  background: rgba(240,180,41,0.14);
  border-color: rgba(240,180,41,0.45);
  color: #f0b429;
  font-weight: 700;
}
.date-sheet-opt > span { display: inline-flex; align-items: center; gap: 8px; }
.date-sheet-check { color: #f0b429; }
.date-sheet-sep {
  height: 1px;
  background: rgba(255,255,255,0.08);
  margin: 12px 6px;
}
.date-sheet-custom {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 10px 12px;
  margin-top: 12px;
  padding: 14px;
  background: rgba(255,255,255,0.03);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  align-items: center;
}
.date-sheet-custom label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 600;
}
.date-sheet-custom input[type="date"] {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  background: rgba(0,0,0,0.28);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 10px;
  color: var(--text-primary);
  font-size: 14px;
}
.date-sheet-apply {
  grid-column: 1 / -1;
  min-height: 46px;
  background: linear-gradient(135deg, #f0b429, #f0b429cc);
  color: #000;
  font-weight: 700;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  margin-top: 4px;
}
.date-sheet-close {
  width: 100%;
  min-height: 46px;
  margin-top: 14px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

/* Desktop: center sheet instead of bottom */
@media (min-width: 769px) {
  .date-sheet-overlay { align-items: center; }
  .date-sheet {
    border-radius: 22px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    max-width: 420px;
    transform: translateY(20px) scale(0.96);
    padding-bottom: 22px;
  }
  .date-sheet-overlay.show .date-sheet { transform: translateY(0) scale(1); }
  .date-sheet-handle { display: none; }
}

/* =====================================================
   Desktop unchanged above 768px — keep original layout
   ===================================================== */
