/**
 * FiberManager iOS PWA & Standalone Engine Styles
 * Provides notch/Dynamic Island safe-area handling, dynamic viewport units (100dvh),
 * touch feedback optimizations, and Cupertino-style install coachmark modal.
 */

:root {
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --ios-cyan: #00f2ff;
  --ios-blue: #0088ff;
  --ios-bg: rgba(10, 11, 16, 0.94);
  --ios-border: rgba(0, 242, 255, 0.25);
}

/* 1. Viewport & Scrolling Optimizations */
html, body {
  overscroll-behavior-y: none;
  -webkit-overflow-scrolling: touch;
}

#app, .organizer-container, body.login-screen {
  min-height: 100vh;
  min-height: 100dvh !important;
  box-sizing: border-box;
}

/* 2. Touch & Tap Optimizations */
*, *::before, *::after {
  -webkit-tap-highlight-color: transparent !important;
}

button, a, input, select, .leaflet-control, .tool-btn {
  touch-action: manipulation;
}

/* Prevent accidental link/image previews on long-press */
nav a, .nav-links a, .logo img {
  -webkit-touch-callout: none;
}

/* 3. Notch & Dynamic Island Safe Area Adjustments */
nav {
  padding-top: max(0.6rem, calc(0.35rem + env(safe-area-inset-top))) !important;
  padding-left: max(1.5rem, calc(1rem + env(safe-area-inset-left))) !important;
  padding-right: max(1.5rem, calc(1rem + env(safe-area-inset-right))) !important;
}

/* Bottom elements clearing Home Bar */
#global-stats-overlay {
  bottom: max(30px, calc(16px + env(safe-area-inset-bottom))) !important;
  right: max(30px, calc(16px + env(safe-area-inset-right))) !important;
}

/* Floating panels and sidebars */
.overlay-panel {
  top: max(20px, calc(10px + env(safe-area-inset-top))) !important;
  right: max(20px, calc(10px + env(safe-area-inset-right))) !important;
}

.cable-column {
  padding-bottom: max(20px, calc(10px + env(safe-area-inset-bottom))) !important;
}

/* 4. iOS 'Add to Home Screen' Coachmark Sheet */
#ios-install-prompt {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  padding: 0 16px max(24px, calc(12px + env(safe-area-inset-bottom)));
  pointer-events: none;
  opacity: 0;
  transform: translateY(30px);
  transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1), transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

#ios-install-prompt.active {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.ios-prompt-card {
  width: 100%;
  max-width: 440px;
  background: var(--ios-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--ios-border);
  border-radius: 20px;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8), 0 0 25px rgba(0, 242, 255, 0.15);
  color: #e0e6ed;
  position: relative;
}

.ios-prompt-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.ios-prompt-title {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ios-prompt-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: #000;
  border: 1px solid rgba(0, 242, 255, 0.4);
  padding: 4px;
  object-fit: contain;
}

.ios-prompt-heading {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.02rem;
}

.ios-prompt-subheading {
  font-size: 0.75rem;
  color: #94a3b8;
}

.ios-prompt-close {
  background: rgba(255, 255, 255, 0.08);
  border: none;
  color: #94a3b8;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: all 0.2s;
}

.ios-prompt-close:hover {
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
}

.ios-steps-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 14px 0 16px 0;
}

.ios-step {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.88rem;
  color: #cbd5e1;
  background: rgba(255, 255, 255, 0.03);
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.ios-step-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(0, 242, 255, 0.15);
  color: var(--ios-cyan);
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}

.ios-step svg {
  vertical-align: middle;
  fill: var(--ios-cyan);
  margin: 0 3px;
}

.ios-prompt-actions {
  display: flex;
  gap: 10px;
}

.ios-btn-primary {
  flex: 1;
  background: linear-gradient(135deg, #0088ff 0%, #00f2ff 100%);
  color: #05070a;
  border: none;
  padding: 10px 16px;
  border-radius: 10px;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.ios-btn-primary:active {
  transform: scale(0.98);
}

.ios-btn-secondary {
  background: transparent;
  color: #94a3b8;
  border: 1px solid rgba(255, 255, 255, 0.12);
  padding: 10px 14px;
  border-radius: 10px;
  font-size: 0.85rem;
  cursor: pointer;
}

/* Pointer arrow pointing down to Safari share bar on iPhones */
.ios-share-pointer {
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 10px solid var(--ios-border);
}
