/* ═══════════════════════════════════════════════════
   barter/css/base.css
   Design tokens, reset, and layout primitives
   ═══════════════════════════════════════════════════ */

/* ── Design Tokens ── */
:root {
  /* Brand */
  --c-primary:       #2B6E4A;
  --c-primary-light: #58B272;
  --c-primary-pale:  #EAF5EE;
  --c-primary-dark:  #1D5C38;

  /* Neutrals */
  --c-bg:      #F7F4EE;
  --c-card:    #FFFFFF;
  --c-text:    #1A1A18;
  --c-muted:   #6B7282;
  --c-border:  #E5E0D8;
  --c-border2: #CEC9C0;

  /* Semantic */
  --c-danger:  #DC2626;
  --c-warn:    #D97706;
  --c-success: #16A34A;
  --c-info:    #2563EB;
  --c-boost:   #FFFBF0;
  --c-boost-border: #F0D890;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  --font-mono: 'Fira Code', 'Cascadia Code', Consolas, monospace;

  /* Spacing */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;

  /* Radii */
  --r-sm:  8px;
  --r-md:  12px;
  --r-lg:  16px;
  --r-xl:  20px;
  --r-full: 9999px;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.10), 0 2px 4px rgba(0,0,0,.06);
  --shadow-fab: 0 4px 16px rgba(43,110,74,.40);

  /* Transitions */
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur: 150ms;

  /* Layout */
  --header-h:     56px;
  --bottomnav-h:  64px;
  --safe-bottom:  env(safe-area-inset-bottom, 0px);
}

/* ── System dark-mode token overrides ── */
@media (prefers-color-scheme: dark) {
  :root {
    --c-bg:      #111310;
    --c-card:    #1A1C18;
    --c-text:    #F0EDE7;
    --c-muted:   #9B9E96;
    --c-border:  #2E2E2A;
    --c-border2: #3D3D38;
    --c-primary-pale: #0E2A1C;
  }
}

/* ── Reset ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-sans);
  font-size: 1rem;
  line-height: 1.5;
  color: var(--c-text);
  background: var(--c-bg);
  min-height: 100dvh;
  overscroll-behavior: none;
}

img, video, svg { display: block; max-width: 100%; }

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

input, textarea, select {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

ul, ol { list-style: none; }

/* ── Accessibility ── */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 2px solid var(--c-primary);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ── Typography Scale ── */
.text-xs   { font-size: 11px; }
.text-sm   { font-size: 13px; }
.text-base { font-size: 15px; }
.text-lg   { font-size: 18px; }
.text-xl   { font-size: 22px; }
.text-2xl  { font-size: 26px; }

.font-medium { font-weight: 500; }
.font-bold   { font-weight: 700; }
.font-black  { font-weight: 900; }

.text-muted   { color: var(--c-muted); }
.text-primary { color: var(--c-primary); }
.text-danger  { color: var(--c-danger); }

/* ── Utility ── */
.hidden       { display: none !important; }
.invisible    { visibility: hidden; }
.truncate     { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── App Shell Layout ── */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  background: var(--c-bg);
}

/* ── Header ── */
.app-header {
  height: var(--header-h);
  background: var(--c-card);
  border-bottom: 1px solid var(--c-border);
  flex-shrink: 0;
  z-index: 100;
}

.app-header__inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
  padding: 0 var(--space-4);
  gap: var(--space-3);
}

.app-header__left,
.app-header__right {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 44px;
}
.app-header__right { justify-content: flex-end; }

.wordmark {
  font-size: 22px;
  font-weight: 900;
  color: var(--c-primary);
  letter-spacing: -1px;
  line-height: 1;
}

/* ── Screen Container ── */
.screen-container {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.screen {
  min-height: 100%;
  padding-bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 16px);
}

/* ── Bottom Nav ── */
.bottom-nav {
  height: calc(var(--bottomnav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--c-card);
  border-top: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  z-index: 100;
}

.nav-tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 0;
  color: var(--c-muted);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: .2px;
  transition: color var(--dur) var(--ease);
  position: relative;
  min-height: 44px;   /* WCAG touch target */
  min-width: 44px;
}

.nav-tab[aria-current="page"],
.nav-tab.is-active {
  color: var(--c-primary);
  font-weight: 700;
}

.nav-tab--post {
  color: var(--c-card);
}

.nav-tab--post svg {
  width: 44px; height: 44px;
  background: var(--c-primary);
  border-radius: var(--r-full);
  padding: 10px;
  margin-top: -18px;
  box-shadow: var(--shadow-fab);
  stroke: var(--c-card);
  transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}

.nav-tab--post:active svg {
  transform: scale(.93);
}

.nav-tab--post.is-active svg {
  background: var(--c-primary-dark);
}

.nav-badge {
  position: absolute;
  top: 4px; right: calc(50% - 18px);
  background: var(--c-danger);
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  min-width: 16px; height: 16px;
  border-radius: var(--r-full);
  padding: 0 4px;
  border: 2px solid var(--c-card);
  display: none;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.nav-badge:not(:empty) { display: flex; }

/* ── Notification Badge (header) ── */
.icon-btn {
  position: relative;
  width: 40px; height: 40px;
  border-radius: var(--r-sm);
  background: var(--c-primary-pale);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-primary);
  transition: background var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--c-border); }

.notif-badge {
  position: absolute;
  top: 5px; right: 5px;
  width: 8px; height: 8px;
  background: var(--c-danger);
  border-radius: var(--r-full);
  border: 2px solid var(--c-card);
  display: none;
}
.notif-badge:not(:empty) { display: block; }
[data-notify-count]:not([data-notify-count="0"]) .notif-badge { display: block; }

/* ── Install Banner ── */
.install-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  background: var(--c-primary);
  color: #fff;
  padding: var(--space-3) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  z-index: 999;
  box-shadow: var(--shadow-md);
}

.install-banner__content {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  flex: 1;
  min-width: 0;
}
.install-banner__content div {
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.install-banner__content strong {
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.install-banner__content span {
  font-size: 11px;
  opacity: .85;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Offline Bar ── */
.offline-bar {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom));
  left: 0; right: 0;
  background: var(--c-warn);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2);
  z-index: 200;
}

/* ── Toast Notifications ── */
.toast-container {
  position: fixed;
  bottom: calc(var(--bottomnav-h) + var(--safe-bottom) + 16px);
  left: var(--space-4);
  right: var(--space-4);
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  pointer-events: none;
}

.toast {
  background: var(--c-text);
  color: var(--c-bg);
  font-size: 13px;
  font-weight: 500;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--r-md);
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toastIn .2s var(--ease);
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.toast--success { background: var(--c-success); }
.toast--error   { background: var(--c-danger); }
.toast--warn    { background: var(--c-warn); }

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

/* ── Auth Gate ── */
.auth-gate {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--c-bg);
}

/* Single solid white card containing ALL auth content.
   Replaces the old approach of styling each child separately. */
.auth-card {
  background: var(--c-card);
  border-radius: var(--r-xl);
  padding: var(--space-5) var(--space-5) var(--space-4);
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-md);
  text-align: center;
}

/* ── Ad Banner ── */
.ad-banner {
  margin: var(--space-4);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  overflow: hidden;
  position: relative;
  min-height: 60px;
  background: var(--c-card);
}

.ad-badge {
  position: absolute;
  top: 4px; left: 6px;
  font-size: 9px;
  font-weight: 700;
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  z-index: 1;
}

/* ══════════════════════════════════════════════════
   DESKTOP AUTH — WeTransfer style
   Auth card floats over a full-screen ad background.
   Hidden on mobile (auth gate is full-screen there).
   ══════════════════════════════════════════════════ */

@media (min-width: 768px) {
  /* Ad fills entire background */
  .auth-ad-bg {
    position: fixed;
    inset: 0;
    z-index: 0;
  }

  /* Auth gate becomes a transparent overlay, centred */
  .auth-gate {
    position: fixed !important;
    inset: 0;
    z-index: 10;
    display: flex !important;
    align-items: center;
    justify-content: center;
    background: transparent !important;
    padding: var(--space-6);
  }

  /* Desktop: bigger shadow, max-height scroll for tall screens */
  .auth-card {
    max-width: 440px;
    box-shadow: 0 24px 64px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.2);
    position: relative;
    z-index: 1;
    max-height: 92dvh;
    overflow-y: auto;
  }
}


/* On mobile the auth-ad-bg is invisible */
@media (max-width: 767px) {
  .auth-ad-bg { display: none !important; }
}

/* ══════════════════════════════════════════════════
   FEED BANNER AD
   ══════════════════════════════════════════════════ */
.ad-banner {
  min-height: 64px;
  background: var(--c-card);
}

/* ══════════════════════════════════════════════════
   AD-FREE BADGE (profile screen)
   ══════════════════════════════════════════════════ */
.adfree-active {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--c-primary-pale);
  color: var(--c-primary);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: var(--r-full);
  border: 1px solid #8FD4AD;
}
