:root {
  color: #17202a;
  background: #f4f6f8;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  letter-spacing: 0;
  --green: #157a55;
  --green-dark: #0f6244;
  --ink: #17202a;
  --muted: #68737f;
  --line: #dfe4e8;
  --panel: #ffffff;
  --soft: #eef3f1;
  --danger: #b34040;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { min-width: 320px; overflow: hidden; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }
[hidden] { display: none !important; }

.app-shell { height: 100vh; background: var(--panel); }
.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}
.brand, .top-actions { display: flex; align-items: center; gap: 10px; }
.brand strong { font-size: 16px; }
.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  color: #fff;
  background: var(--green);
  font: 700 21px/1 Georgia, serif;
}
.brand-mark.small { width: 30px; height: 30px; font-size: 16px; }

.status-pill {
  min-height: 28px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 9px;
  border: 1px solid #cddbd5;
  border-radius: 999px;
  color: #35614e;
  background: #f3f8f6;
  font-size: 12px;
  white-space: nowrap;
}
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: #2da56f; }
.status-pill.offline { color: #7b5555; border-color: #e2cece; background: #fbf5f5; }
.status-pill.offline i { background: #bf5555; }
.status-pill.warning { color: #865d19; border-color: #e7d5ad; background: #fff9ed; }

.icon-button, .command-button, .primary, .secondary {
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
  color: var(--ink);
  min-height: 34px;
}
.icon-button { width: 34px; padding: 0; font-size: 21px; line-height: 1; }
.icon-button:hover, .secondary:hover { background: #f5f7f8; }
.command-button { padding: 0 12px; font-size: 13px; }
.primary { border-color: var(--green); background: var(--green); color: #fff; padding: 0 17px; }
.primary:hover { background: var(--green-dark); }
.secondary { padding: 0 17px; }
.wide { width: 100%; height: 42px; }

.workspace { height: calc(100vh - 58px); min-height: 0; display: grid; grid-template-columns: 330px minmax(0, 1fr); overflow: hidden; }
.room-pane { min-width: 0; min-height: 0; overflow: hidden; border-right: 1px solid var(--line); background: #fafbfb; display: flex; flex-direction: column; }
.room-tools { padding: 14px 13px 10px; display: grid; grid-template-columns: minmax(0, 1fr) 105px; gap: 8px; }
.search-box { height: 36px; display: flex; align-items: center; gap: 7px; padding: 0 10px; border: 1px solid var(--line); background: #fff; border-radius: 5px; }
.search-box span { color: var(--muted); font-size: 18px; }
.search-box input { width: 100%; min-width: 0; border: 0; outline: 0; background: transparent; }
select { border: 1px solid var(--line); border-radius: 5px; padding: 0 8px; background: #fff; color: var(--ink); }
.room-summary { display: flex; justify-content: space-between; padding: 0 14px 9px; color: var(--muted); font-size: 11px; }
.room-list { min-height: 0; overflow-y: auto; overscroll-behavior: contain; flex: 1 1 0; border-top: 1px solid #e8ebed; }
.room-item { width: 100%; min-height: 76px; display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 10px; padding: 11px 13px; border: 0; border-bottom: 1px solid #e8ebed; background: transparent; text-align: left; color: inherit; }
.room-item:hover { background: #f0f4f2; }
.room-item.active { background: #e6f0ec; box-shadow: inset 3px 0 var(--green); }
.room-avatar { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 6px; color: #fff; font-weight: 700; background: #526d82; }
.room-color-0 { background: #3f6c75; }
.room-color-1 { background: #6b617d; }
.room-color-2 { background: #476a56; }
.room-color-3 { background: #84664e; }
.room-color-4 { background: #536d8a; }
.room-color-5 { background: #7a5961; }
.room-copy { min-width: 0; }
.room-title-row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.room-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 14px; }
.room-time { flex: 0 0 auto; color: var(--muted); font-size: 10px; }
.room-preview { margin: 7px 0 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: 12px; }
.room-meta { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.room-group { color: var(--green-dark); font-size: 10px; }
.room-expiry { color: #795d2c; font-size: 10px; }

.message-pane { min-width: 0; min-height: 0; overflow: hidden; background: #fff; }
.empty-state { height: 100%; display: grid; place-content: center; justify-items: center; color: var(--muted); }
.empty-symbol { width: 54px; height: 54px; display: grid; place-items: center; border: 1px solid #bed0c8; border-radius: 7px; color: var(--green); font: 700 25px Georgia, serif; }
.empty-state h2 { margin: 18px 0 5px; color: #33404b; font-size: 18px; }
.empty-state p { margin: 0; font-size: 13px; }
.message-view { position: relative; height: 100%; min-height: 0; overflow: hidden; display: flex; flex-direction: column; }
.message-header { min-height: 70px; display: flex; align-items: center; gap: 12px; padding: 10px 20px; border-bottom: 1px solid var(--line); }
.room-heading { min-width: 0; flex: 1; }
.room-heading h2 { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 18px; }
.room-heading p { margin: 6px 0 0; color: var(--muted); font-size: 11px; }
.room-heading p span + span::before { content: " · "; }
.limit-control { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.limit-control select { height: 32px; }
.message-list { min-height: 0; flex: 1 1 0; overflow-y: auto; overscroll-behavior: contain; padding: 20px clamp(16px, 4vw, 64px) 38px; background: #f7f8f8; }
.load-older { display: block; min-width: 118px; min-height: 30px; margin: 0 auto 20px; padding: 5px 12px; border: 1px solid #d6ded9; border-radius: 5px; color: #557064; background: #fff; font-size: 11px; }
.load-older:hover:not(:disabled) { border-color: #aebfb7; background: #f3f7f5; }
.new-message-button { position: absolute; right: 24px; bottom: 20px; z-index: 4; min-height: 34px; padding: 7px 13px; border: 1px solid #b9d3c7; border-radius: 17px; color: #fff; background: var(--green); box-shadow: 0 5px 18px rgb(26 57 43 / 20%); font-size: 12px; }
.message-item { max-width: 900px; margin: 0 auto 16px; }
.message-time { margin: 0 0 6px; color: var(--muted); font-size: 11px; }
.message-body { padding: 15px 17px; border: 1px solid var(--line); border-radius: 6px; background: #fff; box-shadow: 0 1px 2px rgb(26 40 33 / 4%); }
.message-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.72; font-size: 14px; }
.message-image { display: block; max-width: min(100%, 680px); max-height: 620px; margin: 9px 0; border-radius: 5px; object-fit: contain; background: #eef0f1; }
.message-image.failed { min-width: min(100%, 420px); min-height: 42px; padding: 10px; color: var(--muted); font-size: 12px; object-fit: none; }
.message-file { display: inline-flex; align-items: center; gap: 8px; margin: 7px 0; color: var(--green-dark); text-decoration: none; }
.message-empty, .loading { padding: 40px 20px; text-align: center; color: var(--muted); font-size: 13px; }

.login-layer { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 20px; background: #edf1ef; }
.login-panel { width: min(390px, 100%); padding: 32px; border: 1px solid #d8e0dc; border-radius: 7px; background: #fff; box-shadow: 0 18px 60px rgb(26 42 34 / 10%); }
.login-panel .brand-mark { margin-bottom: 22px; }
.login-panel h1 { margin: 0; font-size: 22px; }
.login-panel > p { margin: 7px 0 24px; color: var(--muted); font-size: 13px; }
.login-panel label, .dialog-content > label { display: block; margin: 13px 0 6px; color: #46515a; font-size: 12px; font-weight: 600; }
.login-panel input, .dialog-content input { width: 100%; height: 40px; border: 1px solid #ccd3d7; border-radius: 5px; padding: 0 11px; outline: none; }
.login-panel input:focus, .dialog-content input:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgb(21 122 85 / 10%); }
.login-panel .wide { margin-top: 12px; }
.form-error { min-height: 18px; margin: 8px 0 0 !important; color: var(--danger) !important; font-size: 12px !important; }

dialog { width: min(430px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 7px; color: var(--ink); box-shadow: 0 24px 80px rgb(18 31 25 / 24%); }
dialog::backdrop { background: rgb(28 38 34 / 42%); }
.dialog-content { padding: 22px; }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 15px; }
.dialog-header h2 { margin: 0; font-size: 18px; }
.dialog-header p { margin: 5px 0 0; color: var(--muted); font-size: 11px; }
.captcha-row { display: grid; grid-template-columns: 1fr 132px; gap: 9px; }
.captcha-image { height: 40px; padding: 0; overflow: hidden; border: 1px solid #ccd3d7; border-radius: 5px; background: #f4f5f6; }
.captcha-image img { display: block; width: 100%; height: 100%; object-fit: cover; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }
.toast { position: fixed; right: 18px; bottom: 18px; z-index: 30; max-width: min(380px, calc(100% - 36px)); padding: 11px 14px; border-radius: 5px; color: #fff; background: #24342d; font-size: 13px; box-shadow: 0 8px 28px rgb(0 0 0 / 18%); opacity: 0; transform: translateY(8px); pointer-events: none; transition: 160ms ease; }
.toast.show { opacity: 1; transform: translateY(0); }
.mobile-only { display: none; }

.current-user { color: #4c5963; font-size: 12px; white-space: nowrap; }
.admin-menu { position: relative; display: none; }
.admin-menu summary { display: grid; place-items: center; list-style: none; }
.admin-menu summary::-webkit-details-marker { display: none; }
.admin-menu-popover { position: absolute; top: 40px; right: 0; z-index: 12; width: 130px; padding: 5px; border: 1px solid var(--line); border-radius: 6px; background: #fff; box-shadow: 0 10px 30px rgb(20 35 28 / 16%); }
.admin-menu-popover button { width: 100%; min-height: 34px; padding: 6px 9px; border: 0; border-radius: 4px; background: transparent; color: var(--ink); text-align: left; font-size: 12px; }
.admin-menu-popover button:hover { background: #eef3f1; }
.room-avatar { position: relative; }
.unread-dot { position: absolute; top: -4px; right: -4px; width: 11px; height: 11px; border: 2px solid #fff; border-radius: 50%; background: #d94343; }
.room-item.read .room-title { color: #64707a; font-weight: 500; }
.room-item.read .room-preview, .room-item.read .room-time { color: #929aa1; }
.room-item.unread .room-title { font-weight: 700; color: #15202a; }

.wide-dialog { width: min(980px, calc(100% - 28px)); }
.create-user-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; margin-bottom: 9px; }
.create-user-row input { min-width: 0; }
.user-search-row { margin-bottom: 16px; }
.user-search-row input { width: 100%; }
.admin-layout { height: min(600px, 68vh); display: grid; grid-template-columns: 230px minmax(0, 1fr); border: 1px solid var(--line); overflow: hidden; }
.user-list { min-height: 0; overflow-y: auto; border-right: 1px solid var(--line); background: #f8faf9; }
.user-item { width: 100%; min-height: 62px; display: flex; flex-direction: column; justify-content: center; align-items: flex-start; gap: 5px; padding: 10px 13px; border: 0; border-bottom: 1px solid var(--line); background: transparent; color: var(--ink); text-align: left; }
.user-item:hover { background: #eef3f1; }
.user-item.active { background: #e2eee9; box-shadow: inset 3px 0 var(--green); }
.user-item.disabled { opacity: .58; }
.user-item strong { font-size: 14px; }
.user-item em { max-width: 100%; overflow: hidden; color: #45544d; font-size: 12px; font-style: normal; text-overflow: ellipsis; white-space: nowrap; }
.user-item span { color: var(--muted); font-size: 11px; }
.permission-panel { min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.permission-head { min-height: 66px; display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.permission-head h3 { margin: 0 0 4px; font-size: 16px; }
.permission-head span { color: var(--muted); font-size: 11px; }
.permission-head > div:last-child { display: flex; gap: 7px; }
.user-note-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 9px 14px; border-bottom: 1px solid var(--line); }
.permission-tools { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.permission-tools label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; white-space: nowrap; }
.permission-tools label input { width: 16px; height: 16px; }
.permission-batch { display: flex; justify-content: flex-end; gap: 7px; padding: 8px 14px; border-bottom: 1px solid var(--line); background: #fafbfb; }
.permission-batch select { min-width: 120px; }
.permission-list { flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; padding: 7px; }
.permission-item { min-width: 0; display: grid; grid-template-columns: 18px minmax(0, 1fr); align-items: center; gap: 7px 8px; padding: 9px; border-radius: 4px; }
.permission-item:hover { background: #f1f5f3; }
.permission-item.expired { background: #fff8ed; }
.permission-check { width: 16px !important; height: 16px !important; }
.permission-expiry { grid-column: 2; width: 100%; min-width: 0; height: 30px !important; padding: 0 6px !important; font-size: 10px !important; }
.permission-expiry:disabled { background: #f1f3f4; }
.permission-item span { min-width: 0; }
.permission-item strong, .permission-item small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.permission-item strong { font-size: 13px; }
.permission-item small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.permission-panel > .dialog-actions { min-height: 58px; align-items: center; padding: 9px 14px; border-top: 1px solid var(--line); }
.permission-panel > .dialog-actions span { margin-right: auto; color: var(--muted); font-size: 12px; }
.credential-content { width: min(500px, calc(100vw - 32px)); }
.credential-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; margin-bottom: 12px; }
.credential-row input { min-width: 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.integration-toolbar { display: flex; gap: 8px; margin-bottom: 12px; }
.integration-layout { height: min(650px, 70vh); }
.integration-layout .permission-panel { overflow-y: auto; }
.integration-layout .permission-head, .integration-layout .integration-stats { flex-shrink: 0; }
.integration-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border-bottom: 1px solid var(--line); background: #f8faf9; }
.integration-stats div { min-width: 0; padding: 11px 14px; border-right: 1px solid var(--line); }
.integration-stats div:last-child { border-right: 0; }
.integration-stats strong, .integration-stats span { display: block; }
.integration-stats strong { font-size: 17px; }
.integration-stats span { margin-top: 3px; color: var(--muted); font-size: 10px; }
.integration-section { min-height: 0; flex-shrink: 0; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.integration-section.compact { flex: 0 0 auto; }
.section-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 8px; }
.section-title strong { font-size: 13px; }
.section-title span { color: var(--muted); font-size: 10px; }
.integration-room-list { max-height: 220px; overflow-y: auto; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-content: start; margin-top: 8px; border: 1px solid var(--line); }
.integration-room { min-width: 0; display: grid; grid-template-columns: 18px minmax(0, 1fr); align-items: center; gap: 8px; padding: 8px; border-bottom: 1px solid var(--line); }
.integration-room:nth-child(odd) { border-right: 1px solid var(--line); }
.integration-room input { width: 16px; height: 16px; }
.integration-room strong, .integration-room small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.integration-room strong { font-size: 12px; }
.integration-room small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.integration-key-row, .integration-log-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; padding: 6px 0; font-size: 11px; }
.integration-key-row code, .integration-log-row code { overflow: hidden; color: #405a4e; text-overflow: ellipsis; white-space: nowrap; }
.integration-key-row span, .integration-log-row span, .integration-log-row time { color: var(--muted); }
.integration-log-list { max-height: 105px; overflow-y: auto; }
.integration-log-row { grid-template-columns: 145px 90px 90px minmax(0, 1fr); border-bottom: 1px solid var(--line); }
.integration-actions { margin-top: auto !important; padding: 10px 14px; border-top: 1px solid var(--line); }
.integration-actions .danger { margin-right: auto; color: #a22d2d; }
.integration-create-form { min-height: 0; display: flex; flex: 1; flex-direction: column; overflow: hidden; }
.integration-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 12px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.integration-edit-fields { flex-shrink: 0; }
.integration-fields label { color: var(--muted); font-size: 10px; }
.integration-fields input, .integration-fields select { width: 100%; margin-top: 4px; }
.integration-key-content { width: min(620px, calc(100vw - 32px)); }
.code-example { width: 100%; resize: none; font: 11px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; }
.audit-list { max-height: min(650px, 72vh); overflow: auto; border: 1px solid var(--line); }
.audit-row { min-height: 52px; display: grid; grid-template-columns: 150px 110px 90px minmax(130px, 1fr) 130px; align-items: center; gap: 10px; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 12px; }
.audit-row:last-child { border-bottom: 0; }
.audit-row:nth-child(even) { background: #fafbfb; }
.audit-row time, .audit-row small { color: var(--muted); }
.audit-row strong, .audit-row span, .audit-row code, .audit-row small { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.audit-row code { color: #4f635a; font: 11px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; }

@media (max-width: 720px) {
  .topbar { padding: 0 11px; }
  .brand strong, #session-pill, #archive-pill { display: none; }
  .top-actions { gap: 6px; }
  .top-actions .command-button { display: none; }
  .admin-menu:not([hidden]) { display: block; }
  .workspace { display: block; }
  .room-pane { width: 100%; height: 100%; border-right: 0; }
  .message-pane { display: none; height: 100%; }
  .app-shell.show-messages .room-pane { display: none; }
  .app-shell.show-messages .message-pane { display: block; }
  .mobile-only { display: inline-block; flex: 0 0 auto; }
  .message-header { padding: 9px 11px; }
  .message-list { padding: 15px 11px 30px; }
  .new-message-button { right: 14px; bottom: 14px; }
  .room-heading h2 { font-size: 16px; }
  .limit-control { font-size: 0; }
  .limit-control select { font-size: 12px; }
  .login-panel { padding: 25px; }
  .current-user { display: none; }
  .wide-dialog { width: calc(100% - 16px); }
  .dialog-content { padding: 14px; }
  .create-user-row { grid-template-columns: 1fr; }
  .admin-layout { height: 68vh; grid-template-columns: 120px minmax(0, 1fr); }
  .permission-list { grid-template-columns: 1fr; }
  .permission-head { align-items: flex-start; }
  .permission-head > div:last-child { flex-direction: column; }
  .permission-tools { grid-template-columns: 1fr; }
  .user-note-row { grid-template-columns: 1fr; }
  .integration-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .integration-room-list, .integration-fields { grid-template-columns: 1fr; }
  .integration-room:nth-child(odd) { border-right: 0; }
  .integration-log-row { grid-template-columns: 1fr auto; }
  .integration-log-row code, .integration-log-row time { display: none; }
  .integration-layout .permission-head { flex-direction: column; align-items: stretch; }
  .integration-layout .permission-head > div:last-child { flex-direction: row; }
  .integration-layout .permission-head > div:last-child button { min-width: 0; flex: 1; padding-inline: 6px; font-size: 11px; white-space: nowrap; }
  .audit-row { grid-template-columns: 120px 1fr 80px; }
  .audit-row code, .audit-row small { display: none; }
}
