/* CRM Saúde Pro - Estilos customizados */

:root {
  --primary: #1e40af;
  --primary-light: #3b82f6;
  --secondary: #0f766e;
  --accent: #7c3aed;
  --danger: #dc2626;
  --warning: #d97706;
  --success: #16a34a;
  --sidebar-width: 260px;
}

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

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: #f8fafc;
  color: #1e293b;
  overflow-x: hidden;
}

/* ===== LAYOUT ===== */
#sidebar {
  width: var(--sidebar-width);
  background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
  min-height: 100vh;
  position: fixed;
  left: 0; top: 0;
  z-index: 100;
  transition: transform 0.3s ease;
  overflow-y: auto;
  box-shadow: 4px 0 20px rgba(0,0,0,0.3);

  .sidebar {
  height: 100vh;
  overflow-y: auto;
}

}

#main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  transition: margin-left 0.3s ease;
}

/* ===== SIDEBAR ===== */
.sidebar-logo {
  background: linear-gradient(135deg, #1e40af, #7c3aed);
  padding: 20px;
  text-align: center;
}

.sidebar-logo h1 {
  font-size: 1.1rem;
  font-weight: 800;
  color: white;
  letter-spacing: -0.5px;
}

.sidebar-logo p {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.6);
  margin-top: 2px;
}

.sidebar-section {
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}

.sidebar-section-title {
  font-size: 0.65rem;
  font-weight: 700;
  color: rgba(255,255,255,0.3);
  text-transform: uppercase;
  letter-spacing: 1.5px;
  padding: 8px 20px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: rgba(255,255,255,0.65);
  cursor: pointer;
  transition: all 0.2s;
  border-left: 3px solid transparent;
  font-size: 0.85rem;
}

.nav-item:hover {
  background: rgba(255,255,255,0.07);
  color: white;
}

.nav-item.active {
  background: rgba(59,130,246,0.15);
  color: #60a5fa;
  border-left-color: #3b82f6;
}

.nav-item i {
  width: 18px;
  text-align: center;
  font-size: 0.9rem;
}

.nav-badge {
  margin-left: auto;
  background: #dc2626;
  color: white;
  font-size: 0.65rem;
  padding: 1px 6px;
  border-radius: 10px;
  font-weight: 700;
}

/* ===== TOPBAR ===== */
#topbar {
  background: white;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: #1e293b;
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ===== CARDS / KPIs ===== */
.kpi-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid #e2e8f0;
  transition: transform 0.2s, box-shadow 0.2s;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.kpi-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  margin-bottom: 12px;
}

.kpi-value {
  font-size: 1.6rem;
  font-weight: 800;
  color: #1e293b;
  line-height: 1;
}

.kpi-label {
  font-size: 0.75rem;
  color: #64748b;
  margin-top: 4px;
  font-weight: 500;
}

.kpi-trend {
  font-size: 0.75rem;
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  text-decoration: none;
}

.btn-primary {
  background: #1e40af;
  color: white;
}

.btn-primary:hover { background: #1d4ed8; transform: translateY(-1px); }

.btn-secondary {
  background: #f1f5f9;
  color: #475569;
  border: 1px solid #e2e8f0;
}

.btn-secondary:hover { background: #e2e8f0; }

.btn-success {
  background: #16a34a;
  color: white;
}

.btn-success:hover { background: #15803d; }

.btn-danger {
  background: #dc2626;
  color: white;
}

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

.btn-warning {
  background: #d97706;
  color: white;
}

.btn-ai {
  background: linear-gradient(135deg, #7c3aed, #2563eb);
  color: white;
  box-shadow: 0 2px 8px rgba(124,58,237,0.3);
}

.btn-ai:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(124,58,237,0.4);
}

.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn-lg { padding: 12px 24px; font-size: 0.95rem; }

/* ===== TABELAS ===== */
.table-container {
  background: white;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid #e2e8f0;
  overflow: hidden;
}

.table-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #f1f5f9;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th {
  background: #f8fafc;
  padding: 10px 16px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #64748b;
  border-bottom: 1px solid #e2e8f0;
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
}

.data-table tr:hover td { background: #f8fafc; }
.data-table tr:last-child td { border-bottom: none; }

/* ===== BADGES / STATUS ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-success { background: #dcfce7; color: #16a34a; }
.badge-warning { background: #fef3c7; color: #d97706; }
.badge-danger { background: #fee2e2; color: #dc2626; }
.badge-info { background: #dbeafe; color: #2563eb; }
.badge-purple { background: #ede9fe; color: #7c3aed; }
.badge-gray { background: #f1f5f9; color: #64748b; }
.badge-teal { background: #ccfbf1; color: #0f766e; }

/* ===== PIPELINE KANBAN ===== */
.kanban-board {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 16px;
  min-height: 500px;
}

.kanban-column {
  min-width: 240px;
  max-width: 240px;
  background: #f1f5f9;
  border-radius: 12px;
  padding: 12px;
  flex-shrink: 0;
}

.kanban-column-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 10px;
  border-bottom: 2px solid;
}

.kanban-card {
  background: white;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border-left: 3px solid;
}

.kanban-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(0,0,0,0.1);
}

.kanban-card-title {
  font-size: 0.82rem;
  font-weight: 600;
  color: #1e293b;
  margin-bottom: 4px;
}

.kanban-card-meta {
  font-size: 0.72rem;
  color: #64748b;
}

/* ===== FORMULÁRIOS ===== */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 5px;
}

.form-input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.87rem;
  color: #1e293b;
  background: white;
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.form-input:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.form-select {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.87rem;
  background: white;
  cursor: pointer;
  outline: none;
}

.form-select:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.form-textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.87rem;
  resize: vertical;
  min-height: 80px;
  outline: none;
}

.form-textarea:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  animation: modalIn 0.2s ease;
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(-10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  background: #f8fafc;
}

/* ===== IA CHAT ===== */
.ia-chat-container {
  background: white;
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  height: 600px;
  overflow: hidden;
}

.ia-chat-header {
  background: linear-gradient(135deg, #1e40af, #7c3aed);
  padding: 16px 20px;
  color: white;
  display: flex;
  align-items: center;
  gap: 12px;
}

.ia-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.ia-message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 0.87rem;
  line-height: 1.6;
}

.ia-message.user {
  background: #1e40af;
  color: white;
  align-self: flex-end;
  border-radius: 12px 12px 2px 12px;
}

.ia-message.assistant {
  background: #f1f5f9;
  color: #1e293b;
  align-self: flex-start;
  border-radius: 12px 12px 12px 2px;
  border: 1px solid #e2e8f0;
}

.ia-chat-input {
  padding: 14px 16px;
  border-top: 1px solid #e2e8f0;
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.ia-chat-input textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #e2e8f0;
  border-radius: 10px;
  font-size: 0.87rem;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  outline: none;
}

.ia-chat-input textarea:focus {
  border-color: #7c3aed;
  box-shadow: 0 0 0 3px rgba(124,58,237,0.1);
}

/* ===== ANÁLISE IA ===== */
.ia-analise-card {
  background: linear-gradient(135deg, #ede9fe 0%, #dbeafe 100%);
  border: 1px solid #c4b5fd;
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
}

.score-ring {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 800;
  border: 5px solid;
  flex-shrink: 0;
}

/* ===== TABS ===== */
.tabs {
  display: flex;
  border-bottom: 2px solid #e2e8f0;
  margin-bottom: 20px;
  gap: 0;
  overflow-x: auto;
}

.tab {
  padding: 10px 20px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #64748b;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  white-space: nowrap;
  transition: all 0.2s;
}

.tab:hover { color: #1e293b; }

.tab.active {
  color: #1e40af;
  border-bottom-color: #1e40af;
}

/* ===== SEARCH BAR ===== */
.search-bar {
  position: relative;
  flex: 1;
}

.search-bar input {
  width: 100%;
  padding: 9px 12px 9px 36px;
  border: 1.5px solid #e2e8f0;
  border-radius: 8px;
  font-size: 0.87rem;
  outline: none;
  background: #f8fafc;
}

.search-bar input:focus {
  border-color: #3b82f6;
  background: white;
  box-shadow: 0 0 0 3px rgba(59,130,246,0.1);
}

.search-bar i {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
  font-size: 0.85rem;
}

/* ===== TOAST / NOTIFICAÇÃO ===== */
#toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: white;
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.87rem;
  font-weight: 500;
  min-width: 280px;
  max-width: 380px;
  border-left: 4px solid;
  animation: toastIn 0.3s ease;
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

.toast.success { border-left-color: #16a34a; }
.toast.error { border-left-color: #dc2626; }
.toast.warning { border-left-color: #d97706; }
.toast.info { border-left-color: #2563eb; }

/* ===== LOADING ===== */
.spinner {
  width: 20px;
  height: 20px;
  border: 2.5px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: inherit;
  z-index: 10;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #94a3b8;
}

.empty-state i {
  font-size: 3rem;
  margin-bottom: 12px;
  display: block;
  opacity: 0.4;
}

.empty-state p { font-size: 0.9rem; }

/* ===== CHARTS ===== */
.chart-container {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid #e2e8f0;
}

/* ===== PROGRESS BAR ===== */
.progress-bar {
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.5s ease;
}

/* ===== TIMELINE ===== */
.timeline {
  position: relative;
  padding-left: 24px;
}

.timeline::before {
  content: '';
  position: absolute;
  left: 7px;
  top: 0;
  bottom: 0;
  width: 2px;
  background: #e2e8f0;
}

.timeline-item {
  position: relative;
  padding-bottom: 20px;
}

.timeline-dot {
  position: absolute;
  left: -21px;
  top: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 0 0 2px #e2e8f0;
}

/* ===== RESPONSIVE - MOBILE / IPHONE ===== */
@media (max-width: 768px) {
  :root { --sidebar-width: 0px; }

  /* Sidebar oculta por padrão no mobile */
  #sidebar {
    transform: translateX(-260px);
    z-index: 200;
  }
  #sidebar.open {
    transform: translateX(0);
    width: 260px;
  }

  /* Overlay escuro ao abrir sidebar */
  #sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 199;
  }
  #sidebar-overlay.active { display: block; }

  /* Conteúdo principal ocupa tela toda */
  #main-content { margin-left: 0; }

  /* Topbar mobile */
  #topbar { padding: 10px 14px; }
  .topbar-title { font-size: 0.95rem; }
  .topbar-actions { gap: 8px; }

  /* KPI cards em coluna única */
  .kpi-grid {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 10px !important;
  }
  .kpi-card { padding: 14px; }
  .kpi-value { font-size: 1.3rem; }

  /* Section header empilhado */
  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }
  .section-header .topbar-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  /* Tabelas com scroll horizontal */
  .table-container { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table { min-width: 600px; }

  /* Kanban com scroll horizontal */
  .kanban-board { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .kanban-column { min-width: 220px; }

  /* Modais em tela cheia no mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    max-height: 92vh;
    border-radius: 20px 20px 0 0;
    animation: modalInMobile 0.3s ease;
  }
  @keyframes modalInMobile {
    from { opacity: 0; transform: translateY(40px); }
    to { opacity: 1; transform: translateY(0); }
  }

  /* IA Chat adaptado */
  .ia-chat-container { height: calc(100vh - 120px); border-radius: 12px; }

  /* Botões maiores para toque */
  .btn { padding: 10px 14px; font-size: 0.88rem; min-height: 40px; }
  .btn-sm { padding: 7px 12px; font-size: 0.80rem; }

  /* Formulários full width */
  .form-grid-2 { grid-template-columns: 1fr !important; }
  .form-grid-3 { grid-template-columns: 1fr !important; }

  /* Tabs com scroll */
  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab { padding: 10px 14px; font-size: 0.8rem; }

  /* Toast no topo no mobile */
  #toast-container {
    bottom: auto;
    top: 12px;
    right: 12px;
    left: 12px;
  }
  .toast { min-width: unset; max-width: 100%; }

  /* Charts responsivos */
  .chart-container canvas { max-height: 220px; }

  /* Padding geral menor */
  .modal-body { padding: 16px; }
  .modal-header { padding: 14px 16px; }
  .modal-footer { padding: 12px 16px; }

  /* Search bar full width */
  .search-bar { min-width: 0; }

  /* Grids adaptativos */
  [class*="grid-cols-2"],
  [class*="grid-cols-3"],
  [class*="grid-cols-4"] {
    grid-template-columns: 1fr !important;
  }
}

/* Telas muito pequenas (iPhone SE, etc) */
@media (max-width: 375px) {
  .kpi-grid { grid-template-columns: 1fr !important; }
  .kpi-value { font-size: 1.2rem; }
  .section-title { font-size: 1rem; }
  .topbar-title { font-size: 0.85rem; }
}

/* iPad / Tablet */
@media (min-width: 769px) and (max-width: 1024px) {
  :root { --sidebar-width: 220px; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr) !important; }
  .kanban-column { min-width: 200px; max-width: 200px; }
}

/* ===== UTILITIES ===== */
.text-truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cursor-pointer { cursor: pointer; }
.transition-all { transition: all 0.2s ease; }

/* ===== SECTIONS ===== */
.page-section { display: none; }
.page-section.active { display: block; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.section-title {
  font-size: 1.2rem;
  font-weight: 700;
  color: #1e293b;
}

/* ===== SAFE AREA (iPhone notch / home bar) ===== */
@supports (padding: env(safe-area-inset-bottom)) {
  #main-content {
    padding-bottom: env(safe-area-inset-bottom);
  }
  #topbar {
    padding-top: max(12px, env(safe-area-inset-top));
  }
  #sidebar {
    padding-bottom: env(safe-area-inset-bottom);
  }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }
