:root {
  --bg: #f4f6f7; --surface: #ffffff; --surface-2: #f8fafb; --border: #e2e8eb;
  --text: #0f1b24; --muted: #5b6b75; --primary: #0d9488; --primary-ink: #ffffff; --primary-soft: #ccf0ec;
  --good: #15803d; --bad: #dc2626; --warn: #b45309; --warn-bg: #fef3c7; --bad-bg: #fee2e2; --ok-bg: #dcfce7;
  --bar: #0d9488; --bar-2: #5eead4; --shadow: 0 1px 2px rgba(15,27,36,.06), 0 4px 16px rgba(15,27,36,.04);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1115; --surface: #121b21; --surface-2: #0f171c; --border: #22313a;
    --text: #e6edf0; --muted: #93a4ad; --primary: #2dd4bf; --primary-ink: #04201c; --primary-soft: #113a36;
    --good: #4ade80; --bad: #f87171; --warn: #fbbf24; --warn-bg: #3a2c0a; --bad-bg: #3b1414; --ok-bg: #0f2e1b;
    --bar: #14b8a6; --bar-2: #0f766e; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1115; --surface: #121b21; --surface-2: #0f171c; --border: #22313a;
  --text: #e6edf0; --muted: #93a4ad; --primary: #2dd4bf; --primary-ink: #04201c; --primary-soft: #113a36;
  --good: #4ade80; --bad: #f87171; --warn: #fbbf24; --warn-bg: #3a2c0a; --bad-bg: #3b1414; --ok-bg: #0f2e1b;
  --bar: #14b8a6; --bar-2: #0f766e; --shadow: none; color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-variant-numeric: tabular-nums;
}
a { color: var(--primary); }
h1 { font-size: 1.35rem; margin: 18px 0 12px; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 12px; }
h3 { font-size: .95rem; margin: 16px 0 8px; }
p { margin: 0 0 10px; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .86em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hide { display: none !important; }
.nowrap { white-space: nowrap; }

/* topo */
.top { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 10; }
.top-in { max-width: 1180px; margin: 0 auto; padding: 10px 16px 4px; display: flex; align-items: center; justify-content: space-between; }
.brand { display: flex; gap: 8px; align-items: center; color: var(--text); text-decoration: none; font-weight: 700; letter-spacing: -.01em; }
.brand svg { color: var(--primary); }
.icon-btn { background: none; border: 1px solid var(--border); color: var(--muted); border-radius: 10px; width: 36px; height: 36px; display: grid; place-items: center; cursor: pointer; }
.nav { max-width: 1180px; margin: 0 auto; padding: 4px 12px 8px; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a { flex: 0 0 auto; padding: 7px 12px; border-radius: 999px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: .9rem; }
.nav a.on { background: var(--primary-soft); color: var(--text); }
.nav a.out { margin-left: auto; }

.wrap { max-width: 1180px; margin: 0 auto; padding: 12px 16px 40px; }
.foot { text-align: center; color: var(--muted); font-size: .8rem; padding: 20px 16px 32px; }

/* filtros */
.filters { display: flex; flex-wrap: wrap; gap: 8px 10px; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px; margin: 4px 0 14px; }
.filters label { display: flex; flex-direction: column; gap: 2px; font-size: .75rem; color: var(--muted); font-weight: 600; min-width: 0; flex: 1 1 130px; max-width: 220px; }
.filters .range { font-size: .8rem; color: var(--muted); margin-left: auto; padding-bottom: 8px; }
select, input[type=text], input[type=password], input[type=date], input[type=number], input[type=url], textarea {
  font: inherit; color: var(--text); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; width: 100%; min-width: 0;
}
textarea { min-height: 90px; resize: vertical; }
select:focus, input:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }

/* botões */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 650; border: 1px solid transparent; background: var(--primary); color: var(--primary-ink); padding: 9px 16px; border-radius: 10px; cursor: pointer; text-decoration: none; }
.btn.sec { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.sm { padding: 6px 12px; font-size: .85rem; }
.btn:disabled { opacity: .6; cursor: wait; }
.row-btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }

/* cartões */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); min-width: 0; }
.card .lbl { font-size: .78rem; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.card .val { font-size: 1.55rem; font-weight: 750; letter-spacing: -.02em; line-height: 1.2; margin-top: 2px; }
.card .sub { font-size: .78rem; color: var(--muted); margin-top: 2px; }
.card.money .val { color: var(--good); }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; min-width: 0; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.panel-head h2 { margin: 0; display: flex; gap: 6px; align-items: center; }
.grid-2 { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1.4fr 1fr; } }

/* funil */
.funnel { display: flex; flex-direction: column; gap: 6px; }
.stage { display: grid; grid-template-columns: 150px 1fr 190px; gap: 12px; align-items: center; padding: 6px 8px; border-radius: 10px; }
.stage.worst { background: var(--bad-bg); }
.stage .name { font-weight: 650; font-size: .92rem; display: flex; flex-direction: column; }
.stage .name small { font-weight: 500; color: var(--muted); font-size: .75rem; }
.stage .track { background: var(--surface-2); border-radius: 8px; height: 34px; position: relative; overflow: hidden; }
.stage .fill { height: 100%; background: linear-gradient(90deg, var(--bar), var(--bar-2)); border-radius: 8px; min-width: 2px; transition: width .5s ease; }
.stage.off .fill { background: var(--border); }
.stage .count { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); font-weight: 750; font-size: .95rem; color: var(--text); text-shadow: 0 0 6px var(--surface); }
.stage .rates { font-size: .82rem; line-height: 1.35; }
.stage .rates b { font-size: .95rem; }
.stage .leak { color: var(--bad); font-weight: 600; }
.stage.worst .leak::before { content: "⚠ "; }
@media (max-width: 700px) {
  .stage { grid-template-columns: 1fr auto; grid-template-areas: "name rates" "track track"; gap: 4px 10px; padding: 8px; }
  .stage .name { grid-area: name; }
  .stage .rates { grid-area: rates; text-align: right; }
  .stage .track { grid-area: track; }
}

/* ajuda (?) */
.tip { display: inline-block; position: relative; }
.tip summary { list-style: none; cursor: pointer; width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--border); color: var(--muted); font-size: .7rem; font-weight: 700; display: grid; place-items: center; }
.tip summary::-webkit-details-marker { display: none; }
.tip-box { position: absolute; z-index: 20; top: 24px; left: -8px; width: min(300px, 80vw); background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; box-shadow: 0 8px 30px rgba(0,0,0,.15); font-size: .82rem; font-weight: 400; line-height: 1.45; }

/* avisos */
.banner { padding: 10px 14px; border-radius: 12px; margin: 0 0 12px; font-size: .9rem; border: 1px solid transparent; }
.banner.ok { background: var(--ok-bg); }
.banner.warn { background: var(--warn-bg); }
.banner.err, .banner.bad { background: var(--bad-bg); }
.banner.info { background: var(--primary-soft); }
.alert-box { border-left: 4px solid var(--bad); }

/* tabelas */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; }
table { border-collapse: collapse; width: 100%; font-size: .87rem; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { font-size: .75rem; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .02em; background: var(--surface); position: sticky; top: 0; }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--surface); }
td.l, th.l { text-align: left; }
tr:hover td { background: var(--surface-2); }
tr:hover td:first-child { background: var(--surface-2); }
.tag { display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); color: var(--muted); }
.tag.good { background: var(--ok-bg); color: var(--good); border-color: transparent; }
.tag.bad { background: var(--bad-bg); color: var(--bad); border-color: transparent; }
.tag.warn { background: var(--warn-bg); color: var(--warn); border-color: transparent; }
.tag.info { background: var(--primary-soft); color: var(--text); border-color: transparent; }

/* feed */
.feed { list-style: none; margin: 0; padding: 0; }
.feed li { display: flex; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--border); font-size: .88rem; }
.feed li:last-child { border-bottom: 0; }
.feed .what { font-weight: 650; }
.feed .meta { color: var(--muted); font-size: .78rem; }
.feed .amt { font-weight: 750; color: var(--good); white-space: nowrap; }

/* formulários */
.form-grid { display: grid; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-weight: 650; font-size: .88rem; }
.field small { color: var(--muted); font-size: .8rem; }
.check { display: flex; gap: 8px; align-items: center; font-size: .92rem; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.copy { display: flex; gap: 6px; align-items: stretch; }
.copy input, .copy textarea { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .78rem; }
.copy textarea { min-height: 70px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: .88rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }
.chart-box { position: relative; height: 260px; }
.metric-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; }
.metric { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; font-size: .85rem; }
.metric b { display: block; font-size: 1.05rem; }

/* ajuda (manual) */
.manual { max-width: 820px; }
.manual h1 { font-size: 1.5rem; }
.manual h2 { font-size: 1.2rem; margin-top: 30px; padding-top: 10px; border-top: 1px solid var(--border); }
.manual h3 { font-size: 1rem; margin-top: 20px; }
.manual pre { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; overflow-x: auto; font-size: .82rem; }
.manual blockquote { margin: 10px 0; padding: 8px 14px; border-left: 4px solid var(--primary); background: var(--surface-2); border-radius: 0 10px 10px 0; }
.manual li { margin-bottom: 4px; }
.manual table td, .manual table th { white-space: normal; text-align: left; }
.toc { columns: 2 220px; font-size: .9rem; }

/* login / instalador */
.auth { max-width: 420px; margin: 8vh auto; padding: 0 16px; }
.auth .panel { padding: 22px; }
.auth h1 { margin-top: 0; }
.steps-install { max-width: 640px; margin: 4vh auto; padding: 0 16px; }
