:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #1a1a2e);
  --hint: var(--tg-theme-hint-color, #8e8e93);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn-bg: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --border: #e0e0e0;
}

* { 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;
}

.screen { padding: 16px; }

/* Login */
.login-box {
  max-width: 320px;
  margin: 120px auto 0;
  text-align: center;
}
.login-box h1 { margin-bottom: 24px; font-size: 24px; }
.login-box input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 16px;
  margin-bottom: 12px;
  background: var(--secondary-bg);
  color: var(--text);
}
.error { color: #ff3b30; font-size: 14px; margin-top: 8px; }

/* Header */
header { margin-bottom: 16px; }
header h1 { font-size: 22px; font-weight: 700; }
header h2 { font-size: 18px; font-weight: 600; }
.subtitle { font-size: 14px; color: var(--hint); margin-top: 4px; }

/* Tabs */
.tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.tab {
  padding: 8px 14px;
  border: none;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  background: var(--secondary-bg);
  color: var(--hint);
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab.active { background: var(--btn-bg); color: var(--btn-text); }

/* Lead cards */
.leads-list { display: flex; flex-direction: column; gap: 10px; }

.lead-card {
  background: var(--secondary-bg);
  border-radius: 12px;
  padding: 14px 16px;
  cursor: pointer;
  transition: transform 0.1s;
}
.lead-card:active { transform: scale(0.98); }
.lead-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.lead-card-id { font-size: 13px; color: var(--hint); }
.lead-card-name { font-size: 16px; font-weight: 600; }
.lead-card-meta { font-size: 13px; color: var(--hint); margin-top: 4px; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge.new { background: #e8f5e9; color: #2e7d32; }
.badge.duplicate { background: #fff3e0; color: #e65100; border: 1px solid #e65100; }
.lead-card.is-duplicate { border-left: 3px solid #e65100; }
.badge.in_work { background: #e3f2fd; color: #1565c0; }
.badge.hot { background: #fff3e0; color: #e65100; }
.badge.no_response { background: #f3e5f5; color: #7b1fa2; }
.badge.not_interested { background: #fce4ec; color: #c62828; }
.badge.wrong_number { background: #efebe9; color: #4e342e; }

/* Inline assign on new leads */
.assign-inline {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  align-items: center;
}
.assign-inline select {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-appearance: none;
}
.assign-inline button {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  background: var(--btn-bg);
  color: var(--btn-text);
  cursor: pointer;
}

/* Lead detail */
.btn-back {
  background: none;
  border: none;
  font-size: 16px;
  color: var(--link);
  cursor: pointer;
  padding: 4px 0;
  margin-bottom: 8px;
}

.lead-info {
  background: var(--secondary-bg);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 20px;
}
.lead-field { padding: 8px 0; border-bottom: 1px solid var(--border); }
.lead-field:last-child { border-bottom: none; }
.lead-field-label { font-size: 12px; color: var(--hint); text-transform: uppercase; letter-spacing: 0.5px; }
.lead-field-value { font-size: 15px; margin-top: 2px; }

.section { margin-bottom: 20px; }
.section h3 { font-size: 15px; font-weight: 600; margin-bottom: 10px; }

select {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 15px;
  background: var(--secondary-bg);
  color: var(--text);
  margin-bottom: 10px;
  -webkit-appearance: none;
}

.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}
.btn-primary { background: var(--btn-bg); color: var(--btn-text); }
.btn-primary:active { opacity: 0.8; }

.status-buttons { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-status {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  background: var(--secondary-bg);
  color: var(--text);
  cursor: pointer;
  width: auto;
}
.btn-status:active { opacity: 0.7; }
.btn-status.active-status { border-color: var(--btn-bg); background: var(--btn-bg); color: var(--btn-text); }
.btn-status.hot.active-status { background: #e65100; border-color: #e65100; }

/* Comments */
.comments-list { margin-bottom: 12px; }
.comment-item {
  background: var(--secondary-bg);
  border-radius: 10px;
  padding: 10px 14px;
  margin-bottom: 8px;
}
.comment-author { font-size: 13px; font-weight: 600; color: var(--link); }
.comment-time { font-size: 11px; color: var(--hint); margin-left: 8px; }
.comment-text { font-size: 14px; margin-top: 4px; line-height: 1.4; }
.comment-form { display: flex; gap: 8px; align-items: flex-end; }
.comment-form textarea {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  background: var(--secondary-bg);
  color: var(--text);
}
.comment-form .btn { width: auto; padding: 10px 20px; }

/* Stats page */
.stats-block { margin-bottom: 24px; }
.stats-block h2 { font-size: 16px; font-weight: 600; margin-bottom: 10px; }
.stats-block-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.stats-block-header h2 { margin-bottom: 0; }

.btn-icon {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--secondary-bg);
  font-size: 18px;
  color: var(--link);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  background: var(--secondary-bg);
  border-radius: 10px;
  margin-bottom: 6px;
  cursor: default;
}
.stat-row.clickable { cursor: pointer; }
.stat-row.clickable:active { transform: scale(0.98); }
.stat-row-name { font-size: 14px; font-weight: 500; }
.stat-row-count {
  font-size: 14px;
  font-weight: 700;
  min-width: 40px;
  text-align: right;
}
.stat-row-sub { font-size: 12px; color: var(--hint); margin-top: 2px; }

.stat-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.stat-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}

.add-form {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.add-form input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  background: var(--secondary-bg);
  color: var(--text);
}
.btn-small-primary {
  padding: 8px 16px;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  background: var(--btn-bg);
  color: var(--btn-text);
  cursor: pointer;
}

/* Bottom nav */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 6px 0;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  z-index: 100;
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  border: none;
  background: none;
  cursor: pointer;
  padding: 4px 0;
  position: relative;
  color: var(--hint);
}
.nav-btn.active { color: var(--btn-bg); }
.nav-icon { font-size: 20px; }
.nav-label { font-size: 11px; font-weight: 500; }
.nav-badge {
  position: absolute;
  top: 0;
  right: 50%;
  transform: translateX(16px);
  background: #ff3b30;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 9px;
  padding: 0 4px;
}

/* Mode toggle */
.mode-toggle {
  position: fixed;
  top: 12px;
  right: 16px;
  z-index: 101;
  display: flex;
  background: var(--secondary-bg);
  border-radius: 20px;
  padding: 2px;
  border: 1px solid var(--border);
}
.mode-btn {
  padding: 6px 14px;
  border: none;
  border-radius: 18px;
  font-size: 12px;
  font-weight: 600;
  background: transparent;
  color: var(--hint);
  cursor: pointer;
}
.mode-btn.active {
  background: var(--btn-bg);
  color: var(--btn-text);
}

.btn-delete-agent {
  background: none;
  border: none;
  font-size: 20px;
  color: #c62828;
  cursor: pointer;
  padding: 0 4px;
  margin-left: 8px;
  line-height: 1;
  opacity: 0.6;
}
.btn-delete-agent:active { opacity: 1; }

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--hint);
  font-size: 15px;
}
