/* ===== Start page: Claude-style chat ===== */

/* The start page must fill the viewport height AND use flex layout - but ONLY
   when active (.on). The global rules are:
     .pg     { display:none }            (0,1,0) - hidden by default
     .pg.on  { display:block }           (0,2,0) - shown when active
   We need display:flex (not block) for the chat two-column layout, and a fixed
   viewport height. We scope both to the ACTIVE start page via .pg.pg-start.on
   (specificity 0,3,0) so that when Start is NOT active it correctly collapses to
   display:none and does NOT reserve its 851px height (which previously pushed
   Browse / Case study content below the viewport). */
.pg.pg-start.on {
  display: flex;
  padding: 0;
  height: calc(100vh - 49px); /* viewport minus the 48px topbar */
}

.chat-layout {
  display: flex;
  width: 100%;
  min-height: 0;
  flex: 1;
}

/* ---------- Sidebar ---------- */
.chat-sidebar {
  width: 256px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-background-secondary);
  border-right: 0.5px solid var(--color-border-tertiary);
}

.sb-new {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: var(--space-3) var(--space-3) var(--space-2);
  padding: 9px var(--space-3);
  border: 0.5px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-md);
  background: var(--color-background-primary);
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s;
}

.sb-example {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 var(--space-3) var(--space-3);
  padding: 9px var(--space-3);
  border: 0.5px solid var(--color-border-tertiary);
  border-radius: var(--border-radius-md);
  background: var(--color-background-primary);
  color: var(--color-text-primary);
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.12s, color 0.12s, box-shadow 0.12s;
}

.sb-example i {
  font-size: 16px;
  color: var(--color-text-secondary);
}

.sb-example:hover {
  border-color: #f0997b;
  color: #993c1d;
}

.sb-example.active {
  background: var(--color-background-primary);
  box-shadow: 0 0 0 0.5px var(--color-border-tertiary);
}

.sb-example.active i {
  color: #d85a30;
}

.sb-new i {
  font-size: 16px;
  color: #d85a30;
}

.sb-new:hover {
  border-color: #f0997b;
  color: #993c1d;
}

.sb-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 0 var(--space-2) var(--space-2);
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.sb-empty {
  padding: var(--space-4) var(--space-3);
  font-size: 12px;
  color: var(--color-text-secondary);
  line-height: 1.5;
}

.sb-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 8px;
  border-radius: 6px;
  cursor: pointer;
  color: var(--color-text-primary);
  transition: background 0.1s;
  position: relative;
}

.sb-item:hover {
  background: rgba(0, 0, 0, 0.035);
}

.sb-item.active {
  background: var(--color-background-primary);
  box-shadow: 0 0 0 0.5px var(--color-border-tertiary);
}

.sb-item i.sb-item-icon {
  font-size: 14px;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.sb-item.active i.sb-item-icon {
  color: #d85a30;
}

.sb-item-title {
  font-size: 13px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sb-item-meta {
  font-size: 10px;
  color: var(--color-text-secondary);
  flex-shrink: 0;
}

.sb-item-del {
  display: none;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1;
}

.sb-item:hover .sb-item-del {
  display: flex;
}

.sb-item-del:hover {
  background: rgba(0, 0, 0, 0.06);
  color: #993c1d;
}

/* hide title + meta when delete button shows, to avoid jump */
.sb-item:hover .sb-item-del ~ .sb-item-meta,
.sb-item:hover .sb-item-del:not(:hover) ~ .sb-item-meta {
  display: none;
}

.sb-foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: var(--space-3);
  border-top: 0.5px solid var(--color-border-tertiary);
  font-size: 12px;
  color: var(--color-text-secondary);
}

.sb-foot i {
  color: #d85a30;
  font-size: 15px;
}

.agent-mark {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  display: block;
  flex-shrink: 0;
}

/* ---------- Main ---------- */
.chat-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--color-background-primary);
  position: relative;
}

.cm-topbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 0 var(--space-4);
  height: 44px;
  border-bottom: 0.5px solid var(--color-border-tertiary);
  flex-shrink: 0;
}

.cm-menu {
  display: none;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 4px;
  border-radius: 6px;
}

.cm-menu:hover {
  background: var(--color-background-secondary);
  color: var(--color-text-primary);
}

.cm-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--color-text-secondary);
  min-width: 0;
}

.cm-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--color-border-secondary);
  flex-shrink: 0;
  transition: background 0.2s;
}

.cm-status-dot.collecting {
  background: #d8a93a;
}

.cm-status-dot.ready {
  background: #1d9e75;
}

.cm-status-dot.submitted {
  background: #d85a30;
}

#cm-status-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cm-status .pill {
  margin-left: var(--space-2);
}

/* ---------- Scroll area ---------- */
.cm-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: var(--space-5) var(--space-4) var(--space-4);
  display: flex;
  flex-direction: column;
  /* empty-state hero centers vertically; if it overflows, it stays top-anchored
     (margin:auto collapses so content starts at the top padding). */
  justify-content: flex-start;
}

.cm-inner {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.cm-inner--guide {
  flex: 1;
  min-height: 100%;
}

.cm-guide {
  margin-top: auto;
  margin-bottom: auto;
  max-width: 560px;
  padding: 8px 2px 16px;
  color: #b7b2ad;
  font-size: 13px;
  line-height: 1.65;
}

.cm-guide-title {
  margin: 0 0 8px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #aea9a4;
}

.cm-guide ol {
  margin: 0 0 10px;
  padding-left: 18px;
}

.cm-guide li + li {
  margin-top: 4px;
}

.cm-guide p {
  margin: 0;
}

/* Empty-state hero: vertically centered when there's room. */
.cm-hero {
  text-align: center;
  padding: var(--space-4) 0;
  max-width: 720px;
  margin: auto auto; /* center horizontally + vertically within the flex column */
}

.cm-hero-logo {
  width: 48px;
  height: 48px;
  margin: 0 auto var(--space-4);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--border-radius-lg);
  background: #faece7;
  color: #d85a30;
}

.cm-hero-logo i {
  font-size: 26px;
}

.cm-hero-title {
  font-family: var(--font-display);
  font-size: 26px;
  font-weight: 600;
  color: var(--color-text-primary);
  margin-bottom: var(--space-2);
  line-height: 1.2;
}

.cm-hero-sub {
  font-size: 14px;
  color: var(--color-text-secondary);
  line-height: 1.6;
  max-width: 520px;
  margin: 0 auto;
}

/* ---------- Messages ---------- */
.msg-row {
  display: flex;
  gap: var(--space-3);
  align-items: flex-start;
}

.msg-row--user {
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 26px;
  height: 26px;
  min-width: 26px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  flex-shrink: 0;
  margin-top: 2px;
}

.msg-avatar--bot {
  width: 32px;
  height: 32px;
  min-width: 32px;
  background: transparent;
  border: none;
  overflow: hidden;
  padding: 0;
}

.msg-avatar--bot img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}

.msg-avatar--user {
  background: var(--color-background-secondary);
  color: var(--color-text-secondary);
  border: 0.5px solid var(--color-border-tertiary);
}

.msg-body {
  max-width: 80%;
  min-width: 0;
}

.msg-row--user .msg-body {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.msg-bubble {
  padding: 9px var(--space-3);
  border-radius: var(--border-radius-md);
  font-size: 13px;
  line-height: 1.65;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg-bubble--bot {
  background: var(--color-background-secondary);
  border: 0.5px solid var(--color-border-tertiary);
  color: var(--color-text-primary);
  border-top-left-radius: 3px;
}

.msg-bubble--user {
  background: #d85a30;
  color: #faece7;
  border-top-right-radius: 3px;
}

.msg-download {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 10px;
  border-radius: var(--border-radius-md);
  background: #d85a30;
  color: #faece7;
  font-size: 12px;
  line-height: 1.4;
  text-decoration: none;
}

.msg-thinking {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text-secondary);
  font-size: 13px;
}

.msg-thinking i {
  animation: cm-spin 1s linear infinite;
}

@keyframes cm-spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- Composer ---------- */
.cm-composer {
  flex-shrink: 0;
  padding: var(--space-3) var(--space-4) var(--space-4);
  border-top: 0.5px solid var(--color-border-tertiary);
  background: var(--color-background-primary);
}

.cm-file-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: var(--space-2);
}

.cm-file-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 4px;
  border: 0.5px solid var(--color-border-tertiary);
  border-radius: 20px;
  background: var(--color-background-secondary);
  font-size: 11px;
  color: var(--color-text-primary);
  max-width: 260px;
}

.cm-file-chip i.cm-file-chip-icon {
  font-size: 14px;
  color: #d85a30;
  flex-shrink: 0;
}

.cm-file-chip-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.cm-file-chip-remove {
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  padding: 0 2px;
  font-size: 13px;
  line-height: 1;
  border-radius: 50%;
}

.cm-file-chip-remove:hover {
  color: #993c1d;
}

.cm-form {
  display: flex;
  align-items: flex-end;
  gap: var(--space-2);
  max-width: 760px;
  margin: 0 auto;
  position: relative;
  background: var(--color-background-primary);
  border: 0.5px solid var(--color-border-secondary);
  border-radius: var(--border-radius-lg);
  padding: 6px 6px 6px 6px;
  transition: border-color 0.12s, box-shadow 0.12s;
}

.cm-form:focus-within {
  border-color: #f0997b;
  box-shadow: 0 0 0 3px rgba(216, 90, 48, 0.12);
}

.cm-attach {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}

.cm-attach i {
  font-size: 18px;
}

.cm-attach:hover {
  background: #faece7;
  color: #d85a30;
}

.cm-form textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  padding: 7px 0;
  height: auto; /* override global textarea { height:72px } */
  min-height: 20px;
  max-height: 200px;
  width: 100%;
  color: var(--color-text-primary);
}

.cm-form textarea:focus {
  outline: none;
}

.cm-send {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  border: none;
  background: #d85a30;
  color: #faece7;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s, opacity 0.12s;
}

.cm-send i {
  font-size: 16px;
}

.cm-send:hover:not(:disabled) {
  background: #c04f28;
}

.cm-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.cm-hint {
  text-align: center;
  font-size: 11px;
  color: var(--color-text-secondary);
  margin-top: var(--space-2);
}

/* ---------- Focus + reduced motion ---------- */
.sb-new:focus-visible,
.sb-item:focus-visible,
.sb-item-del:focus-visible,
.cm-menu:focus-visible,
.cm-attach:focus-visible,
.cm-send:focus-visible,
.cm-suggest-card:focus-visible {
  outline: 2px solid #d85a30;
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .sb-new,
  .sb-item,
  .cm-attach,
  .cm-send,
  .cm-suggest-card,
  .cm-form {
    transition: none;
  }

  .msg-thinking i {
    animation: none;
  }
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .pg.pg-start.on {
    height: calc(100vh - 49px);
  }

  .chat-sidebar {
    position: absolute;
    z-index: 20;
    height: 100%;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    box-shadow: 0 0 0 0.5px var(--color-border-tertiary);
  }

  .chat-sidebar.open {
    transform: translateX(0);
  }

  .cm-menu {
    display: flex;
  }

  .cm-suggest {
    grid-template-columns: 1fr;
  }

  .cm-scroll {
    padding: var(--space-4) var(--space-3);
  }

  .msg-body {
    max-width: 88%;
  }
}
