* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-size: 13px;
  line-height: 1.45;
  color: #1a1a1a;
  background: #fafafa;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: #fff;
  border-bottom: 1px solid #e2e2e2;
  flex-wrap: wrap;
}
.topbar h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
}
.counts {
  font-weight: 400;
  color: #666;
  margin-left: 8px;
  font-size: 13px;
}
.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.controls input[type="search"],
.controls select {
  font: inherit;
  padding: 5px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
}
.controls input[type="search"] { width: 240px; }

.btn-connect, .btn-download, .btn-primary, .btn-secondary {
  font: inherit;
  padding: 5px 10px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
  cursor: pointer;
}
.btn-connect.connected {
  background: #d4edda;
  border-color: #74c184;
}
.btn-primary {
  background: #1a73e8;
  border-color: #1a73e8;
  color: #fff;
  font-weight: 600;
}
.btn-primary:hover:not(:disabled) { background: #1666cf; border-color: #1666cf; }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary { background: #fff; }
.btn-secondary:hover { background: #f3f3f3; }
.save-status {
  font-size: 12px;
  color: #666;
  min-width: 80px;
}
.save-status.saved { color: #198754; }
.save-status.error { color: #c0392b; }
.save-status.dirty { color: #c08a3c; }

main {
  padding: 12px 20px 60px;
  overflow-x: auto;
}

table {
  border-collapse: collapse;
  width: 100%;
  background: #fff;
  border: 1px solid #e2e2e2;
  border-radius: 6px;
  overflow: hidden;
}
thead { background: #f3f3f3; }
th {
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: #444;
  padding: 8px 10px;
  border-bottom: 1px solid #e2e2e2;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
th[data-sort]::after {
  content: " ";
  display: inline-block;
  width: 0;
  height: 0;
}
th.sort-asc::after  { content: " ▲"; color: #888; }
th.sort-desc::after { content: " ▼"; color: #888; }
td {
  padding: 6px 10px;
  border-bottom: 1px solid #f0f0f0;
  vertical-align: middle;
}
tbody tr:hover { background: #fafbff; }

td.cell-date { white-space: nowrap; color: #555; font-variant-numeric: tabular-nums; }
td.cell-company { font-weight: 600; max-width: 200px; }
td.cell-role { max-width: 260px; color: #333; }
td.cell-files { white-space: nowrap; }
td.cell-files a {
  display: inline-block;
  padding: 2px 6px;
  margin-right: 4px;
  border: 1px solid #d8d8d8;
  border-radius: 3px;
  text-decoration: none;
  color: #333;
  font-size: 11px;
  background: #fff;
}
td.cell-files a:hover { background: #eef2ff; border-color: #b6c1ff; }
td.cell-link a { color: #0a66c2; text-decoration: none; font-size: 12px; }
td.cell-link a:hover { text-decoration: underline; }

select.cell-select, input.cell-input, textarea.cell-textarea {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  padding: 3px 4px;
  width: 100%;
  resize: vertical;
}
select.cell-select:hover, input.cell-input:hover, textarea.cell-textarea:hover {
  border-color: #ccc;
  background: #fff;
}
select.cell-select:focus, input.cell-input:focus, textarea.cell-textarea:focus {
  border-color: #4a8df0;
  background: #fff;
  outline: none;
}
td.cell-comment { min-width: 200px; max-width: 320px; }
td.cell-comment textarea {
  min-height: 28px;
  font-family: inherit;
}

/* Tier color cues – green (best) → red (worst) */
.tier-S { background: #c8eed1; color: #145c2c; }
.tier-A { background: #dff2c7; color: #466e10; }
.tier-B { background: #fff5cc; color: #806000; }
.tier-C { background: #ffe0b8; color: #a05a00; }
.tier-D { background: #ffcebd; color: #a83b0a; }
.tier-E { background: #fcc8c8; color: #962020; }

/* Fit-score badge – objective LLM-scored rubric vs JD */
td.cell-fit { white-space: nowrap; min-width: 64px; text-align: center; }
.fit-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
  cursor: help;
  font-variant-numeric: tabular-nums;
}
.fit-A { background: #c8eed1; color: #145c2c; }
.fit-B { background: #dff2c7; color: #466e10; }
.fit-C { background: #ffe0b8; color: #a05a00; }
.fit-D { background: #fcc8c8; color: #962020; }

/* Result color cues */
.result-waiting    { background: #e7f1ff; color: #1858a8; }
.result-screening  { background: #e1f0ff; color: #0a4a8a; }
.result-interview  { background: #d3eaf7; color: #0a5b86; }
.result-take-home  { background: #d3eaf7; color: #0a5b86; }
.result-final      { background: #c4e0f0; color: #074764; }
.result-offer      { background: #d4f4dd; color: #1a7338; }
.result-rejected   { background: #fde2e2; color: #a02525; }
.result-ghosted    { background: #f0f0f0; color: #666; }
.result-declined   { background: #f4e2fb; color: #6e2092; }
.result-withdrawn  { background: #f0f0f0; color: #666; }

.vacancy-closed { opacity: 0.6; }

/* Row action: delete button (visible on row hover) */
th.th-actions { width: 28px; padding: 8px 6px; }
td.cell-actions {
  width: 28px;
  padding: 4px 6px;
  text-align: right;
  vertical-align: middle;
}
.btn-delete {
  font: inherit;
  font-size: 16px;
  line-height: 1;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: #aaa;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background 0.12s ease, color 0.12s ease;
}
tbody tr:hover .btn-delete,
.btn-delete:focus-visible {
  opacity: 1;
}
.btn-delete:hover {
  background: #fde2e2;
  border-color: #f4baba;
  color: #c0392b;
}
.btn-delete:focus-visible {
  outline: 2px solid #c0392b;
  outline-offset: 1px;
}

td .pill-wrap {
  display: inline-block;
  border-radius: 3px;
  padding: 0;
}
td .pill-wrap select { padding: 3px 18px 3px 8px; }

.footer {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 6px 20px;
  background: #fff;
  border-top: 1px solid #e2e2e2;
  font-size: 11px;
  color: #666;
}
.footer code {
  background: #f0f0f0;
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 11px;
}
.footer button { margin-left: 8px; }

.server-status {
  margin-left: 12px;
  font-size: 11px;
}
.server-status.ok { color: #198754; }
.server-status.off { color: #a05a00; }

/* Generation status badge */
td.cell-status { white-space: nowrap; min-width: 86px; }
.gen-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
}
.gen-queued   { background: #fff5cc; color: #806000; }
.gen-running  { background: #e1f0ff; color: #0a4a8a; animation: pulse 1.6s ease-in-out infinite; }
.gen-failed   { background: #fde2e2; color: #a02525; }
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.55; }
}

/* Circular progress ring for in-flight generations */
.gen-progress {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  line-height: 1;
}
.gen-progress svg {
  flex-shrink: 0;
  display: block;
}
.gen-progress .gp-bg {
  stroke: #e2eaf5;
}
.gen-progress .gp-fg {
  stroke: #1a73e8;
  transition: stroke-dashoffset 0.5s linear;
}
.gen-progress-queued .gp-fg {
  stroke: #d4a000;
  animation: ring-pulse 1.4s ease-in-out infinite;
}
@keyframes ring-pulse {
  0%, 100% { opacity: 0.3; }
  50%      { opacity: 1; }
}
/* Overrun: elapsed > ETA. Indicates "still working, no estimate left". */
.gen-progress-overrun .gp-fg {
  stroke: #d4a000;
  animation: ring-pulse 1.6s ease-in-out infinite;
}
.gen-progress-overrun .gen-progress-text {
  color: #806000;
}
.gen-progress-text {
  font-size: 11px;
  font-weight: 600;
  color: #0a4a8a;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.2px;
  min-width: 28px;
}
.gen-progress-queued .gen-progress-text { color: #806000; }
.btn-retry {
  margin-left: 6px;
  font: inherit;
  font-size: 11px;
  padding: 1px 6px;
  border: 1px solid #c0392b;
  background: #fff;
  color: #c0392b;
  border-radius: 3px;
  cursor: pointer;
}
.btn-retry:hover { background: #fde2e2; }

td.cell-files button.btn-add-qa {
  font: inherit;
  font-size: 11px;
  padding: 2px 6px;
  margin-left: 2px;
  border: 1px dashed #b8b8b8;
  border-radius: 3px;
  background: #fafafa;
  color: #555;
  cursor: pointer;
}
td.cell-files button.btn-add-qa:hover {
  background: #fff5cc;
  border-color: #d4a000;
  color: #6a4d00;
}
td.cell-files button.btn-add-qa[disabled] {
  opacity: 0.45;
  cursor: not-allowed;
}

.dlg-hint-block {
  margin: 0;
  padding: 8px 10px;
  background: #f4f7ff;
  border-left: 3px solid #1a73e8;
  border-radius: 3px;
  font-size: 12px;
  color: #345;
  line-height: 1.45;
}
.dlg-hint-block code {
  background: #e1e8f5;
  padding: 1px 4px;
  border-radius: 2px;
  font-size: 11.5px;
}
.dlg-target {
  font-size: 12px;
  color: #555;
}
.dlg-target strong { color: #111; }

tr.flash-new {
  animation: flash 1.4s ease-out 1;
}
@keyframes flash {
  0%   { background: #fff5cc; }
  100% { background: transparent; }
}

/* New-application dialog */
dialog.new-app-dialog {
  border: none;
  border-radius: 8px;
  padding: 0;
  width: min(720px, 92vw);
  max-height: 92vh;
  box-shadow: 0 10px 40px rgba(0,0,0,0.18);
}
dialog.new-app-dialog::backdrop {
  background: rgba(20, 25, 35, 0.45);
}
.new-app-dialog form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px 20px 16px;
  font-size: 13px;
}
.dlg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: -4px 0 4px;
}
.dlg-header h2 { margin: 0; font-size: 16px; font-weight: 600; }
.dlg-close {
  font-size: 22px;
  line-height: 1;
  background: transparent;
  border: none;
  cursor: pointer;
  color: #888;
}
.dlg-close:hover { color: #222; }
.dlg-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px 16px;
}
.dlg-field { display: flex; flex-direction: column; gap: 4px; }
.dlg-field > span {
  font-size: 12px;
  color: #555;
  font-weight: 500;
}
.dlg-field > span em { color: #999; font-style: normal; font-weight: 400; }
.dlg-field input,
.dlg-field select,
.dlg-field textarea {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid #ccc;
  border-radius: 4px;
  background: #fff;
}
.dlg-field textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12.5px;
  resize: vertical;
  line-height: 1.5;
}
.dlg-field input:focus, .dlg-field select:focus, .dlg-field textarea:focus {
  outline: 2px solid #1a73e8;
  outline-offset: -1px;
  border-color: #1a73e8;
}
.dlg-full { grid-column: 1 / -1; }
.dlg-checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  grid-column: 1 / -1;
}
.dlg-checkbox > span { font-size: 12px; color: #333; font-weight: 400; }
.dlg-checkbox code {
  font-size: 11px;
  background: #f0f0f0;
  padding: 1px 4px;
  border-radius: 2px;
}
.dlg-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 6px;
  border-top: 1px solid #eee;
}
.dlg-hint {
  flex: 1;
  font-size: 11px;
  color: #777;
}
.dlg-hint code {
  font-size: 11px;
  background: #f0f0f0;
  padding: 1px 4px;
  border-radius: 2px;
}

/* ------- Markdown preview dialog ------- */

dialog.md-dialog {
  border: none;
  border-radius: 10px;
  padding: 0;
  width: min(820px, 94vw);
  max-height: 92vh;
  box-shadow: 0 14px 50px rgba(0, 0, 0, 0.22);
}
dialog.md-dialog::backdrop {
  background: rgba(20, 25, 35, 0.45);
}
/* Default <dialog> is display:none when closed and display:block when opened —
 * we only override the open state to flex so the header+body lay out vertically.
 * Setting display on the base selector breaks the browser's modal positioning
 * and leaves the dialog visible inline when closed. */
dialog.md-dialog[open] {
  display: flex;
  flex-direction: column;
}
.md-dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid #eaeaea;
  background: #fafafa;
  border-radius: 10px 10px 0 0;
  flex: 0 0 auto;
}
.md-dialog-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.md-dialog-title strong {
  font-size: 13px;
  color: #111;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.md-dialog-title span {
  font-size: 11px;
  color: #888;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.md-dialog-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.md-dialog-actions a.btn-secondary,
.md-dialog-actions button.btn-secondary {
  font-size: 12px;
  padding: 4px 10px;
  text-decoration: none;
  color: #333;
}

.md-body {
  overflow-y: auto;
  padding: 22px 32px 36px;
  font-family: "Source Serif 4", "Source Serif Pro", Georgia, serif;
  font-size: 15px;
  line-height: 1.62;
  color: #1a1a1a;
  flex: 1 1 auto;
}
.md-body :first-child { margin-top: 0; }
.md-body :last-child  { margin-bottom: 0; }
.md-body h1, .md-body h2, .md-body h3, .md-body h4 {
  font-weight: 600;
  line-height: 1.25;
  margin: 1.4em 0 0.4em;
  letter-spacing: -0.01em;
}
.md-body h1 { font-size: 22px; margin-top: 0; }
.md-body h2 { font-size: 18px; padding-top: 4px; border-top: 1px solid #eee; padding-top: 18px; margin-top: 28px; }
.md-body h2:first-child { border-top: none; padding-top: 0; margin-top: 0; }
.md-body h3 { font-size: 16px; color: #2a2a2a; }
.md-body h4 { font-size: 14px; color: #444; }
.md-body p {
  margin: 0.7em 0;
}
.md-body ul, .md-body ol {
  margin: 0.6em 0;
  padding-left: 24px;
}
.md-body li {
  margin: 0.35em 0;
}
.md-body li > ul, .md-body li > ol {
  margin: 0.25em 0 0.35em;
}
.md-body strong { font-weight: 600; color: #0a0a0a; }
.md-body em { font-style: italic; color: #2a2a2a; }
.md-body a {
  color: #1a73e8;
  text-decoration: none;
  border-bottom: 1px solid rgba(26, 115, 232, 0.3);
}
.md-body a:hover {
  border-bottom-color: #1a73e8;
}
.md-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.88em;
  background: #f3f3f4;
  padding: 1.5px 5px;
  border-radius: 3px;
  color: #444;
}
.md-body pre {
  background: #f7f7f8;
  border: 1px solid #ececed;
  border-radius: 6px;
  padding: 12px 14px;
  overflow-x: auto;
  font-size: 12.5px;
  line-height: 1.5;
  margin: 0.8em 0;
}
.md-body pre code {
  background: none;
  padding: 0;
  border-radius: 0;
  color: #1a1a1a;
  font-size: inherit;
}
.md-body hr {
  border: none;
  border-top: 1px solid #e2e2e2;
  margin: 1.6em 0;
}
.md-body blockquote {
  margin: 0.8em 0;
  padding: 0.2em 14px;
  border-left: 3px solid #1a73e8;
  color: #444;
  background: #f4f7ff;
  border-radius: 0 4px 4px 0;
}
.md-body blockquote p:first-child { margin-top: 0.3em; }
.md-body blockquote p:last-child  { margin-bottom: 0.3em; }

.md-frontmatter {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: #f7f8fa;
  border: 1px solid #ececef;
  border-radius: 6px;
  padding: 10px 14px;
  margin: 0 0 22px;
  font-size: 12px;
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 4px 14px;
}
.md-fm-row {
  display: contents;
}
.md-fm-k {
  color: #888;
  font-weight: 500;
}
.md-fm-v {
  color: #222;
  word-break: break-word;
  font-variant-numeric: tabular-nums;
}

.md-loading { color: #888; font-style: italic; }
.md-error { color: #c0392b; }
