/* App shell layout */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: calc(var(--tg-viewport-height, 100vh));
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--secondary-bg);
  min-height: 48px;
}
.app-header h1 {
  font-size: 18px;
  font-weight: 700;
  flex: 1;
  text-align: center;
}
#btn-back {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--primary);
  transition: opacity 0.2s;
}
#btn-back.hidden { opacity: 0; pointer-events: none; }

/* Content area */
#app-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  padding-bottom: 60px; /* space for bottom nav */
}

/* Bottom navigation */
#bottom-nav {
  display: flex;
  background: var(--bottom-bar-bg-color, var(--secondary-bg));
  border-top: 1px solid var(--section-separator-color, transparent);
  position: sticky;
  bottom: 0;
  z-index: 100;
}
#bottom-nav button {
  flex: 1;
  border: none;
  background: none;
  padding: 8px 4px;
  font-size: 10px;
  color: var(--hint);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: color 0.2s;
}
#bottom-nav button .nav-icon { font-size: 20px; }
#bottom-nav button.active { color: var(--primary); font-weight: 600; }

/* Reusable components */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  color: var(--hint);
  font-size: 14px;
}
.loading::after {
  content: '';
  width: 20px;
  height: 20px;
  margin-left: 8px;
  border: 2px solid var(--hint);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
  color: var(--hint);
}
.empty-state .icon { font-size: 48px; margin-bottom: 12px; }
.empty-state p { margin: 4px 0; font-size: 15px; }

.card {
  background: var(--card-bg, var(--secondary-bg));
  border-radius: var(--border-radius);
  padding: 14px;
  margin-bottom: 8px;
  transition: transform 0.1s;
}
.card:active { transform: scale(0.98); }

.error {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 20px;
  text-align: center;
}
.error h2 { font-size: 24px; margin-bottom: 8px; }
.error p { color: var(--hint); margin-bottom: 12px; font-size: 13px; }

.tg-button {
  background: var(--button-color, var(--primary));
  color: var(--button-text-color, #fff);
  border: none;
  border-radius: 8px;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  width: 100%;
}
.tg-button:active { opacity: 0.7; }
.tg-button-secondary:active { opacity: 0.7; }

/* Toast notifications */
.toast-container {
  position: fixed;
  top: 60px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 90%;
  width: 320px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border-radius: 10px;
  background: var(--secondary-bg, #333);
  color: var(--text, #fff);
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  pointer-events: auto;
  transform: translateY(-20px);
  opacity: 0;
  transition: transform 0.25s ease, opacity 0.25s ease;
}
.toast-visible {
  transform: translateY(0);
  opacity: 1;
}
.toast-hiding {
  transform: translateY(-10px);
  opacity: 0;
}
.toast-success { border-left: 3px solid #4caf50; }
.toast-error { border-left: 3px solid #f44336; }
.toast-info { border-left: 3px solid #2196f3; }
.toast-icon { flex-shrink: 0; font-size: 16px; }
.toast-text { flex: 1; }
.toast-close {
  background: none; border: none; font-size: 18px;
  cursor: pointer; color: var(--hint, #999); padding: 0 2px;
  line-height: 1;
}
.tg-button-secondary {
  background: var(--secondary-bg);
  color: var(--text);
}

.tg-input {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--hint);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  outline: none;
}
.tg-input:focus { border-color: var(--primary); }

.tg-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--button-text-color, #fff);
  display: inline-block;
}

.tg-text-hint { color: var(--hint); font-size: 13px; }

.hidden { display: none !important; }

.page { min-height: 100%; }
