:root {
  --bg: #f6f3ee; --panel: #fff; --ink: #24201c; --muted: #6f675e; --line: #e4ddd2;
  --accent: #a3271f; --accent-soft: #f6e4e1; --ok: #2e7d4f; --warn: #b26a00;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; display: flex; background: var(--bg); color: var(--ink);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
p { margin: 0 0 10px; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.spacer { flex: 1; }

.side { width: 210px; flex: none; background: #2b2420; color: #e9e1d6; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px 18px; }
.brand small { display: block; color: #a89c8d; font-size: 11px; }
.seal { width: 34px; height: 34px; border-radius: 7px; background: var(--accent); color: #fff; display: grid; place-items: center; font-size: 18px; }
nav a { display: flex; justify-content: space-between; padding: 8px 10px; border-radius: 7px; color: #d9cfc2; text-decoration: none; margin-bottom: 2px; }
nav a:hover { background: #3a312b; }
nav a.active { background: var(--accent); color: #fff; }
.count { font-size: 11px; opacity: .8; }

main { flex: 1; min-width: 0; padding: 26px 32px 60px; max-width: 1200px; }
.head { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.head p { margin: 0; color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; align-items: start; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat b { display: block; font-size: 26px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 12px; }

button, .btn { font: inherit; padding: 7px 12px; border-radius: 7px; border: 1px solid var(--line); background: #fff; color: var(--ink); cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { border-color: #c9bfb0; }
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--accent); }
button.ghost { border: 0; background: none; font-size: 16px; }
button.small, .btn.small { padding: 3px 8px; font-size: 12px; }
input, select, textarea { font: inherit; width: 100%; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
label input, label select, label textarea { margin-top: 3px; color: var(--ink); font-size: 14px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row > label { flex: 1; min-width: 150px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.toolbar input[type=search] { width: 220px; }
.toolbar select { width: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: #faf7f2; }
td select { padding: 3px 6px; font-size: 13px; width: auto; }
td small { color: var(--muted); display: block; }
.tablewrap { overflow-x: auto; }
.empty { text-align: center; color: var(--muted); padding: 34px 10px; }
.due { color: var(--accent); font-weight: 600; }
.pill { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: #efe9df; }
.pill.High { background: var(--accent-soft); color: var(--accent); }

.bars div { display: grid; grid-template-columns: 150px 1fr 34px; gap: 8px; align-items: center; margin-bottom: 6px; font-size: 13px; }
.bars i { display: block; height: 10px; border-radius: 5px; background: var(--accent); min-width: 2px; }
.bars span:last-child { text-align: right; color: var(--muted); }
ol.steps { margin: 0; padding-left: 20px; }
ol.steps li { margin-bottom: 6px; }
ul.tips { margin: 0; padding-left: 18px; }
ul.tips li { margin-bottom: 5px; }

.search-group { border-top: 1px solid var(--line); padding: 10px 0; }
.search-group:first-of-type { border-top: 0; }
.search-group .q { font-weight: 600; margin-bottom: 6px; }
.links { display: flex; gap: 6px; flex-wrap: wrap; }
.note { background: #fbf6ea; border: 1px solid #eadfc4; border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.chan { display: grid; grid-template-columns: 220px 1fr; gap: 4px 14px; padding: 8px 0; border-top: 1px solid var(--line); }
.chan:first-of-type { border-top: 0; }
.research { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }

dialog { border: 0; border-radius: 12px; padding: 0; width: min(720px, 94vw); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(30,24,20,.5); }
dialog form { padding: 18px 20px; }
dialog header, dialog footer { display: flex; align-items: center; gap: 8px; }
dialog header { justify-content: space-between; margin-bottom: 8px; }
dialog footer { margin-top: 12px; }
#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: #2b2420; color: #fff; padding: 9px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; }
#toast.show { opacity: 1; }
textarea.mail { min-height: 340px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }

.auto { background: var(--accent-soft); border-radius: 8px; padding: 12px 14px; margin-bottom: 6px; }
.auto p { margin: 4px 0 10px; font-size: 13px; }
label.inline { display: inline-flex; align-items: center; gap: 6px; margin: 0; flex: none; min-width: 0; font-size: 13px; }
label.inline input, th input, td input[type=checkbox] { width: auto; margin: 0; }
tr.dim { opacity: .5; }
body.anon .side nav, body.anon #whoami { display: none; }
.auth { max-width: 440px; margin: 8vh auto 0; }
.auth h1 { margin-bottom: 8px; }
#whoami { margin: 14px 6px 0; padding-top: 12px; border-top: 1px solid #4a3f37; display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; }
#whoami b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#whoami button { background: transparent; color: #d9cfc2; border-color: #4a3f37; flex: none; }
tbody tr.plain { cursor: default; }
tbody tr.plain:hover { background: none; }
.profile { width: 100%; display: grid; grid-template-columns: 170px 1fr; gap: 8px; font-size: 13px; }
#langSwitch { display: flex; gap: 4px; margin: 16px 6px 0; }
#langSwitch button { flex: 1; padding: 4px 6px; font-size: 12px; background: transparent; color: #d9cfc2; border-color: #4a3f37; }
#langSwitch button.on { background: #e9e1d6; color: #2b2420; border-color: #e9e1d6; }
pre.log { margin: 8px 0 0; max-height: 180px; overflow: auto; font: 12px/1.5 ui-monospace, Menlo, monospace; color: var(--muted); white-space: pre-wrap; }
label.inline input[type=time] { padding: 3px 6px; }
.pill.status.on { background: #dcefe3; color: var(--ok); }
.pill.status.off { background: var(--accent-soft); color: var(--accent); }
form.card .row { margin-top: 4px; }
.msg { border-top: 1px solid var(--line); padding: 10px 0; }
.msg:first-of-type { border-top: 0; }
.msg.in { border-left: 3px solid var(--ok); padding-left: 12px; }
.msg .meta { font-size: 12px; color: var(--muted); }
.msg .subj { font-weight: 600; margin: 2px 0 6px; }
.msg pre { margin: 6px 0 0; white-space: pre-wrap; word-break: break-word; font: inherit; font-size: 13px; }
.reply { border-top: 1px solid var(--line); padding: 8px 0; cursor: pointer; }
.reply:hover { background: #faf7f2; }
.pill.score { font-weight: 600; cursor: help; }
.pill.score.hi { background: #dcefe3; color: var(--ok); }
.pill.score.mid { background: #fbeed2; color: var(--warn); }
.pill.score.lo { background: #eee; color: var(--muted); }
thead th { position: sticky; top: 0; background: var(--panel); }

@media (max-width: 760px) {
  body { flex-direction: column; }
  .side { width: 100%; height: auto; position: static; padding: 10px; }
  .brand { padding-bottom: 8px; }
  nav { display: flex; overflow-x: auto; gap: 4px; }
  nav a { white-space: nowrap; }
  main { padding: 16px; }
  .grid2, .chan { grid-template-columns: 1fr; }
}

/* connections console */
.pill.status.neutral { background: #efe9df; color: var(--muted); }
.meter { height: 5px; border-radius: 99px; background: #eee7dc; overflow: hidden; margin-top: 6px; }
.meter i { display: block; height: 100%; background: var(--ok); border-radius: 99px; }
.meter.high i { background: var(--warn); }
.meter.full i { background: var(--accent); }
.conn { display: grid; grid-template-columns: 290px minmax(0, 1fr); gap: 16px; align-items: start; }
.conn-list { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; position: sticky; top: 16px; }
.conn-group { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 10px 10px 4px; }
.conn-item { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: 0; border-radius: 8px; padding: 9px 10px; background: none; }
.conn-item:hover { background: #f6f1ea; }
.conn-item.active { background: var(--accent-soft); }
.conn-name { flex: 1; min-width: 0; }
.conn-name b { display: block; font-weight: 600; }
.conn-name small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conn-state { font-size: 11px; color: var(--muted); text-align: right; max-width: 84px; line-height: 1.25; }
.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; background: #c9c0b3; }
.dot.on { background: var(--ok); }
.dot.off { background: var(--accent); }
.conn-detail { padding: 20px 22px; }
.conn-title { display: flex; gap: 14px; align-items: flex-start; justify-content: space-between; margin-bottom: 14px; }
.conn-title h2 { font-size: 18px; margin: 0 0 4px; }
.conn-title p { margin: 0; max-width: 60ch; }
.conn-title .pill { flex: none; margin-top: 3px; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0; margin: 0 0 6px; border: 1px solid var(--line); border-radius: 8px; background: #fbf9f5; }
.facts div { padding: 9px 12px; border-right: 1px solid var(--line); }
.facts div:last-child { border-right: 0; }
.facts dt { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-size: 13px; }
.conn-detail h3 { margin: 18px 0 8px; padding-top: 14px; border-top: 1px solid var(--line); }
.conn-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.copyrow { display: flex; gap: 10px; align-items: center; margin-bottom: 6px; }
.copyrow .muted { width: 96px; flex: none; font-size: 12px; }
.copyrow code { flex: 1; min-width: 0; overflow-wrap: anywhere; background: #f6f1ea; border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font-size: 12px; }
table.apps td { padding: 10px; }
table.apps td input { width: 76px; }
table.apps .usage { font-variant-numeric: tabular-nums; font-size: 13px; }
table.apps .meter { width: 110px; }
.todo h2 { margin-bottom: 6px; }
.todo-row { display: flex; gap: 12px; align-items: center; padding: 8px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.stat .meter { margin-top: 8px; }
@media (max-width: 980px) {
  .conn { grid-template-columns: minmax(0, 1fr); }
  .conn-list { position: static; }
  .facts div { border-right: 0; border-bottom: 1px solid var(--line); }
  .facts div:last-child { border-bottom: 0; }
}
table.apps .btn { white-space: nowrap; }
table.apps th { white-space: nowrap; }
