.page-new-design {
  &:has(.chat-root) {
    background: var(--new-main-background-color);
    .main { background: var(--new-main-background-color); }
  }
  .main:has(> .chat-root) {
    height: calc(100vh - var(--new-header-height) - var(--new-menu-height));
    min-height: 0;
    margin: 0;
    padding: 0;
    overflow: hidden;
  }
  .chat-root {
    height: 100%;
    min-height: 0;
    background: var(--new-main-background-color);
  }
  .chat-layout {
    display: grid;
    grid-template-columns: 260px minmax(0, 1fr);
    gap: 0;
    height: 100%;
    min-height: 0;
  }
  .chat-sidebar {
    display: grid;
    grid-template-rows: auto 1fr auto;
    min-height: 0;
    overflow: hidden;
    border: 0;
    border-right: 1px solid var(--slate-200);
    border-radius: 0;
    background: var(--white);
  }
  .chat-sidebar-header {
    padding: 12px;
    border-bottom: 0;
    #chat-new-thread {
      width: 100%;
      height: 33px;
      padding: 0 16px;
      font-size: 13px;
    }
  }
  .chat-thread-list {
    padding: 0 12px;
    overflow: auto;
    min-height: 0;
  }
  .chat-thread-group {
    margin: 0;
    padding: 20px 0 0;
    &:first-child { padding-top: 0; }
  }
  .chat-thread-pinned-group {
    margin: 0;
    padding: 0 0 10px;
    border-bottom: 0;
  }
  .chat-thread-group-title {
    display: flex;
    justify-content: space-between;
    margin: 0 8px 4px;
    color: var(--slate-400);
    font-size: 10px;
    font-weight: 400;
    line-height: 16px;
  }
  .chat-thread-group-title span { color: inherit; }
  .chat-thread-item {
    display: flex;
    align-items: center;
    width: 100%;
    min-height: 32px;
    padding: 0;
    border-radius: 8px;
    &:hover { background: var(--white); }
    &.is-active { background: var(--color-selected-background); }
    &:hover { .chat-thread-main { color: var(--slate-600); } }
    &.is-active { .chat-thread-main { color: var(--slate-600); } }
  }
  .chat-thread-main {
    flex: 1 1 auto;
    min-width: 0;
    padding: 8px 10px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--slate-600);
    text-align: left;
    cursor: pointer;
    &:focus-visible { outline: 2px solid var(--color-focus-ring); outline-offset: -2px; }
  }
  .chat-thread-title {
    display: block;
    overflow: hidden;
    color: inherit;
    font-size: 12px;
    line-height: 16px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .chat-thread-title-input {
    flex: 1 1 auto;
    min-width: 0;
    width: 100%;
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--color-input-border);
    border-radius: 8px;
    background: var(--white);
    color: var(--slate-700);
    font: inherit;
    font-size: 12px;
    line-height: 16px;
    outline: 0;
    &:focus { border-color: var(--color-focus); box-shadow: 0 0 0 2px var(--color-focus-ring); }
  }
  .chat-thread-item.is-editing {
    .chat-thread-time, .chat-thread-pin, .chat-thread-edit { display: none; }
  }
  .chat-thread-pin, .chat-thread-edit, .chat-thread-delete {
    flex: 0 0 18px;
    width: 18px;
    height: 18px;
    padding: 0;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--slate-400);
    font-size: 12px;
    &:hover, &:focus-visible { background: var(--sky-50); color: var(--sky-600); }
  }
  .chat-thread-pin {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    img { display: block; width: 14px; height: 14px; }
  }
  .chat-thread-edit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    img { display: block; width: 14px; height: 14px; &.icon-hover { display: none; } }
    &:hover, &:focus-visible {
      img { display: none; &.icon-hover { display: block; } }
    }
  }
  .chat-thread-time {
    flex: 0 0 34px;
    margin-left: 4px;
    color: var(--slate-400);
    font-size: 10px;
    line-height: 16px;
    text-align: right;
  }
  .chat-show-all-history {
    display: flex;
    align-items: center;
    width: 100%;
    height: 40px;
    padding: 0 20px;
    border: 0;
    border-top: 1px solid var(--slate-200);
    background: var(--white);
    color: var(--slate-400);
    font-size: 11px;
    text-align: left;
    &:hover, &:focus-visible { background: var(--slate-50); color: var(--slate-600); }
  }
  .chat-main {
    display: grid;
    grid-template-rows: 57px minmax(0, 1fr) auto;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    border: 0;
    border-radius: 0;
    background: var(--new-main-background-color);
  }
  .chat-main-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 20px;
    border-bottom: 1px solid var(--slate-200);
    background: var(--new-main-background-color);
    h1 {
      margin: 0;
      color: var(--slate-800);
      font-size: 14px;
      font-weight: 400;
      line-height: 24px;
    }
    #chat-current-date { color: var(--slate-400); font-size: 12px; }
  }
  .chat-message-list {
    width: 100%;
    margin: 0;
    padding: 20px;
    overflow: auto;
  }
  .chat-message { display: flex; margin-bottom: 20px; }
  .chat-message.is-user { justify-content: flex-end; }
  .chat-message-content {
    display: flex;
    flex-direction: column;
    max-width: 100%;
  }
  .chat-message-bubble {
    max-width: 100%;
    padding: 0;
    border-radius: 0;
    background: transparent;
  }
  .chat-message {
    &.is-user {
      .chat-message-content { width: 100%; align-items: flex-end; }
      .chat-message-bubble {
        max-width: min(284px, 80%);
        padding: 10px 16px;
        border-radius: 16px;
        background: var(--sky-500);
        color: var(--white);
      }
      &:has(.is-short-prompt) { .chat-message-bubble { max-width: max-content; } }
      .chat-message-text { color: var(--white); }
      .chat-message-time { text-align: right; }
    }
  }
  .chat-message-time {
    margin-top: 4px;
    color: var(--slate-400);
    font-size: 11px;
    line-height: 21px;
  }
  .chat-message-text {
    color: var(--slate-800);
    font-size: 14px;
    line-height: 21px;
    p { margin: 0 0 4px; &:last-child { margin-bottom: 0; } }
    ul { margin: 0 0 4px; padding-left: 20px; }
    &.is-short-prompt { white-space: nowrap; }
  }
  .chat-message-spinner {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: 8px;
    border: 2px solid var(--sky-100);
    border-top-color: var(--sky-600);
    border-radius: 50%;
    animation: common-spinner 0.8s linear infinite;
    vertical-align: -1px;
  }
  .chat-message-status { color: var(--slate-400); }
  .chat-message-table-wrap { margin: 0 0 4px; overflow-x: auto; }
  .chat-message-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    th, td { padding: 6px 8px; border: 1px solid var(--slate-200); text-align: left; vertical-align: top; }
    th { background: var(--slate-100); font-weight: 700; }
  }
  .chat-compose {
    width: 100%;
    margin: 0;
    padding: 0 20px 20px;
    border-top: 0;
  }
  .chat-compose-settings {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    color: var(--slate-400);
    font-size: 11px;
    select { height: 28px; padding: 0 8px; border: 1px solid var(--color-input-border); border-radius: 8px; background: var(--white); color: var(--slate-600); font-size: 11px; }
  }
  .chat-compose textarea {
    width: 100%;
    min-height: 58px;
    padding: 20px 42px 12px;
    resize: vertical;
    border: 1px solid var(--color-input-border);
    border-radius: 16px;
    background: var(--white);
    color: var(--slate-800);
    font-size: 14px;
    line-height: 20px;
    box-shadow: none;
    &::placeholder { color: var(--color-placeholder); opacity: 1; }
    &:focus { outline: 0; }
  }
  .chat-input-wrap {
    position: relative;
    #chat-send {
      position: absolute;
      right: 13px;
      bottom: 13px;
      display: inline-flex;
      align-items: center;
      justify-content: center;
      width: 32px;
      height: 32px;
      min-width: 32px;
      margin: 0;
      padding: 0;
      border: 0;
      border-radius: 10px;
      background: transparent;
      appearance: none;
      &:hover, &:focus-visible { filter: brightness(1.15); }
      &:disabled { opacity: .55; }
      img { display: block; width: 32px; height: 32px; }
    }
  }
  .chat-compose-actions {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 16px;
    margin-top: 8px;
    .chat-compose-hint { color: var(--slate-400); font-size: 11px; line-height: 16px; }
  }
  .chat-thread-empty { padding: 20px 8px; color: var(--slate-400); font-size: 12px; }
}

@media (max-width: 768px) {
  .page-new-design {
    .chat-layout { grid-template-columns: 1fr; grid-template-rows: minmax(220px, 35vh) minmax(0, 1fr); }
    .chat-sidebar { border-right: 0; border-bottom: 1px solid var(--slate-200); }
    .chat-main { min-height: 0; }
  }
}
