:root {
  --bg: #F0FAF6;
  --bg-grad-1: #E7F8EF;
  --bg-grad-2: #F0FAF6;
  --surface: #FFFFFF;
  --surface-2: #F5FBF8;
  --text: #0F2820;
  --text-secondary: #5C7A6F;
  --primary: #10A66B;
  --primary-dark: #0E9F6E;
  --primary-soft: #DCF5E8;
  --gold: #F4A300;
  --gold-light: #FFD86B;
  --gold-soft: #FFF4D6;
  --success: #10A66B;
  --danger: #E04848;
  --warning: #F4A300;
  --border: #DCEAE3;
  --disabled: #BFD3CB;
  --shadow-sm: 0 1px 2px rgba(15, 60, 40, 0.06);
  --shadow: 0 4px 14px rgba(15, 60, 40, 0.08);
  --shadow-coin: 0 6px 16px rgba(244, 163, 0, 0.32);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B1814;
    --bg-grad-1: #0F2620;
    --bg-grad-2: #0B1814;
    --surface: #142A22;
    --surface-2: #1A332A;
    --text: #E8F5EE;
    --text-secondary: #8FA89E;
    --primary: #34D399;
    --primary-dark: #10A66B;
    --primary-soft: #1F4A36;
    --gold: #FFD86B;
    --gold-light: #FFE58A;
    --gold-soft: #3A2D0E;
    --border: #1F3D33;
    --disabled: #2A453B;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "SF Pro Display", "Segoe UI", Roboto, sans-serif;
  background: linear-gradient(180deg, var(--bg-grad-1), var(--bg-grad-2));
  background-attachment: fixed;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  padding-top: env(safe-area-inset-top);
  min-height: 100vh;
}

.hidden { display: none !important; }

.screen { min-height: 100vh; }

/* ---------- Onboarding ---------- */
.onboarding {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.onboarding-content {
  width: 100%;
  max-width: 420px;
  text-align: center;
}

.logo {
  width: 96px;
  height: 96px;
  margin: 0 auto 20px;
  border-radius: 28px;
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
  font-weight: 900;
  color: #7A4A00;
  box-shadow: var(--shadow-coin);
  position: relative;
}

.logo::after {
  content: '';
  position: absolute;
  inset: 6px;
  border-radius: 22px;
  border: 2px solid rgba(122, 74, 0, 0.18);
  pointer-events: none;
}

.onboarding h1 {
  margin: 0 0 8px;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.tagline {
  color: var(--text-secondary);
  margin: 0 0 32px;
  font-size: 15px;
  line-height: 1.45;
  padding: 0 8px;
}

.step {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  text-align: left;
  box-shadow: var(--shadow);
}

.step input[type="url"] {
  margin-bottom: 14px;
  margin-top: 0;
}

/* ---------- Main screen layout ---------- */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.app-header {
  background: var(--surface);
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.app-header h1 {
  font-size: 22px;
  font-weight: 800;
  margin: 0;
  letter-spacing: -0.4px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-header h1::before {
  content: '₽';
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  color: #7A4A00;
  font-size: 18px;
  font-weight: 900;
  box-shadow: var(--shadow-coin);
  flex-shrink: 0;
}

.header-sub {
  margin: 4px 0 0 40px;
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
}

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

.icon-btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-size: 18px;
  color: var(--primary);
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  transition: transform 0.15s;
}

.icon-btn:active { transform: scale(0.93); }
.icon-btn svg { display: block; }
#refreshBtn:active svg { animation: spin-once 0.5s ease; }
#settingsBtn:active svg { transform: rotate(60deg); transition: transform 0.3s; }

@keyframes spin-once {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ---------- Places list ---------- */
.places-list {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-bottom: 130px;
}

.place-card {
  background: var(--surface);
  border-radius: 18px;
  padding: 18px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}

.place-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  opacity: 0;
  transition: opacity 0.3s;
}

.place-card.is-eligible::before { opacity: 1; }

.place-card .top-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

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

.place-card .name {
  font-size: 17px;
  font-weight: 700;
  margin: 0 0 4px;
  letter-spacing: -0.2px;
  line-height: 1.25;
}

.place-card .name-text { color: var(--text); }

.place-card .category {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid var(--primary);
  border-radius: 6px;
  padding: 2px 8px;
  margin: 4px 0 8px;
  letter-spacing: 0.2px;
  line-height: 1.3;
}

.place-card .address {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.4;
}

.coin-badge {
  flex-shrink: 0;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #7A4A00;
  font-size: 22px;
  font-weight: 900;
  box-shadow: var(--shadow-coin);
}

.place-card .meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface-2);
  border-radius: 10px;
  border: 1px solid var(--border);
}

.place-card .distance {
  font-size: 13px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.place-card .status {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.place-card .status.pending { color: var(--text-secondary); font-weight: 500; }
.place-card .status.near { color: var(--primary); }
.place-card .status.eligible { color: var(--gold); }
.place-card .status.reviewed { color: var(--text-secondary); font-weight: 500; }
.place-card .status.submitted { color: var(--warning); }
.place-card .status.approved { color: var(--success); }
.place-card .status.rejected { color: var(--danger); }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}

.place-card .status.near .status-dot {
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.4; transform: scale(0.85); }
}

.review-btn {
  width: 100%;
  padding: 14px;
  border-radius: 12px;
  border: none;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
  letter-spacing: 0.2px;
}

.review-btn:active:not(:disabled) { transform: scale(0.98); }

.review-btn:not(:disabled) {
  background: linear-gradient(135deg, var(--gold-light), var(--gold));
  color: #7A4A00;
  box-shadow: var(--shadow-coin);
}

.review-btn:disabled {
  background: var(--surface-2);
  color: var(--text-secondary);
  cursor: not-allowed;
  border: 1px solid var(--border);
}

.review-btn.reviewed {
  background: transparent;
  color: var(--success);
  border: 1.5px solid var(--success);
  box-shadow: none;
}

.review-btn.submitted {
  background: var(--gold-soft);
  color: var(--warning);
  border: 1.5px solid var(--warning);
  box-shadow: none;
}

.review-btn.rejected {
  background: transparent;
  color: var(--danger);
  border: 1.5px solid var(--danger);
}

.history-btn {
  margin-top: 12px;
  padding: 14px;
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 14px;
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: transform 0.1s;
}
.history-btn:active { transform: scale(0.985); }

.modal-tall {
  height: 90vh;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.filter-chips {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.chip {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.chip.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.chip-count {
  font-size: 11px;
  background: rgba(255,255,255,0.25);
  padding: 1px 6px;
  border-radius: 10px;
  font-variant-numeric: tabular-nums;
}

.chip:not(.active) .chip-count {
  background: var(--bg);
  color: var(--text-secondary);
}

#historyList {
  overflow-y: auto;
  flex: 1;
}

.empty-state {
  text-align: center;
  padding: 80px 20px;
  color: var(--text-secondary);
}

.empty-state::before {
  content: '👟';
  display: block;
  font-size: 56px;
  margin-bottom: 12px;
  opacity: 0.5;
}

.empty-state.empty-wallet::before { content: '💰'; }

.empty-state p { margin: 4px 0; }
.empty-state .hint { font-size: 14px; opacity: 0.7; }

.loading {
  text-align: center;
  padding: 40px;
  color: var(--text-secondary);
}

.settings-section {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-top: 14px;
}

.settings-section-title {
  margin: 0 0 4px;
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.settings-section-hint {
  margin: 0 0 12px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.settings-section .btn-secondary {
  margin-top: 0;
  padding: 11px;
  font-size: 14px;
}

.settings-howto {
  margin-top: 18px;
  font-weight: 500;
  font-size: 13px;
  color: var(--text-secondary);
}

/* ---------- Tab bar ---------- */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
}

.tab-btn.active { color: var(--primary); }

.tab-icon {
  font-size: 20px;
  line-height: 1;
}

/* ---------- Wallet ---------- */
.wallet-content {
  padding: 20px 16px;
  padding-bottom: 130px;
}

.balance-card {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 22px;
  padding: 28px 24px;
  color: white;
  text-align: center;
  box-shadow: 0 10px 30px rgba(16, 166, 107, 0.3);
  position: relative;
  overflow: hidden;
  margin-bottom: 24px;
}

.balance-card::before {
  content: '₽';
  position: absolute;
  font-size: 220px;
  font-weight: 900;
  line-height: 1;
  top: -40px;
  right: -40px;
  opacity: 0.08;
}

.balance-label {
  font-size: 13px;
  opacity: 0.85;
  margin: 0 0 8px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.balance-amount {
  font-size: 56px;
  font-weight: 900;
  margin: 0;
  letter-spacing: -2px;
  font-variant-numeric: tabular-nums;
}

.balance-amount .rub {
  font-size: 28px;
  margin-left: 6px;
  opacity: 0.85;
}

.balance-sub {
  font-size: 13px;
  opacity: 0.85;
  margin: 8px 0 0;
}

.referral-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.referral-head {
  margin-bottom: 14px;
}

.referral-label {
  font-size: 16px;
  font-weight: 800;
  margin: 0 0 4px;
  letter-spacing: -0.2px;
}

.referral-sub {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 0;
  line-height: 1.4;
}

.referral-code-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.referral-code-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 600;
}

.referral-code {
  font-family: 'SF Mono', Menlo, monospace;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 2px;
  color: var(--gold);
  flex: 1;
}

.referral-share-btn {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border: none;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.referral-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.referral-stat {
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.referral-stat-label {
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.referral-stat-num {
  font-size: 20px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.referral-stat-amount {
  font-size: 13px;
  color: var(--gold);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.submissions-section h2 {
  font-size: 17px;
  font-weight: 800;
  margin: 0 0 12px;
}

.submissions-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.submission-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-sm);
}

.submission-card .sub-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.submission-card.pending .sub-icon {
  background: var(--gold-soft);
  color: var(--warning);
}
.submission-card.approved .sub-icon {
  background: var(--primary-soft);
  color: var(--success);
}
.submission-card.rejected .sub-icon {
  background: rgba(224, 72, 72, 0.15);
  color: var(--danger);
}

.submission-card .sub-info {
  flex: 1;
  min-width: 0;
}

.submission-card .sub-place {
  font-weight: 600;
  font-size: 14px;
  margin: 0 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.submission-card .sub-status {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 0;
}

.submission-card .sub-amount {
  font-weight: 700;
  font-size: 15px;
  flex-shrink: 0;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}

.submission-card.approved .sub-amount { color: var(--success); }
.submission-card.rejected .sub-amount { color: var(--danger); text-decoration: line-through; opacity: 0.6; }
.submission-card.pending .sub-amount { color: var(--warning); }

/* ---------- Modal ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 24, 0.55);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}

.modal.hidden { display: none !important; }

.modal-content {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
}

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

.modal-header h2 {
  margin: 0;
  font-size: 20px;
  font-weight: 800;
}

.modal-content label {
  display: block;
  margin-bottom: 14px;
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 600;
}

input[type="url"], input[type="text"], input[type="number"] {
  display: block;
  width: 100%;
  padding: 14px;
  margin-top: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}

input:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--surface);
}

input[type="range"] {
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  background: var(--surface-2);
  border-radius: 3px;
  margin-top: 12px;
  margin-bottom: 4px;
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

.btn-primary, .btn-secondary {
  width: 100%;
  padding: 15px;
  border-radius: 12px;
  border: none;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 10px;
  letter-spacing: 0.2px;
  transition: transform 0.1s;
  font-family: inherit;
}

.btn-primary:active, .btn-secondary:active { transform: scale(0.985); }

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  box-shadow: 0 4px 12px rgba(16, 166, 107, 0.32);
}

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

.error {
  color: var(--danger);
  font-size: 13px;
  margin: 12px 0 0;
  font-weight: 500;
}

.hint {
  font-size: 13px;
  color: var(--text-secondary);
  margin: 12px 0 0;
  line-height: 1.4;
}

.hint.error {
  color: var(--danger);
  font-weight: 500;
}

.how-list {
  margin: 0 0 16px;
  padding-left: 20px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
.how-list li { margin-bottom: 8px; }

.howto-section {
  font-size: 15px;
  font-weight: 700;
  margin: 18px 0 6px;
  color: var(--text);
}

.howto-compact {
  margin: 0 0 16px;
  padding: 12px 14px 12px 28px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text);
  line-height: 1.55;
}
.howto-compact li { margin: 0; padding: 0; }
.howto-compact li + li { margin-top: 4px; }

.upload-preview {
  margin-bottom: 16px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  max-height: 360px;
}

.upload-preview img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 360px;
  object-fit: contain;
  background: var(--surface-2);
}

/* ========== OTA update banner ========== */
.update-banner {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom, 0));
  background: linear-gradient(135deg, #2DC080 0%, #1F8F5C 100%);
  color: #fff;
  border-radius: 14px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .28);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  z-index: 9999;
  font-size: 14px;
  animation: update-banner-in .3s ease-out;
}
.update-banner.hidden { display: none; }
@keyframes update-banner-in {
  from { transform: translateY(100%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.update-banner-text {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 auto;
  min-width: 0;
}
.update-banner-text strong { color: #F5C842; font-weight: 700; }
.update-banner-icon { font-size: 20px; flex-shrink: 0; }
.update-banner-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}
.update-btn-install,
.update-btn-later {
  border: 0;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.update-btn-install { background: #F5C842; color: #5A3B0E; }
.update-btn-install:active { background: #E5A82A; }
.update-btn-later {
  background: transparent;
  color: rgba(255, 255, 255, .85);
  border: 1px solid rgba(255, 255, 255, .35);
}
.update-btn-later:active { background: rgba(255, 255, 255, .15); }

/* ========== iOS install prompt ========== */
.ios-steps {
  text-align: left;
  padding: 0 0 0 1.2em;
  margin: 16px auto 0;
  max-width: 360px;
  line-height: 1.5;
  color: var(--text-2, #5A6B62);
  font-size: 15px;
}
.ios-steps li { margin-bottom: 10px; }
.ios-steps strong { color: var(--text, #16201A); }
.hint-web {
  font-size: 13px;
  color: var(--text-2, #5A6B62);
  margin-top: 12px;
  text-align: center;
  display: block !important;
}
