/* Lovim Mini App – современный дизайн, совместим с Telegram WebApp theme */
:root {
  /* Telegram theme (подставляются из WebApp) */
  --tg-theme-bg-color: #ffffff;
  --tg-theme-text-color: #1a1a1a;
  --tg-theme-hint-color: #8e8e93;
  --tg-theme-link-color: #007aff;
  --tg-theme-button-color: #007aff;
  --tg-theme-button-text-color: #ffffff;
  --tg-theme-secondary-bg-color: #f2f2f7;
  --tg-safe-area-inset-top: 0;
  --tg-safe-area-inset-bottom: 0;
  --tg-safe-area-inset-left: 0;
  --tg-safe-area-inset-right: 0;
  /* Design system */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --radius-full: 9999px;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-card: 0 2px 8px rgba(0, 0, 0, 0.06);
  --section-gap: 16px;
  --tap-height: 48px;
  --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, sans-serif;
  --transition: 0.2s ease;
}

* {
  box-sizing: border-box;
}

html {
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.45;
  background: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  min-height: 100vh;
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

body.mini-app-ready {
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.app {
  display: none;
  padding-top: 56px;
  padding-bottom: 64px;
  min-height: 100vh;
  background: var(--tg-theme-bg-color);
}
.app.active {
  display: block;
}

/* ========== Top bar ========== */
.top-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--tg-theme-bg-color);
  box-shadow: var(--shadow-sm);
  z-index: 100;
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
}
.top-bar-logo {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--tg-theme-text-color);
  letter-spacing: -0.03em;
}
.top-bar-profile {
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: var(--radius-full);
  background: var(--tg-theme-secondary-bg-color);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition), opacity var(--transition);
}
.top-bar-profile:active {
  transform: scale(0.96);
  opacity: 0.9;
}
.top-bar-avatar {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.top-bar-avatar-placeholder {
  font-size: 1.15rem;
  color: var(--tg-theme-hint-color);
}

/* ========== Bottom tab bar ========== */
.bottom-tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--tg-theme-bg-color);
  box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.06);
  z-index: 100;
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tab-btn {
  flex: 1;
  max-width: 72px;
  height: 100%;
  padding: 0;
  border: none;
  background: none;
  color: var(--tg-theme-hint-color);
  font-size: 1.4rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--transition), transform var(--transition);
}
.tab-btn:active {
  transform: scale(0.9);
}
.tab-btn.active {
  color: var(--tg-theme-button-color);
}
.bottom-tab-bar.hidden {
  display: none;
}

/* ========== Stub & Loading ========== */
.stub {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 32px;
  text-align: center;
  background: var(--tg-theme-bg-color);
}
.stub h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--tg-theme-text-color);
  letter-spacing: -0.02em;
}
.stub p {
  color: var(--tg-theme-hint-color);
  font-size: 1rem;
  line-height: 1.5;
  max-width: 280px;
  margin: 0;
}

.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  color: var(--tg-theme-hint-color);
  font-size: 1rem;
}

/* ========== Screens ========== */
.screen {
  display: none;
  padding: 20px;
  padding-left: max(20px, env(safe-area-inset-left));
  padding-right: max(20px, env(safe-area-inset-right));
  animation: screenIn 0.25s ease;
}
.screen.active {
  display: block;
}
@keyframes screenIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 20px;
  letter-spacing: -0.02em;
  color: var(--tg-theme-text-color);
}

/* Back link */
[data-screen-back] {
  display: inline-flex;
  align-items: center;
  margin-bottom: 16px;
  font-size: 0.9375rem;
  color: var(--tg-theme-link-color);
  text-decoration: none;
  transition: opacity var(--transition);
}
[data-screen-back]:active {
  opacity: 0.7;
}

/* ========== Buttons ========== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap-height);
  padding: 0 24px;
  border: none;
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  width: 100%;
  max-width: 320px;
  transition: transform var(--transition), opacity var(--transition), box-shadow var(--transition);
}
.btn:active {
  transform: scale(0.98);
  opacity: 0.95;
}
.btn-primary {
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
  box-shadow: var(--shadow-sm);
}
.btn-primary:active {
  box-shadow: none;
}
.btn-secondary {
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
}
.btn + .btn {
  margin-top: 12px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}
.actions .btn {
  margin-top: 0;
}

/* ========== Cards ========== */
.card {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: var(--section-gap);
  box-shadow: var(--shadow-card);
}
.card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--tg-theme-text-color);
}
.card-text {
  font-size: 0.9375rem;
  line-height: 1.5;
  color: var(--tg-theme-hint-color);
}

/* ========== List ========== */
.list {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--tg-theme-bg-color);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.list-item {
  display: flex;
  align-items: center;
  min-height: var(--tap-height);
  padding: 14px 20px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  text-decoration: none;
  color: var(--tg-theme-text-color);
  font-size: 1rem;
  transition: background var(--transition);
}
.list-item:last-child {
  border-bottom: none;
}
.list-item:active {
  background: var(--tg-theme-secondary-bg-color);
}

/* ========== Feed ========== */
.feed-header {
  margin-bottom: 20px;
}
.feed-header .page-title {
  margin-bottom: 16px;
}
.feed-tabs {
  display: flex;
  gap: 10px;
  margin-bottom: 0;
}
.feed-tab {
  flex: 1;
  padding: 10px 14px;
  border: none;
  border-radius: var(--radius-full);
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}
.feed-tab:active {
  transform: scale(0.98);
}
.feed-tab.active {
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
}

.feed-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.feed-item {
  background: var(--tg-theme-bg-color);
  border-radius: var(--radius-lg);
  margin-bottom: var(--section-gap);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  transition: transform var(--transition), box-shadow var(--transition);
}
.feed-item:active {
  transform: scale(0.99);
  box-shadow: var(--shadow-sm);
}
.feed-item img {
  width: 100%;
  height: 220px;
  object-fit: cover;
  display: block;
  background: var(--tg-theme-secondary-bg-color);
}
.feed-item .body {
  padding: 16px;
}
.feed-item .meta {
  font-size: 0.8125rem;
  color: var(--tg-theme-hint-color);
  margin-bottom: 6px;
}
.feed-item .title {
  font-weight: 600;
  font-size: 1.0625rem;
  color: var(--tg-theme-text-color);
}

/* ========== Map ========== */
.map-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}
.map-filter-btn {
  padding: 8px 14px;
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: var(--radius-full);
  background: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.map-filter-btn:active { opacity: 0.9; }
.map-filter-btn.active {
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
  border-color: transparent;
}

.map-container {
  position: relative;
  height: 340px;
  border-radius: var(--radius-lg);
  background: var(--tg-theme-secondary-bg-color);
  margin-bottom: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-card);
}
.map-container #map {
  width: 100%;
  height: 100%;
  border-radius: var(--radius-lg);
}

.map-controls {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.map-controls > * {
  pointer-events: auto;
}
.map-controls-zoom {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--tg-theme-bg-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.map-control-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  background: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.map-control-btn:hover,
.map-control-btn:active {
  background: var(--tg-theme-secondary-bg-color);
}
.map-controls-type {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: var(--tg-theme-bg-color);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}
.map-type-btn {
  padding: 8px 12px;
  border: none;
  background: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  transition: background var(--transition), color var(--transition);
}
.map-type-btn:hover,
.map-type-btn:active {
  background: var(--tg-theme-secondary-bg-color);
}
.map-type-btn.active {
  background: var(--tg-theme-button-color);
  color: var(--tg-theme-button-text-color);
}

/* ========== Profile ========== */
.profile-header {
  text-align: center;
  padding: 28px 0 24px;
  margin-bottom: 24px;
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-card);
}
.profile-avatar {
  width: 88px;
  height: 88px;
  border-radius: var(--radius-full);
  object-fit: cover;
  margin-bottom: 12px;
  border: 3px solid var(--tg-theme-bg-color);
  box-shadow: var(--shadow-sm);
}
.profile-name {
  font-size: 1.35rem;
  font-weight: 700;
  margin-bottom: 4px;
  letter-spacing: -0.02em;
  color: var(--tg-theme-text-color);
}
.profile-username {
  font-size: 0.9375rem;
  color: var(--tg-theme-hint-color);
  margin-bottom: 20px;
}
.profile-stats {
  display: flex;
  justify-content: center;
  gap: 32px;
}
.profile-stats span {
  font-size: 0.875rem;
  color: var(--tg-theme-hint-color);
}
.profile-stats strong {
  display: block;
  color: var(--tg-theme-text-color);
  font-size: 1.25rem;
  font-weight: 700;
  margin-top: 2px;
}

/* ========== Referral ========== */
.referral-code-box {
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
  margin: 20px 0;
  word-break: break-all;
  font-family: 'SF Mono', 'Menlo', monospace;
  font-size: 0.9375rem;
  color: var(--tg-theme-text-color);
  box-shadow: var(--shadow-sm);
}
.rankings-unavailable {
  padding: 24px;
  text-align: center;
  font-size: 1rem;
  color: var(--tg-theme-hint-color);
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius-md);
  margin: 0 0 var(--section-gap);
}

/* ========== Forms ========== */
.form-group {
  margin-bottom: 20px;
}
.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--tg-theme-text-color);
}
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  min-height: 48px;
  padding: 14px 18px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: var(--radius-md);
  font-size: 1rem;
  font-family: inherit;
  background: var(--tg-theme-bg-color);
  color: var(--tg-theme-text-color);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--tg-theme-button-color);
  box-shadow: 0 0 0 3px rgba(0, 122, 255, 0.15);
}
.form-group textarea {
  min-height: 100px;
  resize: vertical;
  padding: 14px 18px;
}

/* ========== Chat ========== */
.chat-messages {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  max-height: 45vh;
  overflow-y: auto;
}
.chat-msg {
  padding: 12px 16px;
  margin-bottom: 8px;
  background: var(--tg-theme-secondary-bg-color);
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  line-height: 1.45;
  max-width: 85%;
}
.chat-send {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
}
.chat-send input {
  flex: 1;
  min-height: 48px;
  padding: 12px 18px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  border-radius: var(--radius-full);
  font-size: 1rem;
  font-family: inherit;
  background: var(--tg-theme-secondary-bg-color);
  color: var(--tg-theme-text-color);
}
.chat-send input:focus {
  outline: none;
  border-color: var(--tg-theme-button-color);
}

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