/* ══════════════════════════════════════════════════════════════
   KONYCT WEB MOBILE — app-like polish for mobile browser
   Loaded after public_theme / app_shell so it can override.
   No new visual language — just tighter spacing, larger taps,
   safe-area handling, and 16px inputs so phones feel native.
   ══════════════════════════════════════════════════════════════ */

/* ── Foundation: no zoom, no sideways scroll, rubber-band polish ── */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scrollbar-gutter: stable;
}
body {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
* {
  -webkit-tap-highlight-color: transparent;
}

/* Safe-area: pages that use .page or .flex-layout get bottom inset */
.page,
.flex-layout {
  padding-bottom: env(safe-area-inset-bottom);
}

/* ── Container: generous on desktop, snug on phones ── */
@media (max-width: 640px) {
  :root { --container-padding: 16px; }
}
@media (max-width: 400px) {
  :root { --container-padding: 12px; }
}

/* ── App content: tighter on phones, respects safe area ── */
@media (max-width: 640px) {
  .app-content {
    padding: 16px 16px calc(80px + env(safe-area-inset-bottom)) !important;
  }
  /* Feed overrides its own app-content — keep it consistent */
  main.app-content { padding-bottom: calc(96px + env(safe-area-inset-bottom)) !important; }
  /* Legacy page-main */
  .page-main, main.page-main, .main {
    padding: 20px 0 calc(72px + env(safe-area-inset-bottom)) !important;
  }
}

/* ── Top bar: add safe-area top, keep blur, tighten on phones ── */
@media (max-width: 640px) {
  .top-bar,
  .top-nav {
    padding-top: env(safe-area-inset-top);
    min-height: calc(48px + env(safe-area-inset-top));
  }
  .top-bar { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
  .top-nav-inner { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
}

/* ── Bottom nav: true app-tab height + safe area ── */
@media (max-width: 640px) {
  .bottom-nav {
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    border-top: 1px solid var(--border);
    /* prevent content peeking through the seam */
    background: color-mix(in srgb, var(--bg) 96%, transparent);
  }
  .bottom-nav-item {
    min-height: 44px;
    min-width: 44px;
    justify-content: center;
    gap: 3px;
    font-size: 10px;
    letter-spacing: 0.02em;
  }
  .bottom-nav-item svg { width: 22px; height: 22px; }
}

/* ── Forms: the core fix — comfortable rhythm on phones ── */

/* Every input/select/textarea should be 16px on phones → no iOS zoom */
@media (max-width: 640px) {
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="url"],
  input[type="search"],
  input[type="tel"],
  textarea,
  select,
  .field-input,
  .form-field,
  .input {
    font-size: 16px !important;
    line-height: 1.45;
  }
  /* iOS zoom still triggers below 16px even inside transforms — force it */
  ::placeholder { font-size: 15px; }
}

/* Inputs: taller taps, roomier padding, clearer focus */
.form-field,
.field-input,
.input,
input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="url"],
input[type="search"],
textarea,
select {
  min-height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  font-weight: 500;
  letter-spacing: -0.01em;
}
textarea.form-field,
textarea,
.field-textarea {
  padding: 14px 14px;
  min-height: 110px;
  line-height: 1.55;
}
@media (max-width: 640px) {
  .form-field,
  .field-input,
  .input,
  input[type="text"],
  input[type="email"],
  input[type="password"],
  input[type="number"],
  input[type="url"],
  input[type="search"],
  textarea,
  select {
    min-height: 52px;
    padding: 0 16px;
    border-radius: 14px;
  }
  textarea,
  .field-textarea,
  textarea.form-field {
    min-height: 120px;
    padding: 14px 16px;
  }
}

/* Labels: clearer hierarchy */
.field-label,
.auth-field-label,
.form-section label,
.cl-label,
.cl-field label {
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
  line-height: 1.2;
}
@media (max-width: 640px) {
  .field { gap: 7px; margin-bottom: 16px; }
  .auth-form { gap: 14px; }
  .cl-field { margin-bottom: 16px; }
}

/* Help + error: more breathing room, not cramped */
.field-help,
.help,
.cl-help,
.auth-subtitle,
.page-subtitle {
  font-size: 12.5px;
  line-height: 1.5;
  font-weight: 500;
}
.form-error,
.banner.error,
.cl-error {
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.45;
  font-weight: 700;
}
.field-input + .field-help,
.input + .help,
.input + .field-help { margin-top: 2px; }

/* Buttons: every primary tap is 48–52px on phones */
@media (max-width: 640px) {
  .btn, .button, .submit, .btn-save, .btn-switch {
    min-height: 48px;
  }
  .btn-full, .submit, .btn-save {
    min-height: 52px;
    font-size: 15px;
    border-radius: 14px;
  }
  .btn-sm { min-height: 36px; }
}

/* Auth shell: the quote art was breathing but the form felt tight */
@media (max-width: 640px) {
  .auth-left { padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); }
  .auth-body { min-height: calc(100dvh - 56px - env(safe-area-inset-top)); }
  .auth-title { font-size: 26px; line-height: 1.05; }
  .auth-subtitle { font-size: 14px; margin-bottom: 20px; }
  .social-row { gap: 10px; }
  .social-btn { height: 48px; border-radius: 12px; font-size: 14px; }
  .submit { height: 52px; border-radius: 14px; font-size: 15px; margin-bottom: 14px; }
  .form-links { gap: 10px; font-size: 13px; }
}

/* Brand setup wizard: footer must clear safe area, cards need air */
@media (max-width: 640px) {
  .wizard-card { padding: 16px 14px 18px; border-radius: 20px; }
  .wizard-wrap { padding: 0 12px; }
  .main { padding: 16px 0 calc(96px + env(safe-area-inset-bottom)); }
  .footer {
    padding: 12px 0 max(12px, env(safe-area-inset-bottom));
  }
  .footer-inner { padding: 0 12px; }
  .btn { min-height: 48px; padding: 0 20px; font-size: 14px; }
  .industry-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .bubble { padding: 16px 8px; border-radius: 16px; }
  .bubble .emoji { font-size: 24px; margin-bottom: 6px; }
  .choice { padding: 16px; border-radius: 16px; }
  .field { gap: 6px; }
}

/* Settings: the cover/avatar block overlapped on narrow phones */
@media (max-width: 480px) {
  .settings-card .card-body { padding: 14px; }
  .card-head { padding: 12px 14px; }
  .profile-visuals-header { margin-bottom: 56px; }
  .cover-box { height: 120px; border-radius: 12px; }
  .avatar-box { width: 76px; height: 76px; bottom: -38px; left: 14px; border-width: 3px; }
  .grid-3, .grid-cols-3 { grid-template-columns: 1fr; }
  .grid-cols-2, .grid-2 { grid-template-columns: 1fr; }
}

/* Cards: keep padding but don't let cards feel crowded on phones */
@media (max-width: 640px) {
  .card, .section { padding: 16px; border-radius: 16px; }
  .settings-card { border-radius: 14px; }
  .cl-card { padding: 16px; border-radius: 16px; }
  .cl-post { padding: 16px; }
  .rail-card { padding: 16px; }
  .brand-cover { height: 180px; }
  .brand-logo { width: 72px; height: 72px; border-radius: 18px; margin-top: -44px; }
  .brand-name { font-size: 1.35rem; }
}

/* Feed: remove the fixed 28px that caused horizontal overflow on 375px */
.feed-list { padding: 0 var(--feed-px, 16px) 20px; }
.load-more-wrap { padding: 4px var(--feed-px, 16px) 0; }
@media (max-width: 640px) {
  .feed-topbar { top: calc(48px + env(safe-area-inset-top)); }
  .scope-tab { padding: 12px 0; font-size: 14px; margin-right: 18px; }
  .bchip { padding: 5px 12px 5px 5px; }
  .brand-spotlight { padding: 14px var(--feed-px) 0; gap: 10px; }
  .compose-box { margin: 12px var(--feed-px) 0 !important; padding: 12px; border-radius: 16px; }
}

/* Brand page: fix negative-margin cover that overflowed on small phones */
@media (max-width: 640px) {
  .brand-cover { margin-left: -16px; margin-right: -16px; width: calc(100% + 32px); }
  .tabs-nav { top: calc(48px + env(safe-area-inset-top)); margin: 0 -16px; padding: 0 8px; }
  .tab-trigger { padding: 12px 14px; font-size: 11px; }
  .stat-band { margin: 16px 0; }
  .card-grid { grid-template-columns: 1fr; }
}

/* Circle page: same cover fix, tab strip safe */
@media (max-width: 640px) {
  .circle-page-header { padding: 16px 0 0; }
  .circle-identity { gap: 14px; }
  .circle-icon { width: 52px; height: 52px; font-size: 1.25rem; border-radius: 14px; }
  .circle-name { font-size: 1.4rem; }
  .tab-strip { margin-top: 14px; gap: 0; }
  .tab-btn { padding: 11px 14px; font-size: 12px; }
  .circle-layout { padding: 20px 0 calc(80px + env(safe-area-inset-bottom)); gap: 20px; }
}

/* Clubs UI: tighten wrap + hero on phones (already has overrides, reinforce) */
@media (max-width: 640px) {
  .cl-wrap { padding: 0 16px calc(88px + env(safe-area-inset-bottom)); }
  .cl-hero { padding: 24px 0 18px; gap: 14px; }
  .cl-title { font-size: 1.55rem; }
  .cl-tabs { top: calc(48px + env(safe-area-inset-top)); margin: 0 0 16px; }
}

/* Modals / creation sheets: must use dvh and safe area, not fixed 90vh that hides behind browser chrome */
.modal-overlay,
.create-menu-overlay,
.invite-modal-overlay,
.mobile-search-overlay {
  padding-bottom: env(safe-area-inset-bottom);
}
.creation-modal,
.invite-modal,
.brand-modal {
  max-height: calc(92dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}
@media (max-width: 640px) {
  .creation-modal,
  .invite-modal {
    border-radius: 20px 20px 0 0;
    width: 100%;
    margin: auto 0 0;
    max-height: calc(94dvh - env(safe-area-inset-top));
  }
  .modal-overlay.open,
  .invite-modal-overlay.open,
  .create-menu-overlay.open {
    align-items: flex-end;
    padding: 0;
  }
  .brand-modal { width: calc(100% - 24px); max-height: calc(88dvh - env(safe-area-inset-bottom)); }
}

/* Media rail / cards: prevent 100vw overflow on narrow phones */
img, video, svg { max-width: 100%; }
.media-preview-grid { grid-template-columns: repeat(2, 1fr); }
@media (min-width: 480px) { .media-preview-grid { grid-template-columns: repeat(3, 1fr); } }

/* Prevent 100%-minus-container math from causing horizontal scroll on 375px */
.container,
.cl-wrap {
  max-width: 100%;
  min-width: 0;
}
.feed-grid,
.brand-page-layout,
.circle-layout,
.settings-shell {
  min-width: 0;
}

/* Tap feedback: subtle press on phones */
@media (hover: none) {
  .btn:active,
  .cl-btn:active,
  .bchip:active,
  .bottom-nav-item:active {
    transform: scale(0.98);
    opacity: 0.96;
  }
}

/* Focus: keep ring visible even with 16px inputs */
*:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--premium-accent) 60%, transparent);
  outline-offset: 2px;
}

/* Hide scrollbars where we do horizontal chip rows, keep touch scroll */
.brand-filter-row,
.scope-tabs,
.tab-strip,
.tabs-nav,
.bchip-row,
.cl-chiprow {
  -webkit-overflow-scrolling: touch;
  scroll-padding-inline: 16px;
}

/* Club perspective composer: breathing room for the share textarea */
@media (max-width: 640px) {
  .cl-composer-inner { padding: 14px; border-radius: 14px; }
  .cl-composer-textarea { padding: 14px 14px; min-height: 120px; font-size: 16px; }
  .composer-inner { padding: 14px; border-radius: 14px; }
  .composer-inner textarea { padding: 14px 14px; min-height: 120px; font-size: 16px; }
  /* Feed empty state icon was 48px — huge on 375px, shrink to 32px */
  .empty-state-box .empty-state-icon { width: 32px; height: 32px; margin-bottom: 12px; }
  .empty-state-box .empty-state-icon svg { width: 32px; height: 32px; }
  .empty-state-box { padding: 32px 16px; }
}
