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

:root {
  --primary: #1a56db;
  --primary-dark: #1040aa;
  --success: #0e9f6e;
  --danger: #f05252;
  --warning: #ff8800;
  --bg: #f3f4f6;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ─── Layout ────────────────────────────────────────── */
.sidebar {
  position: fixed; top: 0; left: 0; height: 100vh;
  width: 220px; background: #1e2433; color: #c9d1e0;
  display: flex; flex-direction: column; z-index: 100;
}

.sidebar-logo {
  padding: 28px 12px 12px;
  border-bottom: 1px solid #2e3648;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  line-height: 0;
}
.sidebar-logo > div { line-height: 1.2; margin-top: 6px; }
.sidebar-logo h2 { color: #fff; font-size: 16px; font-weight: 700; }
.sidebar-logo small { color: #7c8aa0; font-size: 11px; }

.sidebar nav { flex: 1; padding: 12px 0; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 18px; color: #c9d1e0; font-size: 13.5px;
  transition: background .15s, color .15s;
}
.sidebar nav a:hover, .sidebar nav a.ativo {
  background: #2e3648; color: #fff; text-decoration: none;
}
.sidebar nav a svg { width: 17px; height: 17px; flex-shrink: 0; }
.sidebar-footer { padding: 14px 18px; font-size: 11px; color: #7c8aa0; border-top: 1px solid #2e3648; }

.sidebar-user {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; font-weight: 600; color: #cbd5e1;
  margin-bottom: 8px; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user svg { flex-shrink: 0; opacity: .7; }

.btn-logout {
  display: flex; align-items: center; gap: 6px;
  width: 100%; padding: 7px 10px;
  background: rgba(220,38,38,.12); color: #fca5a5;
  border: 1px solid rgba(220,38,38,.25); border-radius: 6px;
  font-size: 12px; font-weight: 600; cursor: pointer;
  transition: background .2s;
}
.btn-logout:hover { background: rgba(220,38,38,.25); color: #fff; }

.main { margin-left: 220px; min-height: 100vh; padding: 28px 32px; transition: margin-left .25s ease; }

/* ─── Sidebar colapsada ─────────────────────────────── */
body.sidebar-collapsed .sidebar { width: 0; overflow: hidden; }
body.sidebar-collapsed .main    { margin-left: 0; }
body.sidebar-collapsed #btn-toggle-sidebar { left: 8px; background: #1e2433; }

#btn-toggle-sidebar {
  position: fixed; top: 16px; left: 184px;
  z-index: 200; background: transparent; color: #c9d1e0;
  border: none; border-radius: 6px; width: 28px; height: 28px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; transition: left .25s ease, background .15s;
}
#btn-toggle-sidebar:hover { background: rgba(255,255,255,.12); color: #fff; }
@media print { #btn-toggle-sidebar { display: none !important; } }

/* ─── Cards de resumo ───────────────────────────────── */
.cards-resumo { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 16px; margin-bottom: 24px; }
.card-resumo {
  background: var(--surface); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow);
  border-left: 4px solid var(--primary);
}
.card-resumo.success { border-left-color: var(--success); }
.card-resumo.danger  { border-left-color: var(--danger); }
.card-resumo.warning { border-left-color: var(--warning); }
.card-resumo label { font-size: 11.5px; text-transform: uppercase; letter-spacing: .5px; color: var(--text-muted); }
.card-resumo .valor { font-size: 26px; font-weight: 700; margin: 4px 0 0; }

/* ─── Painéis ───────────────────────────────────────── */
.painel {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); margin-bottom: 20px;
}
.painel-header {
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px;
}
.painel-header h3 { font-size: 14px; font-weight: 600; }
.painel-body { padding: 16px 20px; }

/* ─── Formulários de filtro ─────────────────────────── */
.filtros { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; }
.filtros .campo { display: flex; flex-direction: column; gap: 4px; }
.filtros label { font-size: 11.5px; color: var(--text-muted); }
.filtros input, .filtros select {
  height: 34px; border: 1px solid var(--border); border-radius: 6px;
  padding: 0 10px; font-size: 13px; background: var(--surface);
  min-width: 140px; outline: none;
}
.filtros input:focus, .filtros select:focus { border-color: var(--primary); }

/* ─── Tabelas ───────────────────────────────────────── */
.tabela-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left; padding: 9px 12px;
  background: #f9fafb; border-bottom: 1px solid var(--border);
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #fafafa; }
tbody td { padding: 9px 12px; vertical-align: middle; }

/* ─── Badges ────────────────────────────────────────── */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px;
}
.badge-ativo     { background: #d1fae5; color: #065f46; }
.badge-cancelado { background: #fee2e2; color: #991b1b; }
.badge-substituido { background: #fef3c7; color: #92400e; }
.badge-ok        { background: #d1fae5; color: #065f46; }
.badge-erro      { background: #fee2e2; color: #991b1b; }
.badge-sem_documento { background: #e5e7eb; color: #374151; }

/* ─── Botões ────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; transition: opacity .15s, background .15s;
}
.btn:hover { opacity: .88; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-success  { background: var(--success); color: #fff; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-ghost    { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-sm       { padding: 4px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ─── Paginação ─────────────────────────────────────── */
.paginacao { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.paginacao span { font-size: 12px; color: var(--text-muted); }

/* ─── Modal ─────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-md); width: 100%; max-width: 580px; max-height: 90vh;
  display: flex; flex-direction: column;
}
.modal-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 15px; font-weight: 600; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* ─── Formulários gerais ────────────────────────────── */
.form-grupo { margin-bottom: 16px; }
.form-grupo label { display: block; font-size: 12.5px; font-weight: 500; margin-bottom: 5px; }
.form-grupo input, .form-grupo select, .form-grupo textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 6px;
  padding: 8px 12px; font-size: 13px; background: var(--surface); outline: none;
}
.form-grupo input:focus, .form-grupo select:focus { border-color: var(--primary); }
.form-grupo small { color: var(--text-muted); font-size: 11.5px; }

/* ─── Alertas ───────────────────────────────────────── */
.alerta {
  padding: 10px 14px; border-radius: 6px; font-size: 13px; margin-bottom: 14px;
}
.alerta-erro    { background: #fee2e2; color: #991b1b; }
.alerta-sucesso { background: #d1fae5; color: #065f46; }
.alerta-info    { background: #dbeafe; color: #1e40af; }

/* ─── Loading ───────────────────────────────────────── */
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid #e5e7eb; border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .6; transform: scale(1.3); }
}

.estado-vazio { text-align: center; padding: 40px 20px; color: var(--text-muted); }
.estado-vazio svg { width: 40px; height: 40px; margin-bottom: 10px; opacity: .4; }

/* ─── XML viewer ────────────────────────────────────── */
.xml-viewer {
  background: #1e2433; color: #abb2bf; border-radius: 6px;
  padding: 14px; font-family: 'Consolas', monospace; font-size: 12px;
  max-height: 400px; overflow: auto; white-space: pre; tab-size: 2;
}

/* ─── Tutorial / primeiros passos ──────────────────────── */
.tutorial-passo {
  display: flex; align-items: flex-start; gap: 14px;
  padding: 18px 20px; border-right: 1px solid #e0e7ff;
  text-decoration: none; color: var(--text);
  transition: background .15s;
}
.tutorial-passo:hover { background: #f5f3ff; text-decoration: none; }
.tutorial-num {
  flex-shrink: 0; width: 32px; height: 32px;
  border-radius: 50%; background: #ede9fe; color: #7c3aed;
  font-size: 14px; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.tutorial-titulo { font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.tutorial-desc   { font-size: 12px; color: var(--text-muted); line-height: 1.4; }

/* ─── Efeito chamativo no link Comprar Créditos ─────────── */
@keyframes sidebar-pulse {
  0%, 100% { background: transparent; color: #c9d1e0; }
  50%       { background: rgba(204,0,0,.3); color: #fff; box-shadow: inset 3px 0 0 #cc0000; }
}
.sidebar-link-destaque {
  animation: sidebar-pulse 1.6s ease-in-out infinite;
}

/* ─── Responsivo ────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main { margin-left: 0; padding: 16px; }
}
