/* =========================================================
   Balance App — Professional Mobile Layer (mobile-pro.css)
   ---------------------------------------------------------
   Loaded last (after all other public/styles/*.css), so any
   rule here takes precedence on phones.
   Goal: a clean, native-feeling experience on real phone widths
   (320–430px) without breaking the desktop look.
   ========================================================= */

:root {
  --balance-pink: #e91e63;
  --balance-pink-dark: #be185d;
  --balance-pink-soft: #fce7f3;
  --balance-ink: #0f172a;
  --balance-ink-soft: #475569;
  --balance-line: #eef2f7;
  --balance-bg-soft: #f8fafc;
  --balance-radius-md: 12px;
  --balance-radius-lg: 16px;
  --balance-shadow-card: 0 8px 22px rgba(15, 23, 42, 0.06);
  --balance-shadow-card-strong: 0 14px 34px rgba(15, 23, 42, 0.08);
  --balance-bottom-nav-h: 64px;
}

/* Make all interactive surfaces touch-friendly + prevent horizontal scroll */
html,
body,
#root {
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  text-rendering: optimizeLegibility;
}

body {
  overflow-x: hidden;
}

/* The .container is already capped at 400px in styles.css; on real phones
   we want it to stretch to the full viewport width so cards don't look
   "boxed in" with grey gutters. */
.app-shell.container,
.role-app .container {
  box-shadow: none;
}

/* Inputs: prevent iOS auto-zoom (must be >= 16px) and align text/baseline */
input,
select,
textarea,
button {
  font-family: inherit;
}

input:not([type='checkbox']):not([type='radio']):not([type='range']),
select,
textarea {
  font-size: 16px;
}

/* =========================================================
   1) BODY MEASUREMENTS (the screen the user shared)
   ========================================================= */

/* Default (desktop & tablet): keep the original card look */
.measurement-card {
  background: linear-gradient(180deg, #ffffff 0%, #fcfcfd 100%);
  border: 1px solid var(--balance-line);
  border-radius: var(--balance-radius-lg);
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--balance-shadow-card);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.15s ease;
}

.measurement-card:hover {
  border-color: rgba(233, 30, 99, 0.35);
  box-shadow: var(--balance-shadow-card-strong);
}

.measurement-icon {
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--balance-pink), var(--balance-pink-dark));
  color: #fff;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 16px rgba(233, 30, 99, 0.28);
  flex-shrink: 0;
}

.measurement-info {
  flex: 1;
  min-width: 0;
}

.measurement-info label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--balance-ink-soft);
  letter-spacing: 0;
  text-transform: none;
  margin-bottom: 6px;
}

.measurement-card .input-with-unit input {
  width: 100%;
  min-width: 0;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #e2e8f0;
  background: #fff;
  color: var(--balance-ink);
  font-weight: 600;
  font-size: 16px;
  text-align: end;
}

.measurement-card .input-with-unit .unit {
  font-size: 13px;
  font-weight: 600;
  color: var(--balance-ink-soft);
  pointer-events: none;
  white-space: nowrap;
}

.measurement-card .measurement-change {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--balance-pink);
}

/* =========================================================
   2) BMI panel polish
   ========================================================= */
.bmi-display {
  border-radius: 14px;
  padding: 18px;
  background: linear-gradient(135deg, #111827 0%, #1f2937 100%);
  color: #fff;
  border: none;
  box-shadow: 0 12px 28px rgba(17, 24, 39, 0.28);
}

.bmi-info {
  gap: 10px;
  flex-wrap: wrap;
}

.bmi-value {
  font-size: 24px;
  color: #f9a8d4;
}

.bmi-category {
  background: rgba(255, 255, 255, 0.18);
}

/* =========================================================
   3) MOBILE BREAKPOINTS — the actual fixes for phones
   ========================================================= */

/* Generic small-phone refinements (<= 480px) */
@media (max-width: 480px) {
  .container {
    box-shadow: none;
    max-width: 100%;
  }

  .header {
    padding: 14px 14px 8px;
  }

  .header h1 {
    font-size: 18px;
    line-height: 1.25;
  }

  .header-logo {
    height: 26px;
  }

  .main-content,
  .role-app {
    padding-left: 12px;
    padding-right: 12px;
  }

  .card {
    padding: 14px;
    margin-bottom: 14px;
    border-radius: var(--balance-radius-lg);
  }

  .section-header h2 {
    font-size: 16px;
  }

  .section-header i {
    font-size: 14px;
  }

  /* --- Body Measurements: stack icon above the input on phones so the
         number + unit never get cut off, and the card fits any width. --- */
  .measurements-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .measurement-card {
    padding: 12px;
    gap: 12px;
    align-items: stretch;
  }

  .measurement-icon {
    width: 38px;
    height: 38px;
    min-width: 38px;
    font-size: 14px;
    border-radius: 10px;
  }

  .measurement-info label {
    font-size: 12px;
    margin-bottom: 6px;
  }

  .measurement-card .input-with-unit {
    width: 100%;
  }

  .measurement-card .input-with-unit input {
    padding: 11px 14px;
    font-size: 16px;
  }

  /* Keep the unit chip INSIDE the input area on both LTR and RTL */
  [dir='ltr'] .measurement-card .input-with-unit input {
    padding-right: 44px !important;
    padding-left: 14px !important;
  }

  [dir='rtl'] .measurement-card .input-with-unit input {
    padding-left: 44px !important;
    padding-right: 14px !important;
  }

  [dir='ltr'] .measurement-card .input-with-unit .unit {
    right: 14px;
    left: auto !important;
  }

  [dir='rtl'] .measurement-card .input-with-unit .unit {
    left: 14px !important;
    right: auto !important;
  }

  .measurement-card .measurement-change {
    font-size: 11px;
    margin-top: 6px;
    line-height: 1.3;
  }

  /* BMI panel on small phones */
  .bmi-display {
    padding: 16px;
    border-radius: 14px;
  }

  .bmi-info {
    margin-bottom: 12px;
  }

  .bmi-value {
    font-size: 22px;
  }

  /* Overview tiles (الهدف، التقدم...) — single column on small screens */
  .overview-stats {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .overview-item {
    padding: 12px;
    min-height: auto;
  }

  .overview-icon {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    font-size: 14px;
  }

  .overview-value {
    font-size: 16px;
  }

  /* Stats grid in the dashboard (السعرات/التغير ...) */
  .progress-stats,
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .stat-item {
    padding: 12px 10px;
  }

  .stat-value {
    font-size: 16px;
  }

  .stat-label {
    font-size: 11px;
  }

  /* Quick actions — 2 columns, comfortable touch targets */
  .quick-actions-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .quick-action-btn {
    min-height: 72px;
    border-radius: 14px;
  }

  /* Forms inside cards: full-width, comfortable padding */
  .form-group {
    margin-bottom: 12px;
  }

  .form-group label {
    font-size: 13px;
    margin-bottom: 6px;
  }

  .form-group input,
  .form-group textarea,
  .form-group select,
  .card > select {
    padding: 11px 12px;
    border-radius: 10px;
    font-size: 16px;
    width: 100%;
    box-sizing: border-box;
  }

  /* Primary action — full width, taller for thumb */
  .btn-primary {
    width: 100%;
    min-height: 48px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 700;
  }

  /* =========================================================
     4) BOTTOM NAVIGATION — clean phone version
     ========================================================= */
  .bottom-nav {
    padding: 6px 4px calc(8px + env(safe-area-inset-bottom, 0px));
    gap: 0;
  }

  .nav-item {
    padding: 6px 2px 4px;
    gap: 3px;
    max-width: none;
  }

  .nav-item i {
    font-size: 16px;
    line-height: 1;
  }

  .nav-item span {
    font-size: 9px;
    font-weight: 600;
    line-height: 1.1;
    letter-spacing: 0;
  }

  .nav-item.active {
    position: relative;
  }

  .nav-item.active::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 22px;
    height: 3px;
    border-radius: 0 0 999px 999px;
    background: var(--balance-pink);
  }

  /* Make sure content never sits under the nav */
  .role-app {
    padding-bottom: calc(var(--balance-bottom-nav-h) + 24px + env(safe-area-inset-bottom, 0px));
  }

  /* =========================================================
     5) CHAT / CONVERSATION — phone polish
     ========================================================= */
  .chat-list,
  .chat-item {
    border-radius: 14px;
  }

  .chat-item {
    padding: 12px;
  }

  .chat-avatar,
  .chat-item img.avatar-img {
    width: 44px;
    height: 44px;
  }

  .chat-meta-time {
    font-size: 11px;
  }

  /* =========================================================
     6) MEDIA / PLANS / SESSIONS cards — full width on phones
     ========================================================= */
  .trainee-media-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }

  .trainee-media-card {
    padding: 12px;
    border-radius: 14px;
  }

  .trainee-media-image,
  .trainee-media-video {
    max-height: 180px;
  }

  .trainee-media-title {
    font-size: 15px;
  }

  /* Coach hero/landing tweaks already handled in App.css; just tighten */
  .coach-hero,
  .trainee-media-hero {
    padding: 16px;
    border-radius: 14px;
  }

  /* =========================================================
     7) PROFILE — measurements/save area
     ========================================================= */
  .trainee-dashboard-save-btn,
  .save-btn {
    width: 100%;
    min-height: 48px;
  }
}

/* Very small devices (iPhone SE / 320px) */
@media (max-width: 360px) {
  .header h1 {
    font-size: 16px;
  }

  .measurement-card {
    padding: 10px;
    gap: 10px;
  }

  .measurement-icon {
    width: 34px;
    height: 34px;
    min-width: 34px;
    font-size: 13px;
  }

  .measurement-info label {
    font-size: 11px;
  }

  .measurement-card .input-with-unit input {
    padding: 10px 12px;
    font-size: 15px;
  }

  [dir='ltr'] .measurement-card .input-with-unit input {
    padding-right: 38px !important;
  }

  [dir='rtl'] .measurement-card .input-with-unit input {
    padding-left: 38px !important;
  }

  [dir='ltr'] .measurement-card .input-with-unit .unit {
    right: 12px;
  }

  [dir='rtl'] .measurement-card .input-with-unit .unit {
    left: 12px !important;
  }

  .nav-item i {
    font-size: 15px;
  }

  .nav-item span {
    font-size: 8px;
  }

  .bmi-value {
    font-size: 20px;
  }
}

/* Large phones / phablets — keep two columns for measurements */
@media (min-width: 481px) and (max-width: 720px) {
  .measurements-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .progress-stats,
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* =========================================================
   8) RTL-aware fine alignment for the input/unit pair
   (applies on every screen, not only phones)
   ========================================================= */
.input-with-unit {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.input-with-unit input {
  width: 100%;
  min-width: 0;
}

.input-with-unit .unit {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  font-size: 13px;
  color: var(--balance-ink-soft);
  pointer-events: none;
  white-space: nowrap;
}

/* Default LTR (units on the right) */
.input-with-unit input {
  padding-right: 46px;
  padding-left: 14px;
}

.input-with-unit .unit {
  right: 14px;
  left: auto;
}

/* RTL (units on the left, value reads naturally on the right) */
[dir='rtl'] .input-with-unit input {
  padding-left: 46px;
  padding-right: 14px;
}

[dir='rtl'] .input-with-unit .unit {
  left: 14px;
  right: auto;
}

/* =========================================================
   9) SAFE AREA + KEYBOARD-FRIENDLY DETAILS
   ========================================================= */
.app-shell .bottom-nav {
  padding-bottom: calc(10px + env(safe-area-inset-bottom, 0px));
}

/* When the on-screen keyboard is open on iOS, prevent layout jumping */
@supports (padding: max(0px)) {
  .role-app {
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
}

/* =========================================================
   10) ULTRA-NARROW DEVICES (≤ 320px)
   Covers Galaxy Z Fold (folded ≈ 280px), older/budget Android phones,
   and any smartwatch-style narrow viewport. Goal: never overflow,
   always readable, never truncate critical content.
   ========================================================= */
@media (max-width: 320px) {
  /* Tighten outer padding so content gets every available pixel */
  .main-content,
  .role-app .main-content,
  .container {
    padding-left: 8px !important;
    padding-right: 8px !important;
  }

  /* Coach hero: shrink the icon + text so the row fits 280px viewports */
  .coach-page-hero {
    gap: 10px;
    padding: 12px 12px 14px;
  }

  .coach-page-hero-icon {
    width: 38px;
    height: 38px;
    font-size: 16px;
    border-radius: 10px;
  }

  .coach-page-hero-text h2 {
    font-size: 1rem;
  }

  .coach-page-hero-text p {
    font-size: 12px;
  }

  /* Coach KPI cards: stack to a single column at <= 320px so values
     (which can be 4-5 digits + currency) are never cramped */
  .coach-kpi-grid--dashboard,
  .coach-earnings-kpi-grid {
    grid-template-columns: 1fr !important;
    gap: 10px;
  }

  .coach-kpi-card--rich .coach-kpi-value {
    font-size: 22px;
  }

  .coach-kpi-card--rich {
    padding: 12px 12px 14px;
  }

  /* Trainee dashboard: keep BMI + overview readable */
  .stats-grid,
  .progress-stats,
  .quick-actions {
    grid-template-columns: 1fr !important;
    gap: 8px;
  }

  /* Bottom nav: tighten further so all 5 items fit on a 280px width */
  .bottom-nav {
    padding: 4px 0 8px 0;
  }

  .nav-item {
    padding: 1px 0;
    gap: 0;
  }

  .nav-item i {
    font-size: 13px;
  }

  .nav-item span {
    font-size: 7px;
    line-height: 1;
  }

  /* Modals: hug the screen edges so inner content gets max width.
     We deliberately don't touch padding here because some modals
     (e.g. .user-profile .modal-content) use padding: 0 and rely on
     their inner sections for spacing. */
  .modal-content,
  .role-app-modal {
    width: calc(100vw - 12px) !important;
    max-width: calc(100vw - 12px) !important;
    margin: 6px !important;
  }

  .modal-overlay {
    padding: 0;
  }

  /* When a modal uses inner padding (.modal-body / .modal-header),
     tighten only that, not the outer container */
  .modal-body,
  .modal-header,
  .modal-footer {
    padding-left: 14px !important;
    padding-right: 14px !important;
  }

  /* Buttons: full width, slightly tighter padding */
  .btn,
  .save-btn,
  .trainee-dashboard-save-btn,
  .subscribe-btn {
    padding: 12px 14px;
    font-size: 14px;
  }

  /* Landing v2 hero: shrink heading so it doesn't overflow on 280px */
  .landing-v2-content h1 {
    font-size: 22px !important;
    line-height: 1.2;
  }

  .landing-v2-content p {
    font-size: 13px !important;
  }

  /* Conversation: avatar slightly smaller to give bubble more room */
  .message-avatar {
    width: 32px;
    height: 32px;
    min-width: 32px;
    font-size: 13px;
  }
}

/* =========================================================
   11) PHONE LANDSCAPE ORIENTATION
   When a phone is rotated (height ≤ 480px), vertical real-estate
   is precious. Compress headers and bottom-nav, allow the chat /
   dashboard scroll area to take more of the screen.
   ========================================================= */
@media (orientation: landscape) and (max-height: 480px) {
  /* Compress page hero blocks vertically */
  .coach-page-hero {
    padding: 10px 14px 12px;
    gap: 12px;
  }

  .coach-page-hero-icon {
    width: 36px;
    height: 36px;
    font-size: 15px;
  }

  .coach-page-hero-text h2 {
    font-size: 1rem;
    margin-bottom: 2px;
  }

  .coach-page-hero-text p {
    font-size: 12px;
    line-height: 1.4;
  }

  /* Header: thinner so more chat / scroll content is visible */
  .header,
  .role-app .header {
    padding: 8px 12px;
  }

  .header h1 {
    font-size: 15px;
  }

  /* Bottom nav: lower profile in landscape so it doesn't eat the screen */
  .bottom-nav,
  .app-shell .bottom-nav {
    padding-top: 4px;
    padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px));
  }

  .nav-item {
    padding: 2px 1px;
  }

  .nav-item i {
    font-size: 14px;
  }

  .nav-item span {
    font-size: 8px;
  }

  /* Trainee BMI: shorter card in landscape so the dashboard fits */
  .bmi-card {
    padding: 12px 16px;
  }

  .bmi-value {
    font-size: 22px;
  }

  /* Conversation: keep input visible above the keyboard */
  .chat-messages {
    padding-bottom: 60px;
  }

  /* Video call: keep grid scrollable when call has many tiles */
  .vc-stage {
    padding: 8px;
  }

  .vc-controls {
    padding: 8px 12px 10px;
  }

  .vc-ctrl {
    width: 42px;
    height: 42px;
    font-size: 14px;
  }
}
