/* rustmail — one stylesheet, no JavaScript anywhere.
   Design: "mail as ledger" — pine accent on a cool-neutral canvas,
   hairline structure, tabular-mono metadata. Light + dark. */

/* ============================== tokens ============================== */
:root {
  --paper: #eceeed;
  --surface: #ffffff;
  --surface-2: #f4f6f5;
  --ink: #17201c;
  --muted: #5f6a64;
  --faint: #8a938d;
  --line: #e2e5e3;
  --line-strong: #d2d7d4;
  --accent: #15795e;
  --accent-hover: #0f5f49;
  --accent-soft: #e2efe9;
  --accent-line: #bfd9cf;
  --amber: #b26a12;
  --danger: #b23a2f;
  --danger-soft: #f7e9e7;
  --focus: #15795e;

  --radius: 10px;
  --radius-sm: 7px;
  --shadow-sm: 0 1px 2px rgba(18, 32, 26, .06);
  --shadow: 0 4px 16px -6px rgba(18, 32, 26, .16), 0 1px 2px rgba(18, 32, 26, .05);

  --ui: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --h-topbar: 3.5rem;
  --w-sidebar: 236px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0f1411;
    --surface: #161c19;
    --surface-2: #1d2420;
    --ink: #e7ebe8;
    --muted: #98a29b;
    --faint: #6d786f;
    --line: #28302b;
    --line-strong: #333d36;
    --accent: #45c39d;
    --accent-hover: #5ed2ac;
    --accent-soft: #172620;
    --accent-line: #244034;
    --amber: #d29a4e;
    --danger: #e58d84;
    --danger-soft: #2d1e1c;
    --focus: #45c39d;
    --shadow-sm: none;
    --shadow: 0 8px 28px -10px rgba(0, 0, 0, .6);
  }
}

/* ============================== reset ============================== */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { height: 100%; }

body {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  font-family: var(--ui);
  font-size: 15px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

h1 { font-size: 1.25rem; font-weight: 650; letter-spacing: -.01em; margin: 0; }
h2 { font-size: 1.05rem; font-weight: 600; letter-spacing: -.01em; margin: 0 0 .5rem; }

.muted { color: var(--muted); }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

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

/* ============================== top bar ============================== */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  height: var(--h-topbar);
  padding: 0 1.1rem;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: -.02em;
  font-size: 1.06rem;
}
.brand:hover { text-decoration: none; color: var(--accent); }
.brand-mark { display: block; flex: none; border-radius: 8px; }
.brand-word { color: var(--ink); }

.topbar nav { display: flex; gap: .15rem; }
.topbar nav a {
  padding: .4rem .75rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-weight: 550;
  font-size: .93rem;
  transition: background .12s, color .12s;
}
.topbar nav a:hover { background: var(--surface-2); color: var(--ink); text-decoration: none; }
.topbar nav a.active { background: var(--accent-soft); color: var(--accent); }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .85rem; }
.whoami {
  font-family: var(--mono);
  font-size: .82rem;
  color: var(--muted);
  max-width: 15rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
@media (max-width: 560px) { .whoami { display: none; } }

/* ============================== layout ============================== */
main.page {
  flex: 1;
  width: 100%;
  max-width: 1360px;
  margin: 0 auto;
  padding: 1.4rem 1.5rem 2.5rem;
}
main.center {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.split {
  display: grid;
  grid-template-columns: var(--w-sidebar) minmax(0, 1fr);
  gap: 1.5rem;
  align-items: start;
}
@media (max-width: 760px) {
  .split { grid-template-columns: 1fr; gap: 1rem; }
}

/* ============================== cards ============================== */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 1.4rem 1.6rem;
}
.card.narrow { width: 100%; max-width: 400px; }
.card > h1 { margin-bottom: 1.1rem; }

/* ============================== sidebar ============================== */
.sidebar { position: sticky; top: calc(var(--h-topbar) + 1.4rem); }
.sidebar .btn-block { margin-bottom: 1.1rem; }

.folder-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 1px; }
.folder-list a {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .5rem;
  padding: .5rem .7rem;
  border-radius: var(--radius-sm);
  color: var(--ink);
  font-weight: 500;
  font-size: .94rem;
  overflow-wrap: anywhere;
  transition: background .12s, color .12s;
}
.folder-list a:hover { background: var(--surface-2); text-decoration: none; }
.folder-list li.active a { background: var(--accent-soft); color: var(--accent); font-weight: 650; }

.badge {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  color: var(--muted);
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  padding: .1rem .5rem;
  flex: none;
}
.folder-list li.active .badge { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .folder-list li.active .badge { color: var(--paper); } }

/* ============================== buttons ============================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink);
  font-family: inherit;
  font-size: .88rem;
  font-weight: 550;
  line-height: 1.2;
  padding: .46rem .85rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s, box-shadow .12s;
}
.btn:hover { background: var(--surface-2); border-color: var(--muted); text-decoration: none; color: var(--ink); }
.btn:active { transform: translateY(.5px); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}
@media (prefers-color-scheme: dark) { .btn-primary { color: var(--paper); } }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
@media (prefers-color-scheme: dark) { .btn-primary:hover { color: var(--paper); } }

.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); }
.btn-quiet:hover { background: var(--surface-2); color: var(--ink); border-color: transparent; }
.btn-quiet.btn-danger:hover { background: var(--danger-soft); color: var(--danger); }

.btn-block { display: flex; width: 100%; }

form.inline { display: inline; }

/* ============================== forms ============================== */
label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--muted);
  margin: 1rem 0 .35rem;
}
.card > form > label:first-of-type,
form > label:first-child { margin-top: 0; }

input[type="text"], input[type="email"], input[type="password"],
input[type="search"], textarea, select {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: .55rem .7rem;
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
input[type="file"] {
  width: 100%;
  font-size: .88rem;
  color: var(--muted);
  padding: .5rem 0;
}
input[type="file"]::file-selector-button {
  font: inherit;
  font-size: .85rem;
  margin-right: .75rem;
  padding: .4rem .8rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}
textarea { resize: vertical; min-height: 15rem; line-height: 1.6; }

.form-actions { margin-top: 1.4rem; display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }

.form-error, .notice {
  display: flex;
  gap: .5rem;
  align-items: baseline;
  border-radius: var(--radius-sm);
  padding: .65rem .85rem;
  margin-bottom: 1.1rem;
  font-size: .9rem;
  border: 1px solid;
}
.form-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 35%, transparent);
}
.notice {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-line);
}
.notice a { font-weight: 600; }

/* ============================== toolbars ============================== */
.toolbar {
  display: flex;
  align-items: center;
  gap: .55rem;
  flex-wrap: wrap;
  margin-bottom: 1.1rem;
}
.toolbar h1 { margin-right: .35rem; }
.toolbar .spacer, .toolbar .searchbox + .spacer { flex: 1; }
/* inline controls in a toolbar size to content, not full width */
.toolbar select { width: auto; min-width: 9rem; }
.toolbar form.inline { display: flex; gap: .4rem; }

.searchbox { display: flex; gap: .4rem; }
.searchbox input { width: 15rem; max-width: 46vw; }

.count {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: .12rem .5rem;
  border-radius: 999px;
  vertical-align: middle;
}

/* ============================== message list ============================== */
.msg-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.msg-table th, .msg-table td {
  text-align: left;
  padding: .62rem .8rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
.msg-table thead th {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--faint);
  padding-top: .7rem;
  padding-bottom: .7rem;
  background: var(--surface-2);
}
.msg-table tbody tr { transition: background .1s; }
.msg-table tbody tr:hover { background: var(--surface-2); }
.msg-table tbody tr:last-child td { border-bottom: none; }

.msg-table .col-dot { width: 2rem; position: relative; }
.msg-table .col-from { width: 22%; }
.msg-table .col-date { width: 8.5rem; white-space: nowrap; }
.msg-table .col-size { width: 5rem; white-space: nowrap; text-align: right; }
.msg-table .col-x { width: 2.6rem; text-align: right; }

.col-date, .col-size {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
  font-size: .82rem;
  color: var(--muted);
}
.from-cell { color: var(--muted); overflow-wrap: anywhere; }
.subject-link { color: var(--ink); display: block; overflow-wrap: anywhere; }
.subject-link:hover { color: var(--ink); }

tr.unread .from-cell { color: var(--ink); font-weight: 600; }
tr.unread .subject-link { font-weight: 650; }
tr.unread .col-dot::before {
  content: "";
  position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--accent);
}

.dot {
  display: inline-block;
  width: .5rem; height: .5rem;
  border-radius: 50%;
  background: var(--accent);
  vertical-align: middle;
}
.flag-star { color: var(--amber); }
.clip { color: var(--faint); font-size: .9em; }
.subject-link .muted { font-weight: 400; }

/* hover-revealed delete on pointer devices */
@media (hover: hover) {
  .msg-table .col-x .btn { opacity: 0; transition: opacity .12s; }
  .msg-table tr:hover .col-x .btn,
  .msg-table .col-x .btn:focus-visible { opacity: 1; }
}

.empty-state {
  padding: 3.5rem 1rem;
  text-align: center;
  color: var(--muted);
}
.empty-state strong { display: block; color: var(--ink); font-size: 1.02rem; margin-bottom: .3rem; }

/* ============================== pager ============================== */
.pager {
  display: flex;
  gap: 1rem;
  align-items: center;
  justify-content: center;
  margin-top: 1.1rem;
  font-family: var(--mono);
  font-size: .82rem;
  color: var(--muted);
}
.pager a { padding: .3rem .6rem; border-radius: var(--radius-sm); }
.pager a:hover { background: var(--surface-2); text-decoration: none; }

/* ============================== message view ============================== */
.msg-head { border-bottom: 1px solid var(--line); padding-bottom: 1rem; margin-bottom: 1.25rem; }
.msg-head h1 { margin-bottom: .85rem; line-height: 1.3; }
.msg-meta {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: .2rem .9rem;
  margin: 0;
  font-size: .9rem;
}
.msg-meta dt {
  font-size: .72rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  font-weight: 600;
  color: var(--faint);
  padding-top: .12rem;
}
.msg-meta dd {
  margin: 0;
  font-family: var(--mono);
  font-size: .84rem;
  color: var(--ink);
  overflow-wrap: anywhere;
}

.msg-body { overflow-x: auto; line-height: 1.65; }
.msg-body pre {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--ui);
  font-size: .96rem;
  margin: 0;
}
.msg-html { max-width: 68ch; }
.msg-html img { max-width: 100%; height: auto; }
.msg-html table { max-width: 100%; }
.msg-html a { text-decoration: underline; }
.msg-html blockquote {
  border-left: 2px solid var(--accent-line);
  margin-left: 0;
  padding-left: 1rem;
  color: var(--muted);
}

.attachments { margin-top: 1.5rem; border-top: 1px solid var(--line); padding-top: 1rem; }
.attachments strong { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); }
.attachments ul { list-style: none; padding: 0; margin: .6rem 0 0; display: flex; flex-wrap: wrap; gap: .5rem; }
.attachments a {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  padding: .4rem .75rem;
  font-size: .88rem;
  color: var(--ink);
}
.attachments a:hover { border-color: var(--accent); text-decoration: none; }
.attachments li { color: var(--muted); font-size: .9rem; }

/* ============================== contacts ============================== */
.contact-table {
  width: 100%;
  border-collapse: collapse;
}
.contact-table th, .contact-table td {
  text-align: left;
  padding: .6rem .75rem;
  border-bottom: 1px solid var(--line);
}
.contact-table tbody tr:last-child td { border-bottom: none; }
.contact-table tbody tr:hover { background: var(--surface-2); }
.contact-table thead th {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--faint); font-weight: 600;
}
.contact-table td:nth-child(2) a { font-family: var(--mono); font-size: .86rem; }
.contact-table td.actions { text-align: right; white-space: nowrap; }
.contact-table td.actions form { display: inline; }

/* ============================== auth / error ============================== */
.status-code {
  font-family: var(--mono);
  font-size: 2.6rem;
  font-weight: 700;
  color: var(--accent);
  margin: 0 0 .25rem;
  letter-spacing: -.02em;
}

.login-card { padding: 2rem 2rem 1.75rem; }
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
  margin-bottom: 1.6rem;
}
.login-brand .brand-word { font-size: 1.5rem; font-weight: 700; letter-spacing: -.02em; }
.login-tagline { font-size: .88rem; color: var(--muted); text-align: center; margin: -.3rem 0 0; }
.login-server {
  text-align: center;
  font-family: var(--mono);
  font-size: .78rem;
  color: var(--faint);
  margin: 1.25rem 0 0;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}

/* ============================== responsive ============================== */
@media (max-width: 760px) {
  main.page { padding: 1rem 1rem 2rem; }
  .sidebar { position: static; }
  .msg-table .col-size { display: none; }
}
@media (max-width: 520px) {
  .msg-table .col-from { display: none; }
  .msg-table .col-date { width: auto; }
}
