/* =====================================================================
   MODOL CONNECT — mobile.css
   Blueprint breakpoints:  < 576 mobile · 576–767 large mobile
   App-like patterns: bottom navigation, card layouts, bottom sheets,
   stacked tables, 44px touch targets, safe-area insets.
   Loaded AFTER pink-theme.css and responsive.css.
   ===================================================================== */

:root {
  --mobile-nav-height: 62px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --touch: 44px;
}

/* ------------- mobile-only shell (hidden on desktop) ------------- */
.mobile-nav { display: none; }
.app-bar { display: none; }
.app-progress { display: none; }
.app-menu, .app-menu-scrim { display: none; }

@media (max-width: 767.98px) {
  .mobile-nav {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 95;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: stretch;
    height: calc(var(--mobile-nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: rgba(255, 255, 255, .97);
    backdrop-filter: blur(14px);
    border-top: 1px solid var(--border-soft);
    box-shadow: 0 -6px 24px rgba(219, 39, 119, .09);
  }
  .mobile-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    font-size: 10.5px;
    font-weight: 600;
    color: var(--text-soft);
    text-decoration: none;
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-nav__item svg { width: 21px; height: 21px; }
  .mobile-nav__item.is-active { color: var(--pink-dark); }
  .mobile-nav__item.is-active::before {
    content: "";
    position: absolute;
    top: 0; left: 50%;
    transform: translateX(-50%);
    width: 26px; height: 3px;
    border-radius: 0 0 4px 4px;
    background: var(--gradient);
  }
  .mobile-nav__badge {
    position: absolute;
    top: 8px; right: 50%;
    margin-right: -20px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: var(--pink);
    color: #fff;
    font-size: 9.5px;
    font-weight: 700;
    display: grid;
    place-items: center;
  }

  /* keep content clear of the bar (only where the bar actually renders) */
  body.has-mobile-nav { padding-bottom: calc(var(--mobile-nav-height) + var(--safe-bottom)); }
  .app-main { padding-bottom: calc(var(--mobile-nav-height) + 34px + var(--safe-bottom)); }
  .chat-composer { bottom: calc(var(--mobile-nav-height) + var(--safe-bottom)); }

  /* the sidebar becomes a drawer above the bar */
  .sidebar { inset: 66px auto calc(var(--mobile-nav-height) + var(--safe-bottom)) 0; overflow-y: auto; }

  /* ---------- native app shell: app bar + progress + transitions ---------- */
  .site-header { display: none; }            /* the desktop navbar is replaced by the app bar */
  .site-footer { display: none; }            /* apps do not scroll into a footer */
  body.has-mobile-nav { background: var(--bg-muted); }

  .app-bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    z-index: 96;
    display: grid;
    grid-template-columns: 56px 1fr 96px;
    align-items: center;
    height: 56px;
    padding-top: env(safe-area-inset-top, 0px);
    background: rgba(255, 255, 255, .94);
    backdrop-filter: saturate(180%) blur(16px);
    border-bottom: 1px solid var(--border-soft);
    transition: transform .22s ease;
    will-change: transform;
  }
  .app-bar.is-hidden { transform: translateY(-104%); }
  .app-bar__side { display: flex; align-items: center; gap: 2px; padding-inline: 6px; }
  .app-bar__side--end { justify-content: flex-end; }
  .app-bar__btn {
    width: 42px; height: 42px;
    display: grid; place-items: center;
    border: 0; border-radius: 12px;
    background: transparent; color: var(--text);
    position: relative;
    -webkit-tap-highlight-color: transparent;
  }
  .app-bar__btn:active { background: var(--pink-soft); }
  .app-bar__brand { display: grid; place-items: center; width: 42px; height: 42px; }
  .app-bar__brand .brand__mark { width: 30px; height: 30px; border-radius: 9px; font-size: 15px; }
  .app-bar__brand .brand__logo { width: 34px; height: 34px; border-radius: 10px; }
  .app-bar__title {
    font-size: 16px; font-weight: 700; letter-spacing: -.01em;
    text-align: center;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    user-select: none;
  }
  .app-bar__dot {
    position: absolute; top: 6px; right: 6px;
    min-width: 15px; height: 15px; padding: 0 3px;
    border-radius: 999px; background: var(--pink); color: #fff;
    font-size: 9px; font-weight: 700; display: grid; place-items: center;
  }
  .app-bar__avatar {
    width: 32px; height: 32px; margin-left: 4px;
    border-radius: 999px; background: var(--gradient); color: #fff;
    display: grid; place-items: center;
    font-size: 12.5px; font-weight: 700; text-decoration: none;
  }
  .app-bar__cta {
    font-size: 13px; font-weight: 700; color: #fff;
    background: var(--gradient); padding: 8px 14px; border-radius: 999px;
    text-decoration: none;
  }

  /* ---------- guest slide-in menu ---------- */
  .app-menu-scrim {
    position: fixed; inset: 0; z-index: 97;
    display: block;
    background: rgba(31, 41, 55, .38);
    opacity: 0; pointer-events: none;
    transition: opacity .2s ease;
  }
  .app-menu-scrim.is-open { opacity: 1; pointer-events: auto; }
  .app-menu {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 98;
    display: flex; flex-direction: column;
    width: 78%; max-width: 320px;
    background: #fff;
    padding: calc(18px + env(safe-area-inset-top, 0px)) 16px calc(18px + var(--safe-bottom));
    box-shadow: 12px 0 40px rgba(31, 41, 55, .18);
    transform: translateX(-102%);
    transition: transform .24s ease;
    overflow-y: auto;
  }
  .app-menu.is-open { transform: none; }
  .app-menu__head { padding: 6px 4px 16px; border-bottom: 1px solid var(--border-soft); margin-bottom: 10px; }
  .app-menu__row {
    display: flex; align-items: center; gap: 12px;
    min-height: var(--touch);
    padding: 12px 6px;
    color: var(--text); font-size: 14.5px; font-weight: 600;
    text-decoration: none;
    border-radius: 12px;
  }
  .app-menu__row:active { background: var(--pink-soft); }
  .app-menu__row svg { color: var(--pink-dark); }
  .app-menu__foot { margin-top: auto; display: grid; gap: 10px; padding-top: 16px; }
  .app-menu__foot .btn-mc, .app-menu__foot .btn-outline { justify-content: center; width: 100%; }

  /* thin loading bar — gives the instant-feedback feel of a native app */
  .app-progress {
    position: fixed; top: 0; left: 0; right: 0; height: 2.5px; z-index: 200;
    display: block;
    background: var(--gradient);
    transform-origin: left center;
    transform: scaleX(0);
    opacity: 0;
    transition: transform .25s ease, opacity .2s ease;
  }
  .app-progress.is-loading { opacity: 1; transform: scaleX(.82); transition: transform 2.4s cubic-bezier(.1,.7,.2,1); }
  .app-progress.is-done { opacity: 0; transform: scaleX(1); transition: transform .18s ease, opacity .3s ease .1s; }

  /* content sits below the fixed bar */
  .app-main { padding-top: calc(56px + env(safe-area-inset-top, 0px) + 12px); }
  .app-main > .mc-row:first-child { display: none; }   /* the in-page menu row is redundant now */

  /* screen enter animation (app-like push) */
  .app-main { animation: screenIn .22s ease both; }
  @keyframes screenIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
  }
  @media (prefers-reduced-motion: reduce) {
    .app-main { animation: none; }
    .app-bar { transition: none; }
  }

  /* ---------- app-like header ---------- */
  .site-header__inner { height: 62px; gap: 12px; }
  .brand { font-size: 17px; }
  .brand__mark { width: 34px; height: 34px; border-radius: 11px; }
  .brand__logo { width: 34px; height: 34px; border-radius: 11px; }
  .lang-switch { display: none; }

  /* ---------- app home: quick action tiles ---------- */
  .mobile-quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
  .mobile-quick__tile {
    display: flex; flex-direction: column; align-items: center; gap: 7px;
    padding: 12px 6px;
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    font-size: 11.5px; font-weight: 600;
    color: var(--text);
    text-decoration: none;
    box-shadow: var(--shadow-sm);
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-quick__tile:active { transform: scale(.97); background: var(--pink-soft); }
  .mobile-quick__icon {
    width: 38px; height: 38px; border-radius: 12px;
    display: grid; place-items: center;
    background: var(--gradient-soft); color: var(--pink-dark);
  }

  /* ---------- iOS-style large screen title ---------- */
  .page-head h1 { font-size: 24px; letter-spacing: -.02em; line-height: 1.2; }
  .page-head p { font-size: 13px; }
  .page-head { gap: 6px; margin-bottom: 14px; }

  /* app spacing: everything a little tighter and rounder */
  .card-mc { border-radius: 16px; box-shadow: 0 1px 2px rgba(31, 41, 55, .05); }
  .card-mc__head { padding: 14px 16px; }
  .row.g-4 { --bs-gutter-y: 12px; }
  .mc-section { padding: 28px 0; }

  /* ---------- card layouts instead of tables (§3) ---------- */
  .table-responsive, .table-mc { border: 0; }
  .table-stack thead { display: none; }
  .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
  .table-stack tr {
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
  }
  .table-stack td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 5px 0;
    border: 0;
    text-align: right;
  }
  .table-stack td::before {
    content: attr(data-label);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: .02em;
    text-transform: uppercase;
    color: var(--text-soft);
    text-align: left;
    flex-shrink: 0;
  }
  .table-stack td:first-child {
    justify-content: flex-start;
    text-align: left;
    font-size: 14.5px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-soft);
    margin-bottom: 6px;
  }
  .table-stack td:first-child::before { display: none; }

  /* ---------- any .table-mc becomes a card list on phones ---------- */
  .table-mc { display: block; width: 100%; }
  .table-mc thead { display: none; }
  .table-mc tbody { display: block; }
  .table-mc tbody tr {
    display: block;
    background: #fff;
    border: 1px solid var(--border-soft);
    border-radius: var(--radius);
    padding: 10px 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow-sm);
  }
  .table-mc tbody td {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    width: 100%;
    border: 0;
    padding: 5px 0;
    text-align: right;
    font-size: 13px;
  }
  .table-mc tbody td:first-child { font-weight: 600; text-align: left; }

  /* ---------- P2P marketplace: cards (§1 / §2) ---------- */
  .p2p-table thead { display: none; }
  .p2p-table, .p2p-table tbody, .p2p-table tr, .p2p-table td { display: block; width: 100%; }
  .p2p-table tr {
    border: 1px solid var(--border-soft);
    border-radius: var(--radius-lg);
    padding: 14px;
    margin-bottom: 12px;
    background: #fff;
    box-shadow: var(--shadow-sm);
  }
  .p2p-table td { border: 0; padding: 3px 0; text-align: left; }
  .p2p-table td[data-label]::before {
    content: attr(data-label) " ";
    font-size: 11px;
    color: var(--text-soft);
    font-weight: 600;
  }
  .p2p-table td.p2p-merchant { font-size: 15px; font-weight: 700; padding-bottom: 6px; }
  .p2p-table td.p2p-action { padding-top: 10px; }
  .p2p-table td.p2p-action .btn-mc,
  .p2p-table td.p2p-action .btn-outline { width: 100%; justify-content: center; min-height: var(--touch); }

  /* ---------- forms: step-by-step, full-width ---------- */
  .form-control, .form-select { min-height: var(--touch); font-size: 16px; }
  textarea.form-control { min-height: 96px; font-size: 16px; }
  .btn-mc, .btn-outline, .btn-ghost { min-height: var(--touch); }
  .page-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .page-head .mc-row { width: 100%; flex-wrap: wrap; }
  .card-mc__body { padding: 16px; }
  .card-mc--pad { padding: 16px; }

  /* ---------- stacked stat/dashboard cards (§3) ---------- */
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .stat-card { padding: 14px; border-radius: var(--radius); }
  .stat-card__value { font-size: 19px; }
  .stat-card__label { font-size: 11px; }

  /* ---------- filters collapse into a sheet ---------- */
  .filter-bar { position: relative; }
  .filter-sheet-toggle { display: inline-flex; }
  .filter-bar.is-collapsed { display: none; }
  .p2p-tabs { position: sticky; top: 62px; z-index: 20; }

  /* ---------- full-screen order / chat (§3) ---------- */
  .order-grid, .chat-shell { grid-template-columns: 1fr !important; }
  .chat-body { max-height: calc(100vh - 210px); }
  .p2p-order-hero { padding: 16px; }

  /* ---------- admin console: collapsible drawer + compact header ---------- */
  .app-shell > .sidebar { box-shadow: 0 24px 60px rgba(31, 41, 55, .22); }
  .app-main > .mc-row:first-child .icon-btn { min-width: var(--touch); min-height: var(--touch); }
  .admin-shell, .app-main { min-width: 0; }
  .app-main .card-mc { border-radius: var(--radius); }

  /* ---------- bottom sheet for actions ---------- */
  .mobile-sheet {
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 120;
    background: #fff;
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -18px 48px rgba(219, 39, 119, .18);
    padding: 18px 18px calc(18px + var(--safe-bottom));
    transform: translateY(110%);
    transition: transform .25s ease;
  }
  .mobile-sheet.is-open { transform: none; }
  .mobile-sheet__handle {
    width: 44px; height: 4px; border-radius: 999px;
    background: var(--border); margin: 0 auto 14px;
  }
}

/* ------------------- 576–767 (large mobile) ------------------- */
@media (min-width: 576px) and (max-width: 767.98px) {
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .model-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ------------------- < 576 (small mobile) ------------------- */
@media (max-width: 575.98px) {
  body { font-size: 14.5px; }
  .mc-container { padding-inline: 14px; }
  .model-grid { grid-template-columns: 1fr; }
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .hero { padding: 34px 0 30px; }
  .hero h1 { font-size: 27px; line-height: 1.24; }
  .page-head h1 { font-size: 21px; }
  .mc-section { padding: 34px 0; }
  .btn-mc, .btn-outline { font-size: 13.5px; padding-inline: 14px; }
  .p2p-tabs { gap: 6px; }
  .p2p-tabs__btn { flex: 1; justify-content: center; }
  .chat-list { max-height: 42vh; }
}

/* ---------- no hover-only affordances on touch ---------- */
@media (hover: none) {
  .model-card:hover, .card-mc:hover { transform: none; }
  .user-menu__panel { display: none; }
  .user-menu.is-open .user-menu__panel { display: block; }
}

/* ---------- print ---------- */
@media print {
  .mobile-nav, .sidebar, .site-header, .app-main > .mc-row:first-child { display: none !important; }
  body.has-mobile-nav { padding-bottom: 0; }
}
