@import url('https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;600;700&family=Oswald:wght@500;600;700&display=swap');

:root {
  --bg: #f4f4f4;
  --surface: #ffffff;
  --surface-2: #fafafa;
  --accent: #931b15;
  --accent-hover: #7a1611;
  --accent-yellow: #fbe23c;
  --text: #272b2d;
  --text-muted: #5c6366;
  --border: #e5e5e5;
  --success: #2d8a4e;
  --radius: 4px;
  --shadow: 0 2px 16px rgba(39, 43, 45, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Montserrat', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  line-height: 1.6;
}

#app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  max-width: 420px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 20px;
}

.header {
  text-align: center;
  margin-bottom: 28px;
  padding-top: 20px;
}

.logo {
  font-family: 'Oswald', sans-serif;
  font-size: 2.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: var(--text);
  text-transform: uppercase;
  line-height: 1;
}

.logo::after {
  content: '';
  display: block;
  width: 48px;
  height: 4px;
  background: var(--accent-yellow);
  margin: 10px auto 0;
}

.subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 14px;
  font-weight: 500;
}

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

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

.form-group label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 8px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.phone-input-wrap {
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.phone-input-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(147, 27, 21, 0.12);
}

.phone-prefix {
  padding: 14px 0 14px 16px;
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  user-select: none;
  white-space: nowrap;
}

.phone-input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 1rem;
  padding: 14px 16px 14px 4px;
  letter-spacing: 0.02em;
}

input[type="password"],
input[type="text"].text-input {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
  padding: 14px 16px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="password"]:focus,
input[type="text"].text-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(147, 27, 21, 0.12);
}

.btn {
  width: 100%;
  padding: 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 0.95rem;
  font-weight: 700;
  font-family: 'Oswald', sans-serif;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  margin-top: 12px;
  font-family: 'Montserrat', sans-serif;
  text-transform: none;
  font-weight: 600;
}

.btn-bio {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  margin-top: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  font-family: 'Montserrat', sans-serif;
  text-transform: none;
}

.btn-bio:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
}

.bio-icon {
  font-size: 1.25rem;
}

.pin-subtitle {
  color: var(--text-muted);
  font-size: 0.95rem;
  margin-top: 8px;
}

.setup-text {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 24px;
  line-height: 1.6;
}

.pin-card {
  text-align: center;
}

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 24px 0 28px;
}

.pin-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid var(--border);
  transition: background 0.15s, border-color 0.15s;
}

.pin-dot.filled {
  background: var(--accent);
  border-color: var(--accent);
}

.pin-pad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-width: 280px;
  margin: 0 auto;
}

.pin-key {
  aspect-ratio: 1.2;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1.4rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
  box-shadow: var(--shadow);
}

.pin-key:active {
  transform: scale(0.95);
  background: var(--surface-2);
  border-color: var(--accent-yellow);
}

.pin-key-empty {
  visibility: hidden;
  pointer-events: none;
  box-shadow: none;
  border: none;
}

.pin-status {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 16px;
  min-height: 1.25rem;
}

.pin-key:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.error-msg {
  background: rgba(147, 27, 21, 0.08);
  border: 1px solid rgba(147, 27, 21, 0.25);
  color: var(--accent);
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.stats-grid {
  display: grid;
  gap: 12px;
  margin-top: 8px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--accent-yellow);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
  font-weight: 600;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
  font-family: 'Oswald', sans-serif;
  letter-spacing: 0.02em;
}

.stat-value.accent {
  color: var(--accent);
}

.stat-value.success {
  color: var(--success);
}

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

.lk-title {
  font-family: 'Oswald', sans-serif;
  font-size: 1.35rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text);
}

.logout-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.dashboard-screen {
  padding-bottom: 32px;
}

.dashboard-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 20px;
}

.dashboard-tab {
  padding: 12px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 700;
  font-family: 'Oswald', sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s, color 0.2s;
}

.dashboard-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.trainers-list {
  display: grid;
  gap: 12px;
}

.trainer-card {
  display: flex;
  gap: 14px;
  width: 100%;
  text-align: left;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  border-left: 4px solid var(--accent-yellow);
  cursor: pointer;
  transition: border-color 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.trainer-card:active {
  transform: scale(0.99);
}

.trainer-photo {
  width: 72px;
  height: 88px;
  object-fit: cover;
  border-radius: var(--radius);
  flex-shrink: 0;
}

.trainer-info {
  min-width: 0;
}

.trainer-name {
  font-family: 'Oswald', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.trainer-short {
  font-size: 0.85rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.trainer-more {
  display: inline-block;
  margin-top: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
}

.trainer-phones {
  margin-top: 20px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.trainer-phone-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.trainer-phone {
  color: var(--accent);
  font-weight: 700;
  font-size: 1rem;
  text-decoration: none;
}

.trainer-phone:hover {
  text-decoration: underline;
}

.trainer-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.trainer-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(39, 43, 45, 0.55);
}

.trainer-modal-panel {
  position: relative;
  width: 100%;
  max-width: 420px;
  max-height: 90dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 12px 12px 0 0;
  padding: 20px 20px calc(24px + var(--safe-bottom));
  box-shadow: 0 -8px 32px rgba(39, 43, 45, 0.2);
}

.trainer-modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: var(--bg);
  color: var(--text-muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  z-index: 1;
}

.trainer-modal-photo {
  width: 100%;
  height: auto;
  max-height: min(65dvh, 480px);
  object-fit: contain;
  object-position: center top;
  border-radius: var(--radius);
  display: block;
  background: var(--surface-2);
}

.trainer-modal-name {
  font-family: 'Oswald', sans-serif;
  font-size: 1.5rem;
  font-weight: 600;
  margin: 16px 0;
  color: var(--text);
}

.trainer-detail-section {
  margin-bottom: 16px;
}

.trainer-detail-heading {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
  font-weight: 600;
}

.trainer-detail-list {
  padding-left: 18px;
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.6;
}

.trainer-detail-list li + li {
  margin-top: 6px;
}

.qr-card {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow);
}

.member-qr {
  display: flex;
  justify-content: center;
  margin: 8px auto 0;
  min-height: 200px;
}

.member-qr img,
.member-qr canvas {
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.qr-countdown {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--accent);
  font-weight: 600;
}

.qr-label {
  margin-top: 8px;
  font-size: 0.7rem;
  color: var(--text-muted);
  word-break: break-all;
  line-height: 1.4;
}

.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 8px;
}

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

@media (max-width: 380px) {
  .screen {
    padding: 16px;
  }

  .stat-value {
    font-size: 1.25rem;
  }

  .logo {
    font-size: 2.25rem;
  }
}
