:root {
  --accent: #1a73e8;
  --accent-hover: #1765cc;
  --bg: #f6f8fc;
  --pane-bg: #ffffff;
  --border: #e3e7ee;
  --text: #1f2328;
  --text-2: #5f6673;
  --text-3: #9aa1ad;
  --unread-bg: #f2f7ff;
  --danger: #d93025;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 4px 14px rgba(16, 24, 40, .06);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}
.hidden { display: none !important; }
.spacer { flex: 1; }

/* ---------- login ---------- */
#login-view {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #e8f0fe 0%, #f6f8fc 55%, #fdeef2 100%);
}
#login-form {
  width: 360px; max-width: 92vw;
  background: var(--pane-bg); border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 40px 36px 32px;
  display: flex; flex-direction: column; gap: 14px;
  text-align: center;
}
.login-logo { font-size: 44px; }
#login-form h1 { font-size: 22px; font-weight: 600; }
.login-sub { color: var(--text-3); font-size: 13px; margin-top: -8px; }
#login-form input {
  padding: 11px 14px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; outline: none; transition: border .15s;
}
#login-form input:focus { border-color: var(--accent); }
#login-btn {
  margin-top: 6px; padding: 11px; border: 0; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 15px; cursor: pointer;
}
#login-btn:hover { background: var(--accent-hover); }
#login-btn:disabled { opacity: .6; cursor: default; }
.login-error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---------- layout ---------- */
#app-view { display: flex; height: 100vh; overflow: hidden; }

#sidebar {
  width: 208px; min-width: 208px;
  background: var(--pane-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.brand {
  padding: 18px 20px 14px; font-size: 18px; font-weight: 700; color: var(--accent);
}
#folder-list { flex: 1; overflow-y: auto; padding: 4px 10px; }
.folder-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; border-radius: 20px; cursor: pointer;
  color: var(--text-2); font-size: 14px; user-select: none;
}
.folder-item:hover { background: #eef1f6; }
.folder-item.active { background: #e2edfd; color: var(--accent); font-weight: 600; }
.folder-item .f-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-badge {
  min-width: 20px; padding: 1px 6px; border-radius: 10px;
  background: var(--accent); color: #fff; font-size: 11px; text-align: center;
}
.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: 6px; }
.me-email { width: 100%; color: var(--text-3); font-size: 12px; padding: 4px 2px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

#list-pane {
  width: 340px; min-width: 300px;
  background: var(--pane-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.list-toolbar {
  padding: 12px; display: flex; flex-direction: column; gap: 8px;
  border-bottom: 1px solid var(--border);
}
#search-input {
  padding: 9px 14px; border: 1px solid var(--border); border-radius: 20px;
  font-size: 13px; outline: none; background: var(--bg);
}
#search-input:focus { border-color: var(--accent); background: #fff; }
#folder-title { font-size: 15px; font-weight: 600; padding: 0 4px; }
.search-banner {
  padding: 8px 16px; background: #fff8e6; color: #8a6d1a; font-size: 13px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
}
.search-banner a { color: var(--accent); cursor: pointer; }
#msg-list { flex: 1; overflow-y: auto; }

.msg-item {
  padding: 12px 16px; border-bottom: 1px solid #f0f2f6;
  cursor: pointer; position: relative;
}
.msg-item:hover { background: #f8fafd; }
.msg-item.active { background: var(--unread-bg); box-shadow: inset 3px 0 0 var(--accent); }
.msg-item.unread { background: var(--unread-bg); }
.msg-item.unread:hover { background: #e9f1fe; }
.msg-row1 { display: flex; align-items: baseline; gap: 8px; }
.msg-from {
  flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-size: 14px; color: var(--text-2);
}
.msg-item.unread .msg-from { font-weight: 700; color: var(--text); }
.msg-date { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.msg-subject {
  margin-top: 3px; font-size: 13px; color: var(--text-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-item.unread .msg-subject { font-weight: 600; color: var(--text); }
.msg-extras { margin-top: 2px; font-size: 12px; color: var(--text-3); display: flex; gap: 8px; }
#load-more-wrap { padding: 10px; text-align: center; border-top: 1px solid var(--border); }

#main-pane { flex: 1; overflow-y: auto; background: var(--bg); position: relative; }

#empty-state {
  height: 100%; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 14px; color: var(--text-3);
}
.empty-icon { font-size: 52px; }

/* ---------- buttons ---------- */
.primary-btn {
  padding: 8px 20px; border: 0; border-radius: 20px;
  background: var(--accent); color: #fff; font-size: 14px; cursor: pointer;
}
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn:disabled { opacity: .55; cursor: default; }
.ghost-btn {
  padding: 7px 14px; border: 1px solid var(--border); border-radius: 18px;
  background: #fff; color: var(--text-2); font-size: 13px; cursor: pointer;
}
.ghost-btn:hover { background: #f2f5f9; color: var(--text); }

/* ---------- read view ---------- */
#read-view { padding: 0 0 40px; }
.read-toolbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; gap: 8px; padding: 12px 24px;
  background: rgba(246, 248, 252, .92); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.read-header { padding: 22px 24px 6px; }
.read-header h2 { font-size: 19px; font-weight: 600; margin-bottom: 14px; }
.read-meta { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--text-2); }
.meta-label { display: inline-block; width: 52px; color: var(--text-3); }

.attachments {
  margin: 14px 24px; padding: 12px 16px;
  background: var(--pane-bg); border: 1px solid var(--border); border-radius: var(--radius);
}
.attachments h4 { font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.att-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.att-chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px; color: var(--text-2);
  text-decoration: none; max-width: 280px;
}
.att-chip:hover { border-color: var(--accent); color: var(--accent); }
.att-chip .att-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-chip .att-size { color: var(--text-3); font-size: 12px; }

.msg-body {
  margin: 14px 24px 0; padding: 24px;
  background: var(--pane-bg); border: 1px solid var(--border); border-radius: var(--radius);
  overflow-wrap: break-word; line-height: 1.7;
}
.msg-body img { max-width: 100%; height: auto; border-radius: 4px; }
.msg-body blockquote {
  border-left: 3px solid var(--border); margin: 8px 0; padding: 2px 14px;
  color: var(--text-2);
}
.msg-body pre { white-space: pre-wrap; font-family: inherit; }

/* ---------- compose ---------- */
#compose-view {
  padding: 16px 24px 40px;
  display: flex; flex-direction: column; gap: 12px; min-height: 100%;
}
.compose-toolbar { display: flex; align-items: center; gap: 10px; }
.compose-title { font-size: 16px; font-weight: 600; }
.compose-fields {
  background: var(--pane-bg); border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0; border-bottom: 0;
}
.compose-fields .field { display: flex; align-items: center; border-bottom: 1px solid #f0f2f6; }
.compose-fields label { width: 64px; padding: 10px 12px; color: var(--text-3); font-size: 13px; }
.compose-fields input {
  flex: 1; padding: 10px 4px; border: 0; outline: none; font-size: 14px; background: transparent;
}
.editor {
  background: var(--pane-bg); border: 1px solid var(--border); border-radius: 0 0 var(--radius) var(--radius);
  padding: 18px 20px; min-height: 240px; outline: none; line-height: 1.7; font-size: 14px;
  overflow-wrap: break-word;
}
.editor:empty::before { content: attr(data-placeholder); color: var(--text-3); }
.editor img { max-width: 100%; }
.editor blockquote.sm-quote {
  border-left: 3px solid var(--accent); margin: 10px 0; padding: 4px 14px;
  color: var(--text-2); max-height: 5.5em; overflow: hidden; cursor: pointer;
  position: relative; transition: max-height .2s;
  background: linear-gradient(#fff, #fff) padding-box;
}
.editor blockquote.sm-quote.expanded { max-height: none; }
.quote-hint { color: var(--text-3); font-size: 12px; margin-top: 12px; }
.quote-meta { color: var(--text-3); font-size: 13px; margin-top: 14px; }

.compose-attachments { display: flex; flex-wrap: wrap; gap: 8px; }
.c-att-chip {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 10px; background: var(--pane-bg); border: 1px solid var(--border);
  border-radius: 8px; font-size: 13px;
}
.c-att-chip button { border: 0; background: none; cursor: pointer; color: var(--text-3); font-size: 14px; }
.c-att-chip button:hover { color: var(--danger); }
.compose-bottom { display: flex; align-items: center; gap: 12px; }
.attach-hint { color: var(--text-3); font-size: 12px; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%);
  background: #303134; color: #fff; padding: 10px 22px;
  border-radius: 24px; font-size: 14px; z-index: 99; box-shadow: var(--shadow);
}

/* ---------- responsive ---------- */
@media (max-width: 900px) {
  #sidebar { width: 64px; min-width: 64px; }
  .brand { font-size: 20px; padding: 16px 0; text-align: center; }
  .folder-item .f-name, .sidebar-footer .ghost-btn span, .me-email { display: none; }
  .folder-item { justify-content: center; }
  #list-pane { width: 260px; min-width: 220px; }
}
@media (max-width: 680px) {
  #app-view { flex-direction: column; }
  #sidebar { width: 100%; min-width: 0; flex-direction: row; align-items: center; border-right: 0; border-bottom: 1px solid var(--border); }
  #folder-list { display: flex; overflow-x: auto; }
  .folder-item { white-space: nowrap; }
  .sidebar-footer { border-top: 0; }
  #list-pane { width: 100%; min-width: 0; border-right: 0; }
  #main-pane.pane-open ~ #list-pane, #list-pane.pane-closed { display: none; }
}

/* ---------- signature modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 80;
  background: rgba(15, 23, 42, .45);
  display: flex; align-items: center; justify-content: center;
  padding: 20px; backdrop-filter: blur(2px);
}
.modal-card {
  width: 620px; max-width: 100%; max-height: 90vh; overflow: hidden;
  background: var(--pane-bg); border-radius: 14px; box-shadow: 0 12px 40px rgba(0,0,0,.25);
  display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-head h3 { font-size: 17px; font-weight: 600; }
.modal-x { border: 0; background: none; font-size: 16px; cursor: pointer; color: var(--text-3); }
.modal-x:hover { color: var(--text); }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--border);
}
.sig-note { font-size: 12px; color: var(--text-3); margin-bottom: 14px; line-height: 1.6; }
.sig-form { display: flex; flex-wrap: wrap; gap: 10px 14px; }
.sig-row { display: flex; flex-direction: column; gap: 4px; flex: 1 1 160px; }
.sig-row.sig-wide { flex: 1 1 100%; }
.sig-row label { font-size: 12px; color: var(--text-2); }
.sig-row input {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px;
  font-size: 13px; outline: none;
}
.sig-row input:focus { border-color: var(--accent); }
.sig-actions { display: flex; align-items: center; gap: 14px; margin: 16px 0 6px; }
.sig-status { font-size: 13px; color: var(--text-2); }
.sig-result { margin-top: 12px; border-top: 1px dashed var(--border); padding-top: 12px; }
.sig-result-head {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 12px; color: var(--text-3); margin-bottom: 8px;
}
.sig-toggle-src { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; }
.sig-preview {
  padding: 16px; background: #fbfcfe; border: 1px solid var(--border);
  border-radius: 8px; overflow-x: auto; min-height: 40px;
}
.sig-preview img { max-width: 100%; }
.sig-source {
  width: 100%; min-height: 140px; padding: 10px; border: 1px solid var(--border);
  border-radius: 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px; resize: vertical; outline: none;
}
#btn-insert-sig { position: relative; }
.sm-signature { margin-top: 14px; }
.editor .sm-signature img { max-width: 100%; }
