body.chat-page {
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  background: #080b14;
  color: #f5f7ff;
}

.cw-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 30;
  width: 300px;
  background: #101321;
  border-right: 1px solid rgba(255,255,255,.1);
  display: flex;
  flex-direction: column;
}

.cw-side-head, .cw-topbar {
  height: 72px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 18px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}

.cw-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #ffd23f;
  font-weight: 900;
  text-decoration: none;
  font-size: 22px;
}

.cw-brand img { width: 36px; height: 36px; object-fit: contain; }
.cw-close, #openSidebar { display: none; }

.cw-icon-btn, .cw-btn, .cw-new, .cw-composer button, .cw-quick button {
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.06);
  color: #f5f7ff;
  cursor: pointer;
  min-height: 40px;
}

.cw-icon-btn {
  width: 42px;
  border-radius: 8px;
  font-size: 22px;
}

.cw-new {
  margin: 16px;
  border-radius: 8px;
  font-weight: 800;
}

.cw-history {
  flex: 1;
  overflow: auto;
  padding: 0 10px 18px;
}

.cw-group-title {
  color: #8e98b8;
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  margin: 18px 8px 8px;
}

.cw-history-item {
  width: 100%;
  position: relative;
  display: block;
  text-align: left;
  border: 0;
  border-radius: 0;
  padding: 7px 8px 7px 22px;
  background: transparent;
  color: #dbe2ff;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cw-history-item::before {
  content: "•";
  position: absolute;
  left: 8px;
  color: #ffd23f;
}

.cw-history-item.active, .cw-history-item:hover {
  background: transparent;
  color: #fff;
}

.cw-main {
  margin-left: 300px;
  min-height: 100vh;
  height: 100vh;
  display: grid;
  grid-template-rows: 44px 1fr auto;
}

.cw-topbar {
  height: 44px;
  padding: 0 14px;
  justify-content: flex-end;
  background: rgba(12,15,28,.88);
  backdrop-filter: blur(12px);
}

.cw-title-wrap[hidden] { display: none !important; }
.cw-title-wrap { min-width: 0; flex: 1; }
.cw-title-wrap h1 {
  margin: 0;
  font-size: 18px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cw-title-wrap span { color: #9da8ca; font-size: 13px; }
.cw-actions { display: flex; gap: 8px; margin-left: auto; }
.cw-btn { border-radius: 8px; padding: 0 12px; font-weight: 700; }
.cw-btn.danger { color: #ffb4b4; }
.cw-delete-icon {
  width: 34px;
  height: 34px;
  min-height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #ffb4b4;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}
.cw-delete-icon:hover {
  background: rgba(255,180,180,.1);
}

.cw-messages {
  overflow: auto;
  padding: 18px max(18px, calc((100vw - 300px - 820px) / 2)) 140px;
}

.cw-msg {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  gap: 12px;
  margin: 0 0 20px;
}

.cw-avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, #5677ff, #8a5cff);
  font-weight: 900;
}

.cw-bubble {
  background: #202438;
  border: 1px solid rgba(255,255,255,.09);
  border-radius: 8px;
  padding: 16px 18px;
  line-height: 1.65;
  overflow-wrap: anywhere;
}

.cw-msg.user .cw-bubble {
  background: linear-gradient(135deg, #5574ff, #8758f2);
  border: 0;
}

.cw-bubble p {
  margin: 0 0 12px;
}

.cw-bubble p:last-child {
  margin-bottom: 0;
}

.cw-bubble ul,
.cw-bubble ol {
  margin: 8px 0 12px 20px;
  padding: 0;
}

.cw-bubble li {
  margin: 4px 0;
}

.cw-tools {
  margin-top: 10px;
  display: flex;
  gap: 8px;
}

.cw-tool {
  border: 0;
  border-radius: 8px;
  padding: 7px 10px;
  background: rgba(255,255,255,.08);
  color: #cdd6fb;
  cursor: pointer;
}

.cw-tool.active {
  background: rgba(255,210,63,.2);
  color: #ffd23f;
}

.cw-route-card {
  margin-top: 12px;
}

.cw-route-card p {
  margin: 8px 0 0;
  color: #aab5d8;
}

.cw-route-card ul {
  margin: 8px 0 0 18px;
  padding: 0;
  color: #aab5d8;
}

.cw-message-tools {
  grid-column: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: -10px;
  margin-bottom: 2px;
}

.cw-workflow-actions {
  grid-column: 2;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: -8px;
}

.cw-workflow-btn {
  min-height: 34px;
  border: 1px solid rgba(255,210,63,.3);
  border-radius: 8px;
  padding: 0 12px;
  background: rgba(255,210,63,.12);
  color: #ffd23f;
  font-weight: 800;
  cursor: pointer;
}

.cw-workflow-btn:hover {
  background: rgba(255,210,63,.2);
}

.cw-workflow-btn:disabled {
  opacity: .55;
  cursor: wait;
}

.cw-icon-tool {
  width: 28px;
  height: 28px;
  min-height: 28px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #9da8ca;
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
}

.cw-icon-tool:hover,
.cw-icon-tool.active {
  color: #ffd23f;
  background: rgba(255,210,63,.08);
}

.cw-sources {
  margin-top: 10px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px 10px;
}

.cw-sources-title {
  color: #9da8ca;
  font-size: 11px;
  font-weight: 700;
}

.cw-source-link {
  color: #9fb0dc;
  font-size: 12px;
  line-height: 1.4;
  text-decoration: underline;
  text-decoration-color: rgba(159,176,220,.35);
  text-underline-offset: 3px;
}

.cw-bubble pre {
  overflow: auto;
  background: #090d18;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px;
  padding: 14px;
}

.cw-bubble code {
  background: rgba(255,255,255,.08);
  padding: 2px 5px;
  border-radius: 5px;
}

.cw-bubble pre code { background: transparent; padding: 0; }
.cw-bubble a { color: #8fb3ff; }
 .cw-bubble blockquote {
  border-left: 3px solid #7c8cff;
  margin: 10px 0;
  padding-left: 12px;
  color: #c8d0ee;
}

.cw-memory-card {
  border-color: rgba(255,210,63,.35);
  background: #222337;
}

.cw-memory-card p {
  margin: 8px 0 0;
  color: #dce3ff;
}

.cw-empty {
  position: fixed;
  left: 300px;
  right: 0;
  top: 28vh;
  text-align: center;
  padding: 0 20px;
}

.cw-empty.hidden { display: none; }
.cw-empty h2 { font-size: clamp(28px, 4vw, 46px); margin: 0 0 24px; }
.cw-quick { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; }
.cw-quick button { border-radius: 8px; padding: 0 14px; }

.cw-composer {
  position: fixed;
  left: 300px;
  right: 0;
  bottom: 0;
  padding: 14px max(18px, calc((100vw - 300px - 820px) / 2));
  background: linear-gradient(180deg, rgba(8,11,20,0), #080b14 22%);
}

.cw-composer-box {
  display: grid;
  gap: 8px;
  border: 1px solid rgba(102,132,255,.75);
  border-radius: 8px;
  background: #11172a;
  padding: 10px;
}

.cw-input-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.cw-composer textarea {
  width: 100%;
  box-sizing: border-box;
  resize: none;
  max-height: 180px;
  min-height: 48px;
  border: 0;
  outline: 0;
  background: transparent;
  color: #fff;
  padding: 4px 2px;
  font: inherit;
}

.cw-composer button {
  border-radius: 8px;
  min-height: 34px;
  padding: 0 12px;
  font-weight: 900;
  background: linear-gradient(135deg, #5677ff, #8a5cff);
  border: 0;
}

.cw-attach-btn {
  width: 34px;
  min-width: 34px;
  height: 34px;
  padding: 0 !important;
  font-size: 22px;
}

#sendChat {
  min-width: 64px;
  height: 34px;
}

.cw-attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.cw-attachment {
  position: relative;
  width: 86px;
  height: 86px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.16);
  background: #141a2e;
}

.cw-attachment.document {
  width: min(260px, 100%);
}

.cw-attachment img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cw-doc-card {
  height: 100%;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr);
  grid-template-rows: 1fr 1fr;
  gap: 0 8px;
  align-items: center;
  padding: 10px 34px 20px 10px;
}

.cw-doc-card span {
  grid-row: 1 / span 2;
  font-size: 22px;
}

.cw-doc-card b,
.cw-doc-card small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cw-doc-card small {
  color: #aeb8db;
  font-size: 11px;
}

.cw-attachment.pending::after,
.cw-attachment.uploading::after {
  content: attr(data-label);
  position: absolute;
  inset: auto 0 0;
  padding: 4px;
  background: rgba(0,0,0,.64);
  color: #fff;
  font-size: 11px;
  text-align: center;
}

.cw-attachment button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  min-height: 24px;
  padding: 0 !important;
  border-radius: 50%;
  background: rgba(0,0,0,.7);
  color: #fff;
}

.cw-msg-images {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 180px));
  gap: 10px;
  margin-bottom: 10px;
}

.cw-msg-images a {
  display: block;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.14);
}

.cw-msg-images a.cw-doc-link {
  aspect-ratio: auto;
  min-height: 76px;
  display: grid;
  grid-template-columns: 34px minmax(0, 1fr);
  grid-template-rows: auto auto;
  gap: 2px 8px;
  align-items: center;
  padding: 12px;
  text-decoration: none;
  color: #f5f7ff;
  background: rgba(255,255,255,.05);
}

.cw-doc-link span { grid-row: 1 / span 2; font-size: 24px; }
.cw-doc-link b,
.cw-doc-link small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cw-doc-link small { color: #aeb8db; font-size: 12px; }

.cw-msg-images img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cw-drop {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 80;
  place-items: center;
  background: rgba(8,11,20,.78);
  color: #fff;
  font-size: clamp(24px, 4vw, 42px);
  font-weight: 900;
}

.cw-drop.show { display: grid; }

.cw-backdrop { display: none; }

@media (max-width: 860px) {
  .cw-sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
  }
  .cw-sidebar.open { transform: translateX(0); }
  .cw-close, #openSidebar { display: grid; place-items: center; }
  .cw-main, .cw-empty, .cw-composer { margin-left: 0; left: 0; }
  .cw-actions .cw-btn { padding: 0 9px; }
  .cw-messages { padding-left: 14px; padding-right: 14px; }
  .cw-backdrop.open {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 20;
    background: rgba(0,0,0,.45);
  }
}

@media (max-width: 520px) {
  .cw-sidebar { width: min(86vw, 320px); }
  .cw-topbar { padding: 0 10px; }
  .cw-actions { gap: 4px; }
  .cw-btn { font-size: 12px; }
  .cw-msg { grid-template-columns: 32px minmax(0, 1fr); }
  .cw-avatar { width: 32px; height: 32px; }
  .cw-bubble { padding: 13px; }
  .cw-composer { padding: 12px 10px; }
  .cw-composer button { padding: 0 14px; }
  .cw-attach-btn { width: 34px; min-width: 34px; height: 34px; }
}
