/* ============================================================
   Monitor RM TSTT — tema clean claro
   Identidade tstt.net.br
   Azul TROI: #3DA0E6 -> #1E5BA8 -> #0A2F6B | Vermelho: #DC1F26
   ============================================================ */

:root {
  --tstt-azul-claro:  #3DA0E6;
  --tstt-azul:        #1E5BA8;
  --tstt-azul-escuro: #0A2F6B;
  --tstt-vermelho:    #DC1F26;

  /* superficie clara */
  --bg:        #F6F8FB;
  --bg-2:      #FFFFFF;
  --surface:   #FFFFFF;
  --surface-2: #F0F4FA;
  --border:    #E3E9F2;
  --text:      #1A2433;
  --text-mut:  #64748B;

  --ok:   #16A34A;
  --warn: #D97706;
  --err:  #DC1F26;
  --run:  #1E5BA8;

  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 32, 60, .05), 0 4px 16px rgba(16, 32, 60, .06);
  --shadow-lg: 0 8px 32px rgba(10, 47, 107, .10);
  --font: 'Inter', -apple-system, 'Segoe UI', sans-serif;
  --mono: 'IBM Plex Mono', 'Consolas', monospace;
}

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

html { font-family: var(--font); font-size: 14px; }
body {
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

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

/* ---- Topbar ------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 50;
  background: rgba(255, 255, 255, .85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1400px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand img { height: 32px; }
.brand-txt strong { font-size: 15px; display: block; letter-spacing: -0.01em; }
.brand-txt small { color: var(--text-mut); font-size: 11.5px; }
.brand-txt small .dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok); margin-right: 4px;
}

.topbar-spacer { flex: 1; }
.chip {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px; font-size: 12px;
  color: var(--text-mut);
}
.chip b { color: var(--text); font-weight: 600; }

/* ---- Botoes ------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; font-size: 13px; font-weight: 500;
  border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text);
  cursor: pointer; transition: all .15s;
  box-shadow: 0 1px 2px rgba(16, 32, 60, .05);
}
.btn:hover { background: var(--surface-2); border-color: #CBD6E5; text-decoration: none; }
.btn-primary {
  background: var(--tstt-azul);
  border-color: var(--tstt-azul); color: #fff; font-weight: 600;
}
.btn-primary:hover { background: var(--tstt-azul-escuro); border-color: var(--tstt-azul-escuro); }
.btn-danger { border-color: #F5C6C8; color: var(--tstt-vermelho); background: #fff; }
.btn-danger:hover { background: #FDF1F1; border-color: var(--tstt-vermelho); }
.btn-sm { padding: 4px 10px; font-size: 12px; box-shadow: none; }

/* ---- Layout ------------------------------------------------ */
.main { max-width: 1400px; margin: 0 auto; padding: 24px; }

.alert { border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-size: 13px; }
.alert-ok   { background: #F0FBF4; border: 1px solid #BBE7CC; color: #14713A; }
.alert-erro { background: #FDF2F2; border: 1px solid #F3C4C6; color: #A61A20; }
.alert-warn { background: #FEF8EC; border: 1px solid #F1DCAF; color: #92600A; }
.alert ul { margin: 6px 0 0 18px; }

/* ---- KPIs -------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
  position: relative; overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--tstt-azul-claro);
}
.kpi.ok::before  { background: var(--ok); }
.kpi.run::before { background: var(--run); }
.kpi.err::before { background: var(--tstt-vermelho); }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-mut); font-weight: 600; }
.kpi-value { font-size: 30px; font-weight: 700; font-family: var(--mono); display: block; margin: 2px 0; letter-spacing: -0.02em; }
.kpi-hint { font-size: 11.5px; color: var(--text-mut); }

/* ---- Paineis / graficos ------------------------------------ */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 18px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 14px; margin-bottom: 18px; }
@media (max-width: 980px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
}
.panel h3 {
  font-size: 11.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-mut); margin-bottom: 14px; font-weight: 600;
}
.panel canvas { max-height: 260px; }

/* ---- Tabela ------------------------------------------------ */
.table-wrap { overflow-x: auto; }
table.dados { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.dados th {
  text-align: left; padding: 9px 10px; color: var(--text-mut);
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  border-bottom: 1px solid var(--border); white-space: nowrap; font-weight: 600;
}
table.dados td { padding: 9px 10px; border-bottom: 1px solid #EDF1F7; vertical-align: top; }
table.dados tr:hover td { background: #F7FAFE; }

.badge {
  display: inline-block; padding: 2px 10px; border-radius: 12px;
  font-size: 11px; font-weight: 600;
}
.badge.sucesso  { background: #EBF9F0; color: #14713A; }
.badge.erro     { background: #FDEEEE; color: #B91B21; }
.badge.execucao { background: #EAF3FC; color: #17549C; }
.badge.pendente { background: #FDF5E4; color: #92600A; }
.badge.cancelado{ background: #F0F3F8; color: var(--text-mut); }
.badge.outros   { background: #F0F3F8; color: var(--text-mut); }

/* ---- Formularios / login ----------------------------------- */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background:
    radial-gradient(900px 460px at 80% -10%, rgba(61, 160, 230, .10), transparent 60%),
    radial-gradient(700px 420px at 0% 110%, rgba(30, 91, 168, .07), transparent 60%),
    var(--bg);
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 36px 32px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 420px;
}
.card .brand { justify-content: center; margin-bottom: 10px; }
.card h1 { font-size: 20px; text-align: center; margin-bottom: 4px; letter-spacing: -0.01em; }
.card p.sub { text-align: center; color: var(--text-mut); font-size: 13px; margin-bottom: 24px; }

label.field { display: block; margin-bottom: 14px; font-size: 12px; color: var(--text-mut); }
label.field span { display: block; margin-bottom: 5px; font-weight: 600; letter-spacing: .02em; color: #3B4A5F; }
input[type=text], input[type=password], input[type=email], input[type=url],
input[type=number], select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 8px;
  border: 1px solid #D4DDE9; background: var(--bg-2);
  color: var(--text); font-family: var(--font); font-size: 13.5px;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--tstt-azul-claro);
  box-shadow: 0 0 0 3px rgba(61, 160, 230, .15);
}
.btn-block { width: 100%; justify-content: center; padding: 11px; font-size: 14px; }

.rodape {
  text-align: center; color: var(--text-mut); font-size: 11px; padding: 24px;
}
.rodape a { color: var(--tstt-azul); }

/* ---- Admin ------------------------------------------------- */
.nav-admin { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.nav-admin a {
  padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 500;
  border: 1px solid transparent; color: var(--text-mut);
}
.nav-admin a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-admin a.ativo {
  background: #EAF3FC; color: var(--tstt-azul); font-weight: 600;
  border-color: #CBE1F6;
}
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.acao-inline { display: inline; }

/* ---- Impressao (export PDF via navegador) ------------------ */
@media print {
  body { background: #fff; color: #111; }
  .topbar, .no-print { display: none !important; }
  .panel, .kpi, .card { box-shadow: none; border-color: #ccc; background: #fff; }
  table.dados tr:hover td { background: none; }
}

/* ---- Badge/KPI de aviso ------------------------------------ */
.badge.aviso { background: #FFF1DB; color: #A05A00; }
.kpi.wn::before { background: var(--warn); }

/* ---- Filtros de status da tabela --------------------------- */
.filtros-status { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.filtros-status button {
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 16px; padding: 4px 12px; font-size: 12px; font-weight: 500;
  color: var(--text-mut); cursor: pointer; font-family: var(--font);
  transition: all .15s;
}
.filtros-status button:hover { border-color: #CBD6E5; color: var(--text); }
.filtros-status button.ativo {
  background: #EAF3FC; color: var(--tstt-azul); border-color: #CBE1F6; font-weight: 600;
}
.filtros-status button .qt { font-family: var(--mono); font-size: 11px; margin-left: 3px; }

/* ---- Linhas clicaveis + destaque de erro ------------------- */
table.dados tr.clicavel { cursor: pointer; }
table.dados tr.linha-erro td:first-child { box-shadow: inset 3px 0 0 var(--tstt-vermelho); }
table.dados tr.linha-aviso td:first-child { box-shadow: inset 3px 0 0 var(--warn); }

/* ---- Modal de detalhes do job ------------------------------ */
.modal-fundo {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16, 32, 60, .45); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: modalIn .12s ease-out;
}
/* CORRECAO DO TRAVAMENTO: display:flex vencia o atributo hidden e a camada
   ficava por cima da pagina bloqueando todos os cliques. */
.modal-fundo[hidden] { display: none !important; }
@keyframes modalIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--surface); border-radius: 16px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 820px; max-height: 88vh;
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-cab {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 12px; padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
}
.modal-cab h2 { font-size: 17px; margin-bottom: 8px; letter-spacing: -0.01em; line-height: 1.3; }
.mj-meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.mj-meta .badge { font-size: 11.5px; }
.mj-meta .meta-chip {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 2px 10px; font-size: 11px; color: var(--text-mut);
}
.mj-meta .meta-chip b { color: var(--text); font-weight: 600; }
.modal-fechar {
  border: none; background: var(--surface-2); color: var(--text-mut);
  width: 32px; height: 32px; border-radius: 8px; font-size: 18px; line-height: 1;
  cursor: pointer; flex-shrink: 0;
}
.modal-fechar:hover { background: #E4EAF3; color: var(--text); }
.modal-corpo { padding: 18px 24px 24px; overflow-y: auto; }

/* Linha do tempo da execucao */
.mj-tempo {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 0; margin-bottom: 18px; border: 1px solid var(--border);
  border-radius: 12px; overflow: hidden; background: var(--surface-2);
}
.mj-tempo .etapa {
  padding: 10px 14px; position: relative; background: var(--surface-2);
}
.mj-tempo .etapa + .etapa { border-left: 1px solid var(--border); }
.mj-tempo .etapa.feita { background: #F3F9F5; }
.mj-tempo .etapa span {
  display: block; font-size: 10px; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-mut); font-weight: 600; margin-bottom: 3px;
}
.mj-tempo .etapa b { font-size: 12px; font-weight: 600; font-family: var(--mono); }
.mj-tempo .etapa .vazio { color: var(--text-mut); font-weight: 400; font-family: var(--font); font-style: italic; font-size: 12px; }
@media (max-width: 640px) { .mj-tempo { grid-template-columns: repeat(2, 1fr); } }

/* Grupos de detalhes */
.mj-sec {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-mut); font-weight: 600; margin: 16px 0 8px;
  display: flex; align-items: center; gap: 10px;
}
.mj-sec::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.det-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 8px 18px;
}
.det-grid .det { padding: 4px 0; }
.det-grid .det span {
  display: block; font-size: 10.5px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-mut); font-weight: 600; margin-bottom: 1px;
}
.det-grid .det b { font-size: 13px; font-weight: 500; word-break: break-word; }
.det-grid .det b.mono { font-family: var(--mono); font-size: 12px; }

/* Log */
.mj-log-wrap { position: relative; }
.btn-copiar {
  position: absolute; top: 8px; right: 8px;
  border: 1px solid var(--border); background: var(--surface);
  border-radius: 6px; padding: 3px 10px; font-size: 11px; font-weight: 500;
  color: var(--text-mut); cursor: pointer; font-family: var(--font);
}
.btn-copiar:hover { color: var(--text); border-color: #CBD6E5; }
.det-log {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 12px 14px; font-family: var(--mono); font-size: 12px; line-height: 1.55;
  white-space: pre-wrap; word-break: break-word; max-height: 240px; overflow-y: auto;
  color: var(--text); margin: 0;
}
.det-log.log-erro { background: #FDF2F2; border-color: #F3C4C6; color: #8F1418; }
.det-log.log-aviso { background: #FFF7E8; border-color: #F1DCAF; color: #7A5104; }
.det-log.log-vazio { color: var(--text-mut); font-style: italic; }

body.modal-aberto { overflow: hidden; }
