:root {
  font: 16px/1.5 system-ui, sans-serif;
  color: #242428;
  background: #f2f2f3;
  --red: #b7152b;
  --ink: #242428;
  --line: #dedee2;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr); }
button, input, textarea { font: inherit; }
button, .upload {
  min-height: 42px; border: 1px solid transparent; border-radius: 9px; padding: .5rem .85rem;
  color: white; background: var(--red); cursor: pointer; font-weight: 650;
}
button:disabled { opacity: .5; cursor: default; }
.quiet { background: white; color: var(--ink); border-color: var(--line); }
:focus-visible { outline: 3px solid #a9152a; outline-offset: 2px; }
.bar {
  display: flex; gap: .65rem; align-items: center; padding: .55rem .85rem; background: white;
  border-top: 4px solid var(--red); border-bottom: 1px solid var(--line);
}
.bar h1 { margin: 0; font-size: 1.16rem; flex: 1; }
#starting { display: grid; place-items: center; padding: 1rem; overflow: auto; }
input, textarea { border: 1px solid var(--line); border-radius: 9px; min-width: 0; background: #fafafb; padding: .65rem; color: var(--ink); }
#workspace { position: relative; min-height: 0; display: flex; }
#history {
  width: min(285px, 85vw); flex: 0 0 auto; background: white; border-right: 1px solid var(--line);
  padding: 1rem; overflow: auto; display: flex; flex-direction: column; gap: .65rem; z-index: 1;
}
.history-top { display: flex; align-items: center; justify-content: space-between; }
.history-top h2 { font-size: 1.05rem; margin: 0; }
#chat-list { display: grid; gap: .35rem; }
#chat-list button { text-align: left; overflow-wrap: anywhere; font-weight: 500; }
#chat-list button[aria-current=true] { border-color: var(--red); color: var(--red); }
#gap-review { border-top: 1px solid var(--line); padding-top: .65rem; overflow-wrap: anywhere; }
#gap-review summary { font-weight: 650; cursor: pointer; }
#gap-review p { margin: .45rem 0; }
#gap-list article { padding: .6rem 0; border-bottom: 1px solid var(--line); }
#gap-list button { display: block; margin-top: .45rem; }
#more-gaps { margin-top: .65rem; }
#logout { margin-top: auto; }
#chat { flex: 1; min-width: 0; display: grid; grid-template-rows: minmax(0, 1fr) auto; }
#messages { overflow: auto; padding: 1.2rem max(1rem, calc((100% - 760px) / 2)); scroll-padding: 1rem; }
.welcome { max-width: 560px; margin: clamp(1rem, 8vh, 5rem) auto 0; }
.welcome h2 { font-size: clamp(1.4rem, 4vw, 2.05rem); line-height: 1.15; margin: 0 0 .65rem; }
.welcome p { margin: 0 0 1rem; color: #515159; }
.message { margin: .8rem 0; width: fit-content; max-width: min(100%, 650px); border-radius: 12px; background: white; border: 1px solid var(--line); padding: .8rem .95rem; overflow-wrap: anywhere; }
.message.user { margin-left: auto; background: #fbe9eb; border-color: #f2cbd0; }
.message p { margin: 0; white-space: pre-wrap; }
.message .who { font-size: .76rem; font-weight: 700; color: #565661; margin-bottom: .2rem; }
.message img { display: block; max-width: min(100%, 300px); max-height: 270px; object-fit: contain; border-radius: 8px; margin: .45rem 0; }
.product { display: block; padding: .65rem .75rem; margin-top: .5rem; border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: #fafafb; text-decoration: none; }
.product strong, .product span, .product small { display: block; }
.product small { color: #565661; }
.product-actions { display: flex; flex-wrap: wrap; align-items: center; gap: .65rem; margin: .65rem 0 .4rem; }
.product .product-code { font-size: 1.2rem; letter-spacing: .035em; }
.copy-code { min-height: 42px; }
.product-link { color: var(--red); font-weight: 600; }
.result-links { display: flex; flex-wrap: wrap; gap: .25rem 1rem; }
.copy-status:not(:empty) { margin-top: .3rem; }
.photo-details { display: grid; justify-items: start; gap: .3rem; overflow-wrap: anywhere; }
#use-markings { padding: .25rem .6rem; min-height: 36px; }
#composer { padding: .75rem max(1rem, calc((100% - 760px) / 2)) max(.65rem, env(safe-area-inset-bottom)); background: white; border-top: 1px solid var(--line); }
.compose-row { display: flex; gap: .45rem; align-items: end; }
.compose-row textarea { flex: 1; resize: vertical; max-height: 160px; }
.upload { position: relative; display: inline-flex; align-items: center; gap: .2rem; white-space: nowrap; }
#photo { position: absolute; width: 1px; height: 1px; opacity: 0; padding: 0; }
.compose-row:has(#photo:focus-visible) .upload { outline: 3px solid var(--red); outline-offset: 2px; }
#attachment { display: flex; gap: .55rem; align-items: center; margin-bottom: .5rem; font-size: .85rem; }
#attachment img { width: 62px; height: 62px; object-fit: cover; border-radius: 8px; }
#attachment button { margin-left: auto; }
.sync-note, #send-error { margin: .35rem 0 0; font-size: .8rem; color: #565661; }
#send-error { color: var(--red); }
#send-error:not(:empty) { margin-bottom: .45rem; }
@media (max-width: 640px) {
  #history { position: absolute; top: 0; bottom: 0; left: 0; box-shadow: 0 4px 20px #0002; }
  .upload span { display: none; }
  .compose-row textarea { padding: .45rem; }
}
