:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #000000);
  --hint: var(--tg-theme-hint-color, #999999);
  --link: var(--tg-theme-link-color, #2678b6);
  --button: var(--tg-theme-button-color, #2678b6);
  --button-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --card-bg: var(--tg-theme-secondary-bg-color, #f5f5f5);
  --border: rgba(0,0,0,0.08);
  --success: #34c759;
  --danger: #ff3b30;
  --warning: #ff9500;
  --radius: 12px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: 70px;
  -webkit-tap-highlight-color: transparent;
}

/* === HEADER === */
.header {
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 50;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header h1 {
  font-size: 18px;
  font-weight: 700;
}

.user-info {
  font-size: 13px;
  color: var(--hint);
}

.btn-back {
  background: none;
  border: none;
  font-size: 22px;
  color: var(--button);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 8px;
}

.btn-back:active { opacity: 0.5; }

/* === BOTTOM NAV === */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 50;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px 6px;
  border: none;
  background: none;
  color: var(--hint);
  cursor: pointer;
  transition: color 0.2s;
}

.nav-btn.active { color: var(--button); }
.nav-icon { font-size: 20px; }
.nav-label { font-size: 10px; font-weight: 500; }

/* === CONTENT === */
.content {
  padding: 16px;
  min-height: calc(100vh - 120px);
}

/* === LOADING === */
.loading-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--hint);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--button);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 12px;
}

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

/* === CARDS === */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}

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

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

.card-subtitle {
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 8px;
  line-height: 1.4;
}

.card-text {
  font-size: 13px;
  color: var(--hint);
  line-height: 1.4;
  white-space: pre-wrap;
  max-height: 60px;
  overflow: hidden;
}

.card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 10px;
}

.card-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 14px;
}

.card-row + .card-row { border-top: 1px solid var(--border); }
.card-row-label { color: var(--hint); }
.card-row-value { font-weight: 500; }

/* === BADGES === */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 500;
}

.badge-active { background: var(--success); color: white; }
.badge-inactive { background: var(--hint); color: white; }
.badge-warning { background: var(--warning); color: white; }
.badge-premium { background: linear-gradient(135deg, #FFD700, #FFA500); color: #333; }
.badge-standard { background: linear-gradient(135deg, #87CEEB, #4169E1); color: white; }
.badge-pinned { background: linear-gradient(135deg, #98FB98, #228B22); color: white; }

/* === BUTTONS === */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:active { opacity: 0.6; }
.btn-primary { background: var(--button); color: var(--button-text); }
.btn-danger { background: var(--danger); color: white; }
.btn-secondary { background: var(--card-bg); color: var(--text); border: 1px solid var(--border); }
.btn-success { background: var(--success); color: white; }
.btn-small { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; padding: 12px; font-size: 16px; justify-content: center; }
.btn-outline { background: transparent; border: 1.5px solid var(--button); color: var(--button); }

/* === HOME PAGE === */
.home-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px 8px;
  text-align: center;
}

.stat-number {
  font-size: 24px;
  font-weight: 700;
  color: var(--button);
}

.stat-label {
  font-size: 11px;
  color: var(--hint);
  margin-top: 2px;
}

.home-plan {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.plan-info { display: flex; flex-direction: column; gap: 4px; }
.plan-name { font-weight: 600; font-size: 15px; }
.plan-detail { font-size: 12px; color: var(--hint); }

.home-balance {
  background: linear-gradient(135deg, var(--button), #1a5490);
  border-radius: var(--radius);
  padding: 16px;
  color: white;
  margin-bottom: 12px;
}

.balance-amount {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 4px;
}

.balance-label {
  font-size: 12px;
  opacity: 0.8;
}

.balance-earned {
  font-size: 13px;
  opacity: 0.9;
  margin-top: 8px;
}

.home-level {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

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

.level-name { font-weight: 600; font-size: 15px; }
.level-percent { color: var(--button); font-weight: 600; }

.progress-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--button);
  border-radius: 3px;
  transition: width 0.3s;
}

.level-detail {
  font-size: 12px;
  color: var(--hint);
  margin-top: 6px;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.quick-btn {
  background: var(--card-bg);
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  cursor: pointer;
  transition: opacity 0.15s;
}

.quick-btn:active { opacity: 0.6; }
.quick-btn-icon { font-size: 24px; margin-bottom: 4px; }
.quick-btn-text { font-size: 13px; font-weight: 500; }

/* === SECTION === */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-header h2 { font-size: 18px; }
.section-title { font-size: 16px; font-weight: 600; margin-bottom: 10px; }

/* === EMPTY STATE === */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--hint);
  font-size: 14px;
}

.empty-icon { font-size: 48px; margin-bottom: 12px; }
.empty-text { line-height: 1.5; }

/* === HINT === */
.hint {
  color: var(--hint);
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 12px;
}

/* === MODAL === */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: fadeIn 0.2s;
}

.modal-overlay.hidden { display: none; }

.modal-content {
  background: var(--bg);
  border-radius: 16px 16px 0 0;
  padding: 20px;
  width: 100%;
  max-width: 500px;
  max-height: 85vh;
  overflow-y: auto;
  animation: slideUp 0.25s;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

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

.modal-header h3 { font-size: 17px; font-weight: 600; }

.btn-close {
  background: var(--card-bg);
  border: none;
  font-size: 18px;
  color: var(--hint);
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* === FORM === */
.form-group {
  margin-bottom: 14px;
}

.form-group label {
  display: block;
  font-size: 13px;
  color: var(--hint);
  margin-bottom: 6px;
  font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  background: var(--card-bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--button);
}

.form-group textarea { resize: vertical; min-height: 80px; }

/* === TOGGLE === */
.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--card-bg);
  border-radius: var(--radius);
  margin-bottom: 8px;
}

.toggle-label { font-size: 14px; font-weight: 500; }
.toggle-hint { font-size: 12px; color: var(--hint); margin-top: 2px; }

.toggle {
  position: relative;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}

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

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--hint);
  border-radius: 13px;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider { background: var(--success); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }

/* === LIST ITEM === */
.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: var(--card-bg);
  border-radius: var(--radius);
  margin-bottom: 8px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.list-item:active { opacity: 0.7; }
.list-item-left { display: flex; flex-direction: column; gap: 2px; }
.list-item-title { font-size: 14px; font-weight: 500; }
.list-item-sub { font-size: 12px; color: var(--hint); }
.list-item-arrow { color: var(--hint); font-size: 16px; }

/* === TAB BAR (in-page) === */
.tab-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.tab-btn {
  padding: 6px 14px;
  border: 1.5px solid var(--border);
  border-radius: 20px;
  background: none;
  color: var(--hint);
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.2s;
}

.tab-btn.active {
  background: var(--button);
  color: var(--button-text);
  border-color: var(--button);
}

/* === CHANNELS BADGES === */
.channel-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
}

.channel-badge {
  display: inline-block;
  background: var(--bg);
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 12px;
  color: var(--hint);
}

/* === REFERRAL === */
.ref-link-box {
  background: var(--card-bg);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}

.ref-link {
  font-size: 13px;
  word-break: break-all;
  color: var(--link);
  margin: 8px 0;
}

/* === TOAST === */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 200;
  animation: toastIn 0.3s, toastOut 0.3s 2s forwards;
  pointer-events: none;
}

@keyframes toastIn { from { opacity: 0; transform: translateX(-50%) translateY(20px); } }
@keyframes toastOut { to { opacity: 0; transform: translateX(-50%) translateY(-10px); } }

/* === TICKET === */
.messages-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.message-bubble {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.4;
}

.message-user {
  align-self: flex-end;
  background: var(--button);
  color: var(--button-text);
  border-bottom-right-radius: 4px;
}

.message-support {
  align-self: flex-start;
  background: var(--card-bg);
  border-bottom-left-radius: 4px;
}

.message-time {
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
}

.card-media {
  margin-bottom: 6px;
}

input[type="file"] {
  width: 100%;
  background: var(--card-bg);
  border: 1.5px dashed var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
}

.hidden { display: none !important; }
