/* ==========================================================================
   ServCalhas — Design System & Global Styles (Vanilla CSS)
   Metodologia AprovaEnem: Tema Claro / Escuro via Variáveis CSS
   ========================================================================== */

:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;

  /* Cores Base - Tema Claro */
  --bg-app: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-sidebar: #0f172a;
  --text-sidebar: #cbd5e1;
  --text-sidebar-muted: #64748b;
  --sidebar-active-bg: #1e293b;
  --sidebar-active-text: #38bdf8;
  --sidebar-border: #1e293b;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --border-color: #e2e8f0;
  --border-subtle: #f1f5f9;

  /* Cores da Marca */
  --brand-50: #f0f9ff;
  --brand-100: #e0f2fe;
  --brand-500: #0ea5e9;
  --brand-600: #0284c7;
  --brand-700: #0369a1;
  --brand-900: #0c4a6e;

  /* Estados e Semântica */
  --success-bg: #ecfdf5;
  --success-text: #047857;
  --success-border: #a7f3d0;
  
  --danger-bg: #fef2f2;
  --danger-text: #b91c1c;
  --danger-border: #fecaca;

  --warning-bg: #fffbeb;
  --warning-text: #b45309;
  --warning-border: #fde68a;

  --info-bg: #eff6ff;
  --info-text: #1d4ed8;
  --info-border: #bfdbfe;

  /* Elevação e Raios */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.07);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.05);
  --shadow-modal: 0 20px 25px -5px rgba(0, 0, 0, 0.15), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
}

body.dark-theme {
  --bg-app: #090d16;
  --bg-card: #111827;
  --bg-card-hover: #1f2937;
  --bg-sidebar: #0b0f19;
  --text-sidebar: #9ca3af;
  --text-sidebar-muted: #6b7280;
  --sidebar-active-bg: #1f2937;
  --sidebar-active-text: #38bdf8;
  --sidebar-border: #1f2937;

  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --text-subtle: #6b7280;
  --border-color: #1f2937;
  --border-subtle: #182234;

  --success-bg: #064e3b;
  --success-text: #a7f3d0;
  --danger-bg: #7f1d1d;
  --danger-text: #fecaca;
  --warning-bg: #78350f;
  --warning-text: #fde68a;
  --info-bg: #1e3a8a;
  --info-text: #bfdbfe;
}

/* Reset Global */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   Estrutura da SPA e Layout
   ========================================================================== */

#app-workspace {
  display: flex;
  min-height: 100vh;
  position: relative;
}

/* Sidebar */
.app-sidebar {
  width: 270px;
  background-color: var(--bg-sidebar);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 100;
  border-right: 1px solid var(--sidebar-border);
  transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-header {
  padding: 20px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--sidebar-border);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.25rem;
  font-weight: 700;
  color: #ffffff;
  text-decoration: none;
}

.sidebar-logo span {
  color: #38bdf8;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.nav-section-title {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  color: var(--text-sidebar-muted);
  padding: 0 10px 6px;
}

.nav-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-sidebar);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s ease;
  cursor: pointer;
}

.nav-item:hover {
  background-color: rgba(255, 255, 255, 0.05);
  color: #ffffff;
}

.nav-item.active {
  background-color: var(--sidebar-active-bg);
  color: var(--sidebar-active-text);
  font-weight: 600;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  stroke-width: 2;
}

.sidebar-footer {
  padding: 16px 14px;
  border-top: 1px solid var(--sidebar-border);
  background-color: rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.user-badge-card {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: linear-gradient(135deg, var(--brand-600), #38bdf8);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
}

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

.user-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: #ffffff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.72rem;
  color: var(--text-sidebar-muted);
  text-transform: capitalize;
}

.sidebar-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

/* Área de Conteúdo Principal */
.app-main {
  flex: 1;
  margin-left: 270px;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.app-topbar {
  display: none;
  height: 60px;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
  gap: 10px;
}

/* Botão de Instalação PWA no Topo (Mobile) */
.btn-pwa-install {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  color: #ffffff;
  background: linear-gradient(135deg, #0284c7, #0369a1);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 20px;
  cursor: pointer;
  box-shadow: 0 3px 10px -2px rgba(2, 132, 199, 0.45);
  transition: all 0.2s ease;
  flex-shrink: 0;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}

.btn-pwa-install:hover {
  background: linear-gradient(135deg, #0369a1, #075985);
  box-shadow: 0 4px 14px -2px rgba(2, 132, 199, 0.6);
  transform: translateY(-1px);
}

.btn-pwa-install:active {
  transform: scale(0.96);
}

.pwa-icon-bounce {
  animation: pwaBounce 2.5s infinite ease-in-out;
}

@keyframes pwaBounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-2px); }
}

@media (max-width: 380px) {
  .btn-pwa-install {
    padding: 5px 9px;
    font-size: 0.78rem;
  }
}

/* Modal Instruções PWA (iOS / Safari) */
.pwa-steps-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pwa-step-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-main);
  padding: 12px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.pwa-step-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--brand-600);
  color: #ffffff;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.pwa-step-text {
  font-size: 0.88rem;
  color: var(--text-main);
  line-height: 1.4;
  flex: 1;
}

.pwa-icon-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  vertical-align: middle;
  margin: 0 4px;
  color: var(--brand-600);
  padding: 2px 4px;
  background: rgba(2, 132, 199, 0.12);
  border-radius: 4px;
}

.app-content {
  flex: 1;
  padding: 30px;
  max-width: 1380px;
  width: 100%;
  margin: 0 auto;
}

/* Backdrop Mobile */
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.5);
  z-index: 90;
}

/* ==========================================================================
   Componentes Utilitários: Cards, Botões, Tabelas, Inputs
   ========================================================================== */

.card {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: 20px;
}

.card-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin-bottom: 14px;
}

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.15s ease;
  line-height: 1.25;
}

.btn-primary {
  background-color: var(--brand-600);
  color: #ffffff;
}
.btn-primary:hover {
  background-color: var(--brand-700);
}

.btn-secondary {
  background-color: var(--bg-card);
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-secondary:hover {
  background-color: var(--bg-card-hover);
}

.btn-danger {
  background-color: var(--danger-text);
  color: #ffffff;
}
.btn-danger:hover {
  background-color: #991b1b;
}

.btn-ghost {
  background-color: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  background-color: var(--bg-card-hover);
  color: var(--text-main);
}

.btn-sm {
  padding: 5px 10px;
  font-size: 0.8rem;
}

.btn:disabled, .btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
  pointer-events: none;
}

/* Formulários & Inputs */
.label {
  display: block;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.input, .select, .textarea {
  width: 100%;
  padding: 8px 12px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  font-size: 0.88rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.18);
}

.textarea {
  min-height: 80px;
  resize: vertical;
}

/* Tabelas de Dados */
.table-container {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  background-color: var(--bg-card);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.88rem;
}

.data-table thead {
  background-color: var(--bg-app);
  border-bottom: 1px solid var(--border-color);
}

.data-table th {
  padding: 12px 16px;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tbody tr:hover {
  background-color: var(--bg-card-hover);
}

/* Badges de Status */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.badge-success {
  background-color: var(--success-bg);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}

.badge-warning {
  background-color: var(--warning-bg);
  color: var(--warning-text);
  border: 1px solid var(--warning-border);
}

.badge-danger {
  background-color: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
}

.badge-info {
  background-color: var(--info-bg);
  color: var(--info-text);
  border: 1px solid var(--info-border);
}

.badge-neutral {
  background-color: var(--bg-card-hover);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

/* Modais */
.modal-overlay {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

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

.modal-container {
  background-color: var(--bg-card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-modal);
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transform: scale(0.96);
  transition: transform 0.2s ease;
  border: 1px solid var(--border-color);
}

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

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  background-color: var(--bg-app);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* Modais de Autenticação Compactos (Desktop & Mobile) */
.modal-auth-container {
  max-width: 380px !important;
  width: 100%;
}

.auth-tabs {
  padding: 12px 18px 0;
  display: flex;
  gap: 8px;
}

.auth-tabs .btn {
  flex: 1;
  height: 36px;
  font-size: 0.86rem;
  padding: 0 10px;
}

.auth-modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-modal-body .label {
  margin-bottom: 4px;
  font-size: 0.82rem;
}

.auth-modal-body .input {
  height: 38px;
  font-size: 0.9rem;
  padding: 8px 12px;
}

.btn-auth-submit {
  height: 40px;
  font-size: 0.92rem;
  margin-top: 4px;
  font-weight: 600;
}

/* Responsividade Mobile para Modais */
@media (max-width: 480px) {
  .modal-overlay {
    padding: 12px 10px;
    align-items: center;
  }

  .modal-container {
    max-height: calc(100dvh - 24px);
    border-radius: 14px;
  }

  .modal-auth-container {
    max-width: 100% !important;
    margin: auto 0;
  }

  .modal-header {
    padding: 10px 14px;
  }

  .modal-header h3 {
    font-size: 0.96rem;
  }

  .modal-header .btn-ghost {
    padding: 2px 8px;
    font-size: 1.25rem;
    line-height: 1;
  }

  .auth-tabs {
    padding: 10px 14px 0;
    gap: 6px;
  }

  .auth-tabs .btn {
    height: 32px;
    font-size: 0.8rem;
  }

  .auth-modal-body {
    padding: 12px 14px;
    gap: 10px;
  }

  .auth-modal-body .label {
    font-size: 0.78rem;
    margin-bottom: 2px;
  }

  .auth-modal-body .input {
    height: 36px;
    font-size: 0.88rem;
    padding: 6px 10px;
  }

  .btn-auth-submit {
    height: 38px;
    font-size: 0.88rem;
    margin-top: 2px;
  }
}

/* Telas com altura muito reduzida (landscape ou teclado virtual aberto) */
@media (max-height: 600px) {
  .modal-overlay {
    padding: 6px;
    align-items: flex-start;
  }

  .modal-container {
    max-height: calc(100dvh - 12px);
  }

  .modal-header {
    padding: 8px 12px;
  }

  .auth-tabs {
    padding: 6px 12px 0;
  }

  .auth-modal-body {
    padding: 8px 12px;
    gap: 8px;
  }
}

/* Toast Notifications */
#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  min-width: 280px;
  max-width: 420px;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background-color: var(--bg-card);
  color: var(--text-main);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.88rem;
  animation: toastIn 0.25s ease-out;
}

.toast.toast-success { border-left: 4px solid var(--success-text); }
.toast.toast-error { border-left: 4px solid var(--danger-text); }
.toast.toast-info { border-left: 4px solid var(--brand-600); }

@keyframes toastIn {
  from { transform: translateY(100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* Spinner */
.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 50%;
  border-top-color: currentColor;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}

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

/* ==========================================================================
   Gráficos e Indicadores Visuais do Dashboard
   ========================================================================== */

.charts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

@media (max-width: 1100px) {
  .charts-grid {
    grid-template-columns: repeat(auto-fit, minmax(310px, 1fr));
  }
}

.chart-card {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  min-height: 310px;
}

.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 10px;
}

.chart-header-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chart-header-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.chart-header-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}

.chart-badge {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 6px;
  background: rgba(2, 132, 199, 0.1);
  color: var(--brand-600);
  white-space: nowrap;
}

.chart-body {
  position: relative;
  width: 100%;
  height: 220px;
  max-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-gauge-overlay {
  position: absolute;
  top: 52%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

.chart-gauge-value {
  font-size: 1.85rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1;
}

.chart-gauge-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-top: 3px;
}

.chart-stars {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: #f59e0b;
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ==========================================================================
   Responsividade Mobile
   ========================================================================== */

@media (max-width: 900px) {
  .app-sidebar {
    transform: translateX(-100%);
  }

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

  .app-sidebar.open + .sidebar-backdrop {
    display: block;
  }

  .app-main {
    margin-left: 0;
  }

  .app-topbar {
    display: flex;
  }

  .app-content {
    padding: 16px;
  }

  .chart-card {
    padding: 16px;
    min-height: 280px;
  }

  .chart-body {
    height: 200px;
  }

  .chart-header-title {
    font-size: 0.95rem;
  }
}

/* ==========================================================================
   Modo de Impressão de Proposta / Orçamento
   ========================================================================== */

@media print {
  body {
    background: #ffffff !important;
    color: #000000 !important;
  }

  .app-sidebar, .app-topbar, .no-print, #toast-container, .modal-overlay {
    display: none !important;
  }

  .app-main {
    margin-left: 0 !important;
  }

  .app-content {
    padding: 0 !important;
    max-width: 100% !important;
  }

  .card {
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
  }
}
