:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1d2330;
  --muted: #667085;
  --line: #e3e6eb;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --ok-bg: #e8f6ee;
  --ok-text: #14632f;
  --err-bg: #fdecec;
  --err-text: #9b1c1c;
  --warn: #b45309;
  --hover: #f0f4ff;
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b;
    --surface: #1b2029;
    --text: #e6e9ef;
    --muted: #9aa3b2;
    --line: #2c3340;
    --accent: #6b9bff;
    --accent-text: #0d1117;
    --ok-bg: #133222;
    --ok-text: #8fe0ad;
    --err-bg: #3a1717;
    --err-text: #ffb4b4;
    --warn: #f0b35a;
    --hover: #222a38;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.55 -apple-system, "Segoe UI", "Noto Sans Thai", "Sarabun", "Leelawadee UI", Tahoma, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.35rem; margin: 0 0 .75rem; }
h2 { font-size: 1.05rem; margin: 1.25rem 0 .5rem; }
h1 small, h2 small { color: var(--muted); font-weight: normal; font-size: .85rem; margin-left: .35rem; }
code { background: var(--hover); padding: 0 .3em; border-radius: 4px; }

/* top bar */
.top {
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem;
  padding: .6rem 16px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); font-size: 1.05rem; }
.brand span { color: var(--muted); font-weight: normal; font-size: .85rem; margin-left: .4rem; }
.top nav { display: flex; flex-wrap: wrap; gap: .25rem; flex: 1; }
.top nav a, .who > a { padding: .3rem .6rem; border-radius: 6px; color: var(--text); white-space: nowrap; }
.top nav a.on, .who > a.on { background: var(--hover); color: var(--accent); }
.who { display: flex; align-items: center; gap: .5rem; }
.who small { color: var(--muted); }
.who form { margin: 0; }

main { max-width: 1100px; margin: 0 auto; padding: 1.25rem 16px 3rem; }
main.narrow { max-width: 420px; padding-top: 12vh; }

/* forms */
input, select, button, textarea { font: inherit; color: inherit; }
input[type=text], input:not([type]), input[type=password], input[type=search], select {
  width: 100%; padding: .45rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button {
  padding: .45rem .9rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); cursor: pointer;
}
button:hover { background: var(--hover); }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.primary:hover { filter: brightness(1.08); }
.linkbtn { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; }
.linkbtn:hover { background: none; text-decoration: underline; }
.linkbtn.small { font-size: .8rem; margin-left: .3rem; }
label { display: block; font-size: .9rem; color: var(--muted); }
label > input, label > select, label > .addr-input { margin-top: .25rem; color: var(--text); }
label.check { display: inline-flex; align-items: center; gap: .35rem; color: var(--text); white-space: nowrap; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.form-grid { display: grid; gap: .75rem; margin-bottom: 1.25rem; max-width: 560px; }
.form-grid h2 { margin: 0; }
.addr-input { display: flex; align-items: center; gap: .35rem; }
.addr-input input { flex: 1.2; }
.addr-input select { flex: 1; width: auto; }
.login h1 { text-align: center; }
.login form { display: grid; gap: .8rem; }

.hint { color: var(--muted); font-size: .88rem; margin: .25rem 0 1rem; }
.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 2rem 0; text-align: center; }
.flash { padding: .6rem .9rem; border-radius: 8px; margin-bottom: 1rem; }
.flash.ok { background: var(--ok-bg); color: var(--ok-text); }
.flash.err { background: var(--err-bg); color: var(--err-text); }
.warn { color: var(--warn); }
.nowrap { white-space: nowrap; }
.num { text-align: right; }

/* inbox */
.bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; margin-bottom: 1rem; }
.bar h1 { margin: 0; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; }
.filters select { width: auto; max-width: 280px; }
.filters input { width: 240px; }
.mlist { list-style: none; margin: 0; padding: 0; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.mlist li + li { border-top: 1px solid var(--line); }
.mlist a { display: block; padding: .65rem .9rem; color: var(--text); }
.mlist a:hover { background: var(--hover); text-decoration: none; }
.mlist .l1 { display: flex; justify-content: space-between; gap: 1rem; }
.mlist .from { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mlist time { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.mlist .l2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mlist .l3 { color: var(--muted); font-size: .82rem; }
.tag { display: inline-block; font-size: .75rem; padding: 0 .45rem; border-radius: 999px; background: var(--hover); color: var(--muted); }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; color: var(--muted); }

/* message */
.back { margin: 0 0 .5rem; }
.subject { word-break: break-word; }
.meta { display: grid; grid-template-columns: max-content 1fr; gap: .2rem 1rem; margin: 0 0 1rem; font-size: .92rem; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; word-break: break-word; }
.atts { list-style: none; padding: 0; margin: 0 0 1rem; display: grid; gap: .4rem; }
.atts li { display: flex; flex-wrap: wrap; align-items: baseline; gap: .25rem .75rem; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: .5rem .75rem; }
.atts .fn { font-weight: 600; word-break: break-all; }
.atts small { color: var(--muted); }
.atts .acts { margin-left: auto; display: flex; gap: .75rem; }
.tabs { display: flex; flex-wrap: wrap; gap: .25rem; border-bottom: 1px solid var(--line); margin: 1.25rem 0 .75rem; }
.tabs a { padding: .4rem .75rem; border-radius: 8px 8px 0 0; color: var(--muted); }
.tabs a.on { color: var(--accent); border: 1px solid var(--line); border-bottom-color: var(--bg); margin-bottom: -1px; background: var(--bg); }
.tabs a.right { margin-left: auto; }
.mailhtml { width: 100%; height: 75vh; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
pre.body { white-space: pre-wrap; word-break: break-word; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 1rem; font: inherit; margin: 0; }

/* tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.grid { width: 100%; border-collapse: collapse; font-size: .92rem; }
.grid th, .grid td { padding: .5rem .6rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
.grid th { color: var(--muted); font-weight: 600; font-size: .82rem; white-space: nowrap; }
.grid tr:last-child td { border-bottom: 0; }
.grid tr.off td { color: var(--muted); }
.grid td input:not([type=checkbox]), .grid td select { min-width: 140px; }
.row-form { display: grid; gap: .3rem; margin: 0; }

@media (max-width: 640px) {
  .top nav { order: 3; flex-basis: 100%; overflow-x: auto; flex-wrap: nowrap; }
  .who { margin-left: auto; }
  .filters, .filters select, .filters input { width: 100%; max-width: none; }
  .meta { grid-template-columns: 1fr; }
  .meta dd { margin-bottom: .35rem; }
  .atts .acts { margin-left: 0; }
  .tabs a.right { margin-left: 0; }
}
