/* ============================================================
   Moovpark Family PWA — mobile shell styles
   Loaded after design-tokens.css. Owns the device frame,
   top app bar, bottom nav, sheets, primitives.
   ============================================================ */

@import url('https://unpkg.com/primeicons@7.0.0/primeicons.css');
@import url('/design-tokens.css');

/* Mobile shell sizing */
:root {
  --mp-device-w:    420px;
  --mp-topbar-h:    62px;
  /* Fluid: co liên tục theo bề ngang máy (320 → 480+). Content padding bám
     cùng token nên không lệch. 49px is standard iOS tab bar height. */
  --mp-bottombar-h: clamp(49px, 12vw, 56px);
  --mp-radius-card: 16px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* Khoá scroll ở tầng trang: chỉ .mp-content cuộn nội bộ. WHY: trang cuộn được
   → mobile browser thu/hiện URL bar → 100dvh đổi liên tục → bottom nav (absolute
   bottom:0 của device cao theo dvh) nhảy lên/xuống. Khoá đây giữ viewport tĩnh. */
html, body, #root { margin: 0; padding: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  font-family: var(--font-body);
  color: var(--app-text);
  font-size: 15px;
  background: #EEF2F7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* Desktop preview: soft gradient around the phone frame */
  background:
    radial-gradient(circle at 12% 18%, color-mix(in srgb, var(--mp-primary) 12%, transparent) 0%, transparent 50%),
    radial-gradient(circle at 88% 88%, color-mix(in srgb, #8B5CF6 10%, transparent) 0%, transparent 50%),
    #0B1224;
  /* Light fallback on small screens (real phones) */
}
@media (max-width: 519px) { body { background: #FAFBFC; } }
html.app-dark body {
  background:
    radial-gradient(circle at 12% 18%, color-mix(in srgb, var(--mp-primary) 16%, transparent) 0%, transparent 50%),
    radial-gradient(circle at 88% 88%, color-mix(in srgb, #8B5CF6 12%, transparent) 0%, transparent 50%),
    #04111A;
}
button { font-family: inherit; }

/* ────────────────────────────────────────────────────────────
   Device frame
   ──────────────────────────────────────────────────────────── */
.mp-stage {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 0;
}
.mp-device {
  width: 100%;
  max-width: var(--mp-device-w);
  height: 100dvh;
  background: var(--app-page-bg);
  overflow: hidden;
  position: relative;
  display: flex;
  flex-direction: column;
  isolation: isolate;
}
@media (min-width: 520px) {
  .mp-stage { padding: 28px 16px; min-height: 100vh; }
  .mp-device {
    height: min(880px, calc(100vh - 56px));
    border-radius: 40px;
    box-shadow:
      0 60px 120px -40px rgba(2, 12, 24, .55),
      0 24px 60px -30px rgba(2, 12, 24, .45),
      inset 0 0 0 8px #0A0E15,
      inset 0 0 0 9px rgba(255, 255, 255, .06);
    padding: 8px;
  }
  .mp-device-inner {
    border-radius: 32px;
    overflow: hidden;
    height: 100%;
    background: var(--app-page-bg);
    display: flex;
    flex-direction: column;
    position: relative;
    transform: translate3d(0, 0, 0); /* Contain fixed descendants */
  }

}
@media (max-width: 519px) {
  /* Shell dùng 100% (của body đã khoá overflow) thay 100dvh → KHÔNG co giãn theo
     URL bar nữa. Bottom nav absolute bám đáy device đứng yên. */
  .mp-stage { min-height: 0; height: 100%; }
  .mp-device { border-radius: 0; height: 100%; padding: 0; }
  .mp-device-inner {
    border-radius: 0;
    height: 100%;
    display: flex;
    flex-direction: column;
    /* Landscape notches cut into L/R edges. Apply at the shell so every
       screen inherits it without each component restating env(). Top/bottom
       insets are baked into the chrome classes below so scroll content can
       slide behind translucent sticky headers / nav. */
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
}
/* Standalone PWA (add-to-home-screen): KHÔNG có URL bar co giãn → 100dvh ổn định
   và fill đúng toàn màn. Dùng height:100% ở block trên (né nav-jump khi browser
   thu/hiện URL bar) lại vướng iOS quirk: standalone webview để hở 1 dải ở đáy =
   bottom nav bị "thụt lên". Ép 100dvh riêng cho standalone để bám đáy vật lý. */
@media (max-width: 519px) and (display-mode: standalone) {
  .mp-stage  { height: 100dvh; }
  .mp-device { height: 100dvh; }
}

/* Safe-area utilities — kept for ad-hoc screens (full-screen overlays) that
   sit OUTSIDE the chrome and need their own inset. */
.mp-safe-top    { padding-top: env(safe-area-inset-top); }
.mp-safe-bottom { padding-bottom: env(safe-area-inset-bottom); }
.mp-safe-x      {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* ────────────────────────────────────────────────────────────
   App header (sticky, with avatar + greeting + bell)
   ──────────────────────────────────────────────────────────── */
.mp-appheader {
  position: sticky; top: 0; z-index: 30;
  background: var(--app-bg);
  /* Safe-area-inset-top baked into the padding via calc() so the chrome's
     own background extends behind the iOS notch / dynamic island. Doing it
     here (not via a separate .mp-safe-top class) means inline `style.padding`
     or Tailwind `p-X` on the React element can't accidentally reset it. */
  padding: calc(14px + env(safe-area-inset-top)) 18px 10px;
  display: flex; align-items: center; gap: 12px;
}
.mp-appheader-eyebrow {
  font-size: 11px; font-weight: 500; color: var(--app-text-muted);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.mp-appheader-title {
  font-size: 17px; font-weight: 700; color: var(--app-text);
  letter-spacing: -0.015em; margin-top: 1px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mp-icon-btn {
  width: 38px; height: 38px; border-radius: 999px;
  background: var(--app-surface-soft); border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--app-text); position: relative;
  transition: background 0.15s ease;
}
.mp-icon-btn:hover { background: var(--app-surface-low); }
.mp-icon-btn-badge {
  position: absolute; top: 6px; right: 6px;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: 999px;
  background: var(--mp-danger); color: #fff;
  font-size: 9.5px; font-weight: 700; line-height: 16px;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--app-bg);
}

/* Sub-screen header (back button + title + optional action) */
.mp-subheader {
  position: sticky; top: 0; z-index: 30;
  background: var(--app-bg);
  /* Safe-area top baked in — same reason as .mp-appheader. */
  padding: calc(14px + env(safe-area-inset-top)) 16px 12px;
  display: flex; align-items: center; gap: 12px;
}
.mp-back-btn {
  width: 36px; height: 36px; border-radius: 999px;
  background: var(--app-surface-soft); border: 0; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  color: var(--app-text);
}

/* ────────────────────────────────────────────────────────────
   Scroll content
   ──────────────────────────────────────────────────────────── */
.mp-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
  background: var(--app-page-bg);
}
.mp-content::-webkit-scrollbar { width: 6px; }
.mp-content::-webkit-scrollbar-thumb { background: rgba(15,28,44,.18); border-radius: 999px; }

/* ────────────────────────────────────────────────────────────
   Bottom navigation
   ──────────────────────────────────────────────────────────── */
.mp-bottomnav {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  width: 100%;
  max-width: inherit; /* Inherit parent max-width on desktop */
  height: calc(var(--mp-bottombar-h) + env(safe-area-inset-bottom, 0px));
  background: color-mix(in srgb, var(--app-surface) 94%, transparent);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-top: 1px solid var(--app-border);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  /* Use max to ensure a small padding even on devices without safe-area */
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 8px);
  z-index: 50;
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.2s ease;
}
.mp-bottomnav-item {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: clamp(2px, 0.8vw, 4px); border: 0; background: transparent; cursor: pointer;
  color: var(--app-text-muted);
  font-weight: 500;
  position: relative;
  min-width: 0; /* grid 1fr: cho item co + bật ellipsis (mặc định min-width:auto = tràn) */
  transition: color 0.2s ease, transform 0.2s ease;
  padding: 4px 2px;
  font-family: var(--font-ui);
}
.mp-bottomnav-item span {
  display: block;
  font-size: clamp(9px, 2.7vw, 11px);
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  transition: transform 0.2s ease, font-weight 0.2s ease;
}
.mp-bottomnav-item i {
  font-size: clamp(18px, 5.4vw, 23px);
  transition: transform 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.mp-bottomnav-item:active i {
  transform: scale(0.85);
}
.mp-bottomnav-item.active {
  color: var(--mp-primary);
  font-weight: 600;
}
.mp-bottomnav-item.active i {
  transform: translateY(-2px) scale(1.1);
}
.mp-bottomnav-item.active span {
  font-weight: 700;
}
@keyframes mp-indicator-pop {
  from { transform: translateX(-50%) scaleX(0); opacity: 0; }
  to { transform: translateX(-50%) scaleX(1); opacity: 1; }
}
.mp-bottomnav-item .mp-bn-indicator {
  position: absolute; top: 0; left: 50%; transform: translateX(-50%);
  width: 24px; height: 3px; border-radius: 0 0 3px 3px;
  background: var(--mp-primary);
  animation: mp-indicator-pop 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
.mp-bottomnav-item .mp-bn-badge {
  position: absolute; top: 6px; right: 50%; margin-right: -16px;
  min-width: 14px; height: 14px; padding: 0 3px;
  border-radius: 999px;
  background: var(--mp-danger); color: #fff;
  font-size: 8.5px; font-weight: 700; line-height: 14px;
  border: 1.5px solid var(--app-surface);
}

/* Narrow viewport (iPhone SE 320px) đã được clamp() ở trên lo liên tục —
   không cần breakpoint cứng nữa. */

/* Hide bottom nav when virtual keyboard is open */
[data-keyboard-open="true"] .mp-bottomnav {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}
[data-keyboard-open="true"] .mp-content {
  padding-bottom: 0 !important;
}

/* ────────────────────────────────────────────────────────────
   Primitives
   ──────────────────────────────────────────────────────────── */
.mp-card {
  background: var(--app-surface);
  border: 1px solid var(--app-border);
  border-radius: var(--mp-radius-card);
  box-shadow: var(--app-card-shadow);
}
.mp-h1 { font-family: var(--font-display); font-weight: 700; font-size: 24px; letter-spacing: -0.025em; line-height: 1.1; margin: 0; }
.mp-h2 { font-family: var(--font-display); font-weight: 700; font-size: 18px; letter-spacing: -0.01em; margin: 0; }

.mp-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 14px; border: 0;
  font-size: 14px; font-weight: 650;
  font-family: var(--font-ui);
  cursor: pointer;
  transition: transform .08s ease, background .15s ease, box-shadow .15s ease;
  min-height: 44px;
  letter-spacing: -0.005em;
}
.mp-btn:active { transform: scale(0.98); }
.mp-btn-primary   { background: var(--mp-primary); color: #fff; box-shadow: var(--shadow-button-glow); }
.mp-btn-primary:hover { background: var(--mp-primary-dark); }
.mp-btn-accent    { background: var(--mp-accent); color: #1a1300; }
.mp-btn-secondary { background: var(--app-surface); color: var(--mp-primary); border: 1px solid var(--app-border-info); }
.mp-btn-ghost     { background: transparent; color: var(--app-text-soft); }
.mp-btn-danger    { background: var(--mp-danger); color: #fff; }
.mp-btn-block     { width: 100%; }
.mp-btn-sm        { padding: 7px 12px; font-size: 12.5px; border-radius: 10px; min-height: 34px; }

.mp-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.01em;
  background: var(--app-surface-soft);
  color: var(--app-text-muted);
}
.mp-chip-primary { background: var(--app-surface-info);    color: var(--app-text-info); }
.mp-chip-success { background: var(--app-surface-success); color: var(--app-text-success); }
.mp-chip-warning { background: var(--app-surface-warning); color: var(--app-text-warning); }
.mp-chip-danger  { background: var(--app-surface-danger);  color: var(--app-text-danger); }

.mp-input {
  width: 100%; height: 48px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1.5px solid var(--app-border);
  background: var(--app-surface);
  color: var(--app-text);
  font-size: 14px;
  font-family: var(--font-ui);
  outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.mp-input:focus {
  border-color: var(--mp-primary);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--mp-primary) 10%, transparent);
}
textarea.mp-input { height: auto; min-height: 48px; padding: 12px 14px; line-height: 1.5; resize: vertical; }

.mp-avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px;
  color: #fff;
  font-weight: 700;
  flex-shrink: 0; overflow: hidden;
  box-shadow: 0 2px 8px rgba(15, 30, 60, 0.10), inset 0 0 0 1px rgba(255, 255, 255, 0.18);
  letter-spacing: -0.02em;
}
.mp-avatar img { width: 100%; height: 100%; object-fit: cover; }

/* List row (recurring pattern) */
.mp-list-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 12px;
}
.mp-list-row + .mp-list-row { border-top: 1px solid var(--app-border); }

/* ────────────────────────────────────────────────────────────
   Bottom sheet (modal)
   ──────────────────────────────────────────────────────────── */
.mp-sheet-scrim {
  position: absolute; inset: 0;
  background: rgba(15, 30, 60, 0.45);
  backdrop-filter: blur(4px);
  z-index: 60;
  animation: mp-fade-in .2s ease both;
}
.mp-sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  background: var(--app-surface);
  border-radius: 24px 24px 0 0;
  z-index: 61;
  max-height: 90%;
  display: flex; flex-direction: column;
  box-shadow: 0 -10px 40px rgba(2, 12, 24, .28);
  animation: mp-slide-up .28s cubic-bezier(.22, 1, .36, 1) both;
  padding-bottom: env(safe-area-inset-bottom);
}
.mp-sheet-handle {
  width: 38px; height: 4px; border-radius: 999px;
  background: var(--app-border);
  margin: 8px auto 4px;
  flex-shrink: 0;
}
.mp-sheet-header {
  padding: 12px 20px 8px;
  display: flex; justify-content: space-between; align-items: center;
  flex-shrink: 0;
}
.mp-sheet-body { padding: 8px 20px 20px; overflow-y: auto; }

/* PWA install banner */
.mp-install-banner {
  position: absolute; bottom: calc(var(--mp-bottombar-h) + 14px);
  left: 12px; right: 12px; z-index: 35;
  background: var(--app-text);
  color: var(--app-bg);
  border-radius: 16px; padding: 12px;
  display: flex; align-items: center; gap: 12px;
  box-shadow: 0 12px 32px -16px rgba(15, 30, 60, 0.45);
  animation: mp-slide-up .4s cubic-bezier(.22, 1, .36, 1) both;
}
.mp-install-logo {
  width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0;
  background: var(--mp-primary);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 18px; font-weight: 800;
}

/* ────────────────────────────────────────────────────────────
   Animations
   ──────────────────────────────────────────────────────────── */
@keyframes mp-fade-in {
  from { opacity: 0; } to { opacity: 1; }
}
@keyframes mp-slide-up {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
@keyframes mp-fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes mp-spin {
  to { transform: rotate(360deg); }
}
.mp-fade-up { animation: mp-fade-up .3s cubic-bezier(.22,1,.36,1) both; }
.mp-screen  { animation: mp-fade-up .25s cubic-bezier(.22,1,.36,1) both; height: 100%; display: flex; flex-direction: column; }

/* Spinner used in auth screens */
.mp-spinner {
  width: 16px; height: 16px;
  border: 2.5px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 999px;
  animation: mp-spin .7s linear infinite;
}

/* ── Voice call overlay (HybeLive 1-1) ── */
.mp-call-overlay {
  position: fixed; inset: 0; z-index: 1000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 10px; padding: 32px;
  background: #0E1A2B; color: #fff;
}
.mp-call-avatar {
  width: 112px; height: 112px; border-radius: 999px;
  display: grid; place-items: center;
  background: #4FA3A0; color: #fff; font-size: 44px; font-weight: 700;
  margin-bottom: 14px;
}
.mp-call-name { font-size: 22px; font-weight: 700; }
.mp-call-status { font-size: 15px; opacity: 0.7; }
.mp-call-actions { display: flex; gap: 48px; margin-top: 48px; }
.mp-call-btn { background: transparent; border: 0; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 8px; color: #fff; }
.mp-call-btn-circle { width: 64px; height: 64px; border-radius: 999px; display: grid; place-items: center; font-size: 26px; color: #fff; }
.mp-call-btn-label { font-size: 13px; opacity: 0.85; }
.mp-call-toast {
  position: fixed; left: 50%; bottom: 88px; transform: translateX(-50%); z-index: 1001;
  background: rgba(0,0,0,0.85); color: #fff; padding: 10px 16px; border-radius: 999px; font-size: 13px;
  max-width: 80%;
}
