/* ============ tokens ============ */
:root {
  --bg: #0b0d10;
  --bg-elev: #12151a;
  --bg-elev-2: #181c23;
  --bg-hover: #1d222b;
  --bg-active: #232936;
  --border: #232833;
  --border-soft: #1a1e26;
  --text: #e6e9ef;
  --text-dim: #9aa3b2;
  --text-faint: #646e7d;
  --accent: #6d8cff;
  --accent-soft: rgba(109, 140, 255, 0.13);
  --accent-glow: rgba(109, 140, 255, 0.28);
  --danger: #ff5f6d;
  --success: #3ddc97;
  --warn: #ffc857;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.55);
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, monospace;
}

[data-theme="light"] {
  --bg: #f4f6fa;
  --bg-elev: #ffffff;
  --bg-elev-2: #eef1f6;
  --bg-hover: #e9edf4;
  --bg-active: #dfe6f2;
  --border: #dbe1ec;
  --border-soft: #e6eaf2;
  --text: #131720;
  --text-dim: #5c6675;
  --text-faint: #8b95a5;
  --accent: #3b5bdb;
  --accent-soft: rgba(59, 91, 219, 0.1);
  --accent-glow: rgba(59, 91, 219, 0.2);
  --shadow: 0 12px 40px rgba(20, 30, 60, 0.12);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body { height: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, textarea { font-family: inherit; font-size: inherit; color: inherit; }
button { cursor: pointer; background: none; border: none; }
a { color: var(--accent); text-decoration: none; }
[hidden] { display: none !important; }

/* ============ login ============ */
.login-screen {
  height: 100%;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1100px 600px at 12% -8%, var(--accent-soft), transparent 60%),
    radial-gradient(900px 500px at 92% 108%, rgba(61, 220, 151, 0.07), transparent 55%),
    var(--bg);
  padding: 24px;
}

.login-card {
  width: 100%;
  max-width: 396px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 34px 30px 26px;
  box-shadow: var(--shadow);
  animation: rise 0.45s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: none; }
}

.login-brand { display: flex; gap: 14px; align-items: center; margin-bottom: 28px; }

.brand-mark {
  width: 46px; height: 46px;
  display: grid; place-items: center;
  border-radius: 13px;
  background: linear-gradient(140deg, var(--accent), #9d7bff);
  color: #fff;
  font-size: 21px;
  box-shadow: 0 6px 20px var(--accent-glow);
  flex-shrink: 0;
}
.brand-mark.small { width: 34px; height: 34px; font-size: 16px; border-radius: 10px; }

.login-brand h1 { font-size: 16px; font-weight: 600; letter-spacing: -0.01em; }
.login-brand p { font-size: 12.5px; color: var(--text-faint); margin-top: 2px; }

#login-form { display: flex; flex-direction: column; gap: 15px; }

#login-form label { display: flex; flex-direction: column; gap: 6px; }
#login-form label span {
  font-size: 11.5px; font-weight: 600; color: var(--text-dim);
  text-transform: uppercase; letter-spacing: 0.07em;
}

input[type="email"], input[type="password"], input[type="text"], input[type="search"], textarea {
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
  width: 100%;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--bg-elev);
}

.btn-primary {
  background: linear-gradient(140deg, var(--accent), #8a6bff);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 11px 18px;
  font-weight: 600;
  font-size: 13.5px;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 0.12s, box-shadow 0.2s, opacity 0.2s;
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 7px 22px var(--accent-glow); }
.btn-primary:active { transform: none; }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }

.error-text {
  color: var(--danger);
  font-size: 12.5px;
  text-align: center;
  padding: 8px;
  background: rgba(255, 95, 109, 0.09);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 95, 109, 0.2);
}

.login-footer {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
  display: flex;
  gap: 8px;
  justify-content: center;
  font-size: 11.5px;
  color: var(--text-faint);
}

/* ============ app shell ============ */
.app {
  height: 100%;
  display: grid;
  grid-template-columns: 232px minmax(300px, 400px) 1fr;
}

/* ============ sidebar ============ */
.sidebar {
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-head {
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border-soft);
}

.btn-compose {
  flex: 1;
  display: flex; align-items: center; justify-content: center; gap: 7px;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(109, 140, 255, 0.22);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-weight: 600;
  font-size: 12.5px;
  transition: background 0.15s, border-color 0.15s;
}
.btn-compose:hover { background: rgba(109, 140, 255, 0.2); border-color: var(--accent); }

.folders { flex: 1; overflow-y: auto; padding: 9px; display: flex; flex-direction: column; gap: 1px; }

.folder-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 500;
  transition: background 0.12s, color 0.12s;
  text-align: left;
  width: 100%;
}
.folder-item:hover { background: var(--bg-hover); color: var(--text); }
.folder-item.active { background: var(--bg-active); color: var(--text); font-weight: 600; }
.folder-item .f-icon { width: 16px; text-align: center; opacity: 0.75; font-size: 13px; }
.folder-item .f-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-item .f-count {
  font-size: 11px; font-weight: 600;
  background: var(--accent); color: #fff;
  padding: 1px 6px; border-radius: 9px;
  font-family: var(--mono);
}

.sidebar-foot {
  border-top: 1px solid var(--border-soft);
  padding: 11px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.account { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }

.avatar {
  width: 30px; height: 30px; border-radius: 9px;
  background: linear-gradient(140deg, var(--accent), #9d7bff);
  color: #fff; font-weight: 700; font-size: 12.5px;
  display: grid; place-items: center; flex-shrink: 0;
}
.avatar.tiny { width: 28px; height: 28px; border-radius: 8px; font-size: 11.5px; }

.account-meta { min-width: 0; }
.account-name {
  font-size: 12px; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.account-sub { font-size: 10.5px; color: var(--text-faint); }

.sidebar-actions { display: flex; gap: 2px; }

.icon-btn {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-size: 14px;
  transition: background 0.12s, color 0.12s;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }
.icon-btn.danger:hover { background: rgba(255, 95, 109, 0.14); color: var(--danger); }

/* ============ list pane ============ */
.list-pane {
  background: var(--bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

.list-head { padding: 13px 14px 10px; border-bottom: 1px solid var(--border-soft); }

.list-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.list-title-row h2 { font-size: 15px; font-weight: 650; letter-spacing: -0.01em; }
.list-tools { display: flex; gap: 2px; }

.search-wrap { position: relative; display: flex; align-items: center; }
.search-icon { position: absolute; left: 10px; color: var(--text-faint); pointer-events: none; }
#search-input { padding-left: 31px; font-size: 13px; background: var(--bg-elev-2); }

.message-list { flex: 1; overflow-y: auto; min-height: 0; }

.msg-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  transition: background 0.1s;
  border-left: 2px solid transparent;
  position: relative;
}
.msg-item:hover { background: var(--bg-hover); }
.msg-item.active { background: var(--bg-active); border-left-color: var(--accent); }
.msg-item.unread { background: rgba(109, 140, 255, 0.045); }
.msg-item.unread .msg-from, .msg-item.unread .msg-subject { color: var(--text); font-weight: 650; }
.msg-item.unread::after {
  content: ''; position: absolute; left: 5px; top: 50%;
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--accent); transform: translateY(-50%);
}

.msg-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 3px; }
.msg-from {
  font-size: 12.8px; font-weight: 550; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg-date { font-size: 10.8px; color: var(--text-faint); flex-shrink: 0; font-family: var(--mono); }
.msg-subject {
  font-size: 12.6px; font-weight: 500; color: var(--text-dim);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  margin-bottom: 2px;
}
.msg-snippet {
  font-size: 11.5px; color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: flex; align-items: center; gap: 6px;
}
.msg-badge { font-size: 9.5px; padding: 1px 5px; border-radius: 4px; background: var(--bg-elev-2); color: var(--text-faint); }
.flag-mark { color: var(--warn); font-size: 11px; }

.list-empty {
  flex: 1; display: grid; place-content: center; justify-items: center;
  gap: 8px; color: var(--text-faint); padding: 40px;
}
.empty-icon { font-size: 30px; opacity: 0.4; }

/* ============ reader ============ */
.reader-pane {
  background: var(--bg-elev);
  display: flex; flex-direction: column;
  min-height: 0; min-width: 0; overflow: hidden;
}

.reader-empty {
  flex: 1; display: grid; place-content: center; justify-items: center;
  gap: 6px; color: var(--text-faint); text-align: center; padding: 40px;
}
.empty-graphic { color: var(--text-faint); opacity: 0.28; margin-bottom: 10px; }
.reader-empty h3 { font-size: 14.5px; font-weight: 600; color: var(--text-dim); }
.reader-empty p { font-size: 12.5px; }

.kbd-hints { display: flex; gap: 14px; margin-top: 20px; flex-wrap: wrap; justify-content: center; font-size: 11px; }
.kbd-hints span { display: flex; align-items: center; gap: 4px; }
kbd {
  font-family: var(--mono); font-size: 10px;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 4px; padding: 1px 5px; color: var(--text-dim);
}

.reader-content { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.reader-head { padding: 13px 20px 15px; border-bottom: 1px solid var(--border-soft); flex-shrink: 0; }
.reader-actions { display: flex; align-items: center; gap: 2px; margin-bottom: 11px; }
.spacer { flex: 1; }

.reader-head h1 {
  font-size: 18px; font-weight: 650; letter-spacing: -0.02em;
  line-height: 1.35; margin-bottom: 12px; word-break: break-word;
}

.reader-meta { display: flex; align-items: center; gap: 10px; }
.reader-meta > div { flex: 1; min-width: 0; }
.reader-from { font-size: 12.8px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-to { font-size: 11.3px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-meta time { font-size: 11px; color: var(--text-faint); font-family: var(--mono); flex-shrink: 0; }

.reader-attachments { padding: 12px 20px 0; display: flex; flex-wrap: wrap; gap: 8px; }

.attachment {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 11px;
  font-size: 12px;
  transition: border-color 0.15s, background 0.15s;
}
.attachment:hover { border-color: var(--accent); background: var(--bg-hover); }
.attachment .att-size { color: var(--text-faint); font-size: 10.5px; font-family: var(--mono); }

.reader-body {
  flex: 1; overflow-y: auto; padding: 20px;
  font-size: 14px; line-height: 1.68;
  word-break: break-word;
}
.reader-body pre, .reader-body .plain-body {
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 12.8px;
  line-height: 1.65;
  color: var(--text);
}
.reader-body img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }
.reader-body a { text-decoration: underline; text-underline-offset: 2px; }
.reader-body blockquote {
  border-left: 2px solid var(--border);
  padding-left: 12px; margin: 10px 0;
  color: var(--text-dim);
}
.reader-body table { border-collapse: collapse; max-width: 100%; }
.reader-body td, .reader-body th { border: 1px solid var(--border); padding: 5px 9px; }

/* ============ modal ============ */
.modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(4, 6, 10, 0.72); backdrop-filter: blur(3px); }

.compose-window {
  position: relative;
  width: 100%; max-width: 620px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  max-height: 82vh;
  animation: rise 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

.compose-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 13px 16px; border-bottom: 1px solid var(--border-soft);
}
.compose-head h3 { font-size: 13.5px; font-weight: 650; }

.compose-fields { padding: 5px 16px; }
.field-row {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0; border-bottom: 1px solid var(--border-soft);
}
.field-row label {
  width: 56px; font-size: 11.5px; font-weight: 600;
  color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em;
}
.field-row input {
  background: none; border: none; padding: 2px 0; font-size: 13px;
  box-shadow: none;
}
.field-row input:focus { box-shadow: none; background: none; }

#compose-body {
  flex: 1; min-height: 220px; resize: none;
  background: none; border: none; padding: 15px 16px;
  font-size: 13.3px; line-height: 1.65;
  box-shadow: none;
}
#compose-body:focus { box-shadow: none; background: none; }

.compose-foot {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-top: 1px solid var(--border-soft);
}
.compose-status { font-size: 11.5px; color: var(--text-faint); }

/* ============ toast ============ */
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 18px;
  font-size: 12.5px;
  box-shadow: var(--shadow);
  z-index: 200;
  animation: toast-in 0.25s ease;
}
.toast.err { border-color: rgba(255, 95, 109, 0.4); color: var(--danger); }
.toast.ok { border-color: rgba(61, 220, 151, 0.4); color: var(--success); }

@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ============ scrollbars ============ */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ============ responsive ============ */
@media (max-width: 1080px) {
  .app { grid-template-columns: 200px minmax(260px, 340px) 1fr; }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: 232px; z-index: 50;
    transform: translateX(-100%); transition: transform 0.24s ease;
  }
  .sidebar.open { transform: none; }
  .list-pane { border-right: none; }
  .reader-pane {
    position: fixed; inset: 0; z-index: 60;
    transform: translateX(100%); transition: transform 0.24s ease;
  }
  .reader-pane.open { transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
