:root {
  --bg: #06090d;
  --bg-elevated: #0c1118;
  --surface: rgba(17, 24, 32, 0.85);
  --surface2: #151d28;
  --border: rgba(148, 163, 184, 0.12);
  --border-strong: rgba(245, 158, 11, 0.25);
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #f59e0b;
  --accent2: #ea580c;
  --accent-glow: rgba(245, 158, 11, 0.35);
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 14px;
  --radius-sm: 10px;
  --font: "DM Sans", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, 0.55);
}

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

html { -webkit-font-smoothing: antialiased; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  background-image:
    radial-gradient(ellipse 100% 80% at 50% -30%, rgba(245, 158, 11, 0.15), transparent 55%),
    radial-gradient(ellipse 50% 40% at 100% 50%, rgba(234, 88, 12, 0.06), transparent),
    radial-gradient(ellipse 40% 30% at 0% 80%, rgba(59, 130, 246, 0.04), transparent);
}

.hidden { display: none !important; }

.logo-img { display: block; object-fit: contain; }
.logo-sm { width: 44px; height: 44px; }

/* ——— Login ——— */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
}
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  backdrop-filter: blur(20px);
  border: 1px solid var(--border-strong);
  border-radius: 20px;
  padding: 2.75rem 2.5rem;
  box-shadow: var(--shadow-lg);
}
.login-card .logo-img {
  width: 88px;
  height: 88px;
  margin: 0 auto 1.25rem;
  filter: drop-shadow(0 8px 24px var(--accent-glow));
}
.login-card h1 {
  text-align: center;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fbbf24, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.login-card p {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0.6rem 0 1.75rem;
}

/* ——— App shell ——— */
.app {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 260px;
  min-height: 100vh;
  height: 100vh;
  position: sticky;
  top: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  padding: 1.5rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
}
.sidebar-footer {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}
.sidebar-user-email {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 0.65rem;
  word-break: break-all;
}
.btn-logout {
  width: 100%;
  color: #fca5a5 !important;
  border-color: rgba(239, 68, 68, 0.35) !important;
}
.btn-logout:hover {
  background: rgba(239, 68, 68, 0.12) !important;
  color: #fecaca !important;
}
.app-topbar {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.25rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.topbar-user {
  font-size: 0.85rem;
  color: var(--muted);
}
.brand {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  margin-bottom: 1.75rem;
  padding: 0.75rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px solid var(--border);
}
.brand > div { min-width: 0; }
.brand .logo-sm { flex-shrink: 0; }
.tenant-badge {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 0.2rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tenant-badge strong { color: var(--accent); font-weight: 600; }
.brand > div > span:first-child {
  display: block;
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: 0.12em;
  background: linear-gradient(135deg, #fbbf24, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.nav { flex: 1; }
.nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.7rem 1rem;
  color: var(--muted);
  text-decoration: none;
  border-radius: var(--radius-sm);
  margin-bottom: 0.2rem;
  font-size: 0.9rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.nav a:hover {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}
.nav a.active {
  background: linear-gradient(90deg, rgba(245, 158, 11, 0.18), rgba(245, 158, 11, 0.05));
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.2);
}
.nav-platform {
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border);
}
.nav-platform.active {
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.15), rgba(59, 130, 246, 0.05));
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.25);
}
.main {
  flex: 1;
  padding: 1.75rem 2rem 2.5rem;
  overflow: auto;
  min-height: 100vh;
}
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
  gap: 1rem;
}
.page-header h2 {
  font-size: 1.65rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

/* ——— Cards ——— */
.grid { display: grid; gap: 1.15rem; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.card {
  background: var(--surface);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.35rem 1.5rem;
  box-shadow: var(--shadow);
}
.card h3 {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}
.stat-value {
  font-size: 2.25rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  background: linear-gradient(135deg, #fbbf24, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.stat-label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.35rem;
  font-weight: 500;
}

/* ——— Forms ——— */
input, select, textarea, button { font-family: inherit; font-size: 0.9rem; }
input, select, textarea {
  width: 100%;
  padding: 0.7rem 1rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  margin-bottom: 0.85rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: #64748b; }

/* API Token: type=text permite pegar; máscara visual opcional */
.token-field {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  margin-bottom: 0.85rem;
}
.token-field .token-input {
  flex: 1;
  margin-bottom: 0;
  font-family: var(--mono);
  font-size: 0.82rem;
  letter-spacing: 0.02em;
}
.token-input.token-masked {
  -webkit-text-security: disc;
}
.token-field .token-toggle {
  flex-shrink: 0;
  align-self: center;
  white-space: nowrap;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.12s, filter 0.15s, box-shadow 0.15s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.98); }
.btn-primary {
  background: linear-gradient(135deg, #fbbf24, var(--accent), var(--accent2));
  color: #0a0a0a;
  box-shadow: 0 4px 20px var(--accent-glow);
}
.btn-ghost {
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text); border-color: var(--muted); }
.btn-sm { padding: 0.45rem 0.9rem; font-size: 0.8rem; }

/* ——— Tables ——— */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
}
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th, td {
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: rgba(0, 0, 0, 0.2);
}
tbody tr:hover td { background: rgba(245, 158, 11, 0.04); }
.mono { font-family: var(--mono); font-size: 0.8rem; color: #cbd5e1; }

.badge {
  display: inline-block;
  padding: 0.25rem 0.55rem;
  border-radius: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-critical { background: rgba(239, 68, 68, 0.2); color: #fca5a5; }
.badge-high { background: rgba(249, 115, 22, 0.2); color: #fdba74; }
.badge-medium { background: rgba(245, 158, 11, 0.2); color: #fcd34d; }
.badge-low { background: rgba(59, 130, 246, 0.2); color: #93c5fd; }
.badge-open { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.badge-resolved { background: rgba(34, 197, 94, 0.15); color: #86efac; }

.chart-box {
  height: 280px;
  position: relative;
  margin-top: 0.5rem;
}

/* ——— Cloudflare setup ——— */
.setup-card {
  border-color: var(--border-strong);
  background: linear-gradient(145deg, rgba(245, 158, 11, 0.06), transparent 50%), var(--surface);
}
.setup-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.setup-desc { color: var(--muted); font-size: 0.875rem; line-height: 1.6; max-width: 52rem; }
.setup-hint { color: #64748b; font-size: 0.75rem; margin: -0.25rem 0 0.85rem; line-height: 1.45; }
.setup-form label {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}
.setup-form .setup-full { grid-column: 1 / -1; }
.setup-form .setup-actions {
  display: flex;
  align-items: flex-end;
  padding-bottom: 0.85rem;
}
.setup-badge {
  display: inline-block;
  padding: 0.4rem 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
}
.setup-ok { background: rgba(34, 197, 94, 0.15); color: #86efac; border: 1px solid rgba(34, 197, 94, 0.25); }
.setup-warn { background: rgba(245, 158, 11, 0.12); color: #fcd34d; border: 1px solid rgba(245, 158, 11, 0.25); }
.cf-zones-list { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.zone-chip {
  padding: 0.65rem 0;
  font-size: 0.85rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.zone-chip { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.zone-chip strong { color: var(--text); }
.zone-chip .plat-actions { margin-left: auto; }

.usage-card { border-color: rgba(34, 197, 94, 0.25); }
.usage-detail-box {
  font-size: 0.82rem;
  color: var(--muted);
  background: var(--bg-elevated);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  line-height: 1.5;
}
.usage-detail-box strong { color: var(--text); }
.usage-metric { font-size: 1.35rem; font-weight: 600; color: var(--accent); }
.usage-metric-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.app-topbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.topbar-zone-label { font-size: 0.75rem; color: var(--muted); margin: 0; }
.topbar-zone-select {
  max-width: 220px;
  margin: 0 !important;
  font-size: 0.8rem;
}
.topbar-user { margin-left: auto; }
.plat-edit-card { border-color: rgba(59, 130, 246, 0.35); }
.plat-actions { display: flex; gap: 0.35rem; flex-wrap: wrap; }
.plat-actions .btn { padding: 0.35rem 0.55rem; font-size: 0.72rem; }

.page { display: block; }
.page.hidden { display: none !important; }

.toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 1rem 1.35rem;
  background: var(--surface2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  font-size: 0.9rem;
  max-width: 360px;
  animation: slideIn 0.3s ease;
}
@keyframes slideIn {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

#report-output {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 1rem;
}

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    min-height: auto;
    position: relative;
    flex-direction: column;
    align-items: stretch;
  }
  .brand { margin-bottom: 0.5rem; }
  .nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    flex: none;
  }
  .nav a { padding: 0.5rem 0.75rem; font-size: 0.8rem; }
  .sidebar-footer {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: wrap;
  }
  .sidebar-footer .btn-logout { width: auto; }
  .sidebar-user-email { margin-bottom: 0; flex: 1; }
  .main { padding: 1.25rem; }
  .app-topbar { display: flex; }
}
