:root {
  --bg: #f6f7f9;
  --panel: #ffffff;
  --border: #e2e5ea;
  --text: #16191d;
  --muted: #6b7280;
  --accent: #2f6feb;
  --danger: #c8342b;
  --unread: #eef3fe;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --panel: #1b1f26;
    --border: #2b313b;
    --text: #e8eaee;
    --muted: #98a1af;
    --accent: #6b9bff;
    --danger: #f0776c;
    --unread: #1f2733;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); }
a { color: var(--accent); }

button {
  font: inherit;
  /* Labels like "Delete for good" must never break mid-phrase; the toolbar
     wraps as a whole instead. */
  white-space: nowrap;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); }

input, textarea {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg);
  color: var(--text);
}
textarea { resize: vertical; }

/* ------------------------------------------------------------------ sign-in */

.auth { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.card {
  width: min(420px, 100%);
  padding: 28px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
}
.card h1 { margin: 0 0 6px; font-size: 22px; }
.tabs { display: flex; gap: 8px; margin: 18px 0 16px; }
.tab { flex: 1; }
.tab.active { border-color: var(--accent); color: var(--accent); }
.auth-form { display: grid; gap: 12px; }
.auth-form label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }

/* --------------------------------------------------------------------- app */

.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.topbar nav { display: flex; flex-wrap: wrap; gap: 6px; }
.brand { display: inline-flex; align-items: center; gap: 7px; }
.brand svg { width: 17px; height: 17px; flex: none; }
.topbar .spacer { flex: 1; }
.topbar #search { width: min(240px, 40vw); }
.folder.active { border-color: var(--accent); color: var(--accent); }
.badge {
  display: inline-block;
  min-width: 20px;
  padding: 0 6px;
  border-radius: 10px;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
}

main { flex: 1; display: grid; grid-template-columns: minmax(280px, 380px) 1fr; min-height: 0; }

.list { display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--panel); min-height: 0; }
.list-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
}
.check { display: flex; gap: 6px; align-items: center; font-size: 13px; color: var(--muted); }
.check input { width: auto; }

#messages { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
#messages li { display: flex; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--border); cursor: pointer; }
#messages li:hover { background: var(--bg); }
#messages li.unread { background: var(--unread); }
#messages li.active { box-shadow: inset 3px 0 0 var(--accent); }
#messages li.trashed .msg-subject { text-decoration: line-through; opacity: 0.75; }
#messages input[type=checkbox] { width: auto; margin-top: 4px; }
.msg-main { min-width: 0; flex: 1; }
.msg-line { display: flex; justify-content: space-between; gap: 10px; }
.msg-from { font-weight: 600; font-size: 13px; }
.msg-date { font-size: 12px; color: var(--muted); white-space: nowrap; }
.msg-subject { font-size: 14px; }
.msg-snippet, .msg-id { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pager { display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-top: 1px solid var(--border); }
.pager span { flex: 1; text-align: center; font-size: 12px; }

.reader { padding: 22px; overflow-y: auto; min-height: 0; }
.reader .empty { display: grid; place-items: center; height: 100%; }
.reader h2 { margin: 0 0 6px; font-size: 20px; }
.reader .meta { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.reader .body { margin-top: 18px; white-space: pre-wrap; word-wrap: break-word; }
.reader .actions { display: flex; gap: 8px; margin-top: 14px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  padding: 10px 16px;
  border-radius: 8px;
  background: var(--text);
  color: var(--bg);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}

dialog {
  width: min(560px, 92vw);
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
dialog h2 { margin: 0 0 14px; font-size: 18px; }
dialog form { display: grid; gap: 12px; }
dialog label { display: grid; gap: 5px; font-size: 13px; color: var(--muted); }
dialog menu { display: flex; justify-content: flex-end; gap: 8px; margin: 6px 0 0; padding: 0; }

@media (max-width: 760px) {
  main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .reader { border-top: 1px solid var(--border); max-height: 45vh; }
}

/* --------------------------------------------------------------- directory */

#directory-dialog { display: none; }
#directory-dialog[open] { display: flex; flex-direction: column; gap: 12px; }
#directory-dialog h2 { margin: 0; font-size: 18px; }
#directory-dialog p { margin: 0; font-size: 13px; }

.directory {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 46vh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 9px;
}
.directory li {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}
.directory li:last-child { border-bottom: 0; }
.directory li.muted { justify-content: center; }
.directory .who { flex: 1; min-width: 0; }
.directory .name { font-weight: 600; font-variant-numeric: tabular-nums; }
.directory .desc { font-size: 13px; margin-top: 3px; }
#directory-dialog .pager { border: 0; padding: 0; }

/* ------------------------------------------------------- assigned-login bar */

.notice {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
  padding: 10px 14px;
  background: var(--unread);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.notice strong { font-size: 15px; font-variant-numeric: tabular-nums; }
.notice .muted { font-size: 13px; }
.notice button { margin-left: auto; padding: 2px 8px; }

.card code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.reader .metadata-label { margin-top: 18px; text-transform: uppercase; letter-spacing: 0.06em; font-size: 11px; }
.reader .metadata {
  margin: 4px 0 0;
  padding: 10px 12px;
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  font-size: 12.5px;
}
