:root {
  --azul: #1a3a5c;
  --azul-medio: #1e5799;
  --azul-claro: #3a7abf;
  --verde: #2e7d32;
  --amarelo: #f59e0b;
  --vermelho: #dc2626;
  --cinza: #6b7280;
  --fundo: #f0f4f8;
  --branco: #ffffff;
  --sombra: 0 2px 12px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; margin: 0; padding: 0; text-transform: uppercase; user-select: none; }

input, textarea, select, [contenteditable] { user-select: text; }

body {
  font-family: 'Segoe UI', system-ui, sans-serif;
  background: var(--fundo);
  color: #1f2937;
  min-height: 100vh;
}

/* HEADER */
.header {
  background: var(--azul);
  color: white;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--sombra);
}
.header .logo { font-size: 1.5rem; }
.header h1 { font-size: 1.1rem; font-weight: 600; }
.header .subtitle { font-size: 0.75rem; opacity: 0.75; margin-top: 2px; }
.header-right { margin-left: auto; display: flex; gap: 8px; }

/* CONTAINER */
/* width:100% é necessário porque .main-content é flex-column: margin:0 auto
   desativa o "stretch" do flex e o container encolhe para o tamanho do
   conteúdo em vez de preencher até o max-width. */
.container { max-width: 900px; width: 100%; margin: 0 auto; padding: 24px 16px; }

/* CARDS */
.card {
  background: white;
  border-radius: 12px;
  box-shadow: var(--sombra);
  padding: 24px;
  margin-bottom: 20px;
}
.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--azul);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--fundo);
}

/* FORMULÁRIO */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.form-grid.full { grid-template-columns: 1fr; }
@media (max-width: 600px) { .form-grid { grid-template-columns: 1fr; } }

.form-group { display: flex; flex-direction: column; gap: 4px; }
.form-group.span-2 { grid-column: span 2; }
@media (max-width: 600px) { .form-group.span-2 { grid-column: span 1; } }

label { font-size: 0.8rem; font-weight: 600; color: #374151; }
input, select, textarea {
  padding: 10px 12px;
  border: 1.5px solid #d1d5db;
  border-radius: 8px;
  font-size: 0.9rem;
  transition: border-color 0.2s;
  background: white;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--azul-claro);
  box-shadow: 0 0 0 3px rgba(58,122,191,0.15);
}
textarea { resize: vertical; min-height: 80px; }

/* BOTÕES */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 20px;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  text-decoration: none;
}
.btn-primary { background: var(--azul); color: white; }
.btn-primary:hover { background: var(--azul-medio); }
.btn-success { background: var(--verde); color: white; }
.btn-success:hover { background: #1b5e20; }
.btn-outline {
  background: transparent;
  border: 2px solid var(--azul);
  color: var(--azul);
}
.btn-outline:hover { background: var(--azul); color: white; }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* LISTA DE PETS */
.pet-list { display: flex; flex-direction: column; gap: 12px; }
.pet-item {
  background: white;
  border-radius: 10px;
  padding: 16px 20px;
  box-shadow: var(--sombra);
  display: flex;
  align-items: center;
  gap: 16px;
  cursor: pointer;
  transition: all 0.2s;
  border-left: 4px solid var(--azul-claro);
}
.pet-item:hover { transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0,0,0,0.15); }
.pet-item.concluido { border-left-color: var(--verde); }
.pet-avatar {
  width: 48px; height: 48px;
  background: var(--fundo);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  flex-shrink: 0;
}
.pet-info { flex: 1; }
.pet-nome { font-weight: 700; font-size: 1rem; color: var(--azul); }
.pet-tutor { font-size: 0.8rem; color: var(--cinza); margin-top: 2px; }
.pet-meta { display: flex; gap: 8px; margin-top: 6px; flex-wrap: wrap; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 600;
}
.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #dcfce7; color: #15803d; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-gray { background: #f3f4f6; color: #374151; }

/* PROGRESS BAR */
.progress-bar {
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  overflow: hidden;
  margin-top: 8px;
}
.progress-fill {
  height: 100%;
  background: var(--azul-claro);
  border-radius: 3px;
  transition: width 0.5s ease;
}
.progress-fill.complete { background: var(--verde); }

/* TIMELINE */
.timeline { display: flex; flex-direction: column; gap: 0; }

.timeline-section { margin-bottom: 8px; }
.timeline-section-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cinza);
  padding: 8px 0 4px 44px;
}

.timeline-item {
  display: flex;
  gap: 16px;
  padding: 10px 0;
  position: relative;
}
.timeline-item:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 17px;
  top: 38px;
  bottom: -10px;
  width: 2px;
  background: #e5e7eb;
}
.timeline-item.concluida::after { background: var(--verde); }

.timeline-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 0.9rem;
  border: 2px solid #e5e7eb;
  background: white;
  z-index: 1;
}
.timeline-item.concluida .timeline-icon {
  background: var(--verde);
  border-color: var(--verde);
  color: white;
}
.timeline-item.em_andamento .timeline-icon {
  background: var(--azul-claro);
  border-color: var(--azul-claro);
  color: white;
  animation: pulse 2s infinite;
}
.timeline-item.pendente .timeline-icon {
  background: #f9fafb;
  color: #9ca3af;
}

@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(58,122,191,0.4); }
  50% { box-shadow: 0 0 0 6px rgba(58,122,191,0); }
}

.timeline-content { flex: 1; padding-top: 6px; }
.timeline-nome {
  font-size: 0.9rem;
  font-weight: 600;
  color: #1f2937;
}
.timeline-item.pendente .timeline-nome { color: #9ca3af; }
.timeline-meta {
  font-size: 0.75rem;
  color: var(--cinza);
  margin-top: 2px;
}
.timeline-obs {
  font-size: 0.78rem;
  color: #4b5563;
  background: var(--fundo);
  padding: 6px 10px;
  border-radius: 6px;
  margin-top: 6px;
}

/* OPERADOR - botões de etapa */
.etapa-actions { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.btn-etapa {
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 0.78rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-iniciar { background: #dbeafe; color: #1d4ed8; }
.btn-iniciar:hover { background: #bfdbfe; }
.btn-concluir { background: #dcfce7; color: #15803d; }
.btn-concluir:hover { background: #bbf7d0; }

/* RASTREIO CLIENTE */
.rastreio-header {
  background: linear-gradient(135deg, var(--azul) 0%, var(--azul-medio) 100%);
  color: white;
  padding: 44px 24px 40px;
  text-align: center;
}
.rastreio-header .pet-emoji {
  font-size: 3.2rem;
  margin-bottom: 10px;
  display: block;
  filter: drop-shadow(0 2px 8px rgba(0,0,0,0.7));
}
.rastreio-header h2 {
  font-size: 1.5rem;
  font-weight: 700;
  text-shadow: 0 1px 6px rgba(0,0,0,0.8);
  letter-spacing: 0.01em;
}
.rastreio-header p {
  opacity: 0.88;
  font-size: 0.9rem;
  margin-top: 4px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.6);
}
.rastreio-codigo {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.8rem;
  margin-top: 8px;
  letter-spacing: 0.1em;
}

.status-banner {
  padding: 12px 24px;
  text-align: center;
  font-weight: 700;
  font-size: 0.9rem;
}
.status-banner.em_andamento { background: #dbeafe; color: #1d4ed8; }
.status-banner.concluido { background: #dcfce7; color: #15803d; }

/* BUSCA */
.busca-wrapper {
  display: flex;
  gap: 8px;
  align-items: center;
}
.busca-wrapper input { flex: 1; }

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--cinza);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.9rem; }

/* MODAL */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: white;
  border-radius: 12px;
  padding: 24px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal h3 { font-size: 1rem; font-weight: 700; color: var(--azul); margin-bottom: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; justify-content: flex-end; }

/* CHIP DE CÓDIGO */
.codigo-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--azul);
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.1em;
}

/* TOAST */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: #1f2937;
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 0.9rem;
  z-index: 300;
  transition: transform 0.3s;
  white-space: nowrap;
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.success { background: var(--verde); }
.toast.error { background: var(--vermelho); }

/* NAV TABS */
.nav-tabs {
  display: flex;
  background: white;
  border-bottom: 2px solid #e5e7eb;
  position: sticky;
  top: 60px;
  z-index: 90;
}
.nav-tab {
  flex: 1;
  padding: 12px;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--cinza);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  transition: all 0.2s;
}
.nav-tab.active { color: var(--azul); border-bottom-color: var(--azul); }

.tab-content { display: none; }
.tab-content.active { display: block; }

/* LINK RASTREIO */
.link-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--fundo);
  border: 1.5px dashed #d1d5db;
  border-radius: 8px;
  padding: 10px 14px;
}
.link-box span { flex: 1; font-size: 0.82rem; color: var(--azul-medio); word-break: break-all; }
.link-box button {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--azul);
  font-size: 1rem;
  padding: 4px;
}

/* SCROLLBAR */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--fundo); }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ═══════════════════════════════════════════════
   LAYOUT COM SIDEBAR
═══════════════════════════════════════════════ */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: 240px;
  background: linear-gradient(180deg, #0f2540 0%, #1a3a5c 100%);
  color: white;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform 0.3s ease;
  overflow: hidden;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.sidebar-brand .brand-icon {
  font-size: 1.6rem;
  line-height: 1;
}
.sidebar-brand .brand-name {
  font-size: 1rem;
  font-weight: 800;
  line-height: 1.2;
}
.sidebar-brand .brand-sub {
  font-size: 0.68rem;
  opacity: 0.6;
  margin-top: 1px;
}

.sidebar-user {
  padding: 14px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 12px;
  text-align: left;
}
.sidebar-user .user-info { min-width: 0; max-width: 100%; }
.sidebar-user .user-avatar {
  width: 44px; height: 44px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-user .user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-user .user-name {
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar-user .user-perfil {
  font-size: 0.68rem;
  opacity: 0.6;
  margin-top: 1px;
}

.sidebar-nav {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}

.sidebar-section {
  padding: 14px 18px 4px;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.45;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  color: rgba(255,255,255,0.72);
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  transition: all 0.15s;
  border-left: 3px solid transparent;
  position: relative;
}
.sidebar-link:hover {
  background: rgba(255,255,255,0.08);
  color: white;
}
.sidebar-link.active {
  background: rgba(255,255,255,0.13);
  color: white;
  border-left-color: #60a5fa;
  font-weight: 600;
}
.sidebar-link .s-icon {
  font-size: 1.05rem;
  width: 22px;
  text-align: center;
  flex-shrink: 0;
}
.sidebar-link .s-badge {
  margin-left: auto;
  background: rgba(255,255,255,0.15);
  padding: 1px 6px;
  border-radius: 10px;
  font-size: 0.65rem;
  font-weight: 700;
}
.sidebar-link.danger { color: rgba(255,150,150,0.85); }
.sidebar-link.danger:hover { background: rgba(220,38,38,0.2); color: #fca5a5; }

.sidebar-footer {
  padding: 8px 0;
  border-top: 1px solid rgba(255,255,255,0.1);
}

/* ── Main content ── */
.main-content {
  margin-left: 240px;
  flex: 1;
  min-width: 0; /* sem isso, item flex não encolhe abaixo da largura do conteúdo (ex: tabela larga), estourando a página inteira */
  min-height: 100vh;
  background: var(--fundo);
  display: flex;
  flex-direction: column;
}

/* ── Mobile hamburger ── */
.hamburger {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px;
  color: white;
  font-size: 1.3rem;
}
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 199;
}

@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.show { display: block; }
  .main-content { margin-left: 0; }
  .hamburger { display: block; }
}

/* ── Page header (dentro de main-content) ── */
.page-header {
  background: white;
  border-bottom: 1px solid #e5e7eb;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.page-header h1 { font-size: 1.05rem; font-weight: 700; color: var(--azul); }
.page-header .page-subtitle { font-size: 0.78rem; color: var(--cinza); margin-top: 1px; }
.page-header-right { margin-left: auto; display: flex; gap: 8px; align-items: center; }

/* Celular: os controles do cabeçalho (busca, período, datas, botão) ficavam cada um
   numa linha própria, empurrados pra direita (a coluna começa onde .page-header-right
   fica, não em x=0) — em vez disso, o cabeçalho quebra pra 2 blocos de largura cheia:
   título em cima, controles embaixo, esses sim livres pra quebrar linha entre si. */
@media (max-width: 640px) {
  .page-header { flex-wrap: wrap; row-gap: 10px; }
  .page-header-right {
    margin-left: 0;
    width: 100%;
    flex-wrap: wrap;
  }
  /* alguns selects têm width:auto inline pra não esticar no layout de desktop —
     em telas pequenas isso faz mais sentido crescer com o resto dos controles */
  .page-header-right > input,
  .page-header-right > select,
  .page-header-right > button {
    width: auto !important;
    flex: 1 1 auto;
  }
  /* gráficos do dashboard: empilha em 1 coluna em vez de dois donuts espremidos.
     O card do topo tinha grid-column:span 2 — com só 1 coluna, isso força o grid
     a criar uma coluna implícita extra pra caber o span, estourando a largura. */
  .dash-charts-grid { grid-template-columns: minmax(0,1fr) !important; }
  .dash-card-full { grid-column: span 1 !important; }
}

/* ═══════════════════════════════════════════════
   TABELAS
═══════════════════════════════════════════════ */
.table-wrapper { overflow-x: auto; max-width: 100%; }
table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
thead th {
  background: var(--fundo);
  padding: 10px 14px;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--cinza);
  border-bottom: 2px solid #e5e7eb;
}
tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid #f3f4f6;
  color: #374151;
  vertical-align: middle;
}
tbody tr:hover td { background: #f9fafb; }
tbody tr:last-child td { border-bottom: none; }

/* ═══════════════════════════════════════════════
   STAT CARDS
═══════════════════════════════════════════════ */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: white;
  border-radius: 12px;
  padding: 20px;
  box-shadow: var(--sombra);
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.stat-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.stat-icon.blue  { background: #dbeafe; }
.stat-icon.green { background: #dcfce7; }
.stat-icon.yellow{ background: #fef9c3; }
.stat-icon.purple{ background: #ede9fe; }
.stat-value { font-size: 1.6rem; font-weight: 800; color: var(--azul); line-height: 1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.75rem; color: var(--cinza); margin-top: 3px; }

/* ═══════════════════════════════════════════════
   FILTRO DE PERÍODO (Página Inicial / Atendimentos)
   — vive no cabeçalho (.page-header-right) como um select discreto,
   não como um quadro separado.
═══════════════════════════════════════════════ */
#fp-resumo b { color: #1a3a5c; }

/* ═══════════════════════════════════════════════
   FORM SECTION
═══════════════════════════════════════════════ */
.section-divider {
  height: 1px;
  background: #e5e7eb;
  margin: 24px 0;
}
.form-section-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--cinza);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 14px;
}
