:root {
  --bg: #ffffff;
  --side: #f3f3f5;
  --line: #e6e6ea;
  --text: #1b1b1b;
  --muted: #8a8a8a;
  --hover: #ececf0;
  --active: #e4e4e8;
  --bubble: #1a1a1a;
  --in: #f3f3f5;
  --purple: #7c5cbf;
  --blue: #4f8edc;
  --teal: #2aa7a1;
  --green: #3d9a6a;
  --orange: #d9893b;
  --ok: #16a34a;
  --bad: #dc2626;
  --warn: #d97706;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

.sync-state {
  padding: 0 14px 8px;
  color: var(--muted);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.conv-name small {
  color: var(--muted);
  font-size: 10px;
  font-weight: normal;
}

.bubble.bot {
  white-space: pre-wrap;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, "PingFang SC", "Noto Sans SC", sans-serif;
}

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

a {
  color: inherit;
}

#login {
  position: fixed;
  inset: 0;
  background: var(--side);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

#login .box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px;
  width: min(360px, 92vw);
  text-align: center;
  box-shadow: 0 10px 40px #00000014;
}

#login h1 {
  font-size: 18px;
  margin-bottom: 6px;
}

#login p {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 16px;
}

#login input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 12px;
}

#login button {
  width: 100%;
  background: #111;
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 10px;
  cursor: pointer;
}

#login .err {
  color: var(--bad);
  font-size: 12px;
  min-height: 16px;
  margin-top: 8px;
}

.app {
  display: flex;
  height: 100%;
  min-height: 0;
  position: relative;
}

.sidebar {
  width: 290px;
  background: var(--side);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow: hidden;
}

.side-top {
  padding: 12px 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.acc-select-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.acc-select-row select {
  flex: 1;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 6px 8px;
  font-size: 13px;
  min-width: 0;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.search {
  flex: 1;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.search input {
  border: 0;
  outline: 0;
  width: 100%;
  background: transparent;
  font-size: 13px;
}

.icon-btn {
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  color: #444;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--hover);
}

.sec-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  padding: 8px 12px 4px;
  text-transform: uppercase;
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 10px;
}

.conv {
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border-radius: 10px;
  cursor: pointer;
  overflow: hidden;
  margin-bottom: 2px;
}

.conv:hover {
  background: var(--hover);
}

.conv.on {
  background: var(--active);
}

.conv.off {
  opacity: 0.55;
}

.avatar {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 650;
  font-size: 13px;
  flex-shrink: 0;
  background: var(--purple);
}

.avatar.sm {
  width: 28px;
  height: 28px;
  min-width: 28px;
  font-size: 12px;
}

.conv-body {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.conv-row {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  align-items: baseline;
}

.conv-name {
  font-weight: 600;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-time {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}

.conv-preview {
  font-size: 12px;
  color: #6b6b73;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #d1d5db;
  flex-shrink: 0;
}

.dot.on {
  background: var(--ok);
}

.dot.run {
  background: var(--orange);
  box-shadow: 0 0 0 3px #d9893b33;
}

.dot.bad {
  background: var(--bad);
}

.side-foot {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.foot-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 8px;
  text-decoration: none;
  color: #333;
  font-size: 13px;
  border: 0;
  background: transparent;
  cursor: pointer;
  text-align: left;
  width: 100%;
}

.foot-link:hover {
  background: var(--hover);
}

.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: #fff;
}

.main-head {
  height: 56px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  flex-shrink: 0;
}

.main-head h2 {
  font-size: 15px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
  flex: 1;
}

.head-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.pill-btn {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}

.pill-btn:hover {
  background: var(--side);
}

.msgs {
  flex: 1;
  overflow-y: auto;
  padding: 20px 6% 28px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.load-older {
  align-self: center;
  border: 1px solid var(--line);
  background: var(--side);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 12px;
  cursor: pointer;
  color: #555;
}

.row {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-width: min(680px, 86%);
}

.row.user {
  align-self: flex-end;
  align-items: flex-end;
}

.row.bot {
  align-self: flex-start;
  align-items: flex-start;
}

.bubble {
  max-width: 100%;
  width: fit-content;
  padding: 10px 14px;
  border-radius: 18px;
  word-break: break-word;
  font-size: 14px;
  line-height: 1.55;
}

.bubble.user {
  background: var(--bubble);
  color: #fff;
  border-bottom-right-radius: 6px;
  white-space: pre-wrap;
}

.bubble.bot {
  background: var(--in);
  color: #1b1b1b;
  border-bottom-left-radius: 6px;
}

.bubble pre {
  background: #1e1e2e;
  color: #f8f8f2;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 6px 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
}

.bubble code {
  background: #e4e4e9;
  color: #111;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
}

.bubble pre code {
  background: transparent;
  color: inherit;
  padding: 0;
}

.msg-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 11px;
  color: var(--muted);
  padding: 0 4px;
}

.msg-meta button {
  border: 0;
  background: transparent;
  color: var(--blue);
  cursor: pointer;
  font-size: 11px;
}

.approval-card {
  background: #fffbeb;
  border: 1px solid #f59e0b;
  border-radius: 14px;
  padding: 12px 14px;
  max-width: min(560px, 92%);
  align-self: flex-start;
}

.approval-card .title {
  font-weight: 650;
  color: #92400e;
  margin-bottom: 4px;
  font-size: 13px;
}

.approval-card .sub {
  font-size: 12px;
  color: #78350f;
  margin-bottom: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  word-break: break-all;
}

.approval-card .btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.approval-card button {
  border: 1px solid #d97706;
  background: #fff;
  color: #92400e;
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12px;
  cursor: pointer;
}

.approval-card button.pri {
  background: #111;
  color: #fff;
  border-color: #111;
}

.approval-card button.danger {
  border-color: var(--bad);
  color: var(--bad);
}

.composer {
  padding: 10px 16px 16px;
  border-top: 1px solid var(--line);
  flex-shrink: 0;
}

.att-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.att-chip {
  background: var(--side);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.att-chip button {
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--bad);
}

.composer-box {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 6px 10px;
  box-shadow: 0 1px 4px #00000010;
}

.composer-box textarea {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  resize: none;
  max-height: 120px;
  min-height: 24px;
  padding: 6px 4px;
}

.composer-box button.send {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  background: #111;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}

.composer-box button.send:disabled {
  background: #ddd;
  color: #999;
  cursor: not-allowed;
}

.composer-box button.stop {
  background: var(--bad);
}

.err-banner {
  color: var(--bad);
  font-size: 12px;
  margin-top: 6px;
  padding: 0 8px;
}

.right {
  width: 310px;
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  background: #fff;
  flex-shrink: 0;
  overflow-y: auto;
  padding: 14px;
  gap: 14px;
}

.card-sec {
  background: var(--side);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
}

.card-sec h3 {
  font-size: 13px;
  font-weight: 650;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.kv-row {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 3px 0;
  gap: 8px;
}

.kv-row .k {
  color: var(--muted);
}

.kv-row .v {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
}

.screen {
  background: #e6e6ec;
  border-radius: 10px;
  height: 140px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  margin-bottom: 8px;
  text-decoration: none;
  color: #444;
  font-size: 12px;
}

.quick-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.quick-btns button, .quick-btns a {
  border: 1px solid #d4d4d8;
  background: #fff;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
  text-decoration: none;
}

.quick-btns button:hover, .quick-btns a:hover {
  background: var(--hover);
}

.hint {
  text-align: center;
  font-size: 12px;
  color: var(--muted);
  padding: 16px;
}

.menu-btn, .panel-btn {
  display: none;
}

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: #0004;
  z-index: 15;
}

@media (max-width: 960px) {
  .right {
    display: none;
    position: fixed;
    top: 56px;
    right: 0;
    bottom: 0;
    z-index: 25;
    width: min(320px, 90vw);
    box-shadow: -8px 0 24px #0002;
  }
  .right.open {
    display: flex;
  }
  .panel-btn {
    display: inline-flex;
  }
}

@media (max-width: 720px) {
  .app {
    height: 100dvh;
  }
  #head-state {
    display: none;
  }
  .main-head {
    padding: 0 10px;
    gap: 6px;
  }
  .head-actions {
    gap: 4px;
  }
  .head-actions .pill-btn {
    padding: 4px 7px;
  }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 26;
    width: min(300px, 86vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .sidebar.open {
    transform: none;
    box-shadow: 8px 0 24px #0002;
  }
  .scrim.open {
    display: block;
  }
  .menu-btn {
    display: inline-flex;
  }
  .msgs {
    padding: 14px 12px 20px;
  }
  .row {
    max-width: 94%;
  }
}
