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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: #333;
}

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

/* Sidebar */
.sidebar {
  width: 360px;
  min-width: 360px;
  height: 100vh;
  background: #fff;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 1000;
  transition: margin-left 0.3s ease;
}

.sidebar.collapsed {
  margin-left: -360px;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: #2196F3;
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.sidebar-toggle {
  background: none;
  border: none;
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
}

.sidebar-toggle:hover {
  background: rgba(255,255,255,0.2);
}

/* Floating toggle when sidebar is collapsed */
.sidebar-toggle-floating {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 1001;
  background: #2196F3;
  color: #fff;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  display: none;
}

.sidebar.collapsed ~ #map .sidebar-toggle-floating,
.sidebar-toggle-floating.visible {
  display: block;
}

/* Auth Section */
.auth-section {
  background: #fafafa;
}

.auth-prompt {
  font-size: 12px;
  color: #888;
  margin-bottom: 8px;
}

.auth-buttons {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.auth-btn {
  padding: 8px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: all 0.2s;
  text-align: center;
}

.auth-btn:hover {
  border-color: #2196F3;
  background: #f0f7ff;
}

.auth-github {
  border-color: #333;
  color: #333;
}

.auth-github:hover {
  background: #333;
  color: #fff;
}

.auth-microsoft {
  border-color: #0078d4;
  color: #0078d4;
}

.auth-microsoft:hover {
  background: #0078d4;
  color: #fff;
}

.auth-user {
  display: flex;
  align-items: center;
  gap: 8px;
}

.auth-avatar {
  font-size: 20px;
  flex-shrink: 0;
}

.auth-name {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.auth-btn-sm {
  padding: 4px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
  font-size: 11px;
  color: #666;
  flex-shrink: 0;
}

.auth-btn-sm:hover {
  border-color: #e53935;
  color: #e53935;
}

/* Section Title Row */
.section-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.section-title-row .section-title {
  margin-bottom: 0;
}

/* Itinerary Action Buttons */
.itinerary-actions {
  display: flex;
  gap: 4px;
}

.btn-action {
  padding: 4px 12px;
  border: none;
  border-radius: 6px;
  background: #2196F3;
  color: #fff;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.btn-action:hover {
  background: #1976D2;
}

.btn-action-sm {
  padding: 3px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 11px;
  color: #666;
}

.btn-action-sm:hover {
  border-color: #2196F3;
  color: #2196F3;
}

/* Editing Indicator */
.editing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin-top: 8px;
  background: #e3f2fd;
  border-radius: 8px;
  font-size: 12px;
  color: #1565c0;
}

.editing-indicator span {
  font-weight: 600;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Saved Itineraries */
.saved-list {
  list-style: none;
}

.saved-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  margin-bottom: 4px;
  background: #f9f9f9;
  border-radius: 8px;
  transition: background 0.15s;
}

.saved-item:hover {
  background: #f0f7ff;
}

.saved-item-info {
  flex: 1;
  min-width: 0;
}

.saved-item-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-item-meta {
  font-size: 11px;
  color: #999;
  margin-top: 2px;
}

.saved-item-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
  margin-left: 8px;
}

.btn-load {
  padding: 4px 10px;
  border: 1px solid #2196F3;
  border-radius: 6px;
  background: #fff;
  color: #2196F3;
  cursor: pointer;
  font-size: 11px;
  font-weight: 600;
}

.btn-load:hover {
  background: #2196F3;
  color: #fff;
}

.btn-delete {
  background: none;
  border: 1px solid #ddd;
  border-radius: 6px;
  color: #999;
  font-size: 16px;
  cursor: pointer;
  padding: 2px 8px;
  line-height: 1;
}

.btn-delete:hover {
  background: #fee;
  border-color: #e53935;
  color: #e53935;
}

/* Modal */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2500;
}

.modal {
  background: #fff;
  border-radius: 12px;
  padding: 24px;
  width: 360px;
  max-width: 90vw;
  box-shadow: 0 8px 30px rgba(0,0,0,0.2);
}

.modal-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
}

.modal .search-input {
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Sections */
.sidebar-section {
  padding: 14px 20px;
  border-bottom: 1px solid #f0f0f0;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: #888;
  margin-bottom: 10px;
}

/* Search */
.search-wrapper {
  position: relative;
}

.search-input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.search-input:focus {
  border-color: #2196F3;
  box-shadow: 0 0 0 3px rgba(33,150,243,0.1);
}

.search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ddd;
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 100;
  display: none;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.search-results.active {
  display: block;
}

.search-result-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid #f5f5f5;
  font-size: 13px;
  transition: background 0.15s;
}

.search-result-item:hover {
  background: #f0f7ff;
}

.search-result-item:last-child {
  border-bottom: none;
}

/* Home Display */
.home-display {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: #e8f5e9;
  border-radius: 8px;
}

.home-display .location-name {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Pin Icons */
.pin-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  font-size: 14px;
  flex-shrink: 0;
}

.home-icon {
  background: #4CAF50;
  color: #fff;
}

/* Travel Mode */
.travel-mode {
  display: flex;
  gap: 6px;
}

.mode-btn {
  flex: 1;
  padding: 8px 4px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
  text-align: center;
}

.mode-btn:hover {
  border-color: #2196F3;
  background: #f0f7ff;
}

.mode-btn.active {
  background: #2196F3;
  color: #fff;
  border-color: #2196F3;
}

/* Itinerary List */
.empty-state {
  color: #aaa;
  font-size: 13px;
  text-align: center;
  padding: 20px 0;
}

.itinerary-list {
  list-style: none;
}

.itinerary-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 4px;
  background: #f9f9f9;
  border-radius: 8px;
  cursor: grab;
  transition: background 0.15s, box-shadow 0.15s;
}

.itinerary-item:active {
  cursor: grabbing;
}

.itinerary-item:hover {
  background: #f0f7ff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.itinerary-item .drag-handle {
  color: #ccc;
  font-size: 16px;
  cursor: grab;
  user-select: none;
}

.itinerary-item .pin-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #2196F3;
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}

.itinerary-item .location-name {
  flex: 1;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.btn-remove {
  background: none;
  border: none;
  color: #999;
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  line-height: 1;
}

.btn-remove:hover {
  background: #fee;
  color: #e53935;
}

/* Sortable ghost */
.sortable-ghost {
  opacity: 0.4;
  background: #e3f2fd;
}

/* Route Info */
.route-info {
  font-size: 13px;
  line-height: 1.6;
}

.route-info .route-total {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 8px;
  color: #2196F3;
}

.route-info .route-leg {
  padding: 6px 0;
  border-bottom: 1px solid #f0f0f0;
  display: flex;
  justify-content: space-between;
}

.route-info .route-leg:last-child {
  border-bottom: none;
}

.flight-segment {
  background: #fff3e0;
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 13px;
}

.flight-segment .flight-icon {
  font-size: 16px;
}

.flight-segment.flight-clickable {
  cursor: pointer;
  transition: background 0.15s;
}

.flight-segment.flight-clickable:hover {
  background: #ffe0b2;
}

.flight-details {
  margin-top: 4px;
  font-size: 12px;
  color: #795548;
  font-weight: 500;
}

/* Flight Modal */
.modal-wide {
  width: 440px;
}

.flight-route-display {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #fff3e0;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 15px;
  font-weight: 600;
}

.flight-city {
  flex: 1;
  text-align: center;
}

.flight-arrow {
  color: #FF9800;
  font-size: 18px;
  flex-shrink: 0;
}

.flight-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 16px;
}

.flight-form-row {
  display: flex;
  gap: 10px;
}

.flight-form-row > * {
  flex: 1;
}

.flight-label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #888;
}

.flight-input {
  padding: 8px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  font-family: inherit;
}

.flight-input:focus {
  border-color: #2196F3;
}

.flight-form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cabin-options {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.cabin-option {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border: 1px solid #ddd;
  border-radius: 6px;
  font-size: 12px;
  cursor: pointer;
  transition: all 0.15s;
  user-select: none;
}

.cabin-option:has(:checked) {
  background: #fff3e0;
  border-color: #FF9800;
  color: #e65100;
}

.cabin-checkbox {
  accent-color: #FF9800;
}

.flight-search-action {
  width: 100%;
  padding: 10px;
  background: #FF9800;
  font-size: 14px;
  text-align: center;
}

.flight-search-action:hover {
  background: #F57C00;
}

.flight-divider {
  border: none;
  border-top: 1px solid #eee;
  margin: 4px 0;
}

.flight-subtitle {
  font-size: 13px;
  font-weight: 600;
  color: #555;
  margin-bottom: 4px;
}

.flight-clear {
  margin-right: auto;
  border-color: #e53935;
  color: #e53935;
}

.flight-clear:hover {
  background: #fee;
}

/* POI List */
.poi-list {
  list-style: none;
}

.poi-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #f5f5f5;
  font-size: 13px;
  cursor: pointer;
}

.poi-item:hover {
  color: #2196F3;
}

.poi-item:last-child {
  border-bottom: none;
}

.poi-item .poi-icon {
  font-size: 16px;
  flex-shrink: 0;
  margin-top: 1px;
}

.poi-item .poi-name {
  font-weight: 500;
}

.poi-item .poi-type {
  color: #999;
  font-size: 11px;
}

/* Map */
#map {
  flex: 1;
  height: 100vh;
  position: relative;
}

/* Custom Leaflet Markers */
.marker-pin {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  font-weight: 700;
  font-size: 13px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.3);
}

.marker-pin span {
  transform: rotate(45deg);
}

.marker-destination {
  background: #2196F3;
  color: #fff;
}

.marker-home {
  background: #4CAF50;
  color: #fff;
  font-size: 16px;
}

.marker-temp {
  background: #9E9E9E;
  color: #fff;
  font-size: 14px;
}

.temp-pin-popup {
  text-align: center;
  min-width: 140px;
}

.temp-pin-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 8px;
}

.temp-pin-dismiss {
  padding: 4px 12px;
  background: #fff;
  color: #666;
  border: 1px solid #ddd;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
}

.temp-pin-dismiss:hover {
  border-color: #999;
  color: #333;
}

.marker-poi {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  background: #fff;
  border: 2px solid #ff9800;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* POI Popup */
.poi-popup {
  text-align: center;
  min-width: 140px;
}

.poi-add-btn {
  margin-top: 8px;
  padding: 5px 12px;
  background: #2196F3;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
}

.poi-add-btn:hover {
  background: #1976D2;
}

/* Loading */
.loading {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255,255,255,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2000;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e0e0e0;
  border-top-color: #2196F3;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 3000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: #333;
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  animation: slideIn 0.3s ease;
  max-width: 320px;
}

.toast.error {
  background: #e53935;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Utility */
.hidden {
  display: none !important;
}

/* Responsive */
@media (max-width: 768px) {
  #app {
    flex-direction: column-reverse;
  }

  .sidebar {
    width: 100%;
    min-width: 100%;
    height: 45vh;
    border-right: none;
    border-top: 1px solid #e0e0e0;
  }

  .sidebar.collapsed {
    margin-left: 0;
    height: 0;
    min-height: 0;
    overflow: hidden;
  }

  #map {
    height: 55vh;
  }

  .sidebar-toggle-floating {
    top: auto;
    bottom: 12px;
  }
}
