:root {
  --primary: #0d6efd;
  --bg-light: #f8f9fa;
  --border-color: #dee2e6;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg-light);
  /* Prevent pull-to-refresh and overscroll on mobile */
  overscroll-behavior: none;
  -webkit-overflow-scrolling: touch;
}

.navbar-brand {
  font-weight: 700;
}

/* Mobile navbar adjustments */
@media (max-width: 991px) {
  .navbar-collapse {
    background: #0d6efd;
    padding: 0.5rem 1rem;
    border-radius: 0 0 0.5rem 0.5rem;
  }
  .navbar-nav .nav-link {
    padding: 0.6rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.15);
  }
  .navbar-nav .nav-link:last-child {
    border-bottom: none;
  }
}

.preview-wrapper {
  position: relative;
  height: calc(100vh - 56px - 1rem);
  min-height: 400px;
  margin-top: 0.5rem;
}

.preview-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 0;
  overflow: hidden;
  /* Prevent browser zoom on double tap */
  touch-action: manipulation;
}

#fieldCanvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 0.25rem;
  /* Ensure canvas captures touch events for Three.js controls */
  touch-action: none;
}

.control-panel {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1rem;
  height: calc(100vh - 56px - 1rem);
  min-height: 400px;
  overflow-y: auto;
  margin-top: 0.5rem;
  /* Smooth scrolling on iOS */
  -webkit-overflow-scrolling: touch;
}

.field-type-btn {
  width: 100%;
  margin-bottom: 0.5rem;
  text-align: left;
}

.field-type-btn.active {
  background-color: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.color-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.color-item label {
  margin-bottom: 0;
  font-size: 0.95rem;
}

.color-item input[type="color"] {
  width: 48px;
  height: 32px;
  border: none;
  padding: 0;
  cursor: pointer;
}

.color-select-wrap {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.color-swatch {
  width: 28px;
  height: 28px;
  border-radius: 0.25rem;
  border: 1px solid var(--border-color);
  display: inline-block;
  flex-shrink: 0;
}

.color-select {
  min-width: 180px;
  max-width: 220px;
}

/* Custom color dropdown */
.custom-color-dropdown {
  position: relative;
  min-width: 180px;
  max-width: 220px;
}

.color-dropdown-trigger {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.5rem;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  background: #fff;
  cursor: pointer;
  font-size: 0.875rem;
}

.color-dropdown-trigger:hover {
  border-color: #adb5bd;
}

.trigger-swatch {
  width: 20px;
  height: 20px;
  border-radius: 0.25rem;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.trigger-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.color-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0.25rem;
  max-height: 260px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.1);
  z-index: 1000;
  display: none;
  /* Smooth scrolling on iOS */
  -webkit-overflow-scrolling: touch;
}

.custom-color-dropdown.open .color-dropdown-menu {
  display: block;
}

.color-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.6rem;
  cursor: pointer;
  font-size: 0.875rem;
}

.color-option:hover,
.color-option.selected {
  background: #f1f3f5;
}

.option-swatch {
  width: 18px;
  height: 18px;
  border-radius: 0.2rem;
  border: 1px solid var(--border-color);
  flex-shrink: 0;
}

.option-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.quick-scheme-btn {
  margin-right: 0.5rem;
  margin-bottom: 0.5rem;
}

.field-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.field-tab {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border-color);
  border-radius: 0.375rem;
  background: #fff;
  cursor: pointer;
  font-size: 0.875rem;
  user-select: none;
}

.field-tab:hover {
  background: #f1f3f5;
}

.field-tab.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.scheme-card {
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1rem;
  background: #fff;
  margin-bottom: 1rem;
}

.scheme-preview-box {
  width: 100%;
  height: 80px;
  border-radius: 0.25rem;
  border: 1px solid var(--border-color);
  margin-bottom: 0.75rem;
}

.auth-card {
  max-width: 420px;
  margin: 4rem auto;
  padding: 2rem;
  background: #fff;
  border-radius: 0.75rem;
  box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.08);
}

.footer-note {
  text-align: center;
  color: #6c757d;
  font-size: 0.875rem;
  margin-top: 1.5rem;
}

.vip-blocker {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(240, 244, 248, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  border-radius: 0.5rem;
}

@media (max-width: 991px) {
  .vip-blocker {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 200;
  }
}

.vip-blocker-content {
  text-align: center;
  padding: 2rem;
  background: #fff;
  border-radius: 0.75rem;
  box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.1);
  max-width: 400px;
}

.vip-blocker-content h4 {
  margin-bottom: 1rem;
  color: #dc3545;
}

.vip-blocker-content p {
  margin-bottom: 0.5rem;
  color: #495057;
}

/* Mobile Color Toolbar */
.mobile-color-toolbar {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 0.5rem 0.75rem;
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

.mobile-toolbar-inner {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.mobile-toolbar-inner::-webkit-scrollbar {
  display: none;
}

.mobile-color-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  flex-shrink: 0;
}

.mobile-color-label {
  font-size: 0.7rem;
  color: #6c757d;
  white-space: nowrap;
}

.mobile-dropdown {
  min-width: auto;
  max-width: none;
}

.mobile-dropdown .color-dropdown-trigger {
  padding: 0.2rem;
  border-radius: 0.25rem;
  min-height: 32px;
}

.mobile-dropdown .color-dropdown-menu {
  position: fixed;
  top: auto;
  left: 0.5rem;
  right: 0.5rem;
  bottom: auto;
  max-height: 50vh;
  z-index: 1050;
}

.mobile-toolbar-divider {
  width: 1px;
  height: 36px;
  background: var(--border-color);
  flex-shrink: 0;
  margin: 0 0.25rem;
}

.mobile-quick-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.mobile-quick-actions .btn {
  min-height: 36px;
  width: 36px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Mobile control panel (below preview) */
.mobile-control-panel {
  background: #fff;
  border: 1px solid var(--border-color);
  border-radius: 0.5rem;
  padding: 1rem;
  margin-bottom: 1rem;
}

/* Mobile-specific enhancements */
@media (max-width: 991px) {
  .preview-wrapper {
    height: calc(55vh - 60px);
    min-height: 250px;
  }
  .control-panel {
    height: auto;
    min-height: unset;
    max-height: none;
    margin-bottom: 1rem;
  }
  /* Larger touch targets for mobile */
  .field-type-btn {
    padding: 0.6rem 1rem;
    font-size: 1rem;
    margin-bottom: 0.6rem;
  }
  .color-dropdown-trigger {
    padding: 0.5rem 0.75rem;
    font-size: 1rem;
    min-height: 44px;
  }
  .color-option {
    padding: 0.6rem 0.8rem;
    font-size: 1rem;
    min-height: 44px;
  }
  .field-tab {
    padding: 0.4rem 0.8rem;
    font-size: 1rem;
    min-height: 44px;
    display: flex;
    align-items: center;
  }
  .quick-scheme-btn {
    padding: 0.5rem 1rem;
    font-size: 0.95rem;
    margin-bottom: 0.6rem;
  }
  /* Auth card adjustments */
  .auth-card {
    margin: 2rem 1rem;
    padding: 1.5rem;
  }
  /* Admin page table responsive */
  .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }
  /* Form inputs larger on mobile */
  .form-control, .form-select {
    min-height: 44px;
    font-size: 16px; /* Prevents iOS zoom on focus */
  }
  /* Buttons larger touch targets */
  .btn {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
  /* Count controls */
  #countDisplay {
    font-size: 1.2rem;
    min-width: 2rem;
    text-align: center;
    display: inline-block;
  }
  /* Prevent text selection on UI controls */
  .control-panel button,
  .control-panel .field-tab,
  .color-dropdown-trigger {
    -webkit-user-select: none;
    user-select: none;
    -webkit-touch-callout: none;
  }
}

/* Small phone adjustments */
@media (max-width: 575px) {
  .preview-wrapper {
    height: 45vh;
    min-height: 250px;
  }
  .navbar-brand {
    font-size: 1rem;
  }
  .control-panel {
    padding: 0.75rem;
  }
  .color-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.4rem;
    margin-bottom: 1rem;
  }
  .color-item label {
    font-size: 0.9rem;
  }
  .custom-color-dropdown {
    width: 100%;
    max-width: none;
    min-width: auto;
  }
  .color-dropdown-trigger {
    width: 100%;
  }
  .color-dropdown-menu {
    left: 0;
    right: 0;
  }
  /* Make scheme cards more compact */
  .scheme-card {
    padding: 0.75rem;
  }
}

/* Landscape mode on mobile */
@media (max-width: 991px) and (orientation: landscape) {
  .preview-wrapper {
    height: 70vh;
  }
}

/* Prevent iOS callout on long press */
* {
  -webkit-touch-callout: none;
}

/* Allow text selection in inputs and content areas */
input, textarea, .card-body, .modal-body {
  -webkit-touch-callout: default;
  -webkit-user-select: text;
  user-select: text;
}
