/* ==========================================================================
   Romaneio – Sistema de Controle
   Tema derivado da identidade visual (touro, azul-marinho + azul aço)
   ========================================================================== */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap");

:root {
  --navy-950: #07142e;
  --navy-900: #0a1d44;
  --navy-800: #0c2559;
  --navy-700: #123273;
  --steel-500: #4f6d94;
  --steel-300: #93a9c6;
  --primary-color: #1d4ed8;
  --primary-hover: #1e40af;
  --secondary-color: #0c2559;
  --accent-color: #3b82f6;
  --accent-soft: #dbeafe;
  --background-color: #eef2f8;
  --card-bg: #ffffff;
  --text-primary: #0f1f3d;
  --text-secondary: #5b6b86;
  --border-color: #e2e8f3;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #f59e0b;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(12, 37, 89, 0.06), 0 1px 3px rgba(12, 37, 89, 0.04);
  --shadow-md: 0 8px 24px -8px rgba(12, 37, 89, 0.18), 0 2px 6px rgba(12, 37, 89, 0.06);
  --shadow-lg: 0 24px 48px -12px rgba(7, 20, 46, 0.35);
  --sidebar-w: 268px;
  --sidebar-w-collapsed: 80px;
  --topbar-h: 60px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  background-color: var(--background-color);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

img {
  max-width: 100%;
}

h2 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--navy-800);
}

h3 {
  font-weight: 600;
  color: var(--navy-800);
}

/* ==========================================================================
   Login
   ========================================================================== */
.auth-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 1.25rem 1.25rem 4rem;
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(900px 500px at 15% 0%, rgba(59, 130, 246, 0.28), transparent 60%),
    radial-gradient(700px 500px at 100% 100%, rgba(79, 109, 148, 0.35), transparent 60%),
    linear-gradient(160deg, var(--navy-950), var(--navy-800));
}

.auth-container::before {
  content: "";
  position: absolute;
  right: -8%;
  top: 50%;
  width: min(620px, 80vw);
  aspect-ratio: 1;
  transform: translateY(-50%);
  background: url("../imagens/logo-touro.png") center / contain no-repeat;
  opacity: 0.07;
  pointer-events: none;
}

.auth-card {
  position: relative;
  background: var(--card-bg);
  padding: 2.25rem 2rem 2rem;
  border-radius: 22px;
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.auth-logo {
  width: 92px;
  height: 92px;
  border-radius: 24px;
  margin: -4.2rem auto 1rem;
  display: block;
  box-shadow: 0 14px 30px -8px rgba(7, 20, 46, 0.55);
  border: 3px solid #fff;
}

.auth-brand {
  font-size: 1.75rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--navy-800);
  line-height: 1.1;
}

.auth-tagline {
  font-size: 0.7rem;
  letter-spacing: 0.32em;
  text-transform: uppercase;
  color: var(--primary-color);
  font-weight: 600;
  margin: 0.4rem 0 1.6rem;
}

.auth-card h2 {
  margin-bottom: 1.5rem;
  color: var(--navy-800);
  font-weight: 700;
}

.auth-error {
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  font-size: 0.875rem;
  margin-bottom: 1rem;
  text-align: left;
}

.auth-card .btn-primary {
  width: 100%;
  margin-top: 0.5rem;
}

.auth-switch {
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.auth-switch a {
  color: var(--primary-color);
  text-decoration: none;
  font-weight: 500;
  cursor: pointer;
}

/* ==========================================================================
   Formulários
   ========================================================================== */
.form-group {
  margin-bottom: 1rem;
  text-align: left;
  min-width: 0;
}

.form-group label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.8rem;
  color: var(--text-secondary);
  font-weight: 600;
  letter-spacing: 0.01em;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="email"],
input[type="tel"],
input[type="search"],
select,
textarea,
.form-control {
  width: 100%;
  max-width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text-primary);
  background: #fff;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent-color);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

input[readonly] {
  background: #f1f5f9 !important;
  color: var(--text-secondary);
}

.btn-primary {
  min-width: 120px;
  padding: 0.72rem 1.4rem;
  background: linear-gradient(135deg, var(--primary-color), var(--navy-700));
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.2s, filter 0.2s;
  box-shadow: 0 6px 14px -6px rgba(29, 78, 216, 0.6);
}

.btn-primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-cancel {
  min-width: 120px;
  padding: 0.72rem 1.4rem;
  background-color: #fff;
  color: var(--text-secondary);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-cancel:hover {
  background-color: #f1f5f9;
  color: var(--text-primary);
  border-color: var(--steel-300);
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0 1rem;
}

/* ==========================================================================
   Layout + Sidebar
   ========================================================================== */
.app-container {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.sidebar {
  width: var(--sidebar-w);
  background:
    radial-gradient(500px 300px at 0% 0%, rgba(59, 130, 246, 0.18), transparent 60%),
    linear-gradient(180deg, var(--navy-900), var(--navy-950));
  color: white;
  padding: 1.25rem 0.9rem;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width 0.28s ease, transform 0.28s ease;
  z-index: 1200;
  scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.sidebar.collapsed {
  width: var(--sidebar-w-collapsed);
  padding: 1.25rem 0.5rem;
}

.sidebar-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  padding: 0 0.25rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  min-height: 60px;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  color: #fff;
  min-width: 0;
}

.sidebar-brand img {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
}

.sidebar-brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.sidebar-brand-text strong {
  font-size: 1.2rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.sidebar-brand-text small {
  font-size: 0.5rem;
  letter-spacing: 0.14em;
  color: var(--steel-300);
  text-transform: uppercase;
  white-space: nowrap;
}

.sidebar.collapsed .sidebar-header {
  flex-direction: column;
  justify-content: center;
  padding-bottom: 0.75rem;
}

.sidebar.collapsed .sidebar-brand-text {
  display: none;
}

.sidebar-toggle-btn {
  background: rgba(255, 255, 255, 0.06);
  border: none;
  color: white;
  cursor: pointer;
  font-size: 1rem;
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  transition: background 0.2s;
}

.sidebar-toggle-btn:hover {
  background-color: rgba(255, 255, 255, 0.16);
}

.nav-links {
  list-style: none;
  flex: 1;
}

.nav-links li {
  margin-bottom: 0.25rem;
}

.nav-links a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.7rem 0.85rem;
  color: rgba(255, 255, 255, 0.72);
  text-decoration: none;
  border-radius: 11px;
  font-size: 0.92rem;
  font-weight: 500;
  line-height: 1.25;
  transition: background 0.2s, color 0.2s;
  position: relative;
}

/* Nome completo do menu: quebra de linha em vez de cortar o texto */
.nav-links a span {
  white-space: normal;
  overflow-wrap: anywhere;
  flex: 1;
  min-width: 0;
}

.nav-links a i {
  width: 22px;
  min-width: 22px;
  text-align: center;
  font-size: 1.05rem;
}

.nav-links a:hover {
  background-color: rgba(255, 255, 255, 0.08);
  color: white;
}

.nav-links a.active {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.95), rgba(29, 78, 216, 0.95));
  color: white;
  box-shadow: 0 8px 18px -8px rgba(59, 130, 246, 0.8);
}

.sidebar.collapsed .nav-links a {
  justify-content: center;
  padding: 0.75rem;
}

.sidebar.collapsed .nav-links a span {
  display: none;
}

.logout-btn {
  margin-top: 1rem;
  padding: 0.7rem 1rem;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: white;
  border-radius: 11px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background 0.2s;
}

.logout-btn:hover {
  background: rgba(220, 38, 38, 0.35);
}

.sidebar.collapsed .logout-btn span {
  display: none;
}

.main-content {
  flex: 1;
  min-width: 0;
  padding: 1.75rem 2rem 4rem;
  overflow-y: auto;
  overflow-x: hidden;
  height: 100%;
  position: relative;
  -webkit-overflow-scrolling: touch;
}

/* Barra superior (somente mobile) */
.mobile-topbar {
  display: none;
}

.sidebar-overlay {
  display: none;
}

/* ==========================================================================
   Chip do usuário
   ========================================================================== */
.header-with-user {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  width: 100%;
  flex-wrap: wrap;
}

.user-header-display {
  display: flex;
  align-items: center;
  margin-bottom: 0 !important;
}

.user-info-container {
  display: flex;
  align-items: center;
  gap: 12px;
  background: white;
  padding: 6px 8px 6px 16px;
  border-radius: 50px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
}

.user-details {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}

.user-name {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.88rem;
}

.user-profile {
  font-size: 0.68rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.user-avatar {
  width: 38px;
  height: 38px;
  background: linear-gradient(135deg, var(--primary-color), var(--navy-800));
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

/* ==========================================================================
   Cards, KPIs e gráficos
   ========================================================================== */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1.25rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  position: relative;
  background: var(--card-bg);
  padding: 1.3rem 1.4rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.2s, box-shadow 0.2s;
}

.stat-card::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: linear-gradient(180deg, var(--accent-color), var(--navy-700));
}

.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.stat-card .stat-icon {
  position: absolute;
  right: 1rem;
  top: 1rem;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--primary-color);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.05rem;
}

.stat-card h3 {
  font-size: 0.72rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.4rem;
  padding-right: 3rem;
  font-weight: 600;
}

.stat-card .value {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--navy-800);
  overflow-wrap: anywhere;
}

.dashboard-grid {
  display: grid;
  gap: 1.25rem;
  margin-top: 1.25rem;
}

.dashboard-grid.cols-2 {
  grid-template-columns: 1fr 1fr;
}

.dashboard-grid.cols-21 {
  grid-template-columns: 2fr 1fr;
}

.dashboard-grid > * {
  min-width: 0;
}

.chart-container,
.chart-card {
  background: var(--card-bg);
  padding: 1.25rem 1.4rem;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  min-width: 0;
}

.chart-card h3,
.chart-container h3 {
  font-size: 1rem;
  margin-bottom: 0.15rem;
}

.chart-card .chart-sub {
  font-size: 0.8rem;
  color: var(--text-secondary);
  margin-bottom: 0.75rem;
}

.chart-box {
  position: relative;
  height: 300px;
}

.table-container,
.form-section {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  padding: 1.4rem;
  margin-bottom: 1.5rem;
  min-width: 0;
}

.table-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.1rem;
  flex-wrap: wrap;
}

.info-box {
  background: var(--accent-soft);
  color: var(--navy-800);
  border-radius: var(--radius-sm);
  padding: 0.9rem 1rem;
  font-size: 0.9rem;
}

/* ==========================================================================
   Tabelas
   ========================================================================== */
.table-scroll {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 0.85rem 0.9rem;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.9rem;
}

th {
  font-weight: 700;
  color: var(--text-secondary);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: #f6f8fc;
  white-space: nowrap;
}

tbody tr {
  transition: background 0.15s;
}

tbody tr:hover {
  background: #f8faff;
}

td button {
  font-family: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.3rem 0.5rem;
  border-radius: 8px;
}

td button:hover {
  background: rgba(29, 78, 216, 0.08) !important;
}

/* ==========================================================================
   Utilidades
   ========================================================================== */
.hidden {
  display: none !important;
}

/* ==========================================================================
   Toasts
   ========================================================================== */
.success-message,
.toast-message {
  position: fixed;
  top: 20px;
  right: 20px;
  max-width: min(92vw, 380px);
  padding: 0.9rem 1.25rem;
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  z-index: 20000;
  animation: slideIn 0.3s ease-out;
  font-weight: 500;
  color: white;
}

.toast-success { background: #16a34a; }
.toast-edit { background: #2563eb; }
.toast-error { background: #dc2626; }
.toast-warning { background: #f59e0b; color: #fff; }

.toast-title {
  font-weight: 700;
  display: block;
  margin-bottom: 0.15rem;
}

/* ==========================================================================
   Modal
   ========================================================================== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(7, 20, 46, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 1rem;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-container {
  background: white;
  padding: 1.75rem;
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  max-width: 440px;
  width: 100%;
  max-height: 90dvh;
  overflow-y: auto;
  transform: translateY(-16px) scale(0.98);
  transition: transform 0.25s ease;
}

.modal-overlay.active .modal-container {
  transform: translateY(0) scale(1);
}

.modal-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 0.75rem;
  color: var(--navy-800);
}

.modal-body {
  margin-bottom: 1.5rem;
  color: var(--text-secondary);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  flex-wrap: wrap;
}

@keyframes slideIn {
  from { transform: translateX(120%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes slideOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(120%); opacity: 0; }
}

/* ==========================================================================
   Paginação
   ========================================================================== */
.pagination-btn {
  padding: 0.5rem 0.9rem;
  border: 1.5px solid var(--border-color);
  background: white;
  border-radius: 9px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.2s;
}

.pagination-btn:hover:not(:disabled) {
  background: var(--primary-color);
  color: white;
  border-color: var(--primary-color);
}

.pagination-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#page-size {
  width: auto;
  padding: 0.45rem 0.6rem;
  border: 1.5px solid var(--border-color);
  border-radius: 9px;
  cursor: pointer;
}

/* ==========================================================================
   Botão flutuante WhatsApp + rodapé
   ========================================================================== */
.whatsapp-float {
  position: fixed;
  width: 56px;
  height: 56px;
  bottom: 24px;
  right: 24px;
  background-color: #25d366;
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.25);
  z-index: 900;
  transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  text-decoration: none;
}

.whatsapp-float:hover {
  background-color: #128c7e;
  transform: scale(1.1);
}

.whatsapp-float img {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.footer-bottom {
  position: fixed;
  bottom: 6px;
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.85);
  z-index: 100;
  padding: 10px;
  pointer-events: none;
}

.footer-bottom a {
  color: white;
  text-decoration: none;
  font-weight: 600;
  pointer-events: auto;
}

.footer-bottom a:hover {
  text-decoration: underline;
}

/* ==========================================================================
   Pesos (manejo)
   ========================================================================== */
.weights-section {
  margin-top: 1.5rem;
  padding: 1.25rem;
  background: #f6f8fc;
  border-radius: var(--radius);
  border: 1px solid var(--border-color);
}

.weights-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  column-gap: 1.5rem;
  row-gap: 1rem;
}

.weight-row {
  display: contents;
}

/* ==========================================================================
   RESPONSIVO
   ========================================================================== */

/* Tablets e abaixo: sidebar vira drawer */
@media (max-width: 900px) {
  .app-container {
    flex-direction: column;
  }

  .mobile-topbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    height: var(--topbar-h);
    flex-shrink: 0;
    padding: 0 0.9rem;
    padding-top: env(safe-area-inset-top);
    background: linear-gradient(90deg, var(--navy-950), var(--navy-800));
    color: #fff;
    z-index: 1100;
    box-shadow: 0 4px 14px rgba(7, 20, 46, 0.35);
  }

  .mobile-topbar .menu-btn {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 1.15rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
  }

  .mobile-topbar .topbar-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex: 1;
    min-width: 0;
    text-decoration: none;
    color: #fff;
  }

  .mobile-topbar .topbar-brand img {
    width: 34px;
    height: 34px;
    border-radius: 10px;
  }

  .mobile-topbar .topbar-brand strong {
    font-size: 1.05rem;
    font-weight: 800;
  }

  .mobile-topbar .topbar-page {
    font-size: 0.78rem;
    color: var(--steel-300);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .mobile-topbar .user-avatar {
    width: 36px;
    height: 36px;
    font-size: 0.8rem;
    flex-shrink: 0;
  }

  .sidebar,
  .sidebar.collapsed {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(84vw, 320px);
    padding: calc(1.25rem + env(safe-area-inset-top)) 0.9rem 1.25rem;
    transform: translateX(-102%);
    box-shadow: var(--shadow-lg);
    height: 100dvh;
  }

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

  /* No drawer, sempre mostra os textos completos */
  .sidebar.collapsed .sidebar-brand-text,
  .sidebar.collapsed .nav-links a span,
  .sidebar.collapsed .logout-btn span {
    display: revert;
  }

  .sidebar.collapsed .sidebar-header {
    flex-direction: row;
  }

  .sidebar.collapsed .nav-links a {
    justify-content: flex-start;
    padding: 0.7rem 0.85rem;
  }

  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(7, 20, 46, 0.55);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s;
    z-index: 1150;
  }

  .sidebar-overlay.show {
    opacity: 1;
    visibility: visible;
  }

  body.drawer-open {
    overflow: hidden;
  }

  .main-content {
    padding: 1.1rem 1rem 6rem;
    width: 100%;
  }

  /* O avatar já aparece na barra superior */
  .user-header-display {
    display: none !important;
  }

  .dashboard-grid.cols-2,
  .dashboard-grid.cols-21,
  .results-container {
    grid-template-columns: 1fr !important;
  }

  .whatsapp-float {
    width: 50px;
    height: 50px;
    bottom: 16px;
    right: 14px;
  }

  .whatsapp-float img {
    width: 26px;
    height: 26px;
  }
}

/* Celulares */
@media (max-width: 640px) {
  /* Contêineres flex com estilo inline (paginação, filtros, botões) passam a quebrar linha */
  .main-content [style*="display: flex"],
  .main-content [style*="display:flex"] {
    flex-wrap: wrap;
  }

  .main-content [style*="display: flex"] > input,
  .main-content [style*="display: flex"] > select {
    min-width: 0;
    flex: 1 1 140px;
  }

  .main-content [style*="justify-content: space-between"] {
    gap: 0.6rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  .stats-grid {
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
  }

  .stat-card {
    padding: 1rem;
  }

  .stat-card .stat-icon {
    display: none;
  }

  .stat-card h3 {
    padding-right: 0;
    font-size: 0.66rem;
  }

  .stat-card .value {
    font-size: 1.15rem;
    overflow-wrap: normal;
    white-space: nowrap;
  }

  .stats-grid > .stat-card:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .table-container,
  .form-section,
  .chart-card,
  .chart-container {
    padding: 1rem;
    border-radius: 12px;
  }

  .chart-box {
    height: 250px;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .form-grid > * {
    grid-column: auto !important;
  }

  .form-actions,
  .modal-actions {
    flex-direction: column;
  }

  .form-actions > button,
  .modal-actions > button,
  .form-actions > *,
  .modal-actions > * {
    width: 100%;
  }

  .table-header {
    align-items: stretch;
  }

  /* Evita zoom automático do iOS em campos de formulário */
  input,
  select,
  textarea {
    font-size: 16px !important;
    min-height: 44px;
  }

  .btn-primary,
  .btn-cancel {
    min-height: 46px;
  }

  .weights-grid {
    grid-template-columns: 1fr;
  }

  .success-message,
  .toast-message {
    left: 12px !important;
    right: 12px !important;
    top: calc(var(--topbar-h) + 8px) !important;
    max-width: none !important;
  }

  .modal-container {
    padding: 1.25rem;
    border-radius: 16px;
  }

  .auth-card {
    padding: 2rem 1.25rem 1.5rem;
  }

  /* ---- Tabelas viram cartões ---- */
  table.responsive-cards,
  table.responsive-cards tbody {
    display: block;
    width: 100%;
  }

  table.responsive-cards thead {
    display: none;
  }

  table.responsive-cards tr {
    display: block;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.35rem 0.85rem;
    margin-bottom: 0.75rem;
    box-shadow: var(--shadow-sm);
  }

  table.responsive-cards td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    text-align: right;
    padding: 0.55rem 0;
    border-bottom: 1px dashed var(--border-color);
    font-size: 0.88rem;
    overflow-wrap: anywhere;
  }

  table.responsive-cards td:last-child {
    border-bottom: none;
  }

  table.responsive-cards td[data-label]::before {
    content: attr(data-label);
    flex-shrink: 0;
    max-width: 45%;
    text-align: left;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
  }

  table.responsive-cards td[colspan] {
    justify-content: center;
    text-align: center;
  }

  table.responsive-cards td.cell-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  table.responsive-cards td button {
    min-height: 38px;
    padding: 0.4rem 0.8rem;
    border: 1px solid var(--border-color);
    background: #fff;
  }
}

@media (max-width: 360px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
}
