:root {
  --bg:#f4f6f8; --panel:#ffffff; --sidebar:#ffffff; --line:#e6e9ee;
  --txt:#1f2a37; --muted:#7b8794; --pri:#333534; --pri-soft:#e0e0e0;
  --ok:#16a34a; --err:#dc2626; --shadow:0 1px 3px rgba(16,24,40,.06);
  --sidebar-w:248px;
}
* { box-sizing: border-box; }
body { margin:0; font-family: system-ui, -apple-system, Segoe UI, sans-serif; background:var(--bg); color:var(--txt); }
a { color:inherit; text-decoration:none; }

/* ---- layout ---- */
.layout { display:flex; min-height:100vh; }
.sidebar { width:var(--sidebar-w); background:var(--sidebar); border-right:1px solid var(--line); position:fixed; inset:0 auto 0 0; display:flex; flex-direction:column; }
.main { margin-left:var(--sidebar-w); flex:1; display:flex; flex-direction:column; min-width:0; }

/* ---- logo ---- */
.brand { display:flex; flex-direction:column; align-items:flex-start; gap:6px; padding:20px 18px; border-bottom:1px solid var(--line); }
.brand .brand-img { max-width:170px; width:100%; height:auto; display:block; }
.brand .sub { color:var(--muted); font-size:11px; }

/* ---- nav ---- */
nav.menu { padding:14px 10px; flex:1; overflow:auto; }
.menu .group { color:var(--muted); font-size:11px; font-weight:700; letter-spacing:.6px; text-transform:uppercase; padding:14px 12px 6px; }
.menu a.item { display:flex; align-items:center; gap:11px; padding:10px 12px; border-radius:9px; color:#3b4658; font-size:14px; font-weight:500; margin:2px 0; border-left:3px solid transparent; }
.menu a.item:hover { background:#f3f5f8; }
.menu a.item.active { background:var(--pri-soft); color:var(--pri); border-left-color:var(--pri); font-weight:600; }
.menu a.item .ic { font-size:16px; width:20px; text-align:center; }
.sidebar .foot { border-top:1px solid var(--line); padding:12px 10px; }

/* ---- topbar ---- */
.topbar { height:62px; background:var(--panel); border-bottom:1px solid var(--line); display:flex; align-items:center; justify-content:space-between; padding:0 24px; position:sticky; top:0; z-index:5; }
.crumb { color:var(--muted); font-size:14px; }
.crumb b { color:var(--txt); }
.userchip { display:flex; align-items:center; gap:10px; }
.userchip .av { width:34px; height:34px; border-radius:50%; background:var(--pri); color:#fff; display:flex; align-items:center; justify-content:center; font-weight:700; }
.userchip .meta { line-height:1.1; text-align:right; }
.userchip .meta .u { font-size:13px; font-weight:600; }
.userchip .meta .r { font-size:11px; color:var(--muted); }

.content { padding:26px 28px; width:100%; }
.narrow { max-width:780px; }

/* ---- componentes ---- */
.card { background:var(--panel); border:1px solid var(--line); border-radius:12px; box-shadow:var(--shadow); }
table { width:100%; border-collapse:collapse; background:var(--panel); border:1px solid var(--line); border-radius:12px; overflow:hidden; box-shadow:var(--shadow); }
th, td { text-align:left; padding:4px 14px; border-bottom:1px solid var(--line); font-size:12px; }
th { color:var(--muted); font-weight:600; text-transform:uppercase; font-size:11px; letter-spacing:.4px; background:#fafbfc; }
tr:last-child td { border-bottom:none; }
tbody tr { transition: background .12s ease; }
tbody tr:hover td { background:#e9edf2; }
code { background:#eef1f5; padding:2px 6px; border-radius:5px; font-size:13px; }

.btn { display:inline-block; padding:8px 14px; border-radius:8px; border:1px solid var(--line); background:#fff; color:var(--txt); cursor:pointer; font-size:14px; font-weight:500; }
.btn:hover { background:#f6f8fa; }
.btn.primary { background:var(--pri); border-color:var(--pri); color:#fff; }
.btn.primary:hover { filter:brightness(1.05); }
.btn.danger { color:#fff; background:var(--err); border-color:var(--err); }
.btn.small { padding:5px 10px; font-size:12px; }
.btn.tableedit { padding:3.5px 10px; font-size:12px; }
form.inline { display:inline; }
/* grupo de ações nas tabelas: alinha links + botões de form na mesma linha */
.action-group { display:flex; gap:6px; align-items:center; flex-wrap:wrap; }
.action-group form.inline { display:inline-flex; margin:0; }

input, textarea, select { width:100%; padding:10px 12px; background:#fff; border:1px solid var(--line); border-radius:8px; color:var(--txt); font-size:14px; font-family:inherit; }
input:focus, textarea:focus, select:focus { outline:none; border-color:var(--pri); box-shadow:0 0 0 3px var(--pri-soft); }
textarea { resize:vertical; font-family: ui-monospace, monospace; }
label { display:block; margin:14px 0 6px; font-size:13px; font-weight:600; color:#3b4658; }
.row { display:flex; gap:14px; } .row > div { flex:1; }
.hint { color:var(--muted); font-size:12px; margin-top:4px; }

.flash { padding:11px 14px; border-radius:8px; margin-bottom:14px; font-size:14px; }
.flash.ok { background:#e9f9f1; border:1px solid #9fe3c3; color:#0f7a4f; }
.flash.error { background:#fdeaea; border:1px solid #f3b4b4; color:#a51f1f; }
.pill { font-size:12px; padding:3px 9px; border-radius:99px; font-weight:600; }
.pill.on { background:#e7f6ef; color:#0f7a4f; }
.pill.off { background:#eef1f5; color:var(--muted); }
.pill.err { background:#fdeaea; color:#a51f1f; }
.pill.warn { background:#fdf1d8; color:#8a5a00; }

/* cards de resumo (monitoramento) */
.cards { display:flex; gap:14px; margin-bottom:18px; flex-wrap:wrap; }
.stat { flex:1; min-width:160px; padding:16px 18px; }
.stat .big { font-size:26px; font-weight:700; }
.stat .lbl { color:var(--muted); font-size:13px; margin-top:2px; }
.stat.ok .big { color:#0f7a4f; }
.stat.bad .big { color:#a51f1f; }
.stat.warn .big { color:#8a5a00; }
a.stat { text-decoration:none; }
a.stat:hover { background:#f6f8fa; }
.stat.active { box-shadow:0 0 0 2px var(--pri) inset; }
tr.row-alert td { background:#fff6f6; }

/* cabeçalhos ordenáveis */
th.sortable { cursor:pointer; user-select:none; white-space:nowrap; }
th.sortable::after { content:' ⇅'; color:var(--muted); font-size:11px; }
th.sortable[data-dir="asc"]::after { content:' ▲'; color:var(--txt); }
th.sortable[data-dir="desc"]::after { content:' ▼'; color:var(--txt); }
.page-head { display:flex; justify-content:space-between; align-items:center; margin-bottom:18px; }
.page-head h2 { margin:0; font-size:20px; }
.page-head h3 { margin:0; font-size:18px; }
.num { text-align:right; }
.form-card { padding:18px; }
.result-section { margin-top:22px; }
.err-list { margin:6px 0 0; padding-left:18px; }

/* ---- login ---- */
.login-wrap { min-height:100vh; display:flex; align-items:center; justify-content:center; background:var(--bg); }
.login-card { width:360px; }

/* ---- modal ---- */
.modal-overlay { display:none; position:fixed; inset:0; background:rgba(16,24,40,.45); z-index:50; align-items:flex-start; justify-content:center; overflow:auto; padding:40px 16px; }
.modal-overlay.show { display:flex; }
.modal { background:var(--panel); border-radius:12px; box-shadow:0 20px 50px rgba(16,24,40,.25); width:100%; max-width:680px; padding:24px; }
.modal h3 { margin:0 0 14px; font-size:18px; }

/* ---- utilitários e componentes ---- */
.muted { color:var(--muted); }
.subtle { font-size:14px; font-weight:400; }
.truncate { max-width:240px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.btn-block { width:100%; }
input[type=checkbox], input[type=radio] { width:auto; }

/* checkbox + rótulo na mesma linha */
.check { display:flex; align-items:center; gap:8px; margin:0; font-weight:400; }
.check-row { display:flex; gap:24px; margin-top:16px; }
.mt16 { margin-top:16px; }

/* rodapé de formulário (botões) */
.form-actions { margin-top:20px; display:flex; gap:8px; align-items:center; }
.field-sm { max-width:140px; }

/* construtor de colunas (página Tabelas) */
.col-row { display:flex; gap:8px; align-items:center; margin-bottom:8px; }
.col-row .c-name { flex:2; }
.col-row .c-type { flex:1; }
.col-row .c-len { max-width:80px; }
.col-flag { display:flex; align-items:center; gap:4px; margin:0; font-weight:400; white-space:nowrap; }

/* itens de lançamento (form da conta): aparece só quando "aceita lançamentos" marcado */
#itens-wrap { display:none; }
.conta-form:has(input[name="aceita_lancamentos"]:checked) #itens-wrap { display:block; }
.item-row { display:flex; gap:8px; align-items:center; margin-bottom:8px; }
.item-row input { flex:1; }

/* resultado de disparo */
.result { margin-top:24px; }
.result h3 { margin-bottom:8px; font-size:16px; }
.desc { color:var(--muted); margin-top:0; }
.code-output { background:#f6f8fa; border:1px solid var(--line); border-radius:8px; padding:12px; overflow:auto; font-size:13px; margin:0; }

/* login */
.login-card .card { padding:28px; }
.login-head { text-align:center; margin-bottom:24px; }
.login-logo { max-width:200px; width:80%; height:auto; }
.login-sub { color:var(--muted); font-size:12px; margin-top:8px; }
.login-submit { width:100%; margin-top:20px; }
