:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --line: #dde1e7;
  --fg: #1b1f24;
  --fg-muted: #5b6470;
  --accent: #4f46e5;
  --accent-soft: #eceafd;
  --ok: #157f3c;
  --ok-soft: #e4f5ea;
  --warn: #8a5a00;
  --warn-soft: #fdf3dc;
  --danger: #b42318;
  --danger-soft: #fdecea;
  --radius: 8px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #1e222a;
    --line: #2b3039;
    --fg: #e6e8eb;
    --fg-muted: #9aa3ae;
    --accent: #8b85ff;
    --accent-soft: #24223f;
    --ok: #5fd08a;
    --ok-soft: #13291c;
    --warn: #f0c060;
    --warn-soft: #2d2410;
    --danger: #ff8a80;
    --danger-soft: #331a18;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

/* Sem isto, regras como label { display: flex } venceriam o atributo hidden. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

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

header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}

header .brand { font-weight: 650; color: var(--fg); }
header nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
header nav a {
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--fg-muted);
}
header nav a:hover { background: var(--surface-2); text-decoration: none; color: var(--fg); }
header nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

main { max-width: 1200px; margin: 0 auto; padding: 24px; }

h1 { font-size: 20px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 28px 0 12px; }
p.muted, .muted { color: var(--fg-muted); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stat .label { color: var(--fg-muted); font-size: 12px; }
.stat .value { font-size: 22px; font-weight: 650; margin-top: 2px; }

table { width: 100%; border-collapse: collapse; background: var(--surface); }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; font-weight: 600; color: var(--fg-muted); background: var(--surface-2); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
pre {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--fg-muted);
}
.badge.enabled, .badge.generated, .badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.disabled, .badge.generating { background: var(--warn-soft); color: var(--warn); }
.badge.blocked, .badge.revoked, .badge.invalid_output, .badge.provider_error, .badge.limit_exceeded { background: var(--danger-soft); color: var(--danger); }

.flash { padding: 10px 14px; border-radius: var(--radius); margin-bottom: 16px; border: 1px solid; }
.flash.ok { background: var(--ok-soft); color: var(--ok); border-color: var(--ok); }
.flash.error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.warnings { background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn); border-radius: var(--radius); padding: 10px 14px 10px 32px; margin: 0 0 20px; }

form.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  align-items: end;
}
form.grid .wide { grid-column: 1 / -1; }
label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--fg-muted); }
label.check { flex-direction: row; align-items: center; gap: 6px; }
input, select, textarea {
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 9px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { min-height: 140px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }

button, .button {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--fg);
  border-radius: 6px;
  padding: 7px 12px;
  white-space: nowrap;
}
button:hover, .button:hover { background: var(--surface-2); text-decoration: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.small, .button.small { padding: 3px 8px; font-size: 12px; }

.inline { display: inline-flex; gap: 6px; align-items: center; flex-wrap: wrap; margin: 0; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

details > summary { cursor: pointer; color: var(--accent); font-weight: 600; margin-bottom: 8px; }
details[open] > summary { margin-bottom: 12px; }

progress { display: block; width: 100%; min-width: 90px; height: 6px; margin-top: 4px; appearance: none; border: none; border-radius: 3px; background: var(--surface-2); overflow: hidden; }
progress::-webkit-progress-bar { background: var(--surface-2); }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }
progress.full::-webkit-progress-value { background: var(--danger); }
progress.full::-moz-progress-bar { background: var(--danger); }
.gap-top { margin-top: 8px; }
.stat .value.small-value { font-size: 14px; }

.code-box {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 28px;
  letter-spacing: 3px;
  padding: 16px 20px;
  background: var(--surface-2);
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  display: inline-block;
  margin: 8px 0 12px;
}

.login { max-width: 380px; margin: 12vh auto; }
.login form { display: flex; flex-direction: column; gap: 12px; }
