/**
 * Responsividade global — breakpoints unificados.
 * Carregado por último para sobrescrever regras conflitantes.
 *
 * sm  640px  — celular
 * md  768px  — celular grande
 * lg  1024px — tablet
 * xl  1200px — desktop estreito
 */

/* ── Tablet e abaixo (≤1024px) ── */
@media (max-width: 1024px) {
  :root {
    --sidebar-w: 260px;
  }

  .sidebar-toggle {
    display: inline-flex;
  }

  .sidebar {
    width: min(var(--sidebar-w), 88vw);
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    z-index: 120;
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    margin-left: 0 !important;
    width: 100% !important;
    max-width: none !important;
    padding: 1rem 1.25rem 1.5rem;
  }

  .app-topbar {
    padding: 0 1rem;
    margin: 0 -1.25rem 0;
    width: calc(100% + 2.5rem);
  }

  .page-header {
    flex-direction: column;
    align-items: stretch !important;
    margin-bottom: 1.25rem;
    gap: 0.75rem;
  }

  .page-header h1 {
    font-size: 1.35rem;
  }

  .header-actions,
  .page-actions {
    width: 100%;
    margin-left: 0 !important;
    justify-content: flex-start;
  }

  .form-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .form-row {
    grid-template-columns: 1fr 1fr;
  }

  .profit-calc-layout {
    grid-template-columns: 1fr;
  }

  .profit-calc-sidebar {
    position: static;
    max-height: none;
  }

  .profit-results-grid {
    grid-template-columns: 1fr;
  }

  .settings-panel-body {
    grid-template-columns: 1fr;
  }

  .settings-section {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .settings-section:last-child {
    border-bottom: none;
  }

  .settings-fields-grid {
    grid-template-columns: 1fr;
  }

  .admin-stats {
    grid-template-columns: repeat(2, 1fr);
  }

  .card-header-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .card-header-row .toggle {
    align-self: flex-start;
  }

  .orders-toolbar-row {
    flex-direction: column;
    align-items: stretch;
  }

  .orders-toolbar-actions,
  .orders-filters-bar {
    width: 100%;
  }
}

/* ── Celular grande (≤768px) ── */
@media (max-width: 768px) {
  .main {
    padding: 0.85rem 1rem 1.25rem;
  }

  .app-topbar {
    margin: 0 -1rem 0;
    width: calc(100% + 2rem);
    padding: 0 0.85rem;
  }

  .page-header h1 {
    font-size: 1.25rem;
  }

  .subtitle {
    font-size: 0.85rem;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .image-preview-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .settings-banner-top {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-banner .toggle {
    align-self: stretch;
    justify-content: space-between;
  }

  .settings-footer {
    flex-direction: column;
    align-items: stretch;
  }

  .settings-footer .btn {
    width: 100%;
  }

  .sidebar-bottom {
    max-height: none;
  }

  .platform-status {
    display: none;
  }

  .sidebar-user-name,
  .sidebar-user-email,
  .sidebar-user-plan {
    display: none;
  }

  .sidebar-user-card {
    padding: 0.35rem;
    align-items: center;
  }

  .sidebar-user-card .btn {
    padding: 0.4rem;
    font-size: 0.7rem;
  }

  .header-actions .btn-primary,
  .page-actions .btn-primary {
    flex: 1;
    justify-content: center;
  }

  .auth-panel {
    padding: 1rem;
  }

  .auth-card {
    padding: 1.25rem;
  }

  .admin-stats {
    grid-template-columns: 1fr;
  }

  .history-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.35rem;
  }

  .modal {
    width: 96vw;
    max-height: 92vh;
  }

  .modal-body {
    max-height: 65vh;
    padding: 1rem;
  }

  .modal-header,
  .modal-footer {
    padding: 0.85rem 1rem;
  }

  .preview-tabs {
    flex-wrap: wrap;
  }

  .description-gen-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .label-row {
    flex-direction: column;
    align-items: stretch;
  }

  .orders-bulk-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .orders-bulk-actions {
    flex-wrap: wrap;
  }

  .orders-bulk-hint {
    margin-left: 0;
  }

  .orders-col-ordered {
    display: none;
  }

  .invoices-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .invoices-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .invoices-item-row {
    grid-template-columns: 1fr;
  }

  .ml-search-row {
    flex-direction: column;
    align-items: stretch;
  }

  .ml-campaign-select-row {
    flex-direction: column;
  }
}

/* ── Celular (≤640px) ── */
@media (max-width: 640px) {
  .dashboard-grid,
  .dashboard-status-grid {
    grid-template-columns: 1fr;
  }

  .dashboard-welcome {
    padding: 1.25rem;
  }

  .breadcrumb-item:not(:last-child) {
    display: none;
  }

  .breadcrumb-item--current::before {
    content: '← ';
    opacity: 0.5;
  }

  .page-actions,
  .header-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .page-actions .btn,
  .header-actions .btn {
    width: 100%;
    justify-content: center;
  }

  .action-menu {
    width: 100%;
  }

  .action-menu > .btn {
    width: 100%;
  }

  .action-menu-panel {
    left: 0;
    right: 0;
    width: 100%;
  }

  .btn-sm {
    min-height: 2.25rem;
  }

  .nav-item {
    padding: 0.85rem 0.9rem;
    min-height: 2.75rem;
  }

  .card {
    padding: 1rem;
  }

  .auth-layout {
    grid-template-columns: 1fr;
  }

  .auth-brand {
    display: none;
  }

  .orders-col-buyer {
    display: none;
  }

  /* Tabela de pedidos → cards */
  .orders-table-wrap {
    overflow-x: visible;
    background: transparent;
    border: none;
    box-shadow: none;
  }

  .orders-table,
  .orders-table tbody {
    display: block;
    width: 100%;
  }

  .orders-table thead {
    display: none;
  }

  .orders-table tbody tr {
    display: block;
    margin-bottom: 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.65rem 0.85rem;
    background: var(--bg-card);
  }

  .orders-table tbody tr:hover {
    background: var(--bg-card);
  }

  .orders-table td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.45rem 0;
    border-bottom: 1px solid var(--border);
    text-align: right;
    width: 100%;
  }

  .orders-table td:last-child {
    border-bottom: none;
    padding-bottom: 0;
  }

  .orders-table td[data-label]::before {
    content: attr(data-label);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted);
    text-align: left;
    flex-shrink: 0;
    padding-top: 0.1rem;
  }

  .orders-table td.orders-col-check {
    border-bottom: 1px solid var(--border);
    justify-content: flex-start;
    padding-bottom: 0.5rem;
    margin-bottom: 0.15rem;
  }

  .orders-table td.orders-col-check::before {
    content: 'Selecionar';
  }

  .orders-table td.orders-col-items {
    flex-direction: column;
    align-items: stretch;
    text-align: left;
  }

  .orders-table td.orders-col-items::before {
    margin-bottom: 0.35rem;
  }

  .orders-table td.orders-col-actions {
    position: static;
    box-shadow: none;
    flex-direction: column;
    align-items: stretch;
    text-align: left;
    min-width: 0;
    background: transparent !important;
  }

  .orders-table td.orders-col-actions::before {
    margin-bottom: 0.35rem;
  }

  .orders-table td.orders-col-actions .orders-actions-wrap {
    flex-wrap: wrap;
    gap: 0.35rem;
  }

  .orders-table td.orders-col-actions .orders-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  /* Mobile: todas as ações visíveis, sem dropdown preso no card */
  .orders-actions > .btn.orders-action-btn {
    display: none;
  }

  .orders-action-menu {
    width: 100%;
  }

  .orders-action-menu-toggle {
    display: none;
  }

  .orders-action-menu-panel {
    position: static !important;
    display: flex !important;
    flex-direction: column;
    gap: 0.35rem;
    box-shadow: none;
    border: none;
    padding: 0;
    margin-top: 0.35rem;
    background: transparent;
    min-width: 0;
  }

  .orders-action-menu-panel[hidden] {
    display: flex !important;
  }

  .orders-action-menu-item {
    width: 100%;
    text-align: center;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
  }

  .orders-action-menu-item.btn-primary {
    margin-bottom: 0;
  }

  .orders-table td.orders-col-order,
  .orders-table td.orders-col-buyer,
  .orders-table td.orders-col-ordered {
    max-width: none;
    white-space: normal;
    overflow: visible;
    text-overflow: unset;
  }

  .orders-item-line {
    -webkit-line-clamp: 3;
  }

  .profit-calc-form-card .form-row {
    grid-template-columns: 1fr;
  }

  .orders-listing-fiscal-modal .form-row {
    grid-template-columns: 1fr;
  }

  .fiscal-settings-form .form-row {
    grid-template-columns: 1fr;
  }
}

/* ── Celular pequeno (≤480px) ── */
@media (max-width: 480px) {
  .main {
    padding: 0.65rem 0.75rem 1rem;
  }

  .app-topbar {
    margin: 0 -0.75rem 0;
    width: calc(100% + 1.5rem);
    min-height: 46px;
  }

  .logo {
    padding-bottom: 1rem;
  }

  .image-preview-grid {
    grid-template-columns: 1fr;
  }

  .orders-tabs,
  .orders-view-tabs {
    width: 100%;
  }

  .orders-tab,
  .orders-view-tab {
    flex: 1;
    text-align: center;
    justify-content: center;
  }

  .orders-filter-field--status,
  .orders-filter-group--dates {
    flex: 1 1 100%;
    min-width: 0;
  }

  .orders-filter-range {
    flex-direction: column;
    align-items: stretch;
  }

  .orders-filter-field--date {
    min-width: 0;
    max-width: none;
    width: 100%;
  }

  .orders-filter-range-sep {
    display: none;
  }

  .toast-container {
    left: 0.75rem;
    right: 0.75rem;
    max-width: none;
  }
}

/* Auth: painel único em telas médias */
@media (max-width: 900px) {
  .auth-layout {
    grid-template-columns: 1fr;
  }

  .auth-brand {
    display: none;
  }
}

/* Desktop estreito — colunas de pedidos */
@media (max-width: 1050px) {
  .orders-col-ordered {
    display: none;
  }
}

@media (max-width: 900px) {
  .orders-col-buyer {
    display: none;
  }
}
