/**
 * DESIGN Info SOLUÇÕES - ERP Corporate Stylesheet
 * Cores Oficiais extraídas do Logotipo:
 * Primária (Azul Corporativo): #326BB2 | Destaque (Vermelho Design): #E31612
 * Light Mode como padrão com seletor opcional Dark Mode
 */

:root {
  --primary: #326BB2;
  --primary-hover: #265591;
  --primary-active: #1e4678;
  --primary-light: #edf4fc;
  --primary-border: #bfdbfe;

  --accent: #E31612;
  --accent-hover: #c4120f;
  --accent-active: #a10f0c;
  --accent-light: #fde8e8;

  --bg-body: #f8f9fa;
  --bg-surface: #ffffff;
  --bg-sidebar: #ffffff;
  --bg-navbar: #ffffff;
  --text-main: #1e293b;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --card-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.05);
  --modal-backdrop-bg: rgba(15, 23, 42, 0.4);

  --font-family-base: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-bs-theme="dark"] {
  --primary: #4a84d4;
  --primary-hover: #326BB2;
  --primary-active: #265591;
  --primary-light: #1e293b;
  --primary-border: #334155;

  --accent: #ef4444;
  --accent-hover: #dc2626;
  --accent-active: #b91c1c;
  --accent-light: #371b1d;

  --bg-body: #0f172a;
  --bg-surface: #1e293b;
  --bg-sidebar: #0f172a;
  --bg-navbar: #1e293b;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;
  --card-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
}

body {
  background-color: var(--bg-body);
  color: var(--text-main);
  font-family: var(--font-family-base);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* Utilitários de Cores */
.bg-primary-custom {
  background-color: var(--primary) !important;
  color: #ffffff !important;
}

.text-primary-custom {
  color: var(--primary) !important;
}

.text-accent-custom {
  color: var(--accent) !important;
}

.btn-primary-custom {
  background-color: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  font-weight: 500;
  transition: all 0.15s ease-in-out;
}

.btn-primary-custom:hover, .btn-primary-custom:focus {
  background-color: var(--primary-hover);
  border-color: var(--primary-hover);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(50, 107, 178, 0.3);
}

.btn-accent-custom {
  background-color: var(--accent);
  border-color: var(--accent);
  color: #ffffff;
  font-weight: 500;
  transition: all 0.15s ease-in-out;
}

.btn-accent-custom:hover, .btn-accent-custom:focus {
  background-color: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(227, 22, 18, 0.3);
}

/* Layout Estrutural */
.app-container {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.app-sidebar {
  width: 250px;
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width 0.25s ease, transform 0.25s ease;
  z-index: 1020;
}

.sidebar-brand {
  padding: 0.85rem 1.15rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.sidebar-brand img {
  max-height: 32px;
  width: auto;
  object-fit: contain;
}

.sidebar-nav {
  padding: 0.65rem 0.5rem;
  flex: 1;
  overflow-y: auto;
}

.sidebar-section-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 700;
  color: var(--text-muted);
  padding: 0.5rem 0.65rem 0.2rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.42rem 0.7rem;
  color: var(--text-main);
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  transition: all 0.15s ease;
  margin-bottom: 0.15rem;
}

.sidebar-link i {
  font-size: 1.05rem;
  width: 20px;
  text-align: center;
  color: var(--text-muted);
  transition: color 0.15s ease;
}

.sidebar-link:hover {
  background-color: var(--primary-light);
  color: var(--primary);
}

.sidebar-link:hover i {
  color: var(--primary);
}

.sidebar-link.active {
  background-color: var(--primary);
  color: #ffffff;
}

.sidebar-link.active i {
  color: #ffffff;
}

/* Main Content Area */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-x: hidden;
}

/* Navbar */
.app-navbar {
  height: 52px;
  background-color: var(--bg-navbar);
  border-bottom: 1px solid var(--border-color);
  padding: 0 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1010;
}

.app-content {
  flex: 1;
  padding: 1rem 1.25rem;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

/* Cards & Surfaces */
.card-custom {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: var(--card-shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.card-header-custom {
  background-color: transparent;
  border-bottom: 1px solid var(--border-color);
  padding: 0.65rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.9rem;
}

.stat-card {
  padding: 0.75rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  box-shadow: var(--card-shadow);
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.stat-icon {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.stat-icon.primary {
  background-color: var(--primary-light);
  color: var(--primary);
}

.stat-icon.accent {
  background-color: var(--accent-light);
  color: var(--accent);
}

.stat-icon.success {
  background-color: #ecfdf5;
  color: #10b981;
}

.stat-icon.warning {
  background-color: #fffbeb;
  color: #f59e0b;
}

/* Modais */
.modal-content {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: 14px;
  color: var(--text-main);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.2), 0 8px 10px -6px rgba(0, 0, 0, 0.2);
}

.modal-header {
  border-bottom: 1px solid var(--border-color);
  padding: 1.25rem 1.5rem;
}

.modal-footer {
  border-top: 1px solid var(--border-color);
  padding: 1rem 1.5rem;
}

/* Form Controls */
.form-control, .form-select {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  border-radius: 6px;
  padding: 0.38rem 0.65rem;
  font-size: 0.88rem;
  min-height: 34px;
}

.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(50, 107, 178, 0.18);
  background-color: var(--bg-surface);
  color: var(--text-main);
}

.form-label {
  font-size: 0.82rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
  color: var(--text-main);
}

/* Tabelas (Compact UI - Dense Padding 0.35rem 0.45rem / 12.5px / 0.78rem) */
.table-custom {
  width: 100%;
  margin-bottom: 0;
  color: var(--text-main);
  table-layout: auto;
}

.table-custom th {
  background-color: var(--bg-body);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.35rem 0.45rem;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}

.table-custom td {
  padding: 0.35rem 0.45rem;
  vertical-align: middle;
  border-bottom: 1px solid var(--border-color);
  font-size: 0.78rem; /* font-size: 0.82rem; font-size: 0.84rem; 12.5px exatos para altíssima densidade e legibilidade */
}

.table-hover tbody tr:hover td {
  background-color: var(--primary-light);
}

/* Fixação e Alinhamento da Coluna de Ações (Sticky Right) */
.table-col-actions,
.table-custom th.text-end:last-child,
.table-custom td.text-end:last-child {
  position: sticky;
  right: 0;
  background-color: var(--bg-surface, #ffffff);
  z-index: 2;
  white-space: nowrap !important;
  width: 1%;
  text-align: right;
  vertical-align: middle;
  box-shadow: -3px 0 6px -2px rgba(15, 23, 42, 0.06);
}

th.table-col-actions,
.table-custom thead th.text-end:last-child {
  background-color: var(--bg-body, #f8fafc);
  z-index: 3;
}

.table-hover tbody tr:hover td.table-col-actions,
.table-hover tbody tr:hover td.text-end:last-child {
  background-color: var(--primary-light, #f1f5f9);
}

.table-actions-container {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  white-space: nowrap;
}

/* Otimização de Tabelas Responsivas e Colunas */
.table-responsive {
  -webkit-overflow-scrolling: touch;
  border-radius: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-color) transparent;
}

.table-responsive::-webkit-scrollbar {
  height: 5px;
  width: 5px;
}

.table-responsive::-webkit-scrollbar-thumb {
  background-color: var(--border-color);
  border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-track {
  background: transparent;
}

.table-nowrap th,
.table-nowrap td {
  white-space: nowrap;
}

.table-cell-wrap {
  white-space: normal !important;
  line-height: 1.25;
}

.table-cell-clamp {
  white-space: normal !important;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.25;
  max-width: 240px;
}

.table-cell-truncate {
  max-width: 210px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Botões de Ação Padronizados em Tabelas */
.btn-action {
  padding: 0.2rem 0.42rem;
  font-size: 0.78rem;
  border-radius: 5px;
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1.2;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Agrupador de Ações em Tabelas para Mobile */
.table-actions-mobile {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Botões de Minimizar / Maximizar Cartões (Collapsible) */
.btn-card-collapse {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}

.btn-card-collapse:hover {
  background-color: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary-border);
}

.btn-card-collapse i {
  transition: transform 0.25s ease;
}

.btn-card-collapse.collapsed i {
  transform: rotate(-90deg);
}

/* Badges de Status */
.badge-status {
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  font-weight: 600;
  font-size: 0.75rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

/* Toggle Dark/Light Mode Button */
.theme-toggle-btn {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.theme-toggle-btn:hover {
  background-color: var(--primary-light);
  color: var(--primary);
  border-color: var(--primary);
}

/* Estilo para Área de Impressão A4 Oficial */
@page {
  size: A4 portrait;
  margin: 10mm;
}

@media print {
  html, body {
    background: #ffffff !important;
    color: #000000 !important;
    font-size: 11pt !important;
    line-height: 1.35 !important;
  }
  .app-sidebar, .app-navbar, .no-print, .btn, .modal-backdrop, .modal-header .btn-close, .toast-container {
    display: none !important;
  }
  .app-main {
    margin: 0 !important;
    padding: 0 !important;
  }
  .app-content {
    padding: 0 !important;
    max-width: 100% !important;
  }
  .card-custom, .modal-content {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }
  .modal {
    position: static !important;
    overflow: visible !important;
    display: block !important;
  }
  .modal-dialog {
    max-width: 100% !important;
    margin: 0 !important;
    width: 100% !important;
    transform: none !important;
  }
  .modal-body {
    padding: 0 !important;
    overflow: visible !important;
  }
  .print-area {
    display: block !important;
    width: 100% !important;
  }
  .page-break {
    page-break-after: always;
  }
  /* Picote de corte para recibos de 2 vias */
  .recibo-picote {
    border-top: 1px dashed #64748b !important;
    margin: 20px 0 !important;
    position: relative;
    text-align: center;
  }
  .recibo-picote::after {
    content: '✂ destaque aqui ✂';
    position: absolute;
    top: -10px;
    left: 45%;
    background: #fff;
    padding: 0 8px;
    font-size: 9pt;
    color: #64748b;
  }

  /* Suporte Exclusivo a Cupom Térmico 80mm */
  body.mode-termica {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  body.mode-termica .app-sidebar,
  body.mode-termica .app-navbar,
  body.mode-termica .no-print,
  body.mode-termica .card,
  body.mode-termica #containerA4 {
    display: none !important;
  }
  body.mode-termica #containerTermica {
    display: block !important;
    width: 76mm !important;
    max-width: 76mm !important;
    margin: 0 !important;
    padding: 2mm !important;
    font-family: 'Courier New', Courier, monospace !important;
    font-size: 9pt !important;
    line-height: 1.25 !important;
  }
}

/* ==========================================================================
   DESIGN RESPONSIVO MULTI-TELAS (1366x768, Tablets & Smartphones / S23 Ultra)
   ========================================================================== */
.sidebar-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: var(--modal-backdrop-bg, rgba(15, 23, 42, 0.5));
  backdrop-filter: blur(2px);
  z-index: 1040;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease-in-out;
}

.sidebar-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

/* Ajuste Cirúrgico para Resolução HD Standard (1366x768 px e Laptops) */
@media (min-width: 992px) and (max-height: 820px) {
  .app-navbar {
    height: 48px;
    padding: 0 1rem;
  }

  .app-content {
    padding: 0.75rem 1rem;
  }

  .sidebar-brand {
    padding: 0.65rem 1rem;
  }

  .sidebar-brand img {
    max-height: 28px;
  }

  .sidebar-link {
    padding: 0.38rem 0.65rem;
    font-size: 0.82rem;
  }

  .stat-card {
    padding: 0.6rem 0.85rem;
    gap: 0.75rem;
  }

  .stat-icon {
    width: 36px;
    height: 36px;
    font-size: 1.15rem;
  }

  .card-header-custom {
    padding: 0.5rem 0.85rem;
  }

  .table-custom th {
    padding: 0.35rem 0.45rem;
    font-size: 0.72rem;
  }

  .table-custom td {
    padding: 0.35rem 0.45rem;
    font-size: 0.78rem;
  }

  .table-cell-truncate {
    max-width: 185px;
  }

  .table-cell-clamp {
    max-width: 210px;
  }
}

@media (max-width: 1400px) {
  .table-cell-truncate {
    max-width: 185px;
  }
}

/* Tablets e Ecrãs Médios (< 992px) */
@media (max-width: 991.98px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: 260px;
    max-width: 82vw;
    z-index: 1050;
    transform: translateX(-100%);
    box-shadow: none;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
  }

  .app-sidebar.show-sidebar {
    transform: translateX(0);
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.25);
  }

  .app-navbar {
    padding: 0 1rem;
    height: 50px;
  }

  .app-content {
    padding: 0.85rem 0.75rem;
  }

  /* Tabelas com rolagem suave em dispositivos móveis */
  .table-responsive {
    -webkit-overflow-scrolling: touch;
    border-radius: 8px;
    margin-bottom: 0.75rem;
  }

  /* Ajuste de cards e grids em telas móveis */
  .card-custom {
    border-radius: 8px;
  }

  .stat-card {
    padding: 0.75rem;
  }
}

/* Smartphones & Dispositivos de Proporções Altas (ex: Samsung Galaxy S23 Ultra < 576px) */
@media (max-width: 575.98px) {
  .app-navbar {
    height: 48px;
    padding: 0 0.75rem;
  }

  .app-content {
    padding: 0.5rem 0.35rem;
  }

  .card-header-custom {
    padding: 0.45rem 0.65rem;
    font-size: 0.85rem;
  }

  .table-custom th {
    padding: 0.35rem 0.45rem;
    font-size: 0.72rem;
  }

  .table-custom td {
    padding: 0.35rem 0.45rem;
    font-size: 0.78rem; /* ~12.5px para densidade perfeita no S23 Ultra */
  }

  .table-cell-truncate {
    max-width: 140px;
  }

  .btn-action {
    padding: 0.16rem 0.32rem;
    font-size: 0.74rem;
    min-height: 24px;
    border-radius: 4px;
  }

  .modal-dialog {
    margin: 0.35rem;
  }

  .btn-sm {
    min-height: 30px;
    padding: 0.25rem 0.5rem;
    font-size: 0.80rem;
  }

  .badge {
    font-size: 0.68rem;
    padding: 0.2rem 0.4rem;
  }
}
