:root {
  --navy: #0b162c;
  --navy-mid: #142547;
  --navy-hover: rgba(255, 255, 255, 0.08);
  --bg: #f4f7fb;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --green: #059669;
  --green-light: #10b981;
  --green-bg: #d1fae5;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --shadow-sm: 0 2px 8px -2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 10px 28px -6px rgba(15, 23, 42, 0.09);
  --shadow-lg: 0 24px 60px -12px rgba(11, 22, 44, 0.32);
  --radius: 14px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4, .kpi-val {
  font-family: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
  letter-spacing: -0.02em;
}

.hidden { display: none !important; }

@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes pulseDot {
  0%, 100% { box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.55); }
  50% { box-shadow: 0 0 0 6px rgba(16, 185, 129, 0); }
}

/* ================= LOGIN ================= */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(circle at 15% 20%, rgba(37, 99, 235, 0.25), transparent 45%),
    radial-gradient(circle at 85% 80%, rgba(16, 185, 129, 0.2), transparent 45%),
    linear-gradient(145deg, #070e1d 0%, #0f1f3d 55%, #162e58 100%);
}

.login-card {
  background: rgba(255, 255, 255, 0.97);
  backdrop-filter: blur(16px);
  width: 100%;
  max-width: 420px;
  padding: 2.25rem 2rem;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.4s ease;
}

.login-card h1 {
  margin: 0 0 0.3rem;
  font-size: 1.5rem;
  color: var(--navy);
}

.login-card p {
  margin: 0 0 1.6rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

/* ================= LAYOUT ADMIN ================= */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 272px;
  background: linear-gradient(180deg, #091326 0%, #0f1f3d 60%, #13284d 100%);
  color: #e2e8f0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid rgba(255, 255, 255, 0.06);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 999px; }

.brand {
  padding: 1.4rem 1.35rem 1.15rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand h2 {
  margin: 0;
  font-size: 1.2rem;
  letter-spacing: 0.4px;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand h2::before {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green-light);
  animation: pulseDot 2.4s infinite;
}

.brand span { font-size: 0.78rem; color: #94a3b8; }

.nav-section {
  padding: 1rem 1.35rem 0.35rem;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: #64748b;
}

.nav-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: calc(100% - 1.5rem);
  margin: 0.18rem 0.75rem;
  padding: 0.68rem 0.9rem;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  color: #cbd5e1;
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.18s ease;
}

.nav-btn:hover:not(.disabled) {
  background: var(--navy-hover);
  color: #ffffff;
  transform: translateX(3px);
}

.nav-btn.active {
  background: linear-gradient(90deg, rgba(16, 185, 129, 0.22), rgba(16, 185, 129, 0.08));
  border-color: rgba(16, 185, 129, 0.35);
  color: #6ee7b7;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(16, 185, 129, 0.12);
}

.nav-btn.disabled { opacity: 0.42; cursor: not-allowed; }

.nav-pill {
  font-size: 0.66rem;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
  color: #cbd5e1;
}

.sidebar-footer {
  margin-top: auto;
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.16);
  font-size: 0.82rem;
  color: #cbd5e1;
}

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(255, 255, 255, 0.88);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.9rem 1.6rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.topbar-left { display: flex; align-items: center; gap: 0.85rem; flex-wrap: wrap; }
.topbar-left h1 { margin: 0; font-size: 1.22rem; color: var(--navy); }
.topbar-right { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

.content {
  padding: 1.6rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}

main section:not(.hidden) { animation: fadeInUp 0.28s ease; }

/* ================= CARDS & KPIs ================= */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(225px, 1fr)); gap: 1rem; }
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 1.15rem; }

@media (max-width: 960px) {
  .two-col { grid-template-columns: 1fr; }
  .app-shell { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: relative; }
}

.card {
  background: var(--card);
  border: 1px solid rgba(226, 232, 240, 0.9);
  border-radius: var(--radius);
  padding: 1.25rem 1.35rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.kpi-grid .card {
  position: relative;
  overflow: hidden;
}

.kpi-grid .card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--navy), var(--blue));
}

.kpi-grid .card:nth-child(2)::before { background: linear-gradient(90deg, var(--green), var(--green-light)); }
.kpi-grid .card:nth-child(3)::before { background: linear-gradient(90deg, #f59e0b, var(--amber)); }
.kpi-grid .card:nth-child(4)::before { background: linear-gradient(90deg, #6366f1, var(--blue)); }

.kpi-grid .card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.card-title { margin: 0; font-size: 1.02rem; font-weight: 700; color: var(--navy); }
.kpi-label { font-size: 0.78rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); margin-bottom: 0.4rem; }
.kpi-val { font-size: 1.65rem; font-weight: 800; color: var(--navy); line-height: 1.15; }
.kpi-sub { font-size: 0.8rem; color: var(--muted); margin-top: 0.4rem; }

/* ================= BADGES ================= */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}
.badge-green { background: var(--green-bg); color: #047857; }
.badge-amber { background: var(--amber-bg); color: #b45309; }
.badge-red { background: var(--red-bg); color: #b91c1c; }
.badge-blue { background: var(--blue-bg); color: #1d4ed8; }

/* ================= FORMS & BUTTONS ================= */
.form-group { margin-bottom: 0.95rem; }
.form-group label { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 0.35rem; color: #334155; }

input, select, textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  font-size: 0.9rem;
  font-family: inherit;
  background: #ffffff;
  color: var(--text);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

textarea { resize: vertical; }
.inline-select { width: auto; min-width: 220px; padding: 0.48rem 0.75rem; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 0.9rem; }

.btn {
  padding: 0.62rem 1.1rem;
  border: none;
  border-radius: 10px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: all 0.18s ease;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, #0f1f3d, #1e3a6e);
  color: #fff;
  box-shadow: 0 4px 12px rgba(15, 31, 61, 0.22);
}
.btn-primary:hover { filter: brightness(1.12); transform: translateY(-1px); }

.btn-green {
  background: linear-gradient(135deg, #059669, #10b981);
  color: #fff;
  box-shadow: 0 4px 12px rgba(5, 150, 105, 0.24);
}
.btn-green:hover { filter: brightness(1.08); transform: translateY(-1px); }

.btn-outline {
  background: #fff;
  color: var(--navy);
  border: 1px solid #cbd5e1;
}
.btn-outline:hover { background: #f8fafc; border-color: #94a3b8; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.78rem; border-radius: 8px; }

/* ================= TABLES ================= */
.table-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 0.87rem; background: #fff; }
th, td { padding: 0.78rem 0.85rem; text-align: left; border-bottom: 1px solid var(--border); }
th {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  background: #f8fafc;
}
tbody tr { transition: background 0.15s ease; }
tbody tr:hover { background: #f8fafc; }
tbody tr:last-child td { border-bottom: none; }

/* ================= RANKING, ALERTS & TIMELINE ================= */
.rank-item { margin-bottom: 0.9rem; }
.rank-head { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 0.3rem; }
.rank-bar-bg { height: 9px; background: #e2e8f0; border-radius: 999px; overflow: hidden; }
.rank-bar-fill { height: 100%; background: linear-gradient(90deg, var(--navy), var(--blue)); border-radius: 999px; transition: width 0.5s ease; }

.alert { padding: 0.8rem 1rem; border-radius: 10px; font-size: 0.88rem; margin-bottom: 0.85rem; font-weight: 500; }
.alert-ok { background: var(--green-bg); color: #065f46; border: 1px solid #a7f3d0; }
.alert-err { background: var(--red-bg); color: #991b1b; border: 1px solid #fecaca; }

pre.json-box {
  background: #0b1324;
  color: #e2e8f0;
  padding: 1.1rem;
  border-radius: 10px;
  overflow-x: auto;
  font-size: 0.8rem;
  max-height: 320px;
  border: 1px solid #1e293b;
}

.subtabs { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-bottom: 1.1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.8rem; }
.subtab-btn {
  padding: 0.5rem 0.95rem;
  border-radius: 9px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: var(--navy);
  font-weight: 600;
  font-size: 0.84rem;
  cursor: pointer;
  transition: all 0.15s ease;
}
.subtab-btn.active { background: var(--navy); color: #fff; border-color: var(--navy); }

.timeline { border-left: 2px solid #cbd5e1; margin-left: 0.5rem; padding-left: 1.1rem; display: flex; flex-direction: column; gap: 0.9rem; }
.timeline-item { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 0.85rem 1rem; position: relative; }
.timeline-item::before {
  content: '';
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--blue);
  border: 2px solid #fff;
  box-shadow: 0 0 0 2px var(--blue);
  position: absolute;
  left: -1.48rem;
  top: 1.05rem;
}

.hash-code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.72rem; color: var(--muted); word-break: break-all; }

.qr-box {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex-wrap: wrap;
  background: linear-gradient(135deg, #f8fafc, #eff6ff);
  border: 1px dashed #93c5fd;
  border-radius: 12px;
  padding: 1rem 1.15rem;
  margin-bottom: 1.1rem;
}

/* ================= PORTAIS PÚBLICOS (DIÁRIO, CIDADÃO, VALIDAÇÃO) ================= */
.public-wrap {
  min-height: 100vh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: 0 0 3rem;
}

.public-hero {
  background:
    radial-gradient(circle at 80% 20%, rgba(16, 185, 129, 0.22), transparent 45%),
    radial-gradient(circle at 15% 80%, rgba(37, 99, 235, 0.28), transparent 45%),
    linear-gradient(135deg, #071124 0%, #0f2347 60%, #163566 100%);
  color: #ffffff;
  padding: 2.4rem 1.5rem 4.6rem;
  position: relative;
}

.public-hero-inner {
  max-width: 960px;
  margin: 0 auto;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}

.public-hero h2 {
  margin: 0.5rem 0 0.25rem;
  font-size: 1.75rem;
  color: #ffffff;
}

.public-hero p {
  margin: 0;
  color: #cbd5e1;
  font-size: 0.92rem;
}

.public-hero .btn-outline {
  background: rgba(255, 255, 255, 0.12);
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(8px);
}
.public-hero .btn-outline:hover { background: rgba(255, 255, 255, 0.22); }

.public-card {
  background: #ffffff;
  width: calc(100% - 2rem);
  max-width: 960px;
  margin: -3rem auto 0;
  border-radius: 16px;
  padding: 1.85rem;
  border: 1px solid rgba(226, 232, 240, 0.95);
  box-shadow: var(--shadow-md);
  position: relative;
  z-index: 2;
  animation: fadeInUp 0.35s ease;
}

.public-footer {
  text-align: center;
  margin-top: 2rem;
  color: var(--muted);
  font-size: 0.8rem;
}
