/* ============================
   SISTEMA DO ESCRITÓRIO — CSS
   ============================ */

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

:root {
  --sidebar-bg: #1a2744;
  --sidebar-hover: #243257;
  --sidebar-active: #2d3f6e;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --danger: #ef4444;
  --success: #22c55e;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-light: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.06);
  --radius: 10px;
  --sidebar-width: 240px;
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* ============================
   LAYOUT COM SIDEBAR
   ============================ */

.layout {
  display: flex;
  min-height: 100vh;
}

/* SIDEBAR */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-logo {
  padding: 28px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-logo h1 {
  font-size: 15px;
  font-weight: 700;
  color: #ffffff;
  letter-spacing: 0.5px;
  line-height: 1.3;
}

.sidebar-logo p {
  font-size: 11px;
  color: rgba(255,255,255,0.45);
  margin-top: 3px;
  letter-spacing: 0.3px;
}

.sidebar-nav {
  flex: 1 1 auto;
  min-height: 0;              /* permite encolher abaixo do conteúdo em flex column */
  overflow-y: auto;           /* rola internamente quando o menu excede a viewport */
  overscroll-behavior: contain;
  padding: 12px 0;
}

/* Scrollbar discreta para combinar com o tema escuro da sidebar */
.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-track { background: transparent; }
.sidebar-nav::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.28);
}
.sidebar-nav { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.2) transparent; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  color: rgba(255,255,255,0.72);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
  background: var(--sidebar-hover);
  color: #ffffff;
}

.sidebar-nav a.active {
  background: var(--sidebar-active);
  color: #ffffff;
  border-left-color: var(--accent);
}

.sidebar-nav a .icon {
  font-size: 16px;
  opacity: 0.85;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-footer .user-info {
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  margin-bottom: 10px;
}

.sidebar-footer .user-info strong {
  display: block;
  color: rgba(255,255,255,0.85);
  font-size: 13px;
  margin-bottom: 1px;
}

.sidebar-footer a {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  transition: color 0.15s;
}

.sidebar-footer a:hover {
  color: var(--danger);
}

/* CONTEÚDO PRINCIPAL */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 36px 36px 60px;
  min-height: 100vh;
}

/* ============================
   CABEÇALHO DE PÁGINA
   ============================ */

.page-header {
  margin-bottom: 28px;
}

.page-header h2 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
}

.page-header p {
  font-size: 14px;
  color: var(--text-light);
  margin-top: 4px;
}

.breadcrumb {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-light);
  margin-bottom: 8px;
}

.breadcrumb a {
  color: var(--accent);
  text-decoration: none;
}

.breadcrumb a:hover {
  text-decoration: underline;
}

.breadcrumb span {
  opacity: 0.5;
}

/* ============================
   CARDS
   ============================ */

.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 24px;
  margin-bottom: 24px;
}

.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 18px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

/* ============================
   FORMULÁRIOS
   ============================ */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.form-group textarea {
  min-height: 90px;
  resize: vertical;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

/* ============================
   BOTÕES
   ============================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: 7px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, transform 0.1s;
  text-decoration: none;
  font-family: inherit;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--border);
  color: var(--text);
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-outline {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

.btn-outline:hover {
  background: rgba(59,130,246,0.07);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 13px;
}

/* ============================
   TABELA DE CLIENTES / PROCESSOS
   ============================ */

.table-container {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-light);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: #f8fafc;
}

tbody td {
  padding: 12px 14px;
  color: var(--text);
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

.badge-blue { background: #dbeafe; color: #1d4ed8; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-yellow { background: #fef9c3; color: #854d0e; }
.badge-gray { background: #f1f5f9; color: #475569; }
.badge-red { background: #fee2e2; color: #dc2626; }

/* ============================
   CARDS DE RESUMO (HOME)
   ============================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

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

.stat-card .label {
  font-size: 12px;
  color: var(--text-light);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.stat-card .value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  margin: 6px 0 2px;
}

.stat-card .sub {
  font-size: 12px;
  color: var(--text-light);
}

/* ============================
   ATENDIMENTOS
   ============================ */

.atendimento-item {
  display: flex;
  gap: 14px;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}

.atendimento-item:last-child {
  border-bottom: none;
}

.atendimento-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #dbeafe;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  margin-top: 2px;
}

.atendimento-body {
  flex: 1;
}

.atendimento-meta {
  font-size: 12px;
  color: var(--text-light);
  margin-bottom: 4px;
}

.atendimento-desc {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
}

/* ============================
   LOGIN PAGE
   ============================ */

.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1a2744 0%, #2d3f6e 100%);
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.2);
  padding: 44px 40px;
  width: 100%;
  max-width: 380px;
}

.login-card .logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-card .logo h1 {
  font-size: 20px;
  font-weight: 800;
  color: var(--sidebar-bg);
  line-height: 1.3;
}

.login-card .logo p {
  font-size: 13px;
  color: var(--text-light);
  margin-top: 4px;
}

.login-card .logo .icon {
  font-size: 40px;
  margin-bottom: 10px;
}

/* ============================
   ALERT / MENSAGENS
   ============================ */

.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 16px;
}

.alert-error {
  background: #fee2e2;
  color: #b91c1c;
  border: 1px solid #fca5a5;
}

.alert-success {
  background: #dcfce7;
  color: #166534;
  border: 1px solid #86efac;
}

/* ============================
   HAMBURGER BUTTON (mobile)
   ============================ */

#ceh-hamburger {
  display: none;
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 500;
  background: var(--sidebar-bg);
  border: none;
  border-radius: 8px;
  width: 44px;
  height: 44px;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 5px;
  padding: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: opacity .2s, visibility .2s;
}

/* Esconde hamburger quando sidebar está aberta (evita sobrepor logo) */
.sidebar.sidebar-open ~ #ceh-hamburger,
body.sidebar-open #ceh-hamburger {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

#ceh-hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: #fff;
  border-radius: 2px;
  transition: all .25s;
}

#ceh-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ============================
   RESPONSIVO
   ============================ */

@media (max-width: 768px) {

  /* Hamburger visível */
  #ceh-hamburger { display: flex; }

  /* Sidebar vira drawer lateral */
  .sidebar {
    transform: translateX(-100%);
    transition: transform .28s cubic-bezier(.4,0,.2,1);
    z-index: 200;
    width: 260px;
    overflow-y: auto;      /* permite rolar o menu inteiro no mobile */
    overflow-x: hidden;
  }
  .sidebar.sidebar-open {
    transform: translateX(0);
  }

  /* Botão fechar (X) dentro da sidebar — só visível no mobile */
  #ceh-sidebar-close {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 10px 14px 0;
  }
  #ceh-sidebar-close button {
    background: rgba(255,255,255,0.1);
    border: none;
    border-radius: 6px;
    color: #fff;
    font-size: 20px;
    width: 36px;
    height: 36px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
  }
  #ceh-sidebar-close button:hover { background: rgba(255,255,255,0.2); }

  /* Overlay de fundo quando sidebar aberta */
  #ceh-overlay.overlay-open { display: block; }

  /* Conteúdo ocupa tela toda */
  .main-content {
    margin-left: 0;
    padding: 68px 16px 32px;
  }

  /* Form rows em coluna */
  .form-row {
    grid-template-columns: 1fr;
  }

  /* Tabelas roláveis — funciona com e sem .table-container */
  .table-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
  }
  /* Tabelas sem container: scroll no próprio elemento */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Tabelas já dentro de .table-container: comportamento normal */
  .table-container table {
    display: table;
    min-width: 560px;
  }

  /* Cards com menos padding */
  .card {
    padding: 16px;
    margin-bottom: 14px;
  }

  /* Botões maiores para toque */
  .btn {
    padding: 10px 16px;
    font-size: 14px;
    min-height: 42px;
  }
  .btn-sm {
    padding: 7px 12px;
    font-size: 13px;
    min-height: 36px;
  }

  /* Inputs maiores */
  input[type=text], input[type=email], input[type=password],
  input[type=tel], input[type=date], input[type=number],
  select, textarea {
    font-size: 16px !important; /* evita zoom automático no iOS */
    padding: 10px 12px;
  }

  /* Modais em tela cheia */
  div[style*="position:fixed"][style*="z-index"] > div,
  div[style*="position: fixed"][style*="z-index"] > div {
    max-width: 100% !important;
    width: 100% !important;
    min-height: 100dvh;
    border-radius: 0 !important;
    margin: 0 !important;
    overflow-y: auto;
  }

  /* Page header compacto */
  .page-header h2 { font-size: 20px; }

  /* Tab nav rolável */
  .tab-nav {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-wrap: nowrap;
    padding-bottom: 2px;
  }
  .tab-btn {
    padding: 8px 14px;
    font-size: 13px;
  }

  /* Flex rows viram coluna */
  .proc-tabs,
  [style*="display:flex"][style*="justify-content:space-between"] {
    flex-wrap: wrap;
  }

  /* Breadcrumb compacto */
  .breadcrumb { font-size: 12px; flex-wrap: wrap; }

  /* Grid de métricas — 1 coluna */
  [style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Oculta colunas menos importantes em tabelas */
  .col-hide-mobile { display: none !important; }

  /* Page-header com botão: virar coluna */
  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 10px;
  }

  /* Barra de filtros: empilha em coluna */
  .filter-bar {
    flex-direction: column !important;
    gap: 8px !important;
  }
  .filter-bar .form-group,
  .filter-bar .fg {
    width: 100% !important;
    min-width: 0 !important;
  }
  .filter-bar input,
  .filter-bar select {
    width: 100% !important;
    box-sizing: border-box;
  }

  /* Tabelas — célula menor */
  table td, table th {
    padding: 8px 8px;
    font-size: 12px;
  }

  /* Ações em tabelas: empilha botões */
  td .btn + .btn {
    margin-top: 4px;
    display: block;
    width: 100%;
  }

  /* Evita overflow no conteúdo principal */
  .main-content {
    overflow-x: hidden;
  }
  .main-content > * {
    max-width: 100%;
  }
}

/* ============================
   ABAS (TAB MENU)
   ============================ */

.tab-nav {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
  overflow-x: auto;
}

.tab-btn {
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-light);
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
  display: flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
}

.tab-btn:hover {
  color: var(--accent);
}

.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* Ação destaque (quitar / excluir) */
.btn-quitar {
  background: #22c55e;
  color: #fff;
  border: none;
}
.btn-quitar:hover { background: #16a34a; }
