/* ==========================================================================
   Plataforma BSC · Norporgest Consultores
   Design system: norporgest.pt (dark · rounded · flat · Poppins)
   ========================================================================== */

:root {
  --primary: #CC1A1A;
  --primary-hover: #B01414;
  --accent: #0078A8;
  --surface: #181818;
  --elevated: #2A2A2A;
  --elevated-2: #333333;
  --text: #ECEBEB;
  --text-secondary: #B8B6B6;
  --text-muted: #8A8888;
  --border: #3D3D3D;

  /* série de dados (validada p/ contraste e CVD sobre --elevated) */
  --dv-planeado: #1F8FBE;
  --dv-realizado: #D94A45;

  /* estados (escala de sucesso) */
  --st-critico: #E0574A;
  --st-serio: #E08A3C;
  --st-medio: #E5C04B;
  --st-bom: #9BBF5A;
  --st-excelente: #4CAF6E;

  --r-card: 12px;
  --r-input: 10px;
  --r-pill: 999px;

  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 20px; --s6: 28px; --s7: 40px; --s8: 44px;

  --font: 'Poppins', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--surface);
  color: var(--text);
  line-height: 1.9;
  min-height: 100vh;
}

h1, h2, h3, h4 { font-weight: 600; line-height: 1.2; }
h1 { font-size: 2.1rem; letter-spacing: -1px; }
h2 { font-size: 1.5rem; letter-spacing: -0.5px; }
h3 { font-size: 1.05rem; }
h4 { font-size: 0.85rem; text-transform: uppercase; letter-spacing: 1.5px; color: var(--text-secondary); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

img { max-width: 100%; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s2);
  font-family: var(--font);
  font-size: 0.95rem;
  font-weight: 600;
  color: #fff;
  background: var(--primary);
  border: none;
  border-radius: var(--r-pill);
  padding: var(--s3) var(--s6);
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn:hover { background: var(--primary-hover); }
.btn:active { transform: scale(0.98); }
.btn-block { width: 100%; }
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--elevated-2); color: var(--text); }

/* ---------- Inputs ---------- */
.field { margin-bottom: var(--s4); }
.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: var(--s1);
}
.field input {
  width: 100%;
  font-family: var(--font);
  font-size: 0.95rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  padding: 13px 16px;
  outline: none;
  transition: border-color 0.2s;
}
.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: var(--text-muted); }

/* ==========================================================================
   LOGIN / LANDING
   ========================================================================== */
.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.15fr 1fr;
}

.login-brand {
  background: linear-gradient(160deg, #1E1E1E 0%, #181818 60%, #201414 100%);
  padding: var(--s8) var(--s7);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid var(--border);
}

.logo-chip {
  background: #fff;
  border-radius: var(--r-card);
  padding: var(--s3) var(--s5);
  display: inline-block;
  width: fit-content;
}
.logo-chip img { height: 52px; display: block; }

.login-brand .brand-body { margin-top: var(--s7); max-width: 560px; }
.login-brand .eyebrow {
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 2px;
  margin-bottom: var(--s3);
}
.login-brand h1 { margin-bottom: var(--s4); }
.login-brand h1 .accent { color: var(--primary); }
.login-brand p.lead {
  color: var(--text-secondary);
  font-size: 0.95rem;
  margin-bottom: var(--s6);
}

.persp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s3);
  margin-bottom: var(--s6);
}
.persp-item {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--s3) var(--s4);
  font-size: 0.85rem;
  line-height: 1.5;
}
.persp-item .dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: var(--s2);
}
.persp-item strong { display: block; font-size: 0.85rem; }
.persp-item span { color: var(--text-muted); font-size: 0.78rem; }

.brand-foot {
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.7;
  border-top: 1px solid var(--border);
  padding-top: var(--s4);
  margin-top: var(--s6);
}
.brand-foot strong { color: var(--text-secondary); }

.login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--s7);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--s7) var(--s6);
}
.login-card h2 { margin-bottom: var(--s1); }
.login-card .sub { color: var(--text-muted); font-size: 0.85rem; margin-bottom: var(--s6); line-height: 1.5; }
.login-error {
  display: none;
  background: rgba(204, 26, 26, 0.12);
  border: 1px solid rgba(204, 26, 26, 0.45);
  color: #F0A9A9;
  border-radius: var(--r-input);
  font-size: 0.82rem;
  line-height: 1.5;
  padding: var(--s2) var(--s3);
  margin-bottom: var(--s4);
}
.login-error.show { display: block; }
.login-note {
  margin-top: var(--s5);
  color: var(--text-muted);
  font-size: 0.75rem;
  line-height: 1.6;
  text-align: center;
}

/* ==========================================================================
   APP SHELL
   ========================================================================== */
.app { display: none; min-height: 100vh; }
.app.active { display: grid; grid-template-columns: 264px 1fr; }
.login-wrap.hidden { display: none; }

.sidebar {
  background: #1E1E1E;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: var(--s5) var(--s4);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .logo-chip { margin-bottom: var(--s6); padding: var(--s2) var(--s4); }
.sidebar .logo-chip img { height: 36px; }

.nav { flex: 1; display: flex; flex-direction: column; gap: var(--s1); }
.nav-label {
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-muted);
  padding: var(--s2) var(--s3);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: var(--s3);
  font-family: var(--font);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  border-radius: var(--r-input);
  padding: var(--s2) var(--s3);
  cursor: pointer;
  text-align: left;
  line-height: 1.4;
  transition: background 0.15s, color 0.15s;
}
.nav-item:hover { background: var(--elevated); color: var(--text); }
.nav-item.active {
  background: var(--primary);
  color: #fff;
  font-weight: 600;
}
.nav-item .ico { width: 18px; text-align: center; flex-shrink: 0; }

.sidebar-user {
  border-top: 1px solid var(--border);
  padding-top: var(--s4);
  margin-top: var(--s4);
  font-size: 0.78rem;
  line-height: 1.5;
}
.sidebar-user .who { color: var(--text-secondary); word-break: break-all; }
.sidebar-user .tag {
  display: inline-block;
  background: var(--elevated-2);
  color: var(--text-muted);
  border-radius: var(--r-pill);
  font-size: 0.68rem;
  padding: 2px 10px;
  margin: var(--s1) 0 var(--s2);
}
.sidebar-user .btn-ghost { width: 100%; padding: var(--s2) var(--s4); font-size: 0.8rem; }

.main { padding: var(--s7); max-width: 1220px; width: 100%; }
.page { display: none; }
.page.active { display: block; animation: fadein 0.25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.page-head { margin-bottom: var(--s6); }
.page-head .crumb {
  color: var(--text-muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  margin-bottom: var(--s1);
}
.page-head p.desc { color: var(--text-secondary); font-size: 0.9rem; max-width: 760px; line-height: 1.7; }

/* ---------- Cartões ---------- */
.card {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--s5) var(--s6);
  margin-bottom: var(--s5);
}
.card h3 { margin-bottom: var(--s3); }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s5); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s4); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s4); }

/* ---------- Stat tiles ---------- */
.stat {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-card);
  padding: var(--s4) var(--s5);
}
.stat .label { font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); line-height: 1.4; }
.stat .value { font-size: 1.9rem; font-weight: 600; line-height: 1.3; letter-spacing: -0.5px; }
.stat .hint { font-size: 0.75rem; color: var(--text-secondary); line-height: 1.4; }
.stat.hero { border-left: 4px solid var(--primary); }
.stat.hero .value { font-size: 2.6rem; }

/* ---------- Tabelas ---------- */
.table-scroll { overflow-x: auto; border-radius: var(--r-card); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; background: var(--elevated); }
thead th {
  background: var(--elevated-2);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  text-align: left;
  padding: var(--s3) var(--s4);
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
tbody td {
  padding: var(--s2) var(--s4);
  border-bottom: 1px solid var(--border);
  color: var(--text);
  line-height: 1.5;
  vertical-align: top;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255,255,255,0.02); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
td.muted { color: var(--text-muted); }
tr.row-group td {
  background: #242424;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ---------- Chips de estado ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: var(--r-pill);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 2px 12px;
  white-space: nowrap;
  line-height: 1.6;
}
.chip::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip-ok { background: rgba(76,175,110,0.14); color: var(--st-excelente); }
.chip-warn { background: rgba(229,192,75,0.12); color: var(--st-medio); }
.chip-bad { background: rgba(224,87,74,0.13); color: var(--st-critico); }
.chip-info { background: rgba(31,143,190,0.14); color: #55AFD6; }
.chip-neutral { background: var(--elevated-2); color: var(--text-secondary); }

/* ---------- Barras de progresso (grau de concretização) ---------- */
.meter { display: flex; align-items: center; gap: var(--s3); }
.meter .track {
  flex: 1;
  height: 10px;
  background: var(--surface);
  border-radius: var(--r-pill);
  overflow: hidden;
  min-width: 90px;
}
.meter .fill { height: 100%; border-radius: var(--r-pill); }
.meter .pct { font-size: 0.8rem; font-weight: 600; min-width: 52px; text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- Gráficos de barras (mensal) ---------- */
.chart-card { padding: var(--s4) var(--s5); }
.chart-card .chart-title { font-size: 0.9rem; font-weight: 600; line-height: 1.4; margin-bottom: 2px; }
.chart-card .chart-sub { font-size: 0.72rem; color: var(--text-muted); margin-bottom: var(--s3); line-height: 1.4; }
.legend { display: flex; gap: var(--s4); font-size: 0.72rem; color: var(--text-secondary); margin-bottom: var(--s3); flex-wrap: wrap; }
.legend .key { display: inline-flex; align-items: center; gap: 6px; }
.legend .swatch { width: 10px; height: 10px; border-radius: 3px; }

.bars {
  display: flex;
  align-items: flex-end;
  gap: var(--s3);
  height: 150px;
  padding-top: var(--s4);
  border-bottom: 1px solid var(--border);
}
.bars.has-neg { border-bottom: none; }
.bar-month { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; min-width: 0; }
.bar-pair { display: flex; align-items: flex-end; gap: 2px; width: 100%; justify-content: center; height: 100%; }
.bar {
  width: 12px;
  max-width: 45%;
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  position: relative;
  cursor: default;
}
.bar.planeado { background: var(--dv-planeado); }
.bar.realizado { background: var(--dv-realizado); }
.bar.neg { border-radius: 0 0 4px 4px; }
.bar-labels { display: flex; gap: var(--s3); margin-top: var(--s2); }
.month-lbl { font-size: 0.68rem; color: var(--text-muted); text-align: center; margin-top: var(--s1); }

/* tooltip */
#dv-tip {
  position: fixed;
  z-index: 99;
  background: #0F0F0F;
  border: 1px solid var(--border);
  border-radius: var(--r-input);
  color: var(--text);
  font-size: 0.75rem;
  line-height: 1.6;
  padding: var(--s2) var(--s3);
  pointer-events: none;
  display: none;
  max-width: 260px;
}
#dv-tip .t-title { font-weight: 600; }
#dv-tip .t-row { display: flex; align-items: center; gap: 6px; color: var(--text-secondary); }
#dv-tip .t-row .swatch { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }

/* ---------- Escala de cores (legenda da folha de metas) ---------- */
.scale-row { display: flex; align-items: flex-start; gap: var(--s3); padding: var(--s2) 0; border-bottom: 1px solid var(--border); font-size: 0.82rem; }
.scale-row:last-child { border-bottom: none; }
.scale-row .band {
  min-width: 90px;
  text-align: center;
  border-radius: var(--r-pill);
  font-weight: 600;
  font-size: 0.75rem;
  color: #14140F;
  padding: 2px 10px;
  flex-shrink: 0;
}
.scale-row p { color: var(--text-secondary); line-height: 1.6; }

/* ---------- Introdução: instruções ---------- */
.howto { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
.howto .item {
  background: var(--elevated);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-card);
  padding: var(--s4) var(--s5);
}
.howto .item strong { display: block; margin-bottom: 2px; font-size: 0.9rem; }
.howto .item span { color: var(--text-secondary); font-size: 0.82rem; line-height: 1.6; }

.readonly-banner {
  display: flex;
  align-items: center;
  gap: var(--s3);
  background: rgba(31,143,190,0.08);
  border: 1px solid rgba(31,143,190,0.35);
  border-radius: var(--r-card);
  color: #7EC3E0;
  font-size: 0.8rem;
  line-height: 1.5;
  padding: var(--s3) var(--s5);
  margin-bottom: var(--s6);
}

/* ---------- Responsivo ---------- */
@media (max-width: 1080px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-brand { border-right: none; border-bottom: 1px solid var(--border); }
  .app.active { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .main { padding: var(--s5); }
  .grid-2, .howto, .persp-grid { grid-template-columns: 1fr; }
}
