/*
 * Claude's own palette rather than Telegram's, because this is Claude's history and
 * it should look like it: warm paper, terracotta accent, a serif for headings.
 *
 * Light and dark both follow the client's theme — Telegram sets `color-scheme` on the
 * document, and a mini app that stays bright inside a dark client is jarring.
 */

:root {
  --paper: #faf9f5;
  --raised: #ffffff;
  --ink: #1f1e1d;
  --muted: #6b6963;
  --line: #e8e6dd;
  --accent: #d97757;
  --accent-soft: #f5e6df;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(31, 30, 29, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #1f1e1d;
    --raised: #262624;
    --ink: #f5f4ef;
    --muted: #9a978e;
    --line: #35332f;
    --accent: #e08a6b;
    --accent-soft: #3a2b25;
    --shadow: none;
  }
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font:
    15px/1.6 ui-sans-serif,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    Roboto,
    sans-serif;
  padding-bottom: calc(28px + env(safe-area-inset-bottom));
  overscroll-behavior-y: contain;
}

/* ---------- header ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: 12px 18px 14px;
  background: color-mix(in srgb, var(--paper) 90%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid var(--line);
}

.bar-row {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-height: 28px;
}

h1 {
  margin: 0;
  /* The serif is the single strongest signal that this is Claude and not a generic
     chat log; it echoes the headings on claude.com. */
  font-family: ui-serif, Georgia, "Times New Roman", serif;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.015em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

/* ---------- search ---------- */

.search {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding: 0 12px;
  background: var(--raised);
  border: 1px solid var(--line);
  border-radius: 12px;
  height: 40px;
  transition: border-color 0.15s ease;
}

.search:focus-within {
  border-color: var(--accent);
}

.search-icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: var(--muted);
}

.search input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 15px;
}

.search input::placeholder {
  color: var(--muted);
}

.search input::-webkit-search-cancel-button {
  appearance: none;
}

/* ---------- layout ---------- */

main {
  padding: 14px 18px 0;
}

.state {
  color: var(--muted);
  text-align: center;
  padding: 56px 16px;
  white-space: pre-line;
}

/* ---------- session list ---------- */

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list li {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--raised);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition:
    transform 0.14s cubic-bezier(0.2, 0, 0.2, 1),
    border-color 0.14s ease;
}

.list li:active {
  transform: scale(0.985);
  border-color: var(--accent);
}

.row {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  letter-spacing: -0.01em;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.when {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.preview {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.tags {
  display: flex;
  gap: 6px;
  margin-top: 10px;
  flex-wrap: wrap;
}

.tag {
  font-size: 11px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--muted) 12%, transparent);
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.tag.model {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* ---------- thread ---------- */

.thread {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: 8px;
}

.msg {
  padding: 12px 15px;
  border-radius: var(--radius);
  background: var(--raised);
  border: 1px solid var(--line);
  max-width: 94%;
  overflow-wrap: anywhere;
  animation: rise 0.2s cubic-bezier(0.2, 0, 0.2, 1) both;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

@media (prefers-reduced-motion: reduce) {
  .msg {
    animation: none;
  }
  .list li:active {
    transform: none;
  }
}

/* The question is the quieter half — it is the answer you came back to read. */
.msg.user {
  align-self: flex-end;
  background: var(--accent-soft);
  border-color: transparent;
}

.msg.error {
  background: color-mix(in srgb, #c0392b 10%, var(--raised));
  border-color: color-mix(in srgb, #c0392b 30%, transparent);
}

.meta {
  color: var(--muted);
  font-size: 11px;
  margin-top: 8px;
  font-variant-numeric: tabular-nums;
}

.msg p {
  margin: 0 0 10px;
  white-space: pre-wrap;
}

.msg p:last-of-type {
  margin-bottom: 0;
}

.msg h3 {
  margin: 14px 0 6px;
  font-family: ui-serif, Georgia, serif;
  font-size: 16px;
  font-weight: 600;
}

.msg h3:first-child {
  margin-top: 0;
}

.msg ul {
  margin: 0 0 10px;
  padding-left: 20px;
}

.msg li {
  margin-bottom: 4px;
}

.msg a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------- images ---------- */

.shot {
  display: block;
  width: 100%;
  margin: 10px 0;
  border-radius: 10px;
  border: 1px solid var(--line);
  /* Never let a tall diagram push the rest of the message off the screen. */
  max-height: 420px;
  object-fit: contain;
  background: var(--paper);
  cursor: zoom-in;
}

/* Tapping an image fills the screen with it — diagrams are unreadable at card size. */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(31, 30, 29, 0.92);
  animation: fade 0.15s ease both;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
}

@keyframes fade {
  from {
    opacity: 0;
  }
}

/* ---------- code ---------- */

.code {
  position: relative;
  margin: 10px 0;
}

.code pre {
  margin: 0;
  overflow-x: auto;
  padding: 12px 14px;
  border-radius: 10px;
  background: color-mix(in srgb, var(--ink) 5%, var(--paper));
  border: 1px solid var(--line);
}

.code .copy {
  position: absolute;
  top: 7px;
  right: 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 3px 9px;
  font: inherit;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  background: var(--raised);
  cursor: pointer;
}

.code .copy:active {
  color: var(--accent);
  border-color: var(--accent);
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
}

p code,
li code {
  background: color-mix(in srgb, var(--ink) 7%, transparent);
  padding: 1.5px 5px;
  border-radius: 5px;
}

/* ---------- skeleton ---------- */

.skeleton {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.sk-card {
  height: 92px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: linear-gradient(
    90deg,
    var(--raised) 25%,
    color-mix(in srgb, var(--raised) 55%, var(--paper)) 37%,
    var(--raised) 63%
  );
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
}

@keyframes shimmer {
  from {
    background-position: 100% 0;
  }
  to {
    background-position: -100% 0;
  }
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 30;
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  font-weight: 600;
  animation: rise 0.18s ease both;
}
