* { box-sizing: border-box; }
body {
  font-family: system-ui, sans-serif;
  margin: 0;
  color: #222;
  background: #f7f7f8;
}

.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
}

.login-form {
  background: #fff;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  width: 280px;
}

.login-form h1 { margin: 0 0 0.5rem; font-size: 1.25rem; }
.login-form label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; }
.login-form input { padding: 0.5rem; font-size: 1rem; }
.login-form button, .top-bar button {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 4px;
  background: #2563eb;
  color: #fff;
  cursor: pointer;
}
.error { color: #b91c1c; margin: 0; font-size: 0.9rem; }

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 2rem;
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
}
.top-bar h1 { margin: 0; font-size: 1.1rem; }
.top-bar-right { display: flex; align-items: center; gap: 1rem; }
.refresh-indicator { font-size: 0.8rem; color: #888; min-width: 8.5em; text-align: right; }

main { padding: 1.5rem 2rem; display: flex; flex-direction: column; gap: 2rem; }
section h2 { font-size: 1rem; margin-bottom: 0.5rem; }

table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  font-size: 0.85rem;
}
th, td {
  text-align: left;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid #eee;
  vertical-align: top;
}
th { color: #666; font-weight: 600; }

tr.status-failed { background: #fef2f2; }
tr.status-running { background: #fefce8; }
tr.status-pending { background: #eff6ff; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}
.filter-input, .filter-select {
  padding: 0.4rem 0.6rem;
  font-size: 0.85rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
}
.filter-input { flex: 1 1 240px; min-width: 180px; }

.info-btn {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;
  color: #2563eb;
  line-height: 1;
  padding: 0.15rem;
}
.info-btn:hover { color: #1d4ed8; }

.retry-btn {
  padding: 0.25rem 0.6rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 0.75rem;
  color: #b45309;
  margin-left: 0.4rem;
}
.retry-btn:hover:not(:disabled) { background: #fffbeb; border-color: #fbbf24; }
.retry-btn:disabled { opacity: 0.6; cursor: default; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
  padding: 0.6rem 0;
  font-size: 0.8rem;
  color: #555;
}
.page-btn {
  padding: 0.3rem 0.7rem;
  border: 1px solid #ddd;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
  font-size: 0.8rem;
}
.page-btn:disabled { opacity: 0.4; cursor: default; }
.page-btn:not(:disabled):hover { background: #f3f4f6; }

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  align-items: center;
  justify-content: center;
  padding: 2rem;
  z-index: 1000;
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff;
  border-radius: 8px;
  width: 100%;
  max-width: 720px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #eee;
}
.modal-header h3 { margin: 0; font-size: 1rem; }
.modal-close {
  border: none;
  background: none;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: #666;
}
.modal-close:hover { color: #222; }
.modal-body {
  margin: 0;
  padding: 1.25rem;
  overflow: auto;
  font-size: 0.85rem;
  line-height: 1.5;
  background: #fff;
}
.modal-body > pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.detail-summary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.4rem 1rem;
  margin: 0 0 1rem;
}
.detail-summary dt {
  font-weight: 600;
  color: #555;
  white-space: nowrap;
}
.detail-summary dd {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.token-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.5rem;
  margin: 0 0 1rem;
}
.token-tile {
  padding: 0.6rem 0.8rem;
  border: 1px solid #e2e2e2;
  border-radius: 6px;
  background: #f9fafb;
}
.token-tile-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.token-tile-value {
  font-size: 1.25rem;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  margin-top: 0.15rem;
}

.detail-raw summary {
  cursor: pointer;
  font-size: 0.8rem;
  color: #2563eb;
  margin-bottom: 0.5rem;
}
.detail-raw pre {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #f3f4f6;
  padding: 0.75rem;
  border-radius: 4px;
  max-height: 320px;
  overflow: auto;
}

/* Live conversation transcript in the run detail modal */
.transcript { max-height: 420px; overflow-y: auto; padding: 8px; background: #fafafa; border: 1px solid #ddd; border-radius: 4px; font-size: 13px; }
.tr-ev { margin: 0 0 8px; padding: 6px 8px; border-left: 3px solid #bbb; background: #fff; }
.tr-text { border-left-color: #4f7cff; }
.tr-tool_use { border-left-color: #b8860b; }
.tr-tool_result { border-left-color: #2e8b57; }
.tr-error { border-left-color: #c0392b; }
.tr-result { border-left-color: #7b3fe4; }
.tr-label { display: block; font-weight: 600; font-size: 12px; color: #555; margin-bottom: 2px; }
.tr-body { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* Readable tool cards in the transcript */
.tr-ev { font-family: inherit; }
.tr-prose { white-space: pre-wrap; word-break: break-word; }
.tr-head { cursor: pointer; display: flex; gap: 8px; align-items: baseline; list-style: none; }
.tr-head::-webkit-details-marker { display: none; }
.tr-icon { font-family: ui-monospace, Menlo, monospace; color: #b8860b; width: 1.2em; text-align: center; }
.tr-title { font-weight: 600; font-size: 12px; }
.tr-summary { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Menlo, monospace; font-size: 12px; color: #444; }
.tr-time { font-size: 11px; color: #999; }
.tr-done { border-left-color: #2e8b57; }
.tr-failed { border-left-color: #c0392b; }
.tr-init { border-left-color: #999; }
.tool-section { margin-top: 6px; }
.tool-section-label { font-size: 11px; font-weight: 600; color: #777; text-transform: uppercase; margin: 6px 0 2px; }
.tool-note { font-size: 12px; color: #666; margin: 4px 0; }
.code-wrap { position: relative; }
.copy-btn, .more-btn { font-size: 11px; cursor: pointer; border: 1px solid #ccc; background: #fff; border-radius: 3px; padding: 1px 6px; }
.copy-btn { position: absolute; top: 4px; right: 4px; opacity: .7; }
.more-btn { margin-top: 4px; }
.code-block { margin: 0; padding: 8px; background: #f4f4f4; border: 1px solid #e2e2e2; border-radius: 4px; white-space: pre-wrap; word-break: break-word; font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.code-block.terminal { background: #1e1e1e; color: #e6e6e6; border-color: #1e1e1e; }
.code-block.result-error { background: #fdecea; border-color: #f5c6c0; }
.code-block.diff { padding: 0; background: #fff; }
.diff-line { display: block; padding: 0 8px; }
.diff-add { background: #e6ffed; color: #1a7f37; }
.diff-del { background: #ffebe9; color: #b42318; }
.kv-table { border-collapse: collapse; font-size: 12px; margin: 4px 0; width: 100%; }
.kv-table th { text-align: left; padding: 2px 10px 2px 0; color: #666; font-weight: 600; white-space: nowrap; vertical-align: top; width: 1%; }
.kv-table td { padding: 2px 0; font-family: ui-monospace, Menlo, monospace; word-break: break-word; white-space: pre-wrap; }
.curl-box { border: 1px solid #ddd; border-radius: 4px; padding: 6px 8px; background: #fff; margin-bottom: 6px; }
.curl-head { display: flex; gap: 8px; align-items: baseline; margin-bottom: 4px; }
.curl-url { font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all; }
.http-method { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 3px; color: #fff; background: #555; }
.m-get { background: #2e8b57; } .m-post { background: #1f6feb; } .m-put, .m-patch { background: #b8860b; } .m-delete { background: #c0392b; }
.todo-list { list-style: none; margin: 4px 0; padding: 0; font-size: 12px; }
.todo-completed { color: #2e8b57; }
.tr-filter { display: flex; gap: 6px; margin: 6px 0; }
.tr-filter-btn { border: 1px solid #ccc; background: #fff; border-radius: 12px; padding: 2px 10px; font-size: 12px; cursor: pointer; }
.tr-filter-btn.active { background: #4f7cff; border-color: #4f7cff; color: #fff; }
[hidden] { display: none !important; }

/* Project memory panel */
.memory-sub { font-size: 12px; font-weight: normal; color: #777; margin-left: 8px; }
.memory-summary { margin: 6px 0 10px; line-height: 1.6; }
.memory-warn { color: #b26a00; }
.memory-toolbar { align-items: center; gap: 8px; }
.memory-toolbar button { padding: 6px 12px; cursor: pointer; }
.memory-toolbar button:disabled { opacity: .5; cursor: not-allowed; }
.primary-btn { background: #1d6ae5; color: #fff; border: 1px solid #1859bf; border-radius: 4px; }
.memory-message.ok { color: #1e7d3a; }
.memory-message.err { color: #c0392b; }
.memory-files { margin-top: 8px; }
.memory-st-added { color: #1e7d3a; }
.memory-st-deleted { color: #c0392b; }
.memory-st-modified { color: #b26a00; }
.memory-runs { margin: 10px 0 0; font-size: 13px; }
.memory-diff { white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; max-height: 60vh; overflow: auto; }
.danger-btn { background: #c0392b; color: #fff; border: 1px solid #a5301f; border-radius: 4px; }
.poll-counter { margin-right: 16px; padding: 4px 10px; border-radius: 12px; background: #eef2ff; color: #1d4ed8; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.diff-btn { background: none; border: 1px solid #c7d2fe; color: #1d4ed8; border-radius: 4px; padding: 2px 8px; cursor: pointer; font-size: 12px; }
.diff-btn:hover { background: #eef2ff; }
/* Memory diff popup: line numbers, coloured add/remove rows, full-file toggle */
.modal.modal-wide { max-width: min(1100px, 96vw); max-height: 88vh; }
.diff-toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.diff-tab { padding: 4px 12px; border: 1px solid #c7d2fe; background: #fff; color: #1d4ed8; border-radius: 4px; cursor: pointer; font-size: 13px; }
.diff-tab.active { background: #1d4ed8; color: #fff; border-color: #1d4ed8; }
.diff-stats { font-size: 13px; color: #444; margin-left: 6px; font-variant-numeric: tabular-nums; }
.diff-legend { margin-left: auto; display: flex; gap: 6px; font-size: 12px; }
.diff-legend .lg { padding: 1px 8px; border-radius: 3px; }
.lg-add { background: #d4f5dc; color: #14532d; }
.lg-del { background: #fddcdc; color: #7f1d1d; }
.diff-holder { max-height: 68vh; overflow: auto; border: 1px solid #ddd; border-radius: 4px; }
.diff-empty { padding: 12px; color: #666; }
.diff-table { border-collapse: collapse; width: 100%; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
.diff-table td { padding: 0 6px; vertical-align: top; }
.diff-no { width: 1%; min-width: 3.2em; text-align: right; color: #8a8f98; user-select: none; background: #f6f7f9; border-right: 1px solid #e3e5e8; white-space: nowrap; }
.diff-sign { width: 1.4em; text-align: center; user-select: none; color: #666; }
.diff-code { white-space: pre-wrap; word-break: break-word; width: 100%; }
.diff-add .diff-code, .diff-add .diff-sign { background: #d4f5dc; }
.diff-add .diff-no { background: #b5ebc3; color: #14532d; }
.diff-del .diff-code, .diff-del .diff-sign { background: #fddcdc; }
.diff-del .diff-no { background: #f7b9b9; color: #7f1d1d; }
.diff-hunk .diff-hunk-text, .diff-note .diff-hunk-text { background: #eaf1fb; color: #3b5b8c; padding: 3px 8px; font-style: italic; }
