:root {
  --bg: #0e1621;
  --panel: #17212b;
  --panel-2: #1d2836;
  --line: #26323f;
  --text: #e8eef5;
  --muted: #8a9bb0;
  --accent: #58a6f5;
  --accent-dim: #2b5278;
  --good: #4fd18b;
  --bad: #f2686b;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

.app { display: flex; height: 100vh; overflow: hidden; }

/* ---------------------------------------------------------------- sidebar */
.sidebar {
  width: 300px;
  flex: 0 0 300px;
  background: var(--panel);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
}

.brand {
  padding: 14px 16px;
  font-weight: 600;
  letter-spacing: .2px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand a { color: var(--text); }

.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); }
.dot.ok { background: var(--good); box-shadow: 0 0 8px rgba(79, 209, 139, .7); }

.mainnav { display: flex; flex-wrap: wrap; gap: 4px; padding: 10px; border-bottom: 1px solid var(--line); }
.mainnav a {
  /* Sized to its label, then sharing what is left: four tabs fit the sidebar,
     and a longer one wraps to a second line instead of breaking mid-word. */
  flex: 1 1 auto;
  white-space: nowrap;
  text-align: center;
  padding: 7px 6px;
  border-radius: 8px;
  color: var(--muted);
  font-size: 13px;
}
.mainnav a:hover { background: var(--panel-2); text-decoration: none; }
.mainnav a.active { background: var(--accent-dim); color: #fff; }

.chatlist { flex: 1; overflow-y: auto; padding: 6px; }

.chatrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 10px;
  color: var(--text);
}
.chatrow:hover { background: var(--panel-2); text-decoration: none; }
.chatrow.active { background: var(--accent-dim); }
.chatrow .meta { display: flex; flex-direction: column; min-width: 0; }
.chatrow .name { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chatrow .sub { font-size: 12px; color: var(--muted); }
.live { color: var(--good); font-size: 10px; vertical-align: middle; }

.sidefoot {
  padding: 10px 14px;
  border-top: 1px solid var(--line);
  font-size: 11px;
  color: var(--muted);
}

.avatar {
  width: 38px; height: 38px;
  flex: 0 0 38px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--accent-dim);
}
.avatar.letter {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #fff;
}
.avatar.sm { width: 26px; height: 26px; flex-basis: 26px; font-size: 12px; }

/* ------------------------------------------------------------------- main */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}
.topbar-title { display: flex; flex-direction: column; min-width: 0; }
.h-title { font-weight: 600; }
.h-sub { font-size: 12px; color: var(--muted); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }
.autorefresh { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

.content { flex: 1; overflow-y: auto; padding: 20px; }

.warn { color: #f0b849; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.section { margin: 28px 0 10px; font-size: 15px; }
.spacer { flex: 1; }

/* ----------------------------------------------------------------- inputs */
.btn {
  display: inline-block;
  padding: 7px 13px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); text-decoration: none; }
.btn.primary { background: var(--accent-dim); border-color: var(--accent-dim); color: #fff; }
.btn.ghost { background: transparent; }

input[type="search"], input[type="number"], input[type="text"], select {
  padding: 7px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
}
input[type="search"] { min-width: 260px; }
input[type="number"] { width: 7rem; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

.filters, .toolbar, .selectbar, .row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.toolbar { justify-content: space-between; margin-bottom: 14px; }
.selectbar { margin: 14px 0; }
.filters { margin-bottom: 14px; }

/* ----------------------------------------------------------------- export */
.exportbox { position: relative; margin-bottom: 14px; }
.exportbox > summary { list-style: none; cursor: pointer; }
.exportbox > summary::-webkit-details-marker { display: none; }
.exportbox[open] > summary { border-color: var(--accent); }

.exportform {
  position: absolute;
  right: 0;
  z-index: 20;
  margin-top: 8px;
  width: min(440px, calc(100vw - 40px));
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 18px 40px rgba(0, 0, 0, .45);
}
.exportform label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.exportform label.wide, .exportform .exhint, .exportform .exportactions { grid-column: 1 / -1; }
.exportform label.check { flex-direction: row; align-items: flex-start; gap: 8px; line-height: 1.35; }
.exportform input, .exportform select { width: 100%; min-width: 0; }
.exportform input[type="date"] {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}
.exportform input[type="checkbox"] { width: 16px; flex: 0 0 16px; margin-top: 2px; }
.exhint { margin: 0; font-size: 12px; color: var(--muted); min-height: 2.4em; }
.exportactions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.notice {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* --------------------------------------------------------------- messages */
.messages { display: flex; flex-direction: column; gap: 10px; max-width: 860px; }

.daysep { text-align: center; margin: 14px 0 6px; }
.daysep span {
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  padding: 3px 12px;
  border-radius: 999px;
}

.bubble {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.bubble.highlight { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(88, 166, 245, .2); }
.bubble.deleted { opacity: .72; border-color: #5a2b2f; }
.bubble.service { background: transparent; border-style: dashed; }

.bubble-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.author { font-weight: 600; color: var(--accent); }
.handle { color: var(--muted); font-size: 12px; }
.stamp { color: var(--muted); font-size: 12px; }

.bubble-foot { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.bubble-foot:empty { display: none; }

.chip {
  font-size: 11px;
  color: var(--muted);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 1px 8px;
}
.chip.danger { color: var(--bad); border-color: #5a2b2f; }
.chip.ghost { background: transparent; }

.badge {
  font-size: 11px; padding: 2px 9px; border-radius: 999px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.badge.live { background: rgba(79, 209, 139, .15); color: var(--good); border-color: rgba(79, 209, 139, .4); }

.reaction {
  font-size: 12px;
  background: var(--accent-dim);
  border-radius: 999px;
  padding: 2px 9px;
}

.text { margin-top: 6px; overflow-wrap: anywhere; }
.text blockquote {
  margin: 6px 0;
  padding-left: 10px;
  border-left: 3px solid var(--accent-dim);
  color: var(--muted);
}
.text code {
  background: #0b1017;
  padding: 1px 5px;
  border-radius: 5px;
  font-size: 13px;
}
.text pre {
  background: #0b1017;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
}
.text pre code { background: none; padding: 0; }

.spoiler {
  background: var(--muted);
  color: transparent;
  border-radius: 4px;
  cursor: pointer;
}
.spoiler.revealed { background: none; color: inherit; }

.fwd, .action { font-size: 12px; color: var(--muted); margin-top: 6px; }
.action { font-style: italic; }

.reply {
  display: block;
  margin-top: 8px;
  padding: 5px 10px;
  border-left: 3px solid var(--accent);
  background: var(--panel-2);
  border-radius: 0 8px 8px 0;
  font-size: 13px;
  color: var(--text);
}
.reply:hover { text-decoration: none; background: var(--line); }
.reply-author { color: var(--accent); font-weight: 600; margin-right: 6px; }
.reply-text { color: var(--muted); }

/* ------------------------------------------------------------------ media */
.media-grid { margin-top: 8px; display: flex; flex-direction: column; gap: 8px; }
.media-grid.album { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }

.m-photo, .m-video { max-width: 100%; max-height: 420px; border-radius: 10px; display: block; }
.m-sticker { max-height: 180px; }
.m-round { border-radius: 50%; max-width: 260px; }
audio { width: 100%; max-width: 420px; }

.m-caption { font-size: 11px; color: var(--muted); margin-top: 3px; }

.m-file, .m-link {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 9px 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--text);
}
.m-file:hover, .m-link:hover { border-color: var(--accent); text-decoration: none; }
.m-file.pending { opacity: .7; }
.file-icon { font-size: 20px; }
.file-name, .link-title { display: block; font-size: 13px; }
.file-meta, .link-desc, .link-site { display: block; font-size: 11px; color: var(--muted); }
.m-link { flex-direction: column; align-items: flex-start; gap: 2px; }
.link-title { font-weight: 600; }

.m-poll { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.poll-q { font-weight: 600; margin-bottom: 8px; }
.poll-a { position: relative; padding: 5px 8px; margin-bottom: 4px; border-radius: 6px; overflow: hidden; font-size: 13px; display: flex; }
.poll-bar { position: absolute; inset: 0 auto 0 0; background: var(--accent-dim); z-index: 0; }
.poll-txt, .poll-num { position: relative; z-index: 1; }
.poll-num { margin-left: auto; color: var(--muted); font-size: 12px; }

/* ------------------------------------------------------------------ cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  color: var(--text);
  display: block;
}
.card:hover { border-color: var(--accent); text-decoration: none; }
.card.tight { padding: 12px; }
.card-head { display: flex; align-items: center; gap: 10px; }
.card-title { font-weight: 600; }
.card-sub { font-size: 12px; color: var(--muted); }
.card-head .badge { margin-left: auto; }
.card-stats { display: flex; gap: 14px; margin-top: 12px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.card-stats b { color: var(--text); font-size: 14px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
.tile {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}
.tile b { display: block; font-size: 20px; }
.tile span { font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------------ table */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--line); text-align: left; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; }
.table tr.on { background: rgba(88, 166, 245, .06); }
.table .num { text-align: right; }
.cellmain { display: flex; align-items: center; gap: 8px; }
.cellmain .muted { display: block; }

.pager { display: flex; align-items: center; gap: 12px; margin-top: 18px; color: var(--muted); font-size: 13px; }

/* ------------------------------------------------------------------ login */
body.centered { display: flex; align-items: center; justify-content: center; padding: 20px; }

.loginbox {
  width: 100%;
  max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px 26px;
  text-align: center;
}
.login-logo { font-size: 40px; line-height: 1; }
.loginbox h1 { font-size: 18px; margin: 10px 0 4px; }
.loginbox p { margin: 0 0 18px; }
.loginbox input[type="password"] {
  width: 100%;
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-size: 14px;
}
.loginbox input[type="password"]:focus { outline: none; border-color: var(--accent); }
.btn.wide { width: 100%; margin-top: 12px; padding: 10px; }
.login-error {
  margin-top: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--bad);
  background: rgba(242, 104, 107, .12);
  border: 1px solid rgba(242, 104, 107, .35);
}
.login-hint { margin: 16px 0 0 !important; }
.login-hint code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }

.logoutform { margin-top: 6px; }
.linkbtn {
  background: none;
  border: none;
  padding: 0;
  color: var(--accent);
  font-size: 11px;
  cursor: pointer;
  font-family: inherit;
}
.linkbtn:hover { text-decoration: underline; }

.empty, .empty-state { color: var(--muted); text-align: center; padding: 30px 10px; }
.empty-state h2 { color: var(--text); margin: 0 0 8px; }
.empty-state .btn { margin-top: 14px; }

@media (max-width: 800px) {
  .app { flex-direction: column; height: auto; }
  .sidebar { width: 100%; flex: none; height: auto; max-height: 45vh; }
  .content { padding: 14px; }
  input[type="search"] { min-width: 0; flex: 1; }
}

/* --------------------------------------------------------------- presence */
.fieldlabel { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.caption { margin: 0 0 12px; max-width: 74ch; }

/* One row per day, midnight to midnight, with a block per visit. */
.tl { display: flex; flex-direction: column; gap: 3px; max-width: 940px; }
.tl-row { display: flex; align-items: center; gap: 10px; }
.tl-day { flex: 0 0 96px; font-size: 12px; color: var(--muted); text-align: right; }
.tl-total { flex: 0 0 70px; font-size: 12px; color: var(--muted); }

.tl-track {
  position: relative;
  flex: 1;
  height: 18px;
  min-width: 0;
  border-radius: 5px;
  background-color: var(--panel-2);
  /* A recessive gridline every six hours. */
  background-image: repeating-linear-gradient(to right, var(--line) 0 1px, transparent 1px 25%);
}
.tl-head { color: var(--muted); }
.tl-head .tl-track { background: none; height: 14px; }
.tl-tick { position: absolute; top: 0; font-size: 11px; color: var(--muted); }
.tl-tick-end { right: 0; }

/* The part of today that has not happened yet -- not the same as "offline". */
.tl-future {
  position: absolute;
  top: 0;
  bottom: 0;
  right: 0;
  border-radius: 0 5px 5px 0;
  background: repeating-linear-gradient(135deg, var(--bg) 0 2px, transparent 2px 5px);
  opacity: .6;
}

.tl-bar {
  position: absolute;
  top: 2px;
  bottom: 2px;
  min-width: 3px;
  border-radius: 3px;
  background: var(--accent);
  /* A ring in the track colour keeps two visits minutes apart from merging. */
  box-shadow: 0 0 0 2px var(--panel-2);
}
/* Inferred from last-seen moving, so the length is an upper bound: hatched
   rather than a second colour, which would read as a different measurement. */
.tl-bar.est {
  background: repeating-linear-gradient(45deg, var(--accent) 0 3px, var(--accent-dim) 3px 6px);
}
.tl-bar.now { background: var(--good); }

/* Hour of the week: one hue, dark (nothing) to light (the busiest hour). */
.grid { display: flex; flex-direction: column; gap: 2px; max-width: 940px; }
.grid-row { display: flex; align-items: center; gap: 2px; }
.grid-label { flex: 0 0 36px; font-size: 11px; color: var(--muted); }
.grid-hour { flex: 1 1 0; min-width: 0; font-size: 10px; color: var(--muted); }

.cell { flex: 1 1 0; min-width: 0; height: 17px; border-radius: 3px; background: var(--panel-2); }
.cell.lv1 { background: #184f95; }
.cell.lv2 { background: #256abf; }
.cell.lv3 { background: #3987e5; }
.cell.lv4 { background: #6da7ec; }
.cell.lv5 { background: #9ec5f4; }

.grid-legend { display: flex; align-items: center; gap: 4px; margin-top: 10px; padding-left: 38px; }
.grid-legend .cell { flex: 0 0 17px; }

@media (max-width: 720px) {
  .tl-day { flex-basis: 70px; }
  .tl-total { flex-basis: 52px; }
  .grid-hour { font-size: 0; }
}

/* ------------------------------------------------------- capture grouping */
.grouphead {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 12px 10px 5px;
  font-size: 11px;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--muted);
}
.grouphead a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  border: 1px solid var(--line);
  border-radius: 50%;
  font-size: 10px;
  color: var(--muted);
}
.grouphead a:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; }

/* Kept automatically rather than chosen -- readable, but never mistaken for
   the green that means "archiving". */
.badge.net {
  background: rgba(88, 166, 245, .12);
  color: var(--accent);
  border-color: rgba(88, 166, 245, .35);
}

.netnotice { display: flex; align-items: center; gap: 16px; border-left-color: var(--good); }
.netnotice form { margin-left: auto; }
.netnotice .btn { white-space: nowrap; }

/* A single-column popover, for the shorter forms. */
.exportform.narrow { grid-template-columns: 1fr; width: min(380px, calc(100vw - 40px)); }
.exportform.narrow .exhint { min-height: 0; }

/* ------------------------------------------------------------ edit history */
.edits { display: inline-block; }
.edits > summary { list-style: none; cursor: pointer; }
.edits > summary::-webkit-details-marker { display: none; }
.edits[open] > summary { border-color: var(--accent); color: var(--accent); }

.editlist {
  margin-top: 6px;
  border-left: 2px solid var(--line);
  padding-left: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.editrow { display: flex; flex-direction: column; gap: 1px; font-size: 13px; }
.editwhen { font-size: 11px; color: var(--muted); }
/* Superseded wording reads as struck through; the current one does not. */
.editwas { color: var(--muted); text-decoration: line-through; overflow-wrap: anywhere; }
.editrow.now .editwas { color: var(--text); text-decoration: none; }
