:root {
  font:
    100%/1.6 system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  color: #f2f0e7;
  background: #18232f;
  color-scheme: dark;
  font-synthesis: none;
  --canvas: #18232f;
  --surface: #222e39;
  --text: #f2f0e7;
  --muted: #afb9c2;
  --cyan: #33f3e6;
  --green: #0bb065;
  --yellow: #ddbf5e;
  --red: #d60202;
  --border: #374654;
  --error: #ffaaa4;
  --warning: #f0ce87;
}
* {
  box-sizing: border-box;
}
[hidden] {
  display: none !important;
}
body {
  margin: 0;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(ellipse at 85% 10%, #3a526d55, transparent 65%),
    linear-gradient(135deg, #1c2b3a, var(--canvas) 55%, #141e29);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: url("/grain.svg");
  opacity: 0.12;
}
button,
textarea,
a {
  -webkit-tap-highlight-color: transparent;
}
button,
textarea {
  font: inherit;
  color: inherit;
}
button,
a {
  touch-action: manipulation;
}
button {
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  padding: 0.55rem 0.85rem;
  cursor: pointer;
}
button:active {
  background: #34383c;
}
button:disabled {
  opacity: 0.5;
  cursor: wait;
}
button:focus-visible,
a:focus-visible,
textarea:focus-visible,
#messages:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 3px;
}
a {
  color: var(--cyan);
  text-underline-offset: 0.2em;
  overflow-wrap: anywhere;
}
.icon {
  width: 44px;
  flex: 0 0 44px;
  padding: 0;
  font-size: 1.5rem;
  background: transparent;
  border-color: transparent;
}
.brand {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.brand strong {
  font-size: 2.25rem;
  font-weight: 650;
  letter-spacing: -0.045em;
  color: var(--text);
}
.brand strong span {
  color: var(--yellow);
}
.business {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 0.5rem;
  letter-spacing: 0.04em;
}
#sidebar {
  position: fixed;
  z-index: 5;
  inset: 0 auto 0 0;
  width: min(300px, 88vw);
  padding: max(1.5rem, env(safe-area-inset-top)) 1.1rem
    max(1rem, env(safe-area-inset-bottom));
  background: #192530;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  transform: translateX(-100%);
  visibility: hidden;
  transition:
    transform 180ms ease,
    visibility 180ms;
}
body.drawer-open #sidebar {
  transform: translateX(0);
  visibility: visible;
}
.sidebar-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0.4rem 2rem;
}
.new-chat {
  text-align: left;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.new-chat span {
  font-size: 1.35rem;
  color: var(--cyan);
}
.nav-label {
  color: var(--muted);
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  margin: 2rem 0.7rem 0.6rem;
}
nav {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
}
.chat-row {
  display: flex;
  align-items: center;
  gap: 0.15rem;
  margin: 0.2rem 0;
}
nav .chat-link {
  display: block;
  flex: 1;
  min-width: 0;
  text-align: left;
  border-color: transparent;
  background: transparent;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--muted);
}
nav .chat-link.selected {
  background: #253b43;
  color: var(--text);
  box-shadow: inset 2px 0 var(--cyan);
}
.delete-chat {
  position: relative;
  flex: 0 0 36px;
  min-height: 36px;
  border-color: transparent;
  background: transparent;
  color: var(--red);
  opacity: 0.72;
}
.delete-chat::before {
  content: "";
  position: absolute;
  width: 11px;
  height: 13px;
  left: 11px;
  top: 12px;
  border: 2px solid currentColor;
  border-top: 0;
  border-radius: 0 0 2px 2px;
}
.delete-chat::after {
  content: "";
  position: absolute;
  width: 15px;
  height: 2px;
  left: 10px;
  top: 9px;
  background: currentColor;
  box-shadow: 5px -3px 0 -0.5px currentColor;
}
.delete-chat:hover,
.delete-chat:focus-visible {
  opacity: 1;
}
.delete-chat:hover:not(:disabled) {
  border-color: transparent;
}
#delete-dialog {
  width: min(calc(100% - 2rem), 26rem);
  margin: auto;
  padding: 1.4rem;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px #0009;
}
#delete-dialog::backdrop {
  background: #0009;
}
#delete-dialog h2 {
  margin: 0;
  font-size: 1.1rem;
}
#delete-dialog p {
  margin: 0.7rem 0 1.3rem;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
}
#delete-confirm {
  border-color: #ef5555;
  background: var(--red);
  color: #fff;
}
#delete-confirm:active {
  background: #fa3838;
}
footer {
  padding: 1rem 0.5rem 0;
  color: var(--muted);
  font-size: 0.7rem;
}
footer button,
footer a {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.8rem;
}
.connection-dot {
  display: inline-block;
  width: 5px;
  height: 5px;
  background: var(--green);
  border-radius: 50%;
  margin-right: 5px;
}
#backdrop {
  position: fixed;
  z-index: 4;
  inset: 0;
  width: 100%;
  height: 100%;
  background: #0009;
  border: 0;
  border-radius: 0;
}
main {
  position: relative;
  height: 100%;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: max(0.7rem, env(safe-area-inset-top))
    max(0.65rem, env(safe-area-inset-right)) 0.7rem
    max(0.65rem, env(safe-area-inset-left));
  border-bottom: 1px solid #ffffff08;
}
header .brand strong {
  font-size: 1.35rem;
}
header .business {
  font-size: 0.65rem;
  margin-top: 0.25rem;
}
h1 {
  min-width: 0;
  flex: 1;
  font-size: 0.85rem;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  margin: 0 0 0 0.5rem;
  color: var(--muted);
}
#notice {
  flex-shrink: 0;
  margin: 0.5rem 1rem 0;
  padding: 0.65rem 0.9rem;
  border: 1px solid #785f35;
  border-radius: 10px;
  color: var(--warning);
  font-size: 0.8rem;
  max-height: 20vh;
  overflow: auto;
}
#notice:empty {
  display: none;
}
.conversation {
  flex: 1;
  min-height: 0;
  position: relative;
}
#messages {
  height: 100%;
  overflow: auto;
  overscroll-behavior-y: contain;
  scrollbar-width: thin;
  scrollbar-color: #555a60 transparent;
  padding: 1.5rem max(1rem, calc((100% - 760px) / 2));
  overflow-anchor: none;
}
.welcome {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding-bottom: 4rem;
}
.welcome-mark {
  color: var(--yellow);
  font-size: 2rem;
  margin-bottom: 1rem;
}
.welcome h2 {
  margin: 0;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  letter-spacing: -0.035em;
  font-weight: 550;
  line-height: 1.2;
}
.welcome p {
  color: var(--muted);
  max-width: 28rem;
  font-size: 0.95rem;
}
.turn {
  margin-bottom: 2rem;
}
.message {
  font-size: 1rem;
  overflow-wrap: anywhere;
  min-width: 0;
}
.user {
  background: linear-gradient(120deg, #253e46, #22343f);
  border: 1px solid #33f3e640;
  box-shadow: 0 0 32px -8px #33f3e63d;
  border-radius: 18px 18px 5px 18px;
  padding: 0.8rem 1rem;
  margin: 0 0 1.3rem auto;
  width: fit-content;
  max-width: 90%;
  white-space: pre-wrap;
}
.assistant {
  background: linear-gradient(120deg, #26323b, #212d37);
  border: 1px solid #ddbf5e38;
  border-radius: 18px 18px 18px 5px;
  padding: 0.6rem 0.8rem;
  box-shadow: 0 0 32px -8px #ddbf5e3d;
}
.assistant-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 650;
  color: var(--yellow);
  margin-bottom: 0.5rem;
}
.activity {
  margin: 0 0 0.9rem;
  color: var(--muted);
  font-size: 0.75rem;
}
.activity summary {
  cursor: pointer;
  width: fit-content;
  padding: 0.25rem 0;
  list-style: none;
}
.activity summary::-webkit-details-marker {
  display: none;
}
.activity summary::before {
  content: "›";
  display: inline-block;
  margin-right: 0.45rem;
  transition: transform 150ms ease;
}
.activity[open] summary::before {
  transform: rotate(90deg);
}
.activity-output {
  margin: 0.35rem 0 0 0.3rem;
  padding-left: 0.8rem;
  border-left: 1px solid var(--border);
}
.activity-output .output p:first-child {
  margin-top: 0;
}
.activity-output .output p:last-child {
  margin-bottom: 0.25rem;
}
.output p {
  white-space: pre-wrap;
  margin: 0.5rem 0 1rem;
}
.output ul,
.output ol {
  padding-left: 1.5rem;
}
.output h2,
.output h3 {
  font-size: 1.15rem;
  line-height: 1.4;
  margin: 1.4rem 0 0.6rem;
}
.output pre {
  overflow: auto;
  background: var(--surface);
  border-radius: 10px;
  padding: 1rem;
  font-size: 0.85rem;
}
.output code {
  background: var(--surface);
  padding: 0.1em 0.25em;
  border-radius: 4px;
}
.output pre code {
  padding: 0;
}
.table-wrap {
  max-width: 100%;
  overflow: auto;
  margin: 1rem 0;
}
table {
  border-collapse: collapse;
  min-width: 100%;
  font-size: 0.85rem;
}
th,
td {
  text-align: left;
  padding: 0.6rem 0.8rem;
  border-bottom: 1px solid var(--border);
}
th {
  font-weight: 600;
  background: var(--surface);
}
.turn-state {
  font-size: 0.75rem;
  color: var(--muted);
  display: block;
  margin-top: 0.7rem;
}
.turn-state[data-status="failed"] {
  color: var(--error);
  border-left: 3px solid var(--red);
  padding-left: 0.6rem;
}
.turn-state[data-status="interrupted"] {
  color: var(--warning);
}
.turn-state[data-status="running"] {
  font-size: 0.84rem;
  font-weight: 600;
  color: transparent;
  background: linear-gradient(100deg, var(--muted) 22%, var(--green) 40%, var(--cyan) 50%, var(--yellow) 60%, var(--muted) 78%);
  background-size: 240% 100%;
  background-clip: text;
  -webkit-background-clip: text;
  text-shadow: 0 0 14px #33f3e655;
  animation: working-glow 3.2s ease-in-out infinite;
}
.files {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  gap: 0.65rem;
}
.artifact {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 1rem;
  padding: 0.9rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.artifact img {
  width: 100%;
  height: 150px;
  object-fit: contain;
  background: var(--canvas);
  border-radius: 6px;
}
.file-name {
  overflow-wrap: anywhere;
  font-size: 0.85rem;
}
.artifact small {
  color: var(--muted);
  font-size: 0.7rem;
}
.artifact a {
  display: flex;
  align-items: center;
  min-height: 44px;
  font-size: 0.8rem;
}
.artifact-reference {
  color: var(--cyan);
  font-weight: 600;
}
.composer-wrap {
  flex-shrink: 0;
  width: 100%;
  max-width: 792px;
  align-self: center;
  padding: 0.6rem max(1rem, env(safe-area-inset-right))
    max(0.5rem, env(safe-area-inset-bottom))
    max(1rem, env(safe-area-inset-left));
}
#composer {
  background: var(--surface);
  border: 1px solid #455866;
  border-radius: 20px;
  padding: 0.7rem 0.75rem 0.65rem;
  box-shadow: 0 6px 22px #0002;
}
#composer:focus-within {
  border-color: var(--cyan);
  box-shadow: 0 0 28px -10px #ddbf5e80;
}
textarea {
  display: block;
  border: 0;
  resize: none;
  min-height: 44px;
  max-height: min(200px, 30dvh);
  width: 100%;
  background: transparent;
  line-height: 1.5;
  padding: 0.4rem 0.35rem;
  overflow-y: auto;
}
textarea::placeholder {
  color: var(--muted);
}
#composer textarea:focus-visible {
  outline: none;
}
.actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  flex-wrap: wrap;
}
.actions #status {
  flex: 1;
  min-width: 100px;
  font-size: 0.7rem;
  color: var(--muted);
  padding-left: 0.35rem;
}
@keyframes working-glow {
  to { background-position: -240% 0; }
}
.actions button {
  font-size: 0.75rem;
}
#send {
  background: var(--cyan);
  color: #122427;
  border: none;
  border-radius: 13px;
  width: 44px;
  padding: 0;
  font-size: 1.6rem;
}
#send:active {
  background: #99f5fa;
}
.composer-note {
  text-align: center;
  margin: 0.55rem 0 0;
  color: var(--muted);
  font-size: 0.65rem;
}
#latest {
  position: absolute;
  bottom: 0.8rem;
  left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  font-size: 0.8rem;
  box-shadow: 0 3px 18px #0005;
}
#scroll-accent {
  position: absolute;
  right: 10px;
  top: 10px;
  bottom: 10px;
  width: 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 250ms;
}
#scroll-accent.visible {
  opacity: 1;
}
#scroll-accent span {
  display: block;
  position: absolute;
  width: 2px;
  min-height: 18px;
  background: var(--cyan);
  border-radius: 2px;
  box-shadow: 0 0 8px #33f3e680;
}
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
@media (min-width: 960px) {
  body {
    display: flex;
  }
  #sidebar {
    position: relative;
    width: 260px;
    flex: 0 0 260px;
    transform: none;
    visibility: visible;
    transition: none;
  }
  main {
    flex: 1;
  }
  .mobile {
    display: none;
  }
  header {
    padding: 1rem 2rem;
  }
  h1 {
    font-size: 0.9rem;
  }
  #messages {
    padding-top: 2.5rem;
  }
  .composer-wrap {
    padding-bottom: 1rem;
  }
}
@media (max-height: 500px) {
  .composer-note {
    display: none;
  }
  header {
    padding-top: 0.2rem;
    padding-bottom: 0.2rem;
  }
}
@media (hover: hover) {
  button:hover:not(:disabled) {
    border-color: #6a7076;
  }
  nav .chat-link:hover {
    background: #263844;
  }
}
@media (prefers-reduced-motion: reduce) {
  *,
  *::before {
    transition: none !important;
    scroll-behavior: auto !important;
  }
  .turn-state[data-status="running"] {
    animation: none;
    background-position: 50% 0;
  }
}
@media (prefers-contrast: more) {
  :root {
    --muted: #dedede;
    --border: #a5a7aa;
  }
  body::before {
    display: none;
  }
  .user {
    background: var(--surface);
    border-color: var(--cyan);
    box-shadow: none;
  }
  #scroll-accent span {
    box-shadow: none;
  }
}
@media (forced-colors: active) {
  #scroll-accent,
  body::before {
    display: none;
  }
  button,
  .artifact,
  .user {
    border: 1px solid ButtonText;
  }
}
.load-older, .load-error {
  display: block;
  margin: 12px auto;
  min-height: 44px;
  padding: 8px 16px;
  color: inherit;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 10px;
}
.load-older[hidden] { display: none; }
