/* =============================================================
   GAATW Members Platform — mobile.css
   Mobile-first additions and fixes.
   Load AFTER app.css.

   What this fixes / adds:
   - Sidebar position bug (CSS var in left property)
   - Touch target sizes (min 44px per Apple/WCAG)
   - Bottom navigation bar for mobile
   - Public request form
   - Captcha widget
   - Admin invite-request review panel
   - Table horizontal scroll on mobile
   - Modal / bottom sheet pattern
   - Font sizes legible on small screens
   - Safe area insets (iPhone notch / home bar)
   ============================================================= */

/* ── Fix sidebar CSS variable bug ─────────────────────────────
   Original: left: -var(--sidebar-width) — invalid CSS.
   Fix: use calc() or a static negative value.
   ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -220px;          /* slightly wider than --sidebar-width for safety */
    top: 0;
    height: 100vh;
    z-index: 200;
    transition: left 0.25s ease;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar.open {
    left: 0;
    box-shadow: 4px 0 24px rgba(0,0,0,0.35);
  }
  .sb-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 190;
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
  }
}

/* ── Bottom navigation bar (mobile only) ──────────────────────
   Replaces sidebar for primary navigation on phones.
   Shows 5 key sections. Scrolls content up above it.
   ─────────────────────────────────────────────────────────── */

.bottom-nav {
  display: none;
}

@media (max-width: 768px) {
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    background: var(--bg-primary);
    border-top: 1px solid var(--border);
    z-index: 150;
    align-items: stretch;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-bottom: constant(safe-area-inset-bottom, 0px);
  }

  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 9px;
    font-weight: 500;
    padding: 6px 4px;
    border: none;
    background: transparent;
    font-family: var(--font-sans);
    -webkit-tap-highlight-color: transparent;
    transition: color 0.1s;
    min-height: 44px;
    text-decoration: none;
  }

  .bottom-nav-item.active {
    color: var(--teal);
  }

  .bottom-nav-item.active .bni-icon {
    background: var(--teal-light);
    border-radius: 10px;
  }

  .bni-icon {
    font-size: 20px;
    line-height: 1;
    width: 36px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: background 0.1s;
  }

  .bni-badge {
    position: absolute;
    top: -2px;
    right: 0px;
    background: var(--amber);
    color: #fff;
    font-size: 8px;
    font-weight: 700;
    min-width: 14px;
    height: 14px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
  }

  /* Push main content above bottom nav */
  .main-area {
    padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
  }

  /* Hide hamburger menu when bottom nav is present */
  .mobile-menu-btn {
    display: none;
  }

  /* Topbar becomes leaner on mobile */
  .topbar {
    height: 44px;
    padding: 0 14px;
  }

  .topbar-title {
    font-size: 14px;
  }

  /* Page content safe area */
  .page-content {
    padding: 12px 12px;
    padding-bottom: 16px;
  }
}

/* ── Touch targets — minimum 44×44px everywhere ───────────────
   Applies universally: any interactive element on mobile.
   ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .btn-main, .btn-amber, .btn-outline {
    min-height: 44px;
    font-size: 14px;
    border-radius: var(--radius);
  }

  .form-input, select.form-input, .filter-input, .filter-select {
    min-height: 44px;
    font-size: 16px;  /* prevents iOS zoom-on-focus */
    padding: 10px 14px;
  }

  .sb-item {
    padding: 12px 16px;
    font-size: 14px;
    min-height: 44px;
  }

  .section-tab {
    padding: 10px 14px;
    font-size: 12px;
    min-height: 44px;
    display: flex;
    align-items: center;
  }

  .digit {
    width: 42px;
    height: 52px;
    font-size: 20px;
  }

  .toggle {
    width: 44px;
    height: 24px;
    border-radius: 12px;
  }

  .toggle::after {
    width: 18px;
    height: 18px;
    top: 3px;
    left: 3px;
  }

  .toggle.on::after { left: 23px; }

  /* Larger tap areas on cards */
  .member-card {
    padding: 14px;
  }

  .media-item {
    padding: 14px;
  }
}

/* ── Responsive grid fixes ────────────────────────────────────
   Supplement what's in app.css.
   ─────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  /* KPI strip: 2 columns on tablet, 1 on phone */
  .grid-5 {
    grid-template-columns: repeat(2, 1fr);
  }

  /* ACL table: scroll horizontally */
  .acl-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Filter bar: stack vertically */
  .filter-bar {
    flex-direction: column;
    gap: 8px;
  }

  .filter-input {
    min-width: unset;
    width: 100%;
  }

  /* Reduce card padding */
  .card {
    padding: 12px;
  }

  /* Topbar actions collapse to icon-only */
  .topbar-actions .btn-outline {
    padding: 6px 10px;
    font-size: 11px;
  }

  /* Media items */
  .mi-summary {
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* Member grid: 2 columns minimum on wider phones */
  .member-grid {
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  }

  /* Hide low-priority columns in tables */
  .hide-mobile {
    display: none;
  }
}

@media (max-width: 380px) {
  /* Single column everything on very small phones */
  .grid-5, .grid-4 {
    grid-template-columns: 1fr;
  }
  .member-grid {
    grid-template-columns: 1fr;
  }
  .digit {
    width: 38px;
    height: 48px;
    font-size: 18px;
  }
}

/* ── Safe area insets (iPhone notch, dynamic island, home bar) */
@supports (padding: max(0px)) {
  .bottom-nav {
    padding-bottom: max(env(safe-area-inset-bottom), 4px);
  }
  .topbar {
    padding-top: max(env(safe-area-inset-top), 0px);
  }
}

/* ── Captcha widget ────────────────────────────────────────────
   Friendly logic puzzle — no third-party dependencies.
   ─────────────────────────────────────────────────────────── */

.captcha-box {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  background: var(--bg-secondary);
  margin-bottom: 14px;
}

.captcha-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.captcha-label::before {
  content: '🛡';
  font-size: 11px;
}

.captcha-question {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 8px;
  line-height: 1.4;
}

.captcha-input {
  width: 100%;
  padding: 9px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--bg-primary);
  outline: none;
  transition: border-color 0.15s;
}

.captcha-input:focus {
  border-color: var(--teal);
}

.captcha-refresh {
  font-size: 10px;
  color: var(--teal);
  cursor: pointer;
  margin-top: 5px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.captcha-refresh:hover {
  text-decoration: underline;
}

/* ── Public request-invite form page ──────────────────────────
   Accessible from the login page via "Request access" link.
   Full-page on mobile, centered panel on desktop.
   ─────────────────────────────────────────────────────────── */

.request-page {
  min-height: 100vh;
  background: var(--bg-secondary);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 24px 16px 48px;
}

.request-panel {
  width: 100%;
  max-width: 520px;
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 28px 28px 32px;
  box-shadow: var(--shadow-lg);
}

@media (max-width: 560px) {
  .request-panel {
    padding: 20px 16px 28px;
    border-radius: var(--radius);
  }
  .request-page {
    padding: 16px 0 0;
    align-items: stretch;
  }
  .request-panel {
    border-radius: 0;
    border: none;
    box-shadow: none;
    min-height: 100vh;
  }
}

.request-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
}

.request-logo {
  width: 36px;
  height: 36px;
  object-fit: contain;
}

.request-brand {
  font-size: 13px;
  font-weight: 600;
  color: var(--teal);
}

.request-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  line-height: 1.3;
}

.request-sub {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 20px;
}

.request-back {
  font-size: 11px;
  color: var(--teal);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 16px;
  text-decoration: none;
}

.request-success {
  text-align: center;
  padding: 32px 16px;
}

.request-success-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.request-success-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--teal);
  margin-bottom: 8px;
}

.request-success-text {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ── Admin: Invite request review panel ───────────────────────
   Shown in Settings → Access Requests tab
   ─────────────────────────────────────────────────────────── */

.invite-req-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  margin-bottom: 10px;
  background: var(--bg-primary);
  transition: border-color 0.15s;
}

.invite-req-card:hover {
  border-color: var(--teal);
}

.invite-req-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 2px;
}

.invite-req-org {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.invite-req-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 8px;
}

.invite-req-tag {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
}

.invite-req-message {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.5;
  font-style: italic;
  border-left: 2px solid var(--border);
  padding-left: 8px;
  margin-bottom: 10px;
}

.invite-req-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 480px) {
  .invite-req-actions {
    flex-direction: column;
  }

  .invite-req-actions .btn-amber,
  .invite-req-actions .btn-outline,
  .invite-req-actions .btn-danger {
    width: 100%;
    justify-content: center;
    text-align: center;
  }
}

/* ── Modal / bottom sheet ─────────────────────────────────────
   Used for approve/decline confirmation dialogs.
   On desktop: centered modal.
   On mobile: bottom sheet with handle.
   ─────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal {
  background: var(--bg-primary);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  animation: fadeUp 0.2s ease;
}

.modal-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.modal-body {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.6;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

@media (max-width: 480px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-width: 100%;
    padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions button {
    width: 100%;
    min-height: 48px;
  }

  /* Bottom sheet handle */
  .modal::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    border-radius: 2px;
    background: var(--border);
    margin: 0 auto 16px;
  }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Sticky topbar on scroll ──────────────────────────────────
   Locks topbar and keeps page content scrollable.
   ─────────────────────────────────────────────────────────── */

.main-area {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex: 1;
}

.page-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
}

/* ── Pull-to-refresh indicator (future enhancement hook) ──── */
.ptr-indicator {
  text-align: center;
  padding: 12px;
  font-size: 12px;
  color: var(--text-muted);
  display: none;
}

/* ── Notification badge fix on mobile ─────────────────────── */
@media (max-width: 768px) {
  .sb-badge {
    display: none; /* Badges shown in bottom nav instead */
  }
}

/* ── Auth screen mobile fixes ─────────────────────────────── */
@media (max-width: 768px) {
  .auth-screen {
    min-height: 100vh;
    min-height: -webkit-fill-available; /* iOS Safari */
  }

  .auth-right {
    padding: 28px 22px 40px;
    padding-bottom: calc(40px + env(safe-area-inset-bottom, 0px));
  }

  .auth-title {
    font-size: 22px;
  }

  .twofa-nudge {
    margin-bottom: 8px;
  }
}

/* ── Scrollable horizontal tables on mobile ────────────────── */
.table-scroll-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.table-scroll-wrap table {
  min-width: 540px;
  border: none;
}

/* ── Focus visible (keyboard navigation) ──────────────────── */
:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
  border-radius: 3px;
}

/* ── Dark mode: mobile nav ─────────────────────────────────── */
[data-theme="dark"] .bottom-nav {
  background: var(--bg-primary);
  border-top-color: var(--border);
}

[data-theme="dark"] .modal {
  box-shadow: 0 -4px 32px rgba(0,0,0,0.4);
}

/* ── Landscape phone fixes ─────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  .auth-screen {
    min-height: unset;
  }

  .auth-right {
    overflow-y: auto;
    max-height: 100vh;
  }

  .bottom-nav {
    display: none; /* Too short for landscape bottom nav */
  }

  .main-area {
    padding-bottom: 0;
  }
}
/* =============================================================
   Additions to mobile.css — two-track request form styles
   Add these at the end of mobile.css (or as a separate file).
   ============================================================= */

/* ── Track selection buttons ─────────────────────────────────── */

.track-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px 15px;
  background: var(--bg-primary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  cursor: pointer;
  font-family: var(--font-sans);
  text-align: left;
  margin-bottom: 10px;
  transition: border-color 0.15s, background 0.12s, transform 0.1s;
  min-height: 72px;
  -webkit-tap-highlight-color: transparent;
}

.track-btn:hover,
.track-btn:focus-visible {
  border-color: var(--teal);
  background: var(--teal-pale);
}

.track-btn:active {
  transform: scale(0.99);
}

.track-icon {
  font-size: 22px;
  flex-shrink: 0;
  width: 36px;
  text-align: center;
}

.track-body {
  flex: 1;
  min-width: 0;
}

.track-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 3px;
}

.track-desc {
  font-size: 11px;
  color: var(--text-secondary);
  line-height: 1.45;
}

.track-arrow {
  font-size: 20px;
  color: var(--border-mid);
  flex-shrink: 0;
}

/* ── Track badge shown inside the form ────────────────────────── */

.track-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  margin-bottom: 16px;
}

.track-badge-member {
  background: var(--teal-light);
  color: var(--teal);
}

.track-badge-nonmember {
  background: var(--amber-light);
  color: var(--amber-dark);
}

/* ── Optional field label marker ─────────────────────────────── */

.form-optional {
  font-weight: 400;
  font-style: italic;
  color: var(--text-muted);
  font-size: 9px;
  margin-left: 4px;
}

/* ── Disabled form message ───────────────────────────────────── */

.request-disabled-msg {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.65;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-top: 8px;
  text-align: center;
}

.request-disabled-msg a {
  color: var(--teal);
  font-weight: 500;
}

/* ── Request panel: scrollable on short screens ──────────────── */

@media (max-height: 700px) {
  .request-panel {
    overflow-y: auto;
    max-height: 100vh;
    max-height: -webkit-fill-available;
  }
}

/* ── Reason textarea: grow with content on mobile ────────────── */

@media (max-width: 560px) {
  #req-reason {
    min-height: 120px;
  }
}

/* ── RTL (Right-to-Left) support — Arabic ─────────────────────
   Applied automatically when language is set to Arabic.
   ─────────────────────────────────────────────────────────── */

[dir="rtl"] .sidebar {
  left: unset;
  right: 0;
}

[dir="rtl"] .sidebar.open {
  left: unset;
  right: 0;
}

@media (max-width: 768px) {
  [dir="rtl"] .sidebar {
    left: unset;
    right: -220px;
    transition: right 0.25s ease;
  }
  [dir="rtl"] .sidebar.open {
    right: 0;
    left: unset;
  }
}

[dir="rtl"] .main-area {
  margin-left: 0;
  margin-right: var(--sidebar-width, 200px);
}

[dir="rtl"] .sb-nav .sb-item,
[dir="rtl"] .card-head,
[dir="rtl"] .filter-bar,
[dir="rtl"] .settings-row {
  flex-direction: row-reverse;
}

[dir="rtl"] .form-label,
[dir="rtl"] .card-title,
[dir="rtl"] .kpi-label {
  text-align: right;
}

[dir="rtl"] .topbar {
  flex-direction: row-reverse;
}

[dir="rtl"] .bottom-nav {
  direction: rtl;
}

[dir="rtl"] .auth-right {
  direction: rtl;
}
