:root {
  --brand-50: #f0f9ff;
  --brand-100: #e0f2fe;
  --brand-200: #bae6fd;
  --brand-400: #38bdf8;
  --brand-500: #0ea5e9;
  --brand-600: #0284c7;
  --ink-200: #e2e8f0;
  --ink-300: #cbd5e1;
  --ink-400: #94a3b8;
  --ink-500: #64748b;
  --ink-600: #475569;
  --ink-800: #1e293b;
  --ink-900: #0f172a;
  --canvas: #f5fafe;
  --white: #fff;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px -12px rgba(14, 165, 233, 0.25);
  --font-display: 'Outfit', ui-sans-serif, system-ui, sans-serif;
  --font-sans: 'Inter', ui-sans-serif, system-ui, sans-serif;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--canvas);
  color: var(--ink-800);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.logo {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--ink-900);
  margin: 0;
}

.logo-sm {
  font-size: 1.15rem;
}

.dot {
  color: var(--brand-500);
}

/* --- Login --- */

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(at 20% 10%, #e0f2fe 0, transparent 50%),
    radial-gradient(at 80% 0%, #bae6fd 0, transparent 45%),
    var(--canvas);
}

.login-card {
  width: 100%;
  max-width: 22rem;
  background: var(--white);
  border: 1px solid var(--brand-100);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  padding: 1.75rem 1.5rem;
}

.login-card .logo {
  font-size: 1.75rem;
  text-align: center;
}

.login-sub {
  text-align: center;
  color: var(--ink-500);
  font-size: 0.9rem;
  margin: 0.35rem 0 1.35rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--ink-600);
  margin-bottom: 1rem;
}

.field input,
.filters input,
.filters select,
.range-field select {
  font: inherit;
  border: 1px solid var(--ink-200);
  border-radius: 0.75rem;
  padding: 0.65rem 0.8rem;
  background: var(--white);
  color: var(--ink-800);
}

.field input:focus,
.filters input:focus,
.filters select:focus,
.range-field select:focus {
  outline: none;
  border-color: var(--brand-400);
  box-shadow: 0 0 0 3px var(--brand-100);
}

.error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
}

.hint {
  margin: 1rem 0 0;
  font-size: 0.75rem;
  color: var(--ink-400);
  text-align: center;
}

.hint code {
  font-size: 0.7rem;
  background: var(--brand-50);
  padding: 0.1rem 0.3rem;
  border-radius: 0.25rem;
}

/* --- Buttons --- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  height: 2.5rem;
  padding: 0 1rem;
  border-radius: 0.75rem;
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-primary {
  width: 100%;
  background: var(--brand-500);
  color: var(--white);
}

.btn-primary:hover {
  background: var(--brand-600);
}

.btn-secondary {
  background: var(--ink-900);
  color: var(--white);
  height: 2.25rem;
}

.btn-ghost {
  background: transparent;
  border-color: var(--ink-200);
  color: var(--ink-600);
  height: 2.25rem;
}

.btn-ghost:hover {
  background: var(--brand-50);
  border-color: var(--brand-200);
  color: var(--brand-700, #0369a1);
}

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

/* --- App shell --- */

.app-view {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1.25rem;
  background: rgba(245, 250, 254, 0.9);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--brand-100);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.topbar-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-400);
}

.topbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.range-field {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--ink-500);
}

.range-field select {
  height: 2.25rem;
  padding: 0 0.6rem;
}

.main {
  max-width: 72rem;
  margin: 0 auto;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

/* --- Stats --- */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}

@media (min-width: 800px) {
  .stats-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--brand-100);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  padding: 1rem;
}

.stat-card .label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-400);
}

.stat-card .value {
  margin-top: 0.35rem;
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 700;
  color: var(--ink-900);
  letter-spacing: -0.02em;
}

/* --- Panels --- */

.panels {
  display: grid;
  gap: 1rem;
}

@media (min-width: 800px) {
  .panels {
    grid-template-columns: 1fr 1fr;
  }
}

.panel {
  background: var(--white);
  border: 1px solid var(--brand-100);
  border-radius: 1rem;
  box-shadow: var(--shadow);
  padding: 1.1rem 1.15rem;
}

.panel h2 {
  margin: 0 0 0.85rem;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink-900);
}

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.panel-head h2 {
  margin: 0;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.filters input,
.filters select {
  height: 2.25rem;
  min-width: 7.5rem;
  font-size: 0.8rem;
  padding: 0 0.6rem;
}

.list-table,
.day-table {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
}

.list-row,
.day-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.75rem;
  padding: 0.45rem 0.55rem;
  border-radius: 0.5rem;
  background: var(--brand-50);
  color: var(--ink-700);
}

.list-row strong,
.day-row strong {
  font-weight: 600;
  color: var(--ink-900);
}

.day-row {
  grid-template-columns: 6.5rem 1fr 1fr;
}

.muted {
  color: var(--ink-400);
  font-size: 0.85rem;
}

/* --- Events table --- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--brand-100);
  border-radius: 0.75rem;
}

.events-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.events-table th,
.events-table td {
  text-align: left;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--brand-100);
  vertical-align: top;
  white-space: nowrap;
}

/* Keep IP on one line; table scrolls horizontally if needed. Hover shows full. */
.events-table td.ip-cell {
  white-space: nowrap;
  max-width: none;
  font-variant-numeric: tabular-nums;
}

.events-table td.ip-cell code {
  font-size: 0.72rem;
  background: transparent;
  padding: 0;
  white-space: nowrap;
}

.events-table th {
  background: var(--brand-50);
  color: var(--ink-500);
  font-weight: 600;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.events-table tbody tr {
  cursor: pointer;
  transition: background 0.1s;
}

.events-table tbody tr:hover,
.events-table tbody tr.is-selected {
  background: var(--brand-50);
}

.badge {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
}

.badge-view {
  background: var(--brand-100);
  color: var(--brand-600);
}

.badge-click {
  background: #ecfdf5;
  color: #047857;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-top: 0.85rem;
  font-size: 0.8rem;
  color: var(--ink-500);
}

.event-detail {
  margin: 0;
  padding: 0.85rem;
  background: var(--ink-900);
  color: #e2e8f0;
  border-radius: 0.75rem;
  font-size: 0.75rem;
  line-height: 1.5;
  overflow: auto;
  max-height: 28rem;
  white-space: pre-wrap;
  word-break: break-word;
}

/* --- Toast --- */

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink-900);
  color: var(--white);
  padding: 0.65rem 1rem;
  border-radius: 0.75rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  z-index: 50;
}
