/* =========================================================
   PilotMetrics - Base Styles
   Shared reset, theme, typography, layout, navigation,
   cards, controls and reusable UI components.
   ========================================================= */

:root {
  --bg: #0b0f19;
  --bg-gradient: radial-gradient(circle at 50% 0%, #172238 0%, #0b0f19 75%);
  --card: #131c2e;
  --card-hover: #17233a;
  --text: #f8fafc;
  --muted: #94a3b8;
  --line: #1e293b;
  --line-light: #334155;
  --blue: #3b82f6;
  --blue-hover: #2563eb;
  --blue-light: rgba(59, 130, 246, 0.15);
  --cyan: #06b6d4;
  --cyan-light: rgba(6, 182, 212, 0.15);
  --green: #10b981;
  --green-light: rgba(16, 185, 129, 0.15);
  --amber: #f59e0b;
  --amber-light: rgba(245, 158, 11, 0.15);
  --purple: #8b5cf6;
  --purple-light: rgba(139, 92, 246, 0.15);
  --danger: #ef4444;
  --danger-light: rgba(239, 68, 68, 0.2);
  --gold: #eab308;
  --gold-light: rgba(234, 179, 8, 0.15);
  --radius: 12px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  overflow-x: hidden;
  width: 100%;
}

/* clip, not hidden: hidden makes body a scroll container, which stops the app bar sticking */
body {
  overflow-x: clip;
}

body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  font-size: 13px;
  line-height: 1.4;
  min-height: 100vh;
  -webkit-text-size-adjust: 100%;
}

.wrap {
  margin: 0 120px;
  padding: 20px 24px 48px;
}

/* Tablets (including landscape iPads) get slimmer side margins */
@media (max-width: 1200px) {
  .wrap {
    margin: 0 40px;
  }
}

@media (max-width: 600px) {
  .wrap {
    margin: 0;
    padding: 16px 12px 40px;
  }
}

.read-only-banner {
background: linear-gradient(135deg, #1e293b, #0f172a);
  color: #ffffff;
  padding: 10px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 1px solid var(--blue);
  box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  margin-bottom: 16px;
  border-radius: var(--radius);
  gap: 12px;
  flex-wrap: wrap;
}

.read-only-banner span {
font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Header */
header.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  background: rgba(19, 28, 46, 0.85);
  backdrop-filter: blur(12px);
  padding: 16px 24px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
  gap: 16px;
  flex-wrap: wrap;
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 10px;
  font-weight: 800;
  color: var(--cyan);
}

.modal-overlay {
position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(3, 7, 18, 0.8);
  display: grid;
  place-items: center;
  z-index: 100;
  backdrop-filter: blur(8px);
  padding: 12px;
  overflow-y: auto;
}

.modal {
background: var(--card);
  border: 1px solid var(--line-light);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 540px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
  color: #fff;
  margin: auto;
  -webkit-overflow-scrolling: touch;
}

.auth-tabs {
display: flex;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.auth-tab {
flex: 1;
  padding: 8px;
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.auth-tab.active {
color: var(--cyan); border-bottom-color: var(--cyan);
}

@media (max-width: 600px) {
  h1 { font-size: 18px; }

  .modal div[style*="display: flex"],
  .modal div[style*="display:flex"] {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
  }

  .modal .field {
    width: 100% !important;
    max-width: none !important;
  }

  .modal button {
    width: 100% !important;
  }
}

h1 {
  font-size: 22px;
  margin: 2px 0 0;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #fff;
  word-break: break-word;
}

.sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 11px;
}

.user-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.user-badge {
  background: #0f172a;
  border: 1px solid var(--line-light);
  padding: 6px 12px;
  border-radius: 20px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 12px;
  color: #fff;
  max-width: 100%;
}

.avatar {
  width: 22px;
  height: 22px;
  background: linear-gradient(135deg, var(--blue), var(--cyan));
  color: #fff;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: 10px;
  font-weight: 700;
  flex-shrink: 0;
}

.sync-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--line);
  color: var(--muted);
  transition: all 0.2s ease;
  border: 1px solid transparent;
  white-space: nowrap;
}

.sync-badge.synced {
  background: var(--green-light);
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.3);
}

.sync-badge.error {
  background: var(--danger-light);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.3);
}

/* =========================================================
   App bar (built by app.js): logo, page tabs, location scope, account
   ========================================================= */
.appbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: rgba(15, 23, 42, 0.88);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}

/* Lines up with .wrap below it */
.appbar-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  height: 56px;
  margin: 0 120px;
  padding: 0 24px;
}

.appbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  color: #fff;
  font-weight: 800;
  font-size: 14px;
  text-decoration: none;
  white-space: nowrap;
}

.appbar-brand img {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  object-fit: contain;
}

.appbar-tabs {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
}

.appbar-tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 100%;
  min-height: 0;
  padding: 0 11px;
  background: none;
  border: 0;
  border-radius: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.appbar-tab:hover {
  background: none;
  box-shadow: none;
  color: #fff;
}

.appbar-tab.active {
  color: #fff;
}

.appbar-tab.active::after {
  content: "";
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: -1px;
  height: 2px;
  border-radius: 2px;
  background: var(--blue);
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.6);
}

.appbar-tab.pro-locked,
.appbar-menu-item.pro-locked {
  opacity: 0.55;
}

.appbar-tab .pro-badge,
.appbar-menu-item .pro-badge {
  font-size: 8px;
  padding: 2px 4px;
  background: var(--blue-light);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.appbar-caret {
  font-size: 10px;
  color: var(--muted);
}

.appbar-more,
.appbar-account {
  position: relative;
  display: flex;
  align-items: center;
  height: 100%;
}

.appbar-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 60;
  min-width: 220px;
  display: grid;
  gap: 2px;
  padding: 6px;
  background: var(--card);
  border: 1px solid var(--line-light);
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}

.appbar-menu[hidden],
.appbar-menu-item[hidden],
.appbar-scope[hidden],
.scope-chip[hidden] {
  display: none;
}

.appbar-menu-right {
  left: auto;
  right: 0;
}

.appbar-menu-head {
  padding: 6px 10px 4px;
  font-size: 10px;
  color: var(--muted);
}

.appbar-menu-head:empty {
  display: none;
}

.appbar-menu-item {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  width: 100%;
  min-height: 0;
  padding: 8px 10px;
  background: none;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.appbar-menu-item:hover {
  background: #0f172a;
  box-shadow: none;
  color: #fff;
}

.appbar-menu-item.active {
  background: var(--blue-light);
  color: #fff;
}

.appbar-menu-item .pro-badge {
  margin-left: auto;
}

.appbar-scope {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
  padding: 3px;
  background: #0f172a;
  border: 1px solid var(--line-light);
  border-radius: 8px;
}

.appbar-scope-label {
  padding: 0 6px 0 4px;
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}

.appbar-scope button {
  min-height: 0;
  padding: 4px 10px;
  background: none;
  border-radius: 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.appbar-scope button:hover {
  background: none;
  box-shadow: none;
  color: #fff;
}

.appbar-scope button[aria-pressed="true"] {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}

.appbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
  height: 100%;
}

.appbar-account-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 0;
  padding: 4px 8px 4px 4px;
  background: none;
  border: 1px solid transparent;
  border-radius: 999px;
  color: #fff;
  font-size: 12px;
  font-weight: 600;
}

.appbar-account-btn:hover {
  background: none;
  box-shadow: none;
  border-color: var(--line-light);
}

.appbar-account-btn .avatar {
  position: relative;
  width: 28px;
  height: 28px;
  font-size: 12px;
}

/* Sync status lives at the bottom of the account menu */
.appbar-menu-sync {
  margin-top: 4px;
  padding: 8px 10px 4px;
  border-top: 1px solid var(--line);
}

/* Red dot on the avatar when loading or saving failed, so it's noticed with the menu closed */
.appbar-account:has(.sync-badge.error) .avatar::after {
  content: "";
  position: absolute;
  bottom: -1px;
  right: -1px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--danger);
  border: 2px solid #0f172a;
}

.appbar-username {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Page title row: the page's three-line heading, plus any page-only controls */
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 16px;
  flex-wrap: wrap;
  margin: 4px 0 16px;
}

.page-head > :first-child {
  min-width: 0;
}

.page-head .sub {
  font-size: 12px;
  max-width: 75ch;
}

.page-tools {
  display: flex;
  align-items: center;
  gap: 8px 12px;
  flex-wrap: wrap;
}

.scope-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
}

.scope-chip b {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--blue-light);
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: #fff;
}

@media (max-width: 1200px) {
  .appbar-inner { margin: 0 40px; }
}

/* Tablets: give the tabs the room the logo text and username were using */
@media (max-width: 1000px) {
  .appbar-brand span,
  .appbar-username { display: none; }
}

/* Phones and small tablets: logo, scope and account on top, tabs swipe in a row underneath */
@media (max-width: 760px) {
  .appbar-inner {
    flex-wrap: wrap;
    height: auto;
    row-gap: 4px;
    padding-top: 8px;
  }
  .appbar-brand span,
  .appbar-username,
  .appbar-scope-label { display: none; }
  .appbar-scope { margin-left: auto; }
  .appbar-right { height: auto; }
  .appbar-tabs {
    order: 3;
    flex: 1 0 100%;
    height: 42px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    mask-image: linear-gradient(to right, #000 85%, transparent);
    -webkit-mask-image: linear-gradient(to right, #000 85%, transparent);
    padding-right: 24px;
  }
  .appbar-tabs::-webkit-scrollbar { display: none; }
  .appbar-account { height: auto; }
}

@media (max-width: 600px) {
  .appbar-inner { margin: 0; padding: 8px 12px 0; }
}

/* Navigation */
.nav-bar,
.filter-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 16px;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

.view-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.view-btn {
  background: #0f172a;
  color: var(--muted);
  border: 1px solid var(--line-light);
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  justify-content: center;
  text-decoration: none;
}

.view-btn:hover {
  background: #1e293b;
  color: #fff;
}

.view-btn.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

.view-btn.pro-locked {
  background: #111827;
  color: #64748b;
  border-color: #1e293b;
  cursor: not-allowed;
/*  pointer-events: none; */
  opacity: 0.7;
  position: relative;
}

.view-btn.pro-locked:hover {
  background: #111827;
  color: #64748b;
  border-color: #1e293b;
  transform: none;
}

/*.view-btn.pro-locked::after {
  content: "🔒";
  font-size: 10px;
  opacity: 0.8;
}*/

/* ================================
   PRO / SUBSCRIPTION UNLOCKED
   ================================ */

.view-btn.pro-unlocked {
  background: #111827;
  color: #cbd5e1;
  border-color: rgba(59, 130, 246, 0.35);
  position: relative;
}

.view-btn.pro-unlocked:hover {
  background: #1e293b;
  color: #fff;
  border-color: rgba(59, 130, 246, 0.65);
}

.view-btn.pro-unlocked .pro-badge {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.35);
  transition: all 0.15s ease;
}

.view-btn.pro-unlocked:hover .pro-badge {
  background: rgba(59, 130, 246, 0.25);
  color: #93c5fd;
  border-color: rgba(59, 130, 246, 0.55);
}


/* Active Pro page */

.view-btn.pro-unlocked.active {
  background: var(--blue);
  color: #fff;
  border-color: var(--blue);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.4);
}

.view-btn.pro-unlocked.active .pro-badge {
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  border-color: rgba(255, 255, 255, 0.25);
}

.pro-badge {
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.5px;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(59, 130, 246, 0.12);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.25);
}

/* Grid & Cards */
.grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 14px;
  width: 100%;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.span-12 { grid-column: span 12; }
.span-8  { grid-column: span 8; }
.span-7  { grid-column: span 7; }
.span-6  { grid-column: span 6; }
.span-5  { grid-column: span 5; }
.span-4  { grid-column: span 4; }
.span-3  { grid-column: span 3; }

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  gap: 8px;
  flex-wrap: wrap;
}

h2 {
  font-size: 14px;
  margin: 0;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #fff;
}

.desc {
  font-size: 11px;
  color: var(--muted);
  margin: -6px 0 12px;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(12, 1fr);
  gap: 10px;
}

.stats-grid-8 {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 10px;
}

.stat {
  background: #0f172a;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  min-width: 0;
}

.stat b {
  font-size: 15px;
  display: block;
  font-weight: 800;
  color: #fff;
  line-height: 1.1;
  word-break: break-word;
}

.stat span {
  font-size: 9px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: block;
}

/* Charts */
.chart {
  height: 210px;
  width: 100%;
  position: relative;
  min-width: 0;
}

.chart svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  display: block;
}

.empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 12px;
  font-style: italic;
}

/* Forms & Controls */
.controls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 100px;
}

.field label {
  font-size: 10px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
}

input,
select,
button {
  font: inherit;
  font-size: 12px;
}

input[type=date],
input[type=time],
input[type=text],
input[type=number],
input[type=password],
input[type=email],
select,
textarea {
  padding: 7px 10px;
  border: 1px solid var(--line-light);
  border-radius: 6px;
  outline: none;
  background: #0f172a;
  color: #fff;
  width: 100%;
  min-height: 36px;
  -webkit-appearance: none;
}

textarea {
  font-family: inherit;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px var(--blue-light);
}

button {
  border: 0;
  border-radius: 6px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
  background: var(--blue);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: all 0.15s ease;
  min-height: 36px;
  touch-action: manipulation;
}

button:hover {
  background: var(--blue-hover);
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.4);
}

button.secondary {
  background: #1e293b;
  color: #cbd5e1;
  border: 1px solid var(--line-light);
}

button.secondary:hover {
  background: #334155;
  color: #fff;
}

button.danger {
  background: var(--danger-light);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

button.danger:hover {
  background: rgba(239, 68, 68, 0.3);
}

/* Busy / unavailable buttons look it, so a slow request isn't mistaken for a missed click */
button:disabled,
button:disabled:hover {
  opacity: 0.6;
  cursor: progress;
  transform: none;
  box-shadow: none;
}

button.sm {
  padding: 4px 10px;
  font-size: 11px;
  border-radius: 4px;
  min-height: 30px;
}

/* Links that look like buttons (actions that go to another page) */
a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 36px;
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  transition: all 0.15s ease;
}

a.btn:hover {
  background: var(--blue-hover);
}

a.btn.secondary {
  background: #1e293b;
  color: #cbd5e1;
  border: 1px solid var(--line-light);
}

a.btn.secondary:hover {
  background: #334155;
  color: #fff;
}

/* Tables */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
}

th {
  font-size: 10px;
  color: var(--muted);
  background: #0f172a;
  text-transform: uppercase;
}

tr:last-child td {
  border-bottom: 0;
}

.filter-bar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-label {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  color: var(--muted);
}

/* Shared utility */
.hidden {
  display: none !important;
}

/* Demo mode (?demo): sample data, everything usable, nothing saved */
.demo-banner {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px 16px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  padding: 10px 16px;
  border-radius: var(--radius);
  background: linear-gradient(135deg, rgba(139, 92, 246, 0.2), rgba(6, 182, 212, 0.14));
  border: 1px solid rgba(139, 92, 246, 0.55);
  color: #e9e5ff;
  font-size: 12px;
  line-height: 1.5;
}
.demo-banner b { color: #fff; }
.demo-banner-actions { display: flex; gap: 8px; flex-shrink: 0; }
body.is-demo #syncBadge,
body.is-demo .appbar-menu-sync { display: none; }

.demo-toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 3000;
  max-width: calc(100% - 32px);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  padding: 10px 14px;
  border-radius: 10px;
  background: #1e1b3a;
  border: 1px solid rgba(139, 92, 246, 0.6);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  color: #e9e5ff;
  font-size: 12px;
}
.demo-toast.visible { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.demo-toast button { margin: 0 4px; padding: 4px 10px; }

/* "Found a bug?" popup, shown once on a visitor's first page load */
.feedback-popup {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 2900;
  width: 320px;
  max-width: calc(100% - 32px);
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--card);
  border: 1px solid var(--line-light);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  color: var(--text);
  font-size: 12px;
  line-height: 1.5;
}
.feedback-popup h3 { margin: 0 24px 6px 0; font-size: 14px; color: #fff; }
.feedback-popup p { margin: 0 0 6px; color: var(--muted); }
.feedback-popup p:last-child { margin-bottom: 0; }
.feedback-popup a { color: #60a5fa; font-weight: 700; }
.feedback-popup-close {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 7px;
  font-size: 11px;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line-light);
}
.feedback-popup-close:hover { color: #fff; background: transparent; }

@media (max-width: 600px) {
  .feedback-popup { right: 16px; bottom: 16px; }
}

footer {
  text-align: center;
  color: var(--muted);
  font-size: 11px;
  margin-top: 24px;
  padding: 0 12px;
}

/* Small-screen shared adjustments */
@media (max-width: 1200px) {
  .stats-grid {
    grid-template-columns: repeat(6, 1fr);
  }
}

@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  header.hero {
    flex-direction: column;
    align-items: stretch;
  }
}

/* =========================================================
   Mobile
   ========================================================= */

/* Cards stack on tablets and phones; every page shares the 12-column grid */
@media (max-width: 900px) {
  .span-8, .span-7, .span-6, .span-5, .span-4, .span-3 { grid-column: span 12; }
  .stats-grid-8 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 600px) {
  .grid { gap: 12px; }
  .stats-grid-8 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Stat tiles sized with span-N still sit two to a row */
  .stats-grid > [class*="span-"],
  .stats-grid-8 > [class*="span-"] { grid-column: auto; }

  /* 16px stops iPhones zooming in whenever a field is tapped */
  input, select, textarea { font-size: 16px !important; }

  /* Page tabs: one swipeable row instead of a tall stack of buttons */
  .nav-bar { padding: 8px; }
  .nav-bar .view-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    width: 100%;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: x proximity;
    /* fade at the right edge hints that there's more to swipe to */
    mask-image: linear-gradient(to right, #000 85%, transparent);
    -webkit-mask-image: linear-gradient(to right, #000 85%, transparent);
    padding-right: 24px;
  }
  .nav-bar .view-tabs::-webkit-scrollbar { display: none; }
  .nav-bar .view-tabs .view-btn { flex: 0 0 auto; white-space: nowrap; scroll-snap-align: start; }
  .nav-bar .filter-bar-group { width: 100%; flex-wrap: wrap; }

  /* Charts keep a readable width and scroll sideways instead of squashing their labels */
  .chart { overflow-x: auto; overflow-y: hidden; -webkit-overflow-scrolling: touch; }
  .chart svg { min-width: 540px; }

  /* Wide tables scroll inside their card rather than pushing the page sideways */
  .card > table:not(.no-scroll) { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th, td { padding: 7px 8px; }
  td { white-space: normal; }

  .modal { padding: 16px; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); }
}

/* Touch screens: bigger tap targets (Apple and Google recommend 44-48px) */
@media (pointer: coarse) {
  button, .view-btn { min-height: 40px; }
  button.sm { min-height: 36px; }
  input[type=checkbox], input[type=radio] { width: 18px; height: 18px; }
}
