/* ELARA Mail. Light and dark follow the device. */
:root {
  color-scheme: light dark;
  --bg: #f6f4fb;
  --card: #fff;
  --ink: #241d36;
  --soft: #5f587a;
  --line: #e2ddef;
  --accent: #5b3fd1;
  --accent-ink: #fff;
  --hover: #efeafc;
  --ok-bg: #e6f6ec;
  --ok: #1f6b3a;
  --bad-bg: #fdecec;
  --bad: #9b1c1c;
  --unread: #5b3fd1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15121e;
    --card: #1e1a2a;
    --ink: #ece8f6;
    --soft: #a9a2c2;
    --line: #322c45;
    --accent: #9d86ff;
    --accent-ink: #15121e;
    --hover: #2a2440;
    --ok-bg: #173323;
    --ok: #8fdcaa;
    --bad-bg: #3a1a1a;
    --bad: #ffb3b3;
    --unread: #b6a5ff;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--bg);
}
a { color: var(--accent); }
h1 { font-size: 1.45rem; margin: 0 0 0.8rem; line-height: 1.25; overflow-wrap: anywhere; }
h2 { font-size: 1.1rem; margin: 1.2rem 0 0.5rem; }
h2:first-child { margin-top: 0; }

/* Top bar */
.bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1.2rem;
  padding: 0.6rem 16px; background: var(--card); border-bottom: 1px solid var(--line);
}
.bar .home { font-weight: 700; text-decoration: none; color: var(--ink); font-size: 1.05rem; }
.bar .mark { color: var(--accent); }
.bar nav { display: flex; gap: 1rem; }
.bar nav a { text-decoration: none; color: var(--soft); font-weight: 500; }
.bar nav a:hover { color: var(--accent); }
.bar .who { margin-left: auto; display: flex; align-items: center; gap: 0.8rem; color: var(--soft); font-size: 0.9rem; min-width: 0; }
.bar .who > span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar form { margin: 0; }

main { max-width: 1100px; margin: 0 auto; padding: 1.2rem 16px 3rem; }

/* Cards and forms */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1.2rem; margin-bottom: 1rem; }
.card.narrow { max-width: 26rem; margin: 3rem auto; }
label { display: block; font-weight: 600; margin: 0.8rem 0 0.25rem; font-size: 0.92rem; }
input, textarea, select {
  font: inherit; color: inherit; background: var(--bg); width: 100%;
  border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.65rem;
}
input[type="file"] { padding: 0.35rem; }
input[type="radio"] { width: auto; margin: 0 0.35rem 0 0; }
textarea { resize: vertical; min-height: 8rem; }
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
button, .button {
  font: inherit; font-weight: 600; cursor: pointer; display: inline-block; text-decoration: none;
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 8px; padding: 0.45rem 0.9rem; margin-top: 0.8rem;
}
button:hover, .button:hover { background: var(--hover); }
button.primary, .button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
button.primary:hover, .button.primary:hover { filter: brightness(1.08); }
button:disabled { opacity: 0.6; cursor: default; }
button.link { background: none; border: 0; padding: 0; margin: 0; color: var(--accent); font-weight: 500; }
button.link:hover { text-decoration: underline; background: none; }
.danger, button.link.danger { color: var(--bad); }
.stack > button { display: block; }
.actions { display: flex; gap: 1rem; align-items: center; flex-wrap: wrap; }
.help { color: var(--soft); font-size: 0.9rem; }
.note { padding: 0.55rem 0.8rem; border-radius: 8px; background: var(--hover); }
.note.ok { background: var(--ok-bg); color: var(--ok); }
.note.bad { background: var(--bad-bg); color: var(--bad); }
.empty { color: var(--soft); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.or { display: flex; align-items: center; gap: 0.6rem; color: var(--soft); margin: 1.2rem 0 0.2rem; }
.or::before, .or::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.passkey button { width: 100%; }
.again { margin-top: 1rem; color: var(--soft); }
.status { min-height: 1.4em; color: var(--soft); }
.tag { font-size: 0.75rem; padding: 0.05rem 0.45rem; border-radius: 99px; background: var(--hover); color: var(--accent); font-weight: 600; }

/* Mail list */
.mail { display: grid; grid-template-columns: 11rem 1fr; gap: 1.2rem; }
.folders .button { width: 100%; text-align: center; margin: 0 0 0.8rem; }
.folders ul { list-style: none; margin: 0; padding: 0; }
.folders a { display: block; padding: 0.4rem 0.7rem; border-radius: 8px; text-decoration: none; color: var(--ink); }
.folders a:hover { background: var(--hover); }
.folders a[aria-current] { background: var(--hover); color: var(--accent); font-weight: 700; }
.search { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.search button { margin: 0; }
.threads { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.thread + .thread { border-top: 1px solid var(--line); }
.thread a {
  display: grid; grid-template-columns: 12rem 1fr auto; gap: 1rem; align-items: baseline;
  padding: 0.7rem 1rem; text-decoration: none; color: var(--ink);
}
.thread a:hover { background: var(--hover); }
.thread .from, .thread .subject { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .when { color: var(--soft); font-size: 0.85rem; white-space: nowrap; }
.thread.unread .from, .thread.unread .subject { font-weight: 700; }
.thread.unread a { box-shadow: inset 3px 0 0 var(--unread); }
.count { font-size: 0.75rem; color: var(--soft); border: 1px solid var(--line); border-radius: 99px; padding: 0 0.4rem; margin-left: 0.4rem; font-weight: 500; }
.clip { margin-left: 0.3rem; }
.pager { display: flex; justify-content: space-between; }

/* A conversation */
.conversation { max-width: 52rem; margin: 0 auto; }
.crumbs { margin: 0 0 0.5rem; }
.tools { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.tools form { margin: 0; }
.tools button, .tools .button { margin: 0; font-weight: 500; }
.message { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; margin-bottom: 0.8rem; }
.message.outbound { border-left: 3px solid var(--accent); }
.message header { display: flex; flex-wrap: wrap; gap: 0.2rem 1rem; margin-bottom: 0.7rem; }
.message .from { font-weight: 700; }
.message .when { color: var(--soft); font-size: 0.85rem; margin-left: auto; }
.message .to { flex-basis: 100%; color: var(--soft); font-size: 0.85rem; overflow-wrap: anywhere; }
iframe.body { display: block; width: 100%; height: 22rem; border: 0; border-radius: 6px; background: #fff; }
pre.plain { white-space: pre-wrap; overflow-wrap: anywhere; font: inherit; margin: 0; }
.files { list-style: none; padding: 0; margin: 0.8rem 0 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.files li { border: 1px solid var(--line); border-radius: 8px; padding: 0.3rem 0.6rem; font-size: 0.9rem; }
.files .size { color: var(--soft); }
.respond details > summary { list-style: none; display: inline-block; margin: 0.4rem 0 0; }
.respond details > summary::-webkit-details-marker { display: none; }
.respond details[open] > summary { display: none; }
.respond form { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; }
.modes { border: 0; padding: 0; margin: 0; display: flex; gap: 1.2rem; flex-wrap: wrap; }
.modes legend { font-weight: 600; font-size: 0.92rem; margin-bottom: 0.3rem; }
.modes label { display: flex; align-items: center; margin: 0; font-weight: 500; }
.compose details summary { cursor: pointer; color: var(--accent); margin-top: 0.6rem; }
.compose .from { margin: 0; color: var(--soft); }

/* Settings and admin */
.keys { list-style: none; padding: 0; }
.keys li { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: 0.6rem 0; border-bottom: 1px solid var(--line); }
.keys .when { display: block; color: var(--soft); font-size: 0.85rem; }
.keys form { margin: 0; }
.people { width: 100%; border-collapse: collapse; }
.people th { text-align: left; font-size: 0.85rem; color: var(--soft); font-weight: 600; padding: 0.4rem 0.5rem; border-bottom: 1px solid var(--line); }
.people td { padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--line); vertical-align: middle; overflow-wrap: anywhere; }
.people form.inline { display: flex; gap: 0.5rem; align-items: center; margin: 0; }
.people form.inline button { margin: 0; }
.people td.actions { display: table-cell; text-align: right; white-space: nowrap; }
.people .actions form { margin: 0 0 0 0.8rem; display: inline-block; }
.people button { white-space: nowrap; }
.check { display: flex; align-items: center; gap: 0.4rem; font-weight: normal; }
.check input { width: auto; margin: 0; }
.fwd summary { cursor: pointer; color: var(--soft); }
.fwd summary strong { color: var(--text); font-weight: 600; }
.fwd form { margin-top: 0.5rem; width: min(22rem, 100%); }
.addr { display: flex; align-items: center; gap: 0.3rem; }
.addr input { min-width: 6rem; }
.addr span { color: var(--soft); white-space: nowrap; }

@media (max-width: 760px) {
  .mail { grid-template-columns: 1fr; }
  .folders ul { display: flex; flex-wrap: wrap; gap: 0.3rem; }
  .thread a { grid-template-columns: 1fr auto; grid-template-areas: "from when" "subject subject"; gap: 0.1rem 0.8rem; }
  .thread .from { grid-area: from; }
  .thread .when { grid-area: when; }
  .thread .subject { grid-area: subject; }
  .people thead { display: none; }
  .people tr { display: block; border-bottom: 1px solid var(--line); padding: 0.5rem 0; }
  .people td { display: block; border: 0; padding: 0.25rem 0; }
  .people td.actions { display: block; text-align: left; }
  .people .actions form { margin: 0 0.8rem 0 0; }
  .bar .who { margin-left: 0; width: 100%; }
}

/* Live updates */
.live-state { color: var(--ok); font-size: 0.8rem; margin: 0.8rem 0.7rem 0; }
