:root {
  --bg: #f5f7f5;
  --panel: #ffffff;
  --panel-soft: #fbfdfb;
  --line: #e2e8e3;
  --line-strong: #cbd7ce;
  --text: #17221d;
  --muted: #66736c;
  --muted-2: #8a958f;
  --wechat: #07c160;
  --wechat-deep: #05a854;
  --wechat-soft: #e9f8f0;
  --bubble-green: #d9f8cf;
  --amber: #9a5c00;
  --amber-soft: #fff4d8;
  --red: #c0352b;
  --red-soft: #fdecea;
  --ink-soft: #eef2ef;
  --shadow: 0 18px 60px rgba(23, 34, 29, 0.16);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  padding: 0 12px;
  cursor: pointer;
  transition:
    border-color 0.16s ease,
    background 0.16s ease,
    color 0.16s ease,
    box-shadow 0.16s ease;
}

button:hover {
  border-color: var(--wechat);
  color: var(--wechat-deep);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid rgba(7, 193, 96, 0.26);
  outline-offset: 1px;
  border-color: var(--wechat);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button.primary {
  border-color: var(--wechat);
  background: var(--wechat);
  color: #fff;
}

button.primary:hover {
  border-color: var(--wechat-deep);
  background: var(--wechat-deep);
  color: #fff;
}

button.ghost {
  border-color: transparent;
  background: var(--wechat-soft);
  color: var(--wechat-deep);
}

button.ghost:hover {
  border-color: rgba(7, 193, 96, 0.28);
  background: #ddf4e8;
}

input,
select,
textarea {
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

textarea {
  line-height: 1.45;
}

input::placeholder,
textarea::placeholder {
  color: var(--muted-2);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 20px;
  line-height: 1.2;
  font-weight: 760;
}

h2 {
  font-size: 15px;
  font-weight: 720;
}

h3 {
  font-size: 15px;
  line-height: 1.35;
  font-weight: 720;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  height: 76px;
  padding: 12px 18px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.brand-block {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  flex: none;
  color: #fff;
  background: var(--wechat);
  font-weight: 800;
  box-shadow: inset 0 -1px 0 rgba(0, 0, 0, 0.08);
}

.topbar p,
.account-meta,
.chat-header p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.create-account {
  display: flex;
  gap: 8px;
}

.create-account input {
  width: 190px;
  height: 36px;
  padding: 0 11px;
}

.workspace {
  height: calc(100vh - 76px);
  display: grid;
  grid-template-columns: 360px 340px minmax(0, 1fr);
  min-width: 0;
}

.accounts-panel,
.inbox-panel,
.chat-panel {
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

.accounts-panel {
  background: var(--panel-soft);
}

.chat-panel {
  border-right: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto 220px;
}

.panel-head,
.chat-header {
  min-height: 56px;
  padding: 12px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-head.compact {
  min-height: 42px;
}

#accountFilter {
  width: 148px;
  height: 34px;
  padding: 0 9px;
  color: var(--muted);
}

.accounts-list,
.conversation-list,
.message-list,
.reply-logs {
  overflow: auto;
}

.accounts-list {
  height: calc(100vh - 132px);
  padding: 10px;
}

.account-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fff;
  box-shadow: 0 1px 0 rgba(23, 34, 29, 0.03);
}

.account-main,
.account-controls,
.account-buttons,
.delay-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.account-main > div {
  min-width: 0;
}

.account-main h3,
.account-meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-controls,
.account-buttons {
  margin-top: 10px;
}

.account-buttons button {
  flex: 1;
  min-width: 0;
  padding: 0 8px;
  white-space: normal;
}

.status-badge {
  flex: none;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  color: var(--muted);
  background: var(--ink-soft);
}

.status-running {
  background: var(--wechat-soft);
  color: var(--wechat-deep);
}

.status-error,
.status-login_required {
  background: var(--red-soft);
  color: var(--red);
}

.status-stopped {
  background: var(--amber-soft);
  color: var(--amber);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.toggle input {
  accent-color: var(--wechat);
}

.file-button {
  height: 34px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--wechat-deep);
  background: var(--wechat-soft);
  font-size: 13px;
}

.file-button input {
  display: none;
}

details {
  margin-top: 10px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}

details label {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

details textarea {
  width: 100%;
  min-height: 58px;
  resize: vertical;
  padding: 8px;
  margin-top: 4px;
}

.delay-row label {
  flex: 1;
}

.delay-row input {
  width: 100%;
  height: 32px;
  padding: 0 8px;
  margin-top: 4px;
}

.save-rule-btn {
  margin-top: 8px;
  width: 100%;
}

.conversation-list {
  height: calc(100vh - 132px);
}

.conversation-item {
  width: 100%;
  min-height: 88px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  padding: 12px;
  text-align: left;
  background: #fff;
  display: block;
}

.conversation-item:hover {
  background: #f5fbf7;
}

.conversation-item.active {
  background: var(--wechat-soft);
}

.conversation-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
}

.conversation-title {
  max-width: 230px;
  font-weight: 720;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.conversation-account,
.conversation-last,
.conversation-time {
  color: var(--muted);
  font-size: 12px;
}

.conversation-last {
  margin-top: 7px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.conversation-time {
  margin-top: 6px;
}

.unread-dot {
  min-width: 20px;
  height: 20px;
  border-radius: 10px;
  display: inline-grid;
  place-items: center;
  flex: none;
  background: #fa5151;
  color: #fff;
  font-size: 12px;
}

.message-list {
  padding: 18px;
  background: #ededed;
}

.empty-state {
  display: grid;
  place-items: center;
  color: var(--muted);
}

.empty-state.tall {
  min-height: 160px;
}

.compact-empty {
  min-height: 100px;
}

.message-row {
  margin-bottom: 12px;
  display: flex;
}

.message-row.outgoing {
  justify-content: flex-end;
}

.bubble {
  max-width: min(620px, 72%);
  border: 1px solid #dde2de;
  border-radius: 8px;
  padding: 9px 11px;
  background: #fff;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.outgoing .bubble {
  border-color: #bde9b3;
  background: var(--bubble-green);
}

.message-meta {
  margin-top: 5px;
  color: var(--muted);
  font-size: 11px;
}

.chat-actions {
  min-height: 56px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.log-panel {
  min-height: 0;
  border-top: 1px solid var(--line);
  background: #fff;
}

.reply-logs {
  height: 178px;
}

.log-item {
  padding: 9px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
}

.log-title {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-weight: 720;
}

.log-title span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.log-body {
  margin-top: 4px;
  color: var(--muted);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  padding: 28px;
  background: rgba(18, 25, 21, 0.52);
  display: grid;
  place-items: center;
}

.modal-card {
  width: min(1120px, 100%);
  max-height: calc(100vh - 56px);
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: auto minmax(280px, 1fr) auto;
  overflow: hidden;
}

.modal-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.modal-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.browser-shot-wrap {
  min-height: 360px;
  max-height: calc(100vh - 210px);
  padding: 12px;
  background: #222724;
  display: grid;
  place-items: center;
  overflow: auto;
}

.browser-shot-wrap img {
  width: 100%;
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  background: #fff;
  opacity: 1;
  transition: opacity 0.16s ease;
}

.browser-shot-wrap img:not([src]) {
  min-height: 320px;
}

.browser-shot-wrap img.loading {
  opacity: 0.55;
}

.modal-actions {
  padding: 12px 16px;
  border-top: 1px solid var(--line);
  display: flex;
  justify-content: flex-end;
}

.toast {
  position: fixed;
  top: 88px;
  right: 18px;
  z-index: 60;
  max-width: min(420px, calc(100vw - 36px));
  border-radius: 8px;
  padding: 11px 13px;
  color: #fff;
  background: #19251f;
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.45;
}

.toast-success {
  background: #19251f;
}

.toast-error {
  background: var(--red);
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 330px 310px minmax(0, 1fr);
  }
}

@media (max-width: 980px) {
  .topbar {
    height: auto;
    align-items: flex-start;
    flex-direction: column;
  }

  .create-account {
    width: 100%;
  }

  .create-account input {
    flex: 1;
    min-width: 0;
  }

  .workspace {
    height: auto;
    min-height: calc(100vh - 124px);
    grid-template-columns: 1fr;
  }

  .accounts-panel,
  .inbox-panel,
  .chat-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .accounts-list,
  .conversation-list {
    height: auto;
    max-height: 420px;
  }

  .chat-panel {
    min-height: 640px;
    grid-template-rows: auto minmax(320px, 1fr) auto 220px;
  }

  .conversation-title {
    max-width: calc(100vw - 96px);
  }

  .modal {
    padding: 12px;
  }

  .browser-shot-wrap {
    min-height: 300px;
    max-height: calc(100vh - 190px);
  }
}

@media (max-width: 520px) {
  .brand-mark {
    width: 40px;
    height: 40px;
  }

  h1 {
    font-size: 18px;
  }

  .account-buttons {
    display: grid;
    grid-template-columns: 1fr;
  }

  .bubble {
    max-width: 88%;
  }
}
