/* ===== iOS App Premium Aesthetic =====
   Modern, minimal, inspired by Things 3, Bear, Apple Notes
   Mobile PWA only - desktop stays unchanged
   ================================================= */

/* Safe areas for notch and home indicator */
:root {
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
  --safe-left: env(safe-area-inset-left);
  --safe-right: env(safe-area-inset-right);
  
  /* Premium mobile palette */
  --ios-bg: #0d0c0e;
  --ios-surface: rgba(22, 20, 26, 0.95);
  --ios-card: rgba(28, 25, 33, 0.85);
  --ios-card-hover: rgba(36, 32, 42, 0.9);
  --ios-gold: #c4956a;
  --ios-gold-soft: rgba(196, 149, 106, 0.15);
  --ios-gold-glow: rgba(196, 149, 106, 0.08);
  --ios-text: #f5f2ef;
  --ios-text-secondary: #a8a3b3;
  --ios-text-muted: #6b6578;
  --ios-border: rgba(255, 255, 255, 0.06);
  --ios-border-active: rgba(196, 149, 106, 0.3);
  --ios-shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.15);
  --ios-shadow-md: 0 4px 20px rgba(0, 0, 0, 0.25);
  --ios-shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.35);
  --ios-radius-sm: 12px;
  --ios-radius-md: 16px;
  --ios-radius-lg: 20px;
}

/* Standalone mode (installed as app) - base styles */
@media (display-mode: standalone) {
  body {
    -webkit-user-select: none;
    user-select: none;
  }
  
  /* Allow text selection only in inputs and text content */
  input, textarea, .note-content, .quote-text, .fact-text {
    -webkit-user-select: text;
    user-select: text;
  }
}

/* Prevent overscroll bounce on non-scrollable areas */
body {
  overscroll-behavior: none;
}

/* Allow bounce only on scrollable content */
.tasks-list,
.events-list,
.notes-list,
.home-dashboard {
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

/* Tap highlight - subtle gold tint */
* {
  -webkit-tap-highlight-color: rgba(196, 149, 106, 0.1);
}

/* ===== MOBILE PWA ONLY STYLES ===== */
/* Using (display-mode: standalone) + (pointer: coarse) for installed mobile PWA */
/* Using (pointer: coarse) + (max-width: 500px) for mobile browsers */

@media (display-mode: standalone) and (pointer: coarse) {
  body {
    padding-top: 0;
    padding-bottom: var(--safe-bottom);
    background: var(--ios-bg);
  }
  
  /* Mobile header needs safe area padding for Dynamic Island */
  .mobile-header {
    padding-top: var(--safe-top) !important;
    height: calc(60px + var(--safe-top)) !important;
  }
  
  /* Hide sidebar on mobile app */
  .sidebar {
    display: none;
  }
  
  .main-content {
    margin-left: 0;
    padding: 20px 16px;
    padding-top: calc(80px + var(--safe-top)) !important;
    padding-bottom: calc(90px + var(--safe-bottom));
  }
  
  /* Show tab bar on mobile app */
  .app-tab-bar {
    display: flex !important;
  }
}

/* Also apply to mobile browsers (not just standalone) */
@media (pointer: coarse) and (max-width: 500px) {
  .app-tab-bar {
    display: flex !important;
  }
  
  .sidebar {
    display: none;
  }
  
  .main-content {
    margin-left: 0 !important;
    padding: 20px 16px;
    padding-bottom: calc(90px + var(--safe-bottom, 20px));
  }
}

/* ===== BOTTOM TAB BAR - Premium Glassmorphism ===== */
.app-tab-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(72px + var(--safe-bottom, 0px));
  padding-bottom: var(--safe-bottom, 0px);
  background: rgba(18, 16, 22, 0.75);
  backdrop-filter: saturate(180%) blur(24px);
  -webkit-backdrop-filter: saturate(180%) blur(24px);
  border-top: 0.5px solid rgba(255, 255, 255, 0.08);
  z-index: 1000;
  /* Subtle top shadow for depth */
  box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.2);
}

.app-tab-bar-inner {
  display: flex;
  justify-content: space-around;
  align-items: center;
  height: 72px;
  max-width: 420px;
  margin: 0 auto;
  padding: 0 8px;
}

.app-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 14px;
  min-width: 60px;
  color: var(--ios-text-muted);
  text-decoration: none;
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.02em;
  gap: 5px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 14px;
  position: relative;
}

.app-tab.active {
  color: var(--ios-gold);
}

/* Active indicator dot */
.app-tab.active::after {
  content: '';
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 4px;
  height: 4px;
  background: var(--ios-gold);
  border-radius: 50%;
  opacity: 0.9;
}

/* Tab icon styling */
.app-tab-icon {
  font-size: 1.35rem;
  line-height: 1;
  transition: transform 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  /* Use tabular nums for consistent icon sizing */
  font-feature-settings: "tnum";
}

/* Premium touch states */
.app-tab:active {
  transform: scale(0.92);
  background: rgba(196, 149, 106, 0.08);
}

.app-tab:active .app-tab-icon {
  transform: scale(0.95);
}

/* ===== HOME DASHBOARD - Mobile Optimizations ===== */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px),
       (max-width: 430px) {
  
  /* Dashboard container */
  .home-dashboard {
    padding: 16px !important;
    padding-bottom: calc(100px + var(--safe-bottom, 20px)) !important;
  }
  
  /* Header section */
  .home-header {
    flex-direction: column;
    align-items: flex-start !important;
    text-align: left !important;
    gap: 12px !important;
    margin-bottom: 24px !important;
  }
  
  .home-header-left {
    width: 100%;
  }
  
  .home-header-right {
    position: absolute;
    top: 16px;
    right: 16px;
  }
  
  .home-greeting {
    font-size: 1.75rem !important;
    line-height: 1.1 !important;
    margin-bottom: 4px !important;
  }
  
  .home-date {
    font-size: 0.75rem !important;
    opacity: 0.7;
  }
  
  /* Analog clock - smaller on mobile */
  .home-analog-clock {
    width: 52px !important;
    height: 52px !important;
  }
  
  /* Quick thought input */
  .quick-thought {
    margin-top: 14px !important;
  }
  
  .quick-thought-input {
    max-width: 100% !important;
    padding: 14px 16px !important;
    font-size: 16px !important; /* Prevents iOS zoom */
    border-radius: var(--ios-radius-md) !important;
    background: rgba(255, 255, 255, 0.04) !important;
    border: 1px solid var(--ios-border) !important;
  }
  
  .quick-thought-input:focus {
    border-color: var(--ios-gold) !important;
    box-shadow: 0 0 0 3px var(--ios-gold-glow) !important;
  }
  
  /* ===== CARDS - Premium Mobile Style ===== */
  .home-row {
    gap: 14px !important;
    margin-bottom: 18px !important;
  }
  
  /* Info cards row - grid layout, fits page width */
  .home-row-3 {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 12px !important;
  }
  
  /* Quote card full width */
  .quote-card {
    grid-column: span 2 !important;
    min-height: 100px !important;
  }
  
  /* Word and Fact side by side, equal width */
  .word-card, .fact-card {
    min-height: 140px !important;
  }
  
  /* Functional cards row - horizontal swipe carousel */
  .home-row-functional {
    display: flex !important;
    overflow-x: auto !important;
    scroll-snap-type: x mandatory !important;
    gap: 12px !important;
    padding-bottom: 8px !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
  }
  
  .home-row-functional::-webkit-scrollbar {
    display: none !important;
  }
  
  /* Row 4 - also horizontal swipe carousel */
  .home-row-4 {
    display: flex !important;
    overflow-x: auto !important;
    scroll-snap-type: x mandatory !important;
    gap: 12px !important;
    padding-bottom: 8px !important;
    -webkit-overflow-scrolling: touch !important;
    scrollbar-width: none !important;
  }
  
  .home-row-4::-webkit-scrollbar {
    display: none !important;
  }
  
  .home-row-4 .home-card {
    flex: 0 0 75% !important;
    scroll-snap-align: center !important;
    min-height: 160px !important;
  }
  
  /* Tasks/Events/Next-up in swipe carousel */
  .tasks-card,
  .events-card,
  .time-awareness-card {
    flex: 0 0 85% !important;
    scroll-snap-align: center !important;
    min-height: 180px !important;
    padding: 16px !important;
  }
  
  /* Normal text sizes for carousel cards */
  .tasks-card .home-card-title,
  .events-card .home-card-title,
  .time-awareness-card .home-card-title {
    font-size: 0.7rem !important;
    margin-bottom: 12px !important;
  }
  
  .task-item, .event-item {
    font-size: 0.85rem !important;
    padding: 6px 0 !important;
  }
  
  .add-task-input {
    font-size: 0.9rem !important;
    padding: 10px 12px !important;
  }
  
  .next-event-countdown {
    font-size: 1.5rem !important;
  }
  
  .next-event-title {
    font-size: 0.9rem !important;
  }
  
  /* Weather and other cards */
  .weather-card,
  .progress-card,
  .habits-card,
  .focus-card {
    min-height: 120px !important;
  }
  
  .home-card {
    background: var(--ios-card) !important;
    border: 1px solid var(--ios-border) !important;
    border-radius: var(--ios-radius-lg) !important;
    padding: 18px !important;
    min-height: auto !important;
    box-shadow: var(--ios-shadow-sm) !important;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
    backdrop-filter: blur(12px) !important;
    -webkit-backdrop-filter: blur(12px) !important;
  }
  
  .home-card:active {
    transform: scale(0.98) !important;
    background: var(--ios-card-hover) !important;
    border-color: var(--ios-border-active) !important;
  }
  
  /* Card titles - refined typography */
  .home-card-title {
    font-size: 0.7rem !important;
    font-weight: 600 !important;
    letter-spacing: 0.08em !important;
    text-transform: uppercase !important;
    color: var(--ios-text-secondary) !important;
    margin-bottom: 14px !important;
    padding-bottom: 10px !important;
    border-bottom: 1px solid var(--ios-border) !important;
    display: flex !important;
    align-items: center !important;
    gap: 8px !important;
  }
  
  .home-card-title .icon {
    font-size: 1rem !important;
    opacity: 0.85;
  }
  
  .home-card-title .card-icon {
    width: 16px !important;
    height: 16px !important;
    color: #c4956a !important;
    flex-shrink: 0 !important;
  }
  
  /* ===== QUOTE CARD ===== */
  .quote-card .quote-text {
    font-size: 1rem !important;
    line-height: 1.55 !important;
    color: var(--ios-text) !important;
    min-height: auto !important;
  }
  
  .quote-card .quote-author {
    font-size: 0.72rem !important;
    color: var(--ios-text-muted) !important;
    margin-top: 10px !important;
  }
  
  /* ===== SWEDISH WORD CARD ===== */
  .word-card .word-swedish {
    font-size: 1.4rem !important;
    margin-bottom: 6px !important;
  }
  
  .word-card .word-english {
    font-size: 0.88rem !important;
    color: var(--ios-text-secondary) !important;
  }
  
  .word-tts-btn {
    font-size: 0.9rem !important;
    padding: 6px !important;
    background: var(--ios-gold-soft) !important;
    border-radius: 8px !important;
    transition: all 0.2s !important;
  }
  
  .word-tts-btn:active {
    transform: scale(0.9) !important;
    background: var(--ios-gold) !important;
  }
  
  /* ===== TASKS & EVENTS LISTS ===== */
  .tasks-list,
  .events-list {
    max-height: 200px !important;
  }
  
  .task-item,
  .event-item {
    padding: 14px 4px !important;
    min-height: 52px !important;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04) !important;
    transition: background 0.15s !important;
  }
  
  .task-item:active,
  .event-item:active {
    background: rgba(196, 149, 106, 0.08) !important;
  }
  
  .task-item input[type="checkbox"] {
    width: 22px !important;
    height: 22px !important;
    border-radius: 6px !important;
    accent-color: var(--ios-gold) !important;
  }
  
  .task-text,
  .event-title {
    font-size: 0.92rem !important;
    line-height: 1.4 !important;
  }
  
  .event-time {
    font-size: 0.72rem !important;
    font-weight: 600 !important;
    color: var(--ios-gold) !important;
    min-width: 52px !important;
  }
  
  /* Add task/focus inputs */
  .add-task-input,
  .focus-input {
    padding: 14px 16px !important;
    font-size: 16px !important; /* Prevents iOS zoom */
    border-radius: var(--ios-radius-sm) !important;
    background: rgba(255, 255, 255, 0.03) !important;
    border: 1px solid var(--ios-border) !important;
    margin-top: 12px !important;
  }
  
  .add-task-input:focus,
  .focus-input:focus {
    border-color: var(--ios-gold) !important;
    box-shadow: 0 0 0 3px var(--ios-gold-glow) !important;
    background: rgba(255, 255, 255, 0.05) !important;
  }
  
  /* ===== WEATHER CARD ===== */
  .weather-card {
    min-height: auto !important;
  }
  
  .weather-dual {
    gap: 20px !important;
  }
  
  .weather-icon {
    font-size: 2rem !important;
  }
  
  .weather-temp {
    font-size: 1.5rem !important;
  }
  
  .weather-toggle {
    margin-bottom: 14px !important;
  }
  
  .weather-location-btn {
    padding: 6px 14px !important;
    font-size: 0.68rem !important;
    border-radius: 10px !important;
    transition: all 0.2s !important;
  }
  
  .weather-location-btn.active {
    background: var(--ios-gold-soft) !important;
    color: var(--ios-gold) !important;
  }
  
  /* ===== HABITS CARD ===== */
  .habits-list {
    gap: 8px !important;
  }
  
  .habit-item {
    padding: 12px 14px !important;
    border-radius: var(--ios-radius-sm) !important;
    background: rgba(255, 255, 255, 0.03) !important;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }
  
  .habit-item:active {
    transform: scale(0.98) !important;
    background: rgba(196, 149, 106, 0.1) !important;
  }
  
  .habit-item.done {
    background: var(--ios-gold-soft) !important;
  }
  
  .habit-icon {
    font-size: 1.1rem !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
  }
  
  .habit-icon svg {
    width: 20px !important;
    height: 20px !important;
    color: #c4956a !important;
  }
  
  .habit-name {
    font-size: 0.88rem !important;
  }
  
  .habit-check {
    color: var(--ios-gold) !important;
    font-size: 1rem !important;
    font-weight: 600 !important;
  }
  
  /* ===== PROGRESS RINGS ===== */
  .progress-rings {
    padding: 12px 0 !important;
  }
  
  .progress-ring svg {
    width: 56px !important;
    height: 56px !important;
  }
  
  .progress-ring-value {
    font-size: 1.1rem !important;
  }
  
  .progress-ring-text {
    font-size: 0.58rem !important;
  }
  
  /* ===== FOCUS CARD ===== */
  .focus-list {
    max-height: 140px !important;
    gap: 8px !important;
  }
  
  .focus-item {
    padding: 10px 12px !important;
    border-radius: 10px !important;
    background: var(--ios-gold-soft) !important;
  }
  
  .focus-text {
    font-size: 0.88rem !important;
  }
  
  .focus-delete {
    font-size: 1.1rem !important;
    padding: 4px 8px !important;
  }
  
  /* ===== QUICK ACCESS / SPACES GRID ===== */
  .home-quick-access {
    margin-top: 24px !important;
    padding-top: 20px !important;
    border-top: 1px solid var(--ios-border) !important;
  }
  
  .quick-access-title {
    font-size: 0.95rem !important;
    margin-bottom: 16px !important;
  }
  
  /* Spaces - modern minimalist grid */
  .spaces-grid {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 16px !important;
    padding: 8px 0 !important;
  }
  
  .space-shortcut {
    padding: 20px 12px !important;
    border-radius: 20px !important;
    border: none !important;
    background: rgba(255, 255, 255, 0.03) !important;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1) !important;
  }
  
  .space-shortcut:active {
    transform: scale(0.92) !important;
    background: rgba(255, 255, 255, 0.08) !important;
  }
  
  /* SVG icon styling */
  .space-icon {
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    margin-bottom: 4px !important;
  }
  
  .space-icon svg {
    width: 32px !important;
    height: 32px !important;
    color: var(--ios-gold) !important;
  }
  
  .space-name {
    font-size: 0.72rem !important;
    font-weight: 500 !important;
    margin-top: 10px !important;
    color: var(--ios-text-secondary) !important;
    letter-spacing: 0.02em !important;
  }
  
  /* ===== EMPTY STATES ===== */
  .empty-state {
    padding: 24px 16px !important;
    font-size: 0.88rem !important;
    color: var(--ios-text-muted) !important;
  }
}

/* ===== MICRO-ANIMATIONS ===== */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px) {
  
  /* Page transitions */
  .home-dashboard,
  .space-content {
    animation: iosFadeIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  @keyframes iosFadeIn {
    from {
      opacity: 0;
      transform: translateY(6px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }
  
  /* Staggered card entrance */
  .home-row .home-card {
    animation: iosCardIn 0.35s cubic-bezier(0.4, 0, 0.2, 1) backwards;
  }
  
  .home-row .home-card:nth-child(1) { animation-delay: 0.05s; }
  .home-row .home-card:nth-child(2) { animation-delay: 0.1s; }
  .home-row .home-card:nth-child(3) { animation-delay: 0.15s; }
  .home-row .home-card:nth-child(4) { animation-delay: 0.2s; }
  
  @keyframes iosCardIn {
    from {
      opacity: 0;
      transform: translateY(12px) scale(0.98);
    }
    to {
      opacity: 1;
      transform: translateY(0) scale(1);
    }
  }
  
  /* Button/interactive press feedback */
  button:active,
  .nav-item:active,
  [role="button"]:active {
    transform: scale(0.96);
    transition: transform 0.1s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  /* Checkbox animation */
  input[type="checkbox"] {
    transition: transform 0.15s cubic-bezier(0.4, 0, 0.2, 1);
  }
  
  input[type="checkbox"]:active {
    transform: scale(0.9);
  }
}

/* ===== SCROLLBAR - Hidden on Mobile ===== */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px) {
  
  /* Hide scrollbars for cleaner mobile look */
  .tasks-list::-webkit-scrollbar,
  .events-list::-webkit-scrollbar,
  .focus-list::-webkit-scrollbar,
  .habits-list::-webkit-scrollbar {
    display: none;
  }
  
  .tasks-list,
  .events-list,
  .focus-list,
  .habits-list {
    scrollbar-width: none;
    -ms-overflow-style: none;
  }
}

/* ===== PULL TO REFRESH ===== */
.pull-indicator {
  position: fixed;
  top: var(--safe-top, 0);
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 20px;
  background: var(--ios-card);
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--ios-text-muted);
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 100;
  box-shadow: var(--ios-shadow-md);
  border: 1px solid var(--ios-border);
}

.pull-indicator.visible {
  opacity: 1;
}

/* ===== STATUS BAR SPACER ===== */
@media (display-mode: standalone) {
  .status-bar-spacer {
    height: var(--safe-top);
    background: var(--ios-bg);
  }
}

/* ===== MOBILE SIDEBAR (When opened) ===== */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px) {
  
  .sidebar {
    position: fixed !important;
    z-index: 1001 !important;
    transform: translateX(-100%) !important;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    width: 85% !important;
    max-width: 320px !important;
    background: var(--ios-surface) !important;
    border-right: 1px solid var(--ios-border) !important;
    box-shadow: var(--ios-shadow-lg) !important;
  }
  
  body.sidebar-open .sidebar {
    display: block !important;
    transform: translateX(0) !important;
  }
  
  .sidebar-overlay {
    background: rgba(0, 0, 0, 0.5) !important;
    backdrop-filter: blur(4px) !important;
    -webkit-backdrop-filter: blur(4px) !important;
  }
}

/* ===== TYPOGRAPHY REFINEMENTS ===== */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px) {
  
  /* Ensure all text is readable on mobile */
  body {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
  }
  
  /* Headings */
  h1 { font-size: 1.5rem !important; line-height: 1.2 !important; }
  h2 { font-size: 1.25rem !important; line-height: 1.25 !important; }
  h3 { font-size: 1.1rem !important; line-height: 1.3 !important; }
  
  /* Body text */
  p, li, span {
    line-height: 1.5 !important;
  }
  
  /* Form inputs - prevent zoom on iOS */
  input, textarea, select {
    font-size: 16px !important;
  }
}

/* ===== LOADING STATES ===== */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px) {
  
  .home-card.loading {
    background: linear-gradient(
      90deg,
      var(--ios-card) 0%,
      rgba(40, 36, 46, 0.9) 50%,
      var(--ios-card) 100%
    ) !important;
    background-size: 200% 100% !important;
    animation: iosShimmer 1.5s infinite !important;
  }
  
  @keyframes iosShimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
  }
}

/* ===== HAPTIC-FEEL INTERACTIONS ===== */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px) {
  
  /* Ripple-free press states */
  .home-card,
  .habit-item,
  .space-shortcut,
  .app-tab {
    will-change: transform;
  }
  
  /* Smooth spring-back */
  .home-card:not(:active),
  .habit-item:not(:active),
  .space-shortcut:not(:active),
  .app-tab:not(:active) {
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
                background 0.2s ease,
                border-color 0.2s ease;
  }
}

/* ===== LANDSCAPE ORIENTATION ===== */
@media (display-mode: standalone) and (pointer: coarse) and (orientation: landscape) {
  .home-row-3 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  .home-row-4 {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  
  .app-tab-bar {
    height: calc(60px + var(--safe-bottom, 0px)) !important;
  }
  
  .app-tab-bar-inner {
    height: 60px !important;
  }
}

/* ===== CALENDAR PAGE - Mobile Optimizations ===== */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px),
       (max-width: 430px) {
  
  .cal-space {
    padding: 16px !important;
    padding-bottom: calc(100px + var(--safe-bottom, 20px)) !important;
  }
  
  /* Calendar header */
  .cal-header {
    flex-direction: column !important;
    gap: 12px !important;
    margin-bottom: 16px !important;
  }
  
  .cal-nav {
    width: 100% !important;
    justify-content: space-between !important;
  }
  
  .cal-nav-title {
    font-size: 1.25rem !important;
    color: var(--ios-gold) !important;
  }
  
  .cal-view-btns {
    width: 100% !important;
    display: flex !important;
    gap: 6px !important;
  }
  
  .cal-view-btn {
    flex: 1 !important;
    padding: 10px 8px !important;
    font-size: 0.75rem !important;
    border-radius: 10px !important;
    background: rgba(255, 255, 255, 0.03) !important;
    border: 1px solid var(--ios-border) !important;
    color: var(--ios-text-secondary) !important;
  }
  
  .cal-view-btn.active {
    background: rgba(196, 149, 106, 0.15) !important;
    border-color: var(--ios-gold) !important;
    color: var(--ios-gold) !important;
  }
  
  /* Month view calendar grid */
  .cal-grid {
    border-radius: 16px !important;
    overflow: hidden !important;
    background: var(--ios-card) !important;
    border: 1px solid var(--ios-border) !important;
  }
  
  .cal-day {
    min-height: 44px !important;
    font-size: 0.85rem !important;
    border-color: var(--ios-border) !important;
  }
  
  .cal-day.today {
    background: rgba(196, 149, 106, 0.15) !important;
    color: var(--ios-gold) !important;
    font-weight: 600 !important;
  }
  
  .cal-day.other-month {
    color: var(--ios-text-muted) !important;
  }
  
  /* Day planner view */
  .cal-planner {
    background: var(--ios-card) !important;
    border-radius: 16px !important;
    padding: 16px !important;
    border: 1px solid var(--ios-border) !important;
  }
  
  .cal-planner-item {
    padding: 12px !important;
    margin-bottom: 10px !important;
    background: rgba(255, 255, 255, 0.03) !important;
    border-radius: 12px !important;
    border: 1px solid var(--ios-border) !important;
  }
  
  .cal-planner-item.google {
    background: rgba(66, 133, 244, 0.05) !important;
  }
  
  .cal-planner-title {
    font-size: 0.9rem !important;
    font-weight: 500 !important;
  }
  
  .cal-planner-time {
    font-size: 0.75rem !important;
    color: var(--ios-gold) !important;
  }
  
  .cal-planner-empty-illustration {
    font-size: 2.5rem !important;
  }
}

/* ===== JOURNAL PAGE - Mobile Optimizations ===== */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px),
       (max-width: 430px) {
  
  .journal-space {
    padding: 16px !important;
    padding-bottom: calc(100px + var(--safe-bottom, 20px)) !important;
  }
  
  /* Journal tabs */
  .journal-tabs {
    display: flex !important;
    gap: 6px !important;
    overflow-x: auto !important;
    padding-bottom: 8px !important;
    margin-bottom: 16px !important;
    scrollbar-width: none !important;
  }
  
  .journal-tabs::-webkit-scrollbar {
    display: none !important;
  }
  
  .journal-tab {
    flex: 0 0 auto !important;
    padding: 10px 16px !important;
    font-size: 0.75rem !important;
    border-radius: 20px !important;
    background: rgba(255, 255, 255, 0.03) !important;
    border: 1px solid var(--ios-border) !important;
    color: var(--ios-text-secondary) !important;
    white-space: nowrap !important;
  }
  
  .journal-tab.active {
    background: rgba(196, 149, 106, 0.15) !important;
    border-color: var(--ios-gold) !important;
    color: var(--ios-gold) !important;
  }
  
  /* Journal type cards */
  .journal-types-list {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  
  .journal-type-card {
    background: var(--ios-card) !important;
    border-radius: 16px !important;
    padding: 16px !important;
    border: 1px solid var(--ios-border) !important;
    border-left: 3px solid #b4a0c4 !important;
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
  }
  
  .journal-type-icon {
    font-size: 1.5rem !important;
  }
  
  .journal-type-name {
    font-size: 0.95rem !important;
    font-weight: 500 !important;
  }
  
  .journal-type-desc {
    font-size: 0.75rem !important;
    color: var(--ios-text-muted) !important;
  }
  
  .journal-type-badge {
    margin-left: auto !important;
    font-size: 0.7rem !important;
    padding: 4px 10px !important;
    border-radius: 12px !important;
    background: rgba(196, 149, 106, 0.15) !important;
    color: var(--ios-gold) !important;
  }
  
  .journal-type-badge.empty {
    background: rgba(255, 255, 255, 0.03) !important;
    color: var(--ios-text-muted) !important;
  }
  
  /* Journal entry card */
  .journal-card {
    background: var(--ios-card) !important;
    border-radius: 16px !important;
    padding: 20px !important;
    border: 1px solid var(--ios-border) !important;
    border-left: 3px solid #b4a0c4 !important;
  }
  
  .journal-card-title {
    font-size: 1rem !important;
    color: var(--ios-gold) !important;
    margin-bottom: 16px !important;
  }
  
  .journal-input {
    background: rgba(255, 255, 255, 0.03) !important;
    border: 1px solid var(--ios-border) !important;
    border-radius: 12px !important;
    padding: 14px !important;
    font-size: 16px !important;
    color: var(--ios-text) !important;
    width: 100% !important;
  }
  
  .journal-input:focus {
    border-color: var(--ios-gold) !important;
    outline: none !important;
  }
  
  /* Mood and energy buttons */
  .journal-mood-btn,
  .journal-energy-btn {
    width: 36px !important;
    height: 36px !important;
    border-radius: 50% !important;
    background: rgba(255, 255, 255, 0.03) !important;
    border: 1px solid var(--ios-border) !important;
  }
  
  .journal-mood-btn.active,
  .journal-energy-btn.active {
    background: rgba(196, 149, 106, 0.2) !important;
    border-color: var(--ios-gold) !important;
  }
}

/* ===== NOTES PAGE - Mobile Optimizations ===== */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px),
       (max-width: 430px) {
  
  .notes-list {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 12px !important;
    padding: 16px !important;
    padding-bottom: calc(100px + var(--safe-bottom, 20px)) !important;
  }
  
  .note-card {
    background: var(--ios-card) !important;
    border-radius: 16px !important;
    padding: 16px !important;
    border: 1px solid var(--ios-border) !important;
    border-left: 3px solid #9ab4a0 !important;
  }
  
  .note-card:active {
    transform: scale(0.98) !important;
    background: var(--ios-card-hover) !important;
  }
  
  .note-card-title {
    font-size: 0.95rem !important;
    font-weight: 500 !important;
    color: var(--ios-text) !important;
    margin-bottom: 8px !important;
  }
  
  .note-card-preview {
    font-size: 0.8rem !important;
    color: var(--ios-text-muted) !important;
    line-height: 1.4 !important;
  }
  
  .note-card-date {
    font-size: 0.7rem !important;
    color: var(--ios-text-muted) !important;
    margin-top: 10px !important;
  }
  
  /* Note editor */
  .note-editor {
    background: var(--ios-bg) !important;
    padding: 16px !important;
  }
  
  .note-editor-title {
    font-size: 1.25rem !important;
    font-weight: 500 !important;
    background: transparent !important;
    border: none !important;
    color: var(--ios-gold) !important;
    margin-bottom: 16px !important;
    width: 100% !important;
  }
  
  .note-editor-content {
    background: var(--ios-card) !important;
    border: 1px solid var(--ios-border) !important;
    border-radius: 12px !important;
    padding: 16px !important;
    font-size: 16px !important;
    min-height: 300px !important;
  }
  
  /* Add note button */
  .add-note-btn {
    position: fixed !important;
    bottom: calc(90px + var(--safe-bottom, 20px)) !important;
    right: 20px !important;
    width: 56px !important;
    height: 56px !important;
    border-radius: 50% !important;
    background: var(--ios-gold) !important;
    color: #1a1a1a !important;
    font-size: 1.5rem !important;
    box-shadow: 0 4px 20px rgba(196, 149, 106, 0.4) !important;
    border: none !important;
    z-index: 100 !important;
  }
}

/* ===== SPACES PAGES - Generic Styling ===== */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px),
       (max-width: 430px) {
  
  /* Space header */
  .space-header {
    padding: 16px !important;
    margin-bottom: 8px !important;
  }
  
  .space-title {
    font-size: 1.5rem !important;
    color: var(--ios-gold) !important;
    font-weight: 500 !important;
  }
  
  /* Task lists in spaces */
  .task-list {
    padding: 0 16px !important;
  }
  
  .task-item {
    background: var(--ios-card) !important;
    border-radius: 12px !important;
    padding: 14px !important;
    margin-bottom: 8px !important;
    border: 1px solid var(--ios-border) !important;
  }
  
  .task-item.done {
    opacity: 0.6 !important;
    background: rgba(154, 180, 160, 0.05) !important;
  }
  
  .task-checkbox {
    width: 22px !important;
    height: 22px !important;
    border-radius: 50% !important;
    border: 2px solid var(--ios-gold) !important;
  }
  
  .task-checkbox:checked {
    background: var(--ios-gold) !important;
  }
}

/* ===== WORKOUT PAGE - Mobile Optimizations ===== */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px),
       (max-width: 430px) {
  
  .workout-space,
  .wo-space {
    padding: 16px !important;
    padding-bottom: calc(100px + var(--safe-bottom, 20px)) !important;
  }
  
  /* Weekly schedule cards */
  .wo-week-card,
  .workout-day-card {
    background: var(--ios-card) !important;
    border-radius: 16px !important;
    padding: 16px !important;
    margin-bottom: 10px !important;
    border: 1px solid var(--ios-border) !important;
    border-left: 3px solid #c4a0a8 !important;
  }
  
  .wo-week-card.completed,
  .workout-day-card.completed {
    border-left-color: #9ab4a0 !important;
    opacity: 0.8 !important;
  }
  
  .wo-week-card.today,
  .workout-day-card.today {
    border-left-color: var(--ios-gold) !important;
    background: rgba(196, 149, 106, 0.08) !important;
  }
  
  /* Day labels */
  .wo-day-label {
    color: var(--ios-gold) !important;
    font-weight: 600 !important;
    font-size: 0.85rem !important;
  }
  
  /* Workout title */
  .wo-workout-title {
    font-size: 0.95rem !important;
    font-weight: 500 !important;
    color: var(--ios-text) !important;
  }
  
  /* Type badges */
  .wo-type-badge {
    font-size: 0.65rem !important;
    padding: 4px 10px !important;
    border-radius: 12px !important;
    background: rgba(255, 255, 255, 0.06) !important;
    color: var(--ios-text-secondary) !important;
    text-transform: uppercase !important;
    letter-spacing: 0.05em !important;
  }
  
  /* Duration */
  .wo-duration {
    font-size: 0.8rem !important;
    color: var(--ios-text-muted) !important;
  }
  
  /* Checkbox */
  .wo-checkbox {
    width: 24px !important;
    height: 24px !important;
    border-radius: 6px !important;
    border: 2px solid var(--ios-border) !important;
    background: transparent !important;
  }
  
  .wo-checkbox:checked,
  .wo-checkbox.checked {
    background: #9ab4a0 !important;
    border-color: #9ab4a0 !important;
  }
}

/* ===== LOADING BAR - Always Gold ===== */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px),
       (max-width: 430px) {
  
  .loading-bar::after {
    background: linear-gradient(90deg, transparent, var(--ios-gold), #c4a0a8, transparent) !important;
  }
  
  /* Workout tabs - ensure visible and gold */
  .wo-tab-bar {
    display: flex !important;
    gap: 8px !important;
    overflow-x: auto !important;
    padding: 0 16px 8px !important;
    margin-bottom: 12px !important;
    border-bottom: 1px solid var(--ios-border) !important;
  }
  
  .wo-tab {
    flex: 0 0 auto !important;
    padding: 8px 14px !important;
    font-size: 0.8rem !important;
    border-radius: 16px !important;
    background: rgba(255, 255, 255, 0.03) !important;
    border: 1px solid var(--ios-border) !important;
    color: var(--ios-text-secondary) !important;
    white-space: nowrap !important;
  }
  
  .wo-tab.active {
    background: rgba(196, 149, 106, 0.15) !important;
    border-color: var(--ios-gold) !important;
    color: var(--ios-gold) !important;
  }
  
  /* Section title */
  .wo-section-title {
    color: var(--ios-gold) !important;
    font-size: 1.1rem !important;
    padding: 0 16px !important;
    margin-bottom: 12px !important;
    border-bottom: none !important;
  }
}

/* ===== TAB ICONS ===== */
.tab-icon {
  width: 16px;
  height: 16px;
  margin-right: 4px;
  vertical-align: middle;
  color: currentColor;
}

@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px),
       (max-width: 430px) {
  
  .tab-icon {
    width: 14px;
    height: 14px;
    color: inherit;
  }
  
  .wo-tab.active .tab-icon,
  .journal-tab.active .tab-icon,
  .sw-tab.active .tab-icon {
    color: var(--ios-gold);
  }
}

/* Fix mobile scroll when sidebar is open */
@media (display-mode: standalone) and (pointer: coarse),
       (pointer: coarse) and (max-width: 500px) {
  
  /* Prevent body scroll when sidebar is open */
  body.sidebar-open {
    overflow: hidden !important;
    position: fixed !important;
    width: 100% !important;
  }
  
  /* Ensure overlay is tappable and covers everything */
  body.sidebar-open .sidebar-overlay {
    display: block !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    z-index: 1000 !important;
    cursor: pointer !important;
  }
  
  /* Sidebar stays above overlay */
  body.sidebar-open .sidebar {
    z-index: 1001 !important;
  }
}
