/* Hemmingway Cloud Chat — bespoke Obsidian glass UI matching the Hero */

html, body.chat-body {
  height: 100%;
  overflow: hidden;
}
body.chat-body {
  display: flex;
  flex-direction: column;
}

.chat-body .topbar.full {
  background: color-mix(in srgb, var(--bg) 74%, transparent);
  border-bottom-color: var(--line-soft);
}

.chat-rail-btn {
  margin-right: -4px;
}

.chat-credit {
  padding: 5px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: color-mix(in srgb, var(--surface) 70%, transparent);
  font-size: 12.5px;
  text-decoration: none;
  color: var(--ink);
}
.chat-credit:hover {
  border-color: var(--accent);
  color: var(--accent);
  text-decoration: none;
}

/* ------------------------------------------------------------------ shell */
.chat-shell {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: 256px minmax(0, 1fr);
  position: relative;
}
.chat-shell.rail-closed {
  grid-template-columns: minmax(0, 1fr);
}
.chat-shell.rail-closed .chat-rail {
  display: none;
}

/* ------------------------------------------------------------------ sidebar rail */
.chat-rail {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--line-soft);
  background: color-mix(in srgb, var(--bg) 82%, var(--deep));
}
html[data-theme="light"] .chat-rail {
  background: var(--subtle);
}

.chat-rail-top {
  padding: 14px 12px 10px;
  display: grid;
  gap: 8px;
}

.chat-new-btn {
  width: 100%;
  justify-content: flex-start;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  border: 1px solid var(--line);
  color: var(--ink);
  font-size: 13.5px;
}
.chat-new-btn:hover {
  border-color: color-mix(in srgb, var(--accent) 50%, var(--line));
  background: var(--surface);
}
.chat-new-btn svg {
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
}

.chat-search-input {
  height: 34px;
  font-size: 13px;
  background: transparent;
  border-color: var(--line-soft);
}
.chat-search-input:focus {
  background: color-mix(in srgb, var(--surface) 80%, transparent);
}

.chat-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 10px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.chat-group-label {
  padding: 12px 10px 4px;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--faint);
}
.chat-group-label:first-child {
  padding-top: 4px;
}

.chat-empty-list {
  padding: 14px 10px;
  font-size: 13px;
  color: var(--faint);
}

.chat-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 34px;
  padding: 0 6px 0 10px;
  border-radius: 7px;
  color: var(--body);
  cursor: pointer;
  transition: background-color 0.12s var(--ease-out), color 0.12s var(--ease-out);
}
.chat-item:hover {
  background: color-mix(in srgb, var(--ink) 5%, transparent);
  color: var(--ink);
}
.chat-item.active {
  background: color-mix(in srgb, var(--ink) 8%, transparent);
  color: var(--ink);
}

.chat-item-title {
  flex: 1;
  min-width: 0;
  background: none;
  border: 0;
  padding: 7px 0;
  color: inherit;
  font: 400 13.5px/1.3 var(--font);
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
}
.chat-item.active .chat-item-title {
  font-weight: 500;
}

.chat-rename-input {
  flex: 1;
  min-width: 0;
  height: 26px;
  padding: 0 6px;
  border: 1px solid var(--accent);
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  font: 13px var(--font);
}

.chat-item-acts {
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.chat-item:hover .chat-item-acts,
.chat-item:focus-within .chat-item-acts,
.chat-item.active .chat-item-acts {
  opacity: 1;
}

.chat-item-btn {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  display: inline-grid;
  place-items: center;
  cursor: pointer;
}
.chat-item-btn:hover {
  background: color-mix(in srgb, var(--ink) 9%, transparent);
  color: var(--ink);
}
.chat-item-btn.danger:hover {
  color: var(--danger);
}
.chat-item-btn svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chat-rail-foot {
  padding: 12px;
  border-top: 1px solid var(--line-soft);
}

.chat-guest-note {
  display: grid;
  gap: 8px;
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--muted);
}
.chat-guest-note .btn {
  width: 100%;
  border-radius: 7px;
}

.chat-account-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.chat-foot-link {
  border: 0;
  background: none;
  padding: 0;
  font: 400 12.5px/1.4 var(--font);
  color: var(--muted);
  text-decoration: none;
  cursor: pointer;
}
.chat-foot-link:hover {
  color: var(--ink);
  text-decoration: none;
}

/* ------------------------------------------------------------------ main canvas */
.chat-main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.chat-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 40px 32px 24px;
  display: flex;
  flex-direction: column;
}

.chat-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-bottom: 4vh;
}
.chat-empty-title {
  font-family: var(--display);
  font-size: clamp(28px, 3.2vw, 38px);
  font-weight: 500;
  line-height: 1.1;
  letter-spacing: -0.036em;
  color: color-mix(in srgb, var(--ink) 88%, transparent);
}

/* ------------------------------------------------------------------ messages */
.chat-messages {
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  display: grid;
  gap: 30px;
}

.chat-turn {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.chat-user-msg {
  justify-self: end;
  max-width: 78%;
  padding: 12px 17px;
  border: 1px solid var(--line-soft);
  border-radius: 14px;
  background: color-mix(in srgb, var(--surface) 84%, transparent);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.chat-assistant-msg {
  display: grid;
  gap: 10px;
  min-width: 0;
}

.chat-think {
  border-left: 2px solid var(--line);
  padding-left: 12px;
  font-size: 13px;
  color: var(--muted);
}
.chat-think summary {
  cursor: pointer;
  font-weight: 500;
  list-style: none;
}
.chat-think summary::-webkit-details-marker { display: none; }
.chat-think summary:hover { color: var(--ink); }
.chat-think-body {
  margin-top: 6px;
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
}

.chat-md {
  color: var(--ink);
  font-size: 15.5px;
  line-height: 1.68;
  overflow-wrap: anywhere;
}
.chat-md > * + * { margin-top: 12px; }
.chat-md h1, .chat-md h2, .chat-md h3 {
  margin-top: 18px;
  font-family: var(--display);
  font-weight: 500;
  letter-spacing: -0.025em;
}
.chat-md h1 { font-size: 22px; }
.chat-md h2 { font-size: 18px; }
.chat-md h3 { font-size: 16px; }
.chat-md ul, .chat-md ol { margin: 8px 0; padding-left: 22px; }
.chat-md li + li { margin-top: 4px; }
.chat-md blockquote {
  margin: 10px 0;
  padding-left: 14px;
  border-left: 2px solid var(--line);
  color: var(--muted);
}
.chat-md table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}
.chat-md th, .chat-md td {
  padding: 8px 12px;
  border: 1px solid var(--line);
  text-align: left;
}
.chat-md pre {
  position: relative;
  margin: 12px 0;
  padding: 15px 17px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: color-mix(in srgb, var(--subtle) 88%, transparent);
  font-size: 13px;
  line-height: 1.58;
}
.chat-code-copy {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font: 500 11.5px/1 var(--font);
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}
.chat-md pre:hover .chat-code-copy,
.chat-code-copy:focus-visible {
  opacity: 1;
}
.chat-code-copy:hover {
  color: var(--ink);
  border-color: var(--accent);
}

.chat-msg-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
  font-size: 12px;
  color: var(--muted);
}
.chat-meta {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--mono);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.chat-meta-tps {
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
}
.chat-msg-acts {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.chat-act-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 500 12px/1 var(--font);
  padding: 5px 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: color 0.12s ease, background-color 0.12s ease;
}
.chat-act-btn:hover {
  color: var(--ink);
  background: var(--subtle);
}

/* ------------------------------------------------------------------ frosted Hero composer */
.chat-composer-wrap {
  padding: 12px 32px max(28px, env(safe-area-inset-bottom));
}
.chat-err {
  max-width: 720px;
  margin: 0 auto 10px;
}

.chat-composer {
  max-width: 720px;
  margin: 0 auto;
  border-radius: 16px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  padding: 14px 14px 12px 20px;
  display: grid;
  gap: 10px;
  transition: border-color 0.16s var(--ease-out), box-shadow 0.16s var(--ease-out);
}
.chat-composer:focus-within {
  border-color: var(--accent);
  box-shadow: var(--shadow-float);
}

.chat-input {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--ink);
  font: 16px/1.5 var(--font);
  padding: 2px 0;
  min-height: 28px;
  max-height: 200px;
  resize: none;
}
.chat-input::placeholder {
  color: var(--muted);
  opacity: 0.72;
}
.chat-input:focus {
  outline: none;
}

.chat-composer-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
}
.chat-composer-left,
.chat-composer-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-model {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--body);
  font: 500 13.5px/1.2 var(--font);
  padding: 6px 18px 6px 0;
  cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 7px) 52%, calc(100% - 2px) 52%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
}
.chat-model option {
  background: var(--surface);
  color: var(--ink);
}
.chat-model:hover,
.chat-model:focus {
  outline: none;
  color: var(--ink);
}

.chat-think-toggle {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 32px;
  padding: 0 11px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font: 500 13px/1 var(--font);
  cursor: pointer;
  transition: color 0.14s var(--ease-out), background-color 0.14s var(--ease-out);
}
.chat-think-toggle svg {
  width: 14px;
  height: 14px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.chat-think-toggle:hover {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
  color: var(--ink);
}
.chat-think-toggle[aria-pressed="true"] {
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.chat-send,
.chat-stop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  appearance: none;
  border: 0;
  border-radius: 999px;
  height: 36px;
  padding: 0 20px;
  font: 500 13.5px/1 var(--font);
  cursor: pointer;
  transition: opacity 0.14s var(--ease-out), transform 0.12s var(--ease-out);
}
.chat-send {
  background: var(--ink);
  color: var(--bg);
}
.chat-send:hover {
  background: color-mix(in srgb, var(--ink) 84%, var(--bg));
}
.chat-send:active,
.chat-stop:active {
  transform: scale(0.97);
}
.chat-stop {
  background: var(--danger);
  color: #ffffff;
}

.chat-starters {
  max-width: 720px;
  margin: 14px auto 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chat-starter {
  appearance: none;
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--surface) 50%, transparent);
  color: var(--muted);
  font: 13px/1.3 var(--font);
  cursor: pointer;
  transition: border-color 0.14s var(--ease-out), color 0.14s var(--ease-out), background-color 0.14s var(--ease-out);
}
.chat-starter:hover {
  border-color: color-mix(in srgb, var(--accent) 55%, var(--line));
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  color: var(--ink);
}

.chat-scrim {
  position: fixed;
  inset: 56px 0 0 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 20;
}

@media (max-width: 860px) {
  .chat-shell {
    grid-template-columns: minmax(0, 1fr);
  }
  .chat-rail {
    position: fixed;
    top: 56px;
    left: 0;
    bottom: 0;
    width: 272px;
    z-index: 25;
  }
  .chat-thread,
  .chat-main.is-empty .chat-thread {
    padding-inline: 18px;
  }
  .chat-composer-wrap {
    padding: 8px 18px 18px;
  }
}
