/* ─── ERP FSM - Stylesheet ─────────────────────────────────────────────── */

:root {
  --sidebar-width: 248px;
  --sidebar-bg: #12261A;
  --sidebar-hover: rgba(255,255,255,.08);
  --sidebar-active: rgba(255,255,255,.15);
  --topbar-height: 56px;
  --brand-primary: #2F8F44;
  --brand-secondary: #5EC96B;
  --brand-light: #7ED97E;

  /* Sobrepor as variáveis do próprio Bootstrap 5 — sem isto, qualquer botão
     ou elemento "btn-primary" simples (fora dos componentes .btn-modern-*)
     continuava azul, por todo o sistema, sem seguir a marca LinkApY. */
  --bs-primary: var(--brand-primary);
  --bs-primary-rgb: 47, 143, 68;
  --bs-link-color: var(--brand-primary);
  --bs-link-color-rgb: 47, 143, 68;
  --bs-link-hover-color: #256e35;
  --bs-btn-bg: var(--brand-primary);
  --bs-btn-border-color: var(--brand-primary);
  --bs-btn-hover-bg: #256e35;
  --bs-btn-hover-border-color: #256e35;
  --bs-btn-active-bg: #1f5c2c;
  --bs-btn-active-border-color: #1f5c2c;
  --bs-focus-ring-color: rgba(47,143,68,.25);
}

.btn-primary {
  --bs-btn-bg: var(--brand-primary);
  --bs-btn-border-color: var(--brand-primary);
  --bs-btn-hover-bg: #256e35;
  --bs-btn-hover-border-color: #256e35;
  --bs-btn-active-bg: #1f5c2c;
  --bs-btn-active-border-color: #1f5c2c;
  --bs-btn-focus-shadow-rgb: 47, 143, 68;
}
.btn-outline-primary {
  --bs-btn-color: var(--brand-primary);
  --bs-btn-border-color: var(--brand-primary);
  --bs-btn-hover-bg: var(--brand-primary);
  --bs-btn-hover-border-color: var(--brand-primary);
  --bs-btn-active-bg: var(--brand-primary);
  --bs-btn-active-border-color: var(--brand-primary);
  --bs-btn-focus-shadow-rgb: 47, 143, 68;
}
.text-primary { color: var(--brand-primary) !important; }
.bg-primary { background-color: var(--brand-primary) !important; }
.border-primary { border-color: var(--brand-primary) !important; }
.form-check-input:checked { background-color: var(--brand-primary); border-color: var(--brand-primary); }
.form-control:focus, .form-select:focus { border-color: var(--brand-light); box-shadow: 0 0 0 .2rem rgba(47,143,68,.15); }
a { color: var(--brand-primary); }
.nav-tabs .nav-link.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }
.spinner-border.text-primary { color: var(--brand-primary) !important; }

/* ── Base ─────────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
body { font-family: 'Inter', system-ui, -apple-system, sans-serif; font-size: .875rem; }
.x-small { font-size: .7rem; }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  z-index: 1040;
  transition: transform .25s ease;
  overflow-y: auto; overflow-x: hidden;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px; min-height: var(--topbar-height);
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-icon {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--brand-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem; color: #fff; flex-shrink: 0;
}
.brand-name { color: #fff; font-weight: 700; font-size: .95rem; letter-spacing: .02em; }

.sidebar-user {
  display: flex; align-items: center;
  padding: 12px 14px; border-bottom: 1px solid rgba(255,255,255,.06);
}
.sidebar-user img { flex-shrink: 0; border: 2px solid rgba(255,255,255,.2); }

.sidebar-nav { padding: 8px 10px; flex: 1; }
.nav-section-label {
  font-size: .65rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: rgba(148,163,184,.45); /* azul-cinza discreto, não compete com os links */
  padding: 10px 8px 4px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px 8px 12px; border-radius: 8px; margin-bottom: 1px;
  color: rgba(255,255,255,.75); text-decoration: none;
  font-size: .83rem; font-weight: 500; cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
  white-space: nowrap; overflow: hidden;
  border-left: 3px solid transparent;
}
.nav-item:hover  { background: var(--sidebar-hover); color: #fff; }
.nav-item.active {
  background: linear-gradient(90deg, rgba(37,99,235,.18), rgba(37,99,235,.05));
  color: #fff;
  border-left: 3px solid var(--brand-primary);
  font-weight: 600;
}
.nav-item i { font-size: 1rem; flex-shrink: 0; width: 20px; text-align: center; }

/* ── Main Wrapper ─────────────────────────────────────────────────────────── */
#main-wrapper {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex; flex-direction: column;
  transition: margin .25s ease;
}

/* ── Topbar ───────────────────────────────────────────────────────────────── */
#topbar {
  height: var(--topbar-height);
  background: var(--bs-body-bg);
  border-bottom: 1px solid var(--bs-border-color);
  display: flex; align-items: center;
  padding: 0 20px; gap: 12px;
  position: sticky; top: 0; z-index: 100;
}

/* ── Page Content ─────────────────────────────────────────────────────────── */
#page-content { flex: 1; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card { border: 1px solid var(--bs-border-color); border-radius: 12px; }
.card-header { background: transparent; border-bottom: 1px solid var(--bs-border-color); }
.stat-card {
  border-radius: 12px; padding: 20px;
  border: 1px solid var(--bs-border-color);
  background: var(--bs-body-bg);
  transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0,0,0,.07); }
.stat-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem;
}
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .75rem; color: var(--bs-secondary-color); margin-top: 4px; }

/* ── Status badges ────────────────────────────────────────────────────────── */
.status-badge { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 20px; font-size: .72rem; font-weight: 600; white-space: nowrap; }
.status-new         { background: #e0f2fe; color: #0369a1; }
.status-pending_payment { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
.status-scheduled   { background: #f0f9ff; color: #0284c7; }
.status-in_transit  { background: #fef3c7; color: #b45309; }
.status-in_progress { background: #fef3c7; color: #d97706; }
.status-paused      { background: #f3f4f6; color: #6b7280; }
.status-completed   { background: #dcfce7; color: #16a34a; }
.status-invoiced    { background: #d1fae5; color: #059669; }
.status-cancelled   { background: #fee2e2; color: #dc2626; }
.status-waiting_parts     { background: #fce7f3; color: #be185d; }
.status-waiting_approval  { background: #ede9fe; color: #7c3aed; }
.priority-emergency { background: #fee2e2; color: #dc2626; }
.priority-urgent    { background: #fef3c7; color: #b45309; }
.priority-high      { background: #fce7f3; color: #be185d; }
.priority-normal    { background: #e0f2fe; color: #0369a1; }
.priority-low       { background: #f0fdf4; color: #16a34a; }

/* ── Tables ───────────────────────────────────────────────────────────────── */
.table-hover > tbody > tr { cursor: pointer; }
.table th { font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--bs-secondary-color); white-space: nowrap; }
.table td { vertical-align: middle; font-size: .83rem; }
.table-actions { white-space: nowrap; width: 1%; }

/* ── Pagination ───────────────────────────────────────────────────────────── */
.pagination-wrapper { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-top: 1px solid var(--bs-border-color); }
.pagination-info { font-size: .78rem; color: var(--bs-secondary-color); }

/* ── Timeline ─────────────────────────────────────────────────────────────── */
.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 4px; bottom: 4px; width: 2px; background: var(--bs-border-color); }
.timeline-item { position: relative; margin-bottom: 20px; }
.timeline-dot { position: absolute; left: -24px; top: 4px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 2px var(--bs-border-color); }
.timeline-time { font-size: .72rem; color: var(--bs-secondary-color); }
.timeline-label { font-size: .78rem; font-weight: 600; margin-bottom: 2px; }
.timeline-note  { font-size: .78rem; color: var(--bs-secondary-color); }

/* ── Chat messages ────────────────────────────────────────────────────────── */
.chat-container { height: 350px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.chat-bubble { max-width: 75%; }
.chat-bubble.mine { align-self: flex-end; }
.chat-bubble.mine .bubble-body { background: var(--brand-primary); color: #fff; border-radius: 18px 4px 18px 18px; }
.chat-bubble .bubble-body { background: var(--bs-tertiary-bg); border-radius: 4px 18px 18px 18px; padding: 8px 14px; font-size: .83rem; }
.bubble-meta { font-size: .68rem; color: var(--bs-secondary-color); margin-top: 3px; }
.chat-bubble.mine .bubble-meta { text-align: right; }

/* ── Kanban ───────────────────────────────────────────────────────────────── */
.kanban-board { display: flex; gap: 16px; overflow-x: auto; padding-bottom: 8px; }
.kanban-col { min-width: 260px; max-width: 280px; flex-shrink: 0; }
.kanban-col-header { padding: 10px 14px; border-radius: 8px 8px 0 0; font-weight: 600; font-size: .83rem; display: flex; align-items: center; justify-content: space-between; }
.kanban-col-body { background: var(--bs-tertiary-bg); border-radius: 0 0 8px 8px; padding: 8px; min-height: 100px; }
.kanban-card { background: var(--bs-body-bg); border: 1px solid var(--bs-border-color); border-radius: 8px; padding: 12px; margin-bottom: 8px; cursor: grab; font-size: .82rem; }
.kanban-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,.08); }

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-label { font-weight: 500; font-size: .82rem; margin-bottom: 4px; }
.form-control, .form-select { font-size: .85rem; }
.form-section { border-bottom: 1px solid var(--bs-border-color); padding-bottom: 20px; margin-bottom: 20px; }
.form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }
.form-section-title { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--bs-secondary-color); margin-bottom: 14px; }

/* ── Offcanvas / Drawers ──────────────────────────────────────────────────── */
.offcanvas.offcanvas-end { width: min(600px, 95vw); }
.offcanvas.offcanvas-wide { width: min(800px, 98vw); }
.offcanvas-header { border-bottom: 1px solid var(--bs-border-color); }
.offcanvas-footer { border-top: 1px solid var(--bs-border-color); padding: 12px 16px; display: flex; gap: 8px; justify-content: flex-end; }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  #main-wrapper { margin-left: 0; }
  #sidebar-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 1039; }
  #sidebar-overlay.d-none { display: none !important; }
}

/* ── Dark mode ────────────────────────────────────────────────────────────── */
[data-bs-theme="dark"] {
  --sidebar-bg: #0f172a;
}
[data-bs-theme="dark"] .stat-card,
[data-bs-theme="dark"] .kanban-col-body { background: #1e293b; }

/* ── Utilities ────────────────────────────────────────────────────────────── */
.cursor-pointer { cursor: pointer; }
.text-truncate-2 { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.bg-primary-subtle-custom { background: rgba(37,99,235,.08); }
.rotate-180 { transform: rotate(180deg); }
.spinner-overlay { position: absolute; inset: 0; background: rgba(255,255,255,.7); display: flex; align-items: center; justify-content: center; border-radius: inherit; z-index: 10; }
[data-bs-theme="dark"] .spinner-overlay { background: rgba(0,0,0,.5); }

/* ── Empty states ─────────────────────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 24px; color: var(--bs-secondary-color); }
.empty-state i { font-size: 3rem; opacity: .35; display: block; margin-bottom: 16px; }
.empty-state h6 { font-weight: 600; color: var(--bs-body-color); }

/* Prevent stacked backdrops */
.modal-backdrop ~ .modal-backdrop { display: none !important; }

/* ── Info Row (label + valor) — usado em detalhes de OS, orçamentos, contratos, etc. ── */
.info-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--bs-border-color);
}
.info-row:last-child { border-bottom: none; }
.info-row > span:first-child { flex-shrink: 0; white-space: nowrap; }
.info-row > span:last-child { text-align: right; }

/* ── Chips de selecção (método de pagamento, serviços, etc.) — usado em várias páginas ── */
.svc-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 20px;
  border: 2px solid var(--bs-border-color);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  user-select: none;
  transition: all .15s;
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
}
.svc-chip:hover { border-color: var(--brand-light); }
.svc-chip.selected {
  border-color: var(--brand-primary);
  background: #ecfdf3;
  color: var(--brand-primary);
  font-weight: 700;
  box-shadow: 0 0 0 1px var(--brand-primary) inset;
}
[data-bs-theme="dark"] .svc-chip.selected { background: rgba(47,143,68,.25); color: var(--brand-light); }
.svc-chip.required { border-color: #dc2626; background: #fef2f2; color: #b91c1c; cursor: default; }

/* ═══════════════════════════════════════════════════════════════════════
   LINKAPY — Design System Premium (cartões, tabelas, badges, botões)
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Cartões de métricas (KPIs) ─────────────────────────────────────────── */
.metric-card {
  background: #fff;
  border: 1px solid #eef1f6;
  border-radius: 12px;
  padding: 20px 22px;
  box-shadow: 0 1px 3px rgba(15,23,42,.04), 0 4px 16px rgba(15,23,42,.03);
  position: relative;
  overflow: hidden;
  height: 100%;
  transition: box-shadow .18s, transform .18s;
}
.metric-card:hover {
  box-shadow: 0 2px 6px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
  transform: translateY(-1px);
}
.metric-card .metric-icon {
  position: absolute;
  top: 18px; right: 18px;
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.05rem;
}
.metric-card .metric-value {
  font-size: 1.9rem;
  font-weight: 800;
  color: #1e293b;
  line-height: 1.15;
  letter-spacing: -.02em;
  margin-bottom: 4px;
}
.metric-card .metric-label {
  font-size: .78rem;
  font-weight: 500;
  color: #64748b;
}
.metric-card .metric-sub {
  font-size: .72rem;
  color: #94a3b8;
  margin-top: 6px;
}
.metric-trend {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: .72rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-top: 6px;
}
.metric-trend.up   { background: #dcfce7; color: #166534; }
.metric-trend.down { background: #fee2e2; color: #991b1b; }
/* Paletas pastel por tipo de dado — usar a classe correspondente no ícone */
.metric-icon.mi-blue   { background: #eff6ff; color: #2563eb; }
.metric-icon.mi-green  { background: #ecfdf5; color: #16a34a; }
.metric-icon.mi-amber  { background: #fffbeb; color: #d97706; }
.metric-icon.mi-purple { background: #f5f3ff; color: #7c3aed; }
.metric-icon.mi-red    { background: #fef2f2; color: #dc2626; }
.metric-icon.mi-cyan   { background: #ecfeff; color: #0891b2; }

/* ── Entrada suave do conteúdo ao mudar de página — subtil, não distrai ──── */
@keyframes pageFadeIn { from { opacity:0; transform:translateY(4px); } to { opacity:1; transform:translateY(0); } }
.page-fade-in { animation: pageFadeIn .22s ease; }
@media (prefers-reduced-motion: reduce) { .page-fade-in { animation: none; } }

/* ── Painel financeiro do mês — cartões com entrada animada e leve profundidade ── */
@keyframes finCardIn { from { opacity:0; transform:translateY(14px) scale(.97); } to { opacity:1; transform:translateY(0) scale(1); } }
.fin-month-card {
  opacity:0; animation: finCardIn .45s cubic-bezier(.2,.8,.2,1) forwards;
  border:1px solid var(--bs-border-color); transition: transform .2s ease, box-shadow .2s ease;
}
.fin-month-card:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(0,0,0,.08); }
@media (prefers-reduced-motion: reduce) { .fin-month-card { animation: none; opacity:1; } }

/* ── Tabelas modernas (dados premium) ───────────────────────────────────── */
.table-modern {
  border-collapse: separate;
  border-spacing: 0;
}
.table-modern thead th {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: #94a3b8;
  border-bottom: 1px solid #eef1f6;
  padding: 12px 16px;
  background: #fafbfc;
  white-space: nowrap;
}
.table-modern tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid #f1f4f8;
  vertical-align: middle;
}
.table-modern tbody tr:last-child td { border-bottom: none; }
.table-modern tbody tr:hover { background: #fafbfc; }

.cell-primary {
  font-weight: 700;
  color: #1e293b;
  font-size: .87rem;
  display: block;
}
.cell-secondary {
  font-size: .74rem;
  color: #94a3b8;
  display: block;
  margin-top: 1px;
}

/* Botões de ação minimalistas nas tabelas */
.action-icon-btn {
  width: 32px; height: 32px;
  border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid #eef1f6;
  background: #fff;
  color: #64748b;
  transition: all .15s;
}
.action-icon-btn:hover { background: #f1f5f9; color: #1e293b; border-color: #e2e8f0; }
.action-icon-btn.danger:hover { background: #fef2f2; color: #dc2626; border-color: #fecaca; }

/* ── Badges/pílulas de estado (pastel forte) ────────────────────────────── */
.pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .01em;
}
.pill-badge.pill-green  { background: #dcfce7; color: #166534; } /* Activa */
.pill-badge.pill-amber  { background: #fef3e2; color: #9a3412; } /* Período de teste */
.pill-badge.pill-red    { background: #fee2e2; color: #991b1b; } /* Suspensa/Cancelada */
.pill-badge.pill-gray   { background: #f1f5f9; color: #475569; } /* Inactiva/Pendente */
.pill-badge.pill-blue   { background: #dbeafe; color: #1e40af; }

/* ── Botão primário moderno ("+ Nova Empresa" e afins) ──────────────────── */
.btn-modern-primary {
  background: linear-gradient(135deg, var(--brand-secondary), var(--brand-primary));
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 9px 18px;
  font-size: .82rem;
  font-weight: 600;
  letter-spacing: .01em;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  box-shadow: 0 1px 2px rgba(47,143,68,.18), 0 4px 10px rgba(47,143,68,.14);
  transition: all .18s cubic-bezier(.2,.8,.2,1);
}
.btn-modern-primary:hover {
  color: #fff;
  box-shadow: 0 2px 6px rgba(47,143,68,.25), 0 8px 20px rgba(47,143,68,.2);
  transform: translateY(-1px);
  filter: brightness(1.04);
}
.btn-modern-primary:active { transform: translateY(0); }

/* ══════════════════════════════════════════════════════════════════════════
   ADAPTAÇÃO A TELEMÓVEL — barras de separadores, tabelas, modais, cartões
   ══════════════════════════════════════════════════════════════════════════ */

/* ── Barras de separadores (nav-tabs do Bootstrap E os botões .tab-pill
   personalizados) — em vez de quebrar para 2-3 linhas num ecrã estreito
   (feio e confuso), deslizam horizontalmente com um dedo, como seria de
   esperar num telemóvel. Funciona em todas as páginas que usam qualquer
   um dos dois padrões: Definições, Definições da Plataforma, RH, RGPD,
   CRM, Loja, Materiais & Stock, Admin Tools, etc. ── */
@media (max-width: 991.98px) {
  .nav-tabs,
  .d-flex.gap-2.flex-wrap:has(> .tab-pill) {
    flex-wrap: nowrap !important;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    padding-bottom: 2px;
  }
  .nav-tabs::-webkit-scrollbar,
  .d-flex.gap-2.flex-wrap:has(> .tab-pill)::-webkit-scrollbar { display: none; }
  .nav-tabs .nav-item,
  .nav-tabs .nav-link,
  .tab-pill { flex-shrink: 0; white-space: nowrap; }
}

/* Fallback para browsers sem suporte a :has() — aplica-se directamente a
   quem já usa a classe .tab-scroll no contentor (usar quando :has() falhar). */
.tab-scroll {
  flex-wrap: nowrap !important;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tab-scroll::-webkit-scrollbar { display: none; }
.tab-scroll > * { flex-shrink: 0; white-space: nowrap; }

/* ── .tab-pill nunca teve estilo próprio — ficava com a aparência default
   do browser, inconsistente com o resto da interface. ── */
.tab-pill {
  display: inline-flex;
  align-items: center;
  padding: 7px 14px;
  border-radius: 8px;
  border: 1px solid var(--bs-border-color);
  background: var(--bs-body-bg);
  color: var(--bs-body-color);
  font-size: .8rem;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
}
.tab-pill:hover { background: var(--bs-tertiary-bg); }
.tab-pill.active { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }

/* ── Nunca deixar um elemento largo empurrar a página inteira para o lado
   — a causa mais comum de "não consigo rolar para o lado direito" no
   telemóvel é precisamente isto: alguma coisa dentro da página é mais
   larga que o ecrã e o browser estica o <body> todo. ── */
@media (max-width: 767.98px) {
  html, body { overflow-x: hidden; max-width: 100vw; }
  #main-content { overflow-x: hidden; }

  /* Modais quase a ecrã inteiro, sem margens a desperdiçar espaço */
  .modal-dialog { margin: 8px; max-width: calc(100vw - 16px); }
  .modal-dialog.modal-lg, .modal-dialog.modal-xl { max-width: calc(100vw - 16px); }

  /* Cartões de indicadores (KPIs) — 2 por linha em vez de espremidos ou
     um por linha a ocupar ecrã infinito */
  .row.g-3 > [class*="col-md-3"] { flex: 0 0 50%; max-width: 50%; }

  /* Cabeçalhos de página — menos preenchimento, texto não corta */
  h5.fw-bold { font-size: 1.05rem; }
  .metric-card, .obs-card { padding: 12px !important; }

  /* Botões de acção no topo das páginas — em coluna em vez de espremidos
     numa linha só */
  .d-flex.align-items-center.justify-content-between.mb-3.flex-wrap { row-gap: 10px; }

  /* Barra de pesquisa superior — não deixar que empurre o sino/avatar
     para fora do ecrã */
  #global-search { min-width: 0; }
}

/* ── Toda a tabela de dados tem de poder deslizar para o lado em vez de
   espremer as colunas ou cortar conteúdo — reforça o que .table-responsive
   já devia fazer, para o caso de faltar nalguma página. ── */
@media (max-width: 767.98px) {
  table:not(.table-responsive table) { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}
