:root {
  --bg: #ffffff;
  --bg-sunken: #f6f8fc;
  --bg-hover: #eef2f9;
  --bg-selected: #e3ecfd;
  --border: #e3e6ea;
  --text: #1f2430;
  --text-muted: #6b7280;
  --text-faint: #9aa2b1;
  --accent: #4f7df3;
  --accent-hover: #3d6ce0;
  --danger: #e0433c;
  --star: #f2b705;
  --shadow: 0 8px 30px rgba(20, 24, 40, 0.12);
  --radius: 10px;
  --sidebar-bg: #1a2233;
  --sidebar-bg-raised: #212b40;
  --sidebar-text: #e6e9f2;
  --sidebar-text-muted: #93a0bd;
  --sidebar-hover: #26314a;
  --sidebar-active: #2c3a58;
  --sidebar-border: #2a3550;
  --root-font-size: 14px;
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Hiragino Sans", "Yu Gothic", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1f26;
    --bg-sunken: #14171d;
    --bg-hover: #262b34;
    --bg-selected: #223050;
    --border: #2e333d;
    --text: #e7e9ee;
    --text-muted: #9aa2b1;
    --text-faint: #6b7280;
    --accent: #6d93f7;
    --accent-hover: #82a2f8;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
  }
}

:root[data-theme="dark"] {
  --bg: #1c1f26;
  --bg-sunken: #14171d;
  --bg-hover: #262b34;
  --bg-selected: #223050;
  --border: #2e333d;
  --text: #e7e9ee;
  --text-muted: #9aa2b1;
  --text-faint: #6b7280;
  --accent: #6d93f7;
  --accent-hover: #82a2f8;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg-sunken);
  color: var(--text);
  font-family: var(--font-family);
  font-size: var(--root-font-size);
}

svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- topbar ---------- */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.small { width: 26px; height: 26px; }
.icon-btn.small svg { width: 14px; height: 14px; }

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 1.2857rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}
.brand-icon { color: var(--accent); width: 22px; height: 22px; }

.search-wrap {
  flex: 1;
  max-width: 640px;
  position: relative;
  margin: 0 auto;
}
.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px; height: 16px;
  color: var(--text-faint);
}
.search-wrap input {
  width: 100%;
  height: 38px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  padding: 0 16px 0 38px;
  font-size: 1rem;
  color: var(--text);
  outline: none;
}
.search-wrap input:focus {
  border-color: var(--accent);
  background: var(--bg);
}

.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 0.9286rem;
  flex-shrink: 0;
}

/* ---------- layout ---------- */
.body-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 240px var(--list-width, 360px) 6px 1fr;
  min-height: 0;
}

.pane-resizer {
  grid-column: 3;
  position: relative;
  cursor: col-resize;
  background: transparent;
  touch-action: none;
}
.pane-resizer::before {
  content: '';
  position: absolute;
  top: 0; bottom: 0;
  left: 2px;
  width: 1px;
  background: var(--border);
}
.pane-resizer:hover::before, .pane-resizer.dragging::before {
  left: 1px;
  width: 3px;
  background: var(--accent);
}

.sidebar {
  grid-column: 1;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  padding: 14px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.compose-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 1rem;
  padding: 12px 18px;
  border-radius: 24px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(79, 125, 243, 0.35);
}
.compose-btn:hover { background: var(--accent-hover); }
.compose-btn svg { width: 16px; height: 16px; }

.account-list { display: flex; flex-direction: column; gap: 2px; padding-bottom: 12px; border-bottom: 1px solid var(--sidebar-border); }
.account-group { display: flex; flex-direction: column; gap: 2px; }
.account-group-header {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 8px 10px 4px;
  color: var(--sidebar-text-muted);
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.account-group-header:hover { color: var(--sidebar-text); }
.account-group-header .count { color: var(--sidebar-text-muted); font-weight: 600; text-transform: none; }
.account-group-header .chevron { width: 12px; height: 12px; margin-left: auto; color: var(--sidebar-text-muted); }
.account-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  border-radius: 10px;
  cursor: pointer;
  color: var(--sidebar-text-muted);
  font-size: 0.9286rem;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}
.account-row:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.account-row.active { background: var(--sidebar-active); color: var(--sidebar-text); font-weight: 600; }
.account-row.add-account-row { color: var(--sidebar-text-muted); margin-top: 2px; }
.account-row.add-account-row:hover { color: var(--sidebar-text); }
.account-row-main {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  border: none;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: inherit;
  padding: 0;
  cursor: pointer;
  text-align: left;
}
.account-row-menu { flex-shrink: 0; }
.account-menu-btn { color: var(--sidebar-text-muted); }
.account-menu-btn:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.avatar-square.add-icon {
  background: transparent;
  border: 1px dashed var(--sidebar-text-muted);
  color: var(--sidebar-text-muted);
}
.avatar-square.add-icon svg { width: 13px; height: 13px; }
.avatar-square {
  width: 22px; height: 22px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.7857rem;
  flex-shrink: 0;
}
.avatar-square.unified-icon { background: var(--sidebar-hover); color: var(--sidebar-text-muted); }
.avatar-square.unified-icon svg { width: 13px; height: 13px; }
.account-row.active .avatar-square.unified-icon { color: var(--accent); }
.account-row-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.unread-pill {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 0.7857rem;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 7px;
  flex-shrink: 0;
}

.folder-list, .label-list { display: flex; flex-direction: column; gap: 2px; }

.folder-item, .label-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 20px;
  cursor: pointer;
  color: var(--sidebar-text-muted);
  font-size: 0.9643rem;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
}
.folder-item:hover, .label-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.folder-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.folder-item.active svg { color: var(--accent); }
.folder-item .count {
  margin-left: auto;
  font-size: 0.8571rem;
  color: var(--sidebar-text-muted);
  font-weight: 600;
}
.folder-item.active .count { color: var(--accent); }

.label-section { display: flex; flex-direction: column; gap: 6px; }
.label-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  font-size: 0.8571rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--sidebar-text-muted);
  font-weight: 600;
}
.label-section-head .icon-btn.small { color: var(--sidebar-text-muted); }
.label-section-head .icon-btn.small:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.label-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.label-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }

/* ---------- message list ---------- */
.message-list-pane {
  grid-column: 2;
  border-right: 1px solid var(--border);
  border-left: 1px solid var(--border);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.list-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 18px 0;
  flex-shrink: 0;
}
.list-tab {
  border: none;
  background: transparent;
  color: var(--text-faint);
  font-size: 0.9286rem;
  font-weight: 600;
  padding: 6px 4px 10px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-right: 14px;
}
.list-tab:hover { color: var(--text); }
.list-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.list-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 8px;
  flex-shrink: 0;
  min-height: 34px;
}
.pane-title { font-size: 1.2143rem; font-weight: 700; }
.msg-count { font-size: 0.8571rem; color: var(--text-faint); }
.list-select-all { display: flex; align-items: center; cursor: pointer; }
.list-select-all input { accent-color: var(--accent); cursor: pointer; width: 16px; height: 16px; }
.bulk-count { font-size: 0.8929rem; font-weight: 600; color: var(--text); white-space: nowrap; }
.bulk-actions { display: flex; gap: 6px; margin-left: 4px; flex-wrap: wrap; }
.bulk-actions .ghost-icon-btn { margin-left: 0; }
#listToolbar #bulkClearBtn { margin-left: auto; }

.msg-checkbox-wrap {
  display: flex;
  align-items: center;
  padding-top: 2px;
  flex-shrink: 0;
  cursor: pointer;
}
.msg-checkbox { accent-color: var(--accent); cursor: pointer; width: 16px; height: 16px; }

.message-list {
  overflow-y: auto;
  flex: 1;
}
.message-sublist { list-style: none; margin: 0; padding: 0; }

.msg-group { border-bottom: 1px solid var(--border); }
.group-header {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 10px 18px;
  color: var(--text-muted);
  font-size: 0.8929rem;
  font-weight: 700;
}
.group-header:hover { background: var(--bg-hover); }
.group-icon { width: 15px; height: 15px; }
.chevron { width: 14px; height: 14px; margin-left: auto; transition: transform .15s ease; }
.chevron.collapsed { transform: rotate(-90deg); }
.show-all-link {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 0.8929rem;
  font-weight: 600;
  text-align: left;
  padding: 8px 18px 12px;
  cursor: pointer;
}
.show-all-link:hover { text-decoration: underline; }

.message-item {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 18px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  position: relative;
}
.message-sublist .message-item:last-child { border-bottom: none; }
.message-item:hover { background: var(--bg-hover); }
.message-item.selected { background: var(--bg-selected); }
.message-item.kb-focused { box-shadow: inset 0 0 0 2px var(--accent); }
.thread-count {
  color: var(--text-faint);
  font-weight: 600;
  font-size: 0.8571rem;
  flex-shrink: 0;
}
.message-item.unread .sender,
.message-item.unread .subject { font-weight: 700; color: var(--text); }
.message-item .unread-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: 6px;
  flex-shrink: 0;
  opacity: 0;
}
.message-item.unread .unread-dot { opacity: 1; }

.message-item .star-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  color: var(--text-faint);
  padding: 0;
  margin-top: 2px;
  flex-shrink: 0;
}
.message-item .star-btn svg { width: 16px; height: 16px; }
.message-item .star-btn.starred { color: var(--star); }
.message-item .star-btn.starred svg { fill: var(--star); }

.message-main { flex: 1; min-width: 0; }
.message-line1 {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}
.sender { color: var(--text); font-size: 0.9643rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.date { font-size: 0.8571rem; color: var(--text-faint); flex-shrink: 0; }
.subject { font-size: 0.9643rem; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.snippet { font-size: 0.8929rem; color: var(--text-faint); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-labels { display: flex; gap: 4px; margin-top: 5px; flex-wrap: wrap; }
.msg-label-chip {
  font-size: 0.75rem;
  padding: 1px 8px;
  border-radius: 8px;
  color: #fff;
  white-space: nowrap;
}

.empty-state {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-faint);
  font-size: 0.9286rem;
}

/* ---------- detail pane ---------- */
.message-detail-pane {
  grid-column: 4;
  background: var(--bg);
  overflow-y: auto;
  min-height: 0;
}
.detail-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-faint);
}
.detail-empty svg { width: 48px; height: 48px; }

.detail-content { padding: 24px 32px; }
.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 16px;
}
.detail-subject-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}
.detail-subject { font-size: 1.4286rem; font-weight: 700; margin: 0 0 12px; }
.detail-from-row { display: flex; align-items: center; gap: 12px; }
.detail-from-meta strong { font-size: 1rem; display: block; }
.detail-from-meta span { font-size: 0.8929rem; color: var(--text-muted); }
.detail-actions { display: flex; gap: 4px; }
.thread-strip {
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}
.thread-strip-label {
  padding: 8px 12px;
  font-size: 0.8571rem;
  color: var(--text-faint);
  background: var(--bg-sunken);
  border-bottom: 1px solid var(--border);
}
.thread-strip-item {
  display: flex;
  align-items: baseline;
  gap: 8px;
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  padding: 8px 12px;
  cursor: pointer;
  text-align: left;
}
.thread-strip-item:last-child { border-bottom: none; }
.thread-strip-item:hover { background: var(--bg-hover); }
.thread-strip-sender { font-size: 0.8929rem; font-weight: 600; color: var(--text); flex-shrink: 0; }
.thread-strip-snippet {
  flex: 1;
  min-width: 0;
  font-size: 0.8571rem;
  color: var(--text-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.thread-strip-date { font-size: 0.7857rem; color: var(--text-faint); flex-shrink: 0; }
.detail-body {
  white-space: pre-wrap;
  line-height: 1.7;
  font-size: 1rem;
  color: var(--text);
}

.reply-actions { display: flex; gap: 8px; margin-top: 20px; }
.ai-actions { display: flex; gap: 8px; margin-top: 14px; }
.ai-btn, .action-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  padding: 7px 14px;
  border-radius: 18px;
  font-size: 0.8929rem;
  cursor: pointer;
}
.ai-btn:hover, .action-btn:hover { background: var(--bg-hover); color: var(--text); }
.ai-btn svg, .action-btn svg { width: 15px; height: 15px; }
.action-btn {
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}
.action-btn:hover { background: var(--bg-selected); color: var(--accent); }

.ai-result {
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-sunken);
  overflow: hidden;
}
.ai-result-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  font-size: 0.8929rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.ai-result-head svg { width: 15px; height: 15px; color: var(--accent); }
.ai-result-close { margin-left: auto; }
.ai-result-body {
  padding: 14px;
  font-size: 0.9286rem;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--text);
}
.ai-result-body.loading { color: var(--text-faint); }
.ai-result-body.error { color: var(--danger); }
.ai-result-link { color: var(--accent); cursor: pointer; text-decoration: underline; background: none; border: none; padding: 0; font: inherit; }
.detail-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.ghost-icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  padding: 7px 12px;
  border-radius: 18px;
  font-size: 0.9286rem;
  cursor: pointer;
  margin-left: 8px;
}
.ghost-icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.ghost-icon-btn svg { width: 15px; height: 15px; }

.icon-btn svg.filled-star { fill: var(--star); color: var(--star); }

.dropdown-menu { position: relative; }
.dropdown-panel, .label-toggle-panel {
  position: absolute;
  top: 34px;
  left: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 180px;
  z-index: 40;
  display: none;
}
.dropdown-panel.open, .label-toggle-panel.open { display: block; }
.dropdown-option {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
  font-size: 0.9286rem;
  color: var(--text);
  white-space: nowrap;
}
.dropdown-option:hover { background: var(--bg-hover); }
.label-toggle-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9286rem;
}
.label-toggle-option:hover { background: var(--bg-hover); }
.label-toggle-option input { accent-color: var(--accent); }

.tag-chip-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 4px;
}
.tag-add-btn {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px dashed var(--text-faint);
  background: transparent;
  color: var(--text-muted);
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.tag-add-btn:hover { background: var(--bg-hover); color: var(--text); }
.tag-chip {
  font-size: 0.7857rem;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 10px;
  color: #fff;
  white-space: nowrap;
  cursor: default;
}
.tag-chip.folder-chip { background: var(--text-faint); }
.tag-chip[data-remove-label] { cursor: pointer; }
.tag-chip[data-remove-label] b { font-weight: 700; margin-left: 2px; }
.tag-chip[data-remove-label]:hover { opacity: 0.8; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 24, 40, 0.4);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 100;
}
@media (min-width: 700px) {
  .modal-overlay { align-items: center; }
}
.compose-modal {
  background: var(--bg);
  width: 100%;
  max-width: 560px;
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  max-height: 90vh;
}
@media (min-width: 700px) {
  .compose-modal { border-radius: var(--radius); }
}
.compose-modal.small { max-width: 360px; }
.compose-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
#composeForm, #labelForm, #accountForm {
  display: flex;
  flex-direction: column;
  padding: 14px 18px 18px;
  gap: 10px;
  overflow-y: auto;
}
.compose-from-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.compose-from {
  font-size: 0.8929rem;
  color: var(--text-faint);
}
.cc-bcc-toggle {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 0.8571rem;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
}
.cc-bcc-toggle:hover { text-decoration: underline; }
.detail-cc-line { display: block; margin-top: 2px; }
.autosave-status {
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-faint);
  margin-left: auto;
  margin-right: 8px;
  white-space: nowrap;
}
.compose-attach-row { display: flex; }
.attachment-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8571rem;
  color: var(--text);
  max-width: 220px;
}
.attachment-chip svg { width: 15px; height: 15px; color: var(--text-faint); flex-shrink: 0; }
.attachment-chip .attachment-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.attachment-chip .attachment-size { color: var(--text-faint); flex-shrink: 0; white-space: nowrap; }
.attachment-chip .attachment-remove {
  border: none;
  background: transparent;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 0 0 2px;
  flex-shrink: 0;
}
.attachment-chip .attachment-remove:hover { color: var(--danger); }
.attachment-chip.clickable { cursor: pointer; }
.attachment-chip.clickable:hover { background: var(--bg-hover); }
.detail-attachments { margin-top: 16px; }
.signature-textarea { min-height: 90px; resize: vertical; font-family: inherit; }
#composeForm input, #composeForm textarea, #labelForm input, #accountForm input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1rem;
  background: var(--bg-sunken);
  color: var(--text);
  font-family: inherit;
  outline: none;
}
#composeForm input:focus, #composeForm textarea:focus, #labelForm input:focus, #accountForm input:focus {
  border-color: var(--accent);
}
#composeForm textarea { min-height: 220px; resize: vertical; }

.autocomplete-wrap { position: relative; }
.autocomplete-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
  z-index: 60;
  padding: 4px;
}
.autocomplete-option {
  display: flex;
  flex-direction: column;
  gap: 1px;
  width: 100%;
  padding: 7px 10px;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  text-align: left;
}
.autocomplete-option:hover, .autocomplete-option.highlighted { background: var(--bg-hover); }
.autocomplete-option strong { font-size: 0.9286rem; color: var(--text); }
.autocomplete-option span { font-size: 0.8571rem; color: var(--text-faint); }
.compose-actions { display: flex; gap: 8px; margin-top: 4px; }
.primary-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 9px 20px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.9643rem;
  cursor: pointer;
}
.primary-btn:hover { background: var(--accent-hover); }
.ghost-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 9px 16px;
  border-radius: 20px;
  font-size: 0.9643rem;
  cursor: pointer;
}
.ghost-btn:hover { background: var(--bg-hover); }

.settings-body { display: flex; flex-direction: column; gap: 16px; padding: 16px 18px 20px; }
.settings-group { display: flex; flex-direction: column; gap: 8px; }
.settings-label { font-size: 0.8929rem; font-weight: 600; color: var(--text-muted); }
.segmented, .mini-segmented {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  background: var(--bg-sunken);
  border-radius: 10px;
  padding: 4px;
}
.segmented button, .mini-segmented button {
  flex: 1;
  min-width: fit-content;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8929rem;
  padding: 7px 10px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
}
.segmented button:hover, .mini-segmented button:hover { color: var(--text); }
.segmented button.active, .mini-segmented button.active { background: var(--bg); color: var(--accent); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,0.15); }

.settings-input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.9286rem;
  background: var(--bg-sunken);
  color: var(--text);
  font-family: inherit;
  outline: none;
}
.settings-input:focus { border-color: var(--accent); }
.settings-hint { font-size: 0.75rem; color: var(--text-faint); margin: 6px 0 0; line-height: 1.5; }

.shortcut-list { display: flex; flex-direction: column; gap: 2px; }
.shortcut-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8929rem;
  color: var(--text-muted);
}
.shortcut-row:last-child { border-bottom: none; }
.shortcut-keys { display: flex; gap: 4px; flex-shrink: 0; }
kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-sunken);
  color: var(--text);
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  box-shadow: 0 1px 0 rgba(0,0,0,0.08);
}

.color-swatches { display: flex; gap: 8px; padding: 2px 0; }
.color-swatch {
  width: 26px; height: 26px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
}
.color-swatch.selected { border-color: var(--text); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #1f2430;
  color: #fff;
  padding: 10px 20px;
  border-radius: 8px;
  font-size: 0.9643rem;
  box-shadow: var(--shadow);
  z-index: 200;
  display: flex;
  align-items: center;
  gap: 14px;
  white-space: nowrap;
}
.toast-action {
  border: none;
  background: transparent;
  color: var(--accent-hover, #82a2f8);
  font-weight: 700;
  font-size: 0.9643rem;
  cursor: pointer;
  padding: 0;
}
.toast-action:hover { text-decoration: underline; }

/* ---------- responsive ---------- */
@media (max-width: 960px) {
  .body-layout { grid-template-columns: 0 1fr 0 0; }
  .pane-resizer { display: none; }
  .sidebar {
    position: fixed;
    top: 57px; bottom: 0; left: 0;
    width: 240px;
    z-index: 60;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow);
  }
  .sidebar.open { transform: translateX(0); }
  .message-detail-pane {
    position: fixed;
    top: 57px; bottom: 0; left: 0; right: 0;
    z-index: 55;
    transform: translateX(100%);
    transition: transform .2s ease;
  }
  .message-detail-pane.open { transform: translateX(0); }
  .message-list-pane { border-left: none; }
  .search-wrap { display: none; }
}
