/* === Test MongoDB Button - Disabled === */
.test-mongo-btn {
  display: none !important;
}

/* === CSS Variables === */
:root {
  /* Colors */
  --color-primary: #795548;
  --color-primary-hover: #6d4c41;
  --color-success: #4caf50;
  --color-success-hover: #45a049;
  --color-success-dark: #2e7d2e;
  --color-error: #f44336;
  --color-error-hover: #d32f2f;
  --color-info: #2196f3;
  --color-black: #000;
  --color-white: #fff;
  --color-gray-dark: #222;
  --color-gray-medium: #666;
  --color-gray-light: #444;
  --color-gray-lighter: #ccc;
  --color-border: #e0e0e0;
  --color-border-darker: #bbb;

  /* Backgrounds */
  --bg-primary: #795548;
  --bg-light: #f7f3ef;
  --bg-white: #ffffff;
  --bg-white-transparent-10: rgba(255, 255, 255, 0.75);
  --bg-light-transparent-10: rgba(247, 243, 239, 0.7);
  --bg-light-gray: #f5f5f5;
  --bg-lighter-gray: #e8e8e8;
  --bg-pale-green: #e8f5e8;
  --bg-pale-red: #ffebee;
  --bg-dark-gray: #323232;

  /* Text Colors */
  --text-primary: #795548;
  --text-dark: #333;
  --text-medium: #666;
  --text-light: #444;

  /* Opacities & Shadows */
  --opacity-primary: rgba(121, 85, 72, 0.08);
  --opacity-primary-focus: rgba(121, 85, 72, 0.1);
  --nut-cluster-bg: rgba(121, 85, 72, 0.8);
  --shadow-light: rgba(0, 0, 0, 0.1);
  --shadow-medium: rgba(0, 0, 0, 0.15);
  --shadow-toast: rgba(0, 0, 0, 0.25);
  --shadow-dark: rgba(0, 0, 0, 0.3);
  --shadow-modal: rgba(0, 0, 0, 0.5);
  --shadow-success: rgba(76, 175, 80, 0.3);

  /* Spacing */
  --space-xs: 4px;
  --space-sm: 6px;
  --space-md: 8px;
  --space-lg: 12px;
  --space-xl: 16px;
  --offset-sm: -14px;

  /* Sizes */
  --size-fab: 56px;
  --size-close-btn: 44px;
  --size-icon: 32px;
  --size-location: 35px;
  --size-width-sm: 20px;

  /* Border Radii */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 50%;
  --radius-fab: 28px;
  --radius-cluster: 50px;

  /* Fonts */
  --font-retro: 'Terminal', 'Monaco', 'Menlo', monospace;
  --font-emoji: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";

  /* Font Sizes */
  --font-size-xs: 11px;
  --font-size-sm: 12px;
  --font-size-md: 14px;
  --font-size-lg: 16px;
  --font-size-base: 16px;
  --font-size-13: 13px;
  --font-size-20: 20px;
  --font-size-24: 20px;
  --font-size-28: 28px;

  /* Z-index */
  --z-modal: 1050;
  --z-toast: 10000;
}

/* === Base Component Classes === */

/* Base Button Class */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-retro);
  font-size: var(--font-size-md);
  padding: var(--space-sm) var(--space-lg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-darker);
  background: var(--bg-light-gray);
  color: var(--text-dark);
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
  text-decoration: none;
  min-width: 80px;
  width: auto;
}

/* Button Modifiers */
.btn.primary {
  background: var(--bg-primary);
  color: var(--color-white);
  border-color: var(--color-primary);
}

.btn.primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.btn.secondary {
  background: var(--bg-white);
  color: var(--text-dark);
  border-color: var(--color-border);
}

.btn.secondary:hover:not(:disabled) {
  background: var(--bg-lighter-gray);
}

.btn.danger {
  background: none;
  border: none;
  color: var(--color-error-hover);
  padding: 0;
  font-size: var(--font-size-sm);
  font-weight: normal;
  text-decoration: underline;
  opacity: 0.8;
  min-width: auto;
}

.btn.danger:hover:not(:disabled) {
  opacity: 1;
  color: #b71c1c;
}

.btn.small {
  padding: var(--space-xs) var(--space-sm);
  font-size: var(--font-size-sm);
  min-width: auto;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn.active {
  background: var(--bg-success);
  border-color: var(--color-success);
  color: var(--color-black);
  box-shadow: 0 2px 4px var(--shadow-success);
}

.btn.active:hover:not(:disabled) {
  background: var(--color-success-hover);
}

/* Base Input Class */
.input {
  width: 100%;
  padding: var(--space-lg);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-retro);
  font-size: var(--font-size-base);
  transition: border-color 0.3s ease;
  box-sizing: border-box;
  background: var(--bg-white);
  color: var(--text-dark);
}

.input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--opacity-primary-focus);
}

/* Form Controls Font Inheritance */
select {
  font-family: var(--font-retro);
}

/* Input Modifiers */
.input.small {
  padding: var(--space-sm);
  font-size: var(--font-size-md);
}

.input.textarea {
  resize: vertical;
  min-height: 80px;
}

/* Base Card Class */
.card {
  background: var(--bg-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-lg);
  box-shadow: 0 1px 3px var(--shadow-light);
  transition: background-color 0.2s ease;
}

/* Card Modifiers */
.card.hover:hover {
  background: var(--bg-pale-green);
}

.card.overlay {
  background: var(--bg-white);
  box-shadow: 0 8px 32px var(--shadow-dark);
  border-radius: var(--radius-lg);
}

.card.compact {
  padding: var(--space-md);
}

/* === Layout === */
body {
  margin: 0;
  font-family: var(--font-retro);
  display: flex;
  min-height: 100vh;
}



#right-panel {
  position: absolute;
  top: 0;
  left: 0; /* Default mobile behavior */
  right: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  background: var(--bg-white);
}

#map {
  flex: 1;
  height: 100%;
  min-height: 400px;
}

/* === Inputs & Buttons === */
#icon-row {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  justify-content: center;
  margin-bottom: var(--space-md);
}

#shape-select, #paint-select {
  flex: 0 0 60px;
  font-size: var(--font-size-sm);
}

#icon-preview {
  flex: 0 0 32px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  image-rendering: -moz-crisp-edges;
}

.input-row {
  display: flex;
  gap: var(--space-sm);
}

#note-text {
  flex: 1;
  min-height: 40px;
  font-size: var(--font-size-md);
  padding: var(--space-sm);
}

.button-row {
  display: flex;
  gap: var(--space-sm);
}

.button-row button {
  flex: 1;
}

/* Desktop controls in input row */
.desktop-controls {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xs);
  margin-top: var(--space-xs);
}

#drop-button {
  font-size: var(--font-size-13);
  padding: var(--space-sm) var(--space-md);
  min-width: 80px;
  width: auto;
}

#char-count {
  font-size: var(--font-size-xs);
  color: var(--text-medium);
  text-align: center;
  white-space: nowrap;
}

.button-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: fit-content;
  min-height: 0;
}

/* Info row for location and login */
.info-row {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
}

#char-count {
  font-size: var(--font-size-xs);
  color: var(--text-medium);
  text-align: center;
  white-space: nowrap;
}

#logout-button {
  margin-top: var(--space-sm);
  padding: var(--space-sm);
  width: 100%;
  font-size: var(--font-size-md);
}

/* Mobile info row styling - consistent between desktop and mobile */
.mobile-info-row p {
  margin: var(--space-xs) 0;
  font-size: var(--font-size-sm);
  color: var(--text-light);
}

/* === Nuts Container Scrolling === */
#nuts-container {
  flex: 1; /* Take up remaining space in flex container */
  min-height: 0; /* Allow flex item to shrink below content size */
  max-height: calc(60vh); /* Limit height to prevent viewport overflow */
  overflow-y: auto; /* Enable vertical scrolling */
  overflow-x: hidden; /* Prevent horizontal scrolling */
}

/* === User location marker === */
.user-location-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--size-location);
  width: var(--size-location);
  height: var(--size-location);
}

/* === Nut markers === */
.nut-marker-icon {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--size-icon);
  height: var(--size-icon);
  /* Ensure pixelated rendering for canvas icons */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  image-rendering: -moz-crisp-edges;
  text-shadow:
      -2px -2px 0 var(--color-white),
      2px -2px 0 var(--color-white),
      -2px 2px 0 var(--color-white),
      2px 2px 0 var(--color-white),
      2px 2px 5px var(--color-black);
}

.leaf-badge {
  position: absolute;
  top: var(--offset-sm);
  right: var(--offset-sm);
  min-width: var(--size-width-sm);
  height: var(--size-width-sm);
  background: var(--color-success);
  color: var(--color-white);
  font-size: var(--font-size-13);
  font-weight: bold;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 4px var(--shadow-medium);
  border: 1px solid var(--bg-white);
  z-index: 2;
  text-shadow: 0 1px 2px var(--color-gray-dark);
}

/* === Static Text for Nut Messages === */
.nut-text-container {
  position: absolute;
  top: 35px;
  left: 50%;
  transform: translateX(-50%);
  width: 80px;
  height: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nut-text {
  display: block;
  font-size: var(--font-size-md);
  font-weight: bold;
  color: var(--text-dark);
  white-space: nowrap;
  text-overflow: ellipsis;
  overflow: hidden;
  text-align: center;
  text-shadow: none; /* Remove inherited white outline from emoji */
}

/* === Author and Leaf Styling === */
.author-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.author-name {
  color: var(--color-primary);
  font-weight: 500;
}

.leaf-message {
  margin-left: 15px;
  padding-right: 15px; /* Reduce effective width to match reply textbox (35 → 33 chars) */
  box-sizing: border-box;
}

.leaf-message > span:first-child {
  font-family: var(--font-retro);
  font-size: 14px; /* Match reply box font size exactly */
  line-height: 1.2; /* Match reply box line height */
  word-wrap: break-word;
  overflow-wrap: break-word;
  white-space: normal;
  word-break: break-word;
}

/* Allow author text and buttons to use retro font like the rest of the interface */
.author-line,
.author-line span,
.author-line .author-name {
  /* Remove Arial override to use retro font like left panel */
}

.popup-delete-text {
  font-family: var(--font-retro); /* Use retro font to match left panel consistency */
}

/* === Sprite Icon Styling === */
.sprite-icon {
  width: 32px;
  height: 32px;
  vertical-align: middle;
}

/* === Loading Indicator Styling === */
.loading-indicator {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.9);
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #666;
}

.loading-spinner {
  width: 16px;
  height: 16px;
  border: 2px solid #f3f3f3;
  border-top: 2px solid #795548;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* === Zoom-in message for performance === */
.zoom-in-message {
  position: absolute;
  top: 10%;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.95);
  color: var(--text-dark);
  padding: var(--space-xl) var(--font-size-24);
  border-radius: var(--radius-md);
  border: 2px solid var(--color-success);
  font-weight: bold;
  font-size: var(--font-size-lg);
  text-align: center;
  z-index: var(--z-modal); /* Higher z-index to ensure it appears above Leaflet elements */
  box-shadow: 0 4px 12px var(--shadow-dark);
  pointer-events: auto;
}

/* Clusters */
.nut-cluster-icon {
  background-color: var(--nut-cluster-bg);
  color: var(--color-white);
  text-align: center;
  line-height: 30px;
  border-radius: 20px;
  font-weight: bold;
  font-size: var(--font-size-md);
  padding: 2px;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
}

.popup-delete-text {
    color: var(--color-error);
    cursor: pointer;
    font-size: var(--font-size-sm);
    margin-left: var(--space-xs);
    text-decoration: underline;
}


/* === Login Page Styles === */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--bg-light) 0%, #e8ddd4 100%);
}

.login-container {
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-container h1 {
  color: var(--text-primary);
  margin-bottom: var(--space-sm);
  font-size: var(--font-size-lg);
}

.login-container p {
  color: var(--text-medium);
  margin-bottom: var(--space-xl);
  font-size: var(--font-size-md);
}

#login-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-xl);
}

#login-form input {
  /* Uses .input base class */
}

#login-confirm-password {
  transition: all 0.3s ease;
  overflow: hidden;
}

#login-confirm-password.show {
  display: block !important;
  animation: slideDown 0.3s ease;
}

#login-confirm-password.hide {
  animation: slideUp 0.3s ease;
}

@keyframes slideDown {
  from {
    opacity: 0;
    max-height: 0;
    padding: 0;
    margin: 0;
  }
  to {
    opacity: 1;
    max-height: 60px;
    padding: var(--space-lg);
    margin: 0;
  }
}

@keyframes slideUp {
  from {
    opacity: 1;
    max-height: 60px;
    padding: var(--space-lg);
    margin: 0;
  }
  to {
    opacity: 0;
    max-height: 0;
    padding: 0;
    margin: 0;
  }
}

#auth-submit-button {
  /* Uses .btn.primary base class */
}

.error-message {
  color: var(--color-error-hover);
  font-size: var(--font-size-md);
  margin: 0;
  padding: var(--space-md);
  background: var(--bg-pale-red);
  border-radius: 4px;
  border-left: 4px solid var(--color-error-hover);
  display: none;
}

.mode-toggle {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--color-border);
}

.mode-toggle p {
  margin: 0;
  font-size: var(--font-size-md);
  color: var(--text-medium);
}

.mode-toggle a {
  color: var(--text-primary);
  text-decoration: none;
  font-weight: bold;
  transition: color 0.3s ease;
}

.mode-toggle a:hover {
  color: var(--color-primary-hover);
  text-decoration: underline;
}

/* === Nut Box Styles === */
.nut-box {
  display: flex;
  flex-direction: column;
  margin: var(--space-md) 0;
  cursor: pointer;
}

.nut-list-main {
  font-size: inherit;
  font-weight: normal;
  margin-bottom: var(--space-md);
}

.nut-details-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: var(--space-xs);
}

.nut-author-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--font-size-sm);
  opacity: 0.8;
  margin-top: var(--space-xs);
}

.nut-time,
.nut-coords,
.nut-replies {
  font-size: var(--font-size-sm);
  opacity: 0.8;
}

/* Ensure emoji rendering in nut coordinates */
.nut-coords {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  font-variant-emoji: emoji;
  text-rendering: optimizeLegibility;
}

.delete-button {
  /* Uses .btn.danger base class */
}

/* === Priority Controls === */
.priority-controls {
    margin-top: var(--space-xl);
}

.priority-controls-header {
    margin-bottom: var(--space-md);
}

.priority-controls-header h3 {
    margin: 0;
    font-size: var(--font-size-md);
    font-weight: 600;
    color: var(--text-dark);
    text-align: center;
}

.priority-buttons {
    display: flex;
    gap: var(--space-xs);
    justify-content: center;
    flex-wrap: wrap;
}

.priority-btn {
    flex: 1;
    min-width: 0;
    border: 2px solid var(--color-border);
}

.priority-btn:hover {
    background: var(--bg-pale-green);
    border-color: var(--color-success);
    color: var(--color-success-dark);
}

.priority-btn.active {
    background: var(--bg-success);
    border-color: var(--color-success);
    color: var(--color-white);
    box-shadow: 0 2px 4px var(--shadow-success);
}

.priority-btn.active:hover {
    background: var(--color-success-hover);
}

/* === Toast Notifications === */
.toast-notification {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-100px);
    background-color: var(--bg-dark-gray);
    color: var(--color-white);
    padding: var(--space-lg) 24px;
    border-radius: 4px;
    font-size: var(--font-size-md);
    font-weight: 500;
    z-index: var(--z-toast);
    opacity: 0;
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px var(--shadow-toast);
    max-width: 90vw;
    text-align: center;
    pointer-events: none;
}

.toast-show {
    opacity: 1 !important;
    transform: translateX(-50%) translateY(0) !important;
}

.toast-success {
    background-color: var(--color-success);
}

.toast-error {
    background-color: var(--color-error);
}

.toast-info {
    background-color: var(--color-info);
}

/* === Modal Styles === */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--shadow-modal);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: var(--z-toast);
}

.modal-overlay.show {
    display: flex;
}

.modal-content {
    max-width: 400px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--bg-white);
    border-radius: 16px;
    box-shadow: 0 8px 32px var(--shadow-dark);
}

/* === Nut Thread Modal Styles === */
/* Mobile-first responsive fullscreen modal */
.thread-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--shadow-modal);
    display: none; /* Hidden by default, shown when thread is active */
    justify-content: center;
    align-items: center;
    z-index: var(--z-toast);
}

/* Mobile fullscreen styles */
@media (max-width: 768px) {
    .thread-modal-overlay {
        /* Mobile: Already fullscreen */
    }
}

.thread-modal-content {
    width: 100%;
    height: 100%;
    max-width: 600px;
    max-height: 100vh;
    background: transparent;
    border-radius: 0;
    box-shadow: none;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.thread-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 16px;
    border-bottom: 1px solid var(--color-border);
    background: var(--bg-white-transparent-10);
    flex-shrink: 0;
}

#thread-header-info {
    flex: 1;
    min-width: 0;
}

.thread-close-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-medium);
    cursor: pointer;
    padding: 4px;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.thread-close-btn:hover {
    background: var(--bg-light-gray);
    color: var(--text-dark);
}

.thread-content {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--bg-light-transparent-10);
}

.thread-footer {
    border-top: 1px solid var(--color-border);
    background: var(--bg-white-transparent-10);
    padding: 16px;
    flex-shrink: 0;
}

.thread-reply-textarea {
    width: 100%;
    min-height: 60px;
    max-height: 120px;
    resize: vertical;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 8px;
    font-family: var(--font-retro);
    font-size: var(--font-size-md);
    background: var(--bg-white);
    color: var(--text-dark);
    box-sizing: border-box;
    transition: border-color 0.3s ease;
}

.thread-reply-textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--opacity-primary-focus);
}

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

.modal-header h2 {
    margin: 0;
    color: var(--text-dark);
    font-size: var(--font-size-20);
    font-weight: 600;
}

.modal-close-btn {
    background: none;
    border: none;
    font-size: var(--font-size-24);
    color: var(--text-medium);
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-full);
    transition: background-color 0.2s ease;
}

.modal-close-btn:hover {
    background: var(--bg-light-gray);
    color: var(--text-dark);
}

.modal-body {
    padding: 20px;
}

.form-group {
    margin-bottom: var(--font-size-20);
}

.form-group label {
    display: block;
    margin-bottom: var(--space-md);
    font-weight: 500;
    color: var(--text-dark);
    font-size: var(--font-size-md);
}

.form-group input {
    /* Uses .input base class */
}

.modal-actions {
    display: flex;
    gap: var(--space-lg);
    justify-content: flex-end;
}

.modal-btn.primary {
    /* Uses .btn.primary base class */
}

.modal-btn.secondary {
    /* Uses .btn.secondary base class */
}

/* === Desktop Modals & FABs === */
/* Desktop left panel container */
#left-panel {
    position: fixed;
    left: 0;
    top: 0;
    height: 100vh;
    width: 320px;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    z-index: 1100;
}

/* Desktop inline modal positioning */
.desktop-modal {
    width: 100%;
    display: none; /* Hidden by default, shown via media query */
}

.desktop-modal-content {
    width: 100%;
    max-height: 100%;
    height:auto;
    background: var(--bg-light);
    box-shadow: 2px 0 8px var(--opacity-primary);
    display: flex;
    flex-direction: column;
    padding: 18px;
    gap: var(--space-xl);
    box-sizing: border-box;
}

/* Desktop modal flex properties */
#add-nut-modal {
    flex-shrink: 0;
    min-height: 200px;
}

#view-nuts-modal {
    flex: 1;
    min-height: 0;
}

#view-nuts-modal .desktop-modal-content {
    /*padding: var(--space-md);*/
    gap: var(--space-md);
    /*max-height: 100%;*/
}

/* === Media Queries (Consolidated) === */
@media (max-width: 768px) {
  body {
    flex-direction: column;
  }

  #right-panel {
    order: 1;
    height: 100vh;
    left: 0 !important; /* Force override of desktop positioning on mobile */
  }

  body {
    min-width: 0;
  }





  .priority-controls-header h3 {
    display: none; /* Hide sort nuts header on mobile for more compact layout */
  }

  .priority-controls {
    padding: 0px; /* Remove padding for ultra-compact mobile layout */
    margin-top: 0px; /* Remove top margin for tighter spacing */
  }

  .priority-controls-header {
    margin: 0px; /* Remove all margins for ultra-compact spacing */
  }

  .nut-box {
    margin: 2px 0; /* Reduce margins for tighter spacing between nut items */
  }

  .input-row {
    gap: var(--space-xs); /* Reduce gap for mobile */
  }

  /* Hide left panel on mobile */
  #left-panel {
    position: absolute;
    left: -9999px;
  }

  /* Desktop modals responsive behavior on mobile */
  .desktop-modal {
    display: none !important;
  }

  .desktop-modal.show {
    display: flex !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: var(--shadow-modal) !important;
    z-index: var(--z-modal) !important;
    justify-content: center;
    align-items: center;
  }

  /* Override for modals inside left-panel to show as overlay even when parent is hidden */
  #left-panel .desktop-modal.show {
    display: flex !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    background: var(--shadow-modal) !important;
    z-index: var(--z-modal) !important;
    justify-content: center !important;
    align-items: center !important;
  }

  .desktop-modal.show .desktop-modal-content {
    width: 95%;
    height: 95vh;
    background: var(--bg-white);
    border-radius: 16px;
    box-shadow: 0 8px 32px var(--shadow-dark);
  }

  /* Hide FABs when desktop modal is open */
  .desktop-modal.show ~ #mobile-fabs {
    display: none;
  }

  /* Override height for add-nut-modal on mobile to prevent filling screen */
  #add-nut-modal.desktop-modal.show .desktop-modal-content {
    height: auto;
    max-height: 80vh;
  }

  /* Make desktop controls stack for mobile */
  .desktop-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-xs);
    margin-top: var(--space-xs);
  }

  #note-text {
    min-height: 36px;
    font-size: var(--font-size-md);
  }

  #drop-button {
    font-size: var(--font-size-13);
    padding: var(--space-sm) var(--space-md);
    width: 80px;
  }

  #char-count {
    font-size: var(--font-size-xs);
  }



  /* Map popup scroll for mobile */
  .leaves-list {
      max-height: 200px; /* Keep mobile-specific height */
      overflow-y: auto;
      padding-right: var(--space-xs); /* avoid cutting off scroll */
  }

    /* Mobile modals and FABs - hide on desktop by default */
    .mobile-modal {
        display: none;
    }

    #mobile-fabs {
        display: flex;
        flex-direction: column;
        position: fixed;
        right: 20px;
        bottom: 80px; /* Above bottom safe area */
        gap: var(--space-lg);
        z-index: 1000;
    }

    .mobile-fab {
        width: var(--size-fab);
        height: var(--size-fab);
        border-radius: var(--radius-fab);
        background: var(--bg-primary);
        color: var(--color-white);
        border: none;
        font-size: var(--font-size-24);
        box-shadow: 0 4px 8px var(--shadow-dark);
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: center;
        transition: all 0.2s ease;
    }

    .mobile-fab:hover {
        background: var(--color-primary-hover);
        transform: scale(1.05);
    }

    .mobile-fab:active {
        transform: scale(0.95);
    }

    /* Mobile modals styling */
    .mobile-modal {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        width: 100vw;
        max-height: 100vh;
        height: auto;
        background: var(--shadow-modal);
        z-index: var(--z-toast);
    }

    .desktop-modal.mobile-modal.show {
        /* Best practice: Combined selector for highest specificity -
           explicitly override ALL desktop modal properties */
        /*display: flex !important;*/
        justify-content: center !important;
        align-items: center !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        /*width: 100vw !important;*/
        max-height: 100vh !important;
        max-width: 100vw !important;
        background: var(--shadow-modal) !important;
        border: none !important;
        z-index: var(--z-toast) !important;
    }

    .mobile-modal-content {
        width: 95%;
        max-width: 100vw;
        max-height: 80vh;
        height: auto;
        background: var(--bg-white);
        border-radius: 16px;
        /*display: flex;
        flex-direction: column;*/
        box-shadow: 0 8px 32px var(--shadow-dark);
    }

    .mobile-modal-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--space-xl) 20px;
        border-bottom: 1px solid var(--color-border);
        flex-shrink: 0;
    }

    .mobile-modal-header h2 {
        margin: 0;
        font-size: var(--font-size-20);
        font-weight: 600;
        color: var(--text-dark);
    }

    .mobile-modal-close-btn {
        background: none;
        border: none;
        font-size: var(--font-size-28);
        color: var(--text-medium);
        cursor: pointer;
        padding: var(--space-xs);
        width: var(--size-close-btn);
        height: var(--size-close-btn);
        border-radius: var(--radius-full);
        display: flex;
        align-items: center;
        justify-content: center;
        transition: background-color 0.2s ease;
    }

    .mobile-modal-close-btn:hover {
        background: var(--bg-light-gray);
        color: var(--text-dark);
    }

    .mobile-modal-body {
        /*flex: 1;*/
        overflow-y: hidden;
        padding: 10px;
        /*display: flex;
        flex-direction: column;
        gap: var(--space-lg);*/
    }

    /* Mobile input modal specific styles */
    #add-nut-modal .input-row {
        display: flex;
        gap: var(--space-sm);
        flex-shrink: 0;
    }

    #add-nut-modal #icon-select {
        flex: 0 0 60px;
        font-size: var(--size-icon);
    }

    #add-nut-modal #note-text {
        flex: 1;
        min-height: 80px;
        font-size: var(--font-size-base); /* Prevents zoom on iOS */
        padding: var(--space-lg);
        border: 2px solid var(--color-border);
        border-radius: var(--radius-md);
        resize: none;
    }

    #add-nut-modal .desktop-controls {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: var(--space-xs);
        flex-shrink: 0;
    }

    /*#add-nut-modal #drop-button {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: var(--font-size-lg);
        padding: 14px 24px;
        border-radius: var(--radius-md);
        border: 1px solid var(--color-border-darker);
        background: var(--bg-primary);
        color: var(--color-white);
        cursor: pointer;
        min-width: 120px;
        transition: background-color 0.2s ease;
    }

    #add-nut-modal #drop-button:hover {
        background: var(--color-primary-hover);
    }*/

    #add-nut-modal #char-count {
        font-size: var(--font-size-md);
        color: var(--text-medium);
        text-align: center;
        font-weight: 500;
    }

    .mobile-info-row {
        flex-shrink: 0;
        margin-top: var(--space-md);
        padding-top: var(--space-md);
        border-top: 1px solid var(--color-border);
    }

    .mobile-info-row p {
        margin: var(--space-xs) 0;
        font-size: var(--font-size-sm);
        color: var(--text-light);
    }

    /* Mobile nuts modal specific styles */
    .mobile-priority-controls {
        flex-shrink: 0;
        background: var(--bg-light-gray);
        border-radius: var(--radius-md);
        padding: var(--space-xl);
        margin-bottom: var(--space-md);
    }

    .mobile-priority-buttons {
        display: flex;
        gap: var(--space-md);
        justify-content: center;
    }

    .mobile-priority-btn {
        flex: 1;
        border: 2px solid var(--color-border);
        display: flex;
        align-items: center;
        justify-content: center;
        text-align: center;
    }

    .mobile-priority-btn:hover {
        background: var(--bg-pale-green);
        border-color: var(--color-success);
        color: var(--color-success-dark);
    }

    .mobile-priority-btn.active {
        background: var(--color-success);
        border-color: var(--color-success);
        color: var(--color-white);
        box-shadow: 0 2px 4px var(--shadow-success);
    }

    /* Hide FABs when modal is open */
    .mobile-modal.show ~ #mobile-fabs {
        display: none;
    }

    /* Safe area handling for mobile devices */
    .mobile-modal-content {
        padding-top: env(safe-area-inset-top, 0px);
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    #mobile-fabs {
        bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    }
}

/* === Leaflet Popup Width Override === */
.leaflet-popup-content-wrapper {
    min-width: 340px;
}

/* === Popup Replies Scrolling === */
.leaves-list {
    max-height: 60vh; /* 60% of viewport height for desktop */
    overflow-y: auto;
    padding-right: var(--space-xs);
}

/* === Reply Form Textarea Styling === */
.reply-form textarea {
    font-size: 14px; /* Explicit font size to match leaf messages exactly */
    line-height: 1.2;
    width: 100%;
    max-width: 280px; /* Reduced to better accommodate 35-38 chars */
    resize: none;
    border: 2px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: 2px 4px; /* Minimal padding to match leaf message appearance */
    background: var(--bg-white);
    color: var(--text-dark);
    word-wrap: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    word-break: break-word;
    box-sizing: border-box;
}

/* Popup reply textarea specific styling */
.popup-reply-textarea {
    width: 100%;
    max-width: 320px;
    resize: none;
}

.reply-form textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--opacity-primary-focus);
}

/* === Game HUD Overlay === */
#game-hud {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 1200;
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    pointer-events: none;
}

#nectar-hud {
    background: var(--bg-white);
    border: 2px solid var(--text-dark);
    border-radius: var(--radius-md);
    padding: var(--space-sm);
    box-shadow: 0 4px 8px var(--shadow-medium);
    min-width: 140px;
    pointer-events: auto;
    display: flex;
    flex-direction: row;
    align-items: center;
}

.nectar-caption {
    font-size: var(--font-size-s);
    font-weight: bold;
    color: var(--text-dark);
    margin-bottom: var(--space-xs);
}

#nectar-bar-container {
    position: relative;
    width: 100px;
    height: 20px;
    background: #ddd;
    border: 1px solid var(--color-border-darker);
    border-radius: 3px;
    overflow: hidden;
}

#nectar-bar-fill {
    height: 100%;
    background: #ffeb3b;
    transition: width 0.3s ease;
    border-radius: 2px;
}

#nectar-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: var(--font-size-xs);
    font-weight: bold;
    color: var(--text-dark);
    text-shadow: 0px 0px 2px var(--bg-white);
    pointer-events: none;
    white-space: nowrap;
}

#amber-hud {
    background: var(--bg-white);
    border: 2px solid var(--text-dark);
    border-radius: var(--radius-md);
    padding: var(--space-xs) var(--space-sm);
    box-shadow: 0 4px 8px var(--shadow-medium);
    pointer-events: auto;
}

#amber-text {
    font-size: var(--font-size-xs);
    font-weight: bold;
    color: var(--text-dark);
    text-align: center;
    display: inline;
}

/* === Desktop Specific Styles === */
@media (min-width: 769px) {
    /* Show desktop modals */
    .desktop-modal {
        display: block !important;
    }

    /* Show mobile modal headers on desktop (modified to display title) */
    .mobile-modal-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: var(--space-lg) var(--space-xl);
        border-bottom: 1px solid var(--color-border);
        flex-shrink: 0;
        background: var(--bg-light);
    }

    .mobile-modal-header h2 {
        margin: 0;
        font-size: var(--font-size-lg);
        font-weight: 600;
        color: var(--text-dark);
    }

    /* Hide close button on desktop since modals are always visible */
    .mobile-modal-header .mobile-modal-close-btn {
        display: none;
    }

    /* Position right panel */
    #right-panel {
        left: 320px;
    }

    /* Show mobile-priority-buttons and mobile-priority-btn */
    .mobile-priority-buttons {
        display: flex;
        gap: var(--space-xs);
        justify-content: center;
    }

    .mobile-priority-btn {
        flex: 1;
        min-width: 0;
        border: 2px solid var(--color-border);
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .mobile-priority-btn:hover {
        background: var(--bg-pale-green);
        border-color: var(--color-success);
        color: var(--color-success-dark);
    }

    .mobile-priority-btn.active {
        background: var(--color-success);
        border-color: var(--color-success);
        color: var(--color-white);
        box-shadow: 0 2px 4px var(--shadow-success);
    }

    .mobile-priority-btn.active:hover {
        background: var(--color-success-hover);
    }
}
