/* =============================================================
   styles.css — MaterialM Tailwind Design System (MSBicalho SaaS)
   ============================================================= */

/* ─── Google Fonts: Plus Jakarta Sans (MaterialM Standard) ─── */
@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:wght@300;400;500;600;700;800&display=swap');

/* ─── Reset & Base ─── */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  overflow-x: hidden;
  width: 100%;
  max-width: 100vw;
  min-width: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: #F4F6F9;
  color: #2A3547;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── Variáveis Globais de Cores (MaterialM Theme Tokens) ─── */
:root {
  --color-primary: #5D87FF;
  --color-primary-hover: #4570EA;
  --color-primary-light: #ECF2FF;
  --color-secondary: #49BEFF;
  --color-secondary-light: #E8F7FF;
  --color-success: #13DEB9;
  --color-success-light: #E6FFFA;
  --color-warning: #FFAE1F;
  --color-warning-light: #FEF5E5;
  --color-danger: #FA896B;
  --color-danger-light: #FBF2EF;
  --color-dark: #2A3547;
  --color-muted: #7C8FAC;
  --color-border: #EAEFF4;
  --color-body-bg: #F4F6F9;
}

/* ─── Scrollbar Customizada ─── */
html {
  accent-color: #5D87FF;
}

* {
  scrollbar-color: rgba(93, 135, 255, 0.25) rgba(0, 0, 0, 0.02);
  scrollbar-width: thin;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: rgba(0, 0, 0, 0.02);
  border-radius: 10px;
}

::-webkit-scrollbar-thumb {
  background: rgba(93, 135, 255, 0.2);
  border-radius: 10px;
  transition: background 0.3s;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(93, 135, 255, 0.5);
}

/* ─── Glassmorphism Card (Login & Cadastro) ─── */
.glass-card {
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: 1.5rem;
  box-shadow: 0 20px 40px -15px rgba(93, 135, 255, 0.15), 0 0 0 1px rgba(234, 239, 244, 0.8);
}

/* ─── Campos de Entrada (Input Fields MaterialM) ─── */
.input-field {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid #EAEFF4;
  border-radius: 0.75rem;
  padding: 0.625rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 500;
  background: #FFFFFF;
  color: #2A3547;
  width: 100%;
  outline: none;
}

.input-field:focus {
  border-color: #5D87FF;
  box-shadow: 0 0 0 3px rgba(93, 135, 255, 0.12);
  background: #FFFFFF;
}

.input-field:disabled {
  background: #F4F6F9;
  color: #7C8FAC;
  cursor: not-allowed;
}

.input-field-dark {
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border: 1px solid #EAEFF4;
  border-radius: 0.75rem;
  padding: 0.625rem 1rem;
  font-size: 0.875rem;
  background: #F4F6F9;
  color: #2A3547;
  width: 100%;
  outline: none;
}

.input-field-dark:focus {
  border-color: #5D87FF;
  background: #FFFFFF;
  box-shadow: 0 0 0 3px rgba(93, 135, 255, 0.15);
}

/* ─── Botões MaterialM ─── */
.btn-primary {
  background: #5D87FF;
  color: #FFFFFF;
  font-weight: 700;
  font-size: 0.8125rem;
  padding: 0.625rem 1.25rem;
  border-radius: 0.75rem;
  border: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(93, 135, 255, 0.25);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
}

.btn-primary:hover {
  background: #4570EA;
  box-shadow: 0 6px 20px rgba(93, 135, 255, 0.35);
  transform: translateY(-1px);
}

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

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.btn-secondary {
  background: #FFFFFF;
  color: #2A3547;
  font-weight: 600;
  font-size: 0.8125rem;
  padding: 0.625rem 1.125rem;
  border-radius: 0.75rem;
  border: 1px solid #EAEFF4;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  text-decoration: none;
}

.btn-secondary:hover {
  background: #ECF2FF;
  color: #5D87FF;
  border-color: #5D87FF;
  transform: translateY(-1px);
}

.btn-danger {
  background: #FA896B;
  color: white;
  font-weight: 600;
  font-size: 0.8125rem;
  padding: 0.625rem 1.125rem;
  border-radius: 0.75rem;
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(250, 137, 107, 0.25);
  transition: all 0.2s;
}

.btn-danger:hover {
  background: #E57354;
}

.btn-icon {
  width: 34px;
  height: 34px;
  border-radius: 0.625rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon-primary {
  color: #5D87FF;
}
.btn-icon-primary:hover {
  background: #ECF2FF;
  color: #4570EA;
}

.btn-icon-secondary {
  color: #7C8FAC;
}
.btn-icon-secondary:hover {
  background: #F4F6F9;
  color: #2A3547;
}

.btn-icon-danger {
  color: #FA896B;
}
.btn-icon-danger:hover {
  background: #FBF2EF;
  color: #E57354;
}

/* ─── Cards & Seções MaterialM ─── */
.materialm-card,
.section-card {
  background: #FFFFFF;
  border: 1px solid #EAEFF4;
  border-radius: 1.25rem;
  padding: 1.5rem;
  box-shadow: 0 9px 17.5px rgba(0, 0, 0, 0.03);
  transition: all 0.2s ease;
  width: 100%;
}

.materialm-card:hover,
.section-card:hover {
  box-shadow: 0 12px 25px rgba(93, 135, 255, 0.08);
  border-color: #D8E0EA;
}

.section-title {
  font-size: 0.875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #2A3547;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.section-title svg {
  width: 1.25rem !important;
  height: 1.25rem !important;
  color: #5D87FF;
  flex-shrink: 0 !important;
}

.label-text {
  display: block;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #7C8FAC;
  margin-bottom: 0.375rem;
}

/* ─── Modais & Diálogos Nativos (<dialog>) ─── */
dialog {
  margin: auto !important;
  position: fixed !important;
  inset: 0 !important;
  border: none !important;
  outline: none !important;
  padding: 0;
  max-width: 95vw;
  max-height: 92vh;
  z-index: 50;
  background: transparent;
}

dialog[open] {
  display: block !important;
  animation: modalFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.55) !important;
  backdrop-filter: blur(8px) !important;
  -webkit-backdrop-filter: blur(8px) !important;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-content {
  background: #FFFFFF;
  border: 1px solid #EAEFF4;
  border-radius: 1.5rem;
  padding: 1.75rem;
  width: 92vw;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(93, 135, 255, 0.2);
  margin: auto !important;
}

/* ─── Badges de Status (MaterialM Pill Style) ─── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.75rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.badge-emitted {
  background: #FEF5E5;
  color: #FFAE1F;
  border-color: rgba(255, 174, 31, 0.3);
}
.badge-emitted::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #FFAE1F;
}

.badge-approved {
  background: #E6FFFA;
  color: #13DEB9;
  border-color: rgba(19, 222, 185, 0.3);
}
.badge-approved::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #13DEB9;
}

.badge-draft {
  background: #F4F6F9;
  color: #7C8FAC;
  border-color: #EAEFF4;
}
.badge-draft::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #7C8FAC;
}

.badge-cancelled {
  background: #FBF2EF;
  color: #FA896B;
  border-color: rgba(250, 137, 107, 0.3);
}
.badge-cancelled::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #FA896B;
}

.badge-rejected {
  background: #FBF2EF;
  color: #FA896B;
  border-color: rgba(250, 137, 107, 0.3);
}
.badge-rejected::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #FA896B;
}

/* ─── Layout Geral (App Layout) ─── */
.app-layout {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

.app-main-content {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #F4F6F9;
}

.app-bg {
  background: #F4F6F9;
  min-height: 100vh;
}

/* ─── SIDEBAR MATERIAL-M (Light Clean, Rounded Pill Nav) ─── */
.sidebar {
  width: 270px;
  background: #FFFFFF;
  border-right: 1px solid #EAEFF4;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  position: sticky;
  top: 0;
  z-index: 40;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s ease;
}

.sidebar.sidebar-hidden {
  display: none !important;
}

.sidebar.collapsed {
  width: 80px;
}

.sidebar.collapsed .sidebar-text,
.sidebar.collapsed .sidebar-section-title,
.sidebar.collapsed .sidebar-badge,
.sidebar.collapsed .user-info-text,
.sidebar.collapsed .sidebar-logo-title {
  display: none !important;
}

.sidebar.collapsed .sidebar-header,
.sidebar.collapsed .sidebar-nav-item,
.sidebar.collapsed .sidebar-user-card {
  justify-content: center;
  padding-left: 0;
  padding-right: 0;
}

/* Header da Sidebar */
.sidebar-header {
  height: 72px;
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #EAEFF4;
}

.sidebar-toggle-btn {
  width: 34px;
  height: 34px;
  border-radius: 0.625rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #F4F6F9;
  color: #7C8FAC;
  transition: all 0.2s;
  cursor: pointer;
  border: none;
}

.sidebar-toggle-btn:hover {
  background: #ECF2FF;
  color: #5D87FF;
}

/* Conteúdo da Sidebar */
.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.sidebar-section-title {
  font-size: 0.6875rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #7C8FAC;
  padding: 0 0.875rem 0.5rem 0.875rem;
}

/* Itens de Menu Nav (MaterialM Pill Style) */
.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: #5A6A85;
  text-decoration: none;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
}

.sidebar-nav-item:hover {
  background: #ECF2FF;
  color: #5D87FF;
}

.sidebar-nav-item.active {
  background: linear-gradient(135deg, #5D87FF 0%, #4f46e5 100%);
  color: #FFFFFF !important;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(93, 135, 255, 0.35);
}

.sidebar-nav-item .nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-badge {
  margin-left: auto;
  font-size: 0.6875rem;
  font-weight: 800;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  background: #ECF2FF;
  color: #5D87FF;
}

.sidebar-nav-item.active .sidebar-badge {
  background: rgba(255, 255, 255, 0.25);
  color: #FFFFFF;
}

/* Footer da Sidebar (User Profile Card) */
.sidebar-footer {
  padding: 1rem 0.875rem;
  border-top: 1px solid #EAEFF4;
}

.sidebar-user-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: 0.875rem;
  background: #F4F6F9;
  border: 1px solid #EAEFF4;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 0.75rem;
  background: #5D87FF;
  color: #FFFFFF;
  font-weight: 800;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(93, 135, 255, 0.3);
}

.user-info-text {
  flex: 1;
  min-width: 0;
}

.user-email-text {
  font-size: 0.75rem;
  font-weight: 700;
  color: #2A3547;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tenant-badge-text {
  font-size: 0.6875rem;
  color: #7C8FAC;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ─── Mobile Sidebar Overlay ─── */
@media (max-width: 1023px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    transform: translateX(-100%);
    width: 270px !important;
  }
  
  .sidebar.mobile-open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    z-index: 35;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
  }

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

/* ─── Diálogos & Modais Responsivos Universais ─── */
dialog {
  margin: auto !important;
  max-height: calc(100vh - 2rem);
  max-height: calc(100dvh - 2rem);
  border: none;
  border-radius: 1.25rem;
  padding: 0;
  box-sizing: border-box;
  box-shadow: 0 25px 50px -12px rgba(15, 23, 42, 0.25);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.65);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

@media (max-width: 768px) {
  dialog {
    width: calc(100vw - 1rem) !important;
    max-width: calc(100vw - 1rem) !important;
    border-radius: 1rem !important;
    margin: auto !important;
  }

  .app-main-content {
    padding: 0.75rem 0.5rem !important;
  }

  .card {
    padding: 1rem !important;
    border-radius: 1rem !important;
  }
}

/* ─── Utilitários de Tabela Responsiva ─── */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ─── Background Login ─── */
.login-bg {
  background: linear-gradient(135deg, #F4F6F9 0%, #E8F0FE 50%, #ECF2FF 100%);
  min-height: 100vh;
  position: relative;
  overflow: hidden;
}

/* ─── Spinner ─── */
.spinner {
  width: 1.25rem;
  height: 1.25rem;
  border: 2.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.hidden { display: none !important; }

/* ─── Cupom Térmico PDV em Tela ─── */
@media screen {
  .cupom-termico-container,
  #cupom-termico-print {
    display: none !important;
  }
}

/* ─── Estilos de Impressão Geral (A4 e Cupom Térmico 80mm/58mm) ─── */
@media print {
  @page {
    size: auto;
    margin: 0mm;
  }

  /* Caso 1: Cupom Térmico do PDV (Venda ou Fechamento de Caixa) */
  body:has(.cupom-termico-container.printing) > :not(.cupom-termico-container.printing) {
    display: none !important;
  }

  body:has(.cupom-termico-container.printing) {
    margin: 0 !important;
    padding: 0 !important;
    background: #FFFFFF !important;
    color: #000000 !important;
    visibility: visible !important;
  }

  .cupom-termico-container.printing {
    display: block !important;
    visibility: visible !important;
    position: static !important;
    width: 80mm !important;
    max-width: 80mm !important;
    margin: 0 auto !important;
    padding: 2mm 3mm !important;
    font-family: 'Courier New', Courier, monospace !important;
    font-size: 11px !important;
    line-height: 1.25 !important;
    color: #000000 !important;
    background: #FFFFFF !important;
  }

  .cupom-termico-container.printing * {
    visibility: visible !important;
    color: #000000 !important;
  }

  /* Caso 2: Orçamento em Folha A4 */
  body:has(#print-sheet) > :not(#print-sheet) {
    display: none !important;
  }

  body:has(#print-sheet) #print-sheet {
    display: block !important;
    visibility: visible !important;
    width: 100% !important;
    max-width: 100% !important;
    padding: 2mm 10mm 10mm 10mm !important;
    margin: 0 !important;
    background: white !important;
    color: #1e293b !important;
  }
}
