/* === Base === */
body { margin: 0; padding: 0; font-family: "Roboto", sans-serif; }
#map { position: absolute; top: 0; bottom: 0; width: 100vw; height: 100vh; }

/* === Shared Card === */
.card {
  background: #fff;
  border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.12);
  border: 1px solid #eee;
  font-family: "Roboto", sans-serif;
}

/* === Loading Overlay === */
#loading-overlay {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  z-index: 100;
  background: rgba(255,255,255,0.92);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.spinner {
  width: 44px; height: 44px;
  border: 4px solid #eee;
  border-top-color: #3b26f9;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text {
  margin-top: 14px;
  color: #333;
  font-size: 0.95em;
  font-weight: 400;
}
.loading-error {
  text-align: center;
  color: #333;
}
.loading-error p:first-child { font-size: 1.1em; font-weight: 500; }
.loading-error p:last-child { font-size: 0.9em; }

/* === Popup === */
.mapboxgl-popup-content {
  font-family: "Roboto", sans-serif;
  border-radius: 10px;
  padding: 14px 16px;
  border: 1px solid #eee;
}
.mapboxgl-popup-close-button {
  font-size: 18px;
  color: #3b26f9;
  padding: 4px 8px;
  right: 2px;
  top: 2px;
}
.mapboxgl-popup-close-button:hover {
  background: #f4f4ff;
  border-radius: 4px;
}
.popup-title {
  font-size: 1.1em;
  font-weight: 500;
  margin-bottom: 4px;
  color: #000;
}
.popup-info {
  font-size: 0.9em;
  margin-bottom: 8px;
  color: #333;
  line-height: 1.5;
}
.popup-thumb {
  margin: 8px 0;
  text-align: center;
  font-size: 0.8em;
  color: #999;
}
.popup-thumb img {
  max-width: 280px;
  border-radius: 6px;
  display: block;
  margin: 0 auto;
}
.popup-actions {
  display: flex;
  gap: 6px;
}
.popup-btn {
  background: #3b26f9;
  color: white;
  border: none;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85em;
  cursor: pointer;
  flex: 1;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  box-sizing: border-box;
}
.popup-btn:hover { background: #301fd0; }
.popup-btn-secondary {
  background: #fff;
  color: #3b26f9;
  border: 1px solid #3b26f9;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.85em;
  cursor: pointer;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  box-sizing: border-box;
  white-space: nowrap;
}
.popup-btn-secondary:hover { background: #f4f4ff; }

/* Add-to-cart in-cart state */
.popup-cart-btn.in-cart {
  background: #e8f5e9;
  color: #2e7d32;
  border-color: #2e7d32;
}
.popup-cart-btn.in-cart:hover {
  background: #c8e6c9;
}

/* === Panel Brand (logo stacked above title) === */
.panel-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 14px 14px 10px;
  text-align: center;
}
#center-logo {
  width: 100%;
  max-width: 180px;
  height: auto;
  object-fit: contain;
  cursor: pointer;
  margin-bottom: 2px;
}
#center-logo-text {
  font-size: 1.05em;
  font-weight: 600;
  color: #000;
  letter-spacing: 0.2px;
  margin: 0;
  user-select: none;
}
.panel-brand-note {
  font-size: 0.7em;
  color: #777;
  margin-top: 4px;
  line-height: 1.4;
}
.contact-link {
  display: inline-block;
  font-size: 0.75em;
  color: #3b26f9;
  text-decoration: none;
  font-weight: 500;
  margin-top: 2px;
}
.contact-link:hover { text-decoration: underline; }

/* === Controls (combined toggle bar) === */
.control-group {
  position: absolute;
  top: 20px;
  right: 20px;
  z-index: 30;
  display: flex;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
  border: 1px solid #eee;
  overflow: hidden;
}
.toggle-btn {
  background: none;
  border: none;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 1.05em;
  color: #3b26f9;
  user-select: none;
  line-height: 1;
}
.toggle-btn:first-child {
  border-right: 1px solid #eee;
}
.toggle-btn:hover {
  background: #f4f4ff;
}

/* === Tools Panel (unified) === */
#tools-panel {
  position: absolute;
  top: 20px;
  left: 20px;
  z-index: 25;
  width: 280px;
  padding: 0;
  overflow: visible;
}
.panel-search {
  position: relative;
}
#tools-panel #search-input {
  width: 100%;
  padding: 11px 14px;
  border: none;
  background: transparent;
  font-family: "Roboto", sans-serif;
  font-size: 0.9em;
  box-sizing: border-box;
  outline: none;
}
#tools-panel #search-input:focus {
  box-shadow: inset 0 0 0 2px #3b26f9;
  border-radius: 0;
}
#search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  max-height: 220px;
  overflow-y: auto;
  display: none;
  z-index: 30;
}
.search-result-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.85em;
  border-bottom: 1px solid #f0f0f0;
  color: #333;
}
.search-result-item:last-child { border-bottom: none; }
.search-result-item:hover { background: #f4f4ff; }

.panel-divider {
  height: 1px;
  background: #eee;
}
.panel-header {
  padding: 10px 14px;
  font-size: 0.88em;
  font-weight: 500;
  color: #555;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  user-select: none;
}
.panel-header:hover {
  color: #3b26f9;
}
.panel-header::after {
  content: "▸";
  font-size: 0.75em;
  color: #999;
}
.panel-section.expanded .panel-header::after {
  content: "▾";
}
.panel-section.expanded .panel-header {
  color: #3b26f9;
}
.panel-body {
  display: none;
  padding: 0 14px 12px;
  font-size: 0.9em;
}
.panel-section.expanded .panel-body {
  display: block;
}
.panel-body input[type="file"] {
  width: 100%;
  font-size: 0.85em;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 6px;
  cursor: pointer;
  box-sizing: border-box;
}
.panel-body input[type="file"]::-webkit-file-upload-button {
  background: #3b26f9;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 12px;
  margin-right: 8px;
  cursor: pointer;
  font-size: 0.85em;
}
.panel-body input[type="file"]::-webkit-file-upload-button:hover {
  background: #301fd0;
}
.upload-note {
  font-size: 0.75em;
  color: #555;
  margin-top: 8px;
  margin-bottom: 0;
}
.panel-body label {
  display: block;
  font-size: 0.85em;
  color: #333;
  margin-bottom: 6px;
}
.panel-body select,
.panel-body input[type="date"] {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: "Roboto", sans-serif;
  font-size: 0.85em;
  margin-top: 2px;
  box-sizing: border-box;
}
.filter-actions {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}
.filter-actions .popup-btn { padding: 6px 10px; font-size: 0.8em; }
.btn-outline {
  background: none;
  border: 1px solid #ddd;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.8em;
  color: #555;
  flex: 1;
}
.btn-outline:hover { background: #f4f4ff; }

/* === Visible IDs Box (two-column layout) === */
#visible-ids {
  position: absolute;
  bottom: 40px;
  right: 20px;
  z-index: 20;
  font-size: 0.85em;
  display: none;
  padding: 0;
  overflow: hidden;
}
@media (min-width: 800px) {
  #visible-ids { display: block; }
}

#visible-ids-layout {
  display: flex;
  flex-direction: row;
}

/* --- Images Pane (right side, always visible) --- */
#images-pane {
  width: 280px;
  min-width: 280px;
  padding: 10px 14px;
  display: flex;
  flex-direction: column;
  max-height: 360px;
}
#images-heading {
  margin: 0 0 6px;
  font-size: 1em;
  font-weight: 500;
  flex-shrink: 0;
}
#ids-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.id-item {
  padding: 6px 4px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  border-radius: 4px;
}
.id-item:last-child { border-bottom: none; }
.id-item:hover { background: #f4f4ff; }
.id-name {
  font-weight: 500;
  font-size: 0.95em;
  color: #000;
}
.id-meta {
  font-size: 0.78em;
  color: #777;
  margin-top: 1px;
}
.ids-empty {
  color: #999;
  font-size: 0.88em;
  padding: 8px 0;
  text-align: center;
}

/* Scrollbar styling */
#ids-list::-webkit-scrollbar { width: 6px; }
#ids-list::-webkit-scrollbar-track { background: #f4f4ff; border-radius: 3px; }
#ids-list::-webkit-scrollbar-thumb { background-color: #3b26f9; border-radius: 3px; }
#ids-list::-webkit-scrollbar-thumb:hover { background-color: #301fd0; }

/* --- Cart Pane (left side, shown when cart has items) --- */
#cart-pane {
  width: 220px;
  min-width: 220px;
  padding: 10px 14px;
  border-right: 1px solid #eee;
  display: flex;
  flex-direction: column;
  max-height: 360px;
}
#cart-heading {
  margin: 0 0 6px;
  font-size: 0.95em;
  font-weight: 600;
  color: #3b26f9;
  flex-shrink: 0;
}
#cart-list {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}
.cart-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid #f0f0f0;
}
.cart-item:last-child { border-bottom: none; }
.cart-item-info { min-width: 0; flex: 1; }
.cart-item-name {
  font-size: 0.85em;
  font-weight: 500;
  color: #000;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cart-item-meta {
  font-size: 0.72em;
  color: #777;
}
.cart-remove {
  background: none;
  border: none;
  color: #999;
  font-size: 1.2em;
  cursor: pointer;
  padding: 2px 6px;
  line-height: 1;
  border-radius: 4px;
  flex-shrink: 0;
}
.cart-remove:hover {
  background: #fee;
  color: #c00;
}
#cart-total {
  font-size: 0.88em;
  font-weight: 600;
  color: #333;
  padding: 6px 0 2px;
  border-top: 1px solid #eee;
  margin-top: 4px;
  flex-shrink: 0;
}
#cart-order {
  margin-top: 8px;
  width: 100%;
  flex-shrink: 0;
  flex-grow: 0;
  padding: 7px 12px;
  font-size: 0.82em;
}
#cart-list::-webkit-scrollbar { width: 5px; }
#cart-list::-webkit-scrollbar-track { background: #f4f4ff; border-radius: 3px; }
#cart-list::-webkit-scrollbar-thumb { background-color: #3b26f9; border-radius: 3px; }

/* === Order Modal === */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 200;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  animation: modalFadeIn 0.2s ease;
}
@keyframes modalFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.modal-overlay.fade-out {
  animation: modalFadeOut 0.4s ease forwards;
}
.modal-overlay.fade-out .modal-card {
  animation: modalSlideOut 0.4s ease forwards;
}
@keyframes modalFadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}
@keyframes modalSlideOut {
  from { transform: translateY(0); opacity: 1; }
  to { transform: translateY(20px); opacity: 0; }
}
.modal-card {
  background: #fff;
  border-radius: 12px;
  padding: 28px 32px;
  width: 400px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  position: relative;
  font-family: "Roboto", sans-serif;
  animation: modalSlideIn 0.2s ease;
}
@keyframes modalSlideIn {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-close {
  position: absolute;
  top: 12px; right: 14px;
  background: none;
  border: none;
  font-size: 1.5em;
  color: #999;
  cursor: pointer;
  padding: 2px 8px;
  border-radius: 4px;
  line-height: 1;
}
.modal-close:hover { background: #f4f4ff; color: #3b26f9; }
.modal-title {
  margin: 0 0 4px;
  font-size: 1.25em;
  font-weight: 600;
  color: #000;
}
.modal-subtitle {
  margin: 0 0 18px;
  font-size: 0.85em;
  color: #666;
}
.modal-label {
  display: block;
  font-size: 0.85em;
  font-weight: 500;
  color: #333;
  margin-bottom: 14px;
}
.modal-required { color: #e53935; }
.modal-label input {
  display: block;
  width: 100%;
  padding: 9px 12px;
  margin-top: 4px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-family: "Roboto", sans-serif;
  font-size: 0.95em;
  box-sizing: border-box;
  outline: none;
  transition: border-color 0.15s;
}
.modal-label input:focus {
  border-color: #3b26f9;
  box-shadow: 0 0 0 2px rgba(59,38,249,0.12);
}
.modal-label input.input-error {
  border-color: #e53935;
  box-shadow: 0 0 0 2px rgba(229,57,53,0.12);
}
.modal-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 0.82em;
  margin-bottom: 12px;
  line-height: 1.4;
}
.modal-submit {
  width: 100%;
  padding: 11px 16px;
  font-size: 0.92em;
  margin-top: 4px;
}
.modal-submit:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}
.modal-success {
  text-align: center;
  padding: 20px 0 8px;
}
.modal-success-icon {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: #e8f5e9;
  color: #2e7d32;
  font-size: 1.5em;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  font-weight: 700;
}
.modal-success h3 {
  margin: 0 0 6px;
  font-size: 1.1em;
  color: #000;
}
.modal-success p {
  margin: 0;
  font-size: 0.88em;
  color: #666;
}

/* Dark mode modal */
body.dark-mode .modal-overlay { background: rgba(0,0,0,0.7); }
body.dark-mode .modal-card { background: #1e1e1e; }
body.dark-mode .modal-title { color: #eee; }
body.dark-mode .modal-subtitle { color: #999; }
body.dark-mode .modal-label { color: #ccc; }
body.dark-mode .modal-label input {
  background: #2a2a2a;
  color: #eee;
  border-color: #444;
}
body.dark-mode .modal-label input:focus {
  border-color: #9b8fff;
  box-shadow: 0 0 0 2px rgba(155,143,255,0.15);
}
body.dark-mode .modal-label input.input-error {
  border-color: #ef5350;
  box-shadow: 0 0 0 2px rgba(239,83,80,0.15);
}
body.dark-mode .modal-error {
  background: #3a1c1c;
  border-color: #5c2020;
  color: #fca5a5;
}
body.dark-mode .modal-close { color: #666; }
body.dark-mode .modal-close:hover { background: #2a2a2a; color: #9b8fff; }
body.dark-mode .modal-success h3 { color: #eee; }
body.dark-mode .modal-success p { color: #999; }
body.dark-mode .modal-success-icon { background: #1b3a1b; color: #66bb6a; }

/* === Coordinate Display === */
#coord-display {
  position: absolute;
  bottom: 8px;
  left: 8px;
  z-index: 10;
  background: rgba(255,255,255,0.85);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 0.72em;
  font-family: "Roboto Mono", monospace;
  color: #555;
  pointer-events: none;
}

/* === Mobile Header (hidden on desktop) === */
#mobile-header {
  display: none;
}

/* === Mapbox GL Draw overrides === */
.mapbox-gl-draw_ctrl-draw-btn { border-radius: 6px !important; }

/* === Responsive: Mobile === */
@media (max-width: 799px) {
  .control-group { top: 10px; right: 10px; }
  .toggle-btn { padding: 6px 10px; font-size: 0.95em; }

  #tools-panel {
    top: 10px;
    left: 10px;
    width: 220px;
  }
  #center-logo { max-width: 120px; }
  #center-logo-text { font-size: 0.88em; }
  .panel-brand-note { display: none; }
  .contact-link { display: none; }

  /* --- Bottom sheet --- */
  #visible-ids {
    display: block;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 100%;
    border-radius: 14px 14px 0 0;
    max-height: 70vh;
    transform: translateY(calc(100% - 52px));
    transition: transform 0.3s ease;
    z-index: 50;
    box-shadow: 0 -2px 12px rgba(0,0,0,0.15);
  }
  #visible-ids.expanded { transform: translateY(0); }

  /* Drag handle indicator */
  #visible-ids::before {
    content: '';
    display: block;
    width: 36px;
    height: 4px;
    background: #ccc;
    border-radius: 2px;
    margin: 10px auto 2px;
    flex-shrink: 0;
  }

  /* Stack columns vertically on mobile */
  #visible-ids-layout { flex-direction: column; }

  /* Constrain each pane so both fit in the sheet */
  #images-pane {
    width: auto;
    min-width: 0;
    max-height: 32vh;
  }
  #cart-pane {
    width: auto;
    min-width: 0;
    max-height: 28vh;
    border-right: none;
    border-bottom: 1px solid #eee;
  }

  /* Both headings act as toggle targets on mobile */
  #images-heading,
  #cart-heading {
    cursor: pointer;
    padding: 10px 14px 8px;
    text-align: center;
  }
  #images-heading::after {
    content: " ▴";
    font-size: 0.7em;
    color: #999;
  }
  #visible-ids.expanded #images-heading::after { content: " ▾"; }

  /* Bigger tap target for Order button on mobile */
  #cart-order {
    padding: 10px 12px;
    font-size: 0.88em;
  }

  /* --- Order modal: full-screen slide-up on mobile --- */
  .modal-card {
    width: 100%;
    max-width: 100%;
    max-height: 100%;
    height: 100%;
    border-radius: 0;
    padding: 20px 16px;
    animation: modalSlideUp 0.25s ease;
  }
  @keyframes modalSlideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
  }
  .modal-overlay.fade-out .modal-card {
    animation: modalSlideDown 0.3s ease forwards;
  }
  @keyframes modalSlideDown {
    from { transform: translateY(0); }
    to { transform: translateY(100%); }
  }
  .modal-label input {
    padding: 12px;
    font-size: 1em;
  }
  .modal-submit {
    padding: 14px 16px;
    font-size: 1em;
  }

  #coord-display { display: none; }
}

@media (max-width: 480px) {
  #tools-panel { display: none; }

  /* Show mobile header only when tools panel is hidden */
  #mobile-header {
    display: flex;
    align-items: center;
    gap: 8px;
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 30;
    background: #fff;
    padding: 6px 12px;
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    border: 1px solid #eee;
    font-family: "Roboto", sans-serif;
  }
  #mobile-logo {
    height: 22px;
    width: auto;
    cursor: pointer;
  }
  #mobile-header span {
    font-size: 0.82em;
    font-weight: 600;
    color: #000;
    letter-spacing: 0.2px;
    white-space: nowrap;
  }
}

/* === Dark Mode === */
body.dark-mode .card,
body.dark-mode .control-group,
body.dark-mode #search-results,
body.dark-mode .search-result-item {
  background: #1e1e1e;
  color: #eee;
  border-color: #333;
}
body.dark-mode .toggle-btn {
  color: #9b8fff;
}
body.dark-mode .toggle-btn:first-child {
  border-color: #333;
}
body.dark-mode .toggle-btn:hover {
  background: #2a2a2a;
}
body.dark-mode #tools-panel #search-input {
  color: #eee;
}
body.dark-mode .panel-divider {
  background: #333;
}
body.dark-mode .panel-header {
  color: #aaa;
}
body.dark-mode .panel-header:hover,
body.dark-mode .panel-section.expanded .panel-header {
  color: #9b8fff;
}
body.dark-mode .panel-brand-note { color: #888; }
body.dark-mode .contact-link { color: #9b8fff; }
body.dark-mode .popup-btn-secondary {
  background: #2a2a2a;
  color: #9b8fff;
  border-color: #9b8fff;
}
body.dark-mode .popup-btn-secondary:hover { background: #333; }
body.dark-mode .popup-cart-btn.in-cart {
  background: #1b3a1b;
  color: #66bb6a;
  border-color: #66bb6a;
}
body.dark-mode .popup-cart-btn.in-cart:hover { background: #254025; }
body.dark-mode .popup-title,
body.dark-mode .id-name,
body.dark-mode #center-logo-text { color: #eee; }
body.dark-mode .popup-info,
body.dark-mode .id-meta { color: #aaa; }
body.dark-mode .mapboxgl-popup-content {
  background: #1e1e1e;
  border-color: #333;
  color: #eee;
}
body.dark-mode .mapboxgl-popup-tip {
  border-top-color: #1e1e1e;
}
body.dark-mode .id-item:hover,
body.dark-mode .search-result-item:hover {
  background: #2a2a2a;
}
body.dark-mode #coord-display {
  background: rgba(30,30,30,0.85);
  color: #ccc;
}
body.dark-mode .panel-body label { color: #ccc; }
body.dark-mode .panel-body select,
body.dark-mode .panel-body input[type="date"] {
  background: #2a2a2a;
  color: #eee;
  border-color: #444;
}
body.dark-mode .btn-outline { color: #aaa; border-color: #444; }
body.dark-mode .btn-outline:hover { background: #2a2a2a; }
body.dark-mode #loading-overlay { background: rgba(14,14,14,0.92); }
body.dark-mode .loading-text { color: #ccc; }
body.dark-mode #ids-list::-webkit-scrollbar-track { background: #2a2a2a; }
body.dark-mode .ids-empty { color: #666; }
body.dark-mode #cart-heading { color: #9b8fff; }
body.dark-mode .cart-item-name { color: #eee; }
body.dark-mode .cart-item-meta { color: #888; }
body.dark-mode .cart-item { border-color: #333; }
body.dark-mode .cart-remove { color: #666; }
body.dark-mode .cart-remove:hover { background: #3a2020; color: #ff6b6b; }
body.dark-mode #cart-total { color: #ccc; border-color: #333; }
body.dark-mode #cart-list::-webkit-scrollbar-track { background: #2a2a2a; }
body.dark-mode #cart-pane { border-color: #333; }
body.dark-mode #visible-ids::before { background: #555; }
body.dark-mode #mobile-header {
  background: #1e1e1e;
  border-color: #333;
}
body.dark-mode #mobile-header span { color: #eee; }
