:root {
  --bg-primary: #0b0f19;
  --bg-surface: #151d30;
  --bg-card: #1c2640;
  --bg-glass: rgba(28, 38, 64, 0.85);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #0284c7;

  --accent-cyan: #06b6d4;
  --accent-blue: #0284c7;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

/* Header & Nav */
header.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--bg-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-shrink: 1;
  overflow: hidden;
}

.logo-badge {
  background: linear-gradient(135deg, var(--accent-cyan), var(--accent-blue));
  color: #fff;
  font-weight: 800;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  letter-spacing: 0.5px;
  flex-shrink: 0;
}

.logo-title {
  font-size: clamp(0.9rem, 3.8vw, 1.08rem);
  font-weight: 700;
  background: linear-gradient(to right, #ffffff, var(--accent-cyan));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.header-btn {
  padding: 5px 9px;
  font-size: 0.78rem;
  white-space: nowrap;
  line-height: 1.2;
}

#btn-user-profile {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 380px) {
  header.app-header {
    padding: 8px 10px;
    gap: 6px;
  }

  .logo-area {
    gap: 5px;
  }

  .logo-badge {
    padding: 2px 5px;
    font-size: 0.72rem;
  }

  .logo-title {
    font-size: 0.88rem;
  }

  .header-btn {
    padding: 4px 7px;
    font-size: 0.74rem;
  }

  #btn-user-profile {
    max-width: 85px;
  }
}

@media (max-width: 330px) {
  .logo-title {
    font-size: 0.8rem;
  }

  #btn-user-profile {
    max-width: 70px;
  }
}

/* Offline & Alert Toasts */
#toast-container {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 440px;
  z-index: 9000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: var(--shadow-md);
  animation: slideDown 0.25s ease-out;
}

.toast.toast-error {
  background: #2a1215;
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #fca5a5;
}

.toast.toast-success {
  background: #0f291e;
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #6ee7b7;
}

.toast.toast-info {
  background: #112240;
  border: 1px solid rgba(6, 182, 212, 0.4);
  color: #a5f3fc;
}

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

/* Main Container */
main.main-content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(78px + env(safe-area-inset-bottom, 0px));
  max-width: 600px;
  margin: 0 auto;
  width: 100%;
}

/* Card Sections */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Guest Intro Section for Unlogged Users */
.guest-intro-card {
  position: relative;
  overflow: hidden;
  background: linear-gradient(135deg, rgba(21, 29, 48, 0.95) 0%, rgba(15, 23, 42, 0.98) 100%);
  border: 1px solid rgba(6, 182, 212, 0.35);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), 0 0 24px rgba(6, 182, 212, 0.12);
  animation: guestFadeIn 0.35s ease-out;
}

.guest-intro-card::before {
  content: "";
  position: absolute;
  top: -50px;
  right: -50px;
  width: 140px;
  height: 140px;
  background: radial-gradient(circle, rgba(6, 182, 212, 0.22) 0%, rgba(2, 132, 199, 0) 70%);
  pointer-events: none;
  border-radius: 50%;
}

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

.guest-intro-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.guest-intro-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.12);
  border: 1px solid rgba(6, 182, 212, 0.28);
  padding: 4px 10px;
  border-radius: 999px;
}

.guest-intro-badge-pulse {
  width: 8px;
  height: 8px;
  background-color: var(--accent-cyan);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-cyan);
  animation: badgePulse 2s infinite ease-in-out;
}

@keyframes badgePulse {
  0%, 100% {
    transform: scale(1);
    opacity: 1;
  }
  50% {
    transform: scale(1.3);
    opacity: 0.6;
  }
}

.guest-intro-tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--accent-amber);
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.25);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}

.guest-intro-heading {
  font-size: clamp(1.05rem, 3.8vw, 1.25rem);
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.3px;
  margin-bottom: 12px;
  line-height: 1.35;
}

.guest-intro-content {
  margin-bottom: 16px;
}

.guest-intro-p {
  font-size: 0.88rem;
  line-height: 1.65;
  color: #cbd5e1;
  margin-bottom: 10px;
}

.guest-intro-p strong {
  color: #fff;
  font-weight: 700;
}

.guest-intro-features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.guest-feature-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(15, 23, 42, 0.7);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  transition: border-color 0.2s, transform 0.2s;
}

.guest-feature-pill:hover {
  border-color: rgba(6, 182, 212, 0.4);
  transform: translateY(-1px);
}

.guest-feature-pill .feature-icon {
  font-size: 1.25rem;
  flex-shrink: 0;
}

.guest-feature-pill .feature-text {
  display: flex;
  flex-direction: column;
}

.guest-feature-pill .feature-text strong {
  font-size: 0.82rem;
  color: #f1f5f9;
}

.guest-feature-pill .feature-text span {
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.guest-intro-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.intro-action-btn {
  font-size: 0.84rem;
  padding: 8px 16px;
}

/* Waypoints & Stages list */
.stage-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 10px;
  transition: border-color 0.2s;
}

.stage-item.stage-active {
  border-color: var(--accent-cyan);
  background: rgba(6, 182, 212, 0.08);
}

.stage-item.stage-completed {
  border-color: rgba(16, 185, 129, 0.4);
  background: rgba(16, 185, 129, 0.05);
}

.stage-item.stage-skipped {
  border-color: rgba(245, 158, 11, 0.35);
  background: rgba(245, 158, 11, 0.04);
  opacity: 0.85;
}

.stage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.stage-labels {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  font-size: 1rem;
}

.badge-label {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--accent-blue);
  color: #fff;
  font-size: 0.85rem;
}

.badge-label.label-end {
  background: var(--accent-cyan);
}

.stage-status-badge {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 999px;
  font-weight: 600;
  text-transform: uppercase;
}

.status-pending { background: #334155; color: #94a3b8; }
.status-active { background: #0369a1; color: #bae6fd; }
.status-completed { background: #065f46; color: #a7f3d0; }
.status-skipped { background: #78350f; color: #fef3c7; }

/* Waypoint Note (Hidden by default, expandable on click) */
.waypoint-note-trigger {
  font-size: 0.78rem;
  color: var(--accent-cyan);
  background: none;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 4px;
}

.waypoint-note-content {
  display: none;
  background: rgba(15, 23, 42, 0.6);
  border: 1px dashed rgba(6, 182, 212, 0.3);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  font-size: 0.82rem;
  color: #cbd5e1;
  line-height: 1.4;
}

.waypoint-note-content.expanded {
  display: block;
}

/* Navigation buttons (Google Maps Instant - No _blank) */
.btn-nav-google {
  width: 100%;
  background: linear-gradient(135deg, #1e3a8a, #0284c7);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  text-decoration: none;
}

.btn-nav-google:active {
  transform: scale(0.98);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-secondary:active {
  background: rgba(255, 255, 255, 0.15);
}

.btn-action-primary {
  background: var(--accent-cyan);
  color: #0b0f19;
  border: none;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-weight: 700;
  cursor: pointer;
  font-size: 0.85rem;
}

/* Geofencing Controls */
.geofence-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-top: 1px solid var(--border-color);
  margin-top: 10px;
  font-size: 0.85rem;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: #334155;
  transition: .3s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider { background-color: var(--accent-green); }
input:checked + .slider:before { transform: translateX(20px); }

/* Touch Friendly Mobile Editor */
.editor-modal-box {
  max-width: 580px;
  width: 100%;
  padding: 0 !important;
  display: flex;
  flex-direction: column;
  overflow: hidden !important;
  max-height: 92vh;
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7);
}

.editor-header {
  padding: 14px 18px;
  background: rgba(15, 23, 42, 0.95);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

.editor-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
}

.editor-footer {
  padding: 12px 16px;
  background: rgba(15, 23, 42, 0.96);
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  backdrop-filter: blur(10px);
}

.editor-section-card {
  background: rgba(15, 23, 42, 0.6);
  padding: 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.editor-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg-card);
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
  border: 1px solid var(--border-color);
  box-sizing: border-box;
  width: 100%;
}

.editor-wp-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.editor-wp-text {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.editor-wp-title {
  font-weight: 600;
  font-size: 0.88rem;
  color: #fff;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.editor-wp-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.editor-wp-actions {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
}

.editor-wp-actions button {
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
}

@media (max-width: 600px) {
  #modal-editor {
    padding: 0;
    align-items: flex-end;
  }

  #modal-editor .editor-modal-box {
    width: 100%;
    height: 100%;
    max-height: 100vh;
    border-radius: 0;
    border: none;
  }

  #modal-editor .editor-header {
    padding: 12px 14px;
  }

  #modal-editor .editor-body {
    padding: 12px;
    gap: 12px;
  }

  #modal-editor .editor-section-card {
    padding: 12px;
  }

  #modal-editor .editor-footer {
    padding: 10px 14px;
    padding-bottom: max(14px, env(safe-area-inset-bottom, 14px));
  }
}

.editor-inputs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

.input-field {
  background: rgba(15, 23, 42, 0.8);
  border: 1px solid var(--border-color);
  color: #fff;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  width: 100%;
}

.input-field:focus {
  outline: none;
  border-color: var(--accent-cyan);
}

.char-counter {
  font-size: 0.75rem;
  color: var(--text-dim);
  text-align: right;
  margin-top: -4px;
}

/* Geocoding / Search Autocomplete Dropdown */
.search-suggestions-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #0f172a;
  border: 1px solid var(--accent-cyan);
  border-radius: var(--radius-sm);
  max-height: 240px;
  overflow-y: auto;
  z-index: 150;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.7);
  margin-top: 4px;
}

.suggestion-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  transition: background 0.15s ease;
}

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

.suggestion-item:hover, .suggestion-item:active {
  background: rgba(6, 182, 212, 0.18);
}

.suggestion-icon {
  font-size: 1.15rem;
  margin-top: 1px;
}

.suggestion-text {
  flex: 1;
  min-width: 0;
}

.suggestion-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: #fff;
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.suggestion-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.3;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

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

.modal-box {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
}

/* Footer */
footer.app-footer {
  display: none; /* Replaced by in-tab info & mobile bottom nav */
}

/* Mobile Tabs System */
.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
  animation: tabFadeIn 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes tabFadeIn {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Mobile Bottom Navigation Bar */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  background: rgba(11, 15, 25, 0.94);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: stretch;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.45);
}

.nav-tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px 0;
  transition: all 0.2s ease;
  position: relative;
  user-select: none;
  outline: none;
}

.nav-tab-btn .nav-tab-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 3px;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nav-tab-btn .nav-tab-icon svg {
  display: block;
}

.nav-tab-btn .nav-tab-label {
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.2px;
  transition: color 0.2s ease;
}

.nav-tab-btn:hover:not(.disabled) {
  color: #fff;
}

.nav-tab-btn.active {
  color: var(--accent-cyan);
}

.nav-tab-btn.active .nav-tab-icon {
  transform: scale(1.15) translateY(-1px);
}

.nav-tab-btn.active::after {
  content: '';
  position: absolute;
  top: 0;
  width: 32px;
  height: 3px;
  background: var(--accent-cyan);
  border-radius: 0 0 3px 3px;
  box-shadow: 0 0 10px var(--accent-cyan);
}

.nav-tab-btn.disabled {
  opacity: 0.38;
  cursor: not-allowed;
  pointer-events: none;
}

.nav-tab-badge {
  font-size: 0.55rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: rgba(148, 163, 184, 0.2);
  color: #94a3b8;
  padding: 1px 5px;
  border-radius: 4px;
  position: absolute;
  top: 6px;
  right: calc(50% - 32px);
  border: 1px solid rgba(148, 163, 184, 0.3);
}
