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

:root {
  --bg: #1a1a1e;
  --bg-card: rgba(255,255,255,0.05);
  --bg-input: rgba(255,255,255,0.04);
  --accent: #4a9eff;
  --accent-hover: #3a8eef;
  --accent-mid: #6db3ff;
  --accent-light: #90c7ff;
  --teal: #5bb8a6;
  --amber: #d4a56a;
  --green: #34d399;
  --yellow: #fbbf24;
  --red: #f87171;
  --text: #e4e4e7;
  --text-dim: #8a90a0;
  --border: rgba(255,255,255,0.08);
  --radius: 14px;
  --radius-sm: 8px;
  --glass: rgba(18,18,22,0.65);
  --glass-border: rgba(255,255,255,0.08);
  --glass-light: rgba(255,255,255,0.06);
  --glass-light-border: rgba(255,255,255,0.1);
}

html { font-size: 16px; }
body {
  font-family: 'Montserrat', sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse at 20% 50%, rgba(60, 60, 65, 0.5) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(50, 50, 55, 0.4) 0%, transparent 55%),
    radial-gradient(ellipse at 60% 80%, rgba(45, 45, 50, 0.35) 0%, transparent 50%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
a { color: var(--accent); text-decoration: none; }

/* ===== Typography ===== */
h1 { font-size: 1.5rem; font-weight: 600; }
h2 { font-size: 1.25rem; font-weight: 600; }
h3 { font-size: 1rem; font-weight: 600; }
.text-dim { color: var(--text-dim); }
.text-sm { font-size: 0.85rem; }

/* ===== Buttons ===== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 18px;
  border: none; border-radius: 6px;
  font-family: inherit; font-size: 0.85rem; font-weight: 600;
  cursor: pointer; transition: all 0.2s;
  min-height: 36px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--bg-input); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: rgba(255,255,255,0.08); }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover:not(:disabled) { background: #2bb385; }
.btn-sm { padding: 5px 12px; font-size: 0.75rem; min-height: 28px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ===== Inputs ===== */
input, select, textarea {
  width: 100%;
  padding: 12px 16px;
  background: rgba(255,255,255,0.06);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit; font-size: 1rem;
  min-height: 48px;
  transition: border-color 0.2s;
}
select option {
  background: var(--bg);
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent);
}
input::placeholder, textarea::placeholder { color: var(--text-dim); }

/* ===== Cards ===== */
.card {
  background: var(--glass-light);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-light-border);
  border-radius: var(--radius);
  padding: 20px;
}

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

/* ===== Status badges ===== */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ===== Toast notifications ===== */
.toast-container {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%);
  z-index: 300; display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem; font-weight: 500;
  pointer-events: auto;
  animation: toast-in 0.3s ease;
  max-width: 90vw;
  backdrop-filter: blur(12px);
}
.toast.success { background: rgba(52, 211, 153, 0.9); color: #000; }
.toast.error { background: rgba(248, 113, 113, 0.9); color: #fff; }
.toast.info { background: rgba(74, 158, 255, 0.9); color: #fff; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Login page ===== */
.login-container {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
}
.login-box {
  width: 100%; max-width: 380px;
}
.login-box h1 { text-align: center; margin-bottom: 8px; }
.login-box .subtitle { text-align: center; color: var(--text-dim); margin-bottom: 32px; font-size: 0.9rem; }
.login-box .brand-sub {
  text-align: center;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
  margin-bottom: 24px;
}

/* ===== Entrance animations ===== */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  animation: fadeUp 0.35s ease-out both;
  animation-delay: 0.05s;
}

/* ===== Spinner ===== */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text-dim);
  padding: 20px 0;
}

/* ===== Top Navigation Bar ===== */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(28,28,32,0.92);
  backdrop-filter: blur(30px);
  -webkit-backdrop-filter: blur(30px);
  border-bottom: 1px solid rgba(255,255,255,0.05);
  padding: 0 20px;
  height: 60px;
  position: relative;
  z-index: 200;
}

.nav-logo {
  height: 40px;
  width: auto;
  max-width: 180px;
  object-fit: contain;
}

.nav-logo-placeholder {
  height: 40px;
  width: 180px;
  background: var(--bg-input);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 0.75rem;
}

.nav-tabs {
  display: flex;
  gap: 8px;
  align-items: center;
}

.nav-tab {
  padding: 10px 12px;
  color: var(--text);
  text-decoration: none;
  font-weight: 500;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  transition: background-color 0.2s, color 0.2s;
}

.nav-tab:hover {
  background: rgba(255,255,255,0.08);
  color: var(--accent);
}

.nav-tab.active {
  background: rgba(74, 158, 255, 0.2);
  border: 1px solid rgba(74, 158, 255, 0.3);
  color: var(--accent);
}

/* Dropdown menu for nav items */
.nav-dropdown {
  position: relative;
  display: flex;
  align-items: center;
}

.nav-dropdown-trigger {
  cursor: pointer;
  display: flex;
  align-items: center;
}

.nav-dropdown-trigger::after {
  content: "\25BE";
  font-size: 0.65rem;
  opacity: 0.6;
  margin-left: 4px;
  transition: transform 0.2s ease;
}

.nav-dropdown:hover .nav-dropdown-trigger::after {
  transform: rotate(180deg);
}

.nav-dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  background: rgba(26,26,30,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-light-border);
  border-radius: var(--radius-sm);
  min-width: 160px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  padding: 6px 0;
  display: none;
  opacity: 0;
  transform: translateY(-4px);
}

/* Invisible bridge to prevent hover gap */
.nav-dropdown-menu::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 0;
  right: 0;
  height: 10px;
}

.nav-dropdown:hover .nav-dropdown-menu {
  display: block;
  opacity: 1;
  transform: translateY(0);
  animation: dropdownFadeIn 0.2s ease forwards;
}

@keyframes dropdownFadeIn {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.nav-dropdown-menu a {
  display: block;
  padding: 10px 16px;
  color: var(--text) !important;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 500;
  background: transparent;
  border-radius: 0;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.nav-dropdown-menu a:hover {
  background: rgba(74, 158, 255, 0.15);
  color: var(--accent) !important;
}

.nav-dropdown-menu a.active {
  background: rgba(74, 158, 255, 0.1);
  color: var(--accent) !important;
}

.nav-logout {
  padding: 6px 14px;
  color: var(--red);
  text-decoration: none;
  font-weight: 600;
  font-size: 0.75rem;
  border-radius: 6px;
  background: none;
  border: 1px solid var(--red);
  cursor: pointer;
  font-family: inherit;
  margin-left: 8px;
  transition: all 0.2s;
}

.nav-logout:hover {
  background: rgba(248, 113, 113, 0.15);
}

/* Sidebar Footer */
.sidebar-footer {
  margin-top: 20px;
  display: flex;
  gap: 10px;
}

/* Update App Button */
.update-app-btn {
  padding: 6px 12px;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-family: inherit;
  font-size: 0.7rem;
  cursor: pointer;
  transition: background-color 0.2s, color 0.2s;
  min-height: auto;
}

.update-app-btn:hover {
  background: rgba(255,255,255,0.04);
  color: var(--text);
}

/* Hamburger Menu Button */
.nav-hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 5px;
  width: 32px;
  height: 32px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.nav-hamburger span {
  display: block;
  width: 100%;
  height: 2px;
  background: var(--text);
  border-radius: 2px;
  transition: transform 0.3s, opacity 0.3s;
}

.nav-hamburger.open span:nth-child(1) {
  transform: rotate(45deg) translate(5px, 5px);
}

.nav-hamburger.open span:nth-child(2) {
  opacity: 0;
}

.nav-hamburger.open span:nth-child(3) {
  transform: rotate(-45deg) translate(5px, -5px);
}

/* Mobile Navigation */
@media (max-width: 1200px) {
  .nav-hamburger {
    display: flex;
  }

  .nav-tabs {
    display: none;
    position: absolute;
    top: 60px;
    right: 0;
    left: 0;
    background: rgba(28,28,32,0.95);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    flex-direction: column;
    padding: 10px 20px 20px;
    border-bottom: 1px solid var(--border);
    gap: 4px;
    z-index: 100;
  }

  .nav-tabs.open {
    display: flex;
  }

  .nav-tab {
    padding: 14px 16px;
    text-align: center;
  }

  /* Mobile dropdown menu styles */
  .nav-dropdown {
    position: static;
    flex-direction: column;
    align-items: stretch;
  }

  .nav-dropdown-trigger {
    justify-content: center;
  }

  .nav-dropdown-menu {
    position: static;
    background: rgba(255, 255, 255, 0.05);
    border: none;
    border-radius: 0;
    box-shadow: none;
    padding: 0;
    margin: 0;
    display: none;
    opacity: 1;
    transform: none;
    animation: none;
    max-height: 0;
    overflow: hidden;
    backdrop-filter: none;
  }

  .nav-dropdown:hover .nav-dropdown-menu {
    display: none;
  }

  .nav-dropdown.open .nav-dropdown-menu {
    display: block;
    max-height: 300px;
    transition: max-height 0.25s ease;
  }

  .nav-dropdown-menu a {
    padding: 12px 24px;
    text-align: center;
    font-size: 0.85rem;
  }

  .nav-dropdown.open .nav-dropdown-trigger::after {
    transform: rotate(180deg);
  }
}

/* ===== Route Optimizer Layout ===== */
.container {
  display: flex;
  height: calc(100vh - 60px);
}

.sidebar {
  width: 380px;
  padding: 20px;
  overflow-y: auto;
  background: rgba(28,28,32,0.6);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-right: 1px solid var(--border);
}

.sidebar h1 {
  font-size: 1.5rem;
  margin-bottom: 20px;
  color: var(--text);
}

/* Instructions */
.instructions {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: 0.875rem;
}

.instructions summary {
  padding: 12px 15px;
  cursor: pointer;
  color: var(--text-dim);
  font-weight: 500;
  user-select: none;
}

.instructions summary:hover {
  color: var(--text);
}

.instructions[open] summary {
  border-bottom: 1px solid var(--border);
}

.instructions ol {
  padding: 15px 15px 15px 30px;
  color: var(--text-dim);
  line-height: 1.6;
}

.instructions li {
  margin-bottom: 8px;
}

.instructions li:last-child {
  margin-bottom: 0;
}

.instructions ul {
  margin-top: 6px;
  margin-left: 15px;
  list-style: disc;
}

.instructions ul li {
  margin-bottom: 4px;
}

.instructions strong {
  color: var(--text);
}

/* Mode-specific control groups */
#optimizeControls {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.sidebar h2 {
  font-size: 1rem;
  margin-bottom: 15px;
  color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  padding-bottom: 10px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.controls label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-dim);
}

.controls select,
.controls input {
  padding: 10px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  background: rgba(255,255,255,0.06);
  color: var(--text);
  transition: border-color 0.2s;
}

.controls select:focus,
.controls input:focus {
  outline: none;
  border-color: var(--accent);
}

.controls select option {
  background: var(--bg);
  color: var(--text);
}

.controls .help-text {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.autocomplete-wrapper {
  position: relative;
}

.suggestions-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: rgba(26,26,30,0.95);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-light-border);
  border-top: none;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
  box-shadow: 0 4px 6px rgba(0,0,0,0.4);
}

.suggestions-dropdown.show {
  display: block;
}

.suggestion-item {
  padding: 10px 12px;
  cursor: pointer;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}

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

.suggestion-item:hover {
  background: rgba(74, 158, 255, 0.1);
}

.suggestion-item .place-name {
  font-weight: 500;
  color: var(--text);
}

.suggestion-item .place-context {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 2px;
}

.map-container {
  flex: 1;
}

#map {
  width: 100%;
  height: 100%;
}

#status {
  margin-bottom: 15px;
}

.status-message {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  margin-bottom: 10px;
}

.status-message.error {
  background: rgba(248, 113, 113, 0.15);
  color: var(--red);
  border: 1px solid rgba(248, 113, 113, 0.3);
}

.status-message.success {
  background: rgba(52, 211, 153, 0.15);
  color: var(--green);
  border: 1px solid rgba(52, 211, 153, 0.3);
}

.status-message.info {
  background: rgba(74, 158, 255, 0.15);
  color: var(--accent);
  border: 1px solid rgba(74, 158, 255, 0.3);
}

.status-message.warning {
  background: rgba(251, 191, 36, 0.15);
  color: var(--yellow);
  border: 1px solid rgba(251, 191, 36, 0.3);
}

.customer-item,
.route-item {
  padding: 12px;
  margin-bottom: 10px;
  background: var(--glass-light);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-light-border);
  border-radius: var(--radius-sm);
  border-left: 4px solid var(--accent);
  font-size: 0.875rem;
  line-height: 1.4;
}

.customer-item.geocoded {
  border-left-color: var(--green);
}

.customer-item.failed {
  border-left-color: var(--red);
  opacity: 0.7;
}

.route-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border-left-color: var(--green);
  cursor: grab;
  user-select: none;
  transition: transform 0.2s ease;
}

.route-item.placeholder {
  opacity: 0.2;
  border-style: dashed;
  cursor: grabbing;
}

.route-item.shift-down {
  transform: translateY(var(--item-height));
}

.route-item.shift-up {
  transform: translateY(calc(-1 * var(--item-height)));
}

.route-item-ghost {
  position: absolute !important;
  z-index: 99999 !important;
  pointer-events: none !important;
  opacity: 0.95;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  background: rgba(30,30,50,0.95) !important;
  border: 2px solid #4a9eff !important;
  border-left: 4px solid #4a9eff !important;
  border-radius: 8px;
  padding: 12px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  transition: none !important;
}

.drag-hint {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin: 0 0 8px 0;
  opacity: 0.7;
}

.route-item .order {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.875rem;
}

.route-item .address {
  flex: 1;
}

.customer-name {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.customer-address {
  color: var(--text-dim);
}

#customerCount {
  font-weight: normal;
  color: var(--text-dim);
}

/* Custom marker styles */
.marker {
  width: 32px;
  height: 32px;
  background: var(--accent);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  font-size: 14px;
  border: 3px solid var(--bg);
  box-shadow: 0 2px 6px rgba(0,0,0,0.5);
  cursor: pointer;
}

.marker.start {
  background: var(--green);
}

.marker.end {
  background: var(--red);
}

/* Mobile/iPad Responsive */
@media (max-width: 1024px) {
  .container {
    flex-direction: column;
  }

  .sidebar {
    width: 100%;
    height: auto;
    max-height: 100vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
    overflow-y: auto;
  }

  .map-container {
    height: 55vh;
    display: none;
  }

  .map-container.show {
    display: block;
  }

  .sidebar.map-visible {
    max-height: 45vh;
  }

  #map {
    height: 100%;
  }
}

@media (max-width: 600px) {
  .sidebar {
    padding: 15px;
  }

  .sidebar.map-visible {
    max-height: 50vh;
  }

  .sidebar h1 {
    font-size: 1.25rem;
    margin-bottom: 15px;
  }

  .controls {
    gap: 12px;
  }

  .controls label {
    font-size: 0.8rem;
  }

  .controls select,
  .controls input {
    padding: 8px 10px;
    font-size: 0.9rem;
  }

  .btn {
    padding: 8px 14px;
    font-size: 0.85rem;
  }

  .customer-item,
  .route-item {
    padding: 10px;
    font-size: 0.8rem;
  }

  .route-item .order {
    width: 24px;
    height: 24px;
    font-size: 0.75rem;
  }
}

/* Location button */
.location-row {
  display: flex;
  gap: 8px;
}

.location-row .autocomplete-wrapper {
  flex: 1;
}

.btn-location {
  padding: 10px 12px;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s;
  min-height: auto;
}

.btn-location:hover {
  background: rgba(255,255,255,0.08);
}

.btn-location svg {
  width: 20px;
  height: 20px;
}

.btn-location.loading {
  opacity: 0.7;
  cursor: wait;
}

/* Directions controls */
.directions-controls {
  background: rgba(74, 158, 255, 0.08);
  border: 1px solid rgba(74, 158, 255, 0.2);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 15px;
}

.directions-controls .help-text {
  display: block;
  margin-top: 8px;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.directions-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.directions-row label {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-dim);
}

.directions-row select {
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  background: rgba(255,255,255,0.06);
  color: var(--text);
}

.btn-directions {
  white-space: nowrap;
  padding: 8px 16px;
  font-size: 0.875rem;
}

@media (max-width: 600px) {
  .directions-row {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-directions {
    width: 100%;
  }
}

/* ===== Responsive ===== */
@media (min-width: 768px) {
  .container-page { padding: 24px 32px; }
}
