/*
  --ink e --accent são a cor primária e a cor de destaque da marca.
  Os valores abaixo são o padrão; o public/js/branding.js sobrescreve essas
  duas variáveis em tempo real com o que o administrador definir em
  Configurações > Marca, calculando --accent-soft automaticamente.
*/
:root {
  --ink: #14213d;
  --ink-soft: #4a5a7a;
  --paper: #f7f8fb;
  --card: #ffffff;
  --line: #e2e6ef;
  --accent: #2d6a4f;
  --accent-soft: #e8f3ee;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --radius: 10px;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Inter", "Segoe UI", -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Tela de login ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
}

/* Painel esquerdo: marca em destaque, usa as cores dinâmicas da empresa */
.login-brand-panel {
  flex: 1.1;
  background: linear-gradient(155deg, var(--ink) 0%, color-mix(in srgb, var(--ink) 55%, var(--accent)) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 48px;
}

.login-brand-panel::before,
.login-brand-panel::after {
  content: "";
  position: absolute;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.06);
}
.login-brand-panel::before { width: 480px; height: 480px; top: -180px; right: -160px; }
.login-brand-panel::after { width: 320px; height: 320px; bottom: -140px; left: -100px; background: rgba(255,255,255,0.05); }

.login-brand-content {
  position: relative;
  z-index: 1;
  text-align: center;
  max-width: 340px;
}

.login-brand-logo {
  width: 96px; height: 96px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 28px;
  font-weight: 700; font-size: 32px; color: #fff;
  overflow: hidden;
  box-shadow: 0 12px 32px rgba(0,0,0,0.18);
}
.login-brand-logo img { width: 100%; height: 100%; object-fit: contain; background: #fff; }

.login-brand-content h2 {
  color: #fff;
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 10px;
}
.login-brand-content p {
  color: rgba(255,255,255,0.75);
  font-size: 14px;
  line-height: 1.6;
  margin: 0;
}

/* Painel direito: formulário */
.login-form-panel {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--paper);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 40px 32px;
  box-shadow: 0 1px 3px rgba(20, 33, 61, 0.06);
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  margin-bottom: 20px;
  overflow: hidden;
}

.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #fff;
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 4px;
  letter-spacing: -0.01em;
}

.login-card p.sub {
  color: var(--ink-soft);
  font-size: 14px;
  margin: 0 0 28px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 6px;
}

input[type="email"],
input[type="password"],
input[type="text"],
select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 14px;
  margin-bottom: 18px;
  font-family: inherit;
  background: #fff;
  color: var(--ink);
}

input:focus, select:focus {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}

button {
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  width: 100%;
  background: var(--ink);
  color: #fff;
  border: none;
  padding: 11px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
}

.btn-primary:hover { background: #0d1730; }

.error-msg {
  background: var(--danger-soft);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

/* ---------- Layout app (painel usuário / admin) ---------- */
.app-shell { min-height: 100vh; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--line);
  padding: 12px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar-left { display: flex; align-items: center; gap: 14px; }

.topbar-title { font-weight: 700; font-size: 16px; }

.topbar-right { display: flex; align-items: center; gap: 16px; font-size: 13px; color: var(--ink-soft); }

.link-btn {
  background: none;
  border: none;
  color: var(--ink-soft);
  font-size: 13px;
  text-decoration: underline;
}

.container { max-width: 1080px; margin: 0 auto; padding: 32px 28px; }

.section-title { font-size: 18px; font-weight: 700; margin: 0 0 4px; }
.section-sub { color: var(--ink-soft); font-size: 14px; margin: 0 0 24px; }

/* Grid de cards de visões (usuário final) */
.views-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.view-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.1s;
}

.view-card:hover { border-color: var(--ink); transform: translateY(-1px); }

.view-card .cat {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 20px;
  margin-bottom: 10px;
}

.view-card h3 { margin: 0 0 6px; font-size: 15px; }
.view-card p { margin: 0; font-size: 13px; color: var(--ink-soft); }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--ink-soft);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

/* Modal de visualização de BI embutido */
.viewer-overlay {
  position: fixed; inset: 0;
  background: rgba(20, 33, 61, 0.55);
  display: none;
  align-items: center; justify-content: center;
  padding: 20px;
  z-index: 50;
}

.viewer-modal {
  background: #fff;
  width: 100%; height: 100%;
  max-width: 1200px; max-height: 88vh;
  border-radius: var(--radius);
  overflow: hidden;
  display: flex; flex-direction: column;
  transition: max-width 0.15s, max-height 0.15s, border-radius 0.15s;
}

/* Modo tela cheia real (Fullscreen API), ocupa 100% da tela do dispositivo */
.viewer-overlay.is-fullscreen {
  padding: 0;
  background: #000;
}

.viewer-overlay.is-fullscreen .viewer-modal {
  max-width: 100vw; max-height: 100vh;
  border-radius: 0;
}

.viewer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
  gap: 12px;
}

.viewer-head h3 { margin: 0; font-size: 15px; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.viewer-head-actions { display: flex; gap: 8px; flex-shrink: 0; }

.viewer-btn {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 6px; width: 32px; height: 32px; font-size: 15px;
  display: flex; align-items: center; justify-content: center;
}

.viewer-modal iframe { flex: 1; border: none; width: 100%; }

.insight-banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 18px; font-size: 13px; line-height: 1.5;
  border-bottom: 1px solid var(--line);
}
.insight-banner .icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.insight-banner.info { background: #eaf2ff; color: #1d4ed8; }
.insight-banner.warning { background: #fff8e1; color: #92700c; }
.insight-banner.critical { background: var(--danger-soft); color: var(--danger); }

/* ---------- Tabelas admin ---------- */
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 28px;
}

.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}

.panel-head h2 { margin: 0; font-size: 15px; }

.btn-small {
  background: var(--ink); color: #fff; border: none;
  padding: 7px 14px; border-radius: 6px; font-size: 13px; font-weight: 600;
}

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 10px 20px; background: var(--paper);
  color: var(--ink-soft); font-weight: 600; border-bottom: 1px solid var(--line);
}
td { padding: 10px 20px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr:last-child td { border-bottom: none; }

.badge {
  font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 20px;
}
.badge.admin { background: #eef2ff; color: #4338ca; }
.badge.user { background: var(--accent-soft); color: var(--accent); }
.badge.active { background: var(--accent-soft); color: var(--accent); }
.badge.inactive { background: var(--danger-soft); color: var(--danger); }

.row-actions button {
  background: none; border: none; font-size: 12px; color: var(--ink-soft);
  text-decoration: underline; margin-right: 10px; padding: 0;
}
.row-actions button.danger { color: var(--danger); }

.tabs { display: flex; gap: 4px; margin-bottom: 20px; }
.tab-btn {
  background: none; border: none; padding: 8px 16px; font-size: 14px;
  font-weight: 600; color: var(--ink-soft); border-radius: 8px;
}
.tab-btn.active { background: var(--ink); color: #fff; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---------- Modal genérico (formulários) ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(20,33,61,0.5);
  display: none; align-items: center; justify-content: center; z-index: 60; padding: 20px;
}
.modal-box {
  background: #fff; border-radius: var(--radius); padding: 28px;
  width: 100%; max-width: 420px;
}
.modal-box h3 { margin: 0 0 20px; font-size: 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 4px; }
.btn-secondary {
  flex: 1; background: var(--paper); border: 1px solid var(--line);
  padding: 10px; border-radius: 8px; font-size: 14px; font-weight: 600;
}
.modal-actions .btn-primary { flex: 1; margin: 0; width: auto; }

.helptext { font-size: 12px; color: var(--ink-soft); margin: -12px 0 18px; }

/* ---------- Aba de Configurações (marca: logo, cores, nome) ---------- */
.settings-form { padding: 20px; max-width: 480px; }

.checklist-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--line);
  font-size: 13px; cursor: pointer;
}
.checklist-item:last-child { border-bottom: none; }
.checklist-item input { width: auto; margin: 0; }
.checklist-item .cat-tag { color: var(--ink-soft); font-size: 12px; }
.checklist-empty { padding: 16px; color: var(--ink-soft); font-size: 13px; text-align: center; }

.logo-preview-row {
  display: flex; align-items: center; gap: 16px; margin-bottom: 20px;
}

.logo-preview {
  width: 64px; height: 64px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0;
}
.logo-preview img { width: 100%; height: 100%; object-fit: contain; }

.color-input-row { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.color-input-row input[type="color"] {
  width: 44px; height: 38px; padding: 2px; border: 1px solid var(--line);
  border-radius: 8px; cursor: pointer; background: #fff;
}
.color-input-row span { font-size: 13px; color: var(--ink-soft); }

.reset-link-box {
  background: var(--paper); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 12px; font-size: 12px; word-break: break-all; margin-top: 10px;
  display: none;
}
.reset-link-box.visible { display: block; }
.reset-link-box button {
  margin-top: 8px; background: var(--ink); color: #fff; border: none;
  padding: 6px 12px; border-radius: 6px; font-size: 12px; font-weight: 600;
}

/* ============================================================
   RESPONSIVIDADE — CELULAR E TELAS PEQUENAS
   ============================================================ */
@media (max-width: 720px) {
  .topbar {
    padding: 10px 16px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .topbar-right {
    font-size: 12px;
    gap: 10px;
  }
  .topbar-right span { display: none; } /* esconde o nome do usuário, mantém "Sair" */

  .container { padding: 20px 16px; }

  .views-grid { grid-template-columns: 1fr; gap: 12px; }

  /* Login: painéis empilham, marca fica compacta no topo */
  .login-shell { flex-direction: column; min-height: auto; }
  .login-brand-panel { flex: none; padding: 32px 24px; }
  .login-brand-panel::before { width: 280px; height: 280px; top: -120px; right: -100px; }
  .login-brand-panel::after { display: none; }
  .login-brand-logo { width: 68px; height: 68px; font-size: 24px; margin-bottom: 16px; }
  .login-brand-content h2 { font-size: 20px; }
  .login-brand-content p { font-size: 13px; }
  .login-form-panel { padding: 28px 20px 40px; }
  .login-card { padding: 0; border: none; box-shadow: none; max-width: 100%; }

  /* Modal do BI ocupa a tela quase inteira no celular, sem margens desperdiçadas */
  .viewer-overlay { padding: 0; }
  .viewer-modal { max-width: 100vw; max-height: 100vh; border-radius: 0; }

  /* Tabelas do admin viram "cards" empilhados em vez de rolar horizontalmente */
  .panel table, .panel thead, .panel tbody, .panel th, .panel td, .panel tr {
    display: block;
  }
  .panel thead { display: none; }
  .panel tr {
    border-bottom: 1px solid var(--line);
    padding: 12px 16px;
  }
  .panel tr:last-child { border-bottom: none; }
  .panel td {
    border: none;
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: center;
  }
  .panel td::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--ink-soft);
    font-size: 12px;
    flex-shrink: 0;
  }
  .panel td[data-label=""]::before { display: none; }

  .tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab-btn { white-space: nowrap; }

  .panel-head { flex-wrap: wrap; gap: 10px; }

  .modal-box { padding: 22px; }

  #tab-assign > .panel > div[style] {
    flex-direction: column !important;
    align-items: stretch !important;
  }
}

@media (max-width: 420px) {
  .login-card h1 { font-size: 18px; }
  .section-title { font-size: 16px; }
}
