/* Otimiza Metas — UI. Vanilla, sem framework. Claro por padrão, respeita dark. */
:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f1f4; --border: #e2e5ea;
  --text: #1a1d23; --muted: #6b7280; --brand: #2563eb; --brand-ink: #fff;
  --ok: #16a34a; --warn: #d97706; --bad: #dc2626; --shadow: 0 1px 3px rgba(20,25,40,.08), 0 1px 2px rgba(20,25,40,.04);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --surface: #171a20; --surface-2: #1f232b; --border: #2a2f39;
    --text: #e8eaed; --muted: #9aa1ad; --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font: 15px/1.5 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* Login */
.login-body { display: grid; place-items: center; min-height: 100vh; }
.login-card { background: var(--surface); padding: 32px; border-radius: var(--radius); box-shadow: var(--shadow); width: min(360px, 92vw); border: 1px solid var(--border); }
.login-logo { font-size: 22px; margin-bottom: 4px; }
.login-sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }
.login-card form { display: grid; gap: 14px; }
.login-card label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
.login-card input { padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font-size: 15px; }
.login-card button { padding: 11px; border: 0; border-radius: 8px; background: var(--brand); color: var(--brand-ink); font-weight: 600; }
.login-err { color: var(--bad); font-size: 13px; margin: 0; }

/* App shell */
#app[data-loading] { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
.shell { display: grid; grid-template-columns: 232px 1fr; grid-template-rows: 56px 1fr; grid-template-areas: "brand top" "side main"; min-height: 100vh; }
.topbar { grid-area: top; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; background: var(--surface); border-bottom: 1px solid var(--border); }
.brandbar { grid-area: brand; display: flex; align-items: center; gap: 8px; padding: 0 18px; background: var(--surface); border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); font-weight: 700; }
.sidebar { grid-area: side; background: var(--surface); border-right: 1px solid var(--border); padding: 12px 10px; overflow-y: auto; }
.main { grid-area: main; padding: 22px 26px; overflow-y: auto; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 9px 11px; border-radius: 8px; color: var(--text); font-size: 14px; cursor: pointer; }
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); font-weight: 600; }
.nav-sep { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 14px 11px 4px; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.who { display: flex; align-items: center; gap: 10px; }
.who small { color: var(--muted); }
.badge { font-size: 11px; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.btn { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; font-size: 13px; }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12px; }

.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head p { margin: 3px 0 0; color: var(--muted); font-size: 14px; }

/* Grid de widgets */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); position: relative; }
.card.w2 { grid-column: span 2; }
@media (max-width: 720px) { .card.w2 { grid-column: span 1; } .shell { grid-template-columns: 1fr; grid-template-areas: "top" "main"; } .sidebar, .brandbar { display: none; } }
.card h3 { margin: 0 0 2px; font-size: 14px; }
.card .sector-tag { font-size: 11px; color: var(--muted); }
.card .ns { color: var(--warn); }
.big { font-size: 34px; font-weight: 700; line-height: 1.1; margin: 10px 0 2px; }
.big .unit { font-size: 15px; color: var(--muted); font-weight: 500; margin-left: 5px; }
.mom { font-size: 13px; font-weight: 600; }
.mom.up { color: var(--ok); } .mom.down { color: var(--bad); } .mom.flat { color: var(--muted); }
.period { font-size: 12px; color: var(--muted); }

/* Escada */
.ladder { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 8px; }
.step { font-size: 12px; padding: 3px 9px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface-2); color: var(--muted); }
.step.on { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); font-weight: 600; }
.step.next { border-color: var(--brand); color: var(--brand); }
.bar { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.progress-cap { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* Config mode */
.card .wtools { position: absolute; top: 8px; right: 8px; display: none; gap: 4px; }
.editing .card .wtools { display: flex; }
.editing .card { border-style: dashed; }
.wtools button { border: 1px solid var(--border); background: var(--surface); border-radius: 6px; width: 26px; height: 26px; line-height: 1; }

/* Tabelas / admin */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs .tab { padding: 7px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); font-size: 13px; }
.tabs .tab.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.form-row { display: grid; gap: 6px; margin-bottom: 12px; }
.form-row label { font-size: 12px; color: var(--muted); }
input, select, textarea { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--text); font: inherit; }
.keybox { background: var(--surface-2); border: 1px dashed var(--warn); padding: 10px; border-radius: 8px; font-family: ui-monospace, monospace; font-size: 13px; word-break: break-all; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 40px; text-align: center; }

/* Drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: none; }
.drawer-bg.open { display: block; }
.drawer { position: fixed; top: 0; right: 0; height: 100vh; width: min(520px, 96vw); background: var(--surface); border-left: 1px solid var(--border); padding: 22px; overflow-y: auto; transform: translateX(100%); transition: transform .18s ease; }
.drawer-bg.open .drawer { transform: translateX(0); }
.seg-row { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; padding: 5px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.seg-bar { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 3px; }
.seg-bar > i { display: block; height: 100%; background: var(--brand); }
svg.spark { display: block; width: 100%; height: 44px; margin-top: 10px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .2s; }
.toast.show { opacity: 1; }
