:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --text: #141a26;
  --muted: #667085;
  --border: #e4e7ee;
  --grid: #eef0f4;
  --primary: #1a56db;
  --primary-ink: #ffffff;
  --c1: #3b6fe0;
  --c2: #f08c2e;
  --c3: rgba(220, 53, 69, 0.12);
  --good: #12804a;
  --bad: #c62828;
  --warn: #b45309;
  --good-bg: #e7f6ee;
  --bad-bg: #fdecec;
  --warn-bg: #fff4e0;
  --best-bg: #fff8e1;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 2px 8px rgba(16, 24, 40, .04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131b;
    --surface: #171c26;
    --text: #e8ebf2;
    --muted: #98a2b3;
    --border: #262d3a;
    --grid: #222937;
    --primary: #4c7df0;
    --c1: #5b8af5;
    --c2: #f5a04f;
    --c3: rgba(239, 83, 80, 0.16);
    --good: #4cc38a;
    --bad: #f07070;
    --warn: #f0b058;
    --good-bg: rgba(76, 195, 138, .12);
    --bad-bg: rgba(240, 112, 112, .12);
    --warn-bg: rgba(240, 176, 88, .12);
    --best-bg: rgba(240, 176, 88, .08);
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 26px; line-height: 1.2; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 14px; }
code { background: var(--grid); padding: 1px 6px; border-radius: 6px; font-size: 13px; }

.wrap { max-width: 1200px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.r { text-align: right; }
.text-warn { color: var(--warn); font-weight: 600; }

/* Topo */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.topbar-in { display: flex; align-items: center; justify-content: space-between; height: 60px; gap: 16px; }
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); font-size: 16px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--primary); color: var(--primary-ink); font-weight: 700;
}
.brand-lg { font-size: 20px; margin-bottom: 8px; }
.nav { display: flex; gap: 18px; flex-wrap: wrap; }
.nav a { color: var(--muted); font-weight: 500; font-size: 14px; }
.nav a:hover { color: var(--text); text-decoration: none; }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head p { margin: 0; }
.back { display: inline-block; font-size: 13px; margin-bottom: 6px; }

/* Seletor de mês */
.month-picker { display: flex; align-items: center; gap: 8px; }
select, input[type=text], input[type=email], input[type=password], input:not([type]) {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; min-width: 0;
}
select:focus, input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.summary {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 20px; margin: 0 0 16px; box-shadow: var(--shadow);
}

/* KPIs */
.kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi-alert { border-color: var(--bad); background: var(--bad-bg); }
.kpi-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi-value { font-size: 24px; font-weight: 700; margin: 4px 0 6px; font-variant-numeric: tabular-nums; letter-spacing: -.01em; }
.kpi-foot { font-size: 12px; color: var(--muted); display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.delta { font-weight: 600; padding: 1px 6px; border-radius: 6px; white-space: nowrap; }
.delta-good { color: var(--good); background: var(--good-bg); }
.delta-bad { color: var(--bad); background: var(--bad-bg); }
.delta-flat { color: var(--muted); background: var(--grid); }

/* Cartões */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; box-shadow: var(--shadow); min-width: 0; }
.card.narrow { max-width: 460px; }
.card.empty { text-align: center; padding: 48px 20px; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.card-head h2 { margin: 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); gap: 16px; }
.grid-2 .card { margin-bottom: 0; }
.grid-2 { margin-bottom: 16px; }

.chart-box { position: relative; height: 300px; }
.chart-box-sm { height: 240px; margin-bottom: 16px; }
.legend { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-left: 8px; }
.sw-1 { background: var(--c1); }
.sw-2 { background: var(--c2); }
.sw-3 { background: var(--c3); border: 1px solid var(--bad); }

/* Destaques */
.highlights .hl { display: flex; gap: 12px; padding: 12px 0; border-top: 1px solid var(--border); }
.highlights .hl:first-of-type { border-top: 0; padding-top: 0; }
.hl-icon { font-size: 20px; line-height: 1.2; }
.hl-label { font-size: 12px; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.hl-value { font-weight: 700; font-size: 16px; }
.hl > div:last-child { min-width: 0; flex: 1; }
.stopped-list { list-style: none; padding: 0; margin: 6px 0 0; max-height: 220px; overflow: auto; }
.stopped-list li { display: flex; justify-content: space-between; gap: 8px; padding: 5px 0; font-size: 13px; border-bottom: 1px dashed var(--border); }
.stopped-list li:last-child { border-bottom: 0; }

/* Etiquetas */
.tag { display: inline-block; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; margin-left: 6px; }
.tag-danger { color: var(--bad); background: var(--bad-bg); }
.tag-warn { color: var(--warn); background: var(--warn-bg); }
.tag-muted { color: var(--muted); background: var(--grid); }
.tag-best { color: var(--warn); background: var(--warn-bg); }
.tag-ok { color: var(--good); background: var(--good-bg); }
.status { font-size: 12px; font-weight: 600; }
.status-enabled { color: var(--good); }
.status-paused { color: var(--muted); }
.status-removed { color: var(--bad); }

/* Tabelas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; font-variant-numeric: tabular-nums; }
.table th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th.r { text-align: right; }
.table td { padding: 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table tr:last-child td { border-bottom: 0; }
.table .row-best td { background: var(--best-bg); }
.table form { display: inline; }

/* Formulários e botões */
.form { display: grid; gap: 14px; }
.form label { display: grid; gap: 6px; font-size: 13px; font-weight: 500; color: var(--muted); }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; align-items: end; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font: inherit; font-weight: 600; font-size: 14px; cursor: pointer;
  padding: 9px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
}
.btn:hover { text-decoration: none; border-color: var(--muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--primary); }
.btn-sm { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn-danger { color: var(--bad); }
.btn-block { width: 100%; }
.btn-link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; }

.flash { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }
.flash-ok { background: var(--good-bg); color: var(--good); }
.flash-error { background: var(--bad-bg); color: var(--bad); }

/* Login */
.login { min-height: 80vh; display: grid; place-items: center; padding: 24px 0; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow); }
.login-card h1 { font-size: 20px; margin-top: 12px; }

/* Alertas do admin */
.alert-list { display: grid; gap: 8px; }
.alert-item { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 10px 14px; border-radius: 10px; background: var(--bad-bg); flex-wrap: wrap; }
.alert-item strong { color: var(--bad); }

.inline-edit summary { list-style: none; display: inline-flex; }
.inline-edit summary::-webkit-details-marker { display: none; }
.inline-edit[open] { text-align: left; }
.inline-edit .form { margin: 10px 0 6px; min-width: 240px; }
details.card summary { cursor: pointer; }

.note { margin: 8px 0 24px; }
.footer { color: var(--muted); font-size: 12px; padding-top: 8px; padding-bottom: 32px; }

@media (max-width: 900px) {
  .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 560px) {
  h1 { font-size: 22px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 12px; }
  .kpi-value { font-size: 19px; }
  .card { padding: 16px; }
  .chart-box { height: 240px; }
  .nav { gap: 12px; }
  .topbar-in { height: auto; padding-top: 12px; padding-bottom: 12px; flex-wrap: wrap; }
}
