html {
  font-feature-settings: "ss01", "cv11";
  -webkit-text-size-adjust: 100%;
}

.app-body {
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.app-header {
  padding-top: env(safe-area-inset-top, 0);
}

.app-main {
  padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0));
}

/* PWA install banner */
.pwa-install {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 40;
  padding: 12px 12px calc(12px + env(safe-area-inset-bottom, 0));
  background: linear-gradient(transparent, rgba(250, 246, 239, 0.92) 24%);
  pointer-events: none;
}

.pwa-install.hidden {
  display: none;
}

.pwa-install-inner {
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: #1f1d1a;
  color: #f5efe6;
  border-radius: 16px;
  box-shadow: 0 8px 32px rgba(31, 29, 26, 0.25);
}

.pwa-install-title {
  font-size: 14px;
  font-weight: 600;
}

.pwa-install-sub {
  font-size: 12px;
  opacity: 0.75;
  margin-top: 2px;
}

.pwa-install-actions {
  display: flex;
  flex-shrink: 0;
  gap: 8px;
}

.pwa-btn-primary,
.pwa-btn-ghost {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

.pwa-btn-primary {
  background: #f5efe6;
  color: #1f1d1a;
}

.pwa-btn-ghost {
  background: transparent;
  color: #f5efe6;
  border: 1px solid rgba(245, 239, 230, 0.35);
}

/* Table sort */
table th[data-sort] {
  user-select: none;
  white-space: nowrap;
}
table th[data-sort]:hover {
  background-color: #2a2722;
}
table th[data-sort].asc::after {
  content: " ▲";
  opacity: 0.8;
}
table th[data-sort].desc::after {
  content: " ▼";
  opacity: 0.8;
}

tbody tr.user-row {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
tbody tr.user-row:hover,
tbody tr.user-row:active {
  background-color: #faf6ef;
}

.plan-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.plan-pill.free {
  background: #efe7d7;
  color: #5a4f3a;
}
.plan-pill.pro {
  background: #d97757;
  color: #fff;
}
.plan-pill.tutor {
  background: #b9933a;
  color: #fff;
}
/* One of our own dev / QA / review logins — excluded from every metric. */
.plan-pill.internal {
  background: rgba(28, 25, 23, 0.08);
  color: rgba(28, 25, 23, 0.65);
  border: 1px dashed rgba(28, 25, 23, 0.25);
}

.exam-badge {
  display: inline-flex;
  align-items: center;
  margin-left: 0.3rem;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  border: 1px solid transparent;
}
.exam-badge.pd2 {
  background: rgba(31, 29, 26, 0.06);
  color: #3a352e;
}
.exam-badge.pd3 {
  background: rgba(185, 147, 58, 0.18);
  color: #6b5418;
}
.exam-badge.pro {
  border-color: currentColor;
}

.ac-pill {
  display: inline-flex;
  align-items: center;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.ac-pill.ok {
  background: #1f7a4a;
  color: #fff;
}
.ac-pill.fail {
  background: #c8102e;
  color: #fff;
}
.ac-pill.unk {
  background: #efe7d7;
  color: #5a4f3a;
}

.kpi {
  background: #f5efe6;
  border: 1px solid rgba(31, 29, 26, 0.08);
  border-radius: 14px;
  padding: 12px 14px;
}
@media (min-width: 640px) {
  .kpi {
    border-radius: 16px;
    padding: 14px 16px;
  }
}
.kpi .label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: rgba(31, 29, 26, 0.6);
  line-height: 1.2;
}
@media (min-width: 640px) {
  .kpi .label {
    font-size: 11px;
  }
}
.kpi .value {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.1;
  margin-top: 4px;
}
@media (min-width: 640px) {
  .kpi .value {
    font-size: 24px;
  }
}
.kpi .sub {
  font-size: 10px;
  color: rgba(31, 29, 26, 0.55);
  margin-top: 2px;
  line-height: 1.25;
}

.modal-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px 14px;
}
@media (min-width: 480px) {
  .modal-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
.modal-grid .k {
  font-size: 11px;
  color: rgba(31, 29, 26, 0.55);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.modal-grid .v {
  font-size: 13px;
  font-weight: 500;
  word-break: break-word;
}

.timeline {
  font-size: 12px;
}
.timeline li {
  padding: 8px 0;
  border-bottom: 1px dashed rgba(31, 29, 26, 0.08);
  display: flex;
  flex-direction: column;
  gap: 2px;
}
@media (min-width: 640px) {
  .timeline li {
    flex-direction: row;
    gap: 10px;
    padding: 4px 0;
  }
}
.timeline li:last-child {
  border-bottom: none;
}
.timeline .ts {
  color: rgba(31, 29, 26, 0.55);
  font-variant-numeric: tabular-nums;
}
@media (min-width: 640px) {
  .timeline .ts {
    min-width: 150px;
  }
}
.timeline .kind {
  font-weight: 500;
}

.user-modal:not(.hidden) {
  display: flex;
}

/* ----- Mobile: card-style user rows ----- */
@media (max-width: 767px) {
  .users-table-wrap {
    overflow-x: visible;
  }

  .users-table thead {
    display: none;
  }

  .users-table tbody tr.user-row {
    display: block;
    margin: 0 12px 12px;
    padding: 12px 14px;
    border: 1px solid rgba(31, 29, 26, 0.1);
    border-radius: 14px;
    background: #faf6ef;
  }

  .users-table tbody tr.user-row td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border: none;
    text-align: right !important;
  }

  .users-table tbody tr.user-row td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: rgba(31, 29, 26, 0.5);
    text-align: left;
    flex: 1;
    min-width: 0;
  }

  .users-table tbody tr.user-row td:first-child {
    display: block;
    padding-bottom: 10px;
    margin-bottom: 4px;
    border-bottom: 1px solid rgba(31, 29, 26, 0.08);
    text-align: left !important;
  }

  .users-table tbody tr.user-row td:first-child::before {
    display: none;
  }

  /* Hide less critical columns on small phones */
  .users-table .col-email,
  .users-table .col-joined,
  .users-table .col-total,
  .users-table .col-streak,
  .users-table .col-ai,
  .users-table .col-appcheck,
  .users-table .col-ac-n,
  .users-table .col-tokens,
  .users-table .col-version {
    display: none;
  }

  .users-table .col-scores {
    display: flex;
  }

  body:has(#pwaInstallBanner:not(.hidden)) .app-main {
    padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0));
  }

  /* User detail modal — full-height bottom sheet */
  .user-modal-panel {
    max-height: 96dvh;
    border-radius: 16px 16px 0 0;
  }

  #modalBody {
    padding-left: 1rem;
    padding-right: 1rem;
    padding-bottom: calc(1.25rem + env(safe-area-inset-bottom, 0));
  }

  .modal-sub-uid {
    display: none;
  }

  .detail-tabs {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 8px;
    margin-left: -1rem;
    margin-right: -1rem;
    padding: 0 1rem 0.75rem;
    scroll-snap-type: x proximity;
  }

  .detail-tabs::-webkit-scrollbar {
    display: none;
  }

  .detail-tab {
    flex-shrink: 0;
    min-height: 44px;
    padding: 10px 16px;
    font-size: 13px;
    scroll-snap-align: start;
  }

  .score-cards {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .score-card {
    padding: 12px;
  }

  .score-card-big {
    font-size: 1.1rem;
  }

  .detail-section-title {
    font-size: 14px;
    margin-top: 1rem;
  }

  .detail-table-wrap {
    overflow-x: visible;
  }

  .detail-table thead {
    display: none;
  }

  .detail-table tbody.detail-record {
    display: block;
    margin-bottom: 12px;
    border: 1px solid rgba(31, 29, 26, 0.12);
    border-radius: 14px;
    background: #f5efe6;
    overflow: hidden;
  }

  .detail-table tbody > tr {
    display: block;
    margin-bottom: 10px;
    border: 1px solid rgba(31, 29, 26, 0.1);
    border-radius: 14px;
    background: #f5efe6;
    padding: 4px 0;
  }

  .detail-table tbody.detail-record > tr {
    margin-bottom: 0;
    border: none;
    border-radius: 0;
    background: transparent;
    padding: 0;
  }

  .detail-table td {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 14px;
    border-bottom: 1px solid rgba(31, 29, 26, 0.06);
    text-align: right !important;
  }

  .detail-table td::before {
    content: attr(data-label);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: rgba(31, 29, 26, 0.5);
    text-align: left;
    flex: 1;
    min-width: 0;
    padding-right: 8px;
  }

  .detail-table tr.row-detail td {
    display: block;
    padding: 0 14px 12px;
  }

  .detail-table tr.row-detail td::before {
    display: none;
  }

  .detail-table tr.row-detail td[colspan] {
    display: block;
  }

  .detail-expand {
    font-size: 13px;
  }

  .detail-expand p,
  .detail-expand li {
    font-size: 13px;
    line-height: 1.5;
  }

  .timeline li {
    padding: 10px 0;
  }
}

/* Desktop: hide columns that are redundant */
@media (min-width: 768px) and (max-width: 1023px) {
  .users-table .col-ac-n,
  .users-table .col-tokens {
    display: none;
  }
}

.chart-wrap {
  touch-action: pan-y;
}

/* Login page (no Tailwind CDN) */
.login-card {
  width: 100%;
  max-width: 28rem;
  background: #f5efe6;
  border: 1px solid rgba(31, 29, 26, 0.1);
  border-radius: 1rem;
  padding: 1.5rem 2rem;
  box-shadow: 0 1px 3px rgba(31, 29, 26, 0.06);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}
.login-brand img {
  border-radius: 0.75rem;
}
.login-title {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
.login-sub {
  font-size: 0.875rem;
  color: rgba(31, 29, 26, 0.6);
  margin-top: 0.5rem;
}
.login-error {
  margin-top: 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  color: #c8102e;
  background: rgba(200, 16, 46, 0.08);
  border: 1px solid rgba(200, 16, 46, 0.25);
  border-radius: 0.75rem;
  padding: 0.5rem 0.75rem;
  line-height: 1.4;
}
.login-error.hidden {
  display: none;
}
.login-google {
  margin-top: 1.5rem;
  width: 100%;
  min-height: 48px;
  padding: 0.75rem 1rem;
  border-radius: 999px;
  background: #1f1d1a;
  color: #f5efe6;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}
.login-google:disabled {
  opacity: 0.6;
  cursor: wait;
}
.login-google:hover:not(:disabled) {
  background: #2a2722;
}
.login-hint {
  margin-top: 1.5rem;
  font-size: 0.75rem;
  color: rgba(31, 29, 26, 0.5);
  text-align: center;
  line-height: 1.5;
}
.login-hint a {
  color: #1f1d1a;
  font-weight: 500;
}

/* ----- User detail modal (tabs + Firestore tables) ----- */
.detail-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid rgba(31, 29, 26, 0.1);
  position: sticky;
  top: 0;
  background: #faf6ef;
  z-index: 2;
}
.detail-tab {
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid rgba(31, 29, 26, 0.15);
  background: #f5efe6;
  color: rgba(31, 29, 26, 0.75);
  cursor: pointer;
}
.detail-tab.active {
  background: #1f1d1a;
  color: #f5efe6;
  border-color: #1f1d1a;
}
.detail-panel {
  display: none;
}
.detail-panel.active {
  display: block;
}
.detail-section-title {
  font-size: 13px;
  font-weight: 600;
  margin: 1.25rem 0 0.5rem;
}
.detail-section-title:first-child {
  margin-top: 0;
}
.detail-empty,
.detail-hint {
  font-size: 13px;
  color: rgba(31, 29, 26, 0.55);
}
.detail-table-wrap {
  overflow-x: auto;
  margin-bottom: 1rem;
  -webkit-overflow-scrolling: touch;
}
.detail-table {
  width: 100%;
  font-size: 12px;
  border-collapse: collapse;
}
.detail-table th {
  text-align: left;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgba(31, 29, 26, 0.5);
  padding: 6px 8px;
  border-bottom: 1px solid rgba(31, 29, 26, 0.12);
  white-space: nowrap;
}
.detail-table td {
  padding: 8px;
  border-bottom: 1px solid rgba(31, 29, 26, 0.06);
  vertical-align: top;
}
.detail-table tr.row-fail td {
  background: rgba(200, 16, 46, 0.06);
}
.detail-table tr.row-detail td {
  background: rgba(31, 29, 26, 0.03);
  padding-top: 0;
}
.detail-expand {
  font-size: 12px;
  line-height: 1.45;
  color: rgba(31, 29, 26, 0.8);
}
.detail-expand p {
  margin: 4px 0 10px;
  white-space: pre-wrap;
  word-break: break-word;
}
.detail-expand strong {
  display: block;
  margin-top: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgba(31, 29, 26, 0.5);
}
.score-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 1rem;
}
@media (min-width: 640px) {
  .score-cards {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}
.score-card {
  background: #f5efe6;
  border: 1px solid rgba(31, 29, 26, 0.1);
  border-radius: 12px;
  padding: 10px 12px;
}
.score-card-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: rgba(31, 29, 26, 0.5);
  margin-bottom: 6px;
}
.score-card-big {
  font-size: 1.25rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.score-card-sub {
  font-size: 11px;
  color: rgba(31, 29, 26, 0.5);
  margin-top: 4px;
}
.grade-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.grade-pill.pass {
  background: rgba(34, 120, 60, 0.15);
  color: #1a5c30;
}
.grade-pill.fail {
  background: rgba(200, 16, 46, 0.12);
  color: #9b0a1f;
}
.grade-pill.marginal {
  background: rgba(185, 147, 58, 0.2);
  color: #6b5418;
}
.grade-pill.unk {
  background: rgba(31, 29, 26, 0.08);
  color: rgba(31, 29, 26, 0.45);
}

/* --- Tab navigation (added to de-clutter the long scroll) ------------------ */
.no-scrollbar { -ms-overflow-style: none; scrollbar-width: none; }
.no-scrollbar::-webkit-scrollbar { display: none; }

.tab-btn {
  flex: 0 0 auto;
  padding: 0.5rem 1.05rem;
  min-height: 40px;
  border-radius: 9999px;
  font-size: 0.9rem;
  font-weight: 600;
  color: rgba(31, 29, 26, 0.6);
  background: transparent;
  border: 1px solid transparent;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.tab-btn:hover { background: rgba(31, 29, 26, 0.06); }
.tab-btn.active {
  background: #1f1d1a;
  color: #f5efe6;
}
.tab-btn:focus-visible {
  outline: 2px solid rgba(31, 29, 26, 0.3);
  outline-offset: 2px;
}

/* --- Insights: auto callouts + engagement funnel -------------------------- */
.callout { border-radius: 12px; padding: 0.75rem 0.9rem; }
.callout-head {
  font-size: 0.62rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em;
}
.callout-title { font-weight: 600; font-size: 0.95rem; margin-top: 0.15rem; line-height: 1.3; }
.callout-body { font-size: 0.82rem; color: rgba(31, 29, 26, 0.7); margin-top: 0.25rem; line-height: 1.45; }

.funnel-meta {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 0.82rem; font-weight: 600; margin-bottom: 0.3rem;
}
.funnel-n { color: rgba(31, 29, 26, 0.55); font-weight: 500; }
.funnel-track {
  height: 10px; background: rgba(31, 29, 26, 0.08);
  border-radius: 9999px; overflow: hidden;
}
.funnel-bar { height: 100%; background: #1f1d1a; border-radius: 9999px; transition: width 0.4s ease; }
.funnel-drop { font-size: 0.7rem; color: rgba(31, 29, 26, 0.45); margin-top: 0.25rem; }
