/* ==========================================================================
   Branch Postback & Trackog Attribution Dashboard Stylesheet
   Modern, Sleek, High-Performance Design System & Full Mobile Responsiveness
   ========================================================================== */

/* ── Light Mode (Default Theme) ──────────────────────────── */
:root {
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;

  /* Surfaces & Ambient Lighting */
  --bg-page: #f8fafc;
  --bg-page-gradient: radial-gradient(circle at 50% 0%, #ffffff 0%, #f8fafc 55%, #f1f5f9 100%);
  --bg-card: #ffffff;
  --bg-card-hover: #f8fafc;
  --bg-card-subtle: #f8fafc;
  --bg-input: #ffffff;
  --bg-table-header: #f8fafc;
  --bg-table-row-hover: rgba(241, 245, 249, 0.7);
  --bg-nav: rgba(255, 255, 255, 0.85);
  --bg-modal-backdrop: rgba(15, 23, 42, 0.45);
  --bg-code: #090e17;

  /* Borders */
  --border-subtle: #e2e8f0;
  --border-input: #cbd5e1;
  --border-focus: #6366f1;
  --border-focus-ring: rgba(99, 102, 241, 0.16);

  /* Typography */
  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;
  --text-placeholder: #94a3b8;

  /* Primary Brand Accent (Indigo/Violet) */
  --accent-primary: #4f46e5;
  --accent-primary-hover: #4338ca;
  --accent-gradient: linear-gradient(135deg, #4f46e5 0%, #6366f1 100%);
  --accent-glow: rgba(79, 70, 229, 0.25);

  /* KPI Icon Surfaces */
  --kpi-primary-bg: rgba(79, 70, 229, 0.08);
  --kpi-primary-color: #4f46e5;
  --kpi-cyan-bg: rgba(14, 165, 233, 0.09);
  --kpi-cyan-color: #0284c7;
  --kpi-success-bg: rgba(16, 185, 129, 0.09);
  --kpi-success-color: #059669;
  --kpi-error-bg: rgba(244, 63, 94, 0.09);
  --kpi-error-color: #e11d48;

  /* Status Colors */
  --emerald-dot: #10b981;
  --emerald-text: #047857;
  --emerald-bg: rgba(16, 185, 129, 0.1);
  --emerald-border: rgba(16, 185, 129, 0.25);

  --rose-dot: #f43f5e;
  --rose-text: #be123c;
  --rose-bg: rgba(244, 63, 94, 0.1);
  --rose-border: rgba(244, 63, 94, 0.25);

  --slate-dot: #94a3b8;
  --slate-text: #475569;
  --slate-bg: rgba(148, 163, 184, 0.12);
  --slate-border: rgba(148, 163, 184, 0.2);

  /* Badges & Pills */
  --badge-event-bg: #eef2ff;
  --badge-event-text: #4338ca;
  --badge-event-border: #e0e7ff;

  --copy-pill-bg: #f1f5f9;
  --copy-pill-border: #e2e8f0;
  --copy-pill-hover: #e2e8f0;

  /* Shadows */
  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.04);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.05), 0 1px 2px -1px rgba(0, 0, 0, 0.03);
  --shadow-card: 0 1px 3px 0 rgba(0, 0, 0, 0.04), 0 4px 12px -2px rgba(0, 0, 0, 0.03);
  --shadow-card-hover: 0 4px 14px -1px rgba(0, 0, 0, 0.08), 0 2px 6px -1px rgba(0, 0, 0, 0.04);
  --shadow-modal: 0 20px 40px -8px rgba(15, 23, 42, 0.2), 0 8px 16px -4px rgba(15, 23, 42, 0.1);

  /* Border Radii */
  --radius-xs: 5px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 9999px;
}

/* ── Dark Mode ───────────────────────────────────────────── */
[data-theme="dark"] {
  --bg-page: #080d16;
  --bg-page-gradient: radial-gradient(circle at 50% 0%, #111a2e 0%, #080d16 65%, #05080e 100%);
  --bg-card: #0f1624;
  --bg-card-hover: #151e30;
  --bg-card-subtle: #0b111c;
  --bg-input: #121a2b;
  --bg-table-header: #0b111c;
  --bg-table-row-hover: rgba(26, 36, 56, 0.6);
  --bg-nav: rgba(15, 22, 36, 0.85);
  --bg-modal-backdrop: rgba(0, 0, 0, 0.75);
  --bg-code: #05080f;

  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-input: rgba(255, 255, 255, 0.12);
  --border-focus: #818cf8;
  --border-focus-ring: rgba(129, 140, 248, 0.2);

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  --text-placeholder: #475569;

  --accent-primary: #6366f1;
  --accent-primary-hover: #4f46e5;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #818cf8 100%);
  --accent-glow: rgba(99, 102, 241, 0.35);

  --kpi-primary-bg: rgba(99, 102, 241, 0.15);
  --kpi-primary-color: #a5b4fc;
  --kpi-cyan-bg: rgba(56, 189, 248, 0.15);
  --kpi-cyan-color: #38bdf8;
  --kpi-success-bg: rgba(52, 211, 153, 0.15);
  --kpi-success-color: #34d399;
  --kpi-error-bg: rgba(251, 113, 133, 0.15);
  --kpi-error-color: #fb7185;

  --emerald-dot: #34d399;
  --emerald-text: #34d399;
  --emerald-bg: rgba(16, 185, 129, 0.16);
  --emerald-border: rgba(16, 185, 129, 0.3);

  --rose-dot: #fb7185;
  --rose-text: #fb7185;
  --rose-bg: rgba(244, 63, 94, 0.16);
  --rose-border: rgba(244, 63, 94, 0.3);

  --slate-dot: #64748b;
  --slate-text: #94a3b8;
  --slate-bg: rgba(148, 163, 184, 0.12);
  --slate-border: rgba(148, 163, 184, 0.2);

  --badge-event-bg: rgba(99, 102, 241, 0.14);
  --badge-event-text: #c7d2fe;
  --badge-event-border: rgba(99, 102, 241, 0.28);

  --copy-pill-bg: rgba(255, 255, 255, 0.05);
  --copy-pill-border: rgba(255, 255, 255, 0.09);
  --copy-pill-hover: rgba(255, 255, 255, 0.1);

  --shadow-xs: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.35);
  --shadow-card-hover: 0 6px 16px rgba(0, 0, 0, 0.5);
  --shadow-modal: 0 24px 50px rgba(0, 0, 0, 0.7);
}

/* ── Base Reset ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

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

/* ── Zero-Flicker View Switching (Eliminates login/dashboard flash) ── */
html.has-auth #loginView {
  display: none !important;
}
html.has-auth #dashboardView {
  display: flex !important;
}
html.no-auth #loginView {
  display: flex !important;
}
html.no-auth #dashboardView {
  display: none !important;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-page);
  background-image: var(--bg-page-gradient);
  color: var(--text-main);
  min-height: 100vh;
  font-size: 13px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* ── Custom Sleek Scrollbars ─────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: var(--radius-pill);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* ── Global Utility Classes ──────────────────────────────── */
.hidden {
  display: none !important;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  letter-spacing: -0.01em;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Compact label variants, swapped in on phones (see responsive section) */
.label-short {
  display: none;
}

/* ==========================================================================
   Login View (Modern Glassmorphic Card)
   ========================================================================== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.25rem;
  position: relative;
}

.theme-toggle-floating {
  position: absolute;
  top: 1.25rem;
  right: 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.theme-toggle-floating:hover {
  background: var(--bg-card-hover);
  color: var(--text-main);
  transform: translateY(-1px);
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 2.25rem 2rem;
  box-shadow: var(--shadow-modal);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: relative;
  overflow: hidden;
  animation: cardFadeIn 0.3s ease-out;
}

@keyframes cardFadeIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.login-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--accent-gradient);
}

.brand-header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.brand-icon {
  width: 46px;
  height: 46px;
  border-radius: var(--radius-md);
  background: var(--kpi-primary-bg);
  border: 1px solid var(--badge-event-border);
  color: var(--accent-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.85rem;
  box-shadow: 0 4px 12px var(--accent-glow);
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.brand-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.form-group {
  margin-bottom: 1.15rem;
}

.form-label {
  display: block;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.input-wrapper {
  position: relative;
}

.form-input {
  width: 100%;
  height: 38px;
  padding: 0 0.85rem;
  font-size: 0.86rem;
  font-family: inherit;
  color: var(--text-main);
  background-color: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  outline: none;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

.form-input::placeholder {
  color: var(--text-placeholder);
}

.form-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--border-focus-ring);
}

.btn-primary {
  width: 100%;
  height: 38px;
  font-size: 0.86rem;
  font-weight: 600;
  font-family: inherit;
  color: #ffffff;
  background: var(--accent-gradient);
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  box-shadow: 0 2px 6px var(--accent-glow);
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-primary:hover {
  opacity: 0.95;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.alert-box {
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  margin-bottom: 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.alert-error {
  background-color: var(--rose-bg);
  color: var(--rose-text);
  border: 1px solid var(--rose-border);
}

/* ==========================================================================
   Navigation Bar (Slim, Glassmorphic 50px)
   ========================================================================== */
.dashboard-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.top-nav {
  height: 50px;
  background-color: var(--bg-nav);
  backdrop-filter: blur(14px) saturate(180%);
  -webkit-backdrop-filter: blur(14px) saturate(180%);
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  position: sticky;
  top: 0;
  z-index: 50;
  transition: border-color 0.2s ease;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.nav-brand-icon {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow: 0 2px 6px var(--accent-glow);
  flex-shrink: 0;
}

.nav-title-group {
  display: flex;
  align-items: center;
  min-width: 0;
}

.nav-title-group h1 {
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text-main);
  letter-spacing: -0.015em;
  display: flex;
  align-items: center;
  white-space: nowrap;
}

/* The h1 is a flex container, which drops the span's trailing space */
.brand-long {
  margin-right: 0.28em;
}

/* Modern Pulsing Live Badge */
.badge.badge-live {
  font-size: 0.68rem;
  font-weight: 600;
  padding: 0.12rem 0.5rem;
  background: var(--emerald-bg);
  color: var(--emerald-text);
  border: 1px solid var(--emerald-border);
  border-radius: var(--radius-pill);
  margin-left: 0.5rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  letter-spacing: 0.02em;
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--emerald-dot);
  display: inline-block;
  position: relative;
}

.live-dot::after {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 50%;
  border: 1.5px solid var(--emerald-dot);
  animation: livePing 2s cubic-bezier(0, 0, 0.2, 1) infinite;
}

@keyframes livePing {
  0% { transform: scale(1); opacity: 0.8; }
  80%, 100% { transform: scale(2.4); opacity: 0; }
}

.nav-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex-shrink: 0;
}

.auto-refresh-select {
  height: 32px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  padding: 0 0.6rem;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-family: inherit;
  font-weight: 500;
  cursor: pointer;
  outline: none;
  transition: all 0.15s ease;
}

.auto-refresh-select:hover, .auto-refresh-select:focus {
  border-color: var(--border-focus);
  color: var(--text-main);
}

.btn-icon {
  width: 32px;
  height: 32px;
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

.btn-icon:hover {
  background-color: var(--bg-card-hover);
  color: var(--text-main);
  border-color: var(--border-input);
  transform: translateY(-1px);
}

.btn-icon:active {
  transform: translateY(0);
}

/* Timezone Toggle Pill (UTC / IST) */
.btn-tz {
  display: inline-flex;
  align-items: center;
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  height: 32px;
  padding: 2px;
  gap: 2px;
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
  outline: none;
}

.btn-tz:hover {
  border-color: var(--border-input);
  background-color: var(--bg-card-hover);
  transform: translateY(-1px);
}

.btn-tz:active {
  transform: translateY(0);
}

.tz-option {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0 0.48rem;
  height: 26px;
  border-radius: 4px;
  color: var(--text-dim);
  transition: all 0.15s ease;
  user-select: none;
}

.tz-option.active {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(79, 70, 229, 0.28);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.2rem 0.55rem;
  background-color: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  height: 32px;
  transition: all 0.15s ease;
}

.user-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--accent-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  font-weight: 700;
  color: #ffffff;
  flex-shrink: 0;
}

.user-name {
  font-size: 0.78rem;
  color: var(--text-main);
  font-weight: 500;
  white-space: nowrap;
}

.btn-logout {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 0.15rem;
  border-radius: var(--radius-xs);
  transition: color 0.15s ease;
}

.btn-logout:hover {
  color: var(--rose-text);
}

/* ==========================================================================
   Main Content Layout
   ========================================================================== */
.main-container {
  max-width: 1280px;
  width: 100%;
  margin: 0 auto;
  padding: 1.15rem 1.25rem;
  flex: 1;
}

/* ==========================================================================
   KPI Metrics Grid (Modern Cards with Icon Badges)
   ========================================================================== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0.65rem;
  margin-bottom: 0.65rem;
}

@media (max-width: 1024px) {
  .kpi-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  }
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
  box-shadow: var(--shadow-xs);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 0.35rem;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  overflow: hidden;
}

.kpi-card:hover {
  border-color: rgba(99, 102, 241, 0.35);
  box-shadow: var(--shadow-sm);
  transform: translateY(-1px);
}

.kpi-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.kpi-icon-wrapper {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.2s ease;
}

.kpi-icon-wrapper svg {
  width: 13px;
  height: 13px;
}

.kpi-card:hover .kpi-icon-wrapper {
  transform: scale(1.05);
}

.kpi-icon-primary {
  background: var(--kpi-primary-bg);
  color: var(--kpi-primary-color);
}

.kpi-icon-purple {
  background: rgba(168, 85, 247, 0.12);
  color: #9333ea;
}

.kpi-tag-purple {
  background: rgba(168, 85, 247, 0.1);
  color: #9333ea;
  border: 1px solid rgba(168, 85, 247, 0.25);
}

.kpi-icon-cyan {
  background: var(--kpi-cyan-bg);
  color: var(--kpi-cyan-color);
}

.kpi-icon-success {
  background: var(--kpi-success-bg);
  color: var(--kpi-success-color);
}

.kpi-icon-error {
  background: var(--kpi-error-bg);
  color: var(--kpi-error-color);
}

.kpi-info {
  display: flex;
  flex-direction: column;
  width: 100%;
}

.kpi-label {
  font-size: 0.63rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi-value {
  font-size: 1.18rem;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.15;
  margin-top: 0.1rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.kpi-tag {
  font-size: 0.63rem;
  font-weight: 600;
  padding: 0.1rem 0.38rem;
  border-radius: var(--radius-pill);
  background: var(--bg-card-subtle);
  color: var(--text-dim);
  border: 1px solid var(--border-subtle);
  white-space: nowrap;
  flex-shrink: 0;
}

.kpi-tag.kpi-tag-success {
  background: var(--emerald-bg);
  color: var(--emerald-text);
  border-color: var(--emerald-border);
}

.kpi-tag.kpi-tag-error {
  background: var(--rose-bg);
  color: var(--rose-text);
  border-color: var(--rose-border);
}

/* ==========================================================================
   Filter Toolbar (Unified Responsive Bar)
   ========================================================================== */
.toolbar-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.75rem 0.95rem;
  margin-bottom: 0.95rem;
  box-shadow: var(--shadow-card);
}

.toolbar-grid {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.search-input-box {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1;
  min-width: 240px;
}

.search-icon {
  position: absolute;
  left: 0.75rem;
  color: var(--text-dim);
  pointer-events: none;
}

.search-input-box .form-input {
  padding-left: 2.15rem;
  height: 34px;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
}

.select-filter {
  height: 34px;
  padding: 0 0.75rem;
  font-size: 0.82rem;
  font-family: inherit;
  color: var(--text-main);
  background-color: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  outline: none;
  cursor: pointer;
  min-width: 135px;
  transition: all 0.15s ease;
}

.select-filter:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--border-focus-ring);
}

.date-filter-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.date-input {
  height: 34px;
  padding: 0 0.55rem;
  font-size: 0.78rem;
  font-family: inherit;
  color: var(--text-main);
  background-color: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--radius-sm);
  outline: none;
  transition: all 0.15s ease;
}

.date-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--border-focus-ring);
}

.date-sep {
  color: var(--text-dim);
  font-size: 0.85rem;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
}

.btn-secondary {
  height: 34px;
  padding: 0 0.85rem;
  font-size: 0.8rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-main);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  white-space: nowrap;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
}

.btn-secondary:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-input);
  transform: translateY(-1px);
}

.btn-secondary:active {
  transform: translateY(0);
}

.btn-export {
  background: var(--emerald-bg);
  border-color: var(--emerald-border);
  color: var(--emerald-text);
  font-weight: 600;
}

.btn-export:hover {
  background: rgba(16, 185, 129, 0.18);
  border-color: rgba(16, 185, 129, 0.45);
}

/* Apply Filter Button (Primary Accent) */
.btn-apply {
  height: 34px;
  padding: 0 1rem;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  color: #ffffff;
  background: var(--accent-gradient);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  white-space: nowrap;
  position: relative;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 1px 4px rgba(79, 70, 229, 0.32);
}

.btn-apply:hover {
  background: linear-gradient(135deg, #4338ca 0%, #4f46e5 100%);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

.btn-apply:active {
  transform: translateY(0);
  box-shadow: 0 1px 4px rgba(79, 70, 229, 0.28);
}

.btn-apply.is-pending {
  background: linear-gradient(135deg, #7c3aed 0%, #6366f1 100%);
  box-shadow: 0 2px 8px rgba(124, 58, 237, 0.4);
}

/* Pending indicator dot on Apply button */
.filter-pending-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fbbf24;
  display: inline-block;
  margin-left: 2px;
  flex-shrink: 0;
  animation: pendingPulse 1.4s ease-in-out infinite;
}

@keyframes pendingPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(0.75); }
}

/* Filter Result Bar (below toolbar-grid, shown after apply) */
.filter-result-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-top: 0.6rem;
  padding: 0.45rem 0.7rem;
  background: var(--bg-card-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  animation: slideDown 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.filter-result-left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-wrap: wrap;
}

.filter-active-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-primary);
  background: rgba(79, 70, 229, 0.1);
  border: 1px solid rgba(79, 70, 229, 0.22);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
  white-space: nowrap;
}

.filter-result-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.filter-result-text strong {
  color: var(--text-main);
  font-weight: 600;
}

.filter-result-clear {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-dim);
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.2rem 0.4rem;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  transition: all 0.15s ease;
  font-family: inherit;
  flex-shrink: 0;
}

.filter-result-clear:hover {
  color: var(--rose-text);
  background: var(--rose-bg);
}

/* Pending state highlight on filter inputs */
.filter-input-pending {
  border-color: #a78bfa !important;
  box-shadow: 0 0 0 2px rgba(167, 139, 250, 0.2) !important;
}

/* ==========================================================================
   Table View Mode Switcher Tabs (All Events vs Unique Clicks)
   ========================================================================== */
.view-mode-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.55rem;
  flex-wrap: wrap;
}

.view-tabs {
  display: inline-flex;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
  box-shadow: var(--shadow-xs);
}

.view-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  background: transparent;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
  user-select: none;
}

.view-tab svg {
  color: var(--text-dim);
  transition: color 0.15s ease;
}

.view-tab:hover {
  color: var(--text-main);
  background: var(--bg-card-hover);
}

.view-tab.active {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 1px 3px rgba(79, 70, 229, 0.3);
}

.view-tab.active svg {
  color: #ffffff;
}

.tab-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.15);
  color: inherit;
}

.view-tab.active .tab-badge {
  background: rgba(255, 255, 255, 0.22);
  color: #ffffff;
}

.view-mode-notice {
  font-size: 0.75rem;
  color: var(--text-dim);
  font-weight: 500;
}

/* Event badges in Unique Clicks table */
.event-badges-container {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
  max-width: 320px;
}

.event-badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: var(--font-mono);
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  white-space: nowrap;
  background: rgba(99, 102, 241, 0.08);
  color: #4f46e5;
  border: 1px solid rgba(99, 102, 241, 0.2);
}

.event-badge-install {
  background: rgba(16, 185, 129, 0.1);
  color: #059669;
  border-color: rgba(16, 185, 129, 0.25);
}

.event-badge-guest {
  background: rgba(14, 165, 233, 0.1);
  color: #0284c7;
  border-color: rgba(14, 165, 233, 0.25);
}

.event-badge-kyc {
  background: rgba(245, 158, 11, 0.1);
  color: #d97706;
  border-color: rgba(245, 158, 11, 0.25);
}

.event-badge-account {
  background: rgba(168, 85, 247, 0.1);
  color: #7c3aed;
  border-color: rgba(168, 85, 247, 0.25);
}

.btn-filter-clickid {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius-xs);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  color: var(--accent-primary);
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: inherit;
}

.btn-filter-clickid:hover {
  background: rgba(79, 70, 229, 0.08);
  border-color: rgba(79, 70, 229, 0.35);
  transform: translateY(-1px);
}

/* ==========================================================================
   Data Table Card (Clean Borders & Responsive Horizontal Touch Scroll)
   ========================================================================== */
.table-card {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 420px;
  position: relative;
}

.table-progress-bar {
  height: 2.5px;
  width: 100%;
  background: var(--bg-card-subtle);
  position: relative;
  overflow: hidden;
  z-index: 10;
}

.table-progress-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 35%;
  background: var(--accent-gradient);
  animation: progressShimmer 1.1s cubic-bezier(0.4, 0, 0.2, 1) infinite;
  border-radius: var(--radius-pill);
}

@keyframes progressShimmer {
  0% { left: -35%; }
  50% { left: 45%; width: 45%; }
  100% { left: 100%; width: 35%; }
}

.table-scroll-hint {
  display: none;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.95rem;
  background: var(--bg-card-subtle);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.73rem;
  color: var(--text-dim);
  font-weight: 500;
}

.table-responsive {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  flex: 1;
}

.data-table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.81rem;
}

.data-table th:nth-child(1) { width: 52px; text-align: center; } /* # */
.data-table th:nth-child(2) { width: 145px; } /* Time (UTC) */
.data-table th:nth-child(3) { width: 155px; } /* Click ID */
.data-table th:nth-child(4) { width: 125px; } /* Event */
.data-table th:nth-child(5) { min-width: 125px; } /* Campaign */
.data-table th:nth-child(6) { width: 90px; } /* Pub ID */
.data-table th:nth-child(7) { width: 110px; } /* Trackog Status */
.data-table th:nth-child(8) { width: 115px; } /* Txn ID */
.data-table th:nth-child(9) { width: 78px; text-align: right; } /* Action */

.cell-num {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.74rem;
  font-weight: 600;
  user-select: none;
}

.th-sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.th-sortable:hover {
  color: var(--text-main);
  background-color: var(--bg-card-hover);
}

.th-sortable .th-content {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.th-sortable .sort-icon {
  display: inline-flex;
  align-items: center;
  color: var(--text-dim);
  transition: transform 0.15s ease, color 0.15s ease;
}

.th-sortable.active-sort {
  color: var(--accent-primary);
}

.th-sortable.active-sort .sort-icon {
  color: var(--accent-primary);
}

#postbacksTableBody {
  transition: opacity 0.18s ease-out;
}

.data-table th {
  background: var(--bg-table-header);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 0.69rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  white-space: nowrap;
}

.data-table td {
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-main);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background-color 0.15s ease;
}

.data-table tbody tr:hover {
  background-color: var(--bg-table-row-hover);
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

/* Status Indicator Dot */
.status-indicator {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
}

.status-dot {
  width: 6.5px;
  height: 6.5px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.status-success {
  color: var(--emerald-text);
}
.status-success .status-dot {
  background-color: var(--emerald-dot);
  box-shadow: 0 0 0 2.5px rgba(16, 185, 129, 0.25);
}

.status-error {
  color: var(--rose-text);
}
.status-error .status-dot {
  background-color: var(--rose-dot);
  box-shadow: 0 0 0 2.5px rgba(244, 63, 94, 0.25);
}

.status-skipped {
  color: var(--slate-text);
}
.status-skipped .status-dot {
  background-color: var(--slate-dot);
}

.badge-event {
  background: var(--badge-event-bg);
  color: var(--badge-event-text);
  border: 1px solid var(--badge-event-border);
  border-radius: var(--radius-pill);
  padding: 0.12rem 0.5rem;
  font-size: 0.73rem;
  font-weight: 600;
  display: inline-block;
  white-space: nowrap;
}

.copy-pill {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.45rem;
  background: var(--copy-pill-bg);
  border: 1px solid var(--copy-pill-border);
  border-radius: var(--radius-xs);
  color: var(--text-main);
  font-size: 0.77rem;
  transition: all 0.15s ease;
}

.copy-pill:hover {
  background: var(--copy-pill-hover);
  border-color: var(--text-dim);
}

.cell-time {
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.cell-campaign {
  max-width: 150px;
  color: var(--text-main);
  font-weight: 500;
}

.cell-dim {
  color: var(--text-dim);
}

.cell-txn {
  max-width: 130px;
}

.btn-inspect {
  height: 28px;
  padding: 0 0.65rem;
  font-size: 0.75rem;
  font-weight: 500;
  font-family: inherit;
  color: var(--text-main);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);
  white-space: nowrap;
}

.btn-inspect:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  transform: translateY(-1px);
}

.btn-inspect:active {
  transform: translateY(0);
}

/* Empty & Loading States */
.table-empty {
  padding: 3.5rem 1rem;
  text-align: center;
}

.empty-icon {
  width: 38px;
  height: 38px;
  margin: 0 auto 0.85rem;
  color: var(--text-dim);
}

.empty-title {
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 0.25rem;
}

.empty-desc {
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* ==========================================================================
   Pagination Controls
   ========================================================================== */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0.95rem;
  background: var(--bg-table-header);
  border-top: 1px solid var(--border-subtle);
  font-size: 0.79rem;
  color: var(--text-muted);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.page-btn {
  height: 30px;
  padding: 0 0.75rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-main);
  cursor: pointer;
  font-size: 0.78rem;
  font-family: inherit;
  font-weight: 500;
  transition: all 0.15s ease;
}

.page-btn:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--border-input);
  transform: translateY(-1px);
}

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

/* ==========================================================================
   Inspect Modal (Glassmorphic Dialog & Mobile Sheet)
   ========================================================================== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: var(--bg-modal-backdrop);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 100;
}

.modal-dialog {
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 640px;
  max-height: 85vh;
  box-shadow: var(--shadow-modal);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: modalScaleIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScaleIn {
  from {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  padding: 0.95rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.015em;
}

.modal-close-btn {
  background: none;
  border: none;
  color: var(--text-dim);
  cursor: pointer;
  padding: 0.25rem;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s ease;
}

.modal-close-btn:hover {
  color: var(--text-main);
  background: var(--bg-card-hover);
}

.modal-tabs {
  display: flex;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-table-header);
  gap: 0.5rem;
  overflow-x: auto;
}

.modal-tab {
  padding: 0.65rem 0.95rem;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: inherit;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: all 0.18s ease;
  white-space: nowrap;
}

.modal-tab:hover {
  color: var(--text-main);
}

.modal-tab.active {
  color: var(--accent-primary);
  border-bottom-color: var(--accent-primary);
}

.modal-body {
  padding: 1.25rem;
  overflow-y: auto;
  flex: 1;
}

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

.detail-item {
  display: flex;
  flex-direction: column;
}

.detail-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.detail-value {
  font-size: 0.84rem;
  color: var(--text-main);
  overflow-wrap: anywhere;
}

.code-container {
  position: relative;
  background: var(--bg-code);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.95rem;
  font-family: var(--font-mono);
  font-size: 0.79rem;
  color: #cbd5e1;
  overflow-x: auto;
  max-height: 340px;
  line-height: 1.45;
}

.btn-copy-code {
  position: absolute;
  top: 0.55rem;
  right: 0.55rem;
  padding: 0.28rem 0.55rem;
  font-size: 0.72rem;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: var(--radius-xs);
  color: #f1f5f9;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  transition: all 0.15s ease;
}

.btn-copy-code:hover {
  background: rgba(255, 255, 255, 0.22);
}

/* ==========================================================================
   Toast Notification System
   ========================================================================== */
.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 150;
  pointer-events: none;
}

.toast {
  padding: 0.65rem 0.95rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  box-shadow: var(--shadow-modal);
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  pointer-events: auto;
  animation: toastSlideUp 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.toast.toast-success {
  border-color: var(--emerald-border);
}

.toast.toast-error {
  border-color: var(--rose-border);
}

.spin {
  animation: spin 0.75s linear infinite;
}

@keyframes spin {
  100% {
    transform: rotate(360deg);
  }
}

/* ==========================================================================
   Comprehensive Mobile & Responsive Media Queries
   ========================================================================== */

/* ── Tablet & Small Laptops (<= 1024px) ───────────────────── */
@media (max-width: 1024px) {
  .main-container {
    padding: 1rem;
  }
}

/* ── Tablets & Mobile Devices (<= 768px) ──────────────────── */
@media (max-width: 768px) {
  .top-nav {
    padding: 0 0.85rem;
  }

  /* Shorter title so the single-row nav still fits down to 641px */
  .brand-long {
    display: none;
  }

  .main-container {
    padding: 0.85rem;
  }

  /* iOS Safari zooms the whole page when a control under 16px gets focus */
  .form-input,
  .select-filter,
  .date-input,
  .auto-refresh-select {
    font-size: 16px;
  }

  /* KPI tiles: 2 columns; the odd 5th tile spans the full row */
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
    margin-bottom: 0.55rem;
  }

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

  .kpi-card {
    padding: 0.5rem 0.65rem;
    gap: 0.25rem;
  }

  .kpi-value {
    font-size: 1.1rem;
  }

  /* Toolbar: full-width search, 2x2 selects, full-width dates and actions.
     minmax(0, 1fr) stops native date inputs from forcing the grid wider than the card. */
  .toolbar-card {
    padding: 0.75rem 0.85rem;
  }

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

  .search-input-box {
    grid-column: 1 / -1;
    min-width: 0;
    width: 100%;
  }

  .search-input-box .form-input,
  .select-filter,
  .date-input {
    height: 38px;
  }

  .select-filter {
    width: 100%;
    min-width: 0;
  }

  .date-filter-group {
    grid-column: 1 / -1;
    width: 100%;
    min-width: 0;
  }

  .date-input {
    flex: 1 1 0;
    width: 100%;
    min-width: 0;
  }

  /* iOS centers the date text by default */
  .date-input::-webkit-date-and-time-value {
    text-align: left;
  }

  .toolbar-actions {
    grid-column: 1 / -1;
    margin-left: 0;
    width: 100%;
    gap: 0.5rem;
  }

  .toolbar-actions > button {
    flex: 1 1 0;
    min-width: 0;
    height: 38px;
    padding: 0 0.5rem;
    font-size: 0.82rem;
  }

  .toolbar-actions svg {
    flex-shrink: 0;
  }

  .filter-result-bar {
    align-items: flex-start;
  }

  /* Table horizontal touch scroll cue */
  .table-scroll-hint {
    display: flex;
  }
}

/* ── Standard Mobile Phones (<= 640px) ────────────────────── */
@media (max-width: 640px) {
  /* Nav: two rows — brand + theme + account on top, refresh + timezone below.
     Not sticky here: a two-row bar would eat too much of a phone screen. */
  .top-nav {
    position: relative;
    height: auto;
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto auto;
    grid-template-areas:
      "brand brand brand theme user"
      "auto  refresh .   tz    tz";
    align-items: center;
    gap: 0.5rem 0.4rem;
    padding: 0.55rem 0.85rem;
  }

  .nav-controls {
    display: contents;
  }

  .nav-brand { grid-area: brand; }
  #autoRefreshSelect { grid-area: auto; }
  #btnManualRefresh { grid-area: refresh; }
  #themeToggleBtn { grid-area: theme; }
  .user-profile { grid-area: user; }

  .btn-tz {
    grid-area: tz;
    justify-self: end;
  }

  .nav-title-group h1 {
    font-size: 0.9rem;
  }

  /* View tabs: full-width segmented control with short labels */
  .view-mode-bar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.4rem;
  }

  .view-tabs {
    display: flex;
    width: 100%;
  }

  .view-tab {
    flex: 1 1 0;
    min-width: 0;
    justify-content: center;
    white-space: nowrap;
    padding: 0.45rem 0.5rem;
  }

  .view-mode-notice {
    padding-left: 0.15rem;
  }

  .label-long {
    display: none;
  }

  .label-short {
    display: inline;
  }

  /* Pagination: summary on top, [size][Prev][Next] below */
  .pagination-bar {
    flex-direction: column;
    gap: 0.6rem;
    align-items: stretch;
    text-align: center;
  }

  .pagination-controls {
    display: grid;
    grid-template-columns: auto 1fr 1fr;
    gap: 0.5rem;
  }

  #pageSizeSelect {
    height: 36px;
  }

  .page-btn {
    height: 36px;
    padding: 0 0.5rem;
  }

  /* Inspect Modal: Mobile Bottom-Sheet Layout */
  .modal-backdrop {
    padding: 0;
    align-items: flex-end;
  }

  .modal-dialog {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    max-height: 92dvh; /* excludes the mobile browser toolbars where supported */
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: none;
    animation: modalSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  }

  @keyframes modalSlideUp {
    from {
      opacity: 0;
      transform: translateY(100%);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .modal-header {
    padding: 0.85rem 1rem;
  }

  .modal-tabs {
    padding: 0 0.5rem;
    gap: 0;
  }

  .modal-tab {
    flex: 1 1 0;
    padding: 0.7rem 0.4rem;
  }

  .modal-body {
    padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom));
    overscroll-behavior: contain;
  }

  /* minmax(0, 1fr) keeps long unbroken tokens from widening the sheet */
  .detail-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.75rem;
  }

  .detail-item {
    min-width: 0;
  }

  .detail-item[style*="grid-column"] {
    grid-column: auto !important;
  }

  .detail-grid .code-container {
    overflow-wrap: anywhere;
  }

  /* Toasts: full-width along the bottom edge */
  .toast-container {
    left: 0.75rem;
    right: 0.75rem;
    bottom: calc(0.75rem + env(safe-area-inset-bottom));
  }
}

/* ── Small Mobile Viewports (<= 480px) ────────────────────── */
@media (max-width: 480px) {
  .top-nav {
    padding: 0.5rem 0.65rem;
  }

  /* Hide username text, keeping only the avatar and logout button */
  .user-name {
    display: none;
  }

  .user-profile {
    padding: 0.2rem 0.35rem;
    gap: 0.3rem;
  }

  .kpi-tag {
    font-size: 0.6rem;
    padding: 0.08rem 0.32rem;
  }

  /* Login card margin */
  .login-card {
    padding: 1.75rem 1.25rem;
  }
}

/* ── Narrow Phones (<= 400px) ─────────────────────────────── */
@media (max-width: 400px) {
  .page-size-label {
    display: none;
  }

  .view-tab svg {
    display: none;
  }
}

/* ── Very Narrow Phones (<= 360px) ────────────────────────── */
@media (max-width: 360px) {
  .main-container {
    padding: 0.65rem;
  }

  /* Two selects per row would clip their labels at 16px */
  .toolbar-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  /* Stack the dates too, otherwise "dd-mm-yyyy" gets clipped */
  .date-sep {
    display: none;
  }

  .date-filter-group {
    flex-direction: column;
    gap: 0.5rem;
  }

  .date-input {
    flex: none;
  }

  /* Same totals are in the KPI tiles right above */
  .view-tab .tab-badge {
    display: none;
  }

  .kpi-label {
    white-space: normal;
  }
}
