:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #dfe3e8;
  --text: #1b1f24;
  --text-muted: #6b7480;
  --accent: #2f6fed;
  --accent-contrast: #ffffff;
  --danger: #d64545;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 8px 24px rgba(0,0,0,.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --surface: #1b1f26;
    --surface-2: #232830;
    --border: #2e343d;
    --text: #e6e9ee;
    --text-muted: #97a0ad;
    --accent: #5b8df5;
    --accent-contrast: #0d1015;
    --danger: #e06b6b;
    --shadow: 0 1px 3px rgba(0,0,0,.4), 0 8px 24px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; font-size: 13px; }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 9px 14px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn {
  border: 1px solid transparent; background: transparent; color: var(--text-muted);
  font-size: 17px; cursor: pointer; border-radius: 8px; padding: 6px 9px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.linkish { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; font-size: 13px; }

/* ---------- Login ---------- */
.login-screen { display: grid; place-items: center; height: 100%; padding: 20px; }
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 32px; width: min(360px, 100%); box-shadow: var(--shadow); text-align: center;
}
.login-icon { font-size: 34px; }
.login-card h1 { font-size: 20px; margin: 10px 0 4px; }
.login-card p { margin: 0 0 18px; font-size: 13px; }
.login-card input {
  width: 100%; padding: 11px 13px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
  margin-bottom: 12px; font-size: 15px;
}

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 230px 360px 1fr; height: 100%; }

.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 16px;
}
.brand { display: flex; gap: 10px; align-items: center; }
.brand-icon { font-size: 22px; }
.brand-text { display: flex; flex-direction: column; overflow: hidden; }
.brand-text strong { font-size: 14px; }
.brand-text small { color: var(--text-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.folders { display: flex; flex-direction: column; gap: 2px; }
.folder {
  text-align: left; background: none; border: 0; color: var(--text);
  padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.folder:hover { background: var(--surface-2); }
.folder.active { background: var(--surface-2); font-weight: 600; }
.sidebar-footer { margin-top: auto; }

.list-pane { display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--surface); min-width: 0; min-height: 0; overflow: hidden; }
.list-header { display: flex; gap: 8px; align-items: center; padding: 12px; border-bottom: 1px solid var(--border); }
.list-header input {
  flex: 1; padding: 8px 12px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 14px; min-width: 0;
}
.list { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.row {
  padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; display: grid; gap: 3px;
}
.row:hover { background: var(--surface-2); }
.row.active { background: color-mix(in srgb, var(--accent) 12%, transparent); }
.row.unread .row-from, .row.unread .row-subject { font-weight: 700; }
.row-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.row-from { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-date { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.row-subject { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-meta { font-size: 12px; color: var(--text-muted); }
.pagination { flex: 0 0 auto; display: flex; gap: 8px; align-items: center; justify-content: center; padding: 10px; border-top: 1px solid var(--border); font-size: 13px; color: var(--text-muted); }

.reader-pane { overflow-y: auto; background: var(--bg); min-width: 0; }
.empty-state { display: grid; place-items: center; min-height: 200px; height: 100%; color: var(--text-muted); font-size: 14px; }
.reader { padding: 22px 26px; max-width: 900px; }
.reader h1 { font-size: 20px; margin: 0 0 14px; line-height: 1.3; }
.reader-meta { font-size: 13px; color: var(--text-muted); display: grid; gap: 3px; margin-bottom: 14px; }
.reader-meta b { color: var(--text); font-weight: 600; }
.reader-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.banner {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; font-size: 13px; margin-bottom: 14px;
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.body-frame { width: 100%; border: 0; background: #fff; border-radius: 8px; min-height: 200px; }
pre.body-text {
  white-space: pre-wrap; word-wrap: break-word; font: inherit; margin: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 16px;
}
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 16px; }
.chip {
  display: inline-flex; gap: 6px; align-items: center; background: var(--surface);
  border: 1px solid var(--border); border-radius: 20px; padding: 6px 12px;
  font-size: 13px; color: var(--text); text-decoration: none;
}
.chip:hover { background: var(--surface-2); }
.chip small { color: var(--text-muted); }

/* ---------- Composer ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal-card {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow);
  width: min(720px, 100%); max-height: 92vh; display: flex; flex-direction: column;
  border: 1px solid var(--border);
}
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.modal-header h2 { font-size: 16px; margin: 0; }
.modal-body { padding: 14px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.modal-footer { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.field { display: flex; align-items: center; gap: 10px; }
.field label { width: 62px; font-size: 13px; color: var(--text-muted); flex-shrink: 0; }
.field input {
  flex: 1; border: 0; border-bottom: 1px solid var(--border); background: transparent;
  color: var(--text); padding: 8px 2px; font-size: 14px; min-width: 0;
}
.field input:focus { outline: none; border-bottom-color: var(--accent); }
.field.readonly span { font-size: 14px; color: var(--text-muted); }
.field.toggle-row { justify-content: flex-end; }
#c-body {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--bg); color: var(--text); padding: 12px; font: inherit; resize: vertical;
}
.attach-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.attach-list { display: flex; flex-wrap: wrap; gap: 6px; }

.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 22px;
  font-size: 14px; z-index: 100; box-shadow: var(--shadow);
}
.toast.err { background: var(--danger); color: #fff; }

.only-mobile { display: none; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .app.show-sidebar .sidebar { display: flex; position: fixed; inset: 0 auto 0 0; width: 240px; z-index: 40; box-shadow: var(--shadow); }
  .list-pane { border-right: 0; }
  .reader-pane { display: none; }
  .app.reading .list-pane { display: none; }
  .app.reading .reader-pane { display: block; }
  .only-mobile { display: inline-block; }
}
