:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --border: #2d3a4f;
  --text: #e7ecf3;
  --muted: #8b9cb3;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --error: #ef4444;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.layout {
  width: 100%;
  max-width: 100%;
  margin: 0 auto;
  padding: 1.5rem clamp(0.75rem, 2vw, 2rem) 4rem;
}

.site-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.site-header h1 {
  margin: 0 0 0.25rem;
  font-size: 1.6rem;
  font-weight: 600;
}

.nav-logout {
  margin-left: 0.5rem;
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}

.nav-logout:hover {
  color: var(--text);
  border-color: var(--accent);
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.nav {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.35rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.85rem;
}

.nav a:hover {
  color: var(--text);
  border-color: var(--accent);
}

.nav a.active {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--accent);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.filters-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 0.8fr auto;
  gap: 0.75rem;
  align-items: end;
}

@media (max-width: 900px) {
  .filters-row {
    grid-template-columns: 1fr 1fr;
  }
  .filters-row .actions {
    grid-column: 1 / -1;
  }
}

.field label {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 0.3rem;
}

input,
select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
}

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
}

.btn {
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 500;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  cursor: pointer;
}

.btn:hover {
  background: var(--accent-hover);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  border-color: var(--accent);
}

.actions {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}

.actions .btn {
  flex: 1;
}

.status-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.85rem;
}

.chip {
  font-size: 0.75rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  cursor: pointer;
}

.chip:hover,
.chip.active {
  border-color: var(--accent);
  color: var(--text);
}

.chip strong {
  color: var(--text);
  margin-left: 0.2rem;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

@media (min-width: 900px) {
  .table-wrap {
    overflow-x: visible;
  }
}

.table-meta {
  margin-bottom: 0.75rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.loading,
.empty {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}

.hidden {
  display: none !important;
}

.jobs-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.85rem;
}

/* Column widths: one source of truth (thead/tbody stay aligned) */
.jobs-table col.c-add { width: 4.25rem; }
.jobs-table col.c-title { width: 30%; }
.jobs-table col.c-company { width: 9%; }
.jobs-table col.c-flag { width: 2.85rem; }
.jobs-table col.c-source { width: 5.25rem; }
.jobs-table col.c-stage { width: 7rem; }
.jobs-table col.c-date { width: 6.25rem; }
.jobs-table col.c-link { width: 2.85rem; }

.table-wrap.is-refreshing {
  opacity: 0.92;
  pointer-events: none;
}

.jobs-table thead th {
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--border);
  text-align: left;
  padding: 0.5rem 0.3rem;
  color: var(--muted);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  vertical-align: bottom;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.jobs-table th.col-center,
.jobs-table td.col-center {
  text-align: center;
}

.jobs-table th.col-add,
.jobs-table th.col-desc,
.jobs-table th.col-score,
.jobs-table th.col-match,
.jobs-table th.col-letter,
.jobs-table th.col-briefing,
.jobs-table th.col-link {
  font-size: 0.72rem;
  padding-left: 0.2rem;
  padding-right: 0.2rem;
}

.jobs-table td.col-add,
.jobs-table td.col-desc,
.jobs-table td.col-score,
.jobs-table td.col-match,
.jobs-table td.col-letter,
.jobs-table td.col-briefing,
.jobs-table td.col-link {
  padding-left: 0.2rem;
  padding-right: 0.2rem;
}

.jobs-table td.col-link {
  overflow: visible;
}

.jobs-table th.sortable {
  cursor: pointer;
  user-select: none;
}

.jobs-table th.sortable:hover {
  color: var(--text);
}

.jobs-table th.sortable::after {
  content: "";
  display: inline-block;
  width: 0.65rem;
  margin-left: 0.25rem;
  opacity: 0.35;
}

.jobs-table th.sortable.sort-asc::after {
  content: "↑";
  opacity: 1;
  color: var(--accent);
}

.jobs-table th.sortable.sort-desc::after {
  content: "↓";
  opacity: 1;
  color: var(--accent);
}

.jobs-table td {
  padding: 0.5rem 0.3rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  overflow: hidden;
  text-overflow: ellipsis;
}

.jobs-table tr:hover td {
  background: rgba(59, 130, 246, 0.06);
}

.job-title {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.job-title a {
  color: var(--text);
  text-decoration: none;
}

.job-title a:hover {
  color: var(--accent);
}

.badge {
  display: inline-block;
  font-size: 0.72rem;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  font-weight: 500;
  white-space: nowrap;
}

.badge-new { background: #1e3a5f; color: #93c5fd; }
.badge-scored { background: #312e81; color: #c4b5fd; }
.badge-archived { background: #374151; color: #9ca3af; }
.badge-not_interesting { background: #3f3f46; color: #a1a1aa; }
.badge-cover_letter { background: #422006; color: #fcd34d; }
.badge-applied { background: #14532d; color: #86efac; }
.badge-interview { background: #164e63; color: #67e8f9; }
.badge-no_response { background: #3f3f46; color: #d4d4d8; }
.badge-rejected { background: #450a0a; color: #fca5a5; }
.badge-offer { background: #052e16; color: #4ade80; }

.score-pill {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.score-high { color: var(--success); }
.score-mid { color: var(--warning); }
.score-low { color: var(--muted); }

.status-select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  font-size: 0.72rem;
  padding: 0.3rem 0.25rem;
  margin-top: 0.25rem;
}

tr.is-saving .status-select {
  opacity: 0.55;
  pointer-events: none;
}

tr.is-saving .badge::after {
  content: " …";
  opacity: 0.75;
}

body.has-pending-saves .table-wrap {
  box-shadow: inset 0 0 0 1px rgba(59, 130, 246, 0.35);
}

.stage-comment {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0;
  border: none;
  background: none;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.3;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage-comment:hover {
  color: var(--accent);
  text-decoration: underline;
}

.source-tag {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
}

.desc-cell {
  text-align: center;
}

.desc-cell .desc-hint {
  display: block;
  margin-top: 0.15rem;
}

.link-cell-actions {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.2rem;
}

.link-cell-actions a {
  color: var(--accent);
  text-decoration: none;
  font-size: 1rem;
  line-height: 1;
}

.link-cell-actions a:hover {
  color: var(--text);
}

.desc-flag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.12rem 0.45rem;
  border-radius: 6px;
  margin-bottom: 0.25rem;
}

.desc-flag-yes {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.desc-flag-no {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
}

.manual-flag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.12rem 0.45rem;
  border-radius: 6px;
  white-space: nowrap;
}

.manual-flag-yes {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
}

.manual-flag-no {
  background: rgba(148, 163, 184, 0.12);
  color: var(--muted);
}

.desc-hint {
  display: block;
  font-size: 0.7rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}

.btn-fetch-page {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 1.45rem;
  height: 1.45rem;
  padding: 0;
  font-size: 1rem;
  line-height: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--accent);
  cursor: pointer;
  font-family: inherit;
}

.btn-fetch-page:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn-fetch-page:disabled {
  opacity: 0.5;
  cursor: wait;
}

.match-cell {
  text-align: center;
}

.cell-flag {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.12rem 0.45rem;
  border-radius: 6px;
  border: none;
  font-family: inherit;
  line-height: 1.2;
}

.cell-flag-yes {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.cell-flag-no {
  background: rgba(239, 68, 68, 0.12);
  color: #f87171;
}

.cell-flag-risk {
  background: rgba(239, 68, 68, 0.15);
  color: #f87171;
}

button.cell-trigger.cell-flag-risk:hover {
  filter: brightness(1.15);
  outline: 1px solid rgba(239, 68, 68, 0.4);
}

.context-menu {
  position: fixed;
  z-index: 300;
  min-width: 10rem;
  padding: 0.35rem 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
}

.context-menu-item {
  display: block;
  width: 100%;
  padding: 0.45rem 0.85rem;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
}

.context-menu-item:hover {
  background: rgba(59, 130, 246, 0.12);
  color: var(--accent);
}

button.cell-trigger {
  cursor: pointer;
}

button.cell-trigger:hover {
  filter: brightness(1.15);
  outline: 1px solid rgba(34, 197, 94, 0.35);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  background: rgba(0, 0, 0, 0.4);
}

.modal-dialog {
  position: relative;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.5);
  color: #c5ced9;
}

.modal-lg {
  max-width: min(900px, 70vw);
  min-width: min(900px, 70vw);
  min-height: 70vh;
}

.modal-md {
  max-width: min(560px, 92vw);
  max-height: 75vh;
}

.modal-close {
  position: absolute;
  top: 0.65rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  color: var(--text);
  background: var(--border);
}

.modal-title {
  margin: 0;
  padding: 1rem 3rem 0.5rem 1.25rem;
  font-size: 1.05rem;
  font-weight: 600;
  color: #d4dbe6;
}

.modal-body {
  padding: 0 1.25rem 1.25rem;
  overflow: auto;
  flex: 1;
}

.modal-text {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.9rem;
  line-height: 1.55;
  color: #b8c4d4;
}

.modal-list {
  margin: 0;
  padding-left: 1.25rem;
  font-size: 0.88rem;
  line-height: 1.5;
  color: #b8c4d4;
}

.modal-list li {
  margin-bottom: 0.5rem;
}

.modal-hint {
  margin: 0 0 0.75rem;
  font-size: 0.88rem;
  color: var(--muted);
}

.modal-prompt-preview {
  max-height: 40vh;
  overflow: auto;
  margin: 0 0 1rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 0.78rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: #9aa8bc;
}

.modal-edit-form textarea {
  width: 100%;
  min-height: 50vh;
  box-sizing: border-box;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: #c5ced9;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.55;
  resize: vertical;
}

.modal-edit-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.75rem;
}

body.modal-open {
  overflow: hidden;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1rem;
}

#toast {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  padding: 0.75rem 1rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-size: 0.85rem;
  z-index: 100;
}

#toast.error {
  border-color: var(--error);
}
