/* Dugraf Analytics v2 */

:root {
  --navy: #0f4070;
  --deep: #082a4d;
  --deeper: #061e38;
  --paper: #f3f5f8;
  --surface: #ffffff;
  --ink: #14202f;
  --muted: #586b80;
  --line: #dce2ea;
  --amber: #f6a21a;
  --danger: #b3261e;
  --danger-bg: #fcecea;
  --ok: #17703f;
  --ok-bg: #e7f5ed;
  --info: #0f4070;
  --info-bg: #e8f0f9;
  --focus: #1b6fd1;
  --rail-w: 264px;
  --topbar-h: 56px;
  /* Altura da barra inferior do Power BI que fica recortada (mantém o link direto fora do alcance). */
  --pbi-footer: 36px;
  --r-sm: 8px;
  --r-md: 12px;
  --font: "Barlow", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "Barlow Semi Condensed", "Barlow", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 400 1rem/1.5 var(--font);
  color: var(--ink);
  background: var(--paper);
}
img { max-width: 100%; height: auto; }
a { color: var(--navy); }
h1, h2, h3, p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.skip {
  position: absolute; left: 8px; top: -48px; z-index: 100;
  background: var(--surface); color: var(--ink); padding: 8px 14px; border-radius: var(--r-sm);
  transition: top .15s;
}
.skip:focus { top: 8px; }

/* ---------- Botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px;
  font: 600 .95rem/1 var(--font); text-decoration: none; cursor: pointer;
  border: 1px solid transparent; border-radius: var(--r-sm);
  transition: background-color .15s, border-color .15s, color .15s;
}
.btn-sm { min-height: 36px; padding: 0 12px; font-size: .875rem; }
.btn-block { width: 100%; }
.btn-primary { background: var(--navy); color: #fff; }
.btn-primary:hover { background: var(--deep); }
.btn-secondary { background: var(--surface); color: var(--navy); border-color: #b9c5d3; }
.btn-secondary:hover { background: var(--info-bg); border-color: var(--navy); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #8f1d17; }
.btn-danger-quiet { background: transparent; color: var(--danger); border-color: transparent; }
.btn-danger-quiet:hover { background: var(--danger-bg); }
.btn-ghost { background: rgba(255,255,255,.08); color: #fff; border-color: rgba(255,255,255,.22); }
.btn-ghost:hover { background: rgba(255,255,255,.16); }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.icon-btn {
  display: inline-grid; place-items: center; width: 44px; height: 44px; padding: 0;
  background: transparent; color: inherit; border: 0; border-radius: var(--r-sm); cursor: pointer;
}
.icon-btn:hover { background: rgba(127,150,180,.18); }

/* ---------- Avisos ---------- */
.notice {
  padding: 12px 14px; border-radius: var(--r-sm); border-left: 4px solid; font-size: .95rem; margin-bottom: 16px;
}
.notice-error { background: var(--danger-bg); border-color: var(--danger); color: #6b1510; }
.notice-success { background: var(--ok-bg); border-color: var(--ok); color: #0d4a29; }
.notice-info { background: var(--info-bg); border-color: var(--info); color: #0a2f52; }

/* ---------- Formulários ---------- */
.form { display: grid; gap: 18px; }
.form-narrow { max-width: 420px; }
.field { display: grid; gap: 6px; align-content: start; }
.field label { font-weight: 600; font-size: .925rem; }
.field input, .field select {
  width: 100%; min-height: 46px; padding: 0 14px;
  font: inherit; color: var(--ink); background: var(--surface);
  border: 1px solid #aebbc9; border-radius: var(--r-sm);
}
.field input:hover, .field select:hover { border-color: var(--navy); }
.field input:focus-visible, .field select:focus-visible { outline: 3px solid var(--focus); outline-offset: 1px; border-color: var(--focus); }
.field.has-error input, .field.has-error select { border-color: var(--danger); background: #fffafa; }
.hint { color: var(--muted); font-size: .875rem; }
.error { color: var(--danger); font-size: .875rem; font-weight: 500; }
.input-wrap { position: relative; }
.input-wrap input { padding-right: 84px; }
.reveal {
  position: absolute; right: 6px; top: 6px; bottom: 6px; padding: 0 12px;
  font: 600 .85rem var(--font); color: var(--navy); background: transparent; border: 0; border-radius: 6px; cursor: pointer;
}
.reveal:hover { background: var(--info-bg); }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; padding-top: 4px; }
.grid-2 { display: grid; gap: 18px; grid-template-columns: repeat(2, minmax(0, 1fr)); }

.meter { margin-top: -6px; display: grid; gap: 6px; }
.meter-bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; }
.meter-bar span { display: block; height: 100%; width: 0; background: var(--danger); transition: width .2s, background-color .2s; }
.meter[data-level="1"] .meter-bar span { width: 25%; background: var(--danger); }
.meter[data-level="2"] .meter-bar span { width: 50%; background: #c77700; }
.meter[data-level="3"] .meter-bar span { width: 75%; background: #3f8f4f; }
.meter[data-level="4"] .meter-bar span { width: 100%; background: var(--ok); }
.meter-text { font-size: .875rem; color: var(--muted); }

/* ---------- Telas sem login ---------- */
body.auth { background: var(--surface); }
.auth-shell { min-height: 100dvh; display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); }
.auth-brand {
  position: relative; isolation: isolate; color: #fff;
  display: flex; flex-direction: column; justify-content: space-between; gap: 40px;
  padding: clamp(28px, 5vw, 64px);
  background:
    linear-gradient(160deg, rgba(8,42,77,.94) 20%, rgba(6,30,56,.78) 100%),
    url("../img/fundo.jpg") center / cover no-repeat;
  background-color: var(--deep);
}
.auth-logo { width: min(260px, 70%); height: auto; }
.auth-claim { max-width: 26rem; }
.auth-claim-title { font: italic 700 clamp(2rem, 3.4vw, 2.9rem)/1.05 var(--font-display); letter-spacing: -.01em; }
.auth-claim-text { margin-top: 14px; color: #d5e0ee; font-size: 1.05rem; max-width: 24rem; }
.auth-credit { font-size: .85rem; color: #b7c7da; }
.auth-credit a { color: #fff; }
.auth-panel { display: grid; place-items: center; padding: clamp(24px, 5vw, 64px); }
.auth-card { width: 100%; max-width: 400px; }
.auth-logo-mobile { display: none; margin-bottom: 28px; }
.auth-title { font: italic 700 2rem/1.1 var(--font-display); color: var(--deep); }
.auth-sub { margin: 8px 0 22px; color: var(--muted); }
.auth-links { margin-top: 22px; text-align: center; }
.auth-links .btn { text-decoration: none; }

/* ---------- Estrutura do portal ---------- */
.shell { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100dvh; }
.rail {
  position: sticky; top: 0; height: 100dvh; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column;
  background: var(--deep); color: #d5e0ee;
}
.rail-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 18px 8px 22px; }
.rail-brand { display: block; line-height: 0; }
.rail-brand img { width: 150px; height: auto; }
.rail-close { display: none; color: #fff; }
.rail-nav { flex: 1; padding: 14px 12px 12px; }
.rail-title { margin: 18px 10px 6px; font-size: .85rem; font-weight: 600; color: #8fa6c0; }
.rail-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.rail-link {
  position: relative; display: block; padding: 10px 12px 10px 14px; border-radius: var(--r-sm);
  color: #d5e0ee; text-decoration: none; font-weight: 500; line-height: 1.25;
}
.rail-link:hover { background: rgba(255,255,255,.08); color: #fff; }
.rail-link.is-active { background: rgba(255,255,255,.13); color: #fff; font-weight: 600; }
.rail-link.is-active::before {
  content: ""; position: absolute; left: 0; top: 8px; bottom: 8px; width: 4px; border-radius: 2px; background: var(--amber);
}
.rail-link:focus-visible { outline-color: #fff; }
.rail-empty { margin: 4px 10px; color: #9db1c8; font-size: .925rem; }
.rail-foot { padding: 12px; border-top: 1px solid rgba(255,255,255,.12); display: grid; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 4px 4px 6px; }
.avatar {
  flex: none; width: 36px; height: 36px; display: grid; place-items: center; border-radius: 50%;
  background: #fff; color: var(--navy); font: italic 700 1.1rem var(--font-display);
}
.user-meta { min-width: 0; flex: 1; display: grid; line-height: 1.25; }
.user-name { color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-sub { color: #9db1c8; font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip .icon-btn { color: #d5e0ee; }
.user-chip .icon-btn:hover { background: rgba(255,255,255,.12); color: #fff; }
.scrim { display: none; }

.main-col { display: flex; flex-direction: column; min-width: 0; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px; min-height: var(--topbar-h); padding: 6px 16px 6px 20px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.menu-btn { display: none; margin-left: -10px; }
.topbar-title { font: italic 700 1.4rem/1.1 var(--font-display); color: var(--deep); flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.page { padding: 24px clamp(16px, 3vw, 32px) 48px; max-width: 1180px; width: 100%; }
.stack { display: grid; gap: 20px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: clamp(18px, 3vw, 28px); }
.panel-title { font: italic 700 1.3rem/1.2 var(--font-display); color: var(--deep); margin-bottom: 16px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px 24px; margin: 0 0 16px; }
.facts dt { color: var(--muted); font-size: .875rem; }
.facts dd { margin: 2px 0 0; font-weight: 500; overflow-wrap: anywhere; }

/* ---------- Relatório (Power BI) ---------- */
body.app-canvas .shell { height: 100dvh; min-height: 0; }
body.app-canvas .main-col { height: 100dvh; min-height: 0; }
.canvas { flex: 1; min-height: 0; display: flex; flex-direction: column; background: var(--deeper); }
.canvas > .notice { margin: 12px 16px 0; }
.stage { position: relative; flex: 1; min-height: 0; overflow: hidden; background: var(--surface); }
/* O iframe é maior que a janela: a faixa inferior do Power BI (zoom, link do Power BI) fica fora da área visível. */
.stage iframe {
  position: absolute; inset: 0 auto auto 0; width: 100%;
  height: calc(100% + var(--pbi-footer)); border: 0; background: var(--surface);
}
.stage:fullscreen { background: var(--surface); }
.loader {
  position: absolute; inset: 0; z-index: 1; display: none; place-items: center; align-content: center; gap: 12px;
  background: var(--surface); color: var(--muted);
}
.stage.is-loading .loader { display: grid; }
.loader-dot { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--navy); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty { margin: auto; padding: 32px; text-align: center; max-width: 28rem; color: #d5e0ee; }
.empty h2 { font: italic 700 1.6rem var(--font-display); color: #fff; margin-bottom: 8px; }

/* ---------- Tabelas ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.search { flex: 1 1 280px; max-width: 460px; }
.search input {
  width: 100%; min-height: 44px; padding: 0 14px; font: inherit; background: var(--surface);
  border: 1px solid #aebbc9; border-radius: var(--r-sm);
}
.count { color: var(--muted); font-size: .9rem; }
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: .95rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .875rem; padding: 12px 16px; background: #f8fafc; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #f8fafc; }
.col-actions { text-align: right; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.row-actions form { margin: 0; }
.badge { display: inline-block; padding: 2px 8px; font-size: .8rem; font-weight: 600; border-radius: 99px; background: var(--info-bg); color: var(--info); }
.badge-admin { background: #fff1d6; color: #7a4b00; }
.badge-warn { background: var(--danger-bg); color: var(--danger); }
.empty-row { padding: 28px; text-align: center; color: var(--muted); }

/* ---------- Filtros e resumo (Acessos) ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab {
  position: relative; padding: 12px 16px; white-space: nowrap; text-decoration: none; color: var(--muted); font-weight: 500;
  border-radius: var(--r-sm) var(--r-sm) 0 0;
}
.tab:hover { color: var(--deep); background: var(--info-bg); }
.tab.is-active { color: var(--deep); font-weight: 600; }
.tab.is-active::after { content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 3px; border-radius: 2px; background: var(--amber); }
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; align-items: end; margin-bottom: 20px; }
.top-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.top-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; }
.top-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-n { font-weight: 600; color: var(--deep); }
.top-bar { grid-column: 1 / -1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.top-bar span { display: block; height: 100%; background: var(--navy); }
.top-bar .w0 { width: 0; } .top-bar .w10 { width: 10%; } .top-bar .w20 { width: 20%; } .top-bar .w30 { width: 30%; }
.top-bar .w40 { width: 40%; } .top-bar .w50 { width: 50%; } .top-bar .w60 { width: 60%; } .top-bar .w70 { width: 70%; }
.top-bar .w80 { width: 80%; } .top-bar .w90 { width: 90%; } .top-bar .w100 { width: 100%; }

/* ---------- Diálogo de confirmação ---------- */
.dialog { border: 0; border-radius: var(--r-md); padding: 24px; width: min(440px, calc(100vw - 32px)); color: var(--ink); box-shadow: 0 20px 60px rgba(8,42,77,.35); }
.dialog::backdrop { background: rgba(6,30,56,.55); }
.dialog-title { font: italic 700 1.4rem var(--font-display); color: var(--deep); }
.dialog-body { margin: 10px 0 22px; color: var(--ink); }
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------- Offline ---------- */
.netbar {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 60;
  max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: 99px;
  background: var(--ink); color: #fff; font-size: .9rem; box-shadow: 0 6px 24px rgba(0,0,0,.3);
}
.offline-page { min-height: 100dvh; display: grid; place-items: center; padding: 24px; text-align: center; background: var(--deep); color: #fff; }
.offline-page img { width: 200px; margin-bottom: 24px; }
.offline-page h1 { font: italic 700 2rem var(--font-display); }
.offline-page p { margin: 10px 0 22px; color: #d5e0ee; }

/* ---------- Responsivo ---------- */
@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: fixed; z-index: 50; inset: 0 auto 0 0; width: min(310px, 86vw);
    transform: translateX(-102%); visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
  }
  .rail.is-open { transform: none; visibility: visible; transition: transform .22s ease; }
  .rail-close, .menu-btn { display: inline-grid; }
  .scrim.is-open { display: block; position: fixed; inset: 0; z-index: 40; background: rgba(6,30,56,.55); }
  .topbar { padding-left: 14px; }
  .topbar-title { font-size: 1.2rem; }
}

@media (max-width: 760px) {
  .auth-shell { grid-template-columns: minmax(0, 1fr); }
  .auth-brand { display: none; }
  .auth-logo-mobile { display: block; }
  .auth-panel { align-items: start; padding-top: 40px; }
  .grid-2 { grid-template-columns: minmax(0, 1fr); }

  .table-wrap { border: 0; background: transparent; overflow: visible; }
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); padding: 6px 0; margin-bottom: 12px; }
  .table td { display: flex; gap: 12px; justify-content: space-between; align-items: baseline; border: 0; padding: 7px 16px; text-align: right; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .85rem; text-align: left; flex: none; }
  .table td.col-actions { display: block; text-align: left; padding-top: 10px; }
  .table td.col-actions::before { display: none; }
  .row-actions { justify-content: flex-start; }
  .topbar-actions .btn-secondary { padding: 0 10px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
