:root {
  --bg: var(--tg-theme-bg-color, #171717);
  --surface: #1e1e1e;
  --text: var(--tg-theme-text-color, #ffffff);
  --hint: var(--tg-theme-hint-color, #8b8b8b);
  --accent: #D4AF37;
  --divider: #2a2a2a;
  --bubble-us: #2a2a2a;
  --bubble-them: #1e1e1e;
  --bubble-them-border: #F59E0B;
  --radius: 12px;
  --radius-sm: 8px;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}

#app {
  height: 100%;
  position: relative;
}

.view {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.hidden { display: none !important; }

/* ── Header ─────────────────────────────────────────── */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
  gap: 12px;
}

.header h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.3px;
}

.header-info {
  flex: 1;
  min-width: 0;
}

.header-title {
  font-size: 17px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-sub {
  font-size: 13px;
  color: var(--hint);
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--hint);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 44px;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}

.icon-btn:active {
  background: var(--divider);
  color: var(--text);
}

/* ── Conversation grid ───────────────────────────────── */

.conv-scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.conv-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 12px;
}

.conv-card {
  border-left: 3px solid;
  border-radius: var(--radius-sm);
  padding: 12px 12px 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-height: 96px;
  transition: opacity 0.12s;
}

.conv-card:active { opacity: 0.65; }

.card-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  flex: 1;
}

.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  margin-top: auto;
}

.card-username {
  font-size: 11px;
  color: var(--hint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-members {
  font-size: 11px;
  color: var(--hint);
  flex-shrink: 0;
}

/* ── Status badge ────────────────────────────────────── */

.status-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.2px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Thread action bar ───────────────────────────────── */

.thread-actions-bar {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--divider);
  flex-shrink: 0;
}

.thread-actions-bar:empty { display: none; }

.action-btn {
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  min-height: 36px;
  background: transparent;
  transition: opacity 0.15s;
}

.action-btn:active { opacity: 0.6; }

.action-convert {
  border-color: var(--accent);
  color: var(--accent);
}

.action-ignore {
  border-color: #374151;
  color: #6B7280;
}

/* ── Chat bubbles ────────────────────────────────────── */

.bubbles {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: var(--radius);
  word-break: break-word;
}

.bubble-us {
  align-self: flex-end;
  background: var(--bubble-us);
  border-bottom-right-radius: 4px;
}

.bubble-them {
  align-self: flex-start;
  background: var(--bubble-them);
  border-left: 2px solid var(--bubble-them-border);
  border-bottom-left-radius: 4px;
}

.bubble-text {
  font-size: 15px;
  line-height: 1.5;
}

.bubble-time {
  font-size: 11px;
  color: var(--hint);
  margin-top: 4px;
  text-align: right;
}

.bubble-optimistic { opacity: 0.55; }

.show-more {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  padding: 0;
}

/* ── Reply composer ──────────────────────────────────── */

.composer {
  background: var(--bg);
  border-top: 1px solid var(--divider);
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  flex-shrink: 0;
  position: relative;
}

.composer textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  line-height: 1.5;
  padding: 10px 12px;
  resize: none;
  min-height: 48px;
  max-height: 160px;
  overflow-y: auto;
  outline: none;
  transition: border-color 0.15s;
  display: block;
}

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

.composer textarea::placeholder { color: var(--hint); }

.char-counter {
  position: absolute;
  right: 20px;
  bottom: calc(max(12px, env(safe-area-inset-bottom)) + 8px);
  font-size: 11px;
  color: var(--hint);
  pointer-events: none;
}

/* ── Empty / error states ────────────────────────────── */

.empty, .error-msg {
  text-align: center;
  padding: 48px 24px;
  color: var(--hint);
  font-size: 15px;
}

.error-msg { color: #EF4444; }

/* ── Loading skeleton ────────────────────────────────── */

.skeleton-card {
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 12px;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sk {
  background: var(--divider);
  border-radius: 4px;
  animation: shimmer 1.4s ease-in-out infinite;
}

.sk-badge { width: 64px;  height: 18px; border-radius: 100px; }
.sk-title { width: 100%;  height: 14px; }
.sk-meta  { width: 60%;   height: 12px; margin-top: auto; }

@keyframes shimmer {
  0%   { opacity: 0.35; }
  50%  { opacity: 0.7; }
  100% { opacity: 0.35; }
}
