: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, #2481cc);
  --btn: var(--tg-theme-button-color, #3390ec);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --secondary-bg: var(--tg-theme-secondary-bg-color, #f0f0f0);
  --section-bg: var(--tg-theme-section-bg-color, var(--bg));
  --section-header: var(--tg-theme-section-header-text-color, var(--hint));
  --destructive: var(--tg-theme-destructive-text-color, #e53935);
}

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

body {
  font-family: -apple-system, 'SF Pro Text', system-ui, sans-serif;
  background: var(--secondary-bg);
  color: var(--text);
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom, 0);
  -webkit-text-size-adjust: 100%;
}

/* Screen container */
.screen { display: none; }
.screen.active { display: block; }

/* Header */
.header {
  background: var(--bg);
  padding: 12px 16px;
  font-size: 17px;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  border-bottom: 0.5px solid var(--hint);
}

.header .back-btn {
  font-size: 24px;
  color: var(--link);
  cursor: pointer;
  line-height: 1;
  padding: 0 4px;
  background: none;
  border: none;
}

.header .title { flex: 1; }

.header .admin-badge {
  font-size: 10px;
  background: var(--hint);
  color: var(--bg);
  padding: 2px 6px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0.6;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* Section card */
.section {
  background: var(--section-bg);
  margin: 8px 0;
  border-top: 0.5px solid rgba(0,0,0,.08);
  border-bottom: 0.5px solid rgba(0,0,0,.08);
}

.section-header {
  padding: 8px 16px 4px;
  font-size: 13px;
  color: var(--section-header);
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

/* List items */
.list-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  background: var(--section-bg);
  cursor: pointer;
  gap: 12px;
  position: relative;
}

.list-item + .list-item {
  border-top: 0.5px solid rgba(0,0,0,.08);
  margin-left: 16px;
  padding-left: 0;
}

.list-item:active { opacity: 0.6; }

.list-item .icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--btn);
  color: var(--btn-text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}

.list-item .content { flex: 1; min-width: 0; }

.list-item .primary {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-item .secondary {
  font-size: 13px;
  color: var(--hint);
  margin-top: 1px;
}

.list-item .badge {
  background: var(--btn);
  color: var(--btn-text);
  font-size: 12px;
  font-weight: 600;
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
}

.list-item .chevron {
  color: var(--hint);
  font-size: 18px;
  flex-shrink: 0;
}

.list-item .copy-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--link);
  flex-shrink: 0;
}

.list-item .delete-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  color: var(--destructive);
  flex-shrink: 0;
}

/* Buttons */
.btn {
  display: block;
  width: calc(100% - 32px);
  margin: 16px auto;
  padding: 14px;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
}

.btn-primary {
  background: var(--btn);
  color: var(--btn-text);
}

.btn-primary:active { opacity: 0.8; }

.btn-secondary {
  background: var(--secondary-bg);
  color: var(--link);
}

.btn-danger {
  background: var(--destructive);
  color: #fff;
}

/* Empty state */
.empty {
  text-align: center;
  padding: 60px 32px;
  color: var(--hint);
}

.empty .emoji { font-size: 48px; margin-bottom: 12px; }
.empty .text { font-size: 15px; line-height: 1.4; }

/* Email detail */
.email-meta {
  background: var(--section-bg);
  padding: 16px;
  border-bottom: 0.5px solid rgba(0,0,0,.08);
}

.email-meta .field {
  font-size: 14px;
  margin-bottom: 4px;
}

.email-meta .field .label {
  color: var(--hint);
  font-weight: 500;
}

.email-meta .subject {
  font-size: 18px;
  font-weight: 700;
  margin-top: 8px;
}

.email-body {
  background: var(--section-bg);
  margin-top: 8px;
  padding: 16px;
  font-size: 15px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  border-top: 0.5px solid rgba(0,0,0,.08);
  border-bottom: 0.5px solid rgba(0,0,0,.08);
}

.email-body iframe {
  width: 100%;
  border: none;
  min-height: 200px;
  background: #fff;
  border-radius: 8px;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--section-bg);
}

.tab {
  padding: 6px 16px;
  border-radius: 16px;
  font-size: 13px;
  cursor: pointer;
  border: 1px solid var(--hint);
  background: transparent;
  color: var(--text);
}

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

/* Email view toggle */
.email-view-toggle {
  display: flex;
  justify-content: flex-end;
  padding: 4px 16px;
}

.tab-toggle {
  padding: 4px 14px;
  border-radius: 14px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--hint);
  background: transparent;
  color: var(--hint);
}

/* Dialog / modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.modal {
  background: var(--bg);
  width: 100%;
  max-width: 480px;
  border-radius: 16px 16px 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0));
}

.modal h3 {
  font-size: 17px;
  font-weight: 600;
  margin-bottom: 16px;
  text-align: center;
}

.modal input {
  display: block;
  width: 100%;
  padding: 12px;
  border: 1px solid var(--hint);
  border-radius: 10px;
  font-size: 15px;
  background: var(--secondary-bg);
  color: var(--text);
  margin-bottom: 12px;
}

.modal .suffix {
  font-size: 14px;
  color: var(--hint);
  text-align: center;
  margin-bottom: 16px;
}

/* Admin */
.stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 12px 16px;
  background: var(--section-bg);
  border-top: 0.5px solid rgba(0,0,0,.08);
  border-bottom: 0.5px solid rgba(0,0,0,.08);
}

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

.stat-card .value {
  font-size: 24px;
  font-weight: 700;
  color: var(--btn);
}

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

/* Toggle */
.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--section-bg);
}

.toggle-row + .toggle-row {
  border-top: 0.5px solid rgba(0,0,0,.08);
}

.toggle-row .label {
  font-size: 15px;
}

.toggle-row select, .toggle-row input[type="number"] {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--hint);
  background: var(--secondary-bg);
  color: var(--text);
  font-size: 14px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom, 0));
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 14px;
  z-index: 200;
  opacity: 0;
  transition: opacity .3s;
  pointer-events: none;
}

.toast.show { opacity: 1; }

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--hint);
  font-size: 14px;
}
