/* One stylesheet, no framework. The whole front end is a few forms and a few
   tables; a component library would be more code than the thing it dresses. */

:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #d8dce3;
  --text: #1b1f24;
  --muted: #5c6672;
  --accent: #1a6dd4;
  --accent-text: #ffffff;
  --danger: #b3261e;
  --ok: #1c7a44;
  --warn: #8a5a00;
  --radius: 6px;
  --gap: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171a;
    --surface: #1c2024;
    --border: #333a42;
    --text: #e6e9ed;
    --muted: #9aa4b0;
    --accent: #4d9bf0;
    --accent-text: #0b0e11;
    --danger: #f2857c;
    --ok: #6fd39b;
    --warn: #e0b25c;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.6 system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;
}

a {
  color: var(--accent);
}

/* ------------------------------------------------------------- layout --- */

.shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: var(--gap);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sidebar h1 {
  font-size: 15px;
  margin: 0 0 4px;
}

.sidebar .who {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: var(--gap);
  word-break: break-all;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 10px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
}

/* The dead letter count rides on the 队列 link. It is empty most of the time,
   and an empty slot must not push the label around -- an inbox that twitches
   is one people learn to stop reading. */
.sidebar nav a .tag-slot:empty {
  display: none;
}

.sidebar nav a:hover {
  background: var(--bg);
}

.sidebar nav a[aria-current="page"] {
  background: var(--accent);
  color: var(--accent-text);
}

.sidebar .spacer {
  flex: 1;
}

main {
  padding: 24px;
  max-width: 1100px;
}

main h2 {
  margin-top: 0;
  font-size: 20px;
}

.loading {
  padding: 48px;
  color: var(--muted);
}

/* -------------------------------------------------------------- cards --- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--gap);
  margin-bottom: var(--gap);
}

.card > h3 {
  margin: 0 0 12px;
  font-size: 15px;
}

.hint {
  color: var(--muted);
  font-size: 13px;
  margin: 4px 0 12px;
}

/* -------------------------------------------------------------- forms --- */

form.stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 520px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

input,
select,
textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 9px;
  width: 100%;
}

textarea {
  min-height: 88px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------ buttons --- */

button {
  font: inherit;
  padding: 7px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button:hover:not(:disabled) {
  border-color: var(--accent);
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

button.danger {
  color: var(--danger);
  border-color: var(--danger);
}

/* ------------------------------------------------------------- tables --- */

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: none;
}

.empty {
  color: var(--muted);
  padding: 16px 0;
}

/* -------------------------------------------------------- annotations --- */

.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}

.badge.ok {
  color: var(--ok);
  border-color: var(--ok);
}

.badge.bad {
  color: var(--danger);
  border-color: var(--danger);
}

.badge.warn {
  color: var(--warn);
  border-color: var(--warn);
}

.notice {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: var(--gap);
  background: var(--surface);
}

.notice.error {
  border-left-color: var(--danger);
  color: var(--danger);
}

/* A finding reads as an error because it is one, but it is the page working
   rather than the page failing. The heavier rule is the only difference: it is
   a statement about the system, not about this request. See ui.finding. */
.notice.finding {
  border-left-width: 4px;
}

.notice.ok {
  border-left-color: var(--ok);
}

/* Not an error and not nothing: something that wants a person to look, like a
   month whose payments were mostly rescued by the sweep. */
.notice.warn {
  border-left-color: var(--warn);
}

/* --------------------------------------------------------------- login --- */

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login .card {
  width: 340px;
  margin: 0;
}

.mono {
  font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  word-break: break-all;
}

/* --------------------------------------------------------------- scope --- */

/* Which account a per-account screen is showing. Above the cards rather than
   inside one, because it applies to all of them. */
.scope {
  margin-bottom: var(--gap);
}

.scope label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.scope select {
  width: auto;
  min-width: 280px;
}

/* ------------------------------------------------------------ previews --- */

/* Bounded so that one oversized upload cannot set the height of every row in
   the table. Media loads at whatever size WeChat stored it at. */
.preview {
  min-width: 88px;
}

.preview img,
.preview video {
  max-width: 88px;
  max-height: 88px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
}

.preview audio {
  max-width: 220px;
  height: 32px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: block;
}

.qr {
  width: 72px;
  height: 72px;
  display: block;
}

/* -------------------------------------------------------------- lists --- */

.pager {
  margin-top: 12px;
  align-items: center;
}

/* A row of buttons standing in for tabs. Buttons rather than links because
   these switch what a card is showing, not where the page is. */
.tabs {
  gap: 4px;
  align-items: center;
}

/* Whatever the last failure said, in a cell that will not let a stack trace
   push every other column off the screen. */
td.err {
  max-width: 22rem;
  font-size: 12px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* -------------------------------------------------------------- audit --- */

/* The filter row above the trail. Wider gaps than a plain .row because these
   are four separate questions, not one control split into parts. */
.filters {
  gap: 16px;
  margin-bottom: 12px;
}

/* What a record carries beyond its five fixed columns: the path parameters and
   whatever the handler named. One pair per line rather than a comma-joined
   string, because the interesting one is usually the last. */
.kv {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-width: 26rem;
  font-size: 12px;
}

.kv code {
  color: var(--muted);
}

/* A button that reads as a link. Used where the affordance is "this word does
   something" rather than "here is a control": an openid that starts a reply, a
   remark that becomes editable. */
button.linkish {
  border: none;
  background: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
}

/* --------------------------------------------------------------- menu --- */

/* The menu editor nests one level and no more, which is also WeChat's limit,
   so the indentation can be a constant rather than a variable. */
.menu-tree {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.menu-top {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.menu-sub-wrap {
  padding-left: 16px;
  border-left: 2px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

.menu-subs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.menu-sub {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.menu-fields {
  flex: 1;
  align-items: center;
}

.menu-fields input,
.menu-fields select {
  width: auto;
  min-width: 140px;
  flex: 1;
}

.menu-preview {
  margin: 0;
  padding-left: 20px;
}

.menu-preview ul {
  padding-left: 20px;
}

/* ------------------------------------------------------------ replies --- */

.keyword input {
  flex: 1;
}

.keyword select,
.content select {
  width: auto;
}

.content {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
}

/* ------------------------------------------------------------- orders --- */

/* The refund form appears inside a table cell, so it needs a width of its own
   rather than the column's. */
.refund-form {
  min-width: 260px;
  margin-top: 8px;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 12px;
}

/* ---------------------------------------------------------- reconcile --- */

.totals {
  gap: 32px;
  margin-bottom: var(--gap);
}

.total {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.total strong {
  font-size: 22px;
}

.total-label {
  color: var(--muted);
  font-size: 13px;
}

/* One day's differences expand under their row, so the detail keeps the date
   it belongs to next to it rather than in a dialogue that loses the context. */
tr.detail > td {
  background: var(--surface);
}
