:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #eef2f6;
  --surface-strong: #172033;
  --border: #d8e0ea;
  --border-strong: #b8c4d4;
  --text: #172033;
  --muted: #64748b;
  --muted-strong: #475569;
  --primary: #2563eb;
  --primary-strong: #1d4ed8;
  --teal: #0f766e;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --shadow: 0 18px 45px rgba(15, 23, 42, 0.08);
  --radius: 8px;
  --font-ui: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "JetBrains Mono", "SFMono-Regular", Consolas, monospace;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(37, 99, 235, 0.08), transparent 280px),
    var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
}

[hidden] {
  display: none !important;
}

button,
select,
input {
  font: inherit;
}

button {
  border: 0;
}

.mono {
  font-family: var(--font-mono);
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.12), transparent 380px),
    var(--bg);
}

.auth-card {
  width: min(100%, 460px);
  padding: 1.25rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.auth-brand {
  margin-bottom: 1.5rem;
}

.auth-copy {
  display: grid;
  gap: 0.65rem;
  margin-bottom: 1.25rem;
}

.auth-copy h1 {
  font-size: clamp(1.7rem, 5vw, 2.35rem);
  line-height: 1.05;
}

.auth-copy p:not(.eyebrow) {
  color: var(--muted-strong);
  line-height: 1.6;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.4rem;
  padding: 0.28rem;
  margin-bottom: 1rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.auth-tab {
  min-height: 38px;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-strong);
  font-weight: 800;
  cursor: pointer;
}

.auth-tab.active {
  background: var(--surface);
  color: var(--primary);
  box-shadow: 0 8px 22px rgba(15, 23, 42, 0.08);
}

.auth-form {
  display: grid;
  gap: 0.85rem;
}

.auth-field {
  display: grid;
  gap: 0.35rem;
}

.auth-field span {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.auth-field input {
  min-height: 44px;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
}

.auth-field input:focus {
  outline: 3px solid rgba(37, 99, 235, 0.14);
  border-color: var(--primary);
}

.auth-message {
  min-height: 1.2rem;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.auth-message.error {
  color: var(--red);
}

.auth-submit,
.auth-demo {
  width: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 68px;
  padding: 0 1.5rem;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  color: inherit;
  text-decoration: none;
  min-width: 0;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  background: var(--surface-strong);
  color: #ffffff;
  font-weight: 800;
  letter-spacing: 0;
}

.brand strong,
.brand small {
  display: block;
  line-height: 1.15;
}

.brand small {
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
}

.topbar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  min-width: 0;
}

.clock {
  color: var(--muted-strong);
  font-size: 0.8rem;
  white-space: nowrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.42rem;
  min-height: 30px;
  padding: 0.25rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted-strong);
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--amber);
  box-shadow: 0 0 0 4px rgba(217, 119, 6, 0.12);
}

.status-pill.online .status-dot {
  background: var(--green);
  box-shadow: 0 0 0 4px rgba(22, 163, 74, 0.12);
}

.status-pill.offline .status-dot {
  background: var(--red);
  box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.12);
}

.user-chip {
  max-width: 180px;
  overflow: hidden;
  padding: 0.35rem 0.7rem;
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted-strong);
  font-size: 0.78rem;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  gap: 1rem;
  overflow-x: hidden;
}

.page-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 380px);
  align-items: end;
  gap: 1rem;
  padding: 1rem 0 0.25rem;
}

.eyebrow {
  margin: 0 0 0.45rem;
  color: var(--teal);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.9rem, 3vw, 3.2rem);
  line-height: 1;
  letter-spacing: 0;
}

.page-subtitle {
  max-width: 760px;
  margin-top: 0.85rem;
  color: var(--muted-strong);
  line-height: 1.65;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1rem;
}

.stat-card {
  position: relative;
  min-height: 138px;
  padding: 1.1rem;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 5px;
  background: var(--accent-color, var(--primary));
}

.accent-blue {
  --accent-color: var(--primary);
}

.accent-green {
  --accent-color: var(--green);
}

.accent-amber {
  --accent-color: var(--amber);
}

.accent-red {
  --accent-color: var(--red);
}

.stat-label,
.stat-sub {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.stat-label {
  text-transform: uppercase;
}

.stat-value {
  display: block;
  margin: 1.25rem 0 0.42rem;
  color: var(--accent-color, var(--text));
  font-size: clamp(2rem, 3vw, 2.8rem);
  line-height: 0.9;
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
  gap: 1rem;
}

.panel {
  min-width: 0;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.panel-header-wide {
  align-items: center;
}

.panel h2 {
  font-size: 1rem;
  line-height: 1.2;
}

.panel p {
  margin-top: 0.28rem;
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.panel-meta {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.chart-wrap {
  position: relative;
  height: 280px;
}

.upload-zone {
  display: grid;
  place-items: center;
  gap: 0.42rem;
  width: 100%;
  min-height: 170px;
  padding: 1rem;
  color: var(--text);
  background: var(--surface-soft);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    background 0.18s ease,
    border-color 0.18s ease,
    transform 0.18s ease;
}

.upload-zone:hover,
.upload-zone.drag-over {
  background: #e8f3f1;
  border-color: var(--teal);
  transform: translateY(-1px);
}

.upload-icon {
  display: grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--teal);
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 800;
}

.upload-title {
  font-weight: 800;
}

.upload-copy,
.file-info {
  color: var(--muted);
  font-size: 0.82rem;
}

input[type="file"] {
  display: none;
}

.upload-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.json-preview {
  margin-top: 1rem;
}

.json-preview pre {
  max-height: 210px;
  margin: 0;
  padding: 1rem;
  overflow: auto;
  background: #101827;
  border-radius: var(--radius);
  color: #dbeafe;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.55;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  padding: 0.55rem 0.95rem;
  border-radius: var(--radius);
  font-weight: 800;
  cursor: pointer;
  transition:
    background 0.18s ease,
    color 0.18s ease,
    opacity 0.18s ease,
    transform 0.18s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.55;
  transform: none;
}

.btn-primary {
  background: var(--primary);
  color: #ffffff;
}

.btn-primary:hover {
  background: var(--primary-strong);
}

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-secondary:hover {
  background: var(--surface-soft);
}

.btn-sm {
  min-height: 34px;
  padding: 0.42rem 0.75rem;
  font-size: 0.82rem;
}

.toolbar {
  display: flex;
  align-items: end;
  justify-content: flex-end;
  gap: 0.65rem;
  flex-wrap: wrap;
}

.field {
  display: grid;
  gap: 0.28rem;
}

.field span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.field select {
  min-width: 140px;
  min-height: 34px;
  padding: 0.35rem 0.55rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.admin-panel {
  border-color: rgba(15, 118, 110, 0.28);
}

.admin-table-wrap table {
  min-width: 860px;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  font-size: 0.86rem;
}

th,
td {
  padding: 0.8rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-soft);
  color: var(--muted-strong);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover td {
  background: #f8fafc;
}

.record-summary {
  max-width: 420px;
  color: var(--text);
  line-height: 1.45;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0.16rem 0.52rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: capitalize;
}

.badge-processed {
  background: rgba(22, 163, 74, 0.12);
  color: #166534;
}

.badge-anomaly {
  background: rgba(217, 119, 6, 0.14);
  color: #92400e;
}

.badge-error {
  background: rgba(220, 38, 38, 0.12);
  color: #991b1b;
}

.badge-admin {
  background: rgba(37, 99, 235, 0.12);
  color: #1d4ed8;
}

.badge-user {
  background: rgba(15, 118, 110, 0.12);
  color: #0f766e;
}

.badge-generic,
.badge-unknown {
  background: rgba(100, 116, 139, 0.12);
  color: var(--muted-strong);
}

.log-stream {
  height: 190px;
  padding: 0.85rem;
  overflow-y: auto;
  background: #101827;
  border-radius: var(--radius);
  color: #dbeafe;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  line-height: 1.7;
}

.log-line {
  display: grid;
  grid-template-columns: 74px minmax(0, 1fr);
  gap: 0.75rem;
}

.log-time {
  color: #94a3b8;
}

.log-info {
  color: #bfdbfe;
}

.log-success {
  color: #86efac;
}

.log-warn {
  color: #fcd34d;
}

.log-error {
  color: #fca5a5;
}

.empty {
  padding: 2.25rem;
  color: var(--muted);
  text-align: center;
}

#toast {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 50;
  max-width: min(420px, calc(100vw - 2.5rem));
  padding: 0.85rem 1rem;
  color: #ffffff;
  background: var(--surface-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(16px);
  pointer-events: none;
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

#toast.success {
  background: #166534;
}

#toast.error {
  background: #991b1b;
}

#toast.warn {
  background: #92400e;
}

@media (max-width: 1100px) {
  .page-heading,
  .content-grid {
    grid-template-columns: 1fr;
  }

  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 0.9rem 1rem;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .app-shell {
    padding: 1rem;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .panel-header,
  .panel-header-wide,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .field select,
  .toolbar .btn,
  .upload-actions .btn {
    width: 100%;
  }

  h1 {
    font-size: 1.72rem;
    overflow-wrap: anywhere;
  }

  .page-subtitle {
    font-size: 0.95rem;
    line-height: 1.6;
    max-width: 100%;
  }

  .clock {
    display: none;
  }
}
