:root {
  --bg: #F5F4F1;
  --surface: #FFFFFF;
  --sidebar: #171A21;
  --sidebar-hover: #23272F;
  --accent: #E85D2C;
  --accent-dark: #C94A1E;
  --text: #1C1E22;
  --text-muted: #6B7280;
  --border: #E5E3DE;
  --success: #1F9254;
  --success-bg: #E9F6EF;
  --danger: #D64545;
  --danger-bg: #FBEAEA;
  --warning: #B8860B;
  --warning-bg: #FBF3DE;
  --info: #3B4EC2;
  --info-bg: #EEF1FB;
  --radius: 12px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
  /* trava qualquer elemento largo demais que escape do layout (ex.: uma
     tabela ou texto sem quebra) de empurrar a página inteira pros lados —
     o conteúdo específico ainda rola por dentro (.table-wrap etc.) */
  overflow-x: hidden;
}

img, svg { max-width: 100%; }

h1, h2, h3, h4 { font-family: 'Sora', system-ui, sans-serif; margin: 0 0 8px; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dark); }
p { margin: 0 0 8px; }

/* ---------- Layout ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 40;
  transition: transform .2s ease;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 22px 22px 18px; }
.sidebar-brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); display: flex; align-items: center; justify-content: center; font-family: 'Sora', sans-serif; font-weight: 800; font-size: 15px; flex-shrink: 0; }
.sidebar-brand .name { font-family: 'Sora', sans-serif; font-weight: 700; font-size: 17px; line-height: 1.1; }
.sidebar-brand .tag { font-size: 10.5px; color: var(--accent); font-weight: 700; letter-spacing: .06em; }

.sidebar nav { flex: 1; padding: 6px 14px; display: flex; flex-direction: column; gap: 2px; }
.navlink { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 8px; font-size: 14px; font-weight: 500; color: #A9ACB4; }
.navlink svg { flex-shrink: 0; }
.navlink:hover { color: #fff; }
.navlink.active { background: var(--sidebar-hover); color: #fff; font-weight: 600; }
.nav-sep { height: 1px; background: #2A2E37; margin: 10px 18px; }

.sidebar-footer { padding: 16px 20px; border-top: 1px solid #2A2E37; display: flex; align-items: center; gap: 10px; }
.avatar-circle { width: 34px; height: 34px; border-radius: 50%; background: #3A3F4B; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; color: #fff; flex-shrink: 0; }
.sidebar-footer .who { min-width: 0; }
.sidebar-footer .who .n { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .who .p { font-size: 12px; color: #8C8F98; }
.sidebar-footer form { margin-left: auto; }
.sidebar-footer button.logout { background: none; border: none; color: #8C8F98; cursor: pointer; }
.sidebar-footer button.logout:hover { color: #fff; }

.main { flex: 1; margin-left: 240px; display: flex; flex-direction: column; min-height: 100vh; min-width: 0; }

.topbar { height: 64px; flex-shrink: 0; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 28px; background: var(--surface); gap: 16px; }
.topbar h2 { font-size: 19px; font-weight: 700; }
.topbar .sub { font-size: 12px; color: var(--text-muted); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.menu-toggle { display: none; background: none; border: none; cursor: pointer; padding: 4px; }

.content { padding: 24px 28px; flex: 1; }

/* ---------- Cards / KPIs ---------- */
.kpi-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.kpi-card { flex: 1 1 200px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.kpi-card .lbl { font-size: 12px; color: var(--text-muted); font-weight: 600; margin-bottom: 8px; }
.kpi-card .val { font-family: 'Sora', sans-serif; font-size: 22px; font-weight: 700; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.card h3 { font-size: 14.5px; font-weight: 700; }

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge-success { background: var(--success-bg); color: var(--success); }
.badge-warning { background: var(--warning-bg); color: var(--warning); }
.badge-danger  { background: var(--danger-bg); color: var(--danger); }
.badge-info    { background: var(--info-bg); color: var(--info); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 16px; border-radius: 8px; font-size: 13.5px; font-weight: 700; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; text-decoration: none; }
.btn:hover { border-color: #cfcbc2; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { height: 32px; padding: 0 12px; font-size: 12.5px; }
.btn-icon { width: 32px; height: 32px; padding: 0; justify-content: center; }
.btn-block { width: 100%; justify-content: center; }

/* ---------- Forms ---------- */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-group label { font-size: 12.5px; font-weight: 600; }
.form-row { display: grid; gap: 16px; }
.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
input, select, textarea {
  height: 40px; border: 1px solid var(--border); border-radius: 8px; padding: 0 12px;
  font-size: 13.5px; font-family: inherit; background: var(--surface); color: var(--text); width: 100%;
}
textarea { height: auto; padding: 10px 12px; resize: vertical; min-height: 90px; }
input:focus, select:focus, textarea:focus, button:focus, a:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--text-muted); font-weight: 500; }
.checkbox-row input { width: 16px; height: 16px; }
.search-box { position: relative; }
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); pointer-events: none; }
.search-box input { padding-left: 34px; }

/* ---------- Tables ----------
   .table-wrap por si só já rola na horizontal (-webkit-overflow-scrolling
   pra inércia suave no iOS) — nunca depende de também ter .table-scroll
   pra não espremer tabela larga em tela pequena; .table-scroll continua
   funcionando como um wrapper extra opcional, sem duplicar o efeito. */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { border-collapse: collapse; width: 100%; min-width: 560px; }
thead { background: var(--bg); }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .03em; color: var(--text-muted); text-align: left; font-weight: 600; padding: 12px 14px; white-space: nowrap; }
td { font-size: 13.5px; padding: 12px 14px; border-top: 1px solid var(--border); vertical-align: middle; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-footer { padding: 12px 16px; border-top: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }

/* ---------- Alerts / Flash ---------- */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 14px; font-size: 13.5px; font-weight: 500; }
.alert-success { background: var(--success-bg); color: var(--success); }
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-info { background: var(--info-bg); color: var(--info); }

/* ---------- Auth screens ---------- */
.auth-shell { min-height: 100vh; display: flex; }
.auth-side { width: 45%; background: var(--sidebar); color: #fff; padding: 56px 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side h1 { font-size: 32px; line-height: 1.28; }
.auth-side p { color: #A9ACB4; font-size: 15px; }
.auth-form-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 48px 24px; }
.auth-form { width: 100%; max-width: 380px; }

/* ---------- Utility ---------- */
.flex { display: flex; }
.gap-8 { gap: 8px; } .gap-10 { gap: 10px; } .gap-16 { gap: 16px; }
.mb-0 { margin-bottom: 0; }
.muted { color: var(--text-muted); }
.text-right { text-align: right; }
.progress { height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }

/* ---------- Responsive ----------
   Três faixas: tablet/sidebar (900px), telefone (640px) e telefone
   pequeno (400px) — cada uma só ajusta o que realmente precisa mudar
   naquele tamanho, em vez de um salto único e brusco de desktop pra
   celular. */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); width: 260px; max-width: 82vw; }
  .sidebar.open { transform: translateX(0); box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .main { margin-left: 0; }
  .menu-toggle { display: flex; }
  .topbar { padding: 0 16px; }
  .content { padding: 16px; }
  .kpi-row { flex-direction: column; }
  .form-row.cols-2, .form-row.cols-3, .form-row.cols-4 { grid-template-columns: 1fr; }
  .auth-side { display: none; }
  .auth-form-wrap { padding: 32px 20px; }
}

@media (max-width: 640px) {
  .content { padding: 12px; }
  .card { padding: 14px 16px; }
  .kpi-card { padding: 13px 14px; }
  .kpi-card .val { font-size: 19px; }

  /* topo: título/subtítulo e as ações (botões, filtros) empilham em vez de
     espremer lado a lado numa faixa de 64px */
  .topbar { height: auto; min-height: 60px; flex-wrap: wrap; padding: 10px 14px; gap: 8px; }
  .topbar h2 { font-size: 16.5px; }
  .topbar-actions { width: 100%; flex-wrap: wrap; gap: 8px; }
  .topbar-actions .btn, .topbar-actions form { flex: 1 1 auto; }

  /* qualquer linha de botões/ações vira empilhável em vez de cortar */
  .flex { flex-wrap: wrap; }
  .flex.text-right, td.text-right .flex { justify-content: flex-end; }

  .btn { font-size: 13px; padding: 0 13px; }
  th, td { padding: 10px 11px; font-size: 12.5px; }
  table { min-width: 480px; }

  .form-row { gap: 12px; }
  .auth-form-wrap { padding: 24px 16px; }
  .auth-form { max-width: 100%; }

  /* nenhum bloco flex fixo (cards de estatística, colunas lado a lado)
     força a página a ficar mais larga que a tela — em telefone, cada um
     vira 100% de largura e empilha */
  .flex > [style*="min-width"] { min-width: 0 !important; flex-basis: 100% !important; }
}

@media (max-width: 400px) {
  html { font-size: 13.5px; }
  .sidebar-brand .name { font-size: 15px; }
  .kpi-card .val { font-size: 17px; }
  .card h3 { font-size: 13.5px; }
  .btn { padding: 0 11px; }
}
