/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: #f5f5f4;
  color: #1a1a1a;
  min-height: 100vh;
}

a { color: #185fa5; }
code { font-family: "SFMono-Regular", Consolas, monospace; font-size: 0.85em; }

/* ── Layout ───────────────────────────────────────────────── */
.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.app-header { margin-bottom: 1.75rem; }
.app-header h1 { font-size: 22px; font-weight: 600; color: #111; }
.app-header .subtitle { font-size: 14px; color: #666; margin-top: 4px; }

/* ── Token input section ──────────────────────────────────── */
.token-section {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1.25rem;
}

.token-section label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: #555;
  margin-bottom: 8px;
}

.token-row { display: flex; gap: 8px; }

.token-row input {
  flex: 1;
  height: 38px;
  padding: 0 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 13px;
  font-family: "SFMono-Regular", Consolas, monospace;
  background: #fafafa;
  color: #111;
  outline: none;
  transition: border-color 0.15s;
}
.token-row input:focus { border-color: #378add; background: #fff; }

.token-row button, button {
  height: 38px;
  padding: 0 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: #111;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
  white-space: nowrap;
}
.token-row button:hover, button:hover { background: #f0f0f0; border-color: #bbb; }
.token-row button:active, button:active { transform: scale(0.98); }

.token-hint {
  margin-top: 10px;
  font-size: 12px;
  color: #999;
}

/* ── Stats bar ────────────────────────────────────────────── */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 1.25rem;
}

.stat {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  padding: 0.85rem 1rem;
}
.stat-label { font-size: 12px; color: #888; margin-bottom: 4px; }
.stat-val { font-size: 24px; font-weight: 600; color: #111; }

/* ── Controls ─────────────────────────────────────────────── */
.controls {
  display: flex;
  gap: 8px;
  margin-bottom: 1rem;
  align-items: center;
}

.controls input {
  flex: 1;
  height: 36px;
  padding: 0 12px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
}
.controls input:focus { border-color: #378add; }

.controls select {
  height: 36px;
  padding: 0 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  background: #fff;
  color: #111;
  outline: none;
  cursor: pointer;
}

/* ── Status message ───────────────────────────────────────── */
.status-msg {
  text-align: center;
  font-size: 13px;
  color: #888;
  padding: 2rem;
}
.status-msg.error { color: #a32d2d; }

/* ── Sender list ──────────────────────────────────────────── */
.sender-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Sender card ──────────────────────────────────────────── */
.sender-card {
  background: #fff;
  border: 1px solid #e5e5e5;
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.15s;
}
.sender-card:hover { border-color: #ccc; }

.sender-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  cursor: pointer;
  user-select: none;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  flex-shrink: 0;
}

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

.sender-name {
  font-size: 14px;
  font-weight: 500;
  color: #111;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sender-addr {
  font-size: 12px;
  color: #888;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sender-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* ── Badges ───────────────────────────────────────────────── */
.badge {
  font-size: 11px;
  padding: 2px 9px;
  border-radius: 999px;
  border: 1px solid #e0e0e0;
  background: #f5f5f5;
  color: #666;
  white-space: nowrap;
}
.badge.unsub {
  background: #fff0f0;
  border-color: #f7c1c1;
  color: #a32d2d;
}
.badge.done {
  background: #eaf3de;
  border-color: #c0dd97;
  color: #3b6d11;
}

/* ── Chevron ──────────────────────────────────────────────── */
.chevron {
  font-size: 18px;
  color: #aaa;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.sender-card.open .chevron { transform: rotate(180deg); }

/* ── Sender body (expanded) ───────────────────────────────── */
.sender-body {
  border-top: 1px solid #f0f0f0;
  padding: 12px 16px;
  display: none;
}
.sender-card.open .sender-body { display: block; }

/* ── Preview list ─────────────────────────────────────────── */
.preview-list {
  list-style: none;
  margin-bottom: 12px;
}
.preview-list li {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid #f5f5f5;
  font-size: 13px;
  color: #555;
}
.preview-list li:last-child { border-bottom: none; }
.preview-subject {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.preview-date {
  font-size: 11px;
  color: #bbb;
  flex-shrink: 0;
}

/* ── Action row ───────────────────────────────────────────── */
.action-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.btn-unsub {
  font-size: 12px;
  height: 32px;
  padding: 0 14px;
  border-radius: 8px;
  background: #fff0f0;
  color: #a32d2d;
  border: 1px solid #f7c1c1;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
}
.btn-unsub:hover { background: #fde8e8; }
.btn-unsub:disabled { opacity: 0.45; cursor: default; }

.btn-gmail {
  font-size: 12px;
  height: 32px;
  padding: 0 14px;
  border-radius: 8px;
  background: transparent;
  color: #555;
  border: 1px solid #e0e0e0;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
}
.btn-gmail:hover { background: #f5f5f5; }

.no-unsub {
  font-size: 12px;
  color: #aaa;
  font-style: italic;
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 520px) {
  .stats { grid-template-columns: 1fr 1fr; }
  .controls { flex-direction: column; }
  .controls input, .controls select { width: 100%; }
  .sender-meta .badge.unsub { display: none; }
}






/* Token help modal */
#tokenHelpModal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 999;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

#tokenHelpModal.open {
  display: flex;
}

.th-modal {
  background: #fff;
  border-radius: 14px;
  width: 100%;
  max-width: 560px;
  max-height: 88vh;
  overflow-y: auto;
  border: 1px solid #e0e0e0;
}

.th-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #f0f0f0;
  position: sticky;
  top: 0;
  background: #fff;
  border-radius: 14px 14px 0 0;
}

.th-modal-header strong {
  font-size: 15px;
}

.th-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #999;
  padding: 2px 6px;
  border-radius: 4px;
}

.th-close:hover {
  background: #f0f0f0;
  color: #333;
}

.th-modal-body {
  padding: 1.25rem;
}

.th-modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-top: 1px solid #f0f0f0;
}

/* ── Modal mobile ─────────────────────────────────────────── */
@media (max-width: 520px) {
  .th-modal {
    max-height: 95vh;
    border-radius: 14px 14px 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    max-width: 100%;
  }

  #tokenHelpModal {
    align-items: flex-end;
    padding: 0;
  }
}
