* { box-sizing: border-box; }

:root {
  --bg: #f6f8fc;
  --card: #ffffff;
  --line: #e3e6ee;
  --text: #1f2330;
  --muted: #6b7280;
  --accent: #1a73e8;
  --accent-dark: #1765cc;
  --danger: #d93025;
}

body {
  margin: 0;
  font-family: "Segoe UI", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; min-height: 1em; }

button { font: inherit; }
.button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 8px;
  padding: 7px 14px;
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  display: inline-block;
}
.button:hover { background: #f1f3f8; }
.button.primary, button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.button.primary:hover { background: var(--accent-dark); }
.button.center { text-align: center; }

/* ===== 中央卡片（登入／授權） ===== */
.center-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 32px;
  width: 460px;
  max-width: 100%;
  box-shadow: 0 8px 30px rgba(20, 30, 60, 0.08);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.card h1 { margin: 0; font-size: 22px; }
.card p { margin: 0; line-height: 1.6; }
.card input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
}
.steps { margin: 0; padding-left: 20px; line-height: 1.8; font-size: 14px; color: var(--muted); }
code { background: #f1f3f8; padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }

/* ===== 主畫面 ===== */
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; white-space: nowrap; }
#search-input {
  flex: 1;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--bg);
  font: inherit;
  min-width: 120px;
}
.actions { display: flex; gap: 8px; align-items: center; }

.layout {
  display: grid;
  grid-template-columns: 180px 380px 1fr;
  height: calc(100vh - 57px);
}

.sidebar { padding: 12px 8px; display: flex; flex-direction: column; gap: 4px; }
.folder { padding: 8px 12px; border-radius: 8px; cursor: pointer; user-select: none; }
.folder:hover { background: #eef1f8; }
.folder.active { background: #e3edfd; color: var(--accent-dark); font-weight: 600; }
.sync-info { padding: 10px 12px; line-height: 1.5; }

.list { overflow-y: auto; border-right: 1px solid var(--line); background: #fff; }
.row { padding: 10px 14px; border-bottom: 1px solid #f0f1f5; cursor: pointer; }
.row:hover { background: #f6f8fc; }
.row.active { background: #eaf1fd; }
.row-top { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.row .who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #555; }
.row .date { color: var(--muted); font-size: 12px; white-space: nowrap; }
.row .subject { margin-top: 2px; font-size: 14px; color: #555; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.unread .subject, .row.unread .who { font-weight: 700; color: var(--text); }
.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  margin-right: 6px;
}
.snippet { margin-top: 2px; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty, .loading { padding: 32px; text-align: center; color: var(--muted); }

.reader { overflow-y: auto; padding: 20px 24px; }
.reader-head h2 { margin: 0 0 8px; font-size: 20px; word-break: break-word; }
.reader-head .meta { font-size: 13px; margin: 2px 0; word-break: break-all; }
.reader-actions { margin: 12px 0; display: flex; gap: 8px; }
.reader-body { background: #fff; border: 1px solid var(--line); border-radius: 10px; }
.reader-body iframe { width: 100%; height: 70vh; border: 0; border-radius: 10px; display: block; }
.reader-body pre { white-space: pre-wrap; word-break: break-word; margin: 0; padding: 16px; font-family: inherit; line-height: 1.6; }

.attachments { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.attachments h3 { margin: 0 6px 0 0; font-size: 14px; }
.attachment {
  background: #fff;
  border: 1px solid var(--line);
  padding: 8px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  font-size: 13px;
}
.attachment:hover { border-color: var(--accent); }

/* ===== 撰寫視窗 ===== */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 25, 40, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}
.compose {
  background: #fff;
  border-radius: 14px;
  width: 640px;
  max-width: 100%;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.25);
}
.compose-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  font-weight: 600;
  border-bottom: 1px solid var(--line);
}
.compose-head button { border: 0; background: none; cursor: pointer; font-size: 16px; }
.compose input, .compose textarea {
  border: 0;
  border-bottom: 1px solid #f0f1f5;
  padding: 12px 16px;
  font: inherit;
  outline: none;
  width: 100%;
  resize: vertical;
}
#compose-files { padding: 8px 16px; font-size: 13px; }
.compose-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-top: 1px solid var(--line);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: #22283a;
  color: #fff;
  padding: 10px 18px;
  border-radius: 24px;
  font-size: 14px;
  z-index: 30;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
  max-width: 80vw;
}

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; height: auto; }
  .sidebar { flex-direction: row; overflow-x: auto; align-items: center; }
  .sync-info { display: none; }
  .list { max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--line); }
  .topbar { flex-wrap: wrap; }
  #search-input { order: 10; flex-basis: 100%; }
}
