:root {
  --ink: #1a1714;
  --ink-2: #3f3a34;
  --muted: #7a736a;
  --line: #e4ddd4;
  --paper: #f4f0ea;
  --card: #fbfaf7;
  --sidebar: #efeae2;
  --cinnabar: #b54a3c;
  --cinnabar-dim: #f4e4e0;
  --pine: #2d6a4f;
  --pine-dim: #e4f0e9;
  --gold: #8a6a3b;
  --gold-dim: #f3ead8;
  --blue: #315f8a;
  --shadow: 0 10px 40px rgba(26, 23, 20, 0.08);
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink); }
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
.view { min-height: 100%; }
[hidden], .view[hidden], .tab-body[hidden], .mask[hidden], .mention-pop[hidden], .gate-hint[hidden], .form-error[hidden], .badge[hidden] {
  display: none !important;
}

.login-view {
  display: grid;
  place-items: center;
  padding: 32px 16px;
  background:
    radial-gradient(1200px 500px at 50% -10%, #fff 0%, transparent 60%),
    var(--paper);
}
.login-card {
  width: min(420px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 36px 32px 28px;
  box-shadow: var(--shadow);
}
.login-kicker {
  margin: 0 0 8px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--gold);
}
.login-card h1 { margin: 0 0 10px; font-size: 28px; font-weight: 650; letter-spacing: 0.04em; }
.login-lead, .login-foot { color: var(--muted); line-height: 1.6; }
.login-lead { margin: 0 0 24px; font-size: 14px; }
.login-foot { margin: 20px 0 0; font-size: 12px; }
.login-card label, dialog label { display: block; font-size: 12px; color: var(--muted); margin: 12px 0 6px; }
.login-card input, dialog input, .composer textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}
.login-card input:focus, dialog input:focus, .composer textarea:focus {
  border-color: var(--ink);
}

.btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--ink);
}
.btn.primary {
  background: var(--ink);
  color: #fbfaf7;
  border-color: var(--ink);
}
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.wide { width: 100%; margin-top: 18px; padding: 11px 16px; }
.btn.icon { width: 40px; height: 40px; padding: 0; border-radius: 12px; position: relative; }
.btn.danger { background: var(--cinnabar); color: #fff; border-color: var(--cinnabar); }
.btn.ok { background: var(--pine); color: #fff; border-color: var(--pine); }
.form-error { color: var(--cinnabar); font-size: 13px; margin: 8px 0 0; }

.app-view {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 320px;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}
.app-view > * { min-height: 0; }
.sidebar, .panel {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.brand, .side-foot, .side-block:not(.grow), .tabs { flex: none; }
.panel { border-right: 0; border-left: 1px solid var(--line); }
.brand { padding: 18px 16px 12px; }
.brand strong { display: block; font-size: 16px; }
.muted { color: var(--muted); font-size: 12px; }
.side-block { padding: 8px 10px; }
.side-block.grow { flex: 1; overflow: auto; }
.side-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--muted);
  padding: 4px 6px;
}
.channel-list button, .member-list .member {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 10px;
  padding: 9px 10px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.channel-list button.on { background: #fff; box-shadow: 0 1px 0 var(--line); }
.channel-list .meta { margin-left: auto; font-size: 11px; color: var(--cinnabar); }
.member { font-size: 13px; }
.avatar {
  width: 28px; height: 28px; border-radius: 9px;
  display: grid; place-items: center;
  color: #fff; font-size: 12px; font-weight: 600; flex: none;
}
.tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 999px;
  background: #fff;
  color: var(--muted);
  border: 1px solid var(--line);
  margin-left: auto;
}
.tag.relay { background: #efe7fb; color: #5b21b6; border-color: transparent; }
.tag.human { background: var(--ink); color: #fff; border-color: var(--ink); }
.side-foot {
  display: flex; align-items: center; gap: 8px;
  padding: 12px; border-top: 1px solid var(--line);
}
.whoami { flex: 1; font-size: 13px; }

.chat { display: flex; flex-direction: column; min-width: 0; background: var(--card); }
.chat-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.chat-title { flex: 1; min-width: 0; }
.chat-title h2 { margin: 0; font-size: 18px; font-weight: 650; }
.chat-title p { margin: 2px 0 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.messages {
  flex: 1;
  overflow: auto;
  padding: 18px 16px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.msg { display: flex; gap: 10px; max-width: 740px; }
.msg.system { max-width: none; justify-content: center; }
.sys-bubble {
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.7;
  text-align: center;
  white-space: pre-wrap;
}
.bubble {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px 16px 16px 16px;
  padding: 8px 12px 10px;
  min-width: 0;
}
.bubble .meta { display: flex; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.bubble .name { font-weight: 600; font-size: 13px; }
.bubble .time { font-size: 11px; color: var(--muted); }
.bubble .body { white-space: pre-wrap; line-height: 1.65; font-size: 14.5px; overflow-wrap: anywhere; }
.behalf { font-size: 11px; color: #5b21b6; margin-top: 2px; }
.approval-chip, .task-chip {
  display: inline-block;
  margin-top: 8px;
  font-size: 12px;
  padding: 3px 8px;
  border-radius: 999px;
}
.approval-chip.pending { background: var(--cinnabar-dim); color: var(--cinnabar); }
.approval-chip.ok { background: var(--pine-dim); color: var(--pine); }
.approval-chip.no { background: #eee; color: var(--muted); }

.composer { position: relative; border-top: 1px solid var(--line); padding: 10px 12px calc(12px + var(--safe-bottom)); background: var(--card); }
.composer textarea { resize: none; min-height: 52px; }
.composer-bar { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.flex { flex: 1; }
.gate-hint { margin: 0 0 8px; font-size: 12px; color: var(--cinnabar); background: var(--cinnabar-dim); padding: 6px 10px; border-radius: 8px; }
.mention-pop {
  position: absolute;
  left: 12px; right: 12px; bottom: 100%;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-height: 240px;
  overflow: auto;
  margin-bottom: 8px;
}
.mention-pop button {
  width: 100%; text-align: left; border: 0; background: transparent;
  padding: 8px 12px; display: flex; gap: 8px; align-items: center;
}
.mention-pop button:hover { background: var(--paper); }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; border: 0; background: transparent; padding: 14px 8px;
  color: var(--muted);
  position: relative;
}
.tab.on { color: var(--ink); font-weight: 650; }
.tab.on::after {
  content: ""; position: absolute; left: 20%; right: 20%; bottom: 0; height: 2px;
  background: var(--ink);
}
.tab-body { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}
.card h4 { margin: 0 0 6px; font-size: 14px; font-weight: 650; }
.card .row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.status {
  font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: var(--gold-dim); color: var(--gold);
}
.status.s-进行中 { background: #e7eef6; color: var(--blue); }
.status.s-待审 { background: var(--cinnabar-dim); color: var(--cinnabar); }
.status.s-完成 { background: var(--pine-dim); color: var(--pine); }
.notes { margin: 8px 0 0; padding: 0; list-style: none; font-size: 12px; color: var(--ink-2); }
.notes li { margin: 0 0 4px; }
.note-form { display: flex; gap: 6px; margin-top: 8px; }
.note-form input { flex: 1; border: 1px solid var(--line); border-radius: 8px; padding: 6px 8px; }

.badge {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px; padding: 0 5px;
  margin-left: 6px; border-radius: 999px;
  background: var(--cinnabar); color: #fff; font-size: 11px;
}
.empty { color: var(--muted); font-size: 13px; padding: 20px 8px; text-align: center; }

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  width: min(420px, calc(100vw - 32px));
  background: var(--card);
}
dialog::backdrop { background: rgba(26, 23, 20, 0.35); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.mask { display: none; }

.only-mobile { display: none; }

@media (max-width: 860px) {
  .app-view { grid-template-columns: 1fr; }
  .only-mobile { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar, .panel {
    position: fixed;
    top: 0; bottom: 0;
    width: min(84vw, 320px);
    z-index: 20;
    box-shadow: var(--shadow);
    transform: translateX(-110%);
    transition: transform 0.2s ease;
  }
  .panel { right: 0; left: auto; transform: translateX(110%); border-left: 1px solid var(--line); }
  .sidebar.open, .panel.open { transform: translateX(0); }
  .mask {
    display: block;
    position: fixed; inset: 0;
    background: rgba(26, 23, 20, 0.35);
    z-index: 15;
  }
}
