/* NotWasted Design System - iOS WebKit Compatibility */
/* Fixes for iOS Safari / WebKit rendering quirks */

/* ========== VIEWPORT & LAYOUT ========== */

/* 100vh bug fix: iOS Safari's 100vh includes the area behind the URL bar.
   Use dvh (dynamic viewport height) with -webkit-fill-available fallback. */
html {
  height: -webkit-fill-available;
}

body {
  min-height: 100dvh;
  min-height: -webkit-fill-available;
}

/* Safe-area insets for notched devices (iPhone X+, etc.) */
@supports (padding: env(safe-area-inset-bottom)) {
  body {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }

  /* Bottom navigation needs extra padding to clear the home indicator */
  .bottom-nav {
    padding-bottom: calc(env(safe-area-inset-bottom) + 8px);
  }

  /* Fixed/sticky headers need to account for the notch */
  .app-header,
  .admin-header,
  nav.fixed,
  header.fixed {
    padding-top: env(safe-area-inset-top);
  }

  /* Modals should also respect safe areas */
  .modal-overlay {
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  }
}

/* ========== SCROLL & BOUNCE ========== */

/* Prevent rubber-band bounce scroll on body */
html {
  position: relative;
  overflow: hidden;
  height: 100%;
}

body {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: none;
  height: 100%;
}

/* Allow scroll inside screens but prevent bounce */
.screen {
  overscroll-behavior: contain;
}

/* ========== TAP & TOUCH ========== */

/* Remove blue tap highlight on all interactive elements */
* {
  -webkit-tap-highlight-color: transparent;
}

/* Remove long-press callout menu */
a, button, input, select, textarea {
  -webkit-touch-callout: none;
}

/* Re-enable callout for inputs where copy/paste is expected */
input:not([type="button"]):not([type="submit"]),
textarea {
  -webkit-touch-callout: default;
}

/* ========== TEXT & FONT ========== */

/* Prevent iOS from auto-adjusting font size on orientation change */
html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* Prevent iOS zoom on input focus (font-size must be >= 16px) */
input,
select,
textarea {
  font-size: 16px;
}

/* ========== FORM ELEMENTS ========== */

/* Normalize iOS-specific input styling */
input[type="text"],
input[type="tel"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="url"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
select,
textarea {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  border-radius: 0;
}

/* Re-add border-radius for elements that should have it */
.input,
.select,
.textarea,
input.input,
select.select,
textarea.textarea {
  border-radius: var(--radius-base, 8px);
}

/* Fix iOS search input styling */
input[type="search"] {
  -webkit-appearance: none;
}

input[type="search"]::-webkit-search-cancel-button,
input[type="search"]::-webkit-search-decoration {
  -webkit-appearance: none;
}

/* Fix iOS select dropdown arrow */
select {
  background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%22292.4%22%20height%3D%22292.4%22%3E%3Cpath%20fill%3D%22%23525252%22%20d%3D%22M287%2069.4a17.6%2017.6%200%200%200-13-5.4H18.4c-5%200-9.3%201.8-12.9%205.4A17.6%2017.6%200%200%200%200%2082.2c0%205%201.8%209.3%205.4%2012.9l128%20127.9c3.6%203.6%207.8%205.4%2012.8%205.4s9.2-1.8%2012.8-5.4L287%2095c3.5-3.5%205.4-7.8%205.4-12.8%200-5-1.9-9.2-5.5-12.8z%22%2F%3E%3C%2Fsvg%3E');
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 10px;
  padding-right: 32px;
}

/* Fix iOS date/datetime-local input placeholder color */
input[type="date"]::-webkit-datetime-edit-text,
input[type="date"]::-webkit-datetime-edit-month-field,
input[type="date"]::-webkit-datetime-edit-day-field,
input[type="date"]::-webkit-datetime-edit-year-field,
input[type="datetime-local"]::-webkit-datetime-edit-text,
input[type="datetime-local"]::-webkit-datetime-edit-month-field,
input[type="datetime-local"]::-webkit-datetime-edit-day-field,
input[type="datetime-local"]::-webkit-datetime-edit-year-field,
input[type="datetime-local"]::-webkit-datetime-edit-hour-field,
input[type="datetime-local"]::-webkit-datetime-edit-minute-field,
input[type="time"]::-webkit-datetime-edit-text,
input[type="time"]::-webkit-datetime-edit-hour-field,
input[type="time"]::-webkit-datetime-edit-minute-field,
input[type="time"]::-webkit-datetime-edit-dayperiod-field {
  color: inherit;
}

/* ========== BUTTONS ========== */

/* Remove iOS button inner shadow */
button,
input[type="button"],
input[type="submit"],
input[type="reset"] {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
}

/* ========== STICKY POSITIONING ========== */

/* Support sticky on older iOS */
.sticky,
[style*="position: sticky"],
[style*="position:sticky"] {
  position: -webkit-sticky;
  position: sticky;
}

/* ========== FULL-HEIGHT UTILITIES ========== */

/* Utility class for full-viewport-height elements that work on iOS */
.h-screen-ios {
  height: 100dvh;
  height: -webkit-fill-available;
}

.min-h-screen-ios {
  min-height: 100dvh;
  min-height: -webkit-fill-available;
}

/* ========== FIXED ELEMENTS ========== */

/* Fixed elements need safe-area padding */
.fixed-bottom {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding-bottom: env(safe-area-inset-bottom);
}

.fixed-top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding-top: env(safe-area-inset-top);
}
