:root {
  --primary: #C0392B;
  --primary-hover: #a93226;
  --secondary: #2C3E50;
  --bg-light: #F8F9FA;
  --white: #FFFFFF;
  --text: #333333;
  --text-muted: #777777;
  --border: #e0e0e0;
  --border-focus: #C0392B;
  --success: #27ae60;
  --danger: #c0392b;
  --shadow: 0 2px 10px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  --radius: 10px;
  --radius-sm: 6px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  height: 100vh;
  overflow: hidden;
  color: var(--text);
  background: var(--bg-light);
}

#app { display: flex; height: 100vh; }

#sidebar {
  width: 380px;
  min-width: 380px;
  background: var(--white);
  color: var(--text);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transition: margin-left 0.3s ease;
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

#sidebar.collapsed { margin-left: -380px; }

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: var(--secondary);
  color: var(--white);
}

.sidebar-header h1 {
  font-size: 17px;
  font-weight: 700;
  color: var(--white);
  white-space: nowrap;
}

#toggle-sidebar {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

#toggle-sidebar:hover { color: var(--white); background: rgba(255,255,255,0.1); }

.sidebar-tabs {
  display: flex;
  background: var(--bg-light);
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  flex: 1;
  padding: 12px 6px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab-btn:hover { color: var(--secondary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-content { display: none; flex: 1; overflow-y: auto; padding: 14px; }
.tab-content.active { display: flex; flex-direction: column; gap: 10px; }

.search-box { display: flex; gap: 8px; }
.search-box input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-light);
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}
.search-box input:focus { border-color: var(--border-focus); }
.search-box input::placeholder { color: #aaa; }
.search-box button {
  padding: 10px 16px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 14px;
  transition: background 0.2s;
}
.search-box button:hover { background: var(--primary-hover); }

#search-results { display: flex; flex-direction: column; gap: 6px; }

.search-result-item {
  padding: 12px 14px;
  background: var(--bg-light);
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.2s;
}
.search-result-item:hover { border-color: var(--primary); background: #fff5f5; }
.search-result-item .result-type {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--primary);
  letter-spacing: 1px;
  font-weight: 700;
}
.search-result-item .result-name { font-weight: 600; margin-top: 3px; font-size: 14px; }
.search-result-item .result-detail { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.action-btn {
  padding: 10px 18px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.2s;
  text-align: center;
}
.action-btn:hover { background: var(--primary-hover); }
.action-btn.secondary { background: var(--secondary); }
.action-btn.secondary:hover { background: #1a252f; }
.action-btn.danger { background: var(--danger); }
.action-btn.danger:hover { background: #a93226; }

#street-list, #building-list { display: flex; flex-direction: column; gap: 6px; }

.list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--bg-light);
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all 0.2s;
}
.list-item:hover { border-color: var(--primary); background: #fff5f5; }
.list-item .item-info { flex: 1; min-width: 0; }
.list-item .item-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list-item .item-detail { font-size: 11px; color: var(--text-muted); margin-top: 1px; }
.list-item .item-actions { display: flex; gap: 4px; }
.list-item .item-actions button {
  padding: 5px 8px;
  background: var(--white);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}
.list-item .item-actions button:hover { border-color: var(--primary); color: var(--primary); }
.list-item .item-actions button.del:hover { border-color: var(--danger); color: var(--danger); }

.filter-bar select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg-light);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.2s;
}
.filter-bar select:focus { border-color: var(--border-focus); }

.settings-section {
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.settings-section h3 {
  font-size: 12px;
  color: var(--primary);
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  font-weight: 700;
}
.settings-section label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 500;
}
.settings-section input[type="number"] {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-light);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-top: 3px;
  outline: none;
  transition: border-color 0.2s;
}
.settings-section input[type="number"]:focus { border-color: var(--border-focus); }
.settings-section input[type="file"] {
  width: 100%;
  padding: 10px;
  background: var(--bg-light);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12px;
  margin-bottom: 10px;
  cursor: pointer;
}
#upload-status { font-size: 12px; color: var(--success); margin-top: 4px; font-weight: 600; }

#map { flex: 1; background: #e8e8e8; }

.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}
.modal.hidden { display: none; }
.modal-content {
  background: var(--white);
  color: var(--text);
  border-radius: var(--radius);
  width: 460px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h2 { font-size: 16px; color: var(--secondary); font-weight: 700; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
}
.modal-close:hover { color: var(--primary); background: #ffeaea; }
#modal-body { padding: 22px; }
.modal-footer {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 5px;
  font-weight: 600;
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-light);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--border-focus); }
.form-group textarea { min-height: 60px; resize: vertical; font-family: inherit; }
.form-row { display: flex; gap: 14px; }
.form-row .form-group { flex: 1; }

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 12px 22px;
  background: var(--secondary);
  color: var(--white);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  z-index: 3000;
  transition: all 0.3s;
  box-shadow: var(--shadow-lg);
}
.toast.hidden { opacity: 0; pointer-events: none; transform: translateY(20px); }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

.leaflet-popup-content-wrapper {
  background: var(--white);
  color: var(--text);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.leaflet-popup-tip { background: var(--white); }
.leaflet-popup-content { font-size: 13px; line-height: 1.6; margin: 12px 16px; }
.popup-title { font-weight: 700; color: var(--secondary); margin-bottom: 4px; font-size: 14px; }
.popup-detail { font-size: 12px; color: var(--text-muted); }
.popup-actions { margin-top: 10px; display: flex; gap: 6px; }
.popup-actions button {
  padding: 6px 14px;
  background: var(--bg-light);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
  transition: all 0.2s;
}
.popup-actions button:hover { background: var(--primary); color: white; border-color: var(--primary); }

.street-color-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.building-marker {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  color: white;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.mode-indicator {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 24px;
  background: var(--secondary);
  color: white;
  border-radius: 30px;
  font-size: 13px;
  font-weight: 600;
  z-index: 1500;
  display: none;
  box-shadow: var(--shadow-lg);
}
.mode-indicator.active { display: block; }

.leaflet-control-zoom a {
  background: var(--white) !important;
  color: var(--secondary) !important;
  border-color: var(--border) !important;
  font-weight: 700;
}
.leaflet-control-zoom a:hover {
  background: var(--bg-light) !important;
  color: var(--primary) !important;
}

.empty-state {
  text-align: center;
  padding: 30px 20px;
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 36px; margin-bottom: 10px; }
.empty-state p { font-size: 13px; }

@media (max-width: 768px) {
  #sidebar { width: 100%; min-width: 100%; }
  #sidebar.collapsed { margin-left: -100%; }
}

.sidebar-header-actions { display: flex; gap: 4px; align-items: center; }

.admin-login-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.8);
  font-size: 16px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}
.admin-login-btn:hover { color: var(--white); background: rgba(255,255,255,0.1); }
.admin-login-btn.admin-active { color: var(--success); }

body:not(.is-admin) .tab-admin { opacity: 0.4; pointer-events: none; }
body:not(.is-admin) .tab-content-admin { display: none !important; }
body:not(.is-admin) .tab-content-admin.active { display: none !important; }
body:not(.is-admin) #tab-search.active { display: flex !important; }

body:not(.is-admin) .popup-actions { display: none; }

.business-marker {
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: auto;
}

.business-marker-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  color: white;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.35);
}

.business-marker-label {
  margin-top: 2px;
  padding: 2px 6px;
  background: rgba(44, 62, 80, 0.9);
  color: white;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
  max-width: 90px;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
  line-height: 1.3;
}

.house-marker {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  color: white;
  border: 2px solid white;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  background: #555;
}

.charger-marker {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: white;
  border: 2px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  background: #27ae60;
}

/* ==================== PLAYER VIEW ==================== */

body.player-view { background: #e8e8e8; }
body.player-view #map { width: 100%; height: 100vh; position: absolute; top: 0; left: 0; }

#search-overlay {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 1100;
  width: 360px;
}

.search-overlay-box {
  display: flex;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.search-overlay-box input {
  flex: 1;
  padding: 12px 16px;
  border: none;
  font-size: 15px;
  outline: none;
  color: var(--text);
  background: var(--white);
}

.search-overlay-box input::placeholder { color: #aaa; }

.search-overlay-box button {
  padding: 12px 18px;
  background: var(--primary);
  color: white;
  border: none;
  cursor: pointer;
  font-size: 16px;
  transition: background 0.2s;
}

.search-overlay-box button:hover { background: var(--primary-hover); }

#search-results {
  background: var(--white);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 350px;
  overflow-y: auto;
  margin-top: -4px;
}

#search-results:empty { display: none; }

.search-overlay-item {
  padding: 10px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.search-overlay-item:last-child { border-bottom: none; }
.search-overlay-item:hover { background: #f5f5f5; }
.soi-type { font-size: 10px; text-transform: uppercase; color: var(--primary); font-weight: 700; letter-spacing: 0.5px; }
.soi-name { font-weight: 600; font-size: 14px; margin-top: 1px; }
.soi-detail { font-size: 12px; color: var(--text-muted); margin-top: 1px; }
.search-overlay-empty { padding: 16px; text-align: center; color: var(--text-muted); font-size: 13px; }

.admin-link {
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 1100;
  width: 40px;
  height: 40px;
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  text-decoration: none;
  transition: all 0.2s;
}

.admin-link:hover { background: var(--bg-light); transform: scale(1.05); }

/* Admin view overrides */
body.admin-view #map { flex: 1; background: #e8e8e8; }
body.admin-view #app { display: flex; height: 100vh; }
