:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efeee9;
  --line: #e2e0da;
  --text: #1f2328;
  --muted: #5f6670;
  --accent: #35597a;
  --accent-ink: #ffffff;
  --unread: #35597a;
  --danger: #a8443b;
  --gmail: #a8443b;
  --chatwork: #9a6a24;
  --discord: #4f58a8;
  --me-bubble: #e6edf3;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.05), 0 1px 2px rgba(0, 0, 0, 0.08);
  --radius: 12px;
  --font: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181b;
    --surface: #1e2125;
    --surface-2: #262a2f;
    --line: #33383e;
    --text: #e8e6e1;
    --muted: #a3a9b1;
    --accent: #8fb3d4;
    --accent-ink: #12161a;
    --unread: #8fb3d4;
    --danger: #e08a80;
    --gmail: #e08a80;
    --chatwork: #d9a95e;
    --discord: #9aa2e6;
    --me-bubble: #263443;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

/* ---------- ヘッダー ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 20px; line-height: 1.3; margin: 0; font-weight: 700; flex: 1; }
.icon-btn {
  min-width: 40px; height: 40px; padding: 0 8px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); line-height: 1;
  transition: all 0.2s ease-in-out;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:focus-visible, .tab:focus-visible, .item:focus-visible, .primary:focus-visible, .ghost:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.icon-btn:active { transform: scale(0.97); }

/* ---------- タブ ---------- */
.tabs {
  display: flex; gap: 8px; overflow-x: auto;
  padding: 8px 16px; background: var(--surface);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
}
.tab {
  flex: none; display: inline-flex; align-items: center; gap: 8px;
  height: 40px; padding: 0 16px;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--surface); font-size: 14px; font-weight: 500; line-height: 1;
  transition: all 0.2s ease-in-out;
}
.tab:hover { background: var(--surface-2); }
.tab:active { transform: scale(0.97); }
.tab[aria-selected="true"] { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.badge {
  min-width: 20px; height: 20px; padding: 0 4px; border-radius: 999px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  background: var(--danger); color: #fff;
}

/* ---------- 状態表示 ---------- */
.status { padding: 8px 16px; font-size: 12px; color: var(--muted); display: flex; gap: 16px; flex-wrap: wrap; }
.status .ng { color: var(--danger); font-weight: 500; }

/* ---------- 一覧 ---------- */
.list { list-style: none; margin: 0; padding: 0 0 64px; }
.item {
  display: grid; grid-template-columns: 8px 1fr auto; gap: 8px 16px;
  width: 100%; padding: 16px; text-align: left;
  border: 0; border-bottom: 1px solid var(--line); background: var(--surface);
  transition: all 0.2s ease-in-out;
}
.item:hover { background: var(--surface-2); }
.item:active { background: var(--line); }
.dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 8px; }
.item.unread .dot { background: var(--unread); }
.item-main { min-width: 0; }
.item-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.sender { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item.unread .sender { font-weight: 700; }
.chip {
  flex: none; font-size: 12px; font-weight: 500; line-height: 1;
  padding: 4px 8px; border-radius: 8px; color: #fff;
}
.chip.gmail { background: var(--gmail); }
.chip.chatwork { background: var(--chatwork); }
.chip.discord { background: var(--discord); }
.place { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.snippet {
  font-size: 14px; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.time { font-size: 12px; color: var(--muted); white-space: nowrap; }
.empty { padding: 48px 16px; text-align: center; color: var(--muted); }

/* ---------- 詳細 ---------- */
.detail { max-width: 800px; margin: 0 auto; padding: 16px 16px 200px; }
.detail-head { padding: 24px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 16px; }
.detail-head h2 { font-size: 20px; line-height: 1.3; margin: 8px 0; }
.meta { font-size: 14px; color: var(--muted); }
.body-text {
  white-space: pre-wrap; word-break: break-word;
  padding: 24px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.mail-frame { width: 100%; min-height: 480px; border: 0; border-radius: var(--radius); background: #fff; box-shadow: var(--shadow); }
.toggle { margin: 8px 0 16px; }
.convo { display: flex; flex-direction: column; gap: 8px; }
.bubble {
  max-width: 88%; padding: 8px 16px; border-radius: var(--radius);
  background: var(--surface); box-shadow: var(--shadow);
  white-space: pre-wrap; word-break: break-word;
}
.bubble.me { align-self: flex-end; background: var(--me-bubble); }
.bubble.target { outline: 2px solid var(--accent); }
.bubble .who { font-size: 12px; color: var(--muted); display: block; margin-bottom: 4px; }

/* ---------- 返信欄 ---------- */
.composer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  padding: 16px; padding-bottom: max(16px, env(safe-area-inset-bottom));
  background: var(--surface); border-top: 1px solid var(--line);
}
.composer-inner { max-width: 800px; margin: 0 auto; display: flex; flex-direction: column; gap: 8px; }
.composer label { font-size: 14px; color: var(--muted); }
.composer textarea {
  width: 100%; min-height: 80px; max-height: 40vh; resize: vertical;
  padding: 8px 16px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.composer textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.composer-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; }
.note { font-size: 12px; color: var(--muted); }
.primary {
  height: 40px; padding: 0 24px; border: 0; border-radius: 8px;
  background: var(--accent); color: var(--accent-ink); font-weight: 700; line-height: 1;
  transition: all 0.2s ease-in-out;
}
.primary:hover { filter: brightness(1.08); }
.primary:active { transform: scale(0.97); }
.primary:disabled { opacity: 0.5; cursor: default; }
.ghost {
  height: 40px; padding: 0 16px; border: 1px solid var(--line); border-radius: 8px;
  background: transparent; line-height: 1; transition: all 0.2s ease-in-out;
}
.ghost:hover { background: var(--surface-2); }
.ghost:active { transform: scale(0.97); }
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 20;
  padding: 8px 16px; border-radius: 8px; background: var(--text); color: var(--bg); font-size: 14px;
}

/* ---------- ログイン ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 400px; padding: 32px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.login-card h1 { font-size: 24px; line-height: 1.3; margin: 0 0 24px; }
.login-card label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 8px; }
.login-card input {
  width: 100%; height: 48px; padding: 0 16px; margin-bottom: 24px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.login-card input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.login-card .primary { width: 100%; height: 48px; }
.error { color: var(--danger); font-size: 14px; margin: 0 0 16px; }

@media (min-width: 768px) {
  .list { max-width: 960px; margin: 0 auto; }
}
