:root {
  --paper: #f8f3ec;
  --paper-card: #fdfbf7;
  --paper-sunk: #f1ebe0;
  --ink: #1c1b19;
  --ink-2: #3a352d;
  --ink-muted: #8b8277;
  --ink-faint: #b9af9d;
  --border-hairline: #e4ddd1;
  --border-strong: #d3c9b8;
  --accent: #c0362c;
  --accent-hover: #a52d24;
  --accent-tint: #f3e1dd;
  --green: #3a5f4a;
  --green-tint: #e3ebe4;

  --serif: "Newsreader", Georgia, serif;
  --sans: "IBM Plex Sans", -apple-system, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

/* Classes like .tag set display, which would otherwise beat the hidden attribute. */
[hidden] { display: none !important; }

body {
  --gutter: 32px;
  --content: 1440px;
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 14px/1.45 var(--sans);
}

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 24px;
  /* Full-bleed rule, content capped and centred on very wide screens. */
  padding: 28px max(var(--gutter), calc((100% - var(--content)) / 2)) 16px;
  border-bottom: 2px solid var(--ink);
}

.kicker, .query, .status, .tab, th, .tag, .empty, .btn {
  font-family: var(--mono);
}

.kicker {
  margin: 0 0 4px;
  font-size: 11px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

h1 {
  margin: 0;
  font: 500 40px/1 var(--serif);
  letter-spacing: -0.01em;
}

.query {
  margin: 8px 0 0;
  font-size: 12px;
  color: var(--ink-2);
}

.control {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
}

.status {
  margin: 0;
  font-size: 12px;
  color: var(--ink-muted);
  text-align: right;
}

.status .error { color: var(--accent); }

.live { color: var(--ink-faint); }
.live::before {
  content: "";
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: var(--ink-faint);
  vertical-align: 1px;
}
.live.is-on { color: var(--green); }
.live.is-on::before { background: var(--green); }

.filter-actions { margin-top: 8px; }

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-2);
  font: 12px var(--mono);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.link-btn:hover { color: var(--accent); }
.notify-toggle { margin-left: 14px; }

.notify-prompt {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px 16px;
  margin: 16px 0 0;
  padding: 12px 16px;
  border: 1px solid var(--border-hairline);
  border-top: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--paper-card);
}
.notify-prompt p { margin: 0; font-size: 14px; }
.notify-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.tag-custom { color: var(--ink-2); background: var(--paper-sunk); }

.filter-form {
  display: grid;
  gap: 6px;
  margin: 16px 0 0;
  padding: 16px;
  border: 1px solid var(--border-hairline);
  border-top: 2px solid var(--ink);
  border-radius: 4px;
  background: var(--paper-card);
}
.filter-form label {
  font: 500 11px var(--mono);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.filter-form textarea, .filter-form input[type="text"] {
  padding: 8px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--paper);
  color: var(--ink);
  font: 13px/1.5 var(--mono);
  resize: vertical;
}
.filter-form textarea:focus, .filter-form input[type="text"]:focus {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}
.filter-form .hint { margin: 0 0 6px; font: 11px var(--mono); color: var(--ink-muted); }
.form-actions { display: flex; gap: 8px; margin-top: 4px; }
.btn-quiet { margin-left: auto; border-color: transparent; background: none; }

main { padding: 0 max(var(--gutter), calc((100% - var(--content)) / 2)) 48px; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 16px 0 12px;
}

.tabs { display: flex; gap: 4px; min-width: 0; }

.tab {
  flex: none;
  white-space: nowrap;
  padding: 6px 10px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  color: var(--ink-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  cursor: pointer;
}

.tab span { color: var(--ink-faint); margin-left: 4px; }
.tab:hover { color: var(--ink); }
.tab[aria-pressed="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tab[aria-pressed="true"] span { color: var(--ink-2); }

input[type="search"] {
  width: 280px;
  padding: 6px 10px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--paper-card);
  color: var(--ink);
  font: 13px var(--sans);
}

input[type="search"]:focus, .btn:focus-visible, .tab:focus-visible, a:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}

.btn {
  white-space: nowrap;
  padding: 6px 12px;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--paper-card);
  color: var(--ink-2);
  font-size: 12px;
  cursor: pointer;
}

.btn:hover { border-color: var(--ink-muted); color: var(--ink); }
.btn:disabled { opacity: 0.55; cursor: progress; }

.btn-primary {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper-card);
  padding: 8px 16px;
}

.btn-primary:hover { background: var(--ink-2); color: var(--paper-card); }

.banner {
  margin: 0 0 12px;
  padding: 8px 12px;
  border-top: 2px solid var(--green);
  background: var(--green-tint);
  font: 12px var(--mono);
}

.banner.is-error { border-top-color: var(--accent); background: var(--accent-tint); }

.jobs {
  width: 100%;
  border-collapse: collapse;
  background: var(--paper-card);
  border: 1px solid var(--border-hairline);
  border-radius: 4px;
}

th {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-strong);
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  text-align: left;
  color: var(--ink-muted);
}

td {
  padding: 7px 12px;
  border-bottom: 1px solid var(--border-hairline);
  vertical-align: baseline;
}

tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--paper-sunk); }

.col-age, .age { width: 64px; white-space: nowrap; }
.age { font-family: var(--mono); font-size: 12px; color: var(--ink-muted); }
.col-actions, .actions { width: 1%; white-space: nowrap; text-align: right; }
.actions .btn + .btn { margin-left: 4px; }

.role a { color: var(--ink); font-weight: 500; text-decoration: none; }
.role a:hover { color: var(--accent); text-decoration: underline; }

.company { color: var(--ink-2); }
.location { color: var(--ink-muted); white-space: nowrap; }

.tag {
  display: inline-block;
  margin-left: 6px;
  padding: 0 4px;
  border-radius: 2px;
  font-size: 10px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  vertical-align: 1px;
}

.tag-new { color: var(--accent); background: var(--accent-tint); }
.tag-applied { color: var(--green); background: var(--green-tint); }
.tag-hidden { color: var(--ink-muted); background: var(--paper-sunk); }

tr.is-hidden .role a, tr.is-hidden .company { color: var(--ink-muted); }
tr.verdict-reject .role a, tr.verdict-reject .company { color: var(--ink-muted); }

.why {
  margin-top: 2px;
  font: 11px/1.4 var(--mono);
  color: var(--ink-muted);
}

.tag-entry { color: var(--green); background: var(--green-tint); }
.tag-maybe { color: #7a6030; background: #efe6d2; }
.tag-reject { color: var(--ink-muted); background: var(--paper-sunk); }
.tag-pending { color: var(--ink-2); background: var(--paper-sunk); }

.btn-jd.is-open { background: var(--ink); border-color: var(--ink); color: var(--paper-card); }
.actions .btn + .btn, .actions .btn-jd { margin-left: 4px; }

tr.jd-row td { padding: 0 12px 16px; background: var(--paper-card); }
tr.jd-row:hover { background: none; }
.jd {
  padding: 12px 16px;
  border-left: 2px solid var(--ink);
  background: var(--paper);
}
.jd-label {
  margin: 10px 0 2px;
  font: 500 10px var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-muted);
}
.jd-label:first-child { margin-top: 0; }
.jd-why { margin: 0; font-weight: 500; }
.jd ul { margin: 0; padding-left: 18px; font-size: 13px; }
.jd-text {
  max-height: 420px;
  overflow: auto;
  padding-right: 8px;
  font-size: 13px;
  line-height: 1.55;
  white-space: pre-line;
  color: var(--ink-2);
}
.jd-loading { margin: 0; font: 12px var(--mono); color: var(--ink-muted); }

/* Rows that just landed via the live stream fade from the accent tint to paper. */
tr.just-arrived { animation: arrive 6s ease-out; }

@keyframes arrive {
  from { background: var(--accent-tint); }
  to { background: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  tr.just-arrived { animation: none; background: var(--accent-tint); }
}

.empty {
  margin: 0;
  padding: 32px 12px;
  border: 1px solid var(--border-hairline);
  border-top: 0;
  background: var(--paper-card);
  font-size: 12px;
  color: var(--ink-muted);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------------------------------------------------------------- responsive */

/* Tablet: same table, tighter gutters, let company/location wrap. */
@media (max-width: 1100px) {
  body { --gutter: 20px; }
  .location { white-space: normal; }
  td, th { padding-left: 10px; padding-right: 10px; }
  input[type="search"] { width: 220px; }
}

/* Phone: header and toolbar stack, jobs become cards. */
@media (max-width: 760px) {
  body { --gutter: 14px; }

  .masthead { flex-direction: column; align-items: stretch; gap: 12px; padding-top: 20px; }
  h1 { font-size: 32px; }
  .control { justify-content: space-between; gap: 12px; flex-shrink: 1; }
  .status { text-align: left; min-width: 0; }

  .toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
  .tabs {
    gap: 0;
    margin: 0 calc(var(--gutter) * -1);
    padding: 0 var(--gutter);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .tab { padding-left: 7px; padding-right: 7px; letter-spacing: 0.02em; }
  .tab span { margin-left: 3px; }
  .tabs::-webkit-scrollbar { display: none; }
  /* 16px stops iOS Safari from zooming into focused fields. */
  input[type="search"], .filter-form textarea, .filter-form input[type="text"] {
    width: 100%;
    font-size: 16px;
  }
  .form-actions { flex-wrap: wrap; }
  .btn-quiet { margin-left: 0; }

  .jobs, .jobs tbody { display: block; border: 0; background: none; }
  .jobs thead { display: none; }  /* cards label their own fields */
  .jobs tbody tr:not(.jd-row) {
    display: grid;
    grid-template-columns: auto auto 1fr;
    grid-template-areas:
      "role role role"
      "company company company"
      "location location location"
      "posted found actions";
    align-items: center;
    gap: 2px 14px;
    margin-bottom: 8px;
    padding: 12px;
    border: 1px solid var(--border-hairline);
    border-radius: 4px;
    background: var(--paper-card);
  }
  .jobs td { display: block; padding: 0; border: 0; }
  .role { grid-area: role; margin-bottom: 2px; font-size: 15px; }
  .company { grid-area: company; }
  .location { grid-area: location; font-size: 13px; }
  .age-posted { grid-area: posted; }
  .age-found { grid-area: found; }
  .age { width: auto; margin-top: 8px; }
  .age::before { content: attr(data-label) " "; color: var(--ink-faint); }
  .jobs td.actions {  /* beats `.jobs td { display: block }` */
    grid-area: actions;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px;
    width: auto;
    margin-top: 8px;
  }
  .actions .btn, .actions .btn + .btn, .actions .btn-jd { margin-left: 0; }
  .why { overflow-wrap: anywhere; }

  tr.jd-row { display: block; margin: -9px 0 8px; }
  tr.jd-row td {
    display: block;
    padding: 0 12px 12px;
    border: 1px solid var(--border-hairline);
    border-top: 0;
    border-radius: 0 0 4px 4px;
  }
  .jd { padding: 10px 12px; }
  .jd-text { max-height: 55vh; }

  .empty { border-top: 1px solid var(--border-hairline); border-radius: 4px; }
}

/* Small phones: buttons get their own row under the ages. */
@media (max-width: 420px) {
  h1 { font-size: 28px; }
  .jobs tbody tr:not(.jd-row) {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "role role"
      "company company"
      "location location"
      "posted found"
      "actions actions";
  }
  .jobs td.actions { justify-content: flex-start; }
}

/* Finger-sized targets wherever the pointer is coarse (phones, tablets). */
@media (pointer: coarse) {
  .btn { min-height: 38px; padding-left: 14px; padding-right: 14px; }
  .tab { min-height: 42px; }
  .link-btn { padding: 8px 0; }
  input[type="search"] { min-height: 42px; }
}
