/* BPTI — sistema interno.
   Sidebar escura + conteudo claro. Sem framework e sem build: o backend serve
   estes arquivos direto, entao cada KB aqui e um KB que a equipe baixa. */

:root {
  --bg: #0f172a;
  --panel: #1e293b;
  --panel-2: #273449;
  --text: #e2e8f0;
  --muted: #94a3b8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --warn: #d97706;
  --warn-soft: #fef3c7;
  --ok: #16a34a;
  --ok-soft: #dcfce7;
  --border: #334155;
  --line: #e2e8f0;
  --surface: #ffffff;
  --canvas: #f1f5f9;
  --ink: #0f172a;
  --ink-2: #475569;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
  --shadow-lg: 0 20px 60px rgba(15, 23, 42, .18);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--canvas);
  color: var(--ink);
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .85rem; }
.error { color: var(--danger); font-size: .85rem; min-height: 1rem; }
.right { text-align: right; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.mono { font-variant-numeric: tabular-nums; }
.grow { flex: 1; }

/* --- Controles ---------------------------------------------------------- */
button {
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: .55rem 1rem;
  background: var(--accent);
  color: #fff;
  font-size: .875rem;
  font-family: inherit;
  font-weight: 500;
  transition: background .12s ease;
}
button:hover { background: var(--accent-hover); }
button:disabled { opacity: .5; cursor: not-allowed; }
button.link { background: none; color: var(--ink-2); padding: .4rem .6rem; }
button.link:hover { background: #e2e8f0; }
button.ghost { background: #fff; color: var(--ink-2); border: 1px solid var(--line); }
button.ghost:hover { background: #f8fafc; }
button.del, button.danger { background: var(--danger); }
button.del:hover, button.danger:hover { background: #b91c1c; }
button.sm { padding: .3rem .6rem; font-size: .78rem; }

input, select, textarea {
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: .875rem;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(37, 99, 235, .35);
  border-color: var(--accent);
}
input[type="checkbox"] { width: auto; }
label.inline { flex-direction: row !important; align-items: center; gap: .5rem; }

/* --- Login -------------------------------------------------------------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 1rem;
}
.login-card {
  background: var(--panel);
  color: var(--text);
  padding: 2.5rem;
  border-radius: 16px;
  width: 360px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  gap: .9rem;
  box-shadow: var(--shadow-lg);
}
.login-card h1 { margin: 0; font-size: 1.5rem; }
.login-card label { display: flex; flex-direction: column; gap: .3rem; font-size: .85rem; }

/* --- Layout ------------------------------------------------------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  padding: 1.2rem 0;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  font-weight: 700;
  font-size: 1.25rem;
  padding: 0 1.4rem 1rem;
  letter-spacing: .05em;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.sidebar nav { display: flex; flex-direction: column; flex: 1; overflow-y: auto; }
.nav-item {
  background: none;
  color: var(--muted);
  text-align: left;
  border-radius: 0;
  padding: .7rem 1.4rem;
  font-weight: 400;
  display: flex;
  align-items: center;
  gap: .6rem;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--panel); color: #fff; }
.nav-item.active { background: var(--panel-2); color: #fff; border-left-color: var(--accent); font-weight: 500; }
.nav-item .pill {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: .68rem;
  padding: .05rem .4rem;
  font-weight: 600;
}
.sidebar-footer {
  padding: 1rem 1.4rem 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .3rem;
}
.sidebar-footer .quem { color: #fff; font-size: .85rem; }
.sidebar-footer button.link { color: var(--muted); text-align: left; padding: .25rem 0; }
.sidebar-footer button.link:hover { background: none; color: #fff; text-decoration: underline; }

.content { flex: 1; padding: 1.75rem 2rem; overflow: auto; min-width: 0; }
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.2rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.view-header h2 { margin: 0; font-size: 1.35rem; }
.view-header .sub { color: var(--muted); font-size: .85rem; margin-top: .15rem; }
.toolbar { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.toolbar input, .toolbar select { width: auto; min-width: 150px; }

/* --- Abas internas ------------------------------------------------------ */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.1rem; flex-wrap: wrap; }
.tab {
  background: none;
  color: var(--ink-2);
  border-radius: 8px 8px 0 0;
  padding: .55rem .9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { background: #e2e8f0; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); background: none; font-weight: 600; }

/* --- Cards e KPIs ------------------------------------------------------- */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
}
.card h3 { margin: 0 0 .8rem; font-size: .95rem; color: var(--ink-2); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .9rem; margin-bottom: 1.25rem; }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem 1.15rem; }
.kpi .rotulo { color: var(--muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; }
.kpi .valor { font-size: 1.5rem; font-weight: 700; margin-top: .3rem; font-variant-numeric: tabular-nums; }
.kpi .nota { color: var(--muted); font-size: .78rem; margin-top: .2rem; }
.kpi.alerta .valor { color: var(--danger); }
.kpi.bom .valor { color: var(--ok); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; }

/* --- Tabelas ------------------------------------------------------------ */
.tabela-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td {
  text-align: left;
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--line);
  font-size: .865rem;
  vertical-align: middle;
}
.data-table th {
  background: #f8fafc;
  color: var(--ink-2);
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .03em;
  white-space: nowrap;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr.clicavel { cursor: pointer; }
.data-table tbody tr.clicavel:hover { background: #f8fafc; }
.row-actions { white-space: nowrap; text-align: right; }
.row-actions button { padding: .28rem .6rem; font-size: .78rem; margin-left: .3rem; }

.badge {
  padding: .15rem .55rem;
  border-radius: 999px;
  font-size: .74rem;
  font-weight: 600;
  display: inline-block;
  white-space: nowrap;
}
.badge.ativo, .badge.online, .badge.liquidado, .badge.emitido, .badge.conciliado { background: var(--ok-soft); color: #166534; }
.badge.prospecto, .badge.instavel, .badge.parcial, .badge.rascunho, .badge.pendente, .badge.suspenso { background: var(--warn-soft); color: #854d0e; }
.badge.inativo, .badge.pausado, .badge.cancelado, .badge.ignorado, .badge.encerrado, .badge.desconhecido { background: #f1f5f9; color: #64748b; }
.badge.offline, .badge.vencido { background: var(--danger-soft); color: #991b1b; }
.badge.aberto { background: #dbeafe; color: #1e40af; }

.vazio { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }

/* --- Modal -------------------------------------------------------------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3vh 1rem;
  z-index: 50;
  overflow-y: auto;
}
.modal-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 1.6rem 1.8rem;
  width: 760px;
  max-width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal-card.larga { width: 1020px; }
.modal-card h3 { margin: 0 0 1rem; font-size: 1.1rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.form-grid label { display: flex; flex-direction: column; gap: .25rem; font-size: .78rem; color: var(--ink-2); font-weight: 500; }
.col-span-2 { grid-column: 1 / -1; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: .6rem; align-items: center; }
fieldset { border: 1px solid var(--line); border-radius: 10px; padding: .9rem 1rem; margin: 0; }
fieldset legend { font-size: .78rem; color: var(--muted); padding: 0 .35rem; font-weight: 600; text-transform: uppercase; }

/* --- Avisos ------------------------------------------------------------- */
.aviso {
  padding: .7rem .9rem;
  border-radius: 10px;
  font-size: .85rem;
  margin-bottom: 1rem;
  border: 1px solid;
}
.aviso.info { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.aviso.alerta { background: var(--warn-soft); border-color: #fde68a; color: #854d0e; }
.aviso.erro { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  background: var(--ink);
  color: #fff;
  padding: .8rem 1.1rem;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  z-index: 100;
  font-size: .875rem;
  max-width: 420px;
}
.toast.erro { background: var(--danger); }
.toast.ok { background: var(--ok); }

/* --- Monitoramento ------------------------------------------------------ */
.sparkline { display: flex; gap: 2px; align-items: flex-end; height: 26px; }
.sparkline i { width: 4px; border-radius: 1px; display: block; background: var(--ok); }
.sparkline i.falha { background: var(--danger); }
.ponto { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: .4rem; }
.ponto.online { background: var(--ok); }
.ponto.offline { background: var(--danger); }
.ponto.instavel { background: var(--warn); }
.ponto.pausado, .ponto.desconhecido { background: #94a3b8; }

/* --- Fluxo de caixa (barras) -------------------------------------------- */
.barras { display: flex; align-items: flex-end; gap: .9rem; height: 170px; padding-top: .5rem; }
.barra-mes { flex: 1; display: flex; flex-direction: column; align-items: center; gap: .35rem; min-width: 0; }
.barra-par { display: flex; gap: 3px; align-items: flex-end; height: 130px; }
.barra-par i { width: 15px; border-radius: 3px 3px 0 0; display: block; min-height: 2px; }
.barra-par i.entrada { background: var(--ok); }
.barra-par i.saida { background: var(--danger); }
.barra-mes span { font-size: .7rem; color: var(--muted); white-space: nowrap; }
.legenda { display: flex; gap: 1rem; font-size: .78rem; color: var(--ink-2); margin-top: .6rem; }
.legenda i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .3rem; }

/* --- Email -------------------------------------------------------------- */
.email-layout { display: grid; grid-template-columns: 190px 340px 1fr; gap: 1rem; height: calc(100vh - 190px); min-height: 420px; }
.email-col { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow-y: auto; }
.email-col.pastas { padding: .5rem; }
.pasta-item {
  background: none;
  color: var(--ink-2);
  text-align: left;
  width: 100%;
  padding: .5rem .7rem;
  border-radius: 8px;
  font-weight: 400;
}
.pasta-item:hover { background: #f1f5f9; }
.pasta-item.active { background: #dbeafe; color: #1e40af; font-weight: 600; }
.msg-item { padding: .7rem .9rem; border-bottom: 1px solid var(--line); cursor: pointer; }
.msg-item:hover { background: #f8fafc; }
.msg-item.active { background: #eff6ff; }
.msg-item.nao-lida .assunto { font-weight: 700; }
.msg-item .de { font-size: .8rem; color: var(--ink-2); display: flex; justify-content: space-between; gap: .5rem; }
.msg-item .de b { font-weight: 600; }
.msg-item .assunto { font-size: .875rem; margin-top: .15rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg-corpo { padding: 1.2rem 1.4rem; }
.msg-corpo header { border-bottom: 1px solid var(--line); padding-bottom: .8rem; margin-bottom: .8rem; }
.msg-corpo h3 { margin: 0 0 .4rem; font-size: 1.05rem; }
/* O corpo do email vive num iframe sandbox — ver core/html_sanitize.py. */
.msg-corpo iframe { width: 100%; min-height: 420px; border: none; background: #fff; }

/* --- Documentos --------------------------------------------------------- */
.doc-preview { width: 100%; height: 62vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.campos-dinamicos { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }

/* --- Responsivo --------------------------------------------------------- */
@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; padding: .8rem 0; }
  .sidebar nav { flex-direction: row; overflow-x: auto; }
  .nav-item { border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; }
  .nav-item.active { border-left-color: transparent; border-bottom-color: var(--accent); }
  .content { padding: 1rem; }
  .form-grid, .campos-dinamicos { grid-template-columns: 1fr; }
  .email-layout { grid-template-columns: 1fr; height: auto; }
  .email-col { max-height: 300px; }
}
