/* ===== Temas (claro/escuro) — paleta espelhando o ERP (brand azul Meintec #1655f1 + slate) ===== */
:root { /* CLARO (padrão) */
  --bg: #f8fafc; --bg2: #eef2f8; --surface: #ffffff; --surface2: #f1f5f9; --border: #e2e8f0;
  --brand: #1655f1; --brand-d: #1a3b9f; --brand-soft: rgba(22,85,241,.10);
  --text: #0f172a; --muted: #64748b; --err: #dc2626; --ok: #16a34a; --amber: #d97706;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0b1220; --bg2: #0d1830; --surface: #131c2e; --surface2: #1c2941; --border: #26324a;
    --brand: #3d6cf5; --brand-d: #5b82f7; --brand-soft: rgba(59,108,245,.18);
    --text: #e8eef6; --muted: #94a3b8; --err: #f87171; --ok: #34d399; --amber: #fbbf24;
    --shadow: 0 2px 24px rgba(0,0,0,.4);
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --bg2: #0d1830; --surface: #131c2e; --surface2: #1c2941; --border: #26324a;
  --brand: #3d6cf5; --brand-d: #5b82f7; --brand-soft: rgba(59,108,245,.18);
  --text: #e8eef6; --muted: #94a3b8; --err: #f87171; --ok: #34d399; --amber: #fbbf24;
  --shadow: 0 2px 24px rgba(0,0,0,.4);
}
:root[data-theme="light"] {
  --bg: #f8fafc; --bg2: #eef2f8; --surface: #ffffff; --surface2: #f1f5f9; --border: #e2e8f0;
  --brand: #1655f1; --brand-d: #1a3b9f; --brand-soft: rgba(22,85,241,.10);
  --text: #0f172a; --muted: #64748b; --err: #dc2626; --ok: #16a34a; --amber: #d97706;
  --shadow: 0 1px 2px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
}

* { box-sizing: border-box; }
body { margin: 0; font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: radial-gradient(1100px 560px at 18% -12%, var(--bg2), var(--bg)); color: var(--text);
  min-height: 100vh; transition: background .25s, color .25s; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.center { text-align: center; }
.err { color: var(--err); font-size: 13px; min-height: 18px; margin-top: 6px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow); }
.brand { font-weight: 800; letter-spacing: .5px; }
.brand span { color: var(--brand); font-weight: 600; }

/* botão de tema */
.theme-btn { width: 36px; height: 36px; border-radius: 9px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer; font-size: 16px; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; }
.theme-btn:hover { color: var(--brand); border-color: var(--brand); }

/* LOGIN */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; position: relative; }
.login-topright { position: absolute; top: 18px; right: 18px; }
.login-card { width: 100%; max-width: 360px; padding: 28px; display: flex; flex-direction: column; gap: 12px; }
.login-card .brand { font-size: 20px; margin-bottom: 2px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 9px;
  padding: 10px 12px; font-size: 14px; outline: none; }
input:focus { border-color: var(--brand); }
.btn { background: var(--brand); color: #fff; border: 0; border-radius: 9px; padding: 11px 16px;
  font-weight: 600; font-size: 14px; cursor: pointer; }
.btn:hover { background: var(--brand-d); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.ghost { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.btn.ghost:hover { color: var(--text); border-color: var(--brand); background: transparent; }

/* APP */
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 14px 24px;
  border-bottom: 1px solid var(--border); background: var(--surface); position: sticky; top: 0; z-index: 10; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.content { max-width: 1100px; margin: 0 auto; padding: 24px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; margin: 0; }
.search { width: 280px; }
.table-card { overflow: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { text-align: left; padding: 12px 16px; font-size: 11px; text-transform: uppercase;
  letter-spacing: .5px; color: var(--muted); background: var(--surface2); }
tbody td { padding: 12px 16px; border-top: 1px solid var(--border); }
tbody tr.clickable { cursor: pointer; }
tbody tr:hover { background: var(--surface2); }
.pill { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.ativa { background: rgba(5,150,105,.14); color: var(--ok); }
.pill.off { background: rgba(96,120,134,.14); color: var(--muted); }
.plan { font-weight: 600; }

/* DRAWER */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; justify-content: flex-end; z-index: 50; }
.drawer { width: 560px; max-width: 100%; height: 100%; border-radius: 0; border-left: 1px solid var(--border);
  display: flex; flex-direction: column; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px;
  padding: 20px 22px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0 0 2px; font-size: 19px; }
.drawer-body { padding: 20px 22px; overflow-y: auto; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.small { font-size: 12px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.fld { display: flex; flex-direction: column; gap: 6px; }
.fld label { font-size: 12px; color: var(--muted); }
select { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 9px; padding: 10px 12px; font-size: 14px; }
select:focus { border-color: var(--brand); outline: none; }
.ro { padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface2); font-size: 14px; }
.uso { display: flex; gap: 16px; flex-wrap: wrap; margin: 16px 0 4px; color: var(--muted); font-size: 14px; }
.sec { font-size: 14px; margin: 20px 0 10px; color: var(--text); }
.mods { display: flex; flex-direction: column; gap: 8px; }
.mod-row { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface2); }
.mod-right { display: flex; align-items: center; gap: 10px; }
.tag { padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.tag.ok { background: rgba(5,150,105,.14); color: var(--ok); }
.tag.cortesia { background: var(--brand-soft); color: var(--brand); }
.tag.pago { background: rgba(217,119,6,.14); color: var(--amber); }
.tag.off { background: rgba(96,120,134,.12); color: var(--muted); }

/* ===== Layout com SIDEBAR (estilo ERP) ===== */
#app { display: flex; min-height: 100vh; }
.sidebar { width: 244px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.side-brand { font-weight: 800; letter-spacing: .5px; padding: 8px 10px 18px; font-size: 16px; }
.side-brand span { color: var(--brand); font-weight: 600; }
.side-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 9px;
  color: var(--muted); font-size: 14px; font-weight: 500; cursor: pointer; user-select: none; }
.nav-item:hover { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.ni { width: 18px; height: 18px; flex-shrink: 0; }
.side-foot { border-top: 1px solid var(--border); padding: 12px 6px 4px; display: flex; flex-direction: column; gap: 10px; }
.side-foot #who { font-size: 13px; padding-left: 4px; }
.side-foot-actions { display: flex; align-items: center; gap: 8px; }
/* content ocupa o resto (sobrescreve o layout antigo centralizado) */
.content { flex: 1; padding: 26px 32px; max-width: none; margin: 0; }
.view { max-width: 1080px; }
.empty-state { padding: 44px 40px; text-align: center; }
.empty-state h3 { margin: 0 0 8px; font-size: 16px; }

/* head com ações (busca + botão) */
.head-actions { display: flex; align-items: center; gap: 10px; }
textarea { background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 9px;
  padding: 10px 12px; font-size: 14px; font-family: inherit; resize: vertical; outline: none; width: 100%; }
textarea:focus { border-color: var(--brand); }
input { width: 100%; }

/* MODAL centralizado */
.center-overlay { align-items: center; justify-content: center; }
.modal { width: 520px; max-width: 94vw; max-height: 90vh; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; }
.kb-actions { display: flex; gap: 10px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.empty-state a.btn { text-decoration: none; }
