:root { --sidebar-w: 280px; --thread: 720px; }

body {
  --bg: #1c1c1c;
  --sidebar: #1c1c1c;
  --surface: #2a2a2a;
  --ink: #d2d2d2;
  --muted: #8f8f8f;
  --line: #343434;
  --hover: #2a2a2a;
  color: var(--ink);
  background: var(--bg);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

button {
  appearance: none;
  -webkit-appearance: none;
  box-shadow: none;
  background-image: none;
}

button.primary {
  border: 0;
  background: #e4e4e4;
  color: #1c1c1c;
  border-radius: 8px;
  padding: 7px 14px;
  font-weight: 500;
  letter-spacing: 0;
}
button.primary:hover:not(:disabled) { background: #f2f2f2; }
button.primary:active:not(:disabled) { background: #d6d6d6; }

button.btn, a.btn {
  box-shadow: none;
  background-image: none;
  color: var(--ink);
}

.login form { width: min(480px, 100%); }
.login .lead { margin: 0; }

button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, .composer:focus-within {
  outline: 2px solid #5c5c5c;
  outline-offset: 2px;
}

.chat-app { height: 100vh; }
.chat-app .sidebar {
  height: 100vh;
  background: var(--bg);
  border-right: 1px solid #2a2a2a;
  padding: 18px 14px 16px;
  gap: 2px;
}
.chat-app .main { height: 100vh; min-height: 0; }
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 2px 6px 12px;
}
.side-title { font-size: 16px; font-weight: 500; color: var(--ink); }
.icon-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
}
.icon-btn:hover, .icon-btn[aria-current="true"] { background: var(--hover); color: var(--ink); }
.icon-btn .tip, .icon-file .tip {
  position: absolute;
  width: max-content;
  max-width: 240px;
  padding: 6px 8px;
  border-radius: 6px;
  background: #2c2c2c;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.4;
  box-shadow: 0 0 0 1px var(--line);
  opacity: 0;
  pointer-events: none;
  z-index: 3;
}
.icon-btn .tip { top: calc(100% + 6px); right: 0; }
.icon-btn:hover .tip, .icon-btn:focus-visible .tip { opacity: 1; }

.side-list.agents {
  overflow: auto;
  flex: 1;
  min-height: 0;
  max-height: none;
  padding-right: 2px;
  align-content: start;
  gap: 1px;
}
.side-day {
  margin: 12px 8px 2px;
  color: #6e6e6e;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0;
}
.side-list.agents .side-day:first-child { margin-top: 2px; }
.chat-app .side-quiet { margin-top: 0; color: #8a8a8a; background: transparent; }
.side-foot { margin-top: auto; display: grid; gap: 2px; padding-top: 16px; }
.side-foot .side-quiet { padding: 5px 8px; }
.side-foot .side-quiet:hover, .chat-app .side-quiet:hover { background: transparent; color: var(--ink); }
.side-foot .side-quiet.on { color: var(--ink); }

.agent-row { border-radius: 6px; }
.agent-row .pick {
  border: 0;
  background: transparent;
  text-align: left;
  border-radius: 6px;
  padding: 5px 8px;
  min-height: 32px;
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-width: 0;
  color: inherit;
}
.agent-row .pick:hover { background: #242424; }
.agent-row.active .pick,
.agent-row.active .pick:hover,
.agent-row .pick[aria-current="true"] { background: #2c2c2c; }
.agent-name {
  flex: 1;
  min-width: 0;
  font-size: 13px;
  font-weight: 400;
  color: #8f8f8f;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.agent-row.active .agent-name { color: #f2f2f2; }
.agent-row:hover:not(.active) .agent-name { color: #a6a6a6; }
.agent-row.archived .agent-name,
.agent-row.archived .when { color: #7a7a7a; }
.when { flex: none; font-size: 12px; color: #6a6a6a; white-space: nowrap; }
.row-spin {
  width: 12px;
  height: 12px;
  flex: 0 0 12px;
  box-sizing: border-box;
  border-radius: 50%;
  border: 1.5px solid #3a3a3a;
  border-top-color: #f2f2f2;
  border-right-color: #f2f2f2;
  animation: run-spin 0.7s linear infinite;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 1px 7px;
  background: #3a3a3a;
  color: #dedede;
  font-size: 11px;
  line-height: 1.6;
  white-space: nowrap;
}
.pill.run { background: #5c4ee0; color: #f4f4f8; }
.pill.done { background: #1e3328; color: #b7ebc9; }
.pill.bad { background: var(--mis); color: var(--mis-ink); }

.chat-head {
  display: grid;
  grid-template-columns: 1fr min(var(--thread), calc(100% - 32px)) 1fr;
  align-items: start;
  column-gap: 12px;
  padding: 20px 18px 0;
}
.chat-head .page-title {
  grid-column: 2;
  margin: 0;
  font-size: 20px;
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
  overflow-wrap: anywhere;
}
.head-actions {
  grid-column: 3;
  justify-self: end;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.status-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid #3a3a3a;
  background: #262626;
  color: #c8c8c8;
  border-radius: 8px;
  padding: 5px 10px;
  font-size: 13px;
}
.status-btn:hover:not(:disabled) { background: #303030; color: var(--ink); }
a.status-btn { text-decoration: none; }

.chat-app .canvas {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 18px 24px 16px;
}
.thread {
  width: min(var(--thread), 100%);
  min-height: 100%;
  display: flex;
  flex-direction: column;
}
.compose { margin-top: auto; display: grid; gap: 12px; width: 100%; padding-top: 20px; position: sticky; bottom: 0; background: var(--bg); }
.setup { display: grid; gap: 10px; }
.setup .lead { margin: 0; }
.composer {
  border: 1px solid #3a3a3a;
  border-radius: 14px;
  background: #1a1a1a;
  padding: 12px 12px 8px;
  display: grid;
  gap: 4px;
}
.composer textarea {
  width: 100%;
  min-height: 112px;
  border: 0;
  background: transparent;
  resize: none;
  padding: 2px 4px;
  font: inherit;
  color: var(--ink);
}
.composer textarea:focus { outline: none; }
.composer textarea::placeholder { color: #6e6e6e; opacity: 1; }
.composer-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
label.check { display: flex; grid-template-columns: none; align-items: center; gap: 8px; color: var(--ink); }
label.check input { width: auto; margin: 0; }
.icon-file {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  margin: 0;
  padding: 0;
  border-radius: 8px;
  color: #8f8f8f;
  cursor: pointer;
}
.icon-file:hover, .icon-file:focus-within { background: var(--hover); color: var(--ink); }
.icon-file input { display: none; }
.icon-file .tip { left: 0; bottom: calc(100% + 8px); }
.icon-file:hover .tip, .icon-file:focus-within .tip { opacity: 1; }
button.send {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #ffffff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
button.send:hover:not(:disabled) { background: #2e2e2e; color: #ffffff; }
.hint { margin: 0; color: var(--muted); font-size: 13px; }
.hint:empty { display: none; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; }
.thumb { position: relative; width: 72px; height: 72px; }
.thumb img { width: 72px; height: 72px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); background: #111; }
.thumb.file {
  width: auto;
  min-width: 72px;
  max-width: 220px;
  display: flex;
  align-items: flex-end;
  padding: 8px 26px 8px 8px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #111;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.3;
}
.thumb.file span {
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.thumb button {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: white;
  line-height: 22px;
}

.run-panel { display: grid; gap: 8px; justify-items: start; width: 100%; }
.ask {
  margin: 0;
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.run-line {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 13px;
}
.run-mark {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  box-sizing: border-box;
  border-radius: 50%;
  border: 2px solid #4a4a4a;
}
.run-mark.live {
  border-width: 2.5px;
  border-color: #f2f2f2 #f2f2f2 #3a3a3a #3a3a3a;
  animation: run-spin 0.7s linear infinite;
}
@keyframes run-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .run-mark.live, .row-spin { animation: none; }
  .run-mark.live { border-color: #f2f2f2; }
}
.reply {
  font-family: inherit;
  font-size: 15px;
  font-weight: 400;
  line-height: 1.55;
  letter-spacing: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  color: #e4e4e4;
  background: #2e2e2e;
  border: 0;
  border-radius: 10px;
  padding: 8px 12px;
  min-height: 0;
  width: fit-content;
  max-width: 100%;
  margin: 0;
}
.queue-panel { margin-top: 22px; display: grid; gap: 10px; width: 100%; }
.queue-item {
  display: grid;
  gap: 4px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.queue-item p { margin: 0; }
.busy-actions { margin-top: 8px; }
.warn { padding: 8px 10px; border-radius: var(--radius-control); margin: 0 0 14px; font-size: 13px; background: var(--extra); color: var(--extra-ink); }
.login input::placeholder { color: var(--muted); opacity: 1; }

@media (max-width: 800px) {
  .chat-app, .chat-app .sidebar, .chat-app .main { height: auto; }
  .side-list.agents { max-height: 280px; min-height: 120px; flex: none; }
  input, textarea, select { font-size: 16px; }
  button.primary { min-height: 44px; padding: 10px 14px; }
  .composer textarea { min-height: 140px; }
  .chat-app .canvas { padding: 16px 16px 24px; }
  .chat-head { grid-template-columns: 1fr; padding: 16px 16px 0; }
  .chat-head .page-title, .head-actions { grid-column: 1; }
  .head-actions { justify-self: start; }
}
