.project-chat-root {
  min-height: 540px;
  color: #172033;
  font-family: var(--crm-font);
}

.project-chat-shell {
  display: grid;
  gap: 14px;
}

.project-chat-heading,
.project-chat-composer,
.project-chat-message,
.project-chat-state {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: #fff;
}

.project-chat-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 16px 18px;
}

.project-chat-heading h2 {
  margin: 0 0 4px;
  font-size: 18px;
  font-weight: 650;
}

.project-chat-heading p,
.project-chat-composer-hint,
.project-chat-state p {
  margin: 0;
  color: #718096;
  font-size: 12px;
  line-height: 1.55;
}

.project-chat-heading-mark {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 8px;
  background: #edf3ff;
  color: #2563eb;
}

.project-chat-heading-mark svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.project-chat-composer {
  overflow: hidden;
}

.project-chat-context {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 39px;
  padding: 8px 12px;
  border-bottom: 1px solid #d7e2f7;
  background: #f5f8ff;
  color: #355987;
  font-size: 12px;
}

.project-chat-context[hidden] {
  display: none;
}

.project-chat-context-copy {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-chat-context button {
  width: 25px;
  height: 25px;
  flex: 0 0 25px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: #e4edff;
  color: #52709c;
  font-size: 17px;
}

.project-chat-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
  min-height: 42px;
  padding: 6px 9px;
  border-bottom: 1px solid #e5eaf0;
  background: #f8fafc;
}

.project-chat-table-tools {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  border-bottom: 1px solid #dce5f3;
  background: #f4f7fc;
}

.project-chat-table-tools[hidden],
.project-chat-link-editor[hidden],
.project-chat-link-error[hidden] {
  display: none;
}

.project-chat-context-label {
  margin-right: 3px;
  color: #6a7990;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
}

.project-chat-table-tools button {
  min-height: 30px;
  padding: 4px 9px;
  border: 1px solid #ccd8e9;
  border-radius: 5px;
  background: #fff;
  color: #465b78;
  font: 550 11px/1 var(--crm-font);
}

.project-chat-table-tools button:hover {
  border-color: #9db5db;
  background: #edf3ff;
  color: #1d4ed8;
}

.project-chat-link-editor {
  display: grid;
  grid-template-columns: minmax(140px, .8fr) minmax(220px, 1.4fr) auto;
  align-items: end;
  gap: 8px 10px;
  padding: 10px;
  border-bottom: 1px solid #dce5f3;
  background: #f4f7fc;
}

.project-chat-link-field {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: #52637b;
  font-size: 11px;
  font-weight: 600;
}

.project-chat-link-field input {
  width: 100%;
  height: 34px;
  padding: 0 9px;
  border: 1px solid #cbd5e1;
  border-radius: 5px;
  background: #fff;
  color: #263246;
  font: 400 12px/1 var(--crm-font);
}

.project-chat-link-field input[aria-invalid="true"] {
  border-color: #c84a55;
  box-shadow: 0 0 0 2px #c84a551a;
}

.project-chat-link-error {
  grid-column: 1 / -1;
  margin: 0;
  color: #a32d35;
  font-size: 11px;
}

.project-chat-link-actions {
  display: flex;
  gap: 7px;
}

.project-chat-link-actions button {
  height: 34px;
  white-space: nowrap;
}

.project-chat-tool {
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: transparent;
  color: #536176;
  font: 600 12px/1 var(--crm-font);
}

.project-chat-tool:hover,
.project-chat-tool.active {
  border-color: #c8d6f0;
  background: #edf3ff;
  color: #1d4ed8;
}

.project-chat-tool:focus-visible,
.project-chat-format-select:focus-visible,
.project-chat-table-tools button:focus-visible,
.project-chat-link-field input:focus-visible,
.project-chat-link-actions button:focus-visible,
.project-chat-message-actions button:focus-visible,
.project-chat-reply-label:focus-visible,
.project-chat-context button:focus-visible {
  outline: 2px solid #2563eb;
  outline-offset: 2px;
}

.project-chat-format-select {
  width: 132px;
  height: 32px;
  padding: 0 28px 0 9px;
  border: 1px solid #d7dee8;
  border-radius: 5px;
  background-color: #fff;
  color: #46566d;
  font: 550 12px/1 var(--crm-font);
}

.project-chat-tool.is-bold { font-weight: 800; }
.project-chat-tool.is-italic { font-style: italic; }
.project-chat-tool-separator { width: 1px; height: 20px; margin: 0 3px; background: #dce2e9; }
.project-chat-editor {
  position: relative;
  display: block;
  width: 100%;
  min-height: 158px;
  max-height: 520px;
  overflow: auto;
  padding: 15px 16px;
  border: 0;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
  color: #263246;
  font: 400 13px/1.62 var(--crm-font);
  white-space: normal;
}

.project-chat-editor:focus {
  border: 0;
  outline: 0;
  box-shadow: inset 0 0 0 2px #2563eb22;
}

.project-chat-editor[data-empty="true"]::before {
  position: absolute;
  top: 15px;
  left: 16px;
  color: #9aa8ba;
  content: attr(data-placeholder);
  pointer-events: none;
}

.project-chat-editor[aria-disabled="true"] {
  background: #fbfcfe;
  color: #7d8999;
}

.project-chat-composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 52px;
  padding: 8px 10px 8px 14px;
  border-top: 1px solid #e5eaf0;
}

.project-chat-composer-actions { display: flex; gap: 7px; }
.project-chat-composer-actions button { height: 34px; }
.project-chat-cancel[hidden] { display: none; }

.project-chat-feed {
  min-width: 0;
}

.project-chat-thread-list {
  display: grid;
  gap: 9px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.project-chat-thread-item {
  position: relative;
  min-width: 0;
}

.project-chat-thread-children {
  position: relative;
  margin: 9px 0 0 26px;
  padding-left: 27px;
}

.project-chat-thread-children::before {
  position: absolute;
  top: -9px;
  bottom: 18px;
  left: 0;
  width: 1px;
  background: #b8c8e5;
  content: "";
}

.project-chat-thread-children > .project-chat-thread-item::before {
  position: absolute;
  top: 23px;
  left: -27px;
  width: 22px;
  height: 12px;
  border-bottom: 1px solid #b8c8e5;
  border-left: 1px solid #b8c8e5;
  border-radius: 0 0 0 8px;
  content: "";
}

.project-chat-thread-children > .project-chat-thread-item::after {
  position: absolute;
  top: 29px;
  left: -7px;
  width: 5px;
  height: 5px;
  border-top: 1px solid #7896c8;
  border-right: 1px solid #7896c8;
  content: "";
  transform: rotate(45deg);
}

.project-chat-message {
  padding: 14px 16px 13px;
}

.project-chat-message:target,
.project-chat-message.is-highlighted {
  border-color: #8fb0fb;
  box-shadow: 0 0 0 2px #2563eb12;
}

.project-chat-message-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
}

.project-chat-avatar {
  display: grid;
  place-items: center;
  width: 29px;
  height: 29px;
  flex: 0 0 29px;
  border-radius: 7px;
  background: #e8eef8;
  color: #335484;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.project-chat-author {
  min-width: 0;
  overflow: hidden;
  color: #2d3a4f;
  font-size: 12px;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-chat-date {
  color: #8a96a6;
  font-size: 11px;
  white-space: nowrap;
}

.project-chat-message-actions {
  display: flex;
  gap: 3px;
  margin-left: auto;
}

.project-chat-message-actions button {
  min-height: 27px;
  padding: 3px 7px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: #63748c;
  font: 550 11px/1 var(--crm-font);
}

.project-chat-message-actions button:hover { background: #f0f4fa; color: #2563eb; }

.project-chat-message-actions .project-chat-delete:hover {
  background: #fff0f1;
  color: #b32631;
}

.project-chat-reply-label {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  max-width: 100%;
  margin: -2px 0 8px 38px;
  padding: 2px 4px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #5b7193;
  font: 550 11px/1.4 var(--crm-font);
  text-align: left;
}

.project-chat-reply-label:hover { background: #f0f4fa; color: #2559a5; }
.project-chat-reply-label span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-chat-reply-arrow { color: #2563eb; font-size: 14px; line-height: 1; }

.project-chat-markdown {
  overflow-wrap: anywhere;
  color: #2d384a;
  font-size: 13px;
  line-height: 1.65;
}

.project-chat-markdown > :first-child { margin-top: 0; }
.project-chat-markdown > :last-child { margin-bottom: 0; }
.project-chat-markdown p { margin: 8px 0; }
.project-chat-markdown h1,
.project-chat-markdown h2,
.project-chat-markdown h3,
.project-chat-markdown h4,
.project-chat-markdown h5,
.project-chat-markdown h6 { margin: 15px 0 7px; color: #202c3e; line-height: 1.3; }
.project-chat-markdown h1 { font-size: 20px; }
.project-chat-markdown h2 { font-size: 18px; }
.project-chat-markdown h3 { font-size: 16px; }
.project-chat-markdown h4,
.project-chat-markdown h5,
.project-chat-markdown h6 { font-size: 14px; }
.project-chat-markdown ul,
.project-chat-markdown ol { margin: 8px 0; padding-left: 24px; }
.project-chat-markdown li + li { margin-top: 3px; }
.project-chat-markdown blockquote { margin: 10px 0; padding: 6px 11px; border-left: 3px solid #8baaf0; background: #f6f8fc; color: #58687f; }
.project-chat-markdown code { padding: 2px 4px; border-radius: 4px; background: #edf1f6; color: #334155; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.project-chat-markdown pre { overflow: auto; margin: 10px 0; padding: 11px 12px; border-radius: 6px; background: #172033; color: #e8edf5; }
.project-chat-markdown pre code { padding: 0; background: transparent; color: inherit; white-space: pre; }
.project-chat-markdown a { color: #1d5fc4; text-decoration: underline; text-underline-offset: 2px; }
.project-chat-markdown table { width: 100%; margin: 10px 0; border-collapse: collapse; font-size: 12px; }
.project-chat-markdown th,
.project-chat-markdown td { padding: 7px 9px; border: 1px solid #dce2e9; text-align: left; vertical-align: top; }
.project-chat-markdown th { background: #f5f7fa; color: #425066; font-weight: 650; }

.project-chat-edited { margin-left: 6px; color: #95a0af; font-size: 10px; }

.project-chat-state {
  min-height: 126px;
  display: grid;
  place-items: center;
  padding: 24px;
  color: #718096;
  text-align: center;
}

.project-chat-state strong { display: block; margin-bottom: 5px; color: #465469; font-size: 13px; }
.project-chat-state.error strong { color: #a32d35; }

@media (max-width: 800px) {
  .project-chat-heading { align-items: flex-start; }
  .project-chat-composer-footer { align-items: flex-start; flex-direction: column; }
  .project-chat-composer-actions { width: 100%; }
  .project-chat-composer-actions button { flex: 1; }
  .project-chat-message-head { flex-wrap: wrap; }
  .project-chat-message-actions { width: 100%; margin-left: 38px; }
  .project-chat-thread-children { margin-left: 12px; padding-left: 19px; }
  .project-chat-thread-children > .project-chat-thread-item::before { left: -19px; width: 15px; }
  .project-chat-thread-children > .project-chat-thread-item::after { left: -6px; }
  .project-chat-format-select { width: 122px; }
  .project-chat-link-editor { grid-template-columns: 1fr; }
  .project-chat-link-error { grid-column: 1; }
  .project-chat-link-actions { justify-content: flex-end; }
}

@media (pointer: coarse) {
  .project-chat-tool,
  .project-chat-context button,
  .project-chat-table-tools button,
  .project-chat-link-field input,
  .project-chat-link-actions button,
  .project-chat-message-actions button { min-height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  .project-chat-root * { scroll-behavior: auto!important; transition: none!important; }
}
