/* ============================================================
   Creator Cache™ — mobile & installed-app layer

   Loaded last, so it wins on equal specificity. Everything here
   is either phone-only (inside a max-width query) or safe at
   every size; the desktop layout is untouched.

   Three jobs:
     1. make a phone a first-class target, not a shrunk desktop
     2. behave like an app once installed (safe areas, no
        rubber-band, no accidental zoom, a real tab bar)
     3. keep hit targets at 44px, which is where most of the
        "it doesn't work on my phone" reports actually come from
   ============================================================ */

:root {
  /* One place to change the bar height; mobile.js reads it too. */
  --tabbar-h: 58px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

/* ---------- Global touch hygiene ---------- */

/* The grey flash on tap reads as broken on Android; we do our own
   :active states below. */
* { -webkit-tap-highlight-color: transparent; }

/* iOS zooms the page in whenever a focused input is under 16px, and
   never zooms back out. Every text entry is therefore >= 16px on
   touch devices; the desktop sizes are left alone. */
@media (max-width: 900px) {
  .input,
  .field input, .field textarea, .field select,
  input[type="text"], input[type="email"], input[type="password"],
  input[type="number"], input[type="tel"], input[type="url"],
  input[type="search"], input[type="date"], textarea, select {
    font-size: 16px;
  }
}

/* Coarse pointers get real targets. Keyed off the pointer rather than
   the width, so a large tablet is covered too. */
@media (pointer: coarse) {
  .btn-sm { min-height: 44px; padding: 10px 16px; }
  .icon-btn, .modal-close { min-width: 44px; min-height: 44px; }
  .nav-item { min-height: 48px; }
  /* Hover transforms fire on tap on touch devices and leave elements
     stuck mid-animation; the :active state replaces them. */
  .btn-primary:hover, .feature-card:hover { transform: none; }
  .btn:active { transform: scale(0.97); }
}

/* ---------- Bottom tab bar (phones + installed app) ---------- */

.tabbar { display: none; }

@media (max-width: 900px) {
  .tabbar {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 180;
    height: calc(var(--tabbar-h) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    padding-left: var(--safe-left); padding-right: var(--safe-right);
    background: var(--chrome-bg);
    border-top: 1px solid var(--border);
    backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  }
  .tabbar-item {
    flex: 1 1 0; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; padding: 6px 2px 4px;
    background: transparent; border: none;
    color: var(--text-muted);
    font-size: 0.63rem; font-weight: 600;
    transition: color 0.15s ease;
    position: relative;
  }
  .tabbar-ico { font-size: 1.24rem; line-height: 1; }
  .tabbar-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar-item.active { color: var(--text-primary); }
  /* An active pip rather than a filled block: at this size a
     background highlight eats the label. */
  .tabbar-item.active::before {
    content: ""; position: absolute; top: 0; left: 50%;
    width: 26px; height: 3px; margin-left: -13px;
    border-radius: 0 0 3px 3px; background: var(--accent-gradient);
  }
  .tabbar-item:active { color: var(--text-primary); }

  /* The main pane has to clear the bar, or the last card in every
     view sits permanently underneath it. */
  .main { padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 26px); }

  /* Top bar respects the notch. */
  .mobile-bar {
    padding-top: calc(13px + var(--safe-top));
    padding-left: calc(16px + var(--safe-left));
    padding-right: calc(16px + var(--safe-right));
  }
  .mobile-bar .logo { font-size: 0.98rem; }

  /* The drawer is reached from the More tab, and has to clear the
     notch and the home indicator. */
  .sidebar {
    padding-top: calc(22px + var(--safe-top));
    padding-bottom: calc(22px + var(--safe-bottom));
    width: min(86vw, 300px);
  }
  .sidebar-scrim { -webkit-backdrop-filter: blur(2px); backdrop-filter: blur(2px); }

  /* Toasts must clear the tab bar. */
  #toast-root { bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 14px); }
}

/* ---------- Modals become bottom sheets on a phone ----------
   A centred 460px card on a 390px screen is a card with 18px of
   margin and a scrollbar. A sheet is thumb-reachable, and matches
   what every other app on the device does. */
@media (max-width: 640px) {
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    max-width: 100%;
    max-height: 92dvh;
    border-radius: 22px 22px 0 0;
    padding: 22px 18px calc(22px + var(--safe-bottom));
    animation: sheetUp 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
    /* Momentum scrolling inside the sheet without dragging the page. */
    overscroll-behavior: contain;
  }
  /* Grab handle: the affordance that says "this slides". */
  .modal::before {
    content: ""; display: block;
    width: 38px; height: 4px; margin: -6px auto 14px;
    border-radius: 999px; background: var(--border);
  }
  .modal-wide { max-width: 100%; }
  .auth-gate .modal { max-height: 94dvh; }
}

@keyframes sheetUp {
  from { opacity: 0.6; transform: translateY(100%); }
  to   { opacity: 1;   transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  .modal { animation: none !important; }
  .tabbar-item { transition: none; }
}

/* ---------- Horizontal boards: swipe, don't squash ---------- */
@media (max-width: 900px) {
  .kanban {
    overflow-x: auto; scroll-snap-type: x mandatory;
    -webkit-overflow-scrolling: touch; overscroll-behavior-x: contain;
    gap: 12px; padding-bottom: 6px;
    /* Bleed to the screen edges so a column peeking in at the right
       reads as "swipe me" instead of a clipped layout. */
    margin-left: -16px; margin-right: -16px;
    padding-left: 16px; padding-right: 16px;
    scrollbar-width: none;
  }
  .kanban::-webkit-scrollbar { display: none; }
  .kanban-col { scroll-snap-align: start; min-width: min(78vw, 300px); }

  /* Any wide table stays inside its own scroller rather than making
     the whole page scroll sideways. */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
}

/* ---------- Installed-app behaviour ---------- */
/* All three modes, not just standalone: a desktop install can land in
   minimal-ui, and everything below is about being a window rather than
   a tab. Keyed off standalone alone, the installed desktop app kept the
   browser's rubber-band scroll and text selection. */
@media (display-mode: standalone), (display-mode: minimal-ui),
       (display-mode: window-controls-overlay) {
  /* No rubber-band on the body: in a standalone window it exposes the
     blank window behind the app and reads as a rendering bug. */
  html, body { overscroll-behavior-y: none; }
  /* Long-press text selection all over a native-feeling app looks
     accidental, so it is off by default... */
  body { -webkit-user-select: none; user-select: none; }
  /* ...except everywhere a member legitimately needs to copy. */
  input, textarea, [contenteditable], .selectable,
  .code-row, .share-url, pre, code { -webkit-user-select: text; user-select: text; }
}

/* ---------- Install prompt (add to home screen) ---------- */
.install-card {
  position: fixed; left: 12px; right: 12px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  z-index: 700;
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 16px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: 16px; box-shadow: var(--shadow);
  animation: slideUp 0.3s ease;
}
@media (min-width: 901px) {
  .install-card { left: auto; right: 20px; bottom: 20px; width: 380px; }
}
.install-card .ic-ico { font-size: 1.6rem; line-height: 1; flex-shrink: 0; }
.install-card .ic-body { flex: 1; min-width: 0; }
.install-card .ic-title { font-weight: 700; font-size: 0.94rem; }
.install-card .ic-sub { color: var(--text-muted); font-size: 0.8rem; margin-top: 2px; line-height: 1.45; }
.install-card .ic-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* iOS has no beforeinstallprompt, so the only honest thing to show is
   the two taps that actually work in Safari. */
.ios-steps { font-size: 0.82rem; color: var(--text-muted); line-height: 1.6; margin-top: 6px; }
.ios-steps b { color: var(--text-primary); }

/* ---------- Offline / connection state ---------- */
.net-banner {
  position: fixed; left: 0; right: 0; top: 0; z-index: 800;
  padding: calc(7px + var(--safe-top)) 14px 7px;
  text-align: center; font-size: 0.82rem; font-weight: 600;
  background: rgba(var(--danger-rgb), 0.16); color: var(--danger);
  border-bottom: 1px solid rgba(var(--danger-rgb), 0.3);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.net-banner.online {
  background: rgba(var(--success-rgb), 0.16); color: var(--success);
  border-bottom-color: rgba(var(--success-rgb), 0.3);
}

/* ---------- Landing page on a phone ---------- */
@media (max-width: 720px) {
  .landing-nav { padding-top: calc(14px + var(--safe-top)); gap: 8px; flex-wrap: wrap; }
  .landing-nav .logo { font-size: 1rem; }
  /* .nav-auth is .flex, which does not wrap. With three controls on a
     390px screen the third slid off the right edge and body's
     overflow-x:hidden swallowed it — the button was in the DOM,
     clickable by nobody. */
  .nav-auth { gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
  .nav-auth .btn-sm { padding: 9px 12px; font-size: 0.8rem; }
  /* A three-line hero headline on a 360px screen needs the tighter
     leading, or it fills the viewport before the sub-copy. */
  .hero h1 { font-size: clamp(1.9rem, 8.5vw, 2.8rem); line-height: 1.12; }
  .hero p { font-size: 0.95rem; }
  .badge { font-size: 0.72rem; }
  .legal-foot { padding-bottom: calc(18px + var(--safe-bottom)); }
  .legal-foot nav { flex-wrap: wrap; justify-content: center; gap: 10px 14px; }
}

/* Landing CTAs stack full-width rather than wrapping into two
   different widths. .hero-cta is already flex + wrap in dashboard.css;
   this only changes the axis on a narrow screen. */
@media (max-width: 480px) {
  .hero-cta { flex-direction: column; align-items: stretch; }
  .hero-cta .btn { width: 100%; }
}
