/* Camada responsiva isolada do CSS legado para manter codificação e rollback seguros. */
html {
  min-width: 0;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body,
.layout-wrapper,
.main-layout,
.main-content-wrapper,
main {
  min-width: 0;
}

img,
svg {
  max-width: 100%;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
a,
input,
select,
textarea {
  -webkit-tap-highlight-color: transparent;
}

:focus-visible {
  outline: 3px solid #7dd3fc;
  outline-offset: 2px;
}

.mobile-app-bar,
.mobile-nav-backdrop {
  display: none;
}

.share-feedback {
  position: fixed;
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  z-index: 1200;
  max-width: min(90vw, 360px);
  padding: .75rem 1rem;
  border-radius: 10px;
  color: #fff;
  background: #145744;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .3);
}

.document-share {
  background: #257fa4;
}

.uc-row {
  display: block !important;
  width: 100%;
  margin: 0 0 14px !important;
  padding: 14px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  background: rgba(0, 0, 0, .16);
}

.uc-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border-color);
}

.uc-card-title {
  color: var(--text-primary);
  font-size: .95rem;
}

.uc-fields-grid {
  display: grid;
  grid-template-columns: 1.4fr 1.2fr 1.2fr .8fr 1.2fr;
  gap: 12px;
}

.uc-field {
  min-width: 0;
  margin: 0;
}

.uc-field-label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-secondary);
  font-size: .78rem;
  font-weight: 600;
}

.uc-field input,
.uc-field select {
  width: 100% !important;
}

.btn-remove-uc {
  width: 40px;
  min-width: 40px;
  min-height: 40px;
  padding: 0;
  font-size: 1.25rem;
}

@media (max-width: 1100px) {
  .dashboard-content {
    padding: 32px !important;
  }

  .dashboard-controls {
    width: 100%;
    flex-wrap: wrap;
  }

  .dashboard-controls .search-box {
    flex: 1 1 320px;
  }

  .main-header {
    align-items: flex-start;
  }

  .header-actions {
    width: 100%;
  }
}

@media (max-width: 900px) {
  body {
    padding-top: calc(60px + env(safe-area-inset-top));
  }

  body.login-body,
  body.document-page {
    padding-top: 0;
  }

  body.document-page .print-actions {
    width: calc(100% - 24px);
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
  }

  body.document-page .print-actions > button {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 10px 8px;
    justify-content: center;
    text-align: center;
  }

  body.document-page #document-wrapper,
  body.document-page #contract-document-wrapper {
    width: 100%;
    overflow: hidden;
  }

  .mobile-app-bar {
    position: fixed;
    inset: 0 0 auto 0;
    z-index: 1100;
    height: calc(60px + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(12px, env(safe-area-inset-right)) 0 max(12px, env(safe-area-inset-left));
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    color: var(--text-primary, #fff);
    background: rgba(25, 40, 38, .97);
    border-bottom: 1px solid var(--border-color, rgba(255, 255, 255, .15));
    backdrop-filter: blur(16px);
  }

  .mobile-app-bar-title {
    min-width: 0;
    overflow: hidden;
    font-size: 1rem;
    font-weight: 700;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .mobile-app-bar-actions {
    display: flex;
    gap: 8px;
  }

  .mobile-menu-button,
  .mobile-share-button {
    width: 44px;
    height: 44px;
    display: inline-grid;
    place-items: center;
    flex: 0 0 auto;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 10px;
    color: inherit;
    background: rgba(255, 255, 255, .07);
  }

  .mobile-menu-button svg,
  .mobile-share-button svg {
    width: 22px;
    height: 22px;
  }

  .sidebar {
    position: fixed;
    z-index: 1150;
    inset: 0 auto 0 0;
    width: min(82vw, 300px);
    height: 100dvh;
    padding-top: max(24px, env(safe-area-inset-top));
    padding-bottom: max(24px, env(safe-area-inset-bottom));
    overflow-y: auto;
    transform: translateX(-105%);
    transition: transform .22s ease;
    box-shadow: 16px 0 40px rgba(0, 0, 0, .35);
    background: #102b25 !important;
    backdrop-filter: none;
  }

  body.nav-open {
    overflow: hidden;
  }

  body.nav-open .sidebar {
    transform: translateX(0);
  }

  .mobile-nav-backdrop {
    position: fixed;
    z-index: 1120;
    inset: 0;
    border: 0;
    background: rgba(0, 0, 0, .72);
  }

  body.nav-open .mobile-nav-backdrop {
    display: block;
  }

  .sidebar-nav a {
    min-height: 48px;
    display: flex;
    align-items: center;
  }

  .layout-wrapper,
  .main-layout {
    display: block !important;
    min-height: calc(100dvh - 60px);
  }

  .main-content-wrapper,
  .main-layout > main {
    width: 100%;
    max-height: none;
    min-height: calc(100dvh - 60px) !important;
    overflow: visible !important;
  }

  .app-container {
    width: 100%;
    padding: 16px;
    gap: 16px;
  }

  .dashboard-content,
  .profile-page-content {
    width: 100%;
    max-width: none !important;
    padding: 24px 16px !important;
  }

  .dashboard-header,
  .main-header,
  .filter-bar {
    align-items: stretch;
  }

  .dashboard-controls,
  .header-actions,
  .filters,
  .backup-group {
    width: 100%;
  }

  .dashboard-controls > *,
  .header-actions > .btn,
  .backup-group > .btn {
    flex: 1 1 auto;
  }

  .search-box {
    min-width: 0;
    width: 100%;
  }

  .filters {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  }

  .results-info {
    width: 100%;
    margin-left: 0;
  }

  #kanban-view {
    width: calc(100vw - 32px);
    margin-inline: 0;
    padding-bottom: 20px;
    overscroll-behavior-inline: contain;
    scroll-snap-type: x proximity;
    -webkit-overflow-scrolling: touch;
  }

  .kanban-col {
    width: min(82vw, 340px);
    min-width: min(82vw, 340px);
    max-height: none;
    scroll-snap-align: start;
  }

  .kanban-cards {
    max-height: none;
    overflow: visible;
  }

  .client-list-item {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 10px;
  }

  .client-list-item > * {
    min-width: min(100%, 220px);
    flex: 1 1 220px !important;
  }

  .main-content {
    grid-template-columns: minmax(0, 1fr);
  }

  .detail-container {
    position: static;
  }

  .tree-root {
    max-height: none;
    overflow: auto;
    overscroll-behavior-inline: contain;
    -webkit-overflow-scrolling: touch;
  }

  .tree-root > .tree-list {
    min-width: 520px;
    padding-bottom: 8px;
  }

  .node-actions {
    opacity: 1;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .modal-content,
  .modal-content.max-w-xl,
  .modal-content.max-w-2xl,
  .modal-content.max-w-3xl {
    width: 100%;
    max-width: none;
    max-height: calc(100dvh - 16px) !important;
    overflow: auto;
    border-radius: 16px 16px 8px 8px;
  }

  .card-footer,
  .modal-actions,
  .form-actions-sticky,
  .profile-actions {
    flex-wrap: wrap;
  }

  .card-footer > *,
  .modal-actions > *,
  .form-actions-sticky > *,
  .profile-actions > * {
    min-height: 44px;
  }

  .contract-uc-distributor-row {
    align-items: stretch;
    flex-direction: column;
    gap: 8px;
  }

  .uc-fields-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .btn-remove-uc {
    width: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    font-size: 1.25rem;
  }

  .uc-distributor-row {
    padding: 14px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: rgba(0, 0, 0, .16);
  }

  .uc-distributor-row label {
    line-height: 1.45;
  }

  .uc-distributor-card-heading {
    display: flex;
    flex-direction: column;
    gap: 3px;
    margin-bottom: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border-color);
  }

  .uc-distributor-card-heading strong {
    color: var(--text-primary);
  }

  .uc-distributor-card-heading span {
    color: var(--text-muted);
    font-size: .8rem;
    overflow-wrap: anywhere;
  }

  .uc-distributor-row .distributor-dropdown-list {
    max-height: min(45dvh, 320px);
    overflow-y: auto;
  }

  .modal-tabs {
    overflow-x: auto;
    gap: 18px;
    padding-inline: 16px;
    scrollbar-width: thin;
  }

  .tab-btn {
    flex: 0 0 auto;
    min-height: 44px;
    white-space: nowrap;
  }

  .toast {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
    left: max(12px, env(safe-area-inset-left));
  }
}

@media (max-width: 600px) {
  body.document-page .print-actions {
    grid-template-columns: 1fr;
  }

  .dashboard-title,
  .profile-title {
    font-size: clamp(1.6rem, 8vw, 2rem) !important;
  }

  .main-header,
  .filter-bar,
  .profile-card,
  .card-body,
  .card-header,
  .card-footer {
    padding: 16px !important;
  }

  .logo-area {
    flex-wrap: wrap;
  }

  .logo-area .divider {
    display: none;
  }

  .logo-area .subtitle {
    flex-basis: 100%;
  }

  .filters,
  .form-row,
  .btn-grid,
  .uc-fields-grid {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .ucs-section-header {
    align-items: flex-start !important;
    gap: 12px;
  }

  .ucs-section-header h3 {
    line-height: 1.4;
  }

  .ucs-section-header #btn-add-uc {
    width: auto;
    min-width: 112px;
    min-height: 44px;
    padding: 8px 12px !important;
  }

  .dashboard-controls > *,
  .header-actions > *,
  .backup-group > *,
  .view-toggle,
  .view-toggle .btn,
  .card-footer > *,
  .modal-actions > *,
  .form-actions-sticky > *,
  .profile-actions > * {
    width: 100%;
    margin-left: 0 !important;
  }

  .backup-group {
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-left: 0;
    padding-left: 0;
    border-left: 0;
  }

  .view-toggle .btn {
    min-width: 0;
  }

  .profile-card {
    margin-top: 16px;
  }

  .profile-header {
    align-items: flex-start;
  }

  .uploaded-file-item,
  .uploaded-file-info,
  .detail-value-with-action,
  .email-status-container {
    align-items: flex-start !important;
    flex-wrap: wrap;
    gap: 8px;
  }

  .uploaded-file-link,
  .uploaded-file-info,
  .uploaded-file-item span {
    min-width: 0;
    max-width: 100% !important;
    overflow-wrap: anywhere;
    white-space: normal !important;
  }

  input,
  select,
  textarea {
    min-height: 44px;
    font-size: 16px !important;
  }

  .btn,
  .btn-icon-only,
  .btn-close,
  .node-toggle-btn,
  button {
    min-height: 44px;
  }
}

@media (max-width: 380px) {
  .app-container,
  .dashboard-content,
  .profile-page-content {
    padding-inline: 10px !important;
  }

  #kanban-view {
    width: calc(100vw - 20px);
  }

  .kanban-col {
    width: 88vw;
    min-width: 88vw;
  }
}

@media (orientation: landscape) and (max-height: 540px) {
  .modal-overlay {
    align-items: stretch;
  }

  .login-container {
    margin-block: 12px;
    padding-block: 20px !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}

@media print {
  .mobile-app-bar,
  .mobile-nav-backdrop,
  .share-feedback,
  .document-share {
    display: none !important;
  }
}
