/* language: CSS, file: webapp/style.css
   mobile-first, uses Telegram WebApp CSS variables with sane fallbacks */

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

:root {
  --tg-bg: var(--tg-theme-bg-color, #1c1c1e);
  --tg-text: var(--tg-theme-text-color, #f2f2f7);
  --tg-hint: var(--tg-theme-hint-color, #8e8e93);
  --tg-btn: var(--tg-theme-button-color, #2ea6ff);
  --tg-btn-text: var(--tg-theme-button-text-color, #ffffff);
  --tg-card: var(--tg-theme-secondary-bg-color, #2c2c2e);
  --tg-danger: #e74c3c;
  --tg-success: #2ecc71;
  --radius: 12px;
  --gap: 12px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--tg-bg);
  color: var(--tg-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}

.boot {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  gap: 16px;
  color: var(--tg-hint);
}

.boot-text { font-size: 14px; }

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0 16px;
  border-bottom: 1px solid rgba(127,127,127,0.15);
  margin-bottom: 16px;
}

.header h1 {
  font-size: 20px;
  font-weight: 600;
  margin: 0;
}

.header .user-id {
  font-size: 12px;
  color: var(--tg-hint);
}

.content {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.card {
  background: var(--tg-card);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 15px;
  font-weight: 500;
}

.card-hint {
  font-size: 13px;
  color: var(--tg-hint);
  margin-top: 2px;
}

.input, .select {
  width: 100%;
  padding: 10px 12px;
  background: rgba(127,127,127,0.12);
  border: 1px solid rgba(127,127,127,0.18);
  border-radius: 10px;
  color: var(--tg-text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.input:focus, .select:focus { border-color: var(--tg-btn); }

.input::placeholder { color: var(--tg-hint); }

.select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--tg-hint) 50%),
                    linear-gradient(135deg, var(--tg-hint) 50%, transparent 50%);
  background-position: calc(100% - 16px) 50%, calc(100% - 11px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-inline-end: 32px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

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

.slider {
  position: absolute;
  inset: 0;
  background: rgba(127,127,127,0.35);
  border-radius: 26px;
  cursor: pointer;
  transition: background 0.2s;
}

.slider::before {
  content: "";
  position: absolute;
  height: 20px;
  width: 20px;
  top: 3px;
  inset-inline-start: 3px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.switch input:checked + .slider { background: var(--tg-btn); }
.switch input:checked + .slider::before { transform: translateX(20px); }

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 18px;
  font-size: 15px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.05s;
}

.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--tg-btn); color: var(--tg-btn-text); }
.btn-danger { background: var(--tg-danger); color: #fff; }
.btn-block { width: 100%; }

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(127,127,127,0.25);
  border-top-color: var(--tg-btn);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

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

.toast-container {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
  width: calc(100% - 32px);
  max-width: 400px;
}

.toast {
  padding: 11px 14px;
  border-radius: 10px;
  font-size: 14px;
  color: #fff;
  background: #333;
  box-shadow: 0 6px 24px rgba(0,0,0,0.28);
  animation: toast-in 0.2s ease-out;
  word-break: break-word;
}

.toast-success { background: var(--tg-success); }
.toast-error { background: var(--tg-danger); }

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

@media (max-width: 380px) {
  #app { padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); }
  .header h1 { font-size: 18px; }
}
