/* Client portal palette, adapted from the human-review light chrome. */
:root {
  --canvas: #eef3f8;
  --rail: #ffffff;
  --card: #ffffff;
  --card-border: #dce5ef;
  --hair: #d9e2ec;
  --hair-2: #e8eef5;
  --dash: #cbd7e4;
  --strong-border: #b9c8d8;
  --txt: #27384a;
  --strong-txt: #15283c;
  --mute: #708196;
  --mute-2: #52677e;
  --faint: #9bacbd;
  --faint-2: #899eb1;
  --soft: #f3f7fb;
  --chip: #eaf1f8;
  --input-bg: #fbfdff;
  --focus: #7ea2c7;
  --danger: #ad3f43;
  --danger-soft: #faeeee;
  --amber: #b97916;
  --green: #477a62;
  --btn-bg: #234b7a;
  --btn-fg: #ffffff;
  --rail-w: 380px;
}

:root[data-theme="dark"] {
  --canvas: #171614;
  --rail: #1f1e1b;
  --card: #262420;
  --card-border: #34322d;
  --hair: #2f2d29;
  --hair-2: #2a2825;
  --dash: #3a3833;
  --strong-border: #403d37;
  --txt: #eae7e0;
  --strong-txt: #f4f1ea;
  --mute: #9c968a;
  --mute-2: #a8a29a;
  --faint: #6e6961;
  --faint-2: #837d74;
  --soft: #2c2a26;
  --chip: #2e2c27;
  --input-bg: #1c1b18;
  --focus: #4d4941;
  --danger: #d9705f;
  --danger-soft: #3a2320;
  --amber: #d9a520;
  --green: #8ea37f;
  --btn-bg: #f0ede6;
  --btn-fg: #1b1a16;
}

* { box-sizing: border-box; }

/* Author display rules beat the UA rule for [hidden], so restate it. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  background: var(--canvas);
  color: var(--txt);
  font: 13px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, textarea { font: inherit; color: inherit; }

.app { display: flex; height: 100vh; }

/* The artifact takes all remaining width and styles itself. */
.stage { flex: 1; min-width: 0; background: var(--canvas); }
#frame { width: 100%; height: 100%; border: 0; display: block; background: #ffffff; }

.handle {
  position: fixed;
  top: 50%;
  right: var(--rail-w);
  z-index: 40;
  width: 22px;
  height: 46px;
  margin-top: -23px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--hair);
  border-right: 0;
  border-radius: 7px 0 0 7px;
  background: var(--rail);
  color: var(--mute);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  box-shadow: -2px 0 8px -6px rgba(0, 0, 0, 0.28);
  transition: right 140ms ease-out;
}
.handle:hover { color: var(--strong-txt); background: var(--soft); }

.rail {
  flex: none;
  width: var(--rail-w);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border-left: 1px solid var(--hair);
  background: var(--rail);
  transition: width 140ms ease-out;
}
body.collapsed .rail { width: 0; border-left-width: 0; }
body.collapsed .handle { right: 0; }

.rail-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 16px 12px 12px; }

.rail-head { display: flex; align-items: baseline; gap: 7px; padding: 0 4px 9px; }
.rail-head.tight { padding-top: 0; }
.section {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--mute);
}
.dim { color: var(--faint); font-size: 11px; }

.icon-btn {
  margin-left: auto;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--hair);
  border-radius: 7px;
  background: var(--soft);
  font-size: 12.5px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { border-color: var(--strong-border); color: var(--strong-txt); }

.link-btn {
  margin-left: auto;
  border: 0;
  padding: 0;
  background: none;
  color: var(--faint-2);
  font-size: 11px;
  cursor: pointer;
}
.link-btn:hover { color: var(--strong-txt); }
.danger-hover:hover { color: var(--danger); }

/* Compose card — always in the rail, never floating over the artifact. */
.compose {
  margin-bottom: 8px;
  padding: 13px 14px;
  border: 1px solid var(--strong-border);
  border-radius: 8px;
  background: var(--card);
  box-shadow: 0 4px 14px -8px rgba(27, 26, 22, 0.3);
  animation: rise 130ms ease-out;
}
.compose-head { display: flex; align-items: center; gap: 7px; margin-bottom: 9px; }
.chip {
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--mute);
  font-size: 10px;
  font-weight: 600;
}
.quote {
  margin: 0 0 10px;
  padding-left: 9px;
  border-left: 2px solid rgba(245, 196, 0, 0.7);
  color: var(--mute);
  font-size: 12px;
  font-style: italic;
  line-height: 1.45;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.compose textarea, .rail-foot textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--hair);
  border-radius: 6px;
  background: var(--input-bg);
  font-size: 13px;
  line-height: 1.5;
  resize: none;
  outline: none;
}
.compose textarea:focus, .rail-foot textarea:focus { border-color: var(--focus); background: var(--card); }
.compose-actions { margin-top: 9px; display: flex; align-items: center; gap: 8px; }

.btn-primary {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 6px 11px;
  border: 1px solid var(--btn-bg);
  border-radius: 6px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}
.btn-ghost {
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--mute);
  font-size: 12px;
  cursor: pointer;
}
.btn-ghost:hover { background: var(--soft); color: var(--strong-txt); }
.key { font-size: 10.5px; opacity: 0.55; }

.cards { display: flex; flex-direction: column; gap: 8px; }
.comment {
  padding: 13px 14px;
  border: 1px solid var(--card-border);
  border-radius: 8px;
  background: var(--card);
  box-shadow: inset 2px 0 0 transparent;
  cursor: pointer;
}
.comment.active { box-shadow: inset 2px 0 0 #e0a800; }
.comment-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.who { color: var(--mute-2); font-size: 11px; font-weight: 500; }
.who .sep { color: var(--focus); margin: 0 4px; }
.who .when { color: var(--faint-2); }
.jump {
  margin-left: auto;
  border: 0;
  padding: 0;
  background: none;
  color: var(--faint-2);
  font-size: 11px;
  white-space: nowrap;
  cursor: pointer;
}
.jump:hover { color: var(--strong-txt); }
.remove {
  width: 18px;
  height: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--faint);
  font-size: 10px;
  line-height: 1;
  cursor: pointer;
}
.remove:hover { background: var(--danger-soft); color: var(--danger); }
.end-review {
  margin-top: 9px;
  width: 100%;
  padding: 6px;
  background: none;
  border: none;
  color: var(--faint-2);
  font-size: 12px;
  cursor: pointer;
  border-radius: 6px;
}
.end-review:hover { color: var(--danger); background: var(--danger-soft); }

.ended {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: var(--rail);
  color: var(--txt);
}
.ended h2 { margin: 0; font-size: 17px; color: var(--strong-txt); }
.ended p { margin: 0; font-size: 13px; color: var(--mute-2); }

.comment .quote { -webkit-line-clamp: 2; margin-bottom: 8px; }
.comment .body { margin: 0; font-size: 13px; line-height: 1.5; cursor: text; border-radius: 4px; }
.comment .body:hover { background: var(--input-bg); box-shadow: 0 0 0 4px var(--input-bg); }
.comment .body-edit {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--focus);
  border-radius: 6px;
  background: var(--card);
  font-size: 13px;
  line-height: 1.5;
  resize: none;
  outline: none;
}
.badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--faint-2);
  font-size: 10px;
  font-weight: 600;
}

.empty {
  padding: 16px 14px;
  border: 1px dashed var(--dash);
  border-radius: 8px;
  color: var(--faint);
  font-size: 11.5px;
  line-height: 1.5;
  text-align: center;
}

#editsBox { margin-top: 20px; animation: rise 140ms ease-out; }
.save-line { display: flex; align-items: center; gap: 7px; padding: 0 4px 9px; color: var(--faint-2); font-size: 11px; }
.save-line.saving { color: var(--mute); }
.save-line.failed { color: var(--danger); }
.save-line.dynamic { color: var(--mute); }
.save-line.dynamic .dot { background: var(--amber); }
.dot { width: 6px; height: 6px; flex: none; border-radius: 50%; background: var(--green); }
.save-line.saving .dot { background: var(--amber); }
.save-line.failed .dot { background: var(--danger); }
.dot.amber { background: var(--amber); }

.edit-list { border: 1px solid var(--card-border); border-radius: 8px; background: var(--card); overflow: hidden; }
.edit-row { display: flex; align-items: center; gap: 9px; padding: 9px 12px; border-top: 1px solid var(--hair-2); }
.edit-row:first-child { border-top: 0; }
.edit-row .pip { width: 5px; height: 5px; flex: none; border-radius: 50%; background: var(--amber); }
.edit-row.deleted .pip { background: var(--danger); }
.edit-row .label { font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.edit-row .kind { margin-left: auto; color: var(--faint-2); font-size: 11px; white-space: nowrap; }

.edit-more {
  width: 100%;
  padding: 8px 12px;
  border: 0;
  border-top: 1px solid var(--hair-2);
  background: transparent;
  color: var(--faint-2);
  font-size: 11.5px;
  text-align: left;
  cursor: pointer;
}
.edit-more:hover { background: var(--soft); color: var(--strong-txt); }

.other-row {
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: inherit;
}
.other-row:hover { background: var(--soft); }

.rail-foot { flex: none; padding: 12px; border-top: 1px solid var(--hair-2); }
.rail-foot textarea { min-height: 58px; max-height: 40vh; margin-bottom: 9px; font-size: 12.5px; overflow-y: auto; resize: vertical; }

.send {
  width: 100%;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--btn-bg);
  border-radius: 6px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}
.send:disabled { border-color: var(--hair); background: var(--soft); color: var(--faint); cursor: default; }

.agent-line {
  margin: 10px 2px 2px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--faint);
  font-size: 11px;
  line-height: 1.4;
}

/* Shown after Send when nothing is polling, so the loop never dead-ends. */
.handoff {
  margin-top: 10px;
  padding: 11px 12px;
  border: 1px solid var(--strong-border);
  border-radius: 8px;
  background: var(--card);
  animation: rise 140ms ease-out;
}
.handoff-title { margin: 0 0 4px; font-size: 12px; font-weight: 600; }
.handoff-body { margin: 0 0 8px; color: var(--mute); font-size: 11.5px; line-height: 1.45; }
.handoff-cmd {
  margin-bottom: 8px;
  padding: 8px 9px;
  border-radius: 6px;
  background: var(--input-bg);
  border: 1px solid var(--hair);
  overflow-x: auto;
}
.handoff-cmd code {
  font: 11.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}
.handoff .btn-ghost { padding: 5px 9px; font-size: 11.5px; }

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  z-index: 60;
  padding: 8px 14px;
  border-radius: 8px;
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
  animation: rise 140ms ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, .rail, .handle { animation: none !important; transition: none !important; }
}

/* Portal pages */
body:not(.review-body) { min-height: 100%; height: auto; overflow: auto; }
.eyebrow {
  margin: 0 0 7px;
  color: var(--mute-2);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
}
.login-shell, .message-card {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card, .message-card > * {
  width: min(100%, 390px);
}
.login-card {
  padding: 34px;
  border: 1px solid var(--card-border);
  border-radius: 16px;
  background: var(--card);
  box-shadow: 0 18px 50px rgba(28, 52, 78, .09);
}
.login-card h1, .workspace-head h1, .message-card h1 {
  margin: 0 0 24px;
  color: var(--strong-txt);
  font-size: 27px;
  line-height: 1.18;
  letter-spacing: -.025em;
}
.login-card label {
  display: grid;
  gap: 7px;
  margin: 16px 0;
  color: var(--mute-2);
  font-size: 12px;
  font-weight: 650;
}
.login-card input, .filter-label select {
  width: 100%;
  border: 1px solid var(--strong-border);
  border-radius: 8px;
  background: var(--input-bg);
  color: var(--txt);
  font: inherit;
  outline: none;
}
.login-card input { padding: 11px 12px; }
.login-card input:focus, .filter-label select:focus { border-color: var(--focus); box-shadow: 0 0 0 3px rgba(71, 116, 161, .12); }
.login-submit { width: 100%; margin-top: 10px; padding: 11px; }
.form-error, .inline-error, .anchor-warning { color: var(--danger); }
.form-error { padding: 9px 11px; border-radius: 7px; background: var(--danger-soft); }

.workspace-shell { width: min(100% - 40px, 880px); margin: 0 auto; padding: 72px 0; }
.workspace-head { margin-bottom: 30px; }
.workspace-head h1 { margin-bottom: 7px; }
.workspace-head > p:last-child { margin: 0; color: var(--mute-2); }
.file-list { display: grid; gap: 12px; margin: 0; padding: 0; list-style: none; }
.file-card a {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-width: 0;
  padding: 20px 22px;
  border: 1px solid var(--card-border);
  border-radius: 11px;
  background: var(--card);
  color: inherit;
  text-decoration: none;
  box-shadow: 0 7px 20px rgba(28, 52, 78, .045);
}
.file-card a:hover { border-color: var(--focus); transform: translateY(-1px); }
.file-card strong { min-width: 0; overflow-wrap: anywhere; color: var(--strong-txt); font-size: 14px; }
.file-card span { flex: none; color: var(--mute); font-size: 12px; }
.empty-list { padding: 30px; border: 1px dashed var(--dash); border-radius: 10px; color: var(--mute); text-align: center; }

.review-body { background: var(--canvas); }
.review-app { display: grid; grid-template-columns: minmax(0, 1fr) var(--rail-w); height: 100vh; }
.review-stage { min-width: 0; display: grid; grid-template-rows: 48px minmax(0, 1fr); }
.version-bar {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 18px;
  min-width: 0;
  padding: 0 17px;
  border-bottom: 1px solid var(--hair);
  background: var(--rail);
  color: var(--mute-2);
  font-size: 12px;
}
.version-bar a { color: var(--btn-bg); font-weight: 650; text-decoration: none; }
.version-title { min-width: 0; overflow: hidden; color: var(--strong-txt); font-weight: 650; text-align: center; text-overflow: ellipsis; white-space: nowrap; }
#review-frame { width: 100%; height: 100%; border: 0; display: block; background: #ffffff; }
.review-rail {
  min-width: 0;
  overflow-y: auto;
  padding: 22px 18px;
  border-left: 1px solid var(--hair);
  background: var(--rail);
}
.review-rail > .rail-head { align-items: end; margin-bottom: 20px; padding: 0 2px; }
.review-rail h1 { margin: 0; color: var(--strong-txt); font-size: 20px; letter-spacing: -.02em; }
.filter-label { display: grid; gap: 4px; color: var(--mute); font-size: 10px; }
.filter-label select { min-width: 112px; padding: 6px 8px; font-size: 11px; }
.review-rail .compose { margin: 0 0 14px; }
.thread-list { display: grid; gap: 12px; }
.thread-card {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--card-border);
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 4px 13px rgba(28, 52, 78, .04);
}
.thread-card.resolved { opacity: .68; }
.thread-head { display: flex; align-items: start; justify-content: space-between; gap: 9px; margin-bottom: 9px; }
.anchor-label, .thread-state {
  border: 0;
  background: none;
  cursor: pointer;
}
.anchor-label { min-width: 0; padding: 0; overflow: hidden; color: var(--btn-bg); font-weight: 650; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.thread-state { flex: none; padding: 1px 0; color: var(--mute); font-size: 10.5px; }
.comment-meta { margin: 0 0 5px; color: var(--mute); font-size: 10.5px; }
.comment-meta strong { color: var(--mute-2); }
.comment-body { margin: 0; color: var(--txt); overflow-wrap: anywhere; white-space: pre-wrap; }
.replies { display: grid; gap: 10px; margin: 13px 0 0 13px; padding-left: 12px; border-left: 2px solid var(--hair-2); }
.reply .comment-body { font-size: 12px; }
.reply-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px; margin-top: 13px; }
.reply-form textarea { min-width: 0; min-height: 54px; padding: 8px; }
.reply-form .btn-ghost { align-self: end; }
.reply-form .inline-error { grid-column: 1 / -1; margin: 0; font-size: 11px; }
.anchor-warning { margin: 8px 0 0; font-size: 10.5px; }

@media (max-width: 780px) {
  :root { --rail-w: 100%; }
  .review-body { height: auto; overflow: auto; }
  .review-app { grid-template-columns: 1fr; grid-template-rows: 62vh auto; height: auto; min-height: 100vh; }
  .review-stage { min-height: 0; }
  .review-rail { min-height: 38vh; border-top: 1px solid var(--hair); border-left: 0; }
  .version-bar { grid-template-columns: auto minmax(0, 1fr); }
  .version-bar > span:last-child { display: none; }
  .file-card a { align-items: start; flex-direction: column; }
}
