:root {
  /* Tema CLARO — "AI Automation" (editorial/Swiss), acento azul #2563EB. */
  --bg: #f3f3f1;
  --card: #ffffff;
  --surface: #ebebe8;
  --hover: #f1f1ee;
  --chip: #e5e7eb;
  --code-bg: #f5f5f3;
  --line: rgba(0, 0, 0, 0.12);
  --text: #0a0a0a;
  --muted: #5b616e;
  --subtle: #9ca3af;
  --accent: #2563eb;
  --accent-2: #3b82f6;
  --ok: #16a34a;
  --err: #dc2626;
  --warn: #b45309;
  --warn-text: #92660a;
  --warn-bg: #fef3c7;
  --radius: 0.75rem;
  --radius-lg: 1.25rem;
}

.dark {
  /* Tema ESCURO — "Luminous" (glow/glass). */
  --bg: #050505;
  --card: #0a0a0a;
  --surface: #171717;
  --hover: #161a22;
  --chip: var(--chip);
  --code-bg: #0c0e12;
  --line: rgba(255, 255, 255, 0.1);
  --text: #f4f4f5;
  --muted: #a3a3a3;
  --subtle: #737373;
  --accent: #2563eb;
  --accent-2: #60a5fa;
  --ok: #22c55e;
  --err: #ef4444;
  --warn: #f0c674;
  --warn-text: #f0c674;
  --warn-bg: #4a3b13;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Inter", system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.45;
}

/* Headings: Inter (semibold, tight) no claro; Bricolage Grotesque no escuro. */
h1, h2 { font-family: "Inter", system-ui, sans-serif; font-weight: 600; letter-spacing: -0.02em; }
.dark h1, .dark h2 {
  font-family: "Bricolage Grotesque", "Inter", system-ui, sans-serif;
  font-weight: 400;
  letter-spacing: -0.01em;
}

header {
  padding: 24px 32px 8px;
}
header h1 { margin: 0; font-size: 22px; }
header p { margin: 4px 0 0; color: var(--muted); }

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 18px; }
.brand-logo {
  height: 46px;
  width: auto;
  padding-right: 18px;
  border-right: 1px solid var(--line);
}

/* Header metric cards (aligned right, even when they wrap to their own line) */
.header-stats { display: flex; gap: 12px; flex-wrap: wrap; margin-left: auto; justify-content: flex-end; }
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
  min-width: 132px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.clickable-card { cursor: pointer; transition: border-color 0.15s, background 0.15s; }
.clickable-card:hover { border-color: var(--accent); background: var(--hover); }
.stat-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--subtle);
}
.stat-value { font-size: 20px; font-weight: 600; color: var(--text); }
.cost-row { display: flex; align-items: center; gap: 10px; }
.donut {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--line);
  flex: none;
  -webkit-mask: radial-gradient(farthest-side, transparent 58%, #000 59%);
  mask: radial-gradient(farthest-side, transparent 58%, #000 59%);
}

.tabs { display: flex; gap: 6px; margin-top: 16px; }
.tab {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 16px;
  font-size: 14px;
}
.tab.active { background: var(--card); color: var(--text); border-color: var(--accent); }

.nav-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.current-user { font-size: 13px; color: var(--muted); white-space: nowrap; }
.current-user strong { color: var(--text); font-weight: 600; }

.theme-toggle {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 15px;
  line-height: 1;
}
.theme-toggle:hover { background: var(--hover); }

/* ---- login page ---- */
.login-body { min-height: 100vh; display: flex; }
.login-main { margin: auto; padding: 24px; width: 100%; max-width: 380px; }
.login-card { display: flex; flex-direction: column; gap: 14px; }
.login-logo { height: 42px; width: auto; align-self: flex-start; }
.login-card h1 { margin: 4px 0 0; font-size: 20px; }
.login-card p { margin: 0; }
.login-card label { color: var(--muted); }
.login-card input[type="text"], .login-card input[type="password"] { width: 100%; }
.login-card button { margin-top: 6px; }

.view { display: none; }
.view.active { display: block; }

main {
  margin: 0;
  padding: 16px 32px 48px;
  /* block (not grid) so children are capped at the container width — the wide
     resumo table then scrolls inside .table-wrap instead of stretching the page. */
}
/* Upload form stays centered/readable; consult tables use the full screen width
   (limited to the screen border) and scroll horizontally inside .table-wrap. */
#view-process {
  width: 100%;
  max-width: 980px;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 20px;
}
.card h2 { margin: 0 0 14px; font-size: 16px; }

.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row.between { justify-content: space-between; align-items: center; }

label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
select {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 220px;
}

.drop {
  margin: 16px 0;
  border: 1.5px dashed var(--line);
  border-radius: 10px;
  padding: 22px;
  text-align: center;
  cursor: pointer;
  color: var(--muted);
}
.drop input { display: block; margin: 0 auto 8px; }

button {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 9px 16px;
  font-size: 14px;
  cursor: pointer;
}
button:disabled { opacity: 0.6; cursor: default; }
button.refresh { background: var(--chip); color: var(--text); }
button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
button.ghost:hover { background: var(--hover); }

.exports { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; font-size: 13px; }
.exports a { color: var(--accent); text-decoration: none; }
.exports .sep { color: var(--line); }

/* ---- activity widget (grouped processing + per-file index) ---- */
.activity {
  margin-top: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: var(--surface);
}
.activity-head,
.item-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  background: transparent;
  color: var(--text);
  border: 0;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
}
.activity-head { padding: 12px 14px; }
.activity-head:hover,
.item-head:hover { background: var(--hover); }
.chevron { color: var(--muted); width: 12px; flex: none; }
.activity-title { flex: 1; }
.activity.done .spinner,
.activity.paused .spinner { display: none; }

/* pause / stop controls for a processing run */
.proc-controls { display: flex; align-items: center; gap: 10px; margin-top: 12px; flex-wrap: wrap; }
.proc-controls[hidden] { display: none; } /* `display:flex` would otherwise beat the hidden attr */
.proc-controls .proc-note { font-size: 13px; }

.spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  flex: none;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.activity-body { border-top: 1px solid var(--line); }
.activity-item { border-bottom: 1px solid var(--line); }
.activity-item:last-child { border-bottom: 0; }

.item-head { padding: 9px 14px 9px 26px; font-size: 13px; }
.item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-status { color: var(--muted); font-size: 12px; white-space: nowrap; }

.status-dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: var(--muted); }
.status-dot.pending { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.status-dot.ok { background: var(--ok); }
.status-dot.warn { background: var(--warn); }
.status-dot.error { background: var(--err); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.item-detail { padding: 4px 14px 14px 26px; }
.detail-meta { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }

#results { margin-top: 16px; }
.result {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  background: var(--surface);
}
.result.ok { border-left: 3px solid var(--ok); }
.result.error { border-left: 3px solid var(--err); }
.result.warn { border-left: 3px solid var(--warn); }
.badge.warn { background: var(--warn-bg); color: var(--warn-text); }
.warn-msg { margin: 8px 0 4px; color: var(--warn-text); font-size: 13px; }
button.reprocess {
  margin-left: auto;
  background: #f0c674;
  color: #1a1300;
  padding: 5px 12px;
  font-size: 13px;
}
button.reprocess:hover { background: #f5d488; }
.result-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.badge { font-size: 11px; background: var(--chip); padding: 2px 8px; border-radius: 999px; color: var(--muted); }
.badge.dup { background: var(--warn-bg); color: var(--warn-text); }
.rec { color: var(--muted); font-size: 12px; }
.err { color: var(--err); }

table.fields, table.records {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.fields td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.fields td:first-child {
  color: var(--muted);
  width: 1%;              /* shrink the key column to its content … */
  white-space: nowrap;    /* … so values sit right next to the keys, not pushed right */
  padding-right: 24px;
}

.table-wrap {
  overflow: auto;          /* horizontal + vertical scroll */
  max-height: 65vh;
  border: 1px solid var(--line);
  border-radius: 8px;
}
table.records th, table.records td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
  text-align: left;
}
table.records thead th {
  color: var(--muted);
  font-weight: 600;
  position: sticky;        /* keep the header visible while scrolling */
  background: var(--card);
  z-index: 1;
}
table.records thead tr:first-child th { top: 0; }
table.records thead tr.filter-row th { top: 30px; padding: 4px 6px; font-weight: 400; }
.col-filter {
  width: 100%;
  min-width: 90px;
  box-sizing: border-box;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 4px 6px;
  font-size: 12px;
}
.col-filter:focus { outline: none; border-color: var(--accent); }
table.records tr.clickable { cursor: pointer; }
table.records tbody tr.clickable:hover td { background: var(--hover); }

.hint { margin: 0 0 8px; font-size: 12px; }
input[type="text"], input[type="number"], input[type="password"] {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
}
input[type="number"] { width: 90px; }
textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
  resize: vertical;
}
.ok-text { color: var(--ok); font-size: 13px; }

.detail {
  margin-top: 16px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 14px;
  background: var(--surface);
}
.detail-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
button.link {
  background: none;
  border: 0;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  padding: 0;
}
button.link.danger-link { color: var(--err); margin-right: 14px; }

a.link, .dl-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
}
a.link { margin-right: 14px; }
a.link:hover, .dl-link:hover { text-decoration: underline; }

button.danger {
  background: transparent;
  color: var(--err);
  border: 1px solid var(--err);
}
button.danger:hover { background: var(--err); color: #fff; }

.warnings { margin: 10px 0 0; padding-left: 18px; color: var(--warn-text); font-size: 12px; }
details { margin-top: 10px; }
summary { cursor: pointer; color: var(--muted); font-size: 13px; }
pre { background: var(--code-bg); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 12px; }
.muted { color: var(--muted); }

/* ---- admin ---- */
.subtabs { display: flex; gap: 6px; flex-wrap: wrap; }
.subtab {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
}
.subtab.active { background: var(--card); color: var(--text); border-color: var(--accent); }
.subtab:hover { background: var(--hover); }

.admin-form h3 { margin: 0 0 10px; font-size: 14px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.form-grid label { font-size: 13px; }
.form-grid input, .form-grid select { width: 100%; min-width: 0; }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text); }
label.check input { width: auto; }

.admin-msg { margin: 10px 0; padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.admin-msg.ok { border: 1px solid var(--ok); color: var(--ok); }
.admin-msg.error { border: 1px solid var(--err); color: var(--err); }

.ldap-test { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 14px; }
.ldap-test h3 { margin: 0 0 6px; font-size: 14px; }
.ldap-checks { list-style: none; padding-left: 0; margin: 10px 0 0; font-size: 13px; }
.ldap-checks li { padding: 3px 0; }

.badge.role-admin { background: var(--accent); color: #fff; }
.admin-actions { white-space: nowrap; }
.admin-actions .link { margin-right: 10px; }
td.ua { max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
