:root {
  --bg: var(--tg-theme-bg-color, #1c1c1e);
  --bg-secondary: var(--tg-theme-secondary-bg-color, #2c2c2e);
  --text: var(--tg-theme-text-color, #ffffff);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #5ac8fa);
  --accent: var(--tg-theme-button-color, #007aff);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(255, 255, 255, 0.08);
  --danger: #ff453a;
  --success: #30d158;
  --warning: #ff9f0a;
  --radius: 14px;
  --tabbar-height: 60px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.me {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.me-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 14px;
  flex-shrink: 0;
}

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

.me-name {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.me-rep {
  font-size: 12px;
  color: var(--hint);
}

.refresh-btn {
  background: var(--bg-secondary);
  border: none;
  color: var(--text);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  transition: transform 0.2s;
}

.refresh-btn:active {
  transform: rotate(180deg);
}

/* Screens */
main {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(var(--tabbar-height) + var(--safe-bottom) + 16px);
}

.screen {
  display: none;
  animation: fadeIn 0.2s ease;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.screen-title {
  margin: 0 0 16px;
  font-size: 24px;
  font-weight: 700;
}

.hint {
  color: var(--hint);
  font-size: 13px;
  margin: 0 0 12px;
}

.loader {
  color: var(--hint);
  text-align: center;
  padding: 32px 0;
  font-size: 14px;
}

.empty {
  color: var(--hint);
  text-align: center;
  padding: 48px 16px;
  font-size: 14px;
}

/* Feed cards */
.card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
}

.card-text {
  font-size: 15px;
  white-space: pre-wrap;
  word-wrap: break-word;
  margin-bottom: 10px;
}

.card-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--hint);
}

.reactions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.reaction {
  background: rgba(255, 255, 255, 0.05);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 12px;
}

/* Top section */
.top-section {
  margin-bottom: 24px;
}

.top-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin: 0 0 10px;
}

.top-row {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--border);
}

.top-row .num {
  color: var(--hint);
  font-weight: 600;
  width: 24px;
}

.top-row .info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.top-row .score {
  color: var(--warning);
  font-weight: 600;
  font-size: 13px;
}

/* Profile */
.profile-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 12px;
  text-align: center;
  border: 1px solid var(--border);
}

.stat-value {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 2px;
}

.stat-label {
  font-size: 11px;
  color: var(--hint);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.history-title {
  margin: 20px 0 10px;
  font-size: 16px;
  font-weight: 600;
}

.history-item {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 6px;
  border: 1px solid var(--border);
  font-size: 13px;
}

.history-status {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 6px;
}

.history-status.approved { background: rgba(48, 209, 88, 0.18); color: var(--success); }
.history-status.rejected { background: rgba(255, 69, 58, 0.18); color: var(--danger); }
.history-status.pending  { background: rgba(255, 159, 10, 0.18); color: var(--warning); }
.history-status.queued   { background: rgba(255, 159, 10, 0.18); color: var(--warning); }

.history-text {
  color: var(--hint);
  font-size: 12px;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* Send screen */
textarea {
  width: 100%;
  min-height: 160px;
  padding: 12px 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  resize: vertical;
  outline: none;
}

textarea:focus {
  border-color: var(--accent);
}

.char-count {
  text-align: right;
  font-size: 12px;
  color: var(--hint);
  margin-top: 6px;
  margin-bottom: 12px;
}

.primary-btn {
  width: 100%;
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: var(--radius);
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
}

.primary-btn:active { opacity: 0.7; }
.primary-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.more-btn {
  width: 100%;
  background: var(--bg-secondary);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  font-size: 14px;
  cursor: pointer;
  margin-top: 8px;
}

.status {
  margin-top: 12px;
  text-align: center;
  font-size: 13px;
  min-height: 20px;
}

.status.ok { color: var(--success); }
.status.err { color: var(--danger); }

/* Tab bar */
.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tabbar-height);
  padding-bottom: var(--safe-bottom);
  background: var(--bg);
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  z-index: 20;
}

.tab {
  flex: 1;
  height: 100%;
  background: transparent;
  border: none;
  color: var(--hint);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  cursor: pointer;
  transition: color 0.15s;
}

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

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

.tab-label {
  font-size: 11px;
  font-weight: 500;
}
