:root {
  --bg: #07111f;
  --bg-2: #0a1830;
  --card: rgba(10, 20, 39, 0.74);
  --card-strong: rgba(14, 28, 52, 0.9);
  --text: #ecf4ff;
  --muted: #92a7c7;
  --line: rgba(126, 167, 255, 0.18);
  --primary: #58f6d2;
  --primary-2: #35d7b4;
  --accent: #72a1ff;
  --accent-2: #ff9f6e;
  --danger: #ff6f91;
  --shadow: 0 24px 80px rgba(0, 0, 0, 0.42);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: "Space Grotesk", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 12% 14%, rgba(61, 103, 255, 0.22) 0%, transparent 28%),
    radial-gradient(circle at 86% 16%, rgba(63, 255, 208, 0.14) 0%, transparent 24%),
    radial-gradient(circle at 50% 88%, rgba(255, 159, 110, 0.12) 0%, transparent 24%),
    linear-gradient(160deg, #040913 0%, #07111f 36%, #081827 72%, #050a12 100%);
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 38px 38px;
  mask-image: linear-gradient(to bottom, rgba(0,0,0,0.5), rgba(0,0,0,0.15));
  pointer-events: none;
  opacity: 0.35;
}

.cosmos-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.mesh {
  position: absolute;
  border-radius: 999px;
  filter: blur(12px);
  opacity: 0.6;
  animation: drift 16s ease-in-out infinite;
}

.mesh-a {
  width: 34vw;
  height: 34vw;
  top: -8vw;
  left: -10vw;
  background: radial-gradient(circle at 30% 30%, rgba(77, 113, 255, 0.72), rgba(77, 113, 255, 0) 72%);
}

.mesh-b {
  width: 28vw;
  height: 28vw;
  top: 14vh;
  right: -6vw;
  background: radial-gradient(circle at 30% 30%, rgba(88, 246, 210, 0.62), rgba(88, 246, 210, 0) 74%);
  animation-delay: 3s;
}

.mesh-c {
  width: 26vw;
  height: 26vw;
  bottom: -8vw;
  left: 30vw;
  background: radial-gradient(circle at 30% 30%, rgba(255, 159, 110, 0.5), rgba(255, 159, 110, 0) 74%);
  animation-delay: 6s;
}

.grid-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at center, rgba(114, 161, 255, 0.1) 0%, transparent 48%);
}

.page { width: 100%; min-height: 100vh; position: relative; z-index: 1; }
.hidden { display: none !important; }

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 100vw;
  margin-left: calc(50% - 50vw);
  padding: 32px;
}

.auth-bg {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, rgba(15, 35, 74, 0.72), rgba(8, 20, 38, 0.4)),
    radial-gradient(circle at 16% 12%, rgba(114, 161, 255, 0.28), transparent 24%),
    radial-gradient(circle at 84% 18%, rgba(88, 246, 210, 0.22), transparent 22%);
}

.orb {
  position: absolute;
  border-radius: 999px;
  filter: blur(18px);
  opacity: 0.44;
  animation: float 14s ease-in-out infinite;
}

.orb-a {
  width: 420px;
  height: 420px;
  background: radial-gradient(circle at 30% 30%, rgba(86, 123, 255, 0.94), rgba(86, 123, 255, 0) 70%);
  top: -90px;
  left: -70px;
}

.orb-b {
  width: 360px;
  height: 360px;
  background: radial-gradient(circle at 30% 30%, rgba(88, 246, 210, 0.82), rgba(88, 246, 210, 0) 70%);
  right: -50px;
  top: 80px;
  animation-delay: 2s;
}

.orb-c {
  width: 320px;
  height: 320px;
  background: radial-gradient(circle at 30% 30%, rgba(255, 159, 110, 0.76), rgba(255, 159, 110, 0) 70%);
  bottom: -90px;
  left: 42%;
  animation-delay: 4s;
}

.auth-shell {
  width: 100%;
  max-width: 1160px;
  display: grid;
  grid-template-columns: 1.25fr 0.95fr;
  gap: 22px;
  position: relative;
  z-index: 2;
}

.auth-hero,
.auth-card,
.card,
.topbar {
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.auth-hero {
  border-radius: 30px;
  padding: 40px;
  background: linear-gradient(145deg, rgba(14, 31, 60, 0.82), rgba(10, 22, 42, 0.56));
}

.auth-kicker,
.top-kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.28em;
  color: #7fb4ff;
  font-weight: 700;
  text-transform: uppercase;
}

.auth-hero h1 {
  margin: 16px 0 0;
  font-size: 50px;
  line-height: 1.02;
}

.auth-copy {
  margin-top: 18px;
  max-width: 520px;
  color: #c5d7f4;
  font-size: 17px;
  line-height: 1.6;
}

.auth-card {
  width: 100%;
  background: rgba(8, 18, 35, 0.8);
  border-radius: 28px;
  padding: 30px;
}

.auth-card h2 { margin: 0; font-size: 32px; }
.auth-card p { margin: 8px 0 18px; color: var(--muted); }

.app-wrap {
  max-width: 1380px;
  margin: 0 auto;
  padding: 28px;
  min-height: 100vh;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 22px;
  background:
    linear-gradient(135deg, rgba(11, 28, 56, 0.82), rgba(8, 20, 38, 0.72)),
    linear-gradient(90deg, rgba(88,246,210,0.08), rgba(114,161,255,0.08));
  border-radius: 22px;
  padding: 22px 24px;
}

.topbar-main h1 {
  margin: 8px 0 0;
  font-size: 40px;
  letter-spacing: -0.03em;
}

.topbar-main p { margin: 10px 0 0; color: #c3d4f0; }
.top-actions { display: flex; align-items: center; gap: 10px; }

.badge {
  border: 1px solid rgba(126, 167, 255, 0.24);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  padding: 10px 16px;
  color: #e4eeff;
  font-size: 14px;
}

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }

.card {
  background:
    linear-gradient(155deg, rgba(12, 23, 43, 0.9), rgba(9, 18, 35, 0.78)),
    linear-gradient(180deg, rgba(255,255,255,0.03), rgba(255,255,255,0));
  border-radius: 22px;
  padding: 20px;
  position: relative;
  overflow: hidden;
  transition: transform 180ms ease, border-color 180ms ease, box-shadow 180ms ease;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(114,161,255,0.12), transparent 40%, rgba(88,246,210,0.06));
  opacity: 0;
  transition: opacity 180ms ease;
  pointer-events: none;
}

.card:hover {
  transform: translateY(-6px) scale(1.015);
  border-color: rgba(114, 161, 255, 0.36);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.48);
}

.card:hover::before { opacity: 1; }

.card h2 { margin: 0; font-size: 20px; }
.card p { margin: 8px 0 14px; color: var(--muted); font-size: 14px; line-height: 1.6; }

input, textarea, button, select {
  font: inherit;
}

input, textarea, select {
  width: 100%;
  border: 1px solid rgba(126, 167, 255, 0.18);
  border-radius: 14px;
  padding: 12px 14px;
  background: rgba(4, 10, 19, 0.58);
  color: var(--text);
  margin-bottom: 8px;
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

input::placeholder,
textarea::placeholder { color: rgba(188, 206, 236, 0.5); }

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: rgba(88, 246, 210, 0.54);
  box-shadow: 0 0 0 3px rgba(88, 246, 210, 0.08);
  transform: translateY(-1px);
}

textarea { resize: vertical; min-height: 140px; }

button {
  border: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #031017;
  border-radius: 14px;
  padding: 11px 15px;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.01em;
  transition: transform 160ms ease, box-shadow 160ms ease, filter 160ms ease;
}

button:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 14px 36px rgba(53, 215, 180, 0.22);
  filter: saturate(1.08);
}

.btn-light {
  background: rgba(255, 255, 255, 0.06);
  color: #dbe8ff;
  border: 1px solid rgba(126, 167, 255, 0.18);
}

.btn-light:hover {
  box-shadow: 0 14px 36px rgba(114, 161, 255, 0.14);
}

.row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.chat-card { display: flex; flex-direction: column; }

.chat-window,
.qr-wrap,
.clients-table,
.ingest-item,
.ingest-empty,
.wa-status,
.wa-help,
.import-summary {
  background: rgba(4, 10, 19, 0.46);
  border: 1px solid rgba(126, 167, 255, 0.14);
}

.chat-window {
  border-radius: 16px;
  height: 290px;
  overflow-y: auto;
  padding: 12px;
}

.chat-msg {
  margin: 8px 0;
  padding: 10px 12px;
  border-radius: 14px;
  max-width: 92%;
  white-space: pre-wrap;
}

.chat-msg.user {
  background: linear-gradient(135deg, rgba(88, 246, 210, 0.24), rgba(53, 215, 180, 0.12));
  margin-left: auto;
}

.chat-msg.bot {
  background: linear-gradient(135deg, rgba(114, 161, 255, 0.18), rgba(114, 161, 255, 0.08));
}

.chat-controls { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.chat-controls input { flex: 1; min-width: 200px; }

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.settings-grid label {
  display: block;
  font-size: 13px;
  color: #b9cae8;
}

.settings-grid span {
  display: block;
  margin-bottom: 6px;
  font-weight: 700;
  color: #e4eeff;
}

.wa-status,
.wa-help,
.import-summary {
  border-radius: 14px;
  padding: 12px;
}

.wa-status { color: #dbe7ff; margin-bottom: 10px; }
.wa-help { margin-top: 10px; font-size: 13px; color: #d4e2ff; }
.wa-help strong { display: block; margin-bottom: 6px; color: #82fff0; }
.wa-help ol { margin: 0; padding-left: 18px; }
.wa-help li { margin: 4px 0; }

.qr-wrap {
  margin-top: 12px;
  border-radius: 16px;
  min-height: 220px;
  display: flex;
  align-items: center;
  justify-content: center;
}

#waQrImage {
  max-width: 320px;
  width: 100%;
  display: none;
  image-rendering: pixelated;
}

.ingest-history-wrap {
  margin-top: 14px;
  border-top: 1px solid rgba(126, 167, 255, 0.12);
  padding-top: 12px;
}

.ingest-history-wrap h3 {
  margin: 0 0 10px;
  font-size: 14px;
  color: #dce8ff;
}

.ingest-history-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  margin-bottom: 8px;
}

.ingest-mini-btn {
  padding: 7px 10px;
  font-size: 12px;
}

.ingest-history {
  display: grid;
  gap: 10px;
  max-height: 260px;
  overflow: auto;
}

.ingest-empty {
  border-radius: 14px;
  padding: 12px;
  color: var(--muted);
}

.ingest-item {
  border-radius: 14px;
  padding: 10px;
}

.ingest-item-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-size: 12px;
  color: #95aeff;
  margin-bottom: 6px;
}

.ingest-item-head input[type="checkbox"] {
  margin-right: 6px;
}

.ingest-item p {
  margin: 0 0 8px;
  color: #ebf4ff;
  font-size: 13px;
  line-height: 1.45;
}

.ingest-use-btn {
  padding: 8px 10px;
  font-size: 13px;
}

.import-summary {
  margin-top: 12px;
  display: grid;
  gap: 6px;
  color: #dbe7ff;
  font-size: 13px;
}

.wide-card { grid-column: 1 / -1; }

.dashboard-card {
  background:
    linear-gradient(140deg, rgba(18, 35, 65, 0.92), rgba(10, 22, 41, 0.86)),
    radial-gradient(circle at 84% 16%, rgba(88, 246, 210, 0.12), transparent 30%);
}

.dashboard-top {
  margin-bottom: 16px;
}

.dashboard-kpis {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.kpi-box {
  border: 1px solid rgba(126, 167, 255, 0.22);
  border-radius: 14px;
  background: rgba(5, 12, 23, 0.48);
  padding: 12px;
}

.kpi-label {
  display: block;
  color: #a9c0e8;
  font-size: 12px;
  margin-bottom: 6px;
}

.kpi-box strong {
  font-size: 22px;
  letter-spacing: -0.02em;
}

.dashboard-series {
  margin-top: 14px;
  display: grid;
  gap: 8px;
}

.series-row {
  display: grid;
  grid-template-columns: 70px 1fr auto;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.series-bar-wrap {
  height: 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.series-bar {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #58f6d2, #72a1ff);
}

.clients-table {
  margin-top: 12px;
  overflow: auto;
  border-radius: 16px;
}

.clients-table table {
  width: 100%;
  border-collapse: collapse;
}

.clients-table th,
.clients-table td {
  padding: 12px;
  border-bottom: 1px solid rgba(126, 167, 255, 0.12);
  text-align: left;
  font-size: 13px;
}

.clients-table th {
  background: rgba(255, 255, 255, 0.04);
  color: #9fc2ff;
}

small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
}

#loginStatus {
  min-height: 20px;
  color: #ff93ae;
  font-weight: 600;
}

@media (max-width: 980px) {
  .auth-shell { grid-template-columns: 1fr; }
  .auth-hero { padding: 28px; }
  .auth-hero h1 { font-size: 36px; }
  .grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
  .dashboard-kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar { flex-direction: column; align-items: flex-start; gap: 10px; }
}

@keyframes float {
  0% { transform: translateY(0px) translateX(0px); }
  50% { transform: translateY(-18px) translateX(10px); }
  100% { transform: translateY(0px) translateX(0px); }
}

@keyframes drift {
  0% { transform: translate3d(0, 0, 0) scale(1); }
  50% { transform: translate3d(20px, -20px, 0) scale(1.06); }
  100% { transform: translate3d(0, 0, 0) scale(1); }
}
