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

:root {
  --bg: #f9f9f7;
  --surface: #ffffff;
  --border: #e4e4e0;
  --text: #1a1a1a;
  --muted: #6b6b6b;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --unread-dot: #2563eb;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,.08);
}

body.dark {
  --bg: #111110;
  --surface: #1c1c1b;
  --border: #2e2e2c;
  --text: #ebebea;
  --muted: #a8a8a6;
  --accent: #4f8ef7;
  --accent-hover: #3b7ef6;
  --unread-dot: #4f8ef7;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* ── Layout ── */
.container { max-width: 780px; margin: 0 auto; padding: 0 8px; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
}

.header-inner h1 { font-size: 1rem; font-weight: 600; flex: 1; }

/* ── Buttons ── */
button {
  cursor: pointer;
  border: none;
  border-radius: var(--radius);
  font-size: .875rem;
  font-weight: 500;
  padding: 6px 14px;
  transition: background .15s, opacity .15s;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: .5; cursor: default; }

.btn-ghost {
  background: transparent;
  color: var(--muted);
  padding: 6px 10px;
}
.btn-ghost:hover { background: var(--border); color: var(--text); }

/* ── Dark mode toggle ── */
.theme-btn {
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
  font-size: .8125rem;
  border: 1px solid var(--border);
  border-radius: 99px;
  line-height: 1;
}
.theme-btn:hover { background: var(--border); color: var(--text); }

/* ── Filter tabs ── */
.filter-bar {
  display: flex;
  gap: 4px;
  padding: 12px 0;
}

.filter-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid transparent;
  padding: 4px 12px;
  border-radius: 99px;
  font-size: .8125rem;
}
.filter-btn.active {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ── Newsletter list ── */
.list { list-style: none; display: flex; flex-direction: column; gap: 4px; padding-bottom: 32px; }

.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  cursor: pointer;
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 0 12px;
  align-items: start;
  transition: border-color .15s, box-shadow .15s;
  overflow: hidden;
}
.list-item:hover { border-color: var(--muted); box-shadow: var(--shadow); }

.unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--unread-dot);
  margin-top: 6px;
  flex-shrink: 0;
}
.unread-dot.hidden { background: transparent; }

.list-item-body {
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.list-item-subject {
  font-size: .9375rem;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-item-sender {
  font-size: .8125rem;
  color: var(--muted);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.list-item-date { font-size: .75rem; color: var(--muted); white-space: nowrap; margin-top: 2px; }

.read .list-item-subject { font-weight: 400; color: var(--muted); }

/* ── Empty / status ── */
.empty { text-align: center; padding: 48px 0; color: var(--muted); font-size: .9375rem; }

.status-bar {
  font-size: .8125rem;
  color: var(--muted);
  padding: 8px 0 4px;
  min-height: 28px;
}

/* ── Reader ── */
.reader-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 52px;
}
.reader-header h1 { font-size: .9375rem; font-weight: 600; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.reader-meta { padding: 16px 0 12px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.reader-subject { font-size: 1.25rem; font-weight: 700; margin-bottom: 6px; }
.reader-sender { font-size: .875rem; color: var(--muted); }
.reader-date { font-size: .8125rem; color: var(--muted); margin-top: 2px; }

.reader-frame-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 32px;
}

.reader-frame {
  width: 100%;
  border: none;
  display: block;
  min-height: 200px;
}
body.dark .reader-frame {
  filter: invert(1) hue-rotate(180deg);
}

.reader-text {
  padding: 24px;
  white-space: pre-wrap;
  font-size: .9375rem;
  line-height: 1.7;
}

/* ── Spinner ── */
@keyframes spin { to { transform: rotate(360deg); } }
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
  margin-right: 4px;
}

/* ── Mark read toggle ── */
.mark-read-btn {
  font-size: .8125rem;
  padding: 4px 12px;
  background: var(--border);
  color: var(--text);
  border-radius: 99px;
}
.mark-read-btn:hover { background: var(--muted); color: var(--surface); }
.mark-read-btn.is-read { background: #dcfce7; color: #166534; }
body.dark .mark-read-btn.is-read { background: #14532d; color: #86efac; }

/* ── Login ── */
.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 16px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}
.login-card h1 { font-size: 1.125rem; margin-bottom: 24px; }
.login-field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.login-field label { font-size: .8125rem; color: var(--muted); }
.login-field input {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: .9375rem;
  width: 100%;
  outline: none;
  background: var(--bg);
  color: var(--text);
}
.login-field input:focus { border-color: var(--accent); }
.password-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.password-wrap input { padding-right: 40px; }
.pw-toggle {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  padding: 4px;
  color: var(--muted);
  display: flex;
  align-items: center;
  border-radius: 4px;
}
.pw-toggle:hover { color: var(--text); background: transparent; }
.login-error { color: #dc2626; font-size: .8125rem; margin-bottom: 12px; min-height: 18px; }
.login-card .btn-primary { width: 100%; padding: 10px; font-size: .9375rem; }
