/* =============================================================================
   app.css — Design system do painel de inadimplência (v2)
   Tokens herdados de opp4s/sispap-painel (css/app.css) para o painel dos polos e
   este console parecerem o mesmo produto. O que é novo está marcado com OPS.
   Regras: sem gradiente decorativo, sem emoji como ícone, números tabulares.
   ========================================================================== */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* --- herdado do painel --- */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  --rail: #1b1c1f;
  --rail-hover: #2a2c31;
  --rail-active: #ffffff;
  --rail-icon: #9aa0a6;
  --rail-icon-active: #1b1c1f;
  --rail-h: 52px;

  --bg: #f4f4f5;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --border: #e6e6e8;
  --border-2: #dcdcdf;

  --text: #26272b;
  --text-2: #5c5f66;
  --text-3: #8b8e94;

  --accent: #068bff;
  --accent-soft: #e7f3ff;
  --danger: #e5484d;
  --success: #12a150;
  --warn: #b7791f;

  --r: 6px;
  --r-sm: 4px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow-pop: 0 8px 28px rgba(0, 0, 0, 0.14);
  --topbar-h: 52px;
  --subbar-h: 40px;
  --t: 140ms ease;

  /* --- OPS: semântica de operação --- */
  --ok-bg: #e6f6ec;
  --ok-fg: #0d7a3c;
  --warn-bg: #fdf3e2;
  --danger-bg: #fdecec;
  --neutral-bg: #eeeef0;
  --info-bg: var(--accent-soft);
  --info-fg: #0568c4;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font-sans); font-size: 14px; color: var(--text);
  background: var(--bg); -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; }
.hidden { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }
/* ícone tem tamanho por padrão; cada componente pode sobrescrever */
.ico { width: 16px; height: 16px; flex: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ============================== APP SHELL ================================ */
.app { display: grid; grid-template-columns: var(--rail-h) 1fr; min-height: 100dvh; }

.rail {
  position: sticky; top: 0; align-self: start; height: 100dvh; width: var(--rail-h); z-index: 50;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: var(--rail); padding: 10px 0; overflow: hidden;
  transition: width 160ms ease, box-shadow 160ms ease;
}
.rail:hover, .rail:focus-within {
  width: 238px; align-items: stretch; padding-left: 10px; padding-right: 10px;
  box-shadow: 6px 0 24px rgba(0, 0, 0, 0.3);
}
@media (min-width: 901px) {
  .rail:hover, .rail:focus-within { position: fixed; top: 0; left: 0; height: 100dvh; }
}
.rail-logo {
  width: 32px; height: 32px; border-radius: 8px; margin-bottom: 12px; flex: none;
  display: grid; place-items: center; color: #fff; background: #2a2c31;
}
.rail-logo svg { width: 18px; height: 18px; }
.rail:hover .rail-logo, .rail:focus-within .rail-logo { width: 100%; justify-content: flex-start; gap: 10px; }
.rail:hover .rail-logo::after {
  content: attr(data-brand); color: #fff; font-size: 13.5px; font-weight: 600; white-space: nowrap;
}
.rail-section {
  display: none; font-size: 10.5px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: rgba(255, 255, 255, 0.4);
  padding: 12px 10px 4px; white-space: nowrap;
}
.rail:hover .rail-section, .rail:focus-within .rail-section { display: block; }
.rail-item {
  width: 38px; height: 38px; border-radius: 8px; flex: none; cursor: pointer;
  display: flex; align-items: center; gap: 11px; padding: 0 10px;
  color: var(--rail-icon); background: transparent; border: 0;
  transition: background var(--t), color var(--t), width var(--t);
}
.rail:hover .rail-item, .rail:focus-within .rail-item { width: 100%; }
.rail-item svg { width: 19px; height: 19px; flex: none; }
.rail-item:hover { background: var(--rail-hover); color: #fff; }
.rail-item.active { background: var(--rail-active); color: var(--rail-icon-active); }
.rail-item .rail-label { display: none; font-size: 13px; font-weight: 500; white-space: nowrap; }
.rail:hover .rail-item .rail-label, .rail:focus-within .rail-item .rail-label { display: block; }
.rail-sep { width: 22px; height: 1px; background: rgba(255, 255, 255, 0.12); margin: 8px 0; flex: none; }
.rail-spacer { flex: 1; }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
  position: sticky; top: 0; z-index: 30; height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px; padding: 0 18px;
  background: var(--bg); border-bottom: 1px solid var(--border);
}
.topbar-title { font-size: 15px; font-weight: 600; }
.topbar-spacer { flex: 1; }
.topbar-meta { font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 6px; }
.topbar-meta b { color: var(--text-2); font-weight: 500; }

.iconbtn {
  display: grid; place-items: center; width: 34px; height: 34px; border-radius: var(--r);
  border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
}
.iconbtn:hover { background: rgba(0, 0, 0, 0.05); }
.iconbtn svg { width: 18px; height: 18px; }
.iconbtn.spin svg { animation: spin 900ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* subbar: estado do processo */
.subbar {
  height: var(--subbar-h); display: flex; align-items: center; gap: 12px; padding: 0 18px;
  background: var(--surface); border-bottom: 1px solid var(--border);
  font-size: 12.5px; color: var(--text-2); position: sticky; top: var(--topbar-h); z-index: 20;
  overflow-x: auto; white-space: nowrap;
}
.subbar .sep { width: 1px; height: 16px; background: var(--border-2); flex: none; }
.subbar .item { display: flex; align-items: center; gap: 6px; }
.subbar b { font-weight: 600; color: var(--text); }

.content { padding: 16px 18px 72px; }
.wrap { max-width: 1440px; margin: 0 auto; display: grid; gap: 12px; }

/* ============================== PAINÉIS ================================= */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-size: 13.5px; font-weight: 600; }
.panel-head .hint { font-size: 12px; color: var(--text-3); }
.panel-body { padding: 16px; }
.panel-body.tight { padding: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }

/* ============================== KPI STRIP =============================== */
.kpis { display: grid; grid-template-columns: repeat(6, 1fr); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--r); overflow: hidden; }
/* variante de 3 colunas (drawer do aluno); colapsa em tela estreita */
.kpis.k3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 640px) {
  .kpis.k3 { grid-template-columns: 1fr; }
  .kpis.k3 .kpi { border-right: 0; border-bottom: 1px solid var(--border); }
  .kpis.k3 .kpi:last-child { border-bottom: 0; }
}
.kpi { padding: 14px 16px; border-right: 1px solid var(--border); min-width: 0; }
.kpi:last-child { border-right: 0; }
.kpi .k-label { font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.k-label { font-size: 10.5px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.kpi .k-value { font-family: var(--font-mono); font-size: 23px; font-weight: 600; letter-spacing: -0.02em; margin-top: 5px; line-height: 1.15; }
.kpi .k-sub { font-size: 11.5px; color: var(--text-3); margin-top: 3px; display: flex; gap: 6px; align-items: center; }
.kpi .k-value.ok { color: var(--ok-fg); }
.kpi .k-value.warn { color: var(--warn); }
.kpi .k-value.bad { color: var(--danger); }

/* ============================== STAGE RAIL ============================== */
.stages { display: flex; align-items: stretch; gap: 0; overflow-x: auto; padding: 4px 0; }
.stage { flex: 1; min-width: 132px; padding: 10px 14px; position: relative; }
.stage + .stage { border-left: 1px solid var(--border); }
.stage .s-label { font-size: 11px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); }
.stage .s-value { font-family: var(--font-mono); font-size: 22px; font-weight: 600; margin-top: 4px; }
.stage .s-note { font-size: 11.5px; color: var(--text-3); margin-top: 2px; }
.stage .s-drop {
  position: absolute; top: 8px; right: 10px; font-size: 11px; font-weight: 600;
  color: var(--danger); background: var(--danger-bg); border-radius: 10px; padding: 1px 7px;
}
.stage .s-drop.neutral { color: var(--text-2); background: var(--neutral-bg); }

/* ============================== TABELA DENSA ============================ */
.table-wrap { overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table th {
  position: sticky; top: 0; z-index: 1; background: var(--surface);
  text-align: left; padding: 9px 14px; font-size: 10.5px; font-weight: 600;
  letter-spacing: .05em; text-transform: uppercase; color: var(--text-3);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td { padding: 9px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr.clickable { cursor: pointer; }
.table .r { text-align: right; font-variant-numeric: tabular-nums; }
.table .name { font-weight: 500; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table .sub { color: var(--text-3); font-size: 11.5px; }

/* ============================== PILLS =================================== */
.pill {
  display: inline-flex; align-items: center; gap: 5px; height: 21px; padding: 0 8px;
  border-radius: var(--r-sm); font-size: 11.5px; font-weight: 500; white-space: nowrap;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.pill.ok { background: var(--ok-bg); color: var(--ok-fg); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.bad { background: var(--danger-bg); color: var(--danger); }
.pill.info { background: var(--info-bg); color: var(--info-fg); }
.pill.neutral { background: var(--neutral-bg); color: var(--text-2); }

/* ============================== ESTADO ================================== */
.banner {
  display: flex; align-items: center; gap: 10px; padding: 11px 14px;
  border-radius: var(--r); border: 1px solid; font-size: 13px;
}
.banner svg { width: 16px; height: 16px; flex: none; }
.banner.ok { background: var(--ok-bg); border-color: #c9eed7; color: var(--ok-fg); }
.banner.warn { background: var(--warn-bg); border-color: #f2e2c4; color: var(--warn); }
.banner.bad { background: var(--danger-bg); border-color: #f6d0d2; color: #b3261e; }
.banner .grow { flex: 1; }
.banner button { border: 0; background: transparent; color: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; }

.empty { display: grid; place-items: center; text-align: center; gap: 6px; padding: 44px 24px; color: var(--text-3); }
.empty h3 { font-size: 14.5px; font-weight: 600; color: var(--text); }
.empty p { font-size: 12.5px; max-width: 46ch; }
.empty .ei { width: 42px; height: 42px; border-radius: 50%; background: var(--neutral-bg); display: grid; place-items: center; margin-bottom: 4px; }
.empty .ei svg { width: 20px; height: 20px; }

.skeleton { background: linear-gradient(90deg, #ececed 25%, #f5f5f6 37%, #ececed 63%);
  background-size: 400% 100%; animation: sh 1.3s ease infinite; border-radius: var(--r); }
@keyframes sh { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
.sk-row { height: 34px; margin: 6px 14px; }

/* ============================== CADENCE PLOT ============================ */
.cad { display: grid; gap: 8px; }
.cad-row { display: grid; grid-template-columns: 132px 1fr 116px; gap: 12px; align-items: center; }
.cad-id { font-family: var(--font-mono); font-size: 11.5px; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; }
.cad-track { position: relative; height: 30px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); }
.cad-track .ref { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--border-2); }
.cad-track .ref.at70 { background: #e5a3a5; }
.cad-track .ref.at240 { background: #9ccdb2; }
.cad-track .dot { position: absolute; top: 50%; width: 7px; height: 7px; margin: -3.5px 0 0 -3.5px; border-radius: 50%; background: var(--accent); }
.cad-track .dot.bad { background: var(--danger); }
.cad-legend { display: flex; gap: 14px; font-size: 11px; color: var(--text-3); }
.cad-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.cad-stats { font-size: 11.5px; color: var(--text-2); text-align: right; font-variant-numeric: tabular-nums; }

/* ============================== DRAWER ================================== */
.drawer-scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 70; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(560px, 100%); z-index: 71;
  background: var(--surface); display: flex; flex-direction: column; box-shadow: var(--shadow-pop);
}
.drawer-head { padding: 14px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: flex-start; gap: 12px; }
.drawer-head .grow { flex: 1; min-width: 0; }
.drawer-head h2 { font-size: 15px; font-weight: 600; }
.drawer-head .d-sub { font-size: 12px; color: var(--text-3); margin-top: 2px; }
.drawer-body { padding: 16px 18px 28px; overflow-y: auto; flex: 1; display: grid; gap: 14px; align-content: start; }
.drawer-foot { padding: 12px 18px; border-top: 1px solid var(--border); }

.defs { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; font-size: 12.5px; align-items: baseline; }
.defs dt { color: var(--text-3); white-space: nowrap; }
.defs dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ============================== FORM / BOTÕES =========================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 32px; padding: 0 12px; border-radius: var(--r); font-size: 12.5px; font-weight: 500;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap; transition: var(--t);
}
.btn:hover { background: var(--surface-2); }
.btn svg { width: 15px; height: 15px; }
.btn-sm { height: 28px; padding: 0 9px; font-size: 12px; }
.input, select.input {
  height: 32px; padding: 0 10px; border: 1px solid var(--border-2); border-radius: var(--r);
  background: var(--surface); font-size: 12.5px; color: var(--text); min-width: 0;
}
.input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.filters .grow { flex: 1; }
.filters .search { position: relative; min-width: 220px; flex: 1; }
.filters .search svg { position: absolute; left: 9px; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--text-3); }
.filters .search input { width: 100%; padding-left: 30px; }

.hbars { display: grid; gap: 7px; }
.hbar { display: grid; grid-template-columns: 190px 1fr 52px; gap: 10px; align-items: center; font-size: 12.5px; }
.hbar .b { height: 18px; border-radius: 3px; background: var(--accent-soft); position: relative; overflow: hidden; }
.hbar .b i { position: absolute; inset: 0 auto 0 0; background: var(--accent); border-radius: 3px; }
.hbar .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--text-2); }
.hbar .lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-2); }

/* sparkline (histórico) */
.spark { display: flex; align-items: flex-end; gap: 3px; height: 84px; border-bottom: 1px solid var(--border); padding-bottom: 1px; }
.spark .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 2px; height: 100%; min-width: 0; }
.spark .bar { width: 100%; background: var(--accent); border-radius: 2px 2px 0 0; }
.spark .bar.wa { background: #7cc0f5; }
.spark .bar.zero { background: #e2e3e5; }

.menu-toggle { display: none !important; }
@media (prefers-reduced-motion: reduce) { * { animation-duration: .001ms !important; transition-duration: .001ms !important; } }

@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .kpi:nth-child(3n) { border-right: 0; }
  .kpi:nth-child(-n+3) { border-bottom: 1px solid var(--border); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .rail { position: fixed; left: 0; top: 0; transform: translateX(-100%); }
  .rail.open { transform: none; width: 238px; align-items: stretch; padding: 10px; }
  .rail.open .rail-label, .rail.open .rail-section { display: block; }
  .rail.open .rail-item { width: 100%; }
  .menu-toggle { display: grid !important; }
  .topbar-meta { display: none; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .cad-row { grid-template-columns: 108px 1fr; }
  .cad-row .cad-stats { grid-column: 2; text-align: left; }
}
@media (max-width: 640px) {
  .content { padding: 12px 12px 60px; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .table th:nth-child(n+5), .table td:nth-child(n+5) { display: none; }
}
