:root {
  --bg: #dfe5ec;
  --hint: #9aa6b4;
  --panel: #f4f6f8;
  --card: #ffffff;
  --line: #e4e8ee;
  --text: #1c2128;
  --muted: #6b7380;
  --green: #16a34a;
  --green-bg: #e8f8ee;
  --red: #dc2626;
  --orange: #c2410c;
  --blue: #1d4ed8;
  --top: #1b222c;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.workspace {
  min-height: 100vh;
  display: flex;
  justify-content: flex-end;
}

.hint-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 32px;
  color: var(--hint);
  text-align: center;
}

.hint-title {
  margin: 0 0 8px;
  font-size: 18px;
  color: #7b8794;
}

.hint-left p {
  margin: 0;
  max-width: 280px;
  line-height: 1.6;
  font-size: 13px;
}

.panel {
  --panel-width: 400px;
  position: relative;
  width: min(100%, var(--panel-width));
  min-width: 300px;
  min-height: 100vh;
  background: var(--panel);
  border-left: 1px solid #cfd6de;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 16px;
  flex-shrink: 0;
}

.panel-resizer {
  position: absolute;
  left: -3px;
  top: 0;
  bottom: 0;
  width: 10px;
  cursor: ew-resize;
  z-index: 3;
  touch-action: none;
}

.panel-resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 4px;
  width: 2px;
  height: 36px;
  margin-top: -18px;
  border-radius: 2px;
  background: #c5ccd4;
}

.panel-resizer:hover::after,
.panel.resizing .panel-resizer::after {
  background: #60a5fa;
}

body.resizing-panel {
  cursor: ew-resize;
  user-select: none;
}

.topbar {
  background: var(--top);
  color: #f3f5f7;
  padding: 14px 16px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.subtitle {
  margin: 4px 0 0;
  font-size: 12px;
  color: #9aa4b2;
}

.live {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #c5ccd6;
  white-space: nowrap;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #f59e0b;
  display: inline-block;
}

.dot.ok {
  background: #22c55e;
}

.dot.err {
  background: #ef4444;
}

.card {
  margin: 0 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

.card h2 {
  margin: 0 0 8px;
  font-size: 13px;
  font-weight: 650;
}

.muted {
  margin: 0 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

code {
  font-size: 11px;
  background: #eef1f5;
  padding: 1px 4px;
  border-radius: 4px;
}

.toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.toggle-card h2 {
  margin-bottom: 2px;
}

.toggle-card .muted {
  margin: 0;
}

.switch {
  position: relative;
  width: 46px;
  height: 26px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  inset: 0;
  background: #c5ccd4;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.15s;
}

.slider::before {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  left: 3px;
  top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.15s;
}

.switch input:checked + .slider {
  background: var(--green);
}

.switch input:checked + .slider::before {
  transform: translateX(20px);
}

.switch input:checked + .slider-warn {
  background: var(--orange);
}

.dry-row {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.account-form {
  margin-top: 10px;
}

.preview-form {
  display: grid;
  gap: 6px;
}

.preview-form textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  font: inherit;
  font-size: 13px;
  resize: vertical;
}

.preview-form textarea:focus {
  outline: 2px solid #bfdbfe;
  border-color: #93c5fd;
}

.preview-form button {
  justify-self: end;
  border: 0;
  border-radius: 6px;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  background: var(--top);
  color: #fff;
}

.preview-result {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.55;
  color: #1e3a5f;
  background: #eff6ff;
  border-radius: 8px;
  padding: 8px;
  white-space: pre-wrap;
  word-break: break-word;
}

.banner.safe {
  background: #ecfdf5;
  color: #166534;
  border-color: #bbf7d0;
}

.banner.live {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}

.stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.stat {
  background: #f7f8fa;
  border-radius: 8px;
  padding: 8px 4px;
  text-align: center;
}

.stat span {
  display: block;
  font-size: 18px;
  font-weight: 650;
}

.stat label {
  display: block;
  margin-top: 2px;
  font-size: 11px;
  color: var(--muted);
}

.meta {
  margin: 0;
  display: grid;
  gap: 6px;
}

.meta div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
}

.meta dt {
  color: var(--muted);
}

.meta dd {
  margin: 0;
  text-align: right;
  word-break: break-all;
}

.allow-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  margin-bottom: 8px;
}

.allow-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  font: inherit;
  font-size: 13px;
}

.allow-form input:focus {
  outline: 2px solid #bfdbfe;
  border-color: #93c5fd;
}

.allow-form input[name="note"] {
  grid-column: 1 / -1;
}

.allow-form button,
.ghost,
.remove {
  border: 0;
  border-radius: 6px;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.allow-form button {
  background: var(--top);
  color: #fff;
}

.ghost {
  background: #eef1f5;
  color: var(--text);
}

.remove {
  background: #fef2f2;
  color: var(--red);
  padding: 4px 8px;
  font-size: 12px;
}

.allow-list,
.log-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.allow-list {
  max-height: 180px;
  overflow: auto;
}

.allow-item,
.empty {
  font-size: 12px;
}

.allow-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.allow-item .id {
  font-weight: 600;
  word-break: break-all;
}

.allow-item .note {
  color: var(--muted);
}

.empty {
  color: var(--muted);
  padding: 8px 0 0;
}

.desk-card {
  flex: 1.4;
  min-height: 480px;
  display: flex;
  flex-direction: column;
}

.thread-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  max-height: 180px;
  overflow: auto;
}

.thread-item {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 7px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 12px;
}

.thread-item.active {
  border-color: #93c5fd;
  background: #eff6ff;
}

.thread-item .id {
  font-weight: 650;
  word-break: break-all;
}

.thread-item .note {
  color: var(--muted);
  margin-top: 2px;
}

.thread-item .acct {
  display: inline-block;
  margin-right: 6px;
  padding: 0 5px;
  border-radius: 4px;
  background: #e8eef7;
  color: #334155;
  font-size: 10px;
  font-weight: 650;
  max-width: 100%;
  line-height: 1.4;
}

.desk-filter {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 8px;
  font-size: 12px;
  color: var(--muted);
}

.desk-filter select {
  flex: 1;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.thread-item .unread {
  display: inline-block;
  margin-left: 6px;
  min-width: 16px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  line-height: 16px;
  text-align: center;
}

.desk-chat {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  flex: 1;
}

.desk-meta {
  font-size: 11px;
  color: var(--muted);
  word-break: break-all;
}

.desk-bubbles {
  flex: 1;
  min-height: 220px;
  max-height: 360px;
  overflow: auto;
  background: #f7f8fa;
  border-radius: 8px;
  padding: 8px;
}

.bubble {
  max-width: 92%;
  margin-bottom: 8px;
}

.bubble p {
  margin: 2px 0 0;
  padding: 7px 8px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.bubble .who {
  font-size: 10px;
  color: var(--muted);
}

.bubble.customer {
  cursor: pointer;
}

.bubble.customer p {
  background: #fff;
  border: 1px solid var(--line);
}

.bubble.customer.selected p {
  border-color: #60a5fa;
  background: #eff6ff;
  box-shadow: 0 0 0 2px #bfdbfe;
}

.bubble.staff {
  margin-left: auto;
}

.bubble.staff p {
  background: #dbeafe;
  color: #1e3a5f;
}

.desk-chat textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  font: inherit;
  font-size: 13px;
  resize: vertical;
  min-height: 120px;
  flex-shrink: 0;
}

.desk-chat textarea:focus {
  outline: 2px solid #bfdbfe;
  border-color: #93c5fd;
}

.desk-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-shrink: 0;
}

.desk-actions button,
.desk-actions .primary {
  border: 0;
  border-radius: 6px;
  padding: 7px 12px;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}

.desk-actions button {
  background: #eef1f5;
  color: var(--text);
}

.desk-actions .primary {
  background: var(--top);
  color: #fff;
}

.desk-actions button:disabled {
  opacity: 0.6;
  cursor: default;
}

.desk-hint {
  margin: 0;
}

.link-hint {
  margin: 0 0 8px;
}

.link-list {
  list-style: none;
  margin: 0 0 8px;
  padding: 0;
  max-height: 240px;
  overflow: auto;
}

.link-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-bottom: 6px;
}

.link-title {
  font-size: 13px;
  font-weight: 650;
  word-break: break-word;
}

.link-url {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.link-actions,
.link-form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.link-actions button,
.link-form button {
  border: 0;
  border-radius: 6px;
  padding: 6px 10px;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.link-actions .primary,
.link-form button[type="submit"] {
  background: var(--top);
  color: #fff;
}

.link-actions button:disabled {
  opacity: 0.45;
  cursor: default;
}

.link-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.link-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 7px 8px;
  font: inherit;
  font-size: 13px;
}

.link-form input:focus {
  outline: 2px solid #bfdbfe;
  border-color: #93c5fd;
}

.logs-card {
  min-height: 180px;
  display: flex;
  flex-direction: column;
}

.logs-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.logs-head h2 {
  margin: 0;
}

.log-list {
  margin-top: 8px;
  overflow: auto;
  max-height: 360px;
}

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

.log-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}

.event {
  display: inline-block;
  border-radius: 999px;
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 650;
  background: #eef1f5;
}

.event.ok { background: var(--green-bg); color: #166534; }
.event.warn { background: #ffedd5; color: var(--orange); }
.event.bad { background: #fee2e2; color: #991b1b; }
.event.info { background: #dbeafe; color: var(--blue); }

.time {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  font-size: 11px;
}

.fid {
  color: var(--blue);
  cursor: pointer;
  text-decoration: underline dotted;
}

.detail {
  margin: 4px 0 0;
  color: #4b5563;
  word-break: break-word;
}

.banner,
.toast {
  margin: 0 12px;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
}

.banner {
  background: #fff7ed;
  color: #9a3412;
  border: 1px solid #fed7aa;
}

.toast {
  background: #ecfdf5;
  color: #166534;
  border: 1px solid #bbf7d0;
}

.toast.err {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fecaca;
}

@media (max-width: 560px) {
  .hint-left {
    display: none;
  }

  .workspace {
    display: block;
  }

  .panel {
    width: 100%;
    max-width: none;
    min-width: 0;
    border-left: 0;
  }

  .panel-resizer {
    display: none;
  }
}

body.embed-mode {
  background: var(--panel);
  min-height: 100%;
  height: auto;
  overflow: auto;
}

body.embed-mode .workspace {
  display: block;
  min-height: 100%;
  height: auto;
}

body.embed-mode .panel {
  width: 100%;
  max-width: none;
  min-width: 0;
  height: auto;
  min-height: 100%;
  border-left: 0;
  overflow: visible;
}

body.embed-mode .desk-card {
  flex: none;
  min-height: 0;
  overflow: visible;
}

body.embed-mode .desk-chat {
  flex: none;
  min-height: 0;
}

body.embed-mode .desk-bubbles {
  flex: none;
  min-height: 120px;
  max-height: 180px;
}

body.embed-mode .desk-chat textarea {
  min-height: 88px;
}
