/* Interface móvel do Sistema CPL — Android e telas compactas */
@media (max-width: 720px), (max-width: 950px) and (max-height: 520px) {
  :root {
    color-scheme: light;
  }

  html {
    min-width: 0;
    overflow-x: hidden;
    -webkit-text-size-adjust: 100%;
  }

  body.preview-app {
    min-width: 0;
    overflow-x: hidden;
    padding: 0;
    overscroll-behavior-y: none;
  }

  button,
  input,
  select,
  textarea {
    font-size: 16px;
  }
  button,
  input,
  select {
    min-height: 44px;
  }
  button,
  .nav-item,
  .table-action {
    touch-action: manipulation;
  }

  /* Login */
  .login-screen {
    min-height: 100dvh;
    padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
    box-sizing: border-box;
  }

  .login-card {
    width: 100%;
    max-width: 390px;
    padding: 28px 22px;
    border-radius: 18px;
  }

  .login-logo {
    width: 132px;
    height: 48px;
    margin-bottom: 14px;
  }
  .login-card h1 {
    font-size: 24px;
    line-height: 1.15;
  }
  .login-card > p {
    margin-bottom: 20px;
    line-height: 1.45;
  }
  .login-card label {
    margin: 12px 0;
  }
  .login-card input,
  .login-card button {
    min-height: 48px;
  }

  /* Estrutura principal e navegação inferior */
  .app-shell {
    display: block;
    min-height: 100dvh;
  }

  .sidebar {
    position: fixed;
    z-index: 1000;
    inset: auto 0 0;
    width: 100%;
    height: calc(72px + env(safe-area-inset-bottom));
    padding: 7px 8px max(7px, env(safe-area-inset-bottom));
    display: block;
    background: rgba(24, 36, 59, 0.98);
    border-top: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 -8px 28px rgba(12, 20, 34, 0.22);
    backdrop-filter: blur(14px);
  }

  .side-logo,
  .side-user {
    display: none !important;
  }

  .sidebar nav {
    display: flex;
    align-items: stretch;
    gap: 5px;
    height: 58px;
    padding: 0 0 3px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
    scrollbar-width: none;
  }

  .sidebar nav::-webkit-scrollbar {
    display: none;
  }

  .sidebar .nav-item {
    flex: 0 0 76px;
    min-width: 76px;
    min-height: 54px;
    padding: 6px 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    border-radius: 11px;
    text-align: center;
    font-size: 17px;
    line-height: 1;
    scroll-snap-align: start;
  }

  .sidebar .nav-item span {
    display: block !important;
    max-width: 70px;
    color: inherit;
    font-size: 9px;
    font-weight: 750;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .sidebar .nav-item.active {
    background: #314563;
    box-shadow: inset 0 -3px var(--gold);
  }

  .workspace {
    width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding: 0 12px calc(94px + env(safe-area-inset-bottom));
  }

  .workspace-header {
    min-height: 72px;
    height: auto;
    margin-bottom: 17px;
    padding: max(10px, env(safe-area-inset-top)) 0 10px;
    gap: 10px;
    align-items: center;
  }

  .workspace-header h1 {
    font-size: 21px;
    line-height: 1.15;
  }
  .eyebrow {
    font-size: 9px;
    letter-spacing: 1.15px;
  }
  .header-actions {
    gap: 6px;
    justify-content: flex-end;
  }
  .header-actions .session-chip {
    display: none;
  }
  .refresh-system-btn {
    min-width: 46px;
    min-height: 44px;
    padding: 8px 10px;
    font-size: 0;
  }
  .refresh-system-btn::before {
    content: '↻';
    font-size: 21px;
  }

  /* Conteúdo geral */
  .welcome-strip {
    padding: 16px;
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .role-badge {
    align-self: flex-start;
  }
  .stats-grid,
  #view-emissao .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 9px;
  }
  .stats-grid article {
    min-width: 0;
    padding: 14px;
  }
  .stats-grid strong {
    font-size: 19px;
  }

  .content-grid,
  .server-grid,
  .two-cols,
  .permissions-layout,
  .compact-permissions,
  .import-steps {
    grid-template-columns: 1fr !important;
  }

  .panel {
    max-width: 100%;
    padding: 15px !important;
    border-radius: 12px !important;
  }

  .page-heading {
    margin-bottom: 14px;
  }
  .page-heading h2 {
    font-size: 21px;
  }
  .page-heading p {
    font-size: 13px;
    line-height: 1.45;
  }

  .filter-row {
    flex-direction: column;
  }
  .filter-row input,
  .filter-row select {
    width: 100%;
    box-sizing: border-box;
    min-height: 46px;
  }

  .data-table,
  .batch-table {
    min-width: 680px;
  }
  .batch-table-wrap,
  .preview-card {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .table-action {
    min-height: 44px;
    padding: 8px 10px;
    margin: 2px;
  }

  /* Janelas e formulários */
  dialog,
  #transportRouteDialog,
  .transport-print-dialog,
  .term-preview-dialog {
    width: calc(100vw - 16px) !important;
    max-width: none !important;
    max-height: calc(100dvh - 16px) !important;
    margin: auto !important;
    border-radius: 16px !important;
    box-sizing: border-box;
  }

  dialog form {
    max-height: calc(100dvh - 16px);
    padding: 17px;
    overflow-y: auto;
    box-sizing: border-box;
  }
  dialog input,
  dialog select,
  dialog textarea {
    width: 100%;
    min-height: 46px;
    box-sizing: border-box;
  }
  dialog textarea {
    min-height: 86px;
    resize: vertical;
  }
  .dialog-head {
    gap: 10px;
  }
  .dialog-head h2 {
    font-size: 19px;
    margin: 0;
  }
  .dialog-head > button {
    flex: 0 0 44px;
    width: 44px;
    height: 44px;
    padding: 0;
  }

  .dialog-actions {
    position: sticky;
    bottom: 0;
    z-index: 2;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 17px -2px -2px;
    padding: 12px 2px 2px;
    background: linear-gradient(transparent, #fff 16%);
  }

  .dialog-actions button {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 46px;
  }
  .transport-route-form-body {
    max-height: calc(100dvh - 175px);
    padding-right: 3px;
  }
  .transport-person-card {
    padding: 12px;
  }

  /* Transporte */
  .transport-page-heading {
    gap: 14px;
    margin-bottom: 16px;
  }
  .transport-page-heading h2 {
    font-size: 24px;
    margin: 4px 0;
  }
  .transport-page-heading p {
    font-size: 12px;
    line-height: 1.45;
  }
  .transport-heading-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .transport-heading-actions .transport-button {
    width: 100%;
    min-width: 0;
    height: 45px !important;
  }

  .transport-stats {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px;
  }
  .transport-stats article {
    min-width: 0;
    padding: 12px 10px;
    gap: 9px;
  }
  .transport-stat-icon {
    width: 37px;
    height: 37px;
    flex: 0 0 37px;
  }
  .transport-stats strong {
    font-size: 18px;
  }
  .transport-stats p {
    display: none;
  }

  .transport-workspace {
    min-height: 0;
    border-radius: 12px;
  }
  .transport-route-list-panel {
    padding: 15px 12px;
  }
  .transport-search {
    height: 46px;
  }
  .transport-search input {
    font-size: 16px !important;
  }
  .transport-route-list {
    max-height: 300px;
    overflow-y: auto;
  }
  .transport-route-card-content {
    padding: 14px 12px;
  }
  .transport-route-top b {
    font-size: 13px;
  }
  .transport-route-meta,
  .transport-route-person {
    font-size: 11px;
  }

  .transport-empty {
    min-height: 260px;
    padding: 24px 15px;
  }
  .transport-detail-head {
    padding: 17px 14px 14px;
    align-items: flex-start;
  }
  .transport-detail-head h3 {
    font-size: 17px;
  }
  .transport-detail-actions {
    width: 100%;
    margin: 4px 0 0;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  .transport-detail-actions .transport-button {
    width: 100%;
    min-width: 0;
    height: 44px !important;
    white-space: normal;
  }
  .transport-detail-actions .transport-button:last-child {
    grid-column: 1 / -1;
  }

  .transport-tabs {
    height: 48px;
    padding: 0 14px;
    gap: 18px;
    overflow-x: auto;
  }
  .transport-tabs button {
    min-width: max-content;
    font-size: 13px;
  }
  .transport-overview,
  .transport-seat-page {
    padding: 15px 13px;
  }
  .transport-info-cards {
    grid-template-columns: 1fr !important;
  }
  .transport-info-cards article {
    padding: 13px;
  }
  .transport-info-cards small {
    font-size: 9px;
  }
  .transport-info-cards strong {
    font-size: 12px;
  }
  .transport-info-cards p {
    font-size: 10px;
  }

  .transport-timeline {
    padding: 4px 11px;
  }
  .transport-stop {
    grid-template-columns: 24px 45px 1fr;
    min-height: 62px;
  }
  .transport-stop time,
  .transport-stop strong {
    font-size: 11px;
  }
  .transport-stop p {
    font-size: 9px;
  }

  .transport-seat-summary {
    align-items: flex-start;
    flex-wrap: wrap;
  }
  .transport-seat-summary > .transport-button {
    width: 100%;
    min-width: 0 !important;
    height: 44px !important;
  }
  .transport-seat-toolbar {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }
  .transport-legend {
    flex-wrap: wrap;
    font-size: 10px;
  }
  .transport-seat-layout {
    grid-template-columns: 1fr !important;
  }
  .transport-vehicle {
    padding: 15px 17px 12px;
    border-radius: 34px 34px 16px 16px;
  }
  .transport-map-seat {
    min-height: 44px;
    font-size: 10px;
  }
  .transport-seat-detail {
    min-height: 190px;
    padding: 14px;
  }
  .transport-seat-detail label {
    font-size: 12px;
  }
  .transport-seat-detail select,
  .transport-seat-detail input {
    font-size: 16px;
    min-height: 46px;
  }

  .transport-fleet {
    padding: 14px 12px;
  }
  .transport-fleet-cards {
    grid-template-columns: 1fr !important;
  }
  .transport-fleet-cards article {
    padding: 13px;
  }
  .transport-fleet-cards small {
    font-size: 9px;
  }
  .transport-fleet-cards strong {
    font-size: 13px;
  }
  .transport-fleet-cards p {
    font-size: 10px;
  }

  .transport-print-dialog,
  .term-preview-dialog {
    padding: 16px !important;
    overflow-y: auto;
  }
  .transport-print-document {
    padding: 8px 0;
    font-size: 11px;
  }
  .transport-print-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }
  .transport-print-head img {
    width: 130px;
    height: 44px;
  }
  .transport-print-head h1 {
    font-size: 18px;
  }
  .transport-print-info,
  .transport-signatures {
    grid-template-columns: 1fr;
    gap: 10px;
  }
  .transport-print-document table {
    display: block;
    overflow-x: auto;
    font-size: 10px;
  }
  .transport-signatures {
    margin-top: 42px;
    gap: 45px;
  }

  /* Termos e etiquetas */
  .term-document {
    padding: 14px 0;
    font-size: 12px;
  }
  .term-document-title {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }
  .term-document-title div {
    text-align: left;
  }
  .term-person {
    grid-template-columns: 1fr;
  }
  .term-person div:nth-child(odd) {
    border-right: 0;
  }
  .term-document table {
    display: block;
    max-width: 100%;
    overflow-x: auto;
  }
  .term-signatures {
    grid-template-columns: 1fr;
    gap: 45px;
    margin-top: 45px;
  }
}

@media (max-width: 340px) {
  .workspace {
    padding-inline: 9px;
  }
  .stats-grid,
  #view-emissao .stats-grid {
    grid-template-columns: 1fr;
  }
  .transport-heading-actions,
  .transport-stats {
    grid-template-columns: 1fr !important;
  }
  .transport-detail-actions {
    grid-template-columns: 1fr;
  }
  .transport-detail-actions .transport-button:last-child {
    grid-column: auto;
  }
}

@media (max-width: 950px) and (max-height: 520px) and (orientation: landscape) {
  .sidebar {
    height: calc(64px + env(safe-area-inset-bottom));
  }
  .sidebar nav {
    height: 50px;
  }
  .sidebar .nav-item {
    min-height: 48px;
  }
  .workspace {
    padding-bottom: calc(82px + env(safe-area-inset-bottom));
  }
}
