/* ==========================================================================
   Apple iOS Theme & Human Interface Guidelines (HIG) Design System
   Optimized specifically for iPhone (Notch, Dynamic Island, Safe Areas, Safari)
   ========================================================================== */

:root {
  /* iOS System Colors */
  --ios-blue: #007aff;
  --ios-blue-rgb: 0, 122, 255;
  --ios-green: #34c759;
  --ios-indigo: #5856d6;
  --ios-orange: #ff9500;
  --ios-pink: #ff2d55;
  --ios-purple: #af52de;
  --ios-red: #ff3b30;
  --ios-teal: #5ac8fa;
  --ios-yellow: #ffcc00;

  /* Construction Theme Primary Accents */
  --primary: #f59e0b; /* Safety Amber / Construction Gold */
  --primary-dark: #d97706;
  --primary-light: #fef3c7;
  --primary-rgb: 245, 158, 11;

  /* iOS System Grays & Backgrounds */
  --bg-primary: #0b0f19;
  --bg-secondary: #111827;
  --bg-tertiary: #1f2937;
  --bg-card: rgba(26, 34, 52, 0.85);
  --bg-card-hover: rgba(36, 48, 74, 0.95);
  --bg-glass: rgba(17, 24, 39, 0.78);
  --bg-sheet: #151d2e;

  /* Borders & Dividers */
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-light: rgba(255, 255, 255, 0.15);
  --border-focus: var(--primary);

  /* Typography */
  --text-primary: #f9fafb;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --text-inverse: #0b0f19;

  /* Apple System Fonts */
  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Shadows & Glassmorphism */
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 12px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 28px -4px rgba(0, 0, 0, 0.6);
  --backdrop-blur: blur(24px) saturate(190%);

  /* Border Radii */
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-xl: 28px;
  --radius-full: 9999px;

  /* iPhone Safe Areas */
  --sat: env(safe-area-inset-top, 20px);
  --sab: env(safe-area-inset-bottom, 20px);
  --sal: env(safe-area-inset-left, 0px);
  --sar: env(safe-area-inset-right, 0px);

  /* Header & Navigation Bar Heights */
  --nav-top-height: 56px;
  --nav-bottom-height: 64px;
  --z-nav: 100;
  --z-modal: 500;
  --z-toast: 1000;
}

/* Light Mode Overrides if device prefers light, but construction apps benefit from crisp dark slate */
@media (prefers-color-scheme: light) {
  :root.allow-light {
    --bg-primary: #f2f4f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #e5e7eb;
    --bg-card: rgba(255, 255, 255, 0.9);
    --bg-glass: rgba(255, 255, 255, 0.85);
    --bg-sheet: #ffffff;
    --border-subtle: rgba(0, 0, 0, 0.08);
    --border-light: rgba(0, 0, 0, 0.15);
    --text-primary: #111827;
    --text-secondary: #4b5563;
    --text-muted: #9ca3af;
  }
}

/* Reset & iOS Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  font-family: var(--font-family);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  user-select: none;
  -webkit-user-select: none;
}

input, textarea, select {
  user-select: auto;
  -webkit-user-select: auto;
  font-family: inherit;
}

/* App Viewport Container */
#app {
  display: flex;
  flex-direction: column;
  width: 100vw;
  height: 100vh;
  height: 100dvh; /* Dynamic viewport height for iOS */
  overflow: hidden;
  position: relative;
  background-color: var(--bg-primary);
}

/* iOS Top Bar / Header */
.ios-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: var(--z-nav);
  background: var(--bg-glass);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border-bottom: 0.5px solid var(--border-subtle);
  padding-top: var(--sat);
  padding-left: max(16px, var(--sal));
  padding-right: max(16px, var(--sar));
}

.ios-header-content {
  height: var(--nav-top-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ios-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ios-brand-badge {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, #f59e0b, #d97706);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: #0b0f19;
  box-shadow: 0 2px 8px rgba(245, 158, 11, 0.4);
}

.ios-header-title-wrap {
  display: flex;
  flex-direction: column;
}

.ios-header-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
  line-height: 1.2;
}

.ios-header-subtitle {
  font-size: 11px;
  font-weight: 500;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.6px;
}

.ios-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ios-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.08);
  border: 0.5px solid var(--border-subtle);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.ios-icon-btn:active {
  transform: scale(0.92);
  background: rgba(255, 255, 255, 0.18);
}

.ios-icon-btn.primary {
  background: var(--primary);
  color: #0b0f19;
  font-weight: 700;
  border: none;
  box-shadow: 0 2px 10px rgba(245, 158, 11, 0.35);
}

/* Site Selector in Header */
.site-selector-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: var(--radius-full);
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.3);
  color: var(--primary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.site-selector-pill:active {
  background: rgba(245, 158, 11, 0.25);
}

/* Main Scrollable Content Area */
.ios-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding-top: calc(var(--sat) + var(--nav-top-height) + 12px);
  padding-bottom: calc(var(--sab) + var(--nav-bottom-height) + 24px);
  padding-left: max(16px, var(--sal));
  padding-right: max(16px, var(--sar));
}

/* Content Views */
.app-view {
  display: none;
  animation: iosFadeIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

.app-view.active {
  display: block;
}

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

/* iOS Bottom Tab Bar */
.ios-tab-bar {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: var(--z-nav);
  background: var(--bg-glass);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border-top: 0.5px solid var(--border-subtle);
  padding-bottom: var(--sab);
  padding-left: var(--sal);
  padding-right: var(--sar);
  height: calc(var(--nav-bottom-height) + var(--sab));
  display: flex;
  align-items: stretch;
  justify-content: space-around;
}

.ios-tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 0;
  transition: all 0.2s ease;
  position: relative;
}

.ios-tab-item:active {
  transform: scale(0.92);
}

.ios-tab-icon {
  font-size: 22px;
  line-height: 1;
  position: relative;
}

.ios-tab-label {
  font-size: 10px;
  font-weight: 500;
  letter-spacing: -0.1px;
}

.ios-tab-item.active {
  color: var(--primary);
}

.ios-tab-item.active .ios-tab-icon {
  transform: scale(1.08);
}

.ios-tab-item.active .ios-tab-label {
  font-weight: 700;
}

.ios-tab-badge {
  position: absolute;
  top: -2px;
  right: -8px;
  background: var(--ios-red);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 16px;
  text-align: center;
}

/* iOS Card Component */
.ios-card {
  background: var(--bg-card);
  backdrop-filter: var(--backdrop-blur);
  -webkit-backdrop-filter: var(--backdrop-blur);
  border-radius: var(--radius-lg);
  border: 0.5px solid var(--border-subtle);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, background 0.15s ease;
}

.ios-card.clickable:active {
  transform: scale(0.985);
  background: var(--bg-card-hover);
}

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

.ios-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.ios-card-action {
  font-size: 13px;
  color: var(--primary);
  font-weight: 600;
  cursor: pointer;
}

/* Summary Metric Cards (Quick Glance) */
.ios-stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.ios-stat-card {
  background: var(--bg-card);
  border-radius: var(--radius-md);
  border: 0.5px solid var(--border-subtle);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ios-stat-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}

.ios-stat-value {
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
}

.ios-stat-sub {
  font-size: 11px;
  color: var(--text-muted);
}

/* Segmented Control (iOS standard pill switch) */
.ios-segmented-control {
  display: flex;
  background: rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  padding: 3px;
  margin-bottom: 14px;
  border: 0.5px solid var(--border-subtle);
}

.ios-segment-btn {
  flex: 1;
  padding: 8px 12px;
  text-align: center;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border: none;
  background: transparent;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

.ios-segment-btn.active {
  background: var(--bg-sheet);
  color: var(--text-primary);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

/* iOS Bottom Sheet Modal */
.ios-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: var(--z-modal);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.ios-modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.ios-modal-sheet {
  background: var(--bg-sheet);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  border-top: 0.5px solid var(--border-light);
  width: 100%;
  max-height: 90vh;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  padding-bottom: var(--sab);
}

.ios-modal-overlay.active .ios-modal-sheet {
  transform: translateY(0);
}

.ios-modal-handle {
  width: 40px;
  height: 5px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.25);
  margin: 10px auto 4px auto;
}

.ios-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  border-bottom: 0.5px solid var(--border-subtle);
}

.ios-modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}

.ios-modal-close {
  background: rgba(255, 255, 255, 0.1);
  border: none;
  border-radius: var(--radius-full);
  width: 30px;
  height: 30px;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.ios-modal-body {
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* iOS Forms & Inputs */
.ios-form-group {
  margin-bottom: 16px;
}

.ios-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.ios-input, .ios-select, .ios-textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 16px; /* Prevents auto zoom in iOS Safari */
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.ios-input:focus, .ios-select:focus, .ios-textarea:focus {
  border-color: var(--primary);
  background: rgba(255, 255, 255, 0.1);
}

.ios-btn {
  width: 100%;
  padding: 14px 18px;
  border-radius: var(--radius-md);
  font-size: 16px;
  font-weight: 700;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s ease, opacity 0.15s ease;
}

.ios-btn:active {
  transform: scale(0.97);
  opacity: 0.9;
}

.ios-btn.primary {
  background: var(--primary);
  color: #0b0f19;
  box-shadow: 0 4px 14px rgba(245, 158, 11, 0.4);
}

.ios-btn.secondary {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
  border: 0.5px solid var(--border-subtle);
}

.ios-btn.danger {
  background: var(--ios-red);
  color: #ffffff;
}

.ios-btn.whatsapp {
  background: #25d366;
  color: #ffffff;
}

/* Toast Notifications */
.ios-toast {
  position: fixed;
  top: calc(var(--sat) + 60px);
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  background: rgba(20, 27, 45, 0.95);
  backdrop-filter: var(--backdrop-blur);
  border: 0.5px solid var(--border-light);
  border-radius: var(--radius-full);
  padding: 10px 20px;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  z-index: var(--z-toast);
  opacity: 0;
  pointer-events: none;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  gap: 8px;
}

.ios-toast.active {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}
