/* ═══════════════════════════════════════════════════════════════
   PRICE MAP — Design System & Layout
   ═══════════════════════════════════════════════════════════════ */

/* ── Tokens ───────────────────────────────────────────────────── */
:root {
  /* Palette */
  --bg-base:       #0d1117;
  --bg-surface:    #161b22;
  --bg-elevated:   #1c2230;
  --bg-hover:      #21293a;
  --border:        rgba(255,255,255,0.07);
  --border-focus:  rgba(99,179,237,0.5);

  --accent-blue:   #3b82f6;
  --accent-green:  #22c55e;
  --accent-amber:  #f59e0b;
  --accent-red:    #ef4444;
  --accent-purple: #8b5cf6;

  --text-primary:  #e2e8f0;
  --text-secondary:#8892a4;
  --text-muted:    #4a5568;

  --cp-color:      #3b82f6;   /* collection point blue  */
  --farm-color:    #22c55e;   /* farm green             */

  /* Shape */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  16px;

  /* Sidebar widths */
  --sidebar-w:  300px;

  /* Header */
  --header-h:   60px;

  /* Transitions */
  --t-fast:  0.15s ease;
  --t-med:   0.25s ease;
}

/* ── Reset / Base ─────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

input, button { font-family: inherit; }

/* ── Scrollbar ────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ════════════════════════════════════════════════════════════════
   HEADER
   ════════════════════════════════════════════════════════════════ */
#app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--header-h);
  background: rgba(22,27,34,0.9);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1.5rem;
  z-index: 1000;
}

#brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

#brand-icon {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

#brand-name {
  font-size: 1rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent-blue), var(--accent-purple));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex: 1;
  justify-content: center;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 500;
  transition: all var(--t-fast);
}
.tool-btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: rgba(255,255,255,0.15);
}
.tool-btn.active {
  background: var(--accent-blue);
  border-color: var(--accent-blue);
  color: #fff;
  box-shadow: 0 0 16px rgba(59,130,246,0.35);
}
.tool-btn.active-cp {
  background: var(--cp-color);
  border-color: var(--cp-color);
  color: #fff;
  box-shadow: 0 0 16px rgba(59,130,246,0.35);
}
.tool-btn.active-farm {
  background: var(--farm-color);
  border-color: var(--farm-color);
  color: #fff;
  box-shadow: 0 0 12px rgba(34,197,94,0.35);
}

#mode-indicator {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}
#mode-label strong { color: var(--text-primary); }

/* ════════════════════════════════════════════════════════════════
   MAIN LAYOUT
   ════════════════════════════════════════════════════════════════ */
#app-main {
  display: flex;
  height: 100vh;
  padding-top: var(--header-h);
}

/* ════════════════════════════════════════════════════════════════
   SIDEBARS
   ════════════════════════════════════════════════════════════════ */
aside {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  width: var(--sidebar-w);
  flex-shrink: 0;
}

#sidebar-right {
  border-right: none;
  border-left: 1px solid var(--border);
  /* slide-in / slide-out */
  width: var(--sidebar-w);
  transition: width 0.25s ease, opacity 0.2s ease, border-color 0.25s ease;
  opacity: 1;
}

#sidebar-right.collapsed {
  width: 0;
  opacity: 0;
  border-color: transparent;
  pointer-events: none;
}

.sidebar-section {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  overflow-y: auto;
  flex: 1;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  flex-shrink: 0;
}

.sidebar-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
  padding-bottom: 0.25rem;
  flex-shrink: 0;
}
.sidebar-title svg { width: 14px; height: 14px; flex-shrink: 0; }

.sort-hint {
  margin-left: auto;
  font-size: 0.65rem;
  color: var(--accent-amber);
  font-weight: 400;
  letter-spacing: 0;
  text-transform: none;
}

/* ── Item List ────────────────────────────────────────────────── */
.item-list {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.empty-hint {
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.6;
  padding: 0.5rem 0;
}

/* Collection Point Card */
.cp-card {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: all var(--t-fast);
  position: relative;
  overflow: hidden;
}
.cp-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--cp-color);
  border-radius: 99px;
}
.cp-card:hover {
  background: var(--bg-hover);
  border-color: rgba(59,130,246,0.3);
}
.cp-card.selected {
  background: rgba(59,130,246,0.12);
  border-color: rgba(59,130,246,0.5);
}

.cp-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--cp-color);
  box-shadow: 0 0 6px rgba(59,130,246,0.6);
  flex-shrink: 0;
}

.cp-name {
  font-weight: 500;
  font-size: 0.82rem;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cp-coords {
  font-size: 0.68rem;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* Farm Row */
.farm-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: pointer;
  transition: all var(--t-fast);
  position: relative;
  overflow: hidden;
}
.farm-row::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--farm-color);
  border-radius: 99px;
}
.farm-row:hover {
  background: var(--bg-hover);
  border-color: rgba(34,197,94,0.3);
}
.farm-row.selected {
  background: rgba(34,197,94,0.1);
  border-color: rgba(34,197,94,0.4);
}

.farm-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--farm-color);
  box-shadow: 0 0 6px rgba(34,197,94,0.5);
  flex-shrink: 0;
}

.farm-info { flex: 1; min-width: 0; }
.farm-name {
  font-weight: 500;
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.farm-meta {
  display: flex;
  gap: 0.6rem;
  margin-top: 2px;
}
.farm-price {
  font-size: 0.72rem;
  color: var(--accent-amber);
  font-weight: 600;
}
.farm-dist {
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* Rank badge */
.rank-badge {
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--bg-base);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* ════════════════════════════════════════════════════════════════
   MAP
   ════════════════════════════════════════════════════════════════ */
#map-container {
  position: relative;
  overflow: hidden;
  flex: 1;        /* fill all space between the two sidebars */
  min-width: 0;   /* prevent flex blowout */
}

#map {
  width: 100%;
  height: 100%;
  background: #0d1117;
}

/* Crosshair overlay */
#map-crosshair {
  position: absolute;
  inset: 0;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  z-index: 500;
}
#map-crosshair.hidden { display: none; }

.crosshair-ring {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px dashed rgba(255,255,255,0.4);
  animation: spin 4s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.crosshair-text {
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 0.78rem;
  padding: 0.35rem 0.85rem;
  border-radius: 99px;
  border: 1px solid rgba(255,255,255,0.15);
}

/* ── Leaflet Custom Bubble Markers ───────────────────────────── */

/* Wrapper — zero-size anchor, centered + floated above the pin point */
.map-pin-wrapper {
  position: absolute;
  transform: translate(-50%, calc(-100% - 10px));
  filter:
    drop-shadow(0 4px 10px rgba(0,0,0,0.30))
    drop-shadow(0 1px 3px rgba(0,0,0,0.20));
  cursor: pointer;
}

/* Tail triangle pointing down */
.map-pin-wrapper::after {
  content: '';
  position: absolute;
  bottom: -9px;
  left: 50%;
  transform: translateX(-50%);
  width: 0; height: 0;
  border-left: 9px solid transparent;
  border-right: 9px solid transparent;
  border-top: 9px solid #fff;
}

/* Bubble shell */
.map-label {
  display: flex;
  align-items: stretch;
  background: #fff;
  border-radius: 12px;
  overflow: hidden;
  white-space: nowrap;
  min-width: 90px;
}

/* Colored icon column */
.map-label-icon {
  width: 42px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.cp-label   .map-label-icon { background: #2563eb; }
.farm-label .map-label-icon { background: #16a34a; }

/* Text column */
.map-label-text {
  padding: 7px 12px 7px 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
}
.map-label-name {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  font-weight: 700;
  color: #0f172a;
  line-height: 1.2;
}
.map-label-price {
  font-family: 'Inter', sans-serif;
  font-size: 11px;
  font-weight: 600;
  color: #16a34a;
  line-height: 1.2;
}
.map-label-sub {
  font-family: 'Inter', sans-serif;
  font-size: 10px;
  font-weight: 500;
  color: #94a3b8;
  line-height: 1.2;
}

/* Leaflet dark override — CartoDB dark tiles need no filter */
.leaflet-popup-content-wrapper {
  background: var(--bg-elevated) !important;
  color: var(--text-primary) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-md) !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.6) !important;
  font-family: 'Inter', sans-serif !important;
  font-size: 13px !important;
}
.leaflet-popup-tip { background: var(--bg-elevated) !important; }
.leaflet-popup-close-button { color: var(--text-secondary) !important; }

.popup-name { font-weight: 700; font-size: 0.9rem; margin-bottom: 4px; }
.popup-price { color: var(--accent-amber); font-weight: 600; font-size: 0.8rem; }
.popup-coords { color: var(--text-muted); font-size: 0.72rem; margin-top: 4px; }

/* ════════════════════════════════════════════════════════════════
   RIGHT SIDEBAR — FORM
   ════════════════════════════════════════════════════════════════ */
#form-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 2rem 1rem;
  text-align: center;
}
.empty-icon { font-size: 2.5rem; }
#form-empty-state p { color: var(--text-muted); font-size: 0.82rem; line-height: 1.6; }

/* ── Price History Chart ──────────────────────────────────────── */
#chart-section {
  border-top: 1px solid var(--border);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
#chart-section.hidden { display: none !important; }

.chart-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-secondary);
}
.chart-header svg { flex-shrink: 0; }

.chart-wrap {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0.75rem;
  position: relative;
  height: 160px;
}
.chart-wrap canvas {
  width: 100% !important;
  height: 100% !important;
}

.chart-no-data {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  padding: 0.25rem 0;
  line-height: 1.5;
}
.chart-no-data.hidden { display: none !important; }

/* Form */
#edit-form { display: flex; flex-direction: column; gap: 1rem; }
#edit-form.hidden { display: none !important; }

.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.65rem;
}

label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.label-sub {
  font-weight: 400;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
  font-size: 0.68rem;
}

input[type="text"],
input[type="number"] {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 0.55rem 0.65rem;
  font-size: 0.82rem;
  transition: border-color var(--t-fast), box-shadow var(--t-fast);
  width: 100%;
}
input:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,179,237,0.1);
}
input::placeholder { color: var(--text-muted); }

.input-prefix {
  display: flex;
  align-items: center;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color var(--t-fast);
}
.input-prefix:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99,179,237,0.1);
}
.input-prefix span {
  padding: 0 0.6rem;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  align-self: stretch;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}
.input-prefix input {
  border: none;
  background: transparent;
  border-radius: 0;
  flex: 1;
}
.input-prefix input:focus { box-shadow: none; }

/* Type badge */
.form-type-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  width: fit-content;
}
.badge-cp   { background: rgba(59,130,246,0.15); color: #93c5fd; border: 1px solid rgba(59,130,246,0.3); }
.badge-farm { background: rgba(34,197,94,0.12); color: #86efac; border: 1px solid rgba(34,197,94,0.3); }

/* Buttons */
.form-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.btn-primary {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.6rem 1rem;
  background: var(--accent-blue);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--t-fast);
  box-shadow: 0 0 16px rgba(59,130,246,0.25);
}
.btn-primary svg { width: 14px; height: 14px; }
.btn-primary:hover {
  background: #2563eb;
  box-shadow: 0 0 24px rgba(59,130,246,0.4);
}

.btn-ghost {
  padding: 0.6rem 0.85rem;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--t-fast);
}
.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.6rem 0.85rem;
  background: transparent;
  border: 1px solid rgba(239,68,68,0.3);
  color: var(--accent-red);
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  cursor: pointer;
  transition: all var(--t-fast);
}
.btn-danger svg { width: 14px; height: 14px; }
.btn-danger:hover {
  background: rgba(239,68,68,0.15);
  border-color: var(--accent-red);
}
.btn-danger.hidden { display: none !important; }

.hidden { display: none !important; }

/* ── Animations ───────────────────────────────────────────────── */
@keyframes fadeSlideIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.cp-card, .farm-row { animation: fadeSlideIn var(--t-med) both; }

/* Status pulse for cursor change when adding */
body.mode-add-cp  #map { cursor: crosshair; }
body.mode-add-farm #map { cursor: crosshair; }
