:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --sunken: #eef0f4;
  --text: #171a21;
  --muted: #5d6573;
  --line: #e1e4ea;
  --accent: #3257d6;
  --accent-soft: #e7ecfc;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --danger-soft: #fdecea;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1116;
    --surface: #171a21;
    --sunken: #12141a;
    --text: #e8eaf0;
    --muted: #9aa2b1;
    --line: #272b35;
    --accent: #7d9bff;
    --accent-soft: #222c4a;
    --accent-text: #0f1116;
    --danger: #ff8a80;
    --danger-soft: #3a1f20;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input { font: inherit; color: inherit; }
ul { list-style: none; margin: 0; padding: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.error { color: var(--danger); margin: 8px 0 0; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.button {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.button:hover { border-color: var(--accent); }
.button.small { padding: 4px 10px; font-size: 13px; }
.button.icon { padding: 6px 11px; }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.button.danger { color: var(--danger); }
.button.danger:hover { background: var(--danger-soft); border-color: var(--danger); }
.button[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); }

input {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  min-width: 0;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 28px;
  font-weight: 700;
}
.brand-mark.small { width: 28px; height: 28px; border-radius: 8px; font-size: 16px; }

.login-page { display: grid; place-items: center; padding: 16px; }
.login-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: min(360px, 100%);
  padding: 40px 28px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
}
.login-card h1 { margin: 8px 0 0; font-size: 22px; }
.login-card p { margin: 0 0 12px; }
.notice { background: var(--sunken); border-radius: 10px; padding: 12px; }
#google-button { min-height: 44px; color-scheme: light; }

.shell {
  display: grid;
  grid-template-columns: 232px minmax(300px, 380px) minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 10px 10px;
  background: var(--sunken);
  border-right: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 14px; font-weight: 700; font-size: 15px; }

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.nav-item:hover { background: var(--surface); }
.nav-item.active { background: var(--accent-soft); font-weight: 600; }
.count {
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
.total, .tag { color: var(--muted); font-size: 12px; }

.section-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 8px 6px; }
.section-head h2 { margin: 0; font-size: 12px; font-weight: 600; color: var(--muted); }
.address-list { flex: 1; overflow-y: auto; min-height: 0; }
.address-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.address.blocked .address-name { text-decoration: line-through; color: var(--muted); }
.hint { padding: 6px 10px; font-size: 13px; }

.account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 8px 0;
  border-top: 1px solid var(--line);
  font-size: 12px;
}
.account span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
}
.toolbar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  gap: 8px;
  padding: 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.toolbar input { flex: 1; }
.menu-toggle, .back, .scrim { display: none; }

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  background: var(--sunken);
  border-bottom: 1px solid var(--line);
}
.filter-text { display: flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
.filter-actions { display: flex; gap: 6px; }

.message {
  display: flex;
  flex-direction: column;
  gap: 2px;
  width: 100%;
  padding: 11px 14px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-left: 3px solid transparent;
  background: transparent;
  text-align: left;
  cursor: pointer;
}
.message:hover { background: var(--sunken); }
.message.selected { background: var(--accent-soft); }
.message.unread { border-left-color: var(--accent); }
.message.unread .message-from, .message.unread .message-subject { font-weight: 700; }
.message-top { display: flex; justify-content: space-between; gap: 8px; }
.message-from, .message-subject, .message-snippet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.message-snippet { color: var(--muted); font-size: 13px; }
.message-bottom { display: flex; gap: 6px; margin-top: 4px; min-width: 0; }
.chip {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--muted);
  font-size: 12px;
}
.message.selected .chip { border-color: var(--muted); }
.empty { margin: auto; padding: 32px; color: var(--muted); text-align: center; }
.load-more { margin: 12px auto; }

.reader { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.reader-content { display: flex; flex: 1; flex-direction: column; min-height: 0; }
.reader-head { padding: 18px 22px 12px; background: var(--surface); border-bottom: 1px solid var(--line); }
.reader-head h1 { margin: 0 0 10px; font-size: 19px; line-height: 1.35; overflow-wrap: anywhere; }
.meta { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 2px 14px; margin: 0 0 12px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; overflow-wrap: anywhere; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.spacer { flex: 1; }
.attachments { display: flex; flex-wrap: wrap; gap: 6px; }
.attachments li { margin-top: 10px; }
.attachment { display: inline-block; padding: 4px 10px; border: 1px solid var(--line); border-radius: 8px; text-decoration: none; overflow-wrap: anywhere; }

#mail-frame { flex: 1; width: 100%; min-height: 0; border: 0; background: #fff; }
#mail-text {
  flex: 1;
  overflow: auto;
  margin: 0;
  padding: 18px 22px;
  font: inherit;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

dialog {
  width: min(420px, calc(100% - 32px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
}
dialog::backdrop { background: rgb(0 0 0 / 45%); }
dialog h2 { margin: 0 0 4px; font-size: 18px; }
dialog p { margin-top: 0; }
dialog label { display: block; margin: 14px 0 4px; font-weight: 600; }
dialog > form > input { width: 100%; }
.address-input { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.address-input input { flex: 1; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 10;
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  transform: translateX(-50%);
  overflow-wrap: anywhere;
}

@media (max-width: 960px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .menu-toggle, .back { display: inline-block; }
  .list-pane { border-right: 0; }
  .reader { display: none; }
  .shell.reading .list-pane { display: none; }
  .shell.reading .reader { display: flex; }
  .back { margin-bottom: 10px; }
  .reader-head { padding: 12px 16px; }
  #mail-text { padding: 14px 16px; }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 3;
    width: min(280px, 85vw);
    transform: translateX(-100%);
    visibility: hidden;
    transition: transform 0.18s ease, visibility 0.18s;
  }
  .shell.menu-open .sidebar { transform: none; visibility: visible; }
  .shell.menu-open .scrim {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 2;
    border: 0;
    background: rgb(0 0 0 / 45%);
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
