:root {
  --bg: #efe6d8;
  --elev: #fbf7f0;
  --ink: #1e1a16;
  --muted: #6f675c;
  --line: #e2d6c6;
  --sidebar: #221e1a;
  --sidebar-ink: #f6f1e8;
  --sidebar-muted: #b7ab9c;
  --copper: #b85c38;
  --copper-deep: #8c3f24;
  --ok: #1f6b45;
  --danger: #8d2f2f;
  --shadow: 0 24px 60px rgba(48, 32, 16, 0.12);
  --serif: "Songti SC", "Noto Serif SC", "Source Han Serif SC", serif;
  --sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, strong.serif { font-family: var(--serif); font-weight: 600; }

.booting {
  margin: 0;
  min-height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.login {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    radial-gradient(circle at top left, rgba(184, 92, 56, 0.16), transparent 32%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 32px 28px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 14px 0 8px; font-size: 36px; }
.lede { margin: 0 0 22px; color: var(--muted); }
.mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  font-family: var(--serif);
  font-size: 22px;
}

.shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 232px 1fr;
}
.sidebar {
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  padding: 22px 16px 16px;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 28px; }
.brand strong { display: block; font-family: var(--serif); font-size: 18px; }
.brand small { color: var(--sidebar-muted); }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; }
.sidebar nav button {
  text-align: left;
  border: 0;
  background: transparent;
  color: var(--sidebar-muted);
  border-radius: 8px;
  padding: 10px 12px;
}
.sidebar nav button.active {
  background: rgba(255, 248, 238, 0.08);
  color: var(--sidebar-ink);
  box-shadow: inset 3px 0 0 var(--copper);
}
.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--sidebar-muted);
  font-size: 13px;
  word-break: break-all;
}
.text-btn {
  border: 0;
  background: transparent;
  color: var(--copper-deep);
  padding: 0;
}
.text-btn.light { color: var(--sidebar-ink); text-align: left; }

.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-end;
  padding: 22px 28px 16px;
}
.topbar h1 { margin: 0; font-size: 32px; }
.topbar p { margin: 4px 0 0; color: var(--muted); }
#actions { display: flex; gap: 8px; flex-wrap: wrap; }
.content { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.btn, .icon-btn {
  border: 1px solid var(--line);
  background: var(--elev);
  border-radius: 999px;
  padding: 8px 14px;
}
.btn-primary { background: var(--copper); border-color: var(--copper); color: white; }
.btn-primary:hover { background: var(--copper-deep); }
.btn-danger { color: var(--danger); border-color: #efc8c4; background: #fff7f6; }
.icon-btn { border-radius: 8px; padding: 6px 10px; }
.btn:disabled { opacity: 0.6; cursor: wait; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field span { font-size: 13px; color: var(--muted); }
.field input, .filters select, .filters input {
  border: 1px solid var(--line);
  background: white;
  border-radius: 10px;
  padding: 10px 12px;
}
.field textarea, .composer textarea {
  border: 1px solid var(--line);
  background: white;
  border-radius: 10px;
  padding: 10px 12px;
  resize: vertical;
}
.form-error { min-height: 1.2em; margin: 0 0 12px; color: var(--danger); }
.checks { display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow: auto; margin-bottom: 8px; }
.check { display: flex; gap: 8px; align-items: center; }
.dialog-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 8px; }
.dialog-actions .right { display: flex; gap: 8px; }

.page { flex: 1; min-height: 0; overflow: auto; padding: 0 28px 28px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.card, .table-wrap {
  background: var(--elev);
  border: 1px solid var(--line);
  border-radius: 16px;
}
.card { padding: 16px; }
.card-top, .msg-meta, .card-actions, .filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.card-top { justify-content: space-between; }
.card h2 { margin: 0; font-size: 22px; }
.count, .group-meta, .history-note, .quiet { color: var(--muted); font-size: 13px; }
.card-actions { margin-top: 14px; }
.chips, .mentions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.recipient-group { display: inline-flex; flex-wrap: wrap; gap: 5px; }
.chip, .role, .status {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  background: #f3ece3;
}
.role.director { background: #e7eef8; color: #2d4570; }
.role.employee { background: #f3e6da; color: #6d4c38; }
.role.admin { background: #e8e5e0; color: #42382e; }
.chip.unread { background: #f8e4da; color: var(--copper-deep); }
.chip.read { background: #e5f2ea; color: var(--ok); }
.msg-type { border-radius: 999px; padding: 2px 8px; font-size: 11px; background: #f3ece3; color: #70583f; }
.msg-type.type-notice { background: #e8eef8; color: #36517d; }
.msg-type.type-task { background: #f8e4da; color: var(--copper-deep); }
.chip.state-completed { background: #e5f2ea; color: var(--ok); }
.chip.state-failed, .chip.state-rejected, .chip.state-blocked { background: #f8e4e2; color: var(--danger); }
.status.on { background: #e5f2ea; color: var(--ok); }
.status.off { background: #f8e4e2; color: var(--danger); }

.chat {
  flex: 1;
  min-height: 0;
  margin: 0 28px 28px;
  display: grid;
  grid-template-columns: 260px 1fr;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--elev);
  overflow: hidden;
}
.chat > * { min-height: 0; }
.group-col { border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.col-label { padding: 14px 14px 8px; color: var(--muted); font-size: 12px; letter-spacing: 0.08em; }
.group-list { overflow: auto; padding: 0 8px 12px; }
.group-item {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
}
.group-item.active { background: #f6efe6; }
.group-name { font-weight: 600; }
.transcript-wrap { display: flex; flex-direction: column; min-height: 0; position: relative; }
.transcript-head {
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.transcript-heading { display: flex; flex-direction: column; min-width: 0; }
.transcript-heading .quiet { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.transcript-head strong { font-family: var(--serif); font-size: 20px; }
.transcript { flex: 1; overflow: auto; padding: 8px 0 18px; }
.msg { display: grid; grid-template-columns: 36px 1fr; gap: 12px; padding: 14px 18px; }
.msg.task-msg { background: #fffdfa; }
.msg + .msg { border-top: 1px solid #f0e7db; }
.avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  color: white;
  font-family: var(--serif);
}
.msg-body { white-space: pre-wrap; word-break: break-word; margin-top: 4px; }
.msg time { color: var(--muted); font-size: 12px; }
.task-history { margin-top: 8px; padding: 0; font-size: 12px; }
.status-timeline { margin: 12px 0 0; padding-left: 22px; }
.status-timeline li { padding: 0 0 14px 4px; }
.status-timeline li:last-child { padding-bottom: 0; }
.status-timeline time { margin-left: 8px; }
.status-timeline p { margin: 5px 0; white-space: pre-wrap; }
.status-timeline small { display: block; margin-top: 5px; overflow-wrap: anywhere; }
.new-pill {
  position: absolute;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  border: 0;
  background: var(--ink);
  color: white;
  border-radius: 999px;
  padding: 8px 14px;
}
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty.slim { padding: 18px 10px; }
.empty .btn { display: block; margin: 14px auto 0; }
.composer {
  padding: 12px 18px 16px;
  border-top: 1px solid var(--line);
  background: #f8f2e9;
}
.composer-recipients, .composer-actions, .recipient-picker, .recipient-option { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.composer-recipients { margin-bottom: 9px; }
.recipient-picker { gap: 6px; }
.recipient-option { border: 1px solid var(--line); background: var(--elev); border-radius: 999px; padding: 4px 9px; font-size: 13px; }
.recipient-option input { margin: 0; }
.composer textarea { display: block; width: 100%; min-height: 68px; }
.composer textarea:disabled { background: #f3ece3; }
.composer-actions { justify-content: space-between; margin-top: 9px; }
.composer-actions .right { display: flex; align-items: center; gap: 8px; }
.composer-actions select { border: 1px solid var(--line); background: white; border-radius: 999px; padding: 8px 12px; }
.member-checks { max-height: 50vh; }
.pager { margin-top: 16px; }

.filters { margin-bottom: 12px; }
.filters input { min-width: 180px; }
.table-wrap { overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 13px; }
th { color: var(--muted); font-weight: 500; }
tr.log-row { cursor: pointer; }
tr.log-row:hover { background: #fbf6ef; }
.method { font-weight: 600; }
.status-code.ok { color: var(--ok); }
.status-code.bad { color: var(--danger); }
.log-detail pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 12px;
}
.path { font-family: ui-monospace, "SFMono-Regular", Menlo, monospace; }

.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(28, 22, 16, 0.48);
  display: grid;
  place-items: center;
  padding: 24px;
  z-index: 20;
}
.dialog {
  width: min(560px, 100%);
  max-height: min(84vh, 820px);
  overflow: auto;
  background: var(--elev);
  border-radius: 16px;
  padding: 20px;
  box-shadow: var(--shadow);
}
.dialog.wide { width: min(780px, 100%); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.dialog h2 { margin: 0 0 8px; font-size: 26px; }
.hint { color: var(--muted); margin-top: 0; }
.instruction {
  white-space: pre-wrap;
  word-break: break-word;
  background: #241f1b;
  color: #f6f1e8;
  border-radius: 12px;
  padding: 16px;
  max-height: 52vh;
  overflow: auto;
  line-height: 1.6;
  font-size: 13px;
}
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  border-radius: 999px;
  padding: 8px 14px;
  z-index: 30;
}

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; height: auto; min-height: 100vh; }
  .sidebar { padding-bottom: 12px; }
  .sidebar nav { flex-direction: row; overflow: auto; }
  .sidebar-foot { margin-top: 16px; }
  .chat { grid-template-columns: 1fr; margin: 0 12px 16px; min-height: 70vh; }
  .group-col { max-height: 180px; border-right: 0; border-bottom: 1px solid var(--line); }
  .topbar, .page { padding-left: 16px; padding-right: 16px; }
  .main { min-height: 80vh; }
}
