:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f8f9f6;
  --line: #e2e4de;
  --text: #1c1f1a;
  --muted: #6b7066;
  --accent: #0f6b5c;
  --accent-ink: #ffffff;
  --accent-soft: #e3f0ec;
  --bubble-in: #ffffff;
  --bubble-out: #dcefe8;
  --ok: #1d7a47; --ok-bg: #e2f3e8;
  --warn: #8a5a00; --warn-bg: #fbf0d6;
  --bad: #a3271f; --bad-bg: #fbe4e1;
  --chat-bg: #eceee8;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 24, 18, .06), 0 2px 8px rgba(20, 24, 18, .04);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121412; --surface: #1a1d1a; --surface-2: #202420; --line: #2c312c;
    --text: #e6e9e3; --muted: #9aa196; --accent: #3fb59b; --accent-ink: #0c1411; --accent-soft: #1d332d;
    --bubble-in: #232723; --bubble-out: #1d3a32; --chat-bg: #161916;
    --ok: #6fd39a; --ok-bg: #18301f; --warn: #e8c06a; --warn-bg: #33290f; --bad: #f08a80; --bad-bg: #3a1b18;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.4rem; margin: 0 0 .25rem; }
h2 { font-size: 1rem; margin: 1.2rem 0 .6rem; }
h2:first-child { margin-top: 0; }
small, .small { font-size: .82rem; }
.muted { color: var(--muted); }
code { font: .85em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }

/* top bar */
.top {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: .55rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { font-weight: 700; color: var(--text); letter-spacing: -.01em; }
.brand span { color: var(--accent); }
.brand.big { font-size: 1.5rem; text-align: center; margin-bottom: .5rem; }
.switcher select { max-width: 14rem; }
.project-name { font-weight: 600; }
nav.main { display: flex; gap: .2rem; flex-wrap: wrap; }
nav.main a, .me a { color: var(--muted); padding: .35rem .6rem; border-radius: 6px; }
nav.main a.on, .me a.on { background: var(--accent-soft); color: var(--accent); }
nav.main a:hover, .me a:hover { text-decoration: none; color: var(--text); }
.me { margin-left: auto; display: flex; align-items: center; gap: .3rem; }
.me form { margin: 0; }

main { max-width: 1100px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
main.wide { max-width: none; padding: 0; }
.head { margin-bottom: 1rem; }
.head p { margin: 0; }

/* forms & buttons */
label { display: block; margin-bottom: .8rem; font-size: .9rem; font-weight: 500; }
label small { font-weight: 400; color: var(--muted); }
label.check { display: flex; gap: .5rem; align-items: flex-start; font-weight: 400; }
label.check input { margin-top: .2rem; }
input, select, button, .btn {
  font: inherit; color: inherit; border-radius: 8px; border: 1px solid var(--line);
  background: var(--surface); padding: .5rem .7rem;
}
label input, label select { display: block; width: 100%; margin-top: .3rem; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button, .btn { cursor: pointer; background: var(--surface-2); display: inline-block; font-size: .88rem; padding: .42rem .75rem; }
button:hover, .btn:hover { border-color: var(--muted); text-decoration: none; }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button.link { background: none; border: 0; color: var(--muted); padding: .35rem .5rem; }
.inline-form { display: flex; gap: .5rem; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 9rem; }
.row-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.row-actions form, .actions form { margin: 0; display: inline; }
.actions { white-space: nowrap; }
.row-actions.inline { display: inline-flex; gap: .3rem; margin-left: .4rem; vertical-align: middle; }
button.small { font-size: .78rem; padding: .2rem .5rem; }
.actions > * { margin: .1rem 0; }

/* cards & tables */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card.narrow { max-width: 460px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin-top: 1rem; align-items: start; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .65rem .8rem; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
table.compact td { padding: .4rem .7rem; font-size: .85rem; }
ul.plain { list-style: none; padding: 0; margin: 0 0 1rem; }
ul.plain li { padding: .35rem 0; border-bottom: 1px solid var(--line); }
ul.log { list-style: none; padding: 0; margin: 0; font-size: .82rem; max-height: 22rem; overflow: auto; }
ul.log li { padding: .3rem 0; border-bottom: 1px solid var(--line); }
dl.kv { display: grid; grid-template-columns: auto 1fr; gap: .4rem 1rem; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }
code.secret { font-size: 1.15rem; padding: .3rem .6rem; letter-spacing: .05em; user-select: all; }

.badge { display: inline-block; font-size: .74rem; font-weight: 600; padding: .12rem .5rem; border-radius: 99px; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.alert { padding: .6rem .85rem; border-radius: 8px; margin: 0 0 1rem; }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.alert.bad { background: var(--bad-bg); color: var(--bad); }

/* login */
body.center { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login { width: 100%; max-width: 360px; }
.login button { width: 100%; padding: .6rem; }

/* QR */
.qr-card h1 { text-align: center; }
.steps { color: var(--muted); font-size: .9rem; padding-left: 1.2rem; }
.qr { display: grid; place-items: center; min-height: 270px; background: #fff; border-radius: 8px; padding: .5rem; color: #333; }
.qr svg { width: 264px; height: 264px; }
.small-qr { min-height: 0; width: 216px; }
.small-qr svg { width: 200px; height: 200px; }
.center-text { text-align: center; }
.ok-big { font-size: 1.4rem; color: #1d7a47; font-weight: 700; }

/* inbox */
.inbox { display: grid; grid-template-columns: 340px 1fr; height: calc(100vh - 53px); }
.list { border-right: 1px solid var(--line); background: var(--surface); display: flex; flex-direction: column; min-height: 0; }
.filters { display: flex; gap: .4rem; padding: .6rem; border-bottom: 1px solid var(--line); }
.filters input { flex: 1; min-width: 0; }
.filters select { max-width: 45%; }
.chats { overflow-y: auto; flex: 1; }
.chat { display: block; padding: .6rem .8rem; border-bottom: 1px solid var(--line); color: var(--text); }
.chat:hover { background: var(--surface-2); text-decoration: none; }
.chat.on { background: var(--accent-soft); }
.chat .row { display: flex; justify-content: space-between; gap: .5rem; align-items: baseline; }
.chat strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat time { font-size: .75rem; color: var(--muted); flex-shrink: 0; }
.chat .sub { font-size: .85rem; color: var(--muted); }
.chat .preview { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat .tiny { font-size: .74rem; color: var(--muted); margin-top: .1rem; }
.tag { background: var(--surface-2); border: 1px solid var(--line); border-radius: 4px; padding: 0 .35rem; }
.empty { padding: 1.5rem 1rem; color: var(--muted); text-align: center; }
.more { display: block; text-align: center; padding: .7rem; font-size: .88rem; }

.pane { display: flex; flex-direction: column; min-height: 0; background: var(--chat-bg); }
.empty-pane { display: grid; place-items: center; height: 100%; color: var(--muted); }
.chat-head { display: flex; align-items: center; gap: .8rem; padding: .65rem 1rem; background: var(--surface); border-bottom: 1px solid var(--line); }
.chat-head .badge { margin-left: auto; }
.back { display: none; font-size: 1.3rem; color: var(--text); }
.messages { flex: 1; overflow-y: auto; padding: 1rem clamp(.75rem, 4vw, 3rem); display: flex; flex-direction: column; gap: .3rem; }
.day { text-align: center; margin: .8rem 0 .4rem; }
.day span { font-size: .75rem; background: var(--surface); color: var(--muted); padding: .2rem .7rem; border-radius: 99px; border: 1px solid var(--line); }
.msg { max-width: min(75%, 640px); display: flex; flex-direction: column; }
.msg.in { align-self: flex-start; }
.msg.out { align-self: flex-end; align-items: flex-end; }
.bubble { padding: .45rem .7rem; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; box-shadow: var(--shadow); }
.msg.in .bubble { background: var(--bubble-in); border-top-left-radius: 3px; }
.msg.out .bubble { background: var(--bubble-out); border-top-right-radius: 3px; }
.msg:not(.t-text) .bubble { font-style: italic; color: var(--muted); }
.meta { font-size: .7rem; color: var(--muted); margin: .1rem .3rem .2rem; }
.archive-links { text-align: center; font-size: .85rem; color: var(--muted); padding: .5rem; }

@media (max-width: 760px) {
  .top { gap: .5rem; }
  .me { margin-left: 0; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .chats, .messages { overflow: visible; }
  .inbox.has-chat .list { display: none; }
  .inbox:not(.has-chat) .pane { display: none; }
  .back { display: inline; }
  .msg { max-width: 88%; }
  th, td { padding: .5rem; }
}
