/* ========================================
   RESET & BASE STYLES
   ======================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary-blue: #6BA5E7;
  --secondary-blue: #7DB3ED;
  --text-dark: #1A1A1A;
  --text-gray: #6B6B6B;
  --text-light: #AAAAAA;
  --icon-light: #D5D5D5;
  --bg-white: #FFFFFF;
  --bg-gray: #F5F5F5;
  --bg-action: #F8F8F8;
  --border-color: #ECECEC;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 1px 4px rgba(0,0,0,0.08);
  --shadow-lg: 0 -1px 3px rgba(0,0,0,0.06);
}

:root {
  /* Smooth transitions for theme changes */
  transition: background-color 0.3s ease, color 0.3s ease;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', Arial, sans-serif;
  background-color: var(--bg-gray);
  color: var(--text-dark);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  padding-top: 60px; /* Top header height */
  padding-bottom: calc(70px + env(safe-area-inset-bottom)); /* Bottom nav height + safe area */
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Smooth transitions for theme-aware elements */
.top-header,
.quick-actions,
.bottom-nav,
.content-section,
.project-card,
.camera-menu,
.camera-menu-option,
.trial-badge,
.action-btn svg,
.nav-icon-wrapper.camera-wrapper {
  transition: background-color 0.3s ease, color 0.3s ease, border-color 0.3s ease;
}

/* Prevent transition on camera wrapper background - always stays blue */
.nav-icon-wrapper.camera-wrapper {
  background-color: var(--primary-blue) !important;
  transition: transform 0.2s ease !important;
}

/* ========================================
   TOP HEADER
   ======================================== */
.top-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 60px;
  background-color: var(--bg-white);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  padding-top: env(safe-area-inset-top);
  box-shadow: var(--shadow-sm);
  z-index: 1000;
}

.app-logo {
  flex-shrink: 0;
}

.create-project-btn {
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  flex-shrink: 0;
}

.create-project-btn:active {
  transform: scale(0.95);
  opacity: 0.8;
}

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

.trial-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  background-color: #E3F2FF;
  color: var(--primary-blue);
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 600;
}

.trial-badge svg {
  width: 14px;
  height: 14px;
  stroke: var(--primary-blue);
}

.search-btn {
  background: none;
  border: none;
  color: var(--text-gray);
  padding: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s;
}

.search-btn:active {
  background-color: var(--bg-gray);
}

/* ========================================
   QUICK ACTIONS ROW
   ======================================== */
.quick-actions {
  background-color: var(--bg-white);
  display: flex;
  justify-content: space-around;
  padding: 16px 12px;
  gap: 8px;
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 60px;
  z-index: 999;
}

.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: none;
  border: none;
  color: var(--text-gray);
  cursor: pointer;
  padding: 4px;
  flex: 1;
  max-width: 80px;
  transition: opacity 0.2s;
}

.action-btn:active {
  opacity: 0.6;
}

.action-btn svg {
  width: 48px;
  height: 48px;
  padding: 10px;
  margin-bottom: 6px;
  stroke-width: 1.5;
  background-color: var(--bg-action);
  border-radius: 50%;
}

.action-btn span {
  font-size: 11px;
  line-height: 1.2;
  text-align: center;
  font-weight: 500;
  color: var(--text-gray);
}

/* ========================================
   MAIN CONTENT AREA
   ======================================== */
.main-content {
  padding: 0;
  min-height: calc(100vh - 60px - 70px);
}

/* ========================================
   USER PROFILE SECTION
   ======================================== */
.user-profile {
  background-color: var(--bg-white);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: background-color 0.2s;
}

.user-profile:active {
  background-color: var(--bg-gray);
}

.user-avatar-large {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  margin-right: 12px;
  object-fit: cover;
}

.user-info {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-name {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-dark);
}

.chevron-right {
  color: var(--text-light);
}

/* ========================================
   CONTENT SECTIONS
   ======================================== */
.content-section {
  background-color: var(--bg-white);
  margin-top: 12px;
  padding: 16px 20px 20px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-dark);
  letter-spacing: -0.3px;
  margin: 0;
}

.section-header svg {
  color: var(--text-light);
}

/* ========================================
   PHOTO GRID
   ======================================== */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.photo-card {
  position: relative;
  aspect-ratio: 4/3;
  border-radius: 6px;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
}

.photo-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

.photo-card:active img {
  transform: scale(0.95);
}

.photo-footer {
  position: absolute;
  bottom: 8px;
  left: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.photo-user-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid white;
  object-fit: cover;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.photo-count {
  color: white;
  font-size: 13px;
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

/* ========================================
   PROJECTS GRID
   ======================================== */
.projects-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}

.project-card {
  background-color: var(--bg-white);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  transition: transform 0.2s, box-shadow 0.2s;
  cursor: pointer;
}

.project-card:active {
  transform: translateY(2px);
  box-shadow: var(--shadow-sm);
}

.project-image-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 4/3;
  overflow: hidden;
}

.project-image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.project-camera-overlay {
  position: absolute;
  top: 8px;
  right: 8px;
  background-color: var(--primary-blue);
  border: none;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(74, 144, 226, 0.5);
  transition: background-color 0.2s, transform 0.2s;
  z-index: 10;
}

.project-camera-overlay:active {
  background-color: var(--secondary-blue);
  transform: scale(0.95);
}

.project-info {
  padding: 12px;
  background-color: var(--bg-white);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.project-text {
  flex: 1;
  min-width: 0;
}

.project-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-address {
  font-size: 13px;
  color: var(--text-gray);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-camera-btn {
  background-color: var(--primary-blue);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  margin-left: 8px;
  transition: background-color 0.2s, transform 0.2s;
}

.project-camera-btn:active {
  background-color: var(--secondary-blue);
  transform: scale(0.95);
}

.project-actions {
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 8px 12px 12px;
  background-color: var(--bg-white);
  border-top: 1px solid var(--border-color);
}

.icon-btn {
  background: none;
  border: none;
  color: var(--icon-light);
  padding: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s, color 0.2s;
}

.icon-btn:active {
  background-color: var(--bg-gray);
  color: var(--text-gray);
}

/* ========================================
   NEARBY PROJECTS SECTION
   ======================================== */
.nearby-projects-scroll {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding-bottom: 4px;
}

.nearby-projects-scroll::-webkit-scrollbar {
  display: none;
}

.nearby-project-card {
  flex-shrink: 0;
  width: 280px;
  background-color: var(--bg-white);
  border-radius: 12px;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  position: relative;
  cursor: pointer;
}

.nearby-project-card img {
  width: 100%;
  height: 160px;
  object-fit: cover;
}

.project-camera-icon {
  position: absolute;
  top: 12px;
  right: 12px;
  background-color: var(--primary-blue);
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(74, 144, 226, 0.5);
  transition: background-color 0.2s, transform 0.2s;
}

.project-camera-icon:active {
  background-color: var(--secondary-blue);
  transform: scale(0.95);
}

.nearby-project-info {
  padding: 12px;
}

.nearby-project-info h4 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-dark);
  margin: 0 0 4px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nearby-project-info p {
  font-size: 13px;
  color: var(--text-gray);
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
   COMPANY FEED SECTION
   ======================================== */
.feed-subtitle {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dark);
  margin: 0 0 12px 0;
}

.feed-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.feed-item {
  cursor: pointer;
}

.feed-photo {
  position: relative;
  aspect-ratio: 4/3;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 6px;
}

.feed-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s;
}

.feed-item:active .feed-photo img {
  transform: scale(0.95);
}

.feed-photo-badge {
  position: absolute;
  bottom: 6px;
  left: 6px;
  background-color: rgba(0, 0, 0, 0.65);
  color: white;
  padding: 4px 8px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  backdrop-filter: blur(4px);
}

.feed-photo-badge svg {
  width: 12px;
  height: 12px;
  flex-shrink: 0;
}

.feed-label {
  font-size: 13px;
  color: var(--text-gray);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ========================================
   BOTTOM NAVIGATION BAR
   ======================================== */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 70px;
  background-color: var(--bg-white);
  display: flex;
  justify-content: space-around;
  align-items: center;
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  padding-bottom: env(safe-area-inset-bottom);
  border-top: 1px solid var(--border-color);
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: var(--text-gray);
  min-width: 56px;
  min-height: 56px;
  position: relative;
  transition: color 0.2s;
  background: none;
  border: none;
}

.nav-icon-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s;
}

.nav-item:active .nav-icon-wrapper {
  transform: scale(0.9);
}

.nav-icon {
  width: 24px;
  height: 24px;
}

/* Active state for home icon */
.nav-item.active {
  color: white;
}

.nav-item.active .nav-icon-wrapper {
  background-color: var(--primary-blue);
  border-radius: 50%;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-item.active .nav-icon {
  fill: white;
  stroke: none;
}

/* Camera button - elevated and styled */
.nav-item-camera {
  background: transparent !important;
}

.nav-item-camera .nav-icon-wrapper.camera-wrapper {
  background-color: var(--primary-blue);
  border-radius: 50%;
  width: 56px;
  height: 56px;
  box-shadow: 0 4px 12px rgba(74, 144, 226, 0.4);
  margin-bottom: 8px;
}

.nav-item-camera:active .nav-icon-wrapper.camera-wrapper {
  background-color: var(--secondary-blue);
  transform: scale(0.95);
}

.nav-item-camera .nav-icon {
  width: 28px;
  height: 28px;
  fill: white;
  stroke: white;
}

/* Profile avatar in nav */
.nav-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid transparent;
  transition: border-color 0.2s;
}

.nav-item.active .nav-avatar {
  border-color: var(--primary-blue);
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

/* Small phones */
@media (max-width: 375px) {
  .action-btn span {
    font-size: 10px;
  }

  .action-btn svg {
    width: 28px;
    height: 28px;
  }

  .page-title {
    font-size: 24px;
  }
}

/* Tablets - Convert to sidebar navigation */
@media (min-width: 768px) {
  body {
    padding-left: 80px;
    padding-bottom: 20px;
    padding-top: 0;
  }

  .top-header {
    left: 80px;
  }

  .bottom-nav {
    top: 0;
    bottom: auto;
    left: 0;
    width: 80px;
    height: 100vh;
    flex-direction: column;
    padding-bottom: 0;
    padding-left: env(safe-area-inset-left);
    padding-top: 20px;
    gap: 12px;
  }

  .nav-item-camera .nav-icon-wrapper.camera-wrapper {
    margin-bottom: 0;
  }

  .quick-actions {
    top: 60px;
    left: 80px;
    right: 0;
  }

  .main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
  }

  .projects-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .photo-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

/* Desktop - Wider layout */
@media (min-width: 1024px) {
  .bottom-nav {
    width: 100px;
  }

  body {
    padding-left: 100px;
  }

  .top-header {
    left: 100px;
  }

  .quick-actions {
    left: 100px;
  }

  .main-content {
    max-width: 1400px;
  }

  .projects-grid {
    grid-template-columns: repeat(4, 1fr);
  }

  .photo-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}

/* ========================================
   DARK MODE - Auto-detect & Manual Override
   ======================================== */

/* Dark mode via system preference OR manual .dark-mode class */
@media (prefers-color-scheme: dark) {
  :root:not(.light-mode) {
    --text-dark: #FFFFFF;
    --text-gray: #AAAAAA;
    --text-light: #666666;
    --icon-light: #777777;
    --bg-white: #1C1C1E;
    --bg-gray: #000000;
    --bg-action: #2C2C2E;
    --border-color: #38383A;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.5);
    --shadow-md: 0 1px 4px rgba(0,0,0,0.6);
    --shadow-lg: 0 -1px 3px rgba(0,0,0,0.5);
  }

  :root:not(.light-mode) .photo-card,
  :root:not(.light-mode) .project-card {
    box-shadow: 0 1px 3px rgba(0,0,0,0.8);
  }

  :root:not(.light-mode) .top-header,
  :root:not(.light-mode) .quick-actions,
  :root:not(.light-mode) .bottom-nav {
    box-shadow: 0 1px 3px rgba(0,0,0,0.7);
  }

  :root:not(.light-mode) img {
    opacity: 0.9;
  }

  :root:not(.light-mode) .trial-badge {
    background-color: rgba(107, 165, 231, 0.2);
  }

  /* Ensure camera button stays blue in dark mode */
  :root:not(.light-mode) .nav-item-camera .nav-icon-wrapper.camera-wrapper {
    background-color: var(--primary-blue);
  }
}

/* Manual dark mode (overrides light mode preference) */
:root.dark-mode {
  --text-dark: #FFFFFF;
  --text-gray: #AAAAAA;
  --text-light: #666666;
  --icon-light: #777777;
  --bg-white: #1C1C1E;
  --bg-gray: #000000;
  --bg-action: #2C2C2E;
  --border-color: #38383A;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.5);
  --shadow-md: 0 1px 4px rgba(0,0,0,0.6);
  --shadow-lg: 0 -1px 3px rgba(0,0,0,0.5);
}

:root.dark-mode .photo-card,
:root.dark-mode .project-card {
  box-shadow: 0 1px 3px rgba(0,0,0,0.8);
}

:root.dark-mode .top-header,
:root.dark-mode .quick-actions,
:root.dark-mode .bottom-nav {
  box-shadow: 0 1px 3px rgba(0,0,0,0.7);
}

:root.dark-mode img {
  opacity: 0.9;
}

:root.dark-mode .trial-badge {
  background-color: rgba(107, 165, 231, 0.2);
}

/* Ensure camera button stays blue in manual dark mode */
:root.dark-mode .nav-item-camera .nav-icon-wrapper.camera-wrapper {
  background-color: var(--primary-blue);
}

/* Loading animation for images */
img {
  background-color: var(--bg-gray);
}

/* Smooth scrolling */
html {
  scroll-behavior: smooth;
}

/* Focus styles for accessibility */
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--primary-blue);
  outline-offset: 2px;
}

/* ========================================
   CAMERA MENU (Bottom Sheet)
   ======================================== */
.camera-menu-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1999;
  animation: fadeIn 0.2s ease-out;
}

.camera-menu {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-radius: 20px 20px 0 0;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 2000;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.2);
  animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.camera-menu-handle {
  width: 36px;
  height: 5px;
  background: #C7C7CC;
  border-radius: 3px;
  margin: 0 auto 20px;
}

.camera-menu-option {
  display: flex;
  align-items: center;
  gap: 16px;
  background: white;
  border: none;
  border-radius: 12px;
  padding: 16px;
  width: 100%;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: 12px;
}

.camera-menu-option:last-child {
  margin-bottom: 0;
}

.camera-menu-option:hover {
  background: #F5F5F7;
}

.camera-menu-option:active {
  transform: scale(0.98);
  background: #E5E5EA;
}

.camera-option-icon {
  width: 56px;
  height: 56px;
  background: var(--primary-blue);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.camera-option-text {
  flex: 1;
  text-align: left;
}

.camera-option-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 4px;
}

.camera-option-desc {
  font-size: 14px;
  color: var(--text-gray);
}

/* Dark mode support for camera menu */
@media (prefers-color-scheme: dark) {
  :root:not(.light-mode) .camera-menu {
    background: #1C1C1E;
  }

  :root:not(.light-mode) .camera-menu-option {
    background: #1C1C1E;
  }

  :root:not(.light-mode) .camera-menu-option:hover {
    background: #2C2C2E;
  }

  :root:not(.light-mode) .camera-menu-option:active {
    background: #3C3C3E;
  }

  :root:not(.light-mode) .camera-menu-handle {
    background: #48484A;
  }
}

:root.dark-mode .camera-menu {
  background: #1C1C1E;
}

:root.dark-mode .camera-menu-option {
  background: #1C1C1E;
}

:root.dark-mode .camera-menu-option:hover {
  background: #2C2C2E;
}

:root.dark-mode .camera-menu-option:active {
  background: #3C3C3E;
}

:root.dark-mode .camera-menu-handle {
  background: #48484A;
}

/* Theme toggle button */
.theme-toggle-btn {
  background: none;
  border: none;
  color: var(--text-gray);
  padding: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background-color 0.2s;
  position: relative;
}

.theme-toggle-btn:active {
  background-color: var(--bg-gray);
}

.theme-toggle-btn svg {
  width: 20px;
  height: 20px;
}

/* Hide/show icons based on theme */
.theme-icon-sun {
  display: none;
}

.theme-icon-moon {
  display: block;
}

:root.dark-mode .theme-icon-sun {
  display: block;
}

:root.dark-mode .theme-icon-moon {
  display: none;
}

@media (prefers-color-scheme: dark) {
  :root:not(.light-mode) .theme-icon-sun {
    display: block;
  }

  :root:not(.light-mode) .theme-icon-moon {
    display: none;
  }
}
