:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --line: #e3e6eb;
  --accent: #2457c5;
  --accent-text: #ffffff;
  --hover: #eef2fa;
  --selected: #dfe8fb;
  --danger: #b42318;
  --radius: 8px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1c2027;
    --text: #e6e9ef;
    --muted: #98a2b3;
    --line: #2d333d;
    --accent: #6d9bff;
    --accent-text: #0d1220;
    --hover: #252b35;
    --selected: #2a3550;
    --danger: #ff7b6e;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { font: 15px/1.45 system-ui, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
button, input, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: var(--radius);
  padding: 6px 12px; cursor: pointer;
}
button:hover { background: var(--hover); }
button:disabled { opacity: .6; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger, .link-btn.danger { color: var(--danger); }
.link-btn { border: 0; background: none; color: var(--accent); padding: 4px 6px; }
.icon-btn { border: 0; background: none; padding: 4px 8px; font-size: 18px; }
input, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: var(--danger); white-space: pre-line; margin: 0; }
.empty { text-align: center; padding: 40px 16px; }

/* sign in */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; padding: 28px; display: grid; gap: 14px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; }
.login-card label { display: grid; gap: 4px; font-size: 14px; font-weight: 500; }
.login-card button { padding: 10px; }
.test-mode {
  border: 1px solid #d98c00; background: rgb(217 140 0 / .12); color: var(--text);
  border-radius: var(--radius); padding: 8px 10px; font-size: 13px;
}

/* layout */
.app {
  height: 100%; display: grid;
  grid-template-columns: 200px minmax(280px, 380px) 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top top" "side list read";
}
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 12px;
  padding: 8px 16px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.brand { font-weight: 700; font-size: 17px; white-space: nowrap; }
.search { flex: 1; max-width: 480px; }
.me { margin-left: auto; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sidebar { grid-area: side; padding: 14px 10px; display: flex; flex-direction: column; gap: 2px; border-right: 1px solid var(--line); }
.compose-btn { margin-bottom: 12px; padding: 10px; }
.folder {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 12px; border-radius: var(--radius); color: var(--text); text-decoration: none;
}
.folder:hover { background: var(--hover); }
.folder.active { background: var(--selected); font-weight: 600; }
.badge { background: var(--accent); color: var(--accent-text); border-radius: 10px; padding: 0 7px; font-size: 12px; font-weight: 700; }

.list-pane { grid-area: list; overflow-y: auto; border-right: 1px solid var(--line); background: var(--panel); }
.list-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.list-head h2 { margin: 0; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-list { list-style: none; margin: 0; padding: 0; }
.msg { padding: 10px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.msg:hover { background: var(--hover); }
.msg.selected { background: var(--selected); }
.msg-top { display: flex; justify-content: space-between; gap: 8px; }
.who, .subj, .preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.date { color: var(--muted); font-size: 12px; flex-shrink: 0; }
.subj { font-size: 14px; }
.preview { color: var(--muted); font-size: 13px; }
.msg.unread .who, .msg.unread .subj { font-weight: 700; }
.msg.unread { box-shadow: inset 3px 0 0 var(--accent); }
.more { display: block; margin: 10px auto; }

.read-pane { grid-area: read; overflow-y: auto; padding: 16px 24px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.read-subj { margin: 0 0 10px; font-size: 20px; overflow-wrap: anywhere; }
.read-meta { display: grid; gap: 2px; padding-bottom: 12px; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.attachment {
  border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px;
  color: var(--text); text-decoration: none; background: var(--panel);
}
.attachment:hover { background: var(--hover); }
.read-body { white-space: pre-wrap; overflow-wrap: anywhere; padding-top: 16px; }
.read-body a { color: var(--accent); }
.outside-note {
  border: 1px solid #d98c00; background: rgb(217 140 0 / .12); border-radius: var(--radius);
  padding: 8px 10px; font-size: 13px; margin-bottom: 12px;
}
.tag {
  display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 4px; font-size: 11px;
  font-weight: 600; border: 1px solid #d98c00; color: #d98c00; vertical-align: 1px;
}

/* compose */
.compose {
  width: min(680px, calc(100vw - 32px)); border: 1px solid var(--line); border-radius: 12px;
  padding: 0; background: var(--panel); color: var(--text);
}
.compose::backdrop { background: rgb(0 0 0 / .35); }
.compose form { display: grid; gap: 8px; padding: 14px 16px 16px; }
.compose-head { display: flex; justify-content: space-between; align-items: center; }
.compose .row { display: grid; grid-template-columns: 64px 1fr; align-items: center; font-size: 14px; color: var(--muted); }
.compose textarea { resize: vertical; min-height: 200px; }
.compose-foot { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.compose-foot .error { flex-basis: 100%; order: -1; }
.attach { cursor: pointer; color: var(--accent); }
.spacer { flex: 1; }

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

.mobile-only { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-areas: "top" "list"; }
  .mobile-only { display: inline-block; }
  .topbar { gap: 8px; padding: 8px 12px; }
  .me { display: none; }
  .sidebar {
    position: fixed; top: 52px; left: 0; bottom: 0; width: 240px; z-index: 5;
    background: var(--panel); transform: translateX(-100%); transition: transform .2s;
  }
  .sidebar.open { transform: none; box-shadow: 4px 0 16px rgb(0 0 0 / .2); }
  .list-pane { border-right: 0; }
  .read-pane {
    position: fixed; inset: 52px 0 0 0; background: var(--bg); z-index: 4; padding: 12px 16px;
    display: none;
  }
  .read-pane.open { display: block; }
}
