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

:root {
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --tab-height: 56px;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--tg-theme-text-color, #000);
  background: var(--tg-theme-bg-color, #fff);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-overflow-scrolling: touch;
}

/* === App Container === */
#app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: calc(var(--tab-height) + var(--safe-bottom));
  overflow: hidden;
}

/* === Tab Views === */
.tab-view {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease;
  will-change: opacity;
}

.tab-view.active {
  opacity: 1;
  pointer-events: auto;
}

/* === Sections (iOS Settings Style) === */
.section {
  padding: 0 16px;
  margin-bottom: 8px;
}

.section-header {
  font-size: 13px;
  font-weight: 500;
  color: var(--tg-theme-hint-color, #999);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding: 16px 0 8px 4px;
}

/* === Cards === */
.card {
  background: var(--tg-theme-secondary-bg-color, #f2f2f7);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 8px;
}

.card-list {
  background: var(--tg-theme-secondary-bg-color, #f2f2f7);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 8px;
}

.card-list .card-row {
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--tg-theme-hint-color, rgba(0,0,0,0.1));
}

.card-list .card-row:last-child {
  border-bottom: none;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  position: relative;
  cursor: pointer;
  -webkit-user-select: none;
  user-select: none;
}

.card-row-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.card-icon {
  font-size: 20px;
  flex-shrink: 0;
  width: 28px;
  text-align: center;
}

.card-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--tg-theme-text-color, #000);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-subtitle {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #999);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-value {
  font-size: 16px;
  font-weight: 600;
  color: var(--tg-theme-text-color, #000);
  flex-shrink: 0;
}

.card-value.good { color: #34c759; }
.card-value.okay { color: #ff9500; }
.card-value.bad { color: #ff3b30; }

.card-action {
  background: var(--tg-theme-button-color, #007aff);
  color: var(--tg-theme-button-text-color, #fff);
  border: none;
  border-radius: 8px;
  padding: 6px 14px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}

.card-action:active {
  opacity: 0.7;
}

/* Ripple effect */
.ripple {
  position: relative;
  overflow: hidden;
}

.ripple::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 0;
  height: 0;
  border-radius: 50%;
  background: var(--tg-theme-hint-color, rgba(0,0,0,0.1));
  transform: translate(-50%, -50%);
  opacity: 0;
}

.ripple:active::after {
  width: 200%;
  height: 200%;
  opacity: 0.15;
  transition: width 0.3s, height 0.3s, opacity 0.3s;
}

/* === Chips === */
.chip-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  padding-bottom: 4px;
}

.chip {
  background: var(--tg-theme-secondary-bg-color, #f2f2f7);
  color: var(--tg-theme-text-color, #000);
  border: none;
  border-radius: 20px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  -webkit-user-select: none;
  user-select: none;
  white-space: nowrap;
}

.chip:active {
  transform: scale(0.95);
}

.chip.active {
  background: var(--tg-theme-button-color, #007aff);
  color: var(--tg-theme-button-text-color, #fff);
}

/* === Map === */
#map-container {
  position: relative;
  height: 55vh;
  min-height: 250px;
}

.top-cta-section {
  margin-top: 12px;
}

#map {
  width: 100%;
  height: 100%;
  z-index: 1;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

.map-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--tg-theme-bg-color, rgba(255,255,255,0.9));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  z-index: 10;
  color: var(--tg-theme-hint-color, #999);
  font-size: 14px;
  transition: opacity 0.3s;
}

.map-overlay.hidden {
  opacity: 0;
  pointer-events: none;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--tg-theme-secondary-bg-color, #e0e0e0);
  border-top-color: var(--tg-theme-button-color, #007aff);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* === Station List (below map) === */
.station-list {
  padding: 8px 0;
  margin: 0 16px;
  background: var(--tg-theme-secondary-bg-color, #f2f2f7);
  border-radius: 12px;
  overflow: hidden;
}

.station-item {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
  border-bottom: 0.5px solid var(--tg-theme-hint-color, rgba(0,0,0,0.08));
}

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

.station-item:active {
  opacity: 0.7;
}

.station-rank {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}

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

.station-name {
  font-size: 15px;
  font-weight: 500;
  color: var(--tg-theme-text-color, #000);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-addr {
  font-size: 13px;
  color: var(--tg-theme-hint-color, #999);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.station-price {
  font-size: 20px;
  font-weight: 700;
  flex-shrink: 0;
}

.station-price sup {
  font-size: 13px;
  vertical-align: super;
}

.station-dist {
  font-size: 12px;
  color: var(--tg-theme-hint-color, #999);
  text-align: right;
}

/* === Chart === */
.chart-container {
  background: var(--tg-theme-secondary-bg-color, #f2f2f7);
  border-radius: 12px;
  padding: 16px 8px 8px;
  height: 280px;
  position: relative;
}

.chart-container canvas {
  width: 100% !important;
  height: 100% !important;
}

/* === Bottom Sheet === */
.bottom-sheet {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 1000;
  transition: visibility 0.3s;
}

.bottom-sheet.hidden {
  visibility: hidden;
  pointer-events: none;
}

.bottom-sheet-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  transition: opacity 0.3s;
}

.bottom-sheet:not(.hidden) .bottom-sheet-backdrop {
  opacity: 1;
}

.bottom-sheet-content {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--tg-theme-bg-color, #fff);
  border-radius: 16px 16px 0 0;
  max-height: 70vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  touch-action: pan-y;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
  padding-bottom: var(--safe-bottom);
}

.bottom-sheet:not(.hidden) .bottom-sheet-content {
  transform: translateY(0);
}

.bottom-sheet-handle {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: var(--tg-theme-hint-color, #ccc);
  margin: 8px auto 4px;
  opacity: 0.5;
}

/* Sheet station detail */
.sheet-station-header {
  padding: 12px 20px 8px;
}

.sheet-station-name {
  font-size: 18px;
  font-weight: 700;
  color: var(--tg-theme-text-color, #000);
}

.sheet-station-brand {
  font-size: 14px;
  color: var(--tg-theme-hint-color, #999);
  margin-top: 2px;
}

.sheet-station-price {
  font-size: 36px;
  font-weight: 800;
  padding: 8px 20px;
}

.sheet-station-price sup {
  font-size: 18px;
  vertical-align: super;
}

.sheet-info-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  font-size: 14px;
  color: var(--tg-theme-text-color, #000);
  border-top: 0.5px solid var(--tg-theme-hint-color, rgba(0,0,0,0.08));
}

.sheet-info-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.sheet-nav-buttons {
  display: flex;
  gap: 8px;
  padding: 16px 20px;
}

.sheet-nav-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  background: var(--tg-theme-button-color, #007aff);
  color: var(--tg-theme-button-text-color, #fff);
  text-decoration: none;
}

.sheet-nav-btn:active {
  opacity: 0.7;
}

.sheet-nav-btn.secondary {
  background: var(--tg-theme-secondary-bg-color, #f2f2f7);
  color: var(--tg-theme-text-color, #000);
}

/* === Slider === */
.slider-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.slider-row span {
  font-size: 15px;
  font-weight: 600;
  min-width: 50px;
  color: var(--tg-theme-text-color, #000);
}

.tg-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 2px;
  background: var(--tg-theme-hint-color, #ccc);
  outline: none;
}

.tg-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--tg-theme-button-color, #007aff);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* === Stats === */
.stat-big {
  text-align: center;
  padding: 20px 16px 12px;
}

.stat-big-value {
  font-size: 42px;
  font-weight: 800;
  color: var(--tg-theme-text-color, #000);
}

.stat-big-label {
  font-size: 14px;
  color: var(--tg-theme-hint-color, #999);
  margin-top: 4px;
}

.stat-row {
  display: flex;
  gap: 8px;
  padding: 0 16px;
  margin-bottom: 8px;
}

.stat-card {
  flex: 1;
  background: var(--tg-theme-secondary-bg-color, #f2f2f7);
  border-radius: 12px;
  padding: 14px 12px;
  text-align: center;
}

.stat-card-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--tg-theme-text-color, #000);
}

.stat-card-label {
  font-size: 12px;
  color: var(--tg-theme-hint-color, #999);
  margin-top: 4px;
}

.ranking-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  gap: 12px;
  border-bottom: 0.5px solid var(--tg-theme-hint-color, rgba(0,0,0,0.08));
}

.ranking-pos {
  font-size: 14px;
  font-weight: 700;
  color: var(--tg-theme-hint-color, #999);
  width: 24px;
  text-align: center;
}

.ranking-name {
  flex: 1;
  font-size: 14px;
  color: var(--tg-theme-text-color, #000);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.ranking-price {
  font-size: 15px;
  font-weight: 600;
  flex-shrink: 0;
}

/* === Tab Bar === */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-height) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--tg-theme-secondary-bg-color, #f8f8f8);
  border-top: 0.5px solid var(--tg-theme-hint-color, rgba(0,0,0,0.12));
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px 12px;
  -webkit-user-select: none;
  user-select: none;
  color: var(--tg-theme-hint-color, #999);
  transition: color 0.2s;
}

.tab-item.active {
  color: var(--tg-theme-button-color, #007aff);
}

.tab-icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.tab-item span {
  font-size: 10px;
  font-weight: 500;
}

/* === Location chip in settings === */
.location-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  gap: 12px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 0.5px solid var(--tg-theme-hint-color, rgba(0,0,0,0.08));
}

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

.location-item:active {
  background: rgba(0,0,0,0.03);
}

.location-item.active {
  background: rgba(0,0,0,0.02);
}

.location-radio {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--tg-theme-hint-color, #ccc);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.2s;
}

.location-item.active .location-radio {
  border-color: var(--tg-theme-button-color, #007aff);
}

.location-radio-inner {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--tg-theme-button-color, #007aff);
  transform: scale(0);
  transition: transform 0.2s;
}

.location-item.active .location-radio-inner {
  transform: scale(1);
}

.location-label {
  font-size: 15px;
  color: var(--tg-theme-text-color, #000);
}

/* My location item */
.location-item .card-icon {
  font-size: 18px;
}

/* Leaflet popup override */
.leaflet-popup-content-wrapper {
  border-radius: 12px !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15) !important;
}

.leaflet-popup-content {
  margin: 10px 14px !important;
  font-family: inherit !important;
  font-size: 14px !important;
}

/* Map bubble markers (tankste! style) */
.map-bubble {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3px 8px 4px;
  border-radius: 8px;
  color: #fff;
  white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  text-align: center;
  min-width: 48px;
}
.map-bubble-brand {
  font-size: 9px;
  font-weight: 500;
  opacity: 0.9;
  letter-spacing: 0.3px;
  line-height: 1.1;
}
.map-bubble-price {
  font-size: 15px;
  font-weight: 800;
  line-height: 1.2;
  letter-spacing: -0.3px;
}
.map-bubble-price sup {
  font-size: 9px;
  vertical-align: super;
}
.map-bubble-arrow {
  position: absolute;
  bottom: -6px;
  left: 50%;
  margin-left: -6px;
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--tg-theme-hint-color, #999);
}

.auth-hero-card {
  background: linear-gradient(135deg, rgba(79,195,247,0.12), rgba(52,199,89,0.08));
  border: 1px solid rgba(127,127,127,0.14);
  border-radius: 18px;
  padding: 18px;
  display: grid;
  gap: 14px;
}

.auth-hero-icon {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--tg-theme-button-color, #007aff);
  color: var(--tg-theme-button-text-color, #fff);
  font-size: 22px;
  box-shadow: 0 8px 18px rgba(0,0,0,0.12);
}

.auth-hero-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--tg-theme-text-color, #000);
}

.auth-hero-text,
.auth-hero-note {
  color: var(--tg-theme-hint-color, #999);
  font-size: 14px;
}

.auth-hero-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.google-login-slot {
  min-height: 44px;
}

.primary-btn,
.secondary-btn {
  border: none;
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary-btn {
  background: var(--tg-theme-button-color, #007aff);
  color: var(--tg-theme-button-text-color, #fff);
}

.secondary-btn {
  background: var(--tg-theme-secondary-bg-color, #f2f2f7);
  color: var(--tg-theme-text-color, #000);
  border: 1px solid rgba(127,127,127,0.16);
}

.secondary-btn.compact {
  padding: 8px 14px;
}

.login-hint-pill {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255,149,0,0.12);
  color: #ff9500;
  font-size: 13px;
  text-align: center;
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state-text {
  font-size: 15px;
}

/* Map floating action button */
.map-fab {
  position: absolute;
  bottom: 16px;
  right: 16px;
  z-index: 1000;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: none;
  background: var(--tg-theme-bg-color, #fff);
  color: var(--tg-theme-button-color, #007aff);
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.map-fab:active { opacity: 0.7; transform: scale(0.92); }

/* Brighten dark map labels for readability */
.bright-labels {
  filter: brightness(1.8) contrast(1.1);
}

/* Disable touch/select quirks on Leaflet chrome */
.leaflet-container,
.leaflet-pane,
.leaflet-control-container,
.leaflet-control-attribution,
.leaflet-control-zoom {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* Hidden attribution for cleaner mini-app UX */
.leaflet-control-attribution {
  display: none !important;
}

/* Toggle Switch */
.toggle-switch { position: relative; display: inline-block; width: 51px; height: 31px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; cursor: pointer; inset: 0;
  background: var(--tg-theme-hint-color, #767577);
  border-radius: 31px; transition: 0.2s;
}
.toggle-track:before {
  content: ""; position: absolute;
  width: 27px; height: 27px; left: 2px; bottom: 2px;
  background: white; border-radius: 50%;
  transition: 0.2s; box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}
.toggle-switch input:checked + .toggle-track { background: var(--tg-theme-button-color, #34c759); }
.toggle-switch input:checked + .toggle-track:before { transform: translateX(20px); }

.account-card {
  display: grid;
  gap: 14px;
}

.account-main-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.account-avatar {
  width: 56px;
  height: 56px;
  border-radius: 18px;
  overflow: hidden;
  background: var(--tg-theme-secondary-bg-color, #f2f2f7);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  color: var(--tg-theme-button-color, #007aff);
  flex-shrink: 0;
}

.account-avatar.has-image {
  background: transparent;
}

.account-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.account-meta {
  min-width: 0;
  flex: 1;
}

.account-name-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.account-subline {
  margin-top: 4px;
  white-space: normal;
}

.account-auth-badge {
  background: rgba(52,199,89,0.14);
  color: #34c759;
  font-size: 12px;
  font-weight: 700;
  padding: 4px 8px;
  border-radius: 999px;
}

.account-actions {
  display: flex;
  justify-content: flex-end;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-height) + var(--safe-bottom) + 18px);
  transform: translateX(-50%) translateY(20px);
  background: rgba(17,17,17,0.92);
  color: #fff;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 10px 24px rgba(0,0,0,0.24);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease, transform 0.22s ease;
  z-index: 1200;
  max-width: min(92vw, 420px);
  text-align: center;
}

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