/* ============================================================
   TimeTrail — Lyst design, rød aksent
   Matcher designskisser: hvit bakgrunn, #E53935 rød
   ============================================================ */

:root {
  --bg: #FFFFFF;
  --bg2: #F5F5F7;
  --bg3: #EBEBED;
  --surface: #FFFFFF;
  --surface2: #F5F5F7;
  --border: #E5E5E7;
  --text: #1A1A1A;
  --text2: #6E6E73;
  --text3: #AEAEB2;
  --red: #E53935;
  --red-dark: #C62828;
  --red-light: #FFEBEE;
  --success: #34C759;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 24px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.16);
  --transition: 0.2s ease;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', sans-serif;
  background: var(--bg2);
  color: var(--text);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
}

/* ============================================================
   VIEWS
   ============================================================ */

.view {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  background: var(--bg2);
  transform: translateX(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-overflow-scrolling: touch;
}

.view.active { transform: translateX(0); }
#view-map { overflow: hidden; }

/* ============================================================
   VIEW HEADER
   ============================================================ */

.view-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px 12px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.view-header h2 {
  flex: 1;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.back-btn {
  background: var(--bg2);
  border: none;
  color: var(--text);
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition);
}

.back-btn:active { background: var(--bg3); }

.icon-btn {
  background: none;
  border: none;
  color: var(--red);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}

/* ============================================================
   BUTTONS
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 13px 24px;
  border-radius: 50px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: -0.2px;
}

.btn-primary {
  background: var(--red);
  color: #FFFFFF;
}

.btn-primary:hover { background: var(--red-dark); }
.btn-primary:active { transform: scale(0.97); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:active { background: var(--bg3); }

.btn-ghost {
  background: transparent;
  color: var(--text2);
  border: 1.5px solid var(--border);
}

.btn-lg { padding: 15px 32px; font-size: 16px; }
.btn-full { width: 100%; }

/* ============================================================
   LANDING VIEW
   ============================================================ */

#view-landing {
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

.landing-header {
  padding: 20px 20px 0;
  padding-top: max(20px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.landing-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-mark {
  width: 32px;
  height: 32px;
}

.logo-text {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.5px;
}

.logo-text span { color: var(--red); }

.landing-login-btn {
  background: none;
  border: 1.5px solid var(--border);
  color: var(--text);
  padding: 7px 16px;
  border-radius: 50px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.landing-hero {
  padding: 32px 20px 24px;
  flex: 1;
}

.landing-hero h1 {
  font-size: 34px;
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: -1px;
  color: var(--text);
  margin-bottom: 12px;
}

.landing-hero h1 span { color: var(--red); }

.landing-hero p {
  font-size: 16px;
  color: var(--text2);
  line-height: 1.55;
  margin-bottom: 28px;
  max-width: 340px;
}

.landing-cta {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 36px;
}

.landing-hero-image {
  width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  height: 200px;
  background: var(--bg2);
  position: relative;
  margin-bottom: 24px;
}

.landing-hero-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.landing-hero-image-placeholder {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #f0f0f0 0%, #e0e0e0 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 48px;
}

.landing-cities {
  padding: 0 20px 32px;
  padding-bottom: max(32px, env(safe-area-inset-bottom));
}

.landing-cities-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 12px;
}

.cities-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.city-chip {
  padding: 7px 14px;
  border-radius: 50px;
  font-size: 13px;
  font-weight: 500;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text2);
}

.city-chip.active {
  background: var(--red-light);
  border-color: var(--red);
  color: var(--red);
}

.city-chip .soon {
  font-size: 10px;
  color: var(--text3);
  margin-left: 3px;
}

/* ============================================================
   ROUTES VIEW
   ============================================================ */

.routes-header {
  padding: 20px 16px 12px;
  padding-top: max(20px, env(safe-area-inset-top));
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.routes-header-left { display: flex; align-items: center; gap: 10px; }
.routes-header-logo { display: flex; align-items: center; gap: 6px; }
.routes-header-logo .logo-text { font-size: 17px; }
.routes-header-logo .logo-mark { width: 24px; height: 24px; }

.routes-section-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 20px 16px 10px;
}

.routes-list {
  padding: 0 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Route card — bilde venstre, tekst høyre */
.route-card {
  background: var(--bg);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  height: 96px;
  transition: transform var(--transition), box-shadow var(--transition);
  border: 1px solid var(--border);
}

.route-card:active { transform: scale(0.98); box-shadow: var(--shadow); }

.route-card-img {
  width: 96px;
  flex-shrink: 0;
  background: var(--bg2) center/cover no-repeat;
  position: relative;
}

.route-card-img::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent 60%, rgba(0,0,0,0.08));
}

.route-card-body {
  flex: 1;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}

.route-card-city {
  font-size: 11px;
  font-weight: 600;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.route-card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.2px;
}

.route-card-meta {
  display: flex;
  gap: 10px;
  font-size: 12px;
  color: var(--text2);
}

.route-card-meta span {
  display: flex;
  align-items: center;
  gap: 3px;
}

/* ============================================================
   ROUTE DETAIL VIEW
   ============================================================ */

#view-route-detail {
  background: var(--bg2);
}

.route-detail-hero {
  position: relative;
  height: 260px;
  background: var(--bg3) center/cover no-repeat;
}

.route-detail-hero::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 120px;
  background: linear-gradient(to bottom, transparent, var(--bg2));
}

.back-btn-hero {
  position: absolute;
  top: max(16px, env(safe-area-inset-top));
  left: 16px;
  z-index: 5;
  background: rgba(255,255,255,0.92);
  backdrop-filter: blur(10px);
  border: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  color: var(--text);
}

.route-detail-card {
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  margin-top: -20px;
  position: relative;
  z-index: 2;
  padding: 20px;
  min-height: calc(100vh - 240px);
}

.route-period-tag {
  display: inline-block;
  background: var(--red-light);
  color: var(--red);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 50px;
  margin-bottom: 10px;
  letter-spacing: 0.3px;
}

.route-detail-card h2 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}

.route-detail-city {
  font-size: 14px;
  color: var(--text2);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.route-stats {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
}

.stat-pill {
  background: var(--bg2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  flex: 1;
  text-align: center;
}

.stat-pill-val {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  display: block;
  letter-spacing: -0.3px;
}

.stat-pill-label {
  font-size: 11px;
  color: var(--text2);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}

.route-detail-desc {
  font-size: 15px;
  color: var(--text2);
  line-height: 1.6;
  margin-bottom: 20px;
}

.stops-preview-label {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 10px;
}

.stops-preview {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-bottom: 24px;
}

.stop-preview-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  transition: background var(--transition);
}

.stop-preview-item.visited { opacity: 0.5; }

.stop-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--red);
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stop-preview-item.visited .stop-num { background: var(--success); }

.stop-preview-title {
  flex: 1;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

.stop-check { color: var(--success); font-size: 14px; }

/* ============================================================
   MAP VIEW
   ============================================================ */

#map-container {
  position: absolute;
  inset: 0;
}

/* Topbar over kartet */
.map-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 5;
}

.map-back-btn {
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 50px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  box-shadow: var(--shadow);
}

.map-title-pill {
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 160px;
  box-shadow: var(--shadow);
}

.gps-pill {
  background: rgba(255,255,255,0.95);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 50px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  white-space: nowrap;
  box-shadow: var(--shadow);
  margin-left: auto;
}

.gps-pill.locked { color: var(--red); }
.gps-pill.good { color: var(--success); }

/* Bottom card på kartet (Bergen-stil) */
.map-bottom-card {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255,255,255,0.98);
  backdrop-filter: blur(20px);
  border-radius: 20px 20px 0 0;
  padding: 16px 20px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 5;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.1);
}

.map-bottom-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
}

.map-route-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.map-stops-btn {
  background: var(--bg2);
  border: none;
  border-radius: 50px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
}

.map-route-meta {
  font-size: 14px;
  color: var(--text2);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.map-route-meta span { display: flex; align-items: center; gap: 3px; }

.map-progress-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.progress-track {
  flex: 1;
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--red);
  border-radius: 2px;
  transition: width 0.5s ease;
}

.progress-text {
  font-size: 12px;
  font-weight: 600;
  color: var(--text2);
  white-space: nowrap;
}

/* ============================================================
   POI MARKERS
   ============================================================ */

.poi-marker {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  border: 2.5px solid white;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  transition: transform 0.15s;
  font-size: 11px;
  font-weight: 700;
  color: white;
}

.poi-marker.unvisited { background: var(--red); }
.poi-marker.visited { background: var(--success); }
.poi-marker:active { transform: scale(1.25); }

/* ============================================================
   SHEETS
   ============================================================ */

.sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg);
  border-radius: 20px 20px 0 0;
  z-index: 100;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  max-height: 82vh;
  overflow-y: auto;
  padding-bottom: env(safe-area-inset-bottom);
  box-shadow: 0 -8px 40px rgba(0,0,0,0.15);
}

.sheet.visible { transform: translateY(0); }

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--bg3);
  border-radius: 2px;
  margin: 12px auto 8px;
  cursor: pointer;
}

.sheet-content { padding: 4px 20px 24px; }

/* POI Sheet */
.poi-sheet-image {
  width: 100%;
  height: 190px;
  object-fit: cover;
  border-radius: var(--radius);
  margin-bottom: 14px;
}

.poi-sheet-period {
  font-size: 11px;
  font-weight: 600;
  color: var(--red);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.sheet-content h3 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin-bottom: 8px;
  color: var(--text);
}

.sheet-content p {
  font-size: 15px;
  color: var(--text2);
  line-height: 1.6;
  margin-bottom: 14px;
}

.funfact-box {
  background: var(--red-light);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 16px;
  display: flex;
  gap: 10px;
  align-items: flex-start;
}

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

.funfact-box p {
  font-size: 13px;
  color: var(--red-dark);
  margin: 0;
  line-height: 1.5;
  font-weight: 500;
}

/* Stop list sheet */
.stop-list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}

.stop-list-item:last-child { border-bottom: none; }
.stop-list-item.visited { opacity: 0.45; }

.stop-list-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--red);
  color: white;
  font-size: 12px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stop-list-item.visited .stop-list-num { background: var(--success); }
.stop-list-title { flex: 1; font-size: 14px; font-weight: 500; }
.stop-list-check { color: var(--success); }

/* ============================================================
   PROFILE VIEW
   ============================================================ */

.profile-body {
  padding: 32px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.profile-avatar-circle {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--red-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
  margin-bottom: 8px;
}

.profile-name { font-size: 20px; font-weight: 700; letter-spacing: -0.3px; }
.profile-email { font-size: 14px; color: var(--text2); margin-bottom: 20px; }

.profile-stat-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 32px;
  text-align: center;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 280px;
}

.profile-stat-val { font-size: 32px; font-weight: 700; color: var(--red); }
.profile-stat-label { font-size: 13px; color: var(--text2); margin-top: 4px; }

/* ============================================================
   AUTH VIEW
   ============================================================ */

.auth-body {
  padding: 24px 20px;
  max-width: 400px;
  margin: 0 auto;
}

.form-group { margin-bottom: 14px; }

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 6px;
}

.form-group input {
  width: 100%;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 15px;
  padding: 12px 14px;
  outline: none;
  transition: border-color var(--transition);
}

.form-group input:focus { border-color: var(--red); }
.form-group input::placeholder { color: var(--text3); }

.auth-error {
  background: #FFF5F5;
  border: 1px solid #FFCDD2;
  color: var(--red-dark);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 14px;
}

.auth-links {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
}

.auth-links a {
  color: var(--red);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}

.auth-info {
  font-size: 14px;
  color: var(--text2);
  line-height: 1.6;
  margin-bottom: 16px;
}

/* ============================================================
   TOAST
   ============================================================ */

.toast {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--text);
  color: white;
  border-radius: 50px;
  padding: 10px 20px;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
  z-index: 200;
  box-shadow: var(--shadow-md);
}

.toast.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ============================================================
   UTILITY
   ============================================================ */

.loading-spinner {
  text-align: center;
  color: var(--text2);
  padding: 48px 20px;
  font-size: 15px;
}

.empty-state, .error-state {
  text-align: center;
  color: var(--text2);
  padding: 48px 20px;
  font-size: 15px;
}

.error-state { color: var(--red); }
.hidden { display: none !important; }

/* Divider */
.divider {
  height: 8px;
  background: var(--bg2);
  margin: 0 -20px;
}
