:root {
  --primary: #0F6E56;
  --primary-dark: #085041;
  --primary-light: #E1F5EE;
  --accent: #378ADD;
  --bg: #F7F8FA;
  --surface: #FFFFFF;
  --border: #E3E5E8;
  --text-primary: #1C1E1F;
  --text-secondary: #6B6F73;
  --text-muted: #9AA0A6;
  --success-bg: #EAF3DE;
  --success-fg: #3B6D11;
  --warning-bg: #FAEEDA;
  --warning-fg: #854F0B;
  --danger-bg: #FCEBEB;
  --danger-fg: #A32D2D;
  --shadow: 0 1px 2px rgba(16, 24, 32, .05), 0 1px 1px rgba(16, 24, 32, .03);
  --shadow-lg: 0 12px 28px rgba(16, 24, 32, .16);
}

[data-theme="dark"] {
  --primary: #1CB88F;
  --primary-dark: #12856A;
  --primary-light: rgba(28, 184, 143, .16);
  --accent: #5CA6EA;
  --bg: #0F1216;
  --surface: #171B20;
  --border: #262C33;
  --text-primary: #EDEFF1;
  --text-secondary: #A7ADB4;
  --text-muted: #6E747B;
  --success-bg: rgba(59, 109, 17, .28);
  --success-fg: #A2D876;
  --warning-bg: rgba(133, 79, 11, .3);
  --warning-fg: #E9BB6E;
  --danger-bg: rgba(163, 45, 45, .3);
  --danger-fg: #F2A0A0;
  --shadow: none;
  --shadow-lg: 0 12px 28px rgba(0, 0, 0, .5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  transition: background-color .2s ease, color .2s ease;
}

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

/* ---------- Layout autenticado ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  transition: background-color .2s ease, border-color .2s ease;
}

.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; padding: 0 6px; }
.brand-mark {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}
.brand-name { font-size: 14px; font-weight: 700; line-height: 1.3; }
.escritorio { font-size: 11px; color: var(--text-muted); }

.sidebar nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar nav a,
.sidebar-footer a {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  transition: background-color .15s, color .15s;
}
.sidebar nav a:hover,
.sidebar-footer a:hover { background: var(--bg); color: var(--text-primary); }
.sidebar nav a.active,
.sidebar-footer a.active { background: var(--primary-light); color: var(--primary-dark); }
[data-theme="dark"] .sidebar nav a.active,
[data-theme="dark"] .sidebar-footer a.active { color: #fff; }

.nav-icon { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border); }

/* ---------- Topbar ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 32px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky; top: 0; z-index: 5;
  transition: background-color .2s ease, border-color .2s ease;
}
.topbar-title { font-size: 18px; font-weight: 700; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: 18px; }

.theme-switch input { display: none; }
.theme-switch-track {
  width: 44px; height: 24px; border-radius: 12px;
  background: var(--border);
  display: flex; align-items: center; padding: 2px;
  cursor: pointer;
  transition: background-color .2s;
}
.theme-switch-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.25);
  transition: transform .2s;
}
.theme-switch input:checked + .theme-switch-track { background: var(--primary); }
.theme-switch input:checked + .theme-switch-track .theme-switch-thumb { transform: translateX(20px); }

.user-menu { position: relative; }
.user-menu summary { list-style: none; cursor: pointer; }
.user-menu summary::-webkit-details-marker { display: none; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.user-menu-dropdown {
  position: absolute; right: 0; top: 46px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  min-width: 200px;
  box-shadow: var(--shadow-lg);
}
.user-menu-nome { font-weight: 700; font-size: 14px; }
.user-menu-email { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; }
.user-menu-dropdown a { display: block; padding: 8px 10px; border-radius: 8px; font-size: 13px; color: var(--text-secondary); font-weight: 600; }
.user-menu-dropdown a:hover { background: var(--bg); color: var(--text-primary); }

.content { padding: 28px 32px 48px; max-width: 1100px; }

h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
h3 { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 16px 0 6px; }

.header-row { display: flex; align-items: center; justify-content: flex-end; margin-bottom: 20px; gap: 12px; }

/* ---------- Cards / grid ---------- */
.stats-row { display: flex; gap: 16px; margin-bottom: 28px; }
.stat-card {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  box-shadow: var(--shadow);
  transition: background-color .2s ease, border-color .2s ease;
}
.stat-card.stat-alerta { border-color: var(--warning-fg); background: var(--warning-bg); }
.stat-value { font-size: 28px; font-weight: 700; color: var(--primary-dark); }
[data-theme="dark"] .stat-value { color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

.panel-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  transition: background-color .2s ease, border-color .2s ease;
}
.panel-box-form { max-width: 480px; }

/* ---------- Tabelas ---------- */
.tabela { width: 100%; border-collapse: collapse; font-size: 14px; }
.tabela th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
}
.tabela td { padding: 11px 10px; border-bottom: 1px solid var(--border); }
.tabela tbody tr[onclick] { cursor: pointer; }
.tabela tbody tr[onclick]:hover { background: var(--bg); }

.vazio { color: var(--text-muted); font-size: 14px; }

/* ---------- Badges ---------- */
.badge { padding: 3px 10px; border-radius: 8px; font-size: 12px; font-weight: 600; }
.badge-pendente { background: var(--warning-bg); color: var(--warning-fg); }
.badge-processado { background: var(--success-bg); color: var(--success-fg); }
.badge-erro { background: var(--danger-bg); color: var(--danger-fg); }
.badge-concluida { background: var(--success-bg); color: var(--success-fg); }

/* ---------- Formulários ---------- */
form { display: flex; flex-direction: column; }
label { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin: 12px 0 4px; }
input, select {
  height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 12px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text-primary);
}
input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.hint { font-size: 12px; color: var(--text-muted); margin-top: 12px; }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-full { width: 100%; margin-top: 20px; }
.btn-link { background: none; border: none; color: var(--primary); font-size: 13px; font-weight: 600; cursor: pointer; padding: 0; }
.icon-inline { width: 15px; height: 15px; }

.filtros { display: flex; gap: 10px; margin-bottom: 16px; }
.filtros select { width: 220px; }

/* ---------- Documento ---------- */
.doc-preview { width: 100%; border-radius: 10px; border: 1px solid var(--border); }
.ocr-texto {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
  white-space: pre-wrap;
  max-height: 220px;
  overflow-y: auto;
  color: var(--text-secondary);
}
.aviso-erro { color: var(--danger-fg); font-size: 13px; margin-top: 10px; }

/* ---------- Configurações ---------- */
.config-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.config-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 8px;
}
.config-card-icon {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--primary-light); color: var(--primary-dark);
  display: flex; align-items: center; justify-content: center;
}
[data-theme="dark"] .config-card-icon { color: var(--primary); }
.config-card h3 { margin: 0; font-size: 15px; color: var(--text-primary); }
.config-card p { margin: 0; font-size: 13px; color: var(--text-secondary); }
.config-card a.btn-link { margin-top: 4px; }

.tema-opcoes { display: flex; gap: 10px; margin-top: 6px; }
.tema-opcoes label {
  flex: 1; margin: 0;
  border: 1px solid var(--border); border-radius: 10px;
  padding: 10px; text-align: center; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text-secondary);
}
.tema-opcoes input { display: none; }
.tema-opcoes input:checked + span { color: var(--primary-dark); }
[data-theme="dark"] .tema-opcoes input:checked + span { color: var(--primary); }

/* ---------- Login ---------- */
body.publico { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.auth-wrap { width: 100%; max-width: 380px; padding: 24px; }
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.auth-logo {
  width: 56px; height: 56px;
  border-radius: 16px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.auth-sub { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.auth-card form { text-align: left; }

/* ---------- Flash messages ---------- */
.flash-list { margin-bottom: 16px; }
.flash { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 8px; }
.flash-sucesso { background: var(--success-bg); color: var(--success-fg); }
.flash-erro { background: var(--danger-bg); color: var(--danger-fg); }

/* ---------- Autorização de computador ---------- */
.codigo-maquina {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin: 14px 0 18px; padding: 12px 14px;
  border: 1px dashed var(--border); border-radius: 10px; background: var(--bg);
  font-family: Consolas, "Courier New", monospace; font-size: 15px; font-weight: 700; letter-spacing: .5px;
}
.auth-card textarea { width: 100%; resize: vertical; font-family: Consolas, "Courier New", monospace; font-size: 12px; }
.acoes { display: flex; gap: 14px; justify-content: flex-end; }
.acoes form { margin: 0; }
.btn-perigo { color: var(--danger-fg); }
