/* ── Admin TJL — Painel de Histórico ─────────────────────────────────────── */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --azul:       #1a56db;
  --azul-claro: #e8f0fe;
  --azul-hover: #1e40af;
  --verde:      #16a34a;
  --verde-cl:   #dcfce7;
  --amarelo:    #d97706;
  --amar-cl:    #fef3c7;
  --vermelho:   #dc2626;
  --cinza-bg:   #f8fafc;
  --cinza-brd:  #e2e8f0;
  --texto:      #1e293b;
  --texto-leve: #64748b;
  --branco:     #ffffff;
  --radius:     12px;
  --sombra:     0 1px 3px rgba(0,0,0,.08);
}

body[data-theme="dark"] {
  --azul:       #3b82f6;
  --azul-claro: #172554;
  --azul-hover: #60a5fa;
  --verde:      #22c55e;
  --verde-cl:   #052e16;
  --amarelo:    #f59e0b;
  --amar-cl:    #451a03;
  --vermelho:   #f87171;
  --cinza-bg:   #0f172a;
  --cinza-brd:  #334155;
  --texto:      #e5e7eb;
  --texto-leve: #94a3b8;
  --branco:     #111827;
  --sombra:     0 1px 3px rgba(0,0,0,.35);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--cinza-bg);
  color: var(--texto);
  min-height: 100vh;
}

/* ── Login ────────────────────────────────────────────────────────────────── */
#loginScreen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: white;
  border-radius: 20px;
  padding: 48px 40px 40px;
  width: min(380px, 94vw);
  box-shadow: 0 8px 32px rgba(0,0,0,.12);
  text-align: center;
}

.login-logo {
  font-size: 48px;
  margin-bottom: 16px;
}

.login-card h1 {
  font-size: 22px;
  color: var(--texto);
  margin-bottom: 6px;
}

.login-card p {
  font-size: 14px;
  color: var(--texto-leve);
  margin-bottom: 28px;
}

.login-erro {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--vermelho);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
}

.login-card input[type=password] {
  width: 100%;
  border: 1.5px solid var(--cinza-brd);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 15px;
  outline: none;
  margin-bottom: 12px;
  transition: border-color .2s;
}
.login-card input:focus { border-color: var(--azul); }

.login-card button {
  width: 100%;
  background: var(--azul);
  color: white;
  border: none;
  border-radius: 10px;
  padding: 13px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s;
}
.login-card button:hover { background: var(--azul-hover); }
.login-card button:disabled { background: var(--cinza-brd); cursor: not-allowed; }

/* ── Header ───────────────────────────────────────────────────────────────── */
.adm-header {
  background: var(--azul);
  color: white;
  padding: 16px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.adm-header-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.adm-logo { font-size: 28px; }

.adm-header-left h1 {
  font-size: 18px;
  font-weight: 700;
}

.adm-sub {
  font-size: 12px;
  color: rgba(255,255,255,.7);
}

.adm-header-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn-voltar, .btn-sair, .btn-tema {
  background: rgba(255,255,255,.15);
  border: 1px solid rgba(255,255,255,.3);
  color: white;
  border-radius: 8px;
  padding: 7px 14px;
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  transition: background .2s;
}
.btn-voltar:hover, .btn-sair:hover, .btn-tema:hover { background: rgba(255,255,255,.28); }

/* ── Stats grid ───────────────────────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  padding: 24px 32px 0;
}

@media (max-width: 768px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

.stat-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--sombra);
  border: 1px solid var(--cinza-brd);
}

.stat-card.destaque {
  border-color: var(--azul);
  background: var(--azul-claro);
}

.stat-valor {
  font-size: 32px;
  font-weight: 700;
  color: var(--azul);
  line-height: 1;
  margin-bottom: 6px;
}

.stat-label {
  font-size: 13px;
  color: var(--texto-leve);
}

/* ── Barras por setor ─────────────────────────────────────────────────────── */
.setores-stats {
  margin: 20px 32px 0;
  background: white;
  border-radius: var(--radius);
  padding: 18px 24px;
  box-shadow: var(--sombra);
  border: 1px solid var(--cinza-brd);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.setor-bar-item {
  display: flex;
  align-items: center;
  gap: 12px;
}

.setor-nome {
  width: 100px;
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
}

.setor-barra-wrap {
  flex: 1;
  height: 10px;
  background: var(--cinza-bg);
  border-radius: 10px;
  overflow: hidden;
}

.setor-barra {
  height: 100%;
  border-radius: 10px;
  width: 0%;
  transition: width .6s ease;
}
.setor-barra.sac      { background: var(--azul); }
.setor-barra.tecnico  { background: var(--verde); }
.setor-barra.comercial { background: var(--amarelo); }

.setor-qtd {
  font-size: 13px;
  font-weight: 600;
  width: 30px;
  text-align: right;
  color: var(--texto-leve);
}

/* ── Filtros ──────────────────────────────────────────────────────────────── */
.filtros-bar {
  display: flex;
  align-items: flex-end;
  gap: 16px;
  padding: 20px 32px 0;
  flex-wrap: wrap;
}

.filtro-grupo {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.filtro-grupo label {
  font-size: 12px;
  font-weight: 600;
  color: var(--texto-leve);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.filtro-grupo select,
.filtro-grupo input {
  border: 1.5px solid var(--cinza-brd);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  outline: none;
  background: var(--branco);
  color: var(--texto);
  min-width: 150px;
  transition: border-color .2s;
}
.filtro-grupo select { cursor: pointer; }
.filtro-grupo select:focus,
.filtro-grupo input:focus { border-color: var(--azul); }

.btn-limpar {
  background: var(--branco);
  border: 1.5px solid var(--cinza-brd);
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 13px;
  cursor: pointer;
  color: var(--texto-leve);
  transition: all .2s;
  margin-bottom: 1px;
}
.btn-limpar:hover { border-color: var(--azul); color: var(--azul); }

.total-label {
  font-size: 13px;
  color: var(--texto-leve);
  margin-left: auto;
  align-self: flex-end;
  padding-bottom: 9px;
}

/* ── Tabela ───────────────────────────────────────────────────────────────── */
.tabela-section {
  padding: 20px 32px 32px;
}

.tabela-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--sombra);
  border: 1px solid var(--cinza-brd);
}

.tabela-conversas {
  width: 100%;
  border-collapse: collapse;
  background: var(--branco);
  font-size: 13px;
}

.tabela-conversas thead {
  background: var(--cinza-bg);
  border-bottom: 1.5px solid var(--cinza-brd);
}

.tabela-conversas th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 700;
  color: var(--texto-leve);
  text-transform: uppercase;
  letter-spacing: .05em;
  white-space: nowrap;
}

.tabela-conversas td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--cinza-brd);
  color: var(--texto);
  vertical-align: middle;
}

.tabela-conversas tbody tr:last-child td { border-bottom: none; }

.tabela-conversas tbody tr:hover { background: var(--cinza-bg); }

.tabela-vazia {
  text-align: center;
  padding: 40px 16px !important;
  color: var(--texto-leve);
  font-style: italic;
}

.badge-setor {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-setor.sac      { background: var(--azul-claro);  color: var(--azul); }
.badge-setor.tecnico  { background: var(--verde-cl);     color: var(--verde); }
.badge-setor.comercial { background: var(--amar-cl);    color: var(--amarelo); }
.badge-setor.sem      { background: var(--cinza-bg);    color: var(--texto-leve); }

.nota-estrelas { color: #f59e0b; font-size: 13px; letter-spacing: -1px; }
.nota-vazia    { color: var(--cinza-brd); font-size: 12px; }

.btn-ver {
  background: var(--azul-claro);
  color: var(--azul);
  border: none;
  border-radius: 6px;
  padding: 5px 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}
.btn-ver:hover { background: var(--azul); color: white; }

.celula-truncar {
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Paginação ────────────────────────────────────────────────────────────── */
.paginacao {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 16px 0 0;
}

.btn-pag {
  background: var(--branco);
  border: 1.5px solid var(--cinza-brd);
  border-radius: 8px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
  transition: all .2s;
  color: var(--texto);
}
.btn-pag:hover   { border-color: var(--azul); color: var(--azul); }
.btn-pag.ativo   { background: var(--azul); border-color: var(--azul); color: white; font-weight: 700; }
.btn-pag:disabled { opacity: .4; cursor: not-allowed; }

/* ── Modal de detalhe ─────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-detalhe {
  background: var(--branco);
  border-radius: 16px;
  width: min(700px, 100%);
  max-height: 85vh;
  overflow-y: auto;
  padding: 32px;
  position: relative;
  box-shadow: 0 20px 60px rgba(0,0,0,.28);
}

.btn-fechar-modal {
  position: absolute;
  top: 16px;
  right: 16px;
  background: var(--cinza-bg);
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 16px;
  cursor: pointer;
  color: var(--texto-leve);
  transition: background .2s;
}
.btn-fechar-modal:hover { background: var(--cinza-brd); }

.detalhe-header {
  margin-bottom: 20px;
  padding-right: 40px;
}

.detalhe-titulo {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}

.detalhe-meta {
  font-size: 13px;
  color: var(--texto-leve);
}

.detalhe-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.detalhe-item {
  background: var(--cinza-bg);
  border-radius: 8px;
  padding: 12px 14px;
}

.detalhe-item-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--texto-leve);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 4px;
}

.detalhe-item-valor {
  font-size: 14px;
  color: var(--texto);
  word-break: break-word;
}

.detalhe-secao {
  margin-bottom: 20px;
}

.detalhe-secao h4 {
  font-size: 13px;
  font-weight: 700;
  color: var(--texto-leve);
  text-transform: uppercase;
  letter-spacing: .05em;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--cinza-brd);
}

/* Histórico de mensagens no detalhe */
.conv-msg {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
  align-items: flex-start;
}

.conv-msg.user   { flex-direction: row-reverse; }

.conv-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--azul);
  color: white;
  font-size: 9px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.conv-msg.user .conv-avatar { background: var(--texto-leve); }

.conv-balao {
  max-width: 75%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  background: var(--cinza-bg);
  color: var(--texto);
}

body[data-theme="dark"] .login-card,
body[data-theme="dark"] .stat-card,
body[data-theme="dark"] .setores-stats {
  background: var(--branco);
}

body[data-theme="dark"] input,
body[data-theme="dark"] select,
body[data-theme="dark"] textarea {
  background: #111827 !important;
  color: #f8fafc !important;
  border-color: #475569 !important;
}

body[data-theme="dark"] input::placeholder,
body[data-theme="dark"] textarea::placeholder {
  color: #94a3b8 !important;
}

body[data-theme="dark"] option {
  background: #111827;
  color: #f8fafc;
}

body[data-theme="dark"] .btn-mini,
body[data-theme="dark"] .btn-limpar,
body[data-theme="dark"] .btn-pag,
body[data-theme="dark"] .btn-ver {
  background: #111827;
  border-color: #475569;
  color: #f8fafc;
}

.conv-msg.user .conv-balao {
  background: var(--azul);
  color: white;
}
