/* Taco Tally Web App – consistent with main site, WCAG AA 2.1 */
:root {
  --taco-yellow: #e6c220;
  --taco-gold: #d4a506;
  --taco-green: #4a9e3a;
  --taco-mint: #6bc459;
  --app-bg: #f5f3f0;
  --app-surface: #ffffff;
  --app-text: #1c1a18;
  --app-text-muted: #3d3935;
  --app-border: #e8e6e2;
  --app-primary: #92278f;
  --app-primary-dark: #6b1d69;
  --app-radius: 12px;
  --app-radius-md: 20px;
  --app-font: "Outfit", sans-serif;
  --font-display: "Fredoka", sans-serif;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.08);
  --transition: 0.25s ease;
  --focus-ring: 2px solid var(--app-primary);
  --focus-offset: 2px;
  /* Font scaling: respect browser/user font size, scale between 100% and 125% */
  --app-font-size-base: clamp(1rem, 0.95rem + 0.25vw, 1.25rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --app-bg: #1c1a18;
    --app-surface: #2a2725;
    --app-text: #f5f3f0;
    --app-text-muted: #b5b2ae;
    --app-border: #3d3935;
    --app-primary: #c44fc1;
    --app-primary-dark: #92278f;
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --transition: 0s;
  }
}

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

body.app-page {
  margin: 0;
  font-family: var(--app-font);
  font-size: var(--app-font-size-base);
  line-height: 1.5;
  color: var(--app-text);
  background: var(--app-bg);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Skip link for accessibility */
.app-skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  padding: 12px 16px;
  background: var(--app-primary);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  border-radius: var(--app-radius);
  z-index: 1000;
  transition: top 0.2s ease;
}
.app-skip-link:focus {
  top: 16px;
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Login page */
.app-login {
  max-width: 400px;
  margin: 0 auto;
  padding: 24px 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.app-login__header {
  text-align: center;
  margin-bottom: 32px;
}

.app-login__logo {
  display: block;
  font-weight: 700;
  font-size: 1.5rem;
  color: var(--app-text);
  text-decoration: none;
  margin-bottom: 8px;
}

.app-login__logo:hover {
  color: var(--app-primary);
}

.app-login__logo img {
  height: 32px;
  width: auto;
  display: block;
}

.app-login__logo:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-radius: 4px;
}

.app-login__tagline {
  margin: 0;
  font-size: 0.9375rem;
  color: var(--app-text-muted);
}

.app-login__steps {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
}

.app-login__step-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--app-border);
  transition: background var(--transition);
}

.app-login__step-dot.active {
  background: var(--app-primary);
  transform: scale(1.2);
}

.app-login__step-dot.done {
  background: var(--taco-green);
}

.app-login__trust-note {
  font-size: 0.875rem;
  color: var(--app-text-muted);
  margin: 0 0 16px;
  padding: 10px 12px;
  background: var(--app-surface);
  border-radius: var(--app-radius);
  border: 1px solid var(--app-border);
}

.app-login__main {
  margin-bottom: 32px;
}

.app-login__step {
  display: block;
}

.app-login__label {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 6px;
  color: var(--app-text);
}

.app-login__phone-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  align-items: stretch;
}

.app-login__country-code {
  flex: 0 0 auto;
  min-width: 0;
  width: 100%;
  max-width: 110px;
  padding: 12px 10px;
  font-family: var(--app-font);
  font-size: 0.9375rem;
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  background: var(--app-surface);
  color: var(--app-text);
  cursor: pointer;
}

.app-login__country-code:focus {
  outline: none;
  border-color: var(--app-primary);
}

.app-login__country-code:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.app-login__country-code[aria-invalid="true"] {
  border-color: #b32d2d;
}

.app-login__country-code-other {
  flex: 0 0 auto;
  width: 72px;
  padding: 12px 10px;
  font-family: var(--app-font);
  font-size: 0.9375rem;
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
}

.app-login__country-code-other:focus {
  outline: none;
  border-color: var(--app-primary);
}

.app-login__country-code-other:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.app-login__country-code-other[aria-invalid="true"] {
  border-color: #b32d2d;
}

.app-login__phone-input {
  flex: 1 1 auto;
  min-width: 0;
  margin-bottom: 0;
}

.app-login__input {
  width: 100%;
  padding: 12px 14px;
  font-family: var(--app-font);
  font-size: 1rem;
  border: 1px solid var(--app-border);
  border-radius: var(--app-radius);
  margin-bottom: 12px;
}

.app-login__input:focus {
  outline: none;
  border-color: var(--app-primary);
}

.app-login__input:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.app-login__input[aria-invalid="true"] {
  border-color: #b32d2d;
}

.app-login__error {
  margin: 0 0 12px;
  font-size: 0.875rem;
  color: #b32d2d;
}

.app-login__error[hidden] {
  display: none;
}

.app-login__hint {
  margin: 0 0 16px;
  font-size: 0.9375rem;
  color: var(--app-text-muted);
}

#recaptcha-container {
  margin-bottom: 12px;
}

.app-login__footer {
  text-align: center;
  font-size: 0.875rem;
  color: var(--app-text-muted);
}

.app-login__footer a {
  color: var(--app-primary);
  font-weight: 600;
}

.app-login__footer a:hover {
  text-decoration: underline;
}

.app-login__footer a:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-radius: 4px;
}

/* Buttons – with feedback and WCAG focus */
.app-btn {
  display: inline-block;
  width: 100%;
  padding: 14px 20px;
  font-family: var(--app-font);
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  border-radius: var(--app-radius);
  border: none;
  cursor: pointer;
  text-decoration: none;
  margin-bottom: 10px;
  transition: transform var(--transition), box-shadow var(--transition), opacity 0.2s;
}

.app-btn:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}

.app-btn:active:not(:disabled) {
  transform: translateY(0);
}

.app-btn:focus {
  outline: none;
}

.app-btn:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

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

.app-btn--primary {
  background: var(--app-primary);
  color: #fff;
}

.app-btn--primary:hover:not(:disabled) {
  background: var(--app-primary-dark);
}

.app-btn--secondary {
  background: var(--app-surface);
  color: var(--app-text);
  border: 1px solid var(--app-border);
}

.app-btn--secondary:hover:not(:disabled) {
  background: var(--app-bg);
}

.app-btn--ghost {
  background: transparent;
  color: var(--app-text-muted);
}

.app-btn--ghost:hover:not(:disabled) {
  color: var(--app-text);
}

.app-btn--small {
  padding: 8px 14px;
  font-size: 0.875rem;
  width: auto;
  margin-bottom: 0;
}

/* Complete signup page */
.app-complete-signup {
  max-width: 420px;
  margin: 0 auto;
  padding: 48px 24px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.app-complete-signup__header {
  margin-bottom: 24px;
}

.app-complete-signup__title {
  margin: 0 0 12px;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--app-text);
}

.app-complete-signup__subtitle {
  margin: 0 0 32px;
  font-size: 1rem;
  color: var(--app-text-muted);
  line-height: 1.5;
}

.app-complete-signup__main {
  width: 100%;
}

.app-complete-signup__ctas {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 280px;
  margin: 0 auto;
}

.app-complete-signup__desktop-hint {
  margin: 0 0 16px;
  font-size: 0.9375rem;
  color: var(--app-text-muted);
}

.app-complete-signup__footer {
  margin-top: 32px;
}

.app-link {
  font-size: 0.9375rem;
  color: var(--app-primary);
  font-weight: 600;
  text-decoration: none;
}

.app-link:hover {
  text-decoration: underline;
}

.app-link:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-radius: 4px;
}

/* Dashboard – safe area for notched devices */
.app-dashboard {
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
  padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px));
}

.app-dashboard__nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--app-surface);
  border-top: 1px solid var(--app-border);
  display: flex;
  justify-content: space-around;
  padding: 8px 0 calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 100;
}

.app-dashboard__nav-link {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--app-text-muted);
  text-decoration: none;
  border-radius: var(--app-radius);
  transition: color var(--transition), background var(--transition);
}

.app-dashboard__nav-link:hover {
  color: var(--app-primary);
}

.app-dashboard__nav-link.active {
  color: var(--app-primary);
}

.app-dashboard__nav-link.active .app-dashboard__nav-icon {
  color: var(--app-primary);
}

.app-dashboard__nav-link:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.app-dashboard__nav-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--app-text-muted);
  transition: color var(--transition);
}

.app-dashboard__header {
  background: var(--app-surface);
  padding: 16px 20px;
  border-bottom: 1px solid var(--app-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.app-dashboard__logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--app-text);
  text-decoration: none;
}

.app-dashboard__logo:hover {
  color: var(--app-primary);
}

.app-dashboard__logo:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-radius: 4px;
}

.app-dashboard__logo-img {
  height: 28px;
  width: auto;
  display: block;
}

.app-dashboard__content {
  padding: 20px;
}

/* View transitions */
.app-view {
  display: none;
  animation: app-view-fade-in 0.2s ease;
}

.app-view.active {
  display: block;
}

@keyframes app-view-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@media (prefers-reduced-motion: reduce) {
  .app-view.active {
    animation: none;
  }
  .app-btn,
  .app-dashboard__nav-link,
  .app-home__link {
    transition: none;
  }
  .app-skeleton {
    animation: none;
    background: var(--app-border);
  }
  .app-toast {
    animation: none;
  }
}

/* Home view – hero count and cards */
.app-home__count {
  text-align: center;
  padding: 40px 20px;
  background: var(--app-surface);
  border-radius: var(--app-radius-md);
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.app-home__count-value {
  font-size: 3.5rem;
  font-weight: 700;
  color: var(--app-primary);
  line-height: 1;
  font-family: var(--font-display), var(--app-font);
}

.app-home__count-label {
  font-size: 1rem;
  color: var(--app-text-muted);
  margin-top: 6px;
}

.app-home__log-cta {
  margin-bottom: 24px;
}

.app-home__log-cta .app-btn {
  margin-bottom: 10px;
}

.app-home__log-desktop {
  font-size: 0.875rem;
  color: var(--app-text-muted);
  margin-top: 8px;
}

.app-home__links {
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr 1fr;
}

.app-home__link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--app-surface);
  border-radius: var(--app-radius);
  border: 1px solid var(--app-border);
  color: var(--app-text);
  text-decoration: none;
  font-weight: 600;
  transition: border-color var(--transition), color var(--transition), box-shadow var(--transition);
}

.app-home__link:hover {
  border-color: var(--app-primary);
  color: var(--app-primary);
  box-shadow: var(--shadow-sm);
}

.app-home__link:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
}

.app-home__link-icon {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
  color: var(--app-text-muted);
}

.app-home__link:hover .app-home__link-icon {
  color: var(--app-primary);
}

/* Empty states */
.app-empty {
  text-align: center;
  padding: 40px 24px;
}

.app-empty__img {
  max-width: 160px;
  height: auto;
  margin: 0 auto 20px;
  display: block;
}

.app-empty__title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--app-text);
  margin: 0 0 8px;
}

.app-empty__text {
  font-size: 0.9375rem;
  color: var(--app-text-muted);
  margin: 0;
  line-height: 1.5;
}

/* Skeleton loading */
.app-skeleton {
  background: linear-gradient(
    90deg,
    var(--app-border) 0%,
    var(--app-bg) 50%,
    var(--app-border) 100%
  );
  background-size: 200% 100%;
  animation: app-skeleton-pulse 1.2s ease-in-out infinite;
  border-radius: var(--app-radius);
}

@keyframes app-skeleton-pulse {
  0% {
    background-position: 200% 0;
  }
  100% {
    background-position: -200% 0;
  }
}

.app-skeleton--circle {
  border-radius: 50%;
}

.app-skeleton--text {
  height: 1em;
}

.app-groups__skeleton,
.app-leaderboard__skeleton {
  margin-bottom: 10px;
}

/* Groups view */
.app-groups__join {
  margin-bottom: 24px;
  padding: 20px;
  background: var(--app-surface);
  border-radius: var(--app-radius);
  border: 1px solid var(--app-border);
}

.app-groups__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.app-groups__item {
  padding: 16px 20px;
  background: var(--app-surface);
  border-radius: var(--app-radius);
  margin-bottom: 10px;
  border: 1px solid var(--app-border);
}

.app-groups__item-name {
  font-weight: 600;
  margin: 0 0 4px;
}

.app-groups__item-meta {
  font-size: 0.875rem;
  color: var(--app-text-muted);
  margin: 0;
}

.app-groups__loading,
.app-groups__empty {
  text-align: center;
  padding: 32px 20px;
  color: var(--app-text-muted);
}

.app-groups__empty[hidden],
.app-groups__loading[hidden],
.app-groups__error[hidden] {
  display: none !important;
}

.app-groups__error {
  margin-bottom: 16px;
}

.app-groups__retry {
  margin-top: 12px;
}

/* Leaderboard view */
.app-leaderboard__list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.app-leaderboard__row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--app-surface);
  border-radius: var(--app-radius);
  margin-bottom: 8px;
  border: 1px solid var(--app-border);
  transition: border-color var(--transition), background var(--transition);
}

.app-leaderboard__row.rank-1 {
  border-color: var(--taco-gold);
  background: linear-gradient(135deg, #fffef8 0%, var(--app-surface) 100%);
}

.app-leaderboard__row.rank-2 {
  border-color: var(--app-border);
  background: linear-gradient(135deg, #fafafa 0%, var(--app-surface) 100%);
}

.app-leaderboard__row.rank-3 {
  border-color: #c4a574;
  background: linear-gradient(135deg, #fdfbf7 0%, var(--app-surface) 100%);
}

.app-leaderboard__row.you {
  border-color: var(--app-primary);
  background: rgba(146, 39, 143, 0.06);
}

.app-leaderboard__rank {
  font-weight: 700;
  color: var(--app-text-muted);
  min-width: 32px;
  text-align: right;
}

.app-leaderboard__row.rank-1 .app-leaderboard__rank {
  color: var(--taco-gold);
}

.app-leaderboard__row.rank-2 .app-leaderboard__rank {
  color: var(--app-text-muted);
}

.app-leaderboard__row.rank-3 .app-leaderboard__rank {
  color: #8b6914;
}

.app-leaderboard__medal {
  width: 24px;
  height: 24px;
  flex-shrink: 0;
}

.app-leaderboard__row.rank-1 .app-leaderboard__medal {
  color: var(--taco-gold);
}

.app-leaderboard__row.rank-2 .app-leaderboard__medal {
  color: var(--app-text-muted);
}

.app-leaderboard__row.rank-3 .app-leaderboard__medal {
  color: #8b6914;
}

.app-leaderboard__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--app-bg);
  object-fit: cover;
  flex-shrink: 0;
}

.app-leaderboard__info {
  flex: 1;
  min-width: 0;
}

.app-leaderboard__username {
  font-weight: 600;
  margin: 0;
}

.app-leaderboard__count {
  font-size: 0.875rem;
  color: var(--app-primary);
  font-weight: 600;
  margin: 0;
}

.app-leaderboard__you-badge {
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--app-primary);
  margin-left: 6px;
}

.app-leaderboard__empty[hidden],
.app-leaderboard__loading[hidden],
.app-leaderboard__error[hidden] {
  display: none !important;
}

.app-leaderboard__retry {
  margin-top: 12px;
}

/* Profile view */
.app-profile__card {
  padding: 24px 20px;
  background: var(--app-surface);
  border-radius: var(--app-radius);
  margin-bottom: 20px;
  border: 1px solid var(--app-border);
}

.app-profile__avatar {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--app-bg);
  object-fit: cover;
  margin-bottom: 12px;
}

.app-profile__name {
  margin: 0 0 4px;
  font-size: 1.25rem;
  font-weight: 700;
}

.app-profile__username {
  margin: 0 0 16px;
  font-size: 0.9375rem;
  color: var(--app-text-muted);
}

.app-profile__stat {
  font-size: 0.9375rem;
  color: var(--app-text-muted);
  margin: 0 0 16px;
}

.app-profile__referral {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--app-border);
}

.app-profile__referral-label {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0 0 8px;
}

.app-profile__referral-row {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.app-profile__referral-link {
  font-size: 0.875rem;
  color: var(--app-primary);
  word-break: break-all;
  flex: 1;
  min-width: 0;
}

.app-profile__referral-link:focus-visible {
  outline: var(--focus-ring);
  outline-offset: var(--focus-offset);
  border-radius: 4px;
}

.app-profile__copy-btn {
  flex-shrink: 0;
}

.app-profile__copy-toast {
  font-size: 0.875rem;
  color: var(--taco-green);
  font-weight: 600;
  margin-top: 6px;
}

.app-profile__copy-toast[hidden] {
  display: none !important;
}

.app-profile__logout {
  margin-top: 24px;
}

/* Toast for copy confirmation */
.app-toast {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: var(--app-text);
  color: var(--app-surface);
  font-size: 0.875rem;
  font-weight: 600;
  border-radius: var(--app-radius);
  box-shadow: var(--shadow-md);
  z-index: 200;
  animation: app-toast-in 0.25s ease;
}

@keyframes app-toast-in {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
  }
}
