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

:root {
  --bg: #070b14;
  --card: rgba(14, 22, 40, 0.9);
  --text: #e8eefc;
  --muted: #9aa8c7;
  --accent: #3d8bfd;
  --accent-2: #00e5c0;
  --border: rgba(61, 139, 253, 0.25);
  --danger: #ff6b8a;
  --ok: #3dde9e;
  --input: rgba(7, 12, 24, 0.9);
  --radius: 18px;
  --pad: clamp(0.85rem, 2.5vw, 1.5rem);
  --tap: 44px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --max-dash: 1100px;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
}

html,
body {
  min-height: 100%;
  min-height: 100dvh;
}

body {
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(0.75rem, var(--safe-top))
    max(0.75rem, var(--safe-right))
    max(0.75rem, var(--safe-bottom))
    max(0.75rem, var(--safe-left));
  overflow-x: hidden;
  position: relative;
  -webkit-font-smoothing: antialiased;
  line-height: 1.45;
}

img,
svg,
video {
  max-width: 100%;
  height: auto;
}

a {
  color: var(--accent-2);
  word-break: break-word;
}

button,
input,
select,
textarea {
  font: inherit;
  max-width: 100%;
  touch-action: manipulation;
}

/* Background */
.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(61, 139, 253, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(61, 139, 253, 0.06) 1px, transparent 1px);
  background-size: clamp(28px, 6vw, 48px) clamp(28px, 6vw, 48px);
  mask-image: radial-gradient(ellipse at center, black 20%, transparent 70%);
  -webkit-mask-image: radial-gradient(ellipse at center, black 20%, transparent 70%);
  pointer-events: none;
  z-index: 0;
}

.glow {
  position: fixed;
  border-radius: 50%;
  filter: blur(80px);
  pointer-events: none;
  z-index: 0;
}

.glow-1 {
  width: min(420px, 70vw);
  height: min(420px, 70vw);
  background: rgba(61, 139, 253, 0.28);
  top: -80px;
  right: -60px;
}

.glow-2 {
  width: min(360px, 65vw);
  height: min(360px, 65vw);
  background: rgba(0, 229, 192, 0.18);
  bottom: -100px;
  left: -40px;
}

/* Login */
.page-login {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding:
    max(1rem, var(--safe-top))
    max(1rem, var(--safe-right))
    max(1rem, var(--safe-bottom))
    max(1rem, var(--safe-left));
  gap: 0.5rem;
}

.card {
  position: relative;
  z-index: 1;
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: clamp(16px, 4vw, 24px);
  padding: clamp(1.25rem, 4vw, 2rem) clamp(1rem, 3.5vw, 1.6rem) clamp(1.15rem, 3vw, 1.75rem);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.03) inset,
    0 24px 64px rgba(0, 0, 0, 0.45);
  animation: rise 0.7s ease-out both;
}

.login-card {
  text-align: center;
}

.brand-logo-wrap {
  display: flex;
  justify-content: center;
  margin: 0 auto 1rem;
}

.brand-logo {
  width: clamp(112px, 32vw, 160px);
  height: auto;
  aspect-ratio: 1;
  border-radius: 18px;
  object-fit: cover;
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.08),
    0 12px 32px rgba(26, 35, 126, 0.45);
}

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

.badge {
  display: inline-block;
  font-size: clamp(0.68rem, 2.5vw, 0.72rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-2);
  background: rgba(0, 229, 192, 0.1);
  border: 1px solid rgba(0, 229, 192, 0.3);
  border-radius: 999px;
  padding: 0.35rem 0.85rem;
  margin-bottom: 1rem;
  max-width: 100%;
  overflow-wrap: anywhere;
}

h1 {
  font-family: "Orbitron", system-ui, sans-serif;
  font-weight: 700;
  font-size: clamp(1.85rem, 8vw, 3rem);
  line-height: 1.05;
  letter-spacing: 0.04em;
  background: linear-gradient(135deg, #fff 20%, var(--accent) 55%, var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  margin-bottom: 0.55rem;
}

.tagline {
  font-size: clamp(1rem, 3.5vw, 1.1rem);
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.tagline span {
  color: var(--accent-2);
}

.sub {
  color: var(--muted);
  font-size: clamp(0.88rem, 3vw, 0.95rem);
  line-height: 1.5;
  margin-bottom: 1.4rem;
}

.login-form {
  text-align: left;
  display: grid;
  gap: 0.95rem;
  margin-bottom: 1.25rem;
}

.field {
  display: grid;
  gap: 0.4rem;
  min-width: 0;
}

.field label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-height: var(--tap);
  border: 1px solid rgba(154, 168, 199, 0.22);
  background: var(--input);
  color: var(--text);
  border-radius: 12px;
  padding: 0.78rem 0.9rem;
  font: inherit;
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
  -webkit-appearance: none;
  appearance: none;
}

.field select {
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) calc(50% - 3px), calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
  padding-right: 2.2rem;
}

.field textarea {
  resize: vertical;
  min-height: 96px;
  line-height: 1.4;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: rgba(61, 139, 253, 0.7);
  box-shadow: 0 0 0 3px rgba(61, 139, 253, 0.15);
}

.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.password-wrap input {
  padding-right: 4.4rem;
}

.toggle-pass {
  position: absolute;
  right: 0.35rem;
  min-height: 36px;
  min-width: 52px;
  border: 0;
  background: transparent;
  color: var(--accent-2);
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  padding: 0.35rem 0.55rem;
  border-radius: 8px;
}

.toggle-pass:hover,
.toggle-pass:focus-visible {
  background: rgba(0, 229, 192, 0.08);
  outline: none;
}

.btn-primary {
  border: 0;
  border-radius: 12px;
  min-height: var(--tap);
  padding: 0.85rem 1rem;
  width: 100%;
  font: inherit;
  font-weight: 600;
  font-size: 1rem;
  color: #041018;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 28px rgba(61, 139, 253, 0.28);
}

.btn-primary:hover {
  filter: brightness(1.05);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-ghost {
  border: 1px solid rgba(154, 168, 199, 0.25);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: 10px;
  min-height: 40px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
}

.btn-ghost:hover,
.btn-ghost:focus-visible {
  border-color: rgba(61, 139, 253, 0.45);
  outline: none;
}

.btn-tiny {
  border: 1px solid rgba(255, 107, 138, 0.35);
  background: rgba(255, 107, 138, 0.08);
  color: #ffb3c3;
  border-radius: 8px;
  min-height: 36px;
  padding: 0.35rem 0.65rem;
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
}

.form-error {
  color: var(--danger);
  font-size: 0.88rem;
}

.form-ok {
  color: var(--ok);
  font-size: 0.88rem;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  justify-content: center;
}

.chips span {
  font-size: 0.75rem;
  color: var(--muted);
  border: 1px solid rgba(154, 168, 199, 0.25);
  border-radius: 999px;
  padding: 0.3rem 0.65rem;
  background: rgba(255, 255, 255, 0.03);
}

footer,
.foot {
  position: relative;
  z-index: 1;
  margin-top: 1.25rem;
  padding-bottom: 0.25rem;
  font-size: clamp(0.78rem, 2.8vw, 0.85rem);
  color: var(--muted);
  text-align: center;
  width: min(100%, var(--max-dash));
  margin-left: auto;
  margin-right: auto;
}

/* Main dashboard */
.page-main {
  max-width: var(--max-dash);
  margin: 0 auto;
  padding:
    max(0.65rem, var(--safe-top))
    max(0.65rem, var(--safe-right))
    max(1.25rem, var(--safe-bottom))
    max(0.65rem, var(--safe-left));
  width: 100%;
}

.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 0.85rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: clamp(0.85rem, 2vw, 1.25rem);
  padding: clamp(0.7rem, 2vw, 0.9rem) clamp(0.75rem, 2.5vw, 1.1rem);
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(14, 22, 40, 0.75);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.topbar-brand {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 0.7rem 0.85rem;
  min-width: 0;
  flex: 1 1 auto;
}

.topbar-logo {
  width: clamp(40px, 10vw, 48px);
  height: clamp(40px, 10vw, 48px);
  border-radius: 10px;
  object-fit: cover;
  flex: 0 0 auto;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.1);
}

.topbar-titles {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
  min-width: 0;
}

.topbar-brand .badge {
  margin: 0;
}

.topbar-brand strong {
  font-size: clamp(0.92rem, 3vw, 1rem);
  overflow-wrap: anywhere;
}

.topbar-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.55rem 0.75rem;
  margin-left: auto;
}

.who {
  color: var(--accent-2);
  font-size: clamp(0.82rem, 2.8vw, 0.9rem);
  font-weight: 600;
  max-width: 100%;
  overflow-wrap: anywhere;
}

.dashboard {
  position: relative;
  z-index: 1;
  display: grid;
  gap: clamp(0.85rem, 2vw, 1.15rem);
  grid-template-columns: 1fr;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: rgba(14, 22, 40, 0.82);
  padding: clamp(1rem, 3vw, 1.35rem);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
  min-width: 0;
}

.panel-head {
  margin-bottom: 1rem;
}

.panel-head h2 {
  font-family: "Orbitron", system-ui, sans-serif;
  font-size: clamp(1rem, 3.5vw, 1.2rem);
  letter-spacing: 0.04em;
  margin-bottom: 0.35rem;
}

.panel-head p {
  color: var(--muted);
  font-size: clamp(0.85rem, 2.8vw, 0.92rem);
}

.stack-form {
  display: grid;
  gap: 0.85rem;
  margin-bottom: 1rem;
}

.field-row {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
}

.btn-row .btn-primary,
.btn-row .btn-ghost {
  flex: 1 1 auto;
  min-width: min(100%, 140px);
  width: auto;
}

.stack-form > .btn-primary {
  width: 100%;
  max-width: 280px;
}

.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid rgba(154, 168, 199, 0.15);
  border-radius: 12px;
  max-width: 100%;
}

.data-table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  font-size: clamp(0.82rem, 2.5vw, 0.9rem);
}

.data-table th,
.data-table td {
  padding: 0.7rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid rgba(154, 168, 199, 0.12);
  vertical-align: middle;
}

.data-table th {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}

.data-table code {
  color: var(--accent-2);
  font-size: 0.86rem;
  word-break: break-all;
}

.muted,
.empty {
  color: var(--muted);
  font-size: 0.9rem;
}

.user-cards {
  display: none;
  gap: 0.65rem;
}

.user-card {
  border: 1px solid rgba(154, 168, 199, 0.18);
  border-radius: 12px;
  padding: 0.85rem 0.95rem;
  background: rgba(7, 12, 24, 0.65);
  display: grid;
  gap: 0.45rem;
}

.user-card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.user-card-meta {
  font-size: 0.78rem;
  color: var(--muted);
}

.http-help {
  border: 1px dashed rgba(61, 139, 253, 0.35);
  border-radius: 12px;
  padding: clamp(0.75rem, 2.5vw, 0.95rem) clamp(0.8rem, 2.5vw, 1rem);
  margin-bottom: 1rem;
  background: rgba(61, 139, 253, 0.06);
}

.http-help .label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.http-help code {
  display: block;
  color: var(--accent-2);
  font-size: clamp(0.78rem, 2.5vw, 0.86rem);
  word-break: break-all;
  margin-bottom: 0.55rem;
}

.http-help .hint {
  color: var(--muted);
  font-size: clamp(0.8rem, 2.6vw, 0.86rem);
  line-height: 1.5;
  margin-top: 0.55rem;
}

.http-help code.inline {
  display: inline;
  color: #cfe0ff;
  font-size: 0.8rem;
}

.link-list {
  list-style: none;
  display: grid;
  gap: 0.55rem;
  margin: 0.35rem 0 0;
  padding: 0;
}

.link-list li {
  min-width: 0;
}

.link-list a {
  display: block;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid rgba(154, 168, 199, 0.18);
  background: rgba(7, 12, 24, 0.55);
  color: var(--accent-2);
  text-decoration: none;
  font-size: clamp(0.75rem, 2.4vw, 0.84rem);
  line-height: 1.4;
  word-break: break-all;
  overflow-wrap: anywhere;
}

.link-list a:hover,
.link-list a:focus-visible {
  border-color: rgba(61, 139, 253, 0.5);
  background: rgba(61, 139, 253, 0.1);
  outline: none;
}

.data-list {
  display: grid;
  gap: 0.65rem;
  max-height: min(420px, 55vh);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-right: 2px;
}

.data-item {
  border: 1px solid rgba(154, 168, 199, 0.18);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  background: rgba(7, 12, 24, 0.65);
  min-width: 0;
}

.data-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.data-meta .src {
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.data-item pre {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: clamp(0.78rem, 2.5vw, 0.86rem);
  color: var(--text);
  line-height: 1.45;
  max-width: 100%;
}

/* Ingest */
.page-ingest {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding:
    max(1rem, var(--safe-top))
    max(1rem, var(--safe-right))
    max(1rem, var(--safe-bottom))
    max(1rem, var(--safe-left));
}

.ingest-card {
  text-align: center;
  width: min(480px, 100%);
}

.ingest-pre {
  text-align: left;
  margin: 0.75rem 0 1rem;
  padding: 0.85rem;
  border-radius: 12px;
  background: rgba(7, 12, 24, 0.8);
  border: 1px solid rgba(154, 168, 199, 0.18);
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: clamp(0.82rem, 2.6vw, 0.9rem);
  max-width: 100%;
  overflow-x: auto;
}

.page-ingest .hint a {
  color: var(--accent-2);
  display: inline-block;
  padding: 0.35rem 0;
  min-height: 44px;
  line-height: 44px;
}

/* ========== Breakpoints: phone / tablet / laptop ========== */

@media (max-width: 380px) {
  .topbar-actions {
    width: 100%;
    justify-content: space-between;
  }

  .btn-row .btn-primary,
  .btn-row .btn-ghost {
    min-width: 100%;
  }

  .stack-form > .btn-primary {
    max-width: none;
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .topbar-brand {
    width: 100%;
  }

  .topbar-actions {
    width: 100%;
    margin-left: 0;
    justify-content: space-between;
  }

  .table-wrap.desktop-only {
    display: none;
  }

  .user-cards {
    display: grid;
  }

  .data-table {
    min-width: 0;
  }

  .glow-1,
  .glow-2 {
    opacity: 0.7;
  }
}

@media (min-width: 641px) and (max-width: 900px) {
  .page-main {
    padding-left: max(1rem, var(--safe-left));
    padding-right: max(1rem, var(--safe-right));
  }

  .field-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field-row .field:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .dashboard {
    gap: 1rem;
  }

  .btn-row .btn-primary,
  .btn-row .btn-ghost {
    flex: 0 1 auto;
    min-width: 120px;
  }

  .stack-form > .btn-primary {
    width: auto;
  }
}

@media (min-width: 901px) {
  .page-main {
    padding: 1.25rem 1.5rem 2rem;
  }

  .field-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .dashboard {
    gap: 1.2rem;
  }

  .stack-form > .btn-primary {
    width: auto;
    min-width: 160px;
  }

  .btn-row .btn-primary {
    width: auto;
    max-width: none;
    flex: 0 0 auto;
  }

  .btn-row .btn-ghost {
    flex: 0 0 auto;
  }

  .data-list {
    max-height: 480px;
  }

  .card {
    width: min(440px, 100%);
  }
}

@media (min-width: 1024px) {
  .dashboard {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr);
    align-items: start;
  }

  .dashboard > .panel {
    min-height: 0;
  }

  .data-list {
    max-height: min(560px, calc(100vh - 220px));
  }
}

@media (min-width: 1280px) {
  :root {
    --max-dash: 1200px;
  }

  .panel {
    padding: 1.5rem;
  }
}

@media (max-height: 480px) and (orientation: landscape) {
  .page-login {
    justify-content: flex-start;
    padding-top: 1rem;
  }

  .page-ingest {
    align-items: flex-start;
    padding-top: 1rem;
  }

  .data-list {
    max-height: 220px;
  }
}

@media (hover: none) and (pointer: coarse) {
  .btn-primary,
  .btn-ghost,
  .btn-tiny,
  .toggle-pass,
  .link-list a {
    min-height: var(--tap);
  }

  .data-table th,
  .data-table td {
    padding: 0.85rem 0.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .card {
    animation: none;
  }

  html {
    scroll-behavior: auto;
  }

  .btn-primary:active {
    transform: none;
  }
}

@media print {
  .bg-grid,
  .glow,
  .topbar-actions {
    display: none !important;
  }

  body {
    background: #fff;
    color: #000;
  }

  .panel,
  .card,
  .topbar {
    box-shadow: none;
    border-color: #ccc;
    background: #fff;
  }
}
