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

:root {
  --bg: #0f1419;
  --bg-card: #1a2332;
  --bg-hover: #243044;
  --border: #2d3a4f;
  --text: #e8edf4;
  --text-muted: #8b9cb3;
  --accent: #14b8a6;
  --accent-hover: #0d9488;
  --accent-glow: rgba(20, 184, 166, 0.25);
  --danger: #f87171;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
  --font: system-ui, -apple-system, "Segoe UI", Tahoma, Arial, sans-serif;
  --refresh-interval: 15s;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.header {
  text-align: center;
  margin-bottom: 1.75rem;
}

.header__brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.header__logo {
  font-size: 1.75rem;
}

.header__title {
  font-size: 1.75rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #38bdf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.header__tagline {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.header__nav {
  margin-top: 0.75rem;
}

.header__link {
  display: inline-block;
  font-size: 0.85rem;
  color: var(--accent);
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--accent-glow);
  border-radius: 6px;
  transition: background 0.15s;
}

.header__link:hover {
  background: rgba(20, 184, 166, 0.12);
}

/* Address card */
.address-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.address-card__label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.address-card__row {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.address-card__email {
  display: block;
  font-size: clamp(1rem, 4vw, 1.35rem);
  font-weight: 600;
  color: var(--accent);
  word-break: break-all;
  padding: 0.75rem 1rem;
  background: rgba(20, 184, 166, 0.08);
  border: 1px solid var(--accent-glow);
  border-radius: 8px;
  direction: ltr;
  text-align: center;
}

.address-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.6rem 1rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.98);
}

.btn--primary {
  background: var(--accent);
  color: #042f2e;
  flex: 1;
  min-width: 140px;
}

.btn--primary:hover {
  background: var(--accent-hover);
}

.btn--secondary {
  background: var(--bg-hover);
  color: var(--text);
  border: 1px solid var(--border);
  flex: 1;
  min-width: 100px;
}

.btn--secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn--ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.45rem 0.75rem;
  font-size: 0.85rem;
}

.btn--ghost:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.btn__icon {
  font-size: 1rem;
  line-height: 1;
}

/* Inbox section */
.inbox-section {
  flex: 1;
}

.inbox-section__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.inbox-section__title {
  font-size: 1.15rem;
  font-weight: 600;
}

.inbox-section__controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.auto-refresh {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.auto-refresh input {
  accent-color: var(--accent);
  width: 1rem;
  height: 1rem;
  cursor: pointer;
}

/* Inbox list */
.inbox-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.inbox-empty {
  text-align: center;
  padding: 2.5rem 1rem;
  background: var(--bg-card);
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.inbox-empty__icon {
  font-size: 2.5rem;
  display: block;
  margin-bottom: 0.75rem;
  opacity: 0.7;
}

.inbox-empty__text {
  font-size: 1.05rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
}

.inbox-empty__hint {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Message card */
.message {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s;
}

.message:hover {
  border-color: var(--accent-glow);
}

.message--expanded {
  border-color: var(--accent);
}

.message__header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.25rem 1rem;
  padding: 0.85rem 1rem;
  cursor: pointer;
  width: 100%;
  text-align: inherit;
  background: none;
  border: none;
  color: inherit;
  font-family: inherit;
}

.message__from {
  font-weight: 600;
  font-size: 0.95rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
  text-align: right;
}

.message__date {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.message__subject {
  grid-column: 1 / -1;
  font-size: 0.9rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message__preview {
  grid-column: 1 / -1;
  font-size: 0.82rem;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.message__body {
  display: none;
  padding: 0 1rem 1rem;
  border-top: 1px solid var(--border);
}

.message--expanded .message__body {
  display: block;
}

.message__content {
  padding-top: 0.85rem;
  font-size: 0.9rem;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  direction: ltr;
  text-align: left;
}

.message__content--html {
  direction: ltr;
  text-align: left;
}

.message__content--html img {
  max-width: 100%;
  height: auto;
}

/* Footer */
.footer {
  margin-top: 2rem;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Toast */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%) translateY(0);
  background: var(--accent);
  color: #042f2e;
  padding: 0.65rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 1000;
  transition: opacity 0.25s, transform 0.25s;
}

.toast[hidden] {
  opacity: 0;
  transform: translateX(-50%) translateY(1rem);
  pointer-events: none;
}

/* Loading pulse */
.loading {
  animation: pulse 1.2s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Responsive */
@media (min-width: 520px) {
  .address-card__row {
    flex-direction: row;
    align-items: center;
  }

  .address-card__email {
    flex: 1;
    text-align: left;
  }

  .address-card__actions {
    flex-shrink: 0;
  }

  .btn--primary,
  .btn--secondary {
    flex: unset;
  }
}

@media (max-width: 380px) {
  .inbox-section__header {
    flex-direction: column;
    align-items: flex-start;
  }
}
