/* ==========================================================================
   Nucleo — folha de estilo do núcleo.
   Módulos NÃO trazem CSS próprio: usam as classes daqui (card, table-card,
   badge, field, kpi, empty...). Se um módulo precisar de algo visual novo,
   o estilo entra aqui para o sistema continuar visualmente coeso.
   ========================================================================== */

:root {
  --bg: #0f1216;
  --panel: #171b21;
  --panel-2: #1e242c;
  --border: #2a323c;
  --text: #e6eaef;
  --muted: #8b97a6;
  --accent: #4c8bf5;
  --accent-soft: #1d2c47;
  --ok: #3fb950;
  --warn: #d29922;
  --danger: #f0663f;
  --radius: 8px;
  --topbar-h: 52px;
  --aside-w: 220px;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-size: 14px; }

/* --------------------------------------------------------------------------
   Barra superior — presente na home e dentro dos módulos
   -------------------------------------------------------------------------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--topbar-h); z-index: 30;
  background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 12px; padding: 0 14px;
}
.topbar .tb-apps {
  background: var(--panel-2); border: 1px solid var(--border); color: var(--text);
  width: 32px; height: 32px; border-radius: 6px; cursor: pointer; font-size: 15px; line-height: 1;
}
.topbar .tb-apps:hover { border-color: var(--accent); color: var(--accent); }
.topbar .tb-brand { font-size: 15px; font-weight: 600; letter-spacing: -0.02em; cursor: pointer; }
.topbar .tb-brand span { color: var(--accent); }
.topbar .tb-sep { width: 1px; height: 22px; background: var(--border); }
.topbar .tb-mod { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--muted); }
.topbar .tb-mod .ico { color: var(--accent); font-size: 15px; }
.topbar .tb-mod strong { color: var(--text); font-weight: 500; }
.topbar .tb-right { margin-left: auto; position: relative; }
.topbar .tb-user {
  display: flex; align-items: center; gap: 9px; background: none; border: 1px solid transparent;
  color: var(--text); padding: 5px 9px; border-radius: 6px; cursor: pointer; font-size: 13px; font-family: inherit;
}
.topbar .tb-user:hover { background: var(--panel-2); border-color: var(--border); }
.avatar {
  width: 26px; height: 26px; border-radius: 50%; background: var(--accent-soft); color: #8bb4f7;
  display: flex; align-items: center; justify-content: center; font-size: 11.5px; font-weight: 600;
}
.menu-pop {
  position: absolute; right: 0; top: 42px; width: 210px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 8px; padding: 6px; z-index: 40;
  box-shadow: 0 12px 30px rgba(0,0,0,.45);
}
.menu-pop .cab { padding: 10px 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.menu-pop .cab .nome { font-size: 13px; font-weight: 500; }
.menu-pop .cab .papel { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 2px; }
.menu-pop button {
  width: 100%; text-align: left; background: none; border: none; color: var(--muted);
  padding: 8px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; font-family: inherit;
}
.menu-pop button:hover { background: var(--panel-2); color: var(--text); }

/* --------------------------------------------------------------------------
   Home de módulos (launcher)
   -------------------------------------------------------------------------- */
.launcher { max-width: 1080px; margin: 0 auto; padding: calc(var(--topbar-h) + 34px) 24px 60px; }
.launcher .saudacao h2 { font-size: 24px; letter-spacing: -0.025em; }
.launcher .saudacao p { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.launcher .secao {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted);
  margin: 30px 0 12px; font-weight: 600;
}
.mod-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 13px; }
.mod-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px;
  padding: 18px 16px; cursor: pointer; text-align: left; color: var(--text);
  font-family: inherit; transition: border-color .12s, transform .12s, background .12s;
  display: flex; flex-direction: column; gap: 4px;
}
.mod-card:hover { border-color: var(--accent); transform: translateY(-2px); background: var(--panel-2); }
.mod-card .ico {
  width: 38px; height: 38px; border-radius: 9px; background: var(--accent-soft); color: #8bb4f7;
  display: flex; align-items: center; justify-content: center; font-size: 19px; margin-bottom: 10px;
}
.mod-card .nome { font-size: 14.5px; font-weight: 600; letter-spacing: -0.01em; }
.mod-card .desc { font-size: 12px; color: var(--muted); line-height: 1.45; }
.mod-card.desativado { opacity: .45; cursor: not-allowed; }
.mod-card.desativado:hover { border-color: var(--border); transform: none; background: var(--panel); }

/* --------------------------------------------------------------------------
   Layout de módulo: sidebar com o menu interno + área de conteúdo
   -------------------------------------------------------------------------- */
.layout { display: flex; min-height: 100vh; padding-top: var(--topbar-h); }
aside {
  width: var(--aside-w); background: var(--panel); border-right: 1px solid var(--border);
  position: fixed; top: var(--topbar-h); bottom: 0; display: flex; flex-direction: column;
}
aside .mod-cab { padding: 16px 18px 14px; border-bottom: 1px solid var(--border); }
aside .mod-cab .nome { font-size: 14.5px; font-weight: 600; letter-spacing: -0.01em; }
aside .mod-cab .desc { font-size: 11.5px; color: var(--muted); margin-top: 3px; line-height: 1.4; }
nav { padding: 10px 8px; flex: 1; overflow-y: auto; }
nav button {
  width: 100%; text-align: left; background: none; border: none; color: var(--muted);
  padding: 9px 12px; border-radius: 6px; cursor: pointer; font-size: 13.5px; font-family: inherit;
  display: flex; align-items: center; gap: 10px; margin-bottom: 2px;
}
nav button:hover { background: var(--panel-2); color: var(--text); }
nav button.active { background: var(--accent-soft); color: var(--text); }
nav button .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: .5; }
aside .voltar { border-top: 1px solid var(--border); padding: 10px 8px; }
aside .voltar button {
  width: 100%; text-align: left; background: none; border: none; color: var(--muted);
  padding: 8px 12px; border-radius: 6px; cursor: pointer; font-size: 12.5px; font-family: inherit;
}
aside .voltar button:hover { background: var(--panel-2); color: var(--text); }

main { margin-left: var(--aside-w); flex: 1; padding: 26px 30px; max-width: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; }
.page-head h2 { font-size: 22px; letter-spacing: -0.02em; }
.page-head p { color: var(--muted); font-size: 13px; margin-top: 3px; }

/* --------------------------------------------------------------------------
   Componentes compartilhados
   -------------------------------------------------------------------------- */
button.btn {
  background: var(--accent); color: #fff; border: none; padding: 9px 15px;
  border-radius: 6px; cursor: pointer; font-size: 13px; font-weight: 500; font-family: inherit;
}
button.btn:hover { filter: brightness(1.08); }
button.btn:disabled { opacity: .55; cursor: default; filter: none; }
button.btn.ghost { background: var(--panel-2); border: 1px solid var(--border); color: var(--text); }
button.btn.sm { padding: 5px 10px; font-size: 12px; }
button.btn.perigo { background: var(--danger); }

.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 22px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 600; margin-top: 6px; letter-spacing: -0.02em; }
.kpi .value.pos { color: var(--ok); }
.kpi .value.neg { color: var(--danger); }
.kpi .origem { font-size: 11px; color: var(--muted); margin-top: 6px; }

table { width: 100%; border-collapse: collapse; }
.card.table-card { padding: 0; overflow: hidden; }
thead th {
  text-align: left; color: var(--muted); font-size: 11.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .04em; padding: 12px 16px;
  border-bottom: 1px solid var(--border); background: var(--panel-2);
}
tbody td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { text-align: right; white-space: nowrap; }
tbody tr.total td { font-weight: 600; background: var(--panel-2); }
tbody tr.total td:first-child { color: var(--text); }
td.indent { padding-left: 32px; color: var(--muted); }

.badge { display: inline-block; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 500; }
.badge.gray { background: var(--panel-2); color: var(--muted); border: 1px solid var(--border); }
.badge.blue { background: var(--accent-soft); color: #8bb4f7; }
.badge.green { background: #12331c; color: #56d364; }
.badge.amber { background: #3a2f11; color: #e3b341; }
.badge.red { background: #3d1e17; color: #f0885f; }

/* Kanban (CRM) */
.kanban { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; }
.kb-col { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; min-height: 120px; }
.kb-col h4 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 4px; display: flex; justify-content: space-between; }
.kb-col .sum { font-size: 11px; color: var(--muted); margin-bottom: 10px; }
.kb-card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 10px; margin-bottom: 8px; cursor: grab; }
.kb-card:active { cursor: grabbing; }
.kb-card .t { font-size: 13px; font-weight: 500; margin-bottom: 4px; }
.kb-card .m { font-size: 11.5px; color: var(--muted); }
.kb-card .v { font-size: 12.5px; color: var(--ok); margin-top: 5px; font-variant-numeric: tabular-nums; }
.kb-col.drop { outline: 2px dashed var(--accent); outline-offset: -4px; }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 50; }
.modal { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; width: 520px; max-width: 92vw; max-height: 88vh; overflow-y: auto; }
.modal-head { padding: 18px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; }
.modal-foot { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 9px 11px; border-radius: 6px; font-size: 13.5px; font-family: inherit;
}
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.close-x { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; line-height: 1; }
.item-row { display: grid; grid-template-columns: 2fr 70px 90px auto; gap: 8px; align-items: end; margin-bottom: 8px; }
.item-row .rm { background: var(--panel-2); border: 1px solid var(--border); color: var(--danger); border-radius: 6px; cursor: pointer; padding: 8px 10px; }

/* Login */
.login-wrap { min-height: 100vh; width: 100%; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 360px; max-width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 30px 28px; }
.login-card h1 { font-size: 22px; letter-spacing: -0.02em; margin-bottom: 4px; }
.login-card h1 span { color: var(--accent); }
.login-card .sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }
.login-card button { width: 100%; margin-top: 4px; }
.login-erro { color: var(--danger); font-size: 12.5px; margin-bottom: 12px; min-height: 16px; }

/* Filtros / utilitários */
.filtros { display: flex; gap: 10px; align-items: end; margin-bottom: 18px; flex-wrap: wrap; }
.filtros .field { margin: 0; }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty p { margin-top: 6px; font-size: 13px; }
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--panel-2); border: 1px solid var(--border); padding: 12px 18px; border-radius: 8px; z-index: 100; border-left: 3px solid var(--accent); }
.link { color: var(--accent); cursor: pointer; }
.muted { color: var(--muted); }
.aviso {
  background: #3a2f11; border: 1px solid #5c4a1a; color: #e3b341;
  padding: 11px 14px; border-radius: 6px; font-size: 12.5px; margin-bottom: 18px; line-height: 1.5;
}

/* Lista de módulos em Configurações */
.mod-linha { display: flex; align-items: center; gap: 14px; }
.mod-linha .ico { width: 30px; height: 30px; border-radius: 7px; background: var(--accent-soft); color: #8bb4f7; display: flex; align-items: center; justify-content: center; font-size: 15px; }
.switch { position: relative; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.switch .tr { position: absolute; inset: 0; background: var(--panel-2); border: 1px solid var(--border); border-radius: 20px; pointer-events: none; transition: background .15s, border-color .15s; }
.switch .tr::after { content: ''; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: var(--muted); transition: transform .15s, background .15s; }
.switch input:checked + .tr { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + .tr::after { transform: translateX(18px); background: var(--accent); }
.switch input:disabled { cursor: not-allowed; }
.switch input:disabled + .tr { opacity: .4; }

@media (max-width: 760px) {
  :root { --aside-w: 60px; }
  aside .mod-cab, aside .voltar button span, nav button span { display: none; }
  aside .mod-cab { display: none; }
  main { padding: 18px; }
  .kanban { grid-template-columns: 1fr; }
  .topbar .tb-mod { display: none; }
}
