:root {
  --accent: #0f6cbd;
  --accent-hover: #115ea3;
  --bg: #faf9f8;
  --surface: #ffffff;
  --surface-2: #f3f2f1;
  --surface-3: #edebe9;
  --border: #e1dfdd;
  --text: #242424;
  --text-2: #616161;
  --text-3: #8a8886;
  --selected: #eaf1fb;
  --selected-bar: #0f6cbd;
  --topbar-bg: #0f6cbd;
  --topbar-fg: #ffffff;
  --search-bg: #ffffff;
  --banner-bg: #fff4ce;
  --banner-border: #f2e2a0;
  --banner-fg: #5c4813;
  --font: "Segoe UI", "Segoe UI Web (West European)", -apple-system, BlinkMacSystemFont,
    Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --accent: #479ef5;
  --accent-hover: #62abf5;
  --bg: #1b1a19;
  --surface: #252423;
  --surface-2: #2b2a29;
  --surface-3: #3b3a39;
  --border: #3b3a39;
  --text: #ffffff;
  --text-2: #c8c6c4;
  --text-3: #979593;
  --selected: #2d3b4d;
  --selected-bar: #479ef5;
  --topbar-bg: #252423;
  --topbar-fg: #ffffff;
  --search-bg: #3b3a39;
  --banner-bg: #3b3320;
  --banner-border: #5c4d1f;
  --banner-fg: #f5e6b8;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }

.app { display: grid; grid-template-rows: 48px 1fr; height: 100vh; overflow: hidden; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--topbar-bg);
  color: var(--topbar-fg);
  padding: 0 6px;
}
.waffle,
.topbar .icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--topbar-fg);
  cursor: pointer;
}
.waffle:hover,
.topbar .icon-btn:hover { background: rgba(255, 255, 255, 0.14); }
[data-theme="dark"] .waffle:hover,
[data-theme="dark"] .topbar .icon-btn:hover { background: rgba(255, 255, 255, 0.08); }

.brand { font-size: 16px; font-weight: 600; margin: 0 8px 0 2px; }

.search { flex: 0 1 640px; margin: 0 auto; position: relative; }
.search svg { position: absolute; left: 10px; top: 8px; color: var(--text-2); opacity: 0.8; }
.search input {
  width: 100%;
  height: 32px;
  border: 0;
  border-radius: 4px;
  padding: 0 12px 0 32px;
  background: var(--search-bg);
  color: var(--text);
  font-size: 14px;
}
.search input::placeholder { color: var(--text-3); }

.topbar-right { display: flex; align-items: center; gap: 0; margin-left: auto; }
.account {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  margin: 0 6px 0 4px;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 12px;
  background: #ffffff;
  color: var(--accent);
  cursor: pointer;
}
[data-theme="dark"] .account { background: var(--accent); color: #fff; }

/* ------------------------------------------------------------------ layout */
.main {
  display: grid;
  grid-template-columns: 48px 264px 400px 1fr;
  min-height: 0;
  background: var(--bg);
}
@media (max-width: 1180px) {
  .main { grid-template-columns: 48px 236px 340px 1fr; }
}

/* -------------------------------------------------------------------- rail */
.rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding-top: 6px;
  border-right: 1px solid var(--border);
}
.rail button {
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  display: grid;
  place-items: center;
  cursor: pointer;
  position: relative;
}
.rail button:hover { background: var(--surface-2); }
.rail button.active { color: var(--accent); }
.rail button.active::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 3px;
  background: var(--accent);
}

/* ------------------------------------------------------------ folder pane */
.folders {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 8px;
  border-right: 1px solid var(--border);
}
.newmail {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  width: max-content;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  cursor: default;
}
.newmail:hover { background: var(--surface-2); }
.folder-list { flex: 1; overflow: auto; }
.folder-section {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-2);
  margin: 12px 4px 4px;
}
.folder-section:first-child { margin-top: 2px; }
.folder {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 30px;
  padding: 0 8px;
  border-radius: 4px;
  color: var(--text);
  cursor: pointer;
  position: relative;
  user-select: none;
}
.folder:hover { background: var(--surface-2); }
.folder.active { background: var(--selected); font-weight: 600; }
.folder.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 5px;
  bottom: 5px;
  width: 3px;
  border-radius: 3px;
  background: var(--selected-bar);
}
.folder .ficon { display: grid; place-items: center; color: var(--text-2); width: 16px; }
.folder.active .ficon { color: var(--accent); }
.folder .name {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.folder .count { color: var(--accent); font-size: 12px; font-weight: 600; }

/* --------------------------------------------------------------- list pane */
.list {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
}
.list-cmdbar {
  display: flex;
  align-items: center;
  gap: 4px;
  height: 40px;
  padding: 0 6px;
  border-bottom: 1px solid var(--border);
}
.list-cmdbar .spacer { flex: 1; }
.icon-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--text-2);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.list-cmdbar .icon-btn:hover,
.rp-cmdbar .icon-btn:hover { background: var(--surface-2); }
.sync-pill { font-size: 12px; color: var(--text-3); padding-left: 4px; }

.pivot {
  display: flex;
  gap: 18px;
  height: 36px;
  padding: 0 14px;
  align-items: flex-end;
  border-bottom: 1px solid var(--border);
}
.pivot button {
  border: 0;
  background: transparent;
  font-size: 14px;
  color: var(--text-2);
  padding: 0 0 8px;
  cursor: pointer;
  position: relative;
}
.pivot button.active { color: var(--text); font-weight: 600; }
.pivot button.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 2px;
  border-radius: 2px;
  background: var(--accent);
}

.list-scroll { flex: 1; overflow: auto; }

.msg {
  display: flex;
  gap: 8px;
  padding: 8px 12px 9px 6px;
  border-bottom: 1px solid var(--surface-2);
  cursor: pointer;
  position: relative;
}
.msg:hover { background: var(--surface-2); }
.msg.active { background: var(--selected); }
.msg.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--selected-bar);
}
.msg .rail-dot { width: 14px; display: flex; justify-content: center; padding-top: 6px; }
.msg .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.msg .body { flex: 1; min-width: 0; }
.msg .row1 { display: flex; align-items: baseline; gap: 8px; }
.msg .from {
  flex: 1;
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg.unread .from { font-weight: 700; }
.msg .time { font-size: 12px; color: var(--text-2); white-space: nowrap; }
.msg.unread .time { color: var(--accent); font-weight: 600; }
.msg .subject {
  font-size: 13px;
  color: var(--text);
  margin-top: 1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg.unread .subject { font-weight: 600; }
.msg .preview {
  font-size: 12px;
  color: var(--text-2);
  margin-top: 1px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ------------------------------------------------------------ reading pane */
.reading { display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.rp-cmdbar {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 44px;
  padding: 0 10px;
  border-bottom: 1px solid var(--border);
}
.rp-cmdbar .icon-btn { width: 36px; height: 36px; }
.rp-cmdbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }
.rp-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.rp-subject {
  font-size: 21px;
  font-weight: 600;
  color: var(--text);
  margin: 16px 20px 12px;
}
.rp-meta { display: flex; align-items: center; gap: 12px; margin: 0 20px 14px; }
.rp-avatar {
  width: 40px;
  height: 40px;
  flex: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
}
.rp-meta .who { flex: 1; min-width: 0; }
.rp-meta .who .n { font-weight: 600; }
.rp-meta .who .a { font-size: 13px; color: var(--text-2); }
.rp-meta .when { font-size: 13px; color: var(--text-2); white-space: nowrap; }

.rp-summary {
  margin: 0 20px 12px;
  padding: 12px 14px;
  max-height: 168px;
  overflow: auto;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}
.rp-links { margin-top: 10px; display: flex; gap: 16px; flex-wrap: wrap; }
a.lnk { color: var(--accent); text-decoration: none; font-weight: 600; }
a.lnk:hover { text-decoration: underline; }

.rp-viewtabs {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 0 20px 8px;
}
.rp-viewtabs button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-2);
  font-size: 12px;
  padding: 3px 12px;
  border-radius: 4px;
  cursor: pointer;
}
.rp-viewtabs button.active {
  background: var(--selected);
  color: var(--text);
  border-color: var(--selected-bar);
  font-weight: 600;
}
.rp-viewnote { font-size: 12px; color: var(--text-3); }

.rp-frame {
  flex: 1;
  margin: 0 20px 20px;
  min-height: 260px;
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  background: #fff;
}
.rp-frame iframe { width: 100%; height: 100%; border: 0; display: block; }
.rp-hint { margin: 0 20px 14px; font-size: 12px; color: var(--text-3); }

/* ------------------------------------------------------------ shared bits */
.banner {
  margin: 12px 16px 4px;
  padding: 10px 12px;
  border-radius: 6px;
  background: var(--banner-bg);
  border: 1px solid var(--banner-border);
  color: var(--banner-fg);
  font-size: 13px;
}
.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px;
  text-align: center;
  color: var(--text-2);
}
.empty h2 { margin: 0; font-size: 17px; font-weight: 600; color: var(--text); }
.empty .retry {
  margin-top: 6px;
  height: 30px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
}
.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
