/* xcode Cloud: restrained black reader, independent of the home page theme. */
@font-face {
  font-family: "Bricolage Grotesque";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url(/fonts/bricolage-grotesque-400-700.v2.woff2) format("woff2");
}
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: url(/fonts/jetbrains-mono-400.v2.woff2) format("woff2");
}

:root {
  color-scheme: dark;
  --bg: #050506;
  --panel: #0a0a0b;
  --card: #111113;
  --hover: #17171a;
  --line: rgba(255, 255, 255, 0.09);
  --line-2: rgba(255, 255, 255, 0.16);
  --ink: #f3f3f5;
  --ink-2: #c9c9d1;
  --muted: #8b8b96;
  --accent: #d5d5d5;
  --accent-soft: rgba(255, 255, 255, 0.06);
  --accent-line: rgba(255, 255, 255, 0.3);
  --accent-fill: #303030;
  --accent-on: #ffffff;
  --danger: #ff7a66;
  --ok: #6ee7b7;
  --radius: 10px;
  --radius-sm: 6px;
  --sans: "Bricolage Grotesque", "Noto Sans Thai", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
  display: flex;
  flex-direction: column;
}
[hidden] { display: none !important; }
h1, h2 { line-height: 1.15; letter-spacing: -0.01em; text-wrap: balance; margin: 0; }
p { margin: 0; text-wrap: pretty; }
code, pre { font-family: var(--mono); font-size: 13px; }
a { color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--radius-sm); }

.skip-link { position: absolute; left: 12px; top: -48px; background: var(--panel); padding: 8px 12px; border-radius: var(--radius-sm); z-index: 10; }
.skip-link:focus { top: 12px; }

/* top bar */
.bar {
  height: 60px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; font-weight: 650; }
.crumb { color: var(--muted); font-weight: 500; padding-left: 10px; border-left: 1px solid var(--line-2); }
.account { display: flex; align-items: center; gap: 12px; min-width: 0; }
.who { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: transparent;
  color: var(--ink);
  font: 600 14px/1 var(--sans);
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 160ms ease, border-color 160ms ease, transform 120ms ease;
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--accent-on); height: 44px; padding: 0 18px; }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); }
.btn.danger { color: var(--danger); }
.btn[disabled] { opacity: 0.55; cursor: progress; }

main { flex: 1; min-height: 0; display: flex; }
.state { margin: auto; padding: 40px 24px; text-align: center; display: grid; gap: 10px; max-width: 520px; }

/* signed out */
.signin {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 72px 24px;
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 56px;
  align-items: start;
}
.signin-copy { display: grid; gap: 18px; justify-items: start; }
.signin-copy h1 { font-size: clamp(30px, 4vw, 46px); max-width: 14ch; }
.signin-copy p { color: var(--ink-2); max-width: 44ch; }
.error { color: var(--danger); font-size: 14px; }
.signin-steps { border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); padding: 24px; }
.signin-steps h2 { font-size: 17px; margin-bottom: 14px; }
.signin-steps ol { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; counter-reset: step; }
.signin-steps li { display: grid; gap: 6px; padding-left: 34px; position: relative; color: var(--ink-2); counter-increment: step; }
.signin-steps li::before {
  content: counter(step);
  position: absolute;
  left: 0;
  top: 1px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--accent-line);
  color: var(--accent);
  font: 600 12px/22px var(--mono);
  text-align: center;
}
.signin-steps code, .empty code {
  justify-self: start;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 3px 8px;
  color: var(--ink);
}

/* signed in */
.app { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(260px, 340px) 1fr; }
.list { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; background: var(--panel); }
.list-head { padding: 14px; display: grid; gap: 8px; border-bottom: 1px solid var(--line); }
#search {
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-2);
  background: var(--bg);
  color: var(--ink);
  padding: 0 12px;
  font: 14px var(--sans);
}
#search::placeholder { color: var(--muted); }
#sessions { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.item {
  width: 100%;
  display: grid;
  gap: 2px;
  text-align: left;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink);
  font: inherit;
  cursor: pointer;
}
.item:hover { background: var(--hover); }
.item[aria-current="true"] { background: var(--accent-soft); box-shadow: inset 2px 0 0 var(--accent); }
.item .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .m { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 28px 18px; display: grid; gap: 8px; color: var(--ink-2); }
.empty h2 { font-size: 16px; }

.reader { min-width: 0; min-height: 0; overflow-y: auto; }
.reader-empty { height: 100%; display: grid; place-items: center; padding: 24px; }
.chat-head {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 24px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.chat-title { flex: 1; min-width: 0; }
.chat-title h1 { font-size: 19px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back { display: none; }

/* minmax(0, 1fr): long unbroken lines (paths, Thai text, code) must wrap, not widen the column. */
.messages { list-style: none; margin: 0 auto; padding: 24px; max-width: 820px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; }
.msg { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; min-width: 0; }
.msg .role { font: 600 12px/1 var(--mono); color: var(--muted); }
.msg.user .body { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.msg .body { color: var(--ink); overflow-wrap: anywhere; }
.msg .body p { white-space: pre-wrap; }
.msg .body > * + * { margin-top: 10px; }
.msg .body .h { font-weight: 700; }
.msg .body ul { margin: 0; padding-left: 20px; }
.msg .body li + li { margin-top: 2px; }
.msg .body :not(pre) > code { background: var(--card); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; font-size: 0.88em; }
.badge { font: 600 11.5px/1 var(--mono); border-radius: 999px; padding: 3px 8px; border: 1px solid var(--line-2); color: var(--ink-2); vertical-align: 1px; }
.badge.green { color: var(--ok, #6ee7b7); border-color: color-mix(in srgb, var(--ok, #6ee7b7) 45%, transparent); }
.badge.red { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 45%, transparent); }
.badge.yellow { color: #e0b34a; border-color: rgba(224, 179, 74, 0.45); }
.msg pre {
  margin: 10px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--panel);
  border: 1px solid var(--line);
  overflow-x: auto;
  white-space: pre;
}
.tools { display: flex; flex-wrap: wrap; gap: 6px; }
.tool { font: 12px/1 var(--mono); color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 4px 8px; }
.tool.error { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }

@media (max-width: 860px) {
  .signin { grid-template-columns: 1fr; padding: 40px 20px; gap: 32px; }
  .app { grid-template-columns: 1fr; }
  .list { border-right: 0; }
  .app.reading .list { display: none; }
  .app:not(.reading) .reader { display: none; }
  .back { display: inline-flex; }
  .chat-head { padding: 12px 16px; flex-wrap: wrap; }
  .messages { padding: 18px 16px; }
  .crumb { display: none; }
}

.chat-search { padding: 14px 24px; display: grid; gap: 8px; }
.chat-search input { background: var(--panel); color: var(--ink); border: 1px solid var(--line-2); border-radius: 4px; padding: 10px; font: inherit; }
details.tool-detail { border: 1px solid var(--line); border-radius: 4px; padding: 10px 12px; min-width: 0; }
details.tool-detail summary { cursor: pointer; font: 13px var(--mono); overflow-wrap: anywhere; }
details.tool-detail pre { max-height: 440px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
#remote-panel { border-bottom: 1px solid var(--line); }

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}

/* Remote: a quiet, collapsed section above the open chat. */
.remote { margin: 16px 24px 0; border: 1px solid var(--line); border-radius: var(--radius); padding: 0 14px; }
.remote[hidden] { display: none; }
.remote summary { cursor: pointer; padding: 12px 0; font-weight: 600; font-size: 14px; }
.remote[open] { padding-bottom: 14px; }
.remote p { margin: 0 0 10px; color: var(--ink-2); font-size: 13px; }
.remote select, .remote textarea, .remote input[type=file] { display: block; width: 100%; margin: 0 0 10px; font: inherit; color: var(--ink); background: var(--card); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; }
.remote textarea { min-height: 72px; resize: vertical; }
.remote button { font: inherit; font-size: 13px; font-weight: 600; color: var(--bg); background: var(--ink); border: 0; border-radius: 6px; padding: 8px 14px; cursor: pointer; }
.remote button:disabled { opacity: .45; cursor: not-allowed; }
.remote p[role=status] { margin: 10px 0 0; }
