/* EKM Mobile Shell — Phase 1 foundation (dark-mode first) */
:root {
  --ekm-mobile-nav-height: calc(56px + env(safe-area-inset-bottom, 0px));
  --ekm-mobile-touch-min: 44px;
  --ekm-mobile-gutter: 16px;
  --ekm-mobile-type-body: 0.875rem;
  --ekm-mobile-type-caption: 0.75rem;
  --ekm-mobile-type-title: 1.125rem;
  --ekm-mobile-nav-bg: var(--c-box, #1e1e1c);
  --ekm-mobile-nav-border: var(--c-rule, rgba(255, 255, 255, 0.08));
  --ekm-mobile-nav-active: var(--c-accent, #c9a227);
  --ekm-mobile-nav-muted: var(--c-muted2, #8a8580);
  --ekm-mobile-sheet-bg: var(--c-box, #1e1e1c);
  --ekm-mobile-card-bg: var(--c-box, #1e1e1c);
  --ekm-mobile-card-border: var(--c-box-border, rgba(255, 255, 255, 0.1));
}

html.ekm-mobile {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

html.ekm-mobile body {
  overflow-x: hidden;
}

html.ekm-mobile main#main-content {
  overflow-x: hidden;
  max-width: 100vw;
  padding-bottom: var(--ekm-mobile-nav-height);
  box-sizing: border-box;
}

html.ekm-mobile body.hp-active main#main-content {
  padding-bottom: var(--ekm-mobile-nav-height);
}

/* Hide desktop left rail on phones */
html.ekm-mobile #main-content.nav-model-b-layout > .hp-nav-rail,
html.ekm-mobile #main-content .hp-nav-rail,
html.ekm-mobile .os-nav-sidebar,
html.ekm-mobile .legacy-nav-sidebar {
  display: none !important;
}

html.ekm-mobile #main-content.nav-model-b-layout:has(.hp-nav-rail) > .nav-model-b-main,
html.ekm-mobile #main-content.nav-model-b-layout:has(.hp-nav-rail):not(:has(> .nav-model-b-main)) > :not(.hp-topnav):not(.hp-nav-rail):not(#ekm-active-alerts) {
  grid-column: 1 / -1 !important;
  grid-row: 3 !important;
  width: 100%;
  max-width: 100%;
}

html.ekm-mobile #main-content.nav-model-b-layout .pds-page,
html.ekm-mobile #main-content.nav-model-b-layout:not(:has(.hp-nav-rail)) .pds-page {
  padding-inline: var(--ekm-mobile-gutter);
}

/* Bottom navigation */
.ekm-mobile-bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 120;
  height: var(--ekm-mobile-nav-height);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--ekm-mobile-nav-bg);
  border-top: 0.5px solid var(--ekm-mobile-nav-border);
  box-shadow: var(--elevation-2, 0 -8px 24px rgba(0, 0, 0, 0.28));
  font-family: var(--font-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

html.ekm-mobile.ekm-mobile-authed .ekm-mobile-bottom-nav {
  display: flex;
  align-items: stretch;
  justify-content: space-around;
}

.ekm-mobile-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  min-height: var(--ekm-mobile-touch-min);
  padding: 6px 4px 4px;
  border: none;
  background: none;
  color: var(--ekm-mobile-nav-muted);
  cursor: pointer;
  font-family: inherit;
  transition: color var(--motion-fast, 120ms) var(--motion-ease, ease);
  -webkit-user-select: none;
  user-select: none;
}

.ekm-mobile-nav-item:active {
  opacity: 0.85;
}

.ekm-mobile-nav-item.active {
  color: var(--ekm-mobile-nav-active);
}

.ekm-mobile-nav-icon {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.ekm-mobile-nav-label {
  font-size: var(--type-eyebrow, 0.6875rem);
  font-weight: 500;
  letter-spacing: 0.02em;
  line-height: 1.1;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* More sheet */
.ekm-mobile-sheet-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 130;
  background: rgba(0, 0, 0, 0.52);
  opacity: 0;
  transition: opacity 0.22s ease;
}

.ekm-mobile-sheet-backdrop.open {
  display: block;
  opacity: 1;
}

.ekm-mobile-more-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 131;
  max-height: min(78vh, 640px);
  padding: 0 var(--ekm-mobile-gutter) calc(var(--ekm-mobile-gutter) + env(safe-area-inset-bottom, 0px));
  background: var(--ekm-mobile-sheet-bg);
  border-radius: 16px 16px 0 0;
  border-top: 0.5px solid var(--ekm-mobile-nav-border);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.35);
  transform: translateY(105%);
  transition: transform 0.26s cubic-bezier(0.32, 0.72, 0, 1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ekm-mobile-more-sheet.open {
  transform: translateY(0);
}

.ekm-mobile-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 999px;
  background: var(--c-rule, rgba(255, 255, 255, 0.18));
  margin: 10px auto 8px;
  flex-shrink: 0;
}

.ekm-mobile-sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0 12px;
  flex-shrink: 0;
}

.ekm-mobile-sheet-title {
  font-size: var(--ekm-mobile-type-title);
  font-weight: 600;
  color: var(--c-ink, #f5f4f0);
  letter-spacing: 0.01em;
}

.ekm-mobile-sheet-close {
  min-width: var(--ekm-mobile-touch-min);
  min-height: var(--ekm-mobile-touch-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: none;
  color: var(--c-muted, #aaa);
  font-size: 22px;
  cursor: pointer;
  border-radius: 8px;
}

.ekm-mobile-sheet-body {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1;
  min-height: 0;
}

.ekm-mobile-sheet-section {
  margin-bottom: 14px;
}

.ekm-mobile-sheet-section-label {
  font-size: var(--ekm-mobile-type-caption);
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--c-muted2, #8a8580);
  padding: 0 4px 8px;
}

.ekm-mobile-sheet-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.ekm-mobile-sheet-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: var(--ekm-mobile-touch-min);
  padding: 10px 12px;
  border: 0.5px solid var(--ekm-mobile-card-border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--c-ink2, #d8d6d0);
  font-size: var(--ekm-mobile-type-body);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.ekm-mobile-sheet-item:active,
.ekm-mobile-sheet-item:hover {
  background: rgba(255, 255, 255, 0.06);
  border-color: var(--c-accent, rgba(201, 162, 39, 0.35));
}

.ekm-mobile-sheet-item-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.88;
}

/* Mobile card utility */
.ekm-mobile-card {
  background: var(--ekm-mobile-card-bg);
  border: 0.5px solid var(--ekm-mobile-card-border);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: var(--hp-shadow, 0 4px 16px rgba(0, 0, 0, 0.12));
}

.ekm-mobile-card-title {
  font-size: var(--ekm-mobile-type-body);
  font-weight: 600;
  color: var(--c-ink, #f5f4f0);
  margin-bottom: 4px;
}

.ekm-mobile-card-meta {
  font-size: var(--ekm-mobile-type-caption);
  color: var(--c-muted2, #8a8580);
  line-height: 1.45;
}

/* FAB utility — compose / primary action */
.ekm-mobile-fab {
  position: fixed;
  right: calc(var(--ekm-mobile-gutter) + env(safe-area-inset-right, 0px));
  bottom: calc(var(--ekm-mobile-nav-height) + 16px);
  z-index: 115;
  width: 52px;
  height: 52px;
  min-width: var(--ekm-mobile-touch-min);
  min-height: var(--ekm-mobile-touch-min);
  border-radius: 50%;
  border: none;
  background: var(--c-accent, #c9a227);
  color: var(--c-accent-text, #fff);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.32);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.ekm-mobile-fab:active {
  transform: scale(0.96);
}

html:not(.ekm-mobile) .ekm-mobile-fab {
  display: none;
}

/* Pull-to-refresh indicator */
.ekm-mobile-ptr {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  z-index: 140;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--ekm-mobile-nav-bg);
  border: 0.5px solid var(--ekm-mobile-nav-border);
  color: var(--c-ink2, #d8d6d0);
  font-size: var(--ekm-mobile-type-caption);
  font-family: var(--font-ui, -apple-system, sans-serif);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.24);
  pointer-events: none;
  opacity: 0;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.ekm-mobile-ptr.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.ekm-mobile-ptr-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid var(--c-muted2, #8a8580);
  border-top-color: var(--c-accent, #c9a227);
  border-radius: 50%;
  animation: ekm-mobile-spin 0.7s linear infinite;
}

@keyframes ekm-mobile-spin {
  to { transform: rotate(360deg); }
}

/* Reposition floating message FAB above bottom nav */
html.ekm-mobile #msg-float-fab {
  bottom: calc(var(--ekm-mobile-nav-height) + 12px);
  right: calc(var(--ekm-mobile-gutter) + env(safe-area-inset-right, 0px));
}

html.ekm-mobile #msg-float-panel {
  bottom: calc(var(--ekm-mobile-nav-height) + 12px);
  right: calc(var(--ekm-mobile-gutter) + env(safe-area-inset-right, 0px));
}

html.ekm-mobile #ekm-msg-toast-stack {
  bottom: calc(var(--ekm-mobile-nav-height) + 12px);
}

/* Responsive typography on mobile */
html.ekm-mobile {
  --type-body-size: var(--ekm-mobile-type-body);
  --type-caption-size: var(--ekm-mobile-type-caption);
}

html.ekm-mobile .section-header h2,
html.ekm-mobile .os-dash-title {
  font-size: clamp(1.375rem, 5vw, 1.75rem);
}

html.ekm-mobile .card-body,
html.ekm-mobile .hp-softbox {
  font-size: var(--ekm-mobile-type-body);
}

/* Dark mode contrast guard */
html[data-dark].ekm-mobile .ekm-mobile-sheet-item {
  color: var(--c-ink2, #d4d2cc);
}

html[data-dark].ekm-mobile .ekm-mobile-nav-item {
  color: var(--c-muted2, #9a9590);
}

html[data-dark].ekm-mobile .ekm-mobile-nav-item.active {
  color: var(--c-accent, #d4b84a);
}

html[data-dark].ekm-mobile .ekm-mobile-bottom-nav,
html[data-dark].ekm-mobile .ekm-mobile-more-sheet {
  background: var(--c-box, #1a1a18);
}

/*
 * Standalone PWA (.1533) — SAME layout path as Safari mobile.
 * Do NOT pad .hp-topnav with safe-area (that shifted absolute badges into a
 * floating top-left ghost and made the nav look doubled under translucent
 * status bars). Put safe-area on the document instead; keep topnav flex intact.
 */
html.ekm-mobile.ekm-standalone {
  padding-top: env(safe-area-inset-top, 0px);
  box-sizing: border-box;
}

html.ekm-mobile.ekm-standalone .hp-topnav,
html.ekm-mobile.ekm-standalone .pwa-install-banner {
  padding-top: 0;
}

/* Reaffirm .1527 hero gap fix under standalone (no parallel height:100% path) */
html.ekm-mobile.ekm-standalone .hp-awareness-row.hp-awareness-row--hero-only,
html.ekm-mobile.ekm-standalone .hp-awareness-row.hp-awareness-row--hero-only > .hp-hero-zone,
html.ekm-mobile.ekm-standalone .hp-awareness-row.hp-awareness-row--hero-only .hp-hero {
  height: auto !important;
  min-height: 0 !important;
  max-height: none !important;
}

/* Kill compositor/text-shadow “ghost double” of lockup + hero date/time on iOS PWA */
html.ekm-mobile.ekm-standalone .hp-lockup-mark,
html.ekm-mobile.ekm-standalone .hp-hero-greeting,
html.ekm-mobile.ekm-standalone .hp-hero-name,
html.ekm-mobile.ekm-standalone .hp-hero-date,
html.ekm-mobile.ekm-standalone .hp-hero-clock-time,
html.ekm-mobile.ekm-standalone .hp-hero-clock-meta,
html.ekm-mobile.ekm-standalone .hp-topnav .tab-btn,
html.ekm-mobile.ekm-standalone .hp-topnav .hp-nav-tab-icon {
  text-shadow: none !important;
  filter: none !important;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* Badges stay glued to their icon button — never the padded viewport */
html.ekm-mobile.ekm-standalone .hp-topnav-utils .hp-nav-inbox-btn,
html.ekm-mobile.ekm-standalone .hp-topnav-utils .whats-new-nav-btn,
html.ekm-mobile.ekm-standalone .hp-topnav-utils .hp-nav-calendar-btn,
html.ekm-mobile.ekm-standalone .hp-topnav-center .tab-btn {
  position: relative;
  overflow: visible;
}

html.ekm-mobile.ekm-standalone .nav-unread-badge,
html.ekm-mobile.ekm-standalone #msg-nav-dot.nav-unread-badge,
html.ekm-mobile.ekm-standalone #notif-dot.nav-unread-badge,
html.ekm-mobile.ekm-standalone #whats-new-nav-badge.nav-unread-badge,
html.ekm-mobile.ekm-standalone .hp-topnav-center .tab-btn #workflow-badge {
  position: absolute !important;
  top: 0 !important;
  right: 0 !important;
  left: auto !important;
  transform: translate(30%, -30%);
  z-index: 3;
}

html.ekm-mobile.ekm-standalone .ekm-mobile-ptr {
  top: calc(env(safe-area-inset-top, 0px) + 12px);
}
