:root {
  --bg: #ffffff;
  --bg-soft: #f5f6f8;
  --border: #e3e6ea;
  --text: #1b1f27;
  --text-muted: #6b7280;
  --accent: #2f6fed;
  --accent-contrast: #ffffff;
  --unread: #2f6fed;
  --danger: #b42318;
  --ok: #027a48;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1f27;
    --bg-soft: #232833;
    --border: #333a47;
    --text: #e8eaed;
    --text-muted: #9aa3b2;
    --accent: #4b86f7;
    --accent-contrast: #0d1017;
    --unread: #6ea0ff;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  display: flex;
  flex-direction: column;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-soft);
  flex: 0 0 auto;
}
.tabs { display: flex; gap: 6px; }
.tab {
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tab.is-active { background: var(--bg); color: var(--text); border-color: var(--border); font-weight: 600; }
.badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.badge.is-zero { background: var(--border); color: var(--text-muted); }
.refresh {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  width: 32px; height: 32px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 16px;
}

/* Layout */
.layout { flex: 1 1 auto; display: flex; min-height: 0; }
.list {
  width: 42%;
  max-width: 460px;
  border-right: 1px solid var(--border);
  overflow-y: auto;
}
.detail { flex: 1 1 auto; overflow-y: auto; padding: 16px 18px; }

/* List items */
.item {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.item:hover { background: var(--bg-soft); }
.item.is-selected { background: var(--bg-soft); box-shadow: inset 3px 0 0 var(--accent); }
.item-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item-from { font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-age { color: var(--text-muted); font-size: 12px; flex: 0 0 auto; }
.item-subject { color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-dot { color: var(--unread); }

.empty, .detail-placeholder {
  color: var(--text-muted);
  text-align: center;
  padding: 40px 20px;
}

/* Detail */
.detail-head { border-bottom: 1px solid var(--border); padding-bottom: 10px; margin-bottom: 12px; }
.detail-subject { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.detail-meta { display: flex; justify-content: space-between; gap: 10px; color: var(--text-muted); font-size: 13px; }
.open-link { color: var(--accent); text-decoration: none; flex: 0 0 auto; }
.open-link:hover { text-decoration: underline; }
.detail-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.5;
  max-height: 38vh;
  overflow-y: auto;
  padding: 4px 2px 12px;
}

/* Reply */
.reply { border-top: 1px solid var(--border); padding-top: 12px; }
.reply-hint { color: var(--text-muted); font-size: 12px; margin-bottom: 6px; }
#reply-text {
  width: 100%;
  resize: vertical;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  font: inherit;
  color: var(--text);
  background: var(--bg);
}
.reply-actions { display: flex; align-items: center; gap: 10px; margin-top: 10px; }
.btn {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
  background: var(--bg);
  color: var(--text);
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--accent-contrast); border-color: var(--accent); font-weight: 600; }
.btn-ghost { color: var(--text-muted); }
.reply-status { font-size: 13px; }
.reply-status.ok { color: var(--ok); }
.reply-status.err { color: var(--danger); }

/* Narrow screens: stack */
@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .list { width: 100%; max-width: none; max-height: 45%; border-right: none; border-bottom: 1px solid var(--border); }
}
