:root {
  --bg: #f5f3ee;
  --surface: #ffffff;
  --surface-soft: #f9faf8;
  --ink: #202522;
  --muted: #66706b;
  --line: #dfe4de;
  --teal: #147d73;
  --teal-dark: #0d5d56;
  --danger: #a94336;
  --shadow: 0 18px 45px rgba(32, 37, 34, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.hidden {
  display: none !important;
}

.shell {
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 24px 18px;
  background: #18211e;
  color: #f5f3ee;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 760;
  margin-bottom: 34px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--teal);
  color: white;
  font-size: 13px;
}

.rail nav {
  display: grid;
  gap: 6px;
}

.rail a {
  color: #cdd7d1;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 14px;
}

.rail a.active,
.rail a:hover {
  color: white;
  background: rgba(255, 255, 255, 0.1);
}

main {
  padding: 28px;
  display: grid;
  gap: 20px;
}

.page {
  display: grid;
  gap: 20px;
}

.topbar,
.panel-heading,
.actions,
.form-grid,
.status-grid,
.toolbar,
.settings-grid {
  display: grid;
  gap: 16px;
}

.topbar {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 44px);
  line-height: 1;
}

h2 {
  font-size: 18px;
  line-height: 1.2;
}

h3 {
  font-size: 16px;
  line-height: 1.25;
}

.eyebrow {
  color: var(--teal);
  font-size: 12px;
  text-transform: uppercase;
  font-weight: 760;
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}

.actions {
  grid-auto-flow: column;
  justify-content: end;
}

.section-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.primary,
.secondary,
.danger {
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  font-weight: 720;
}

.primary {
  background: var(--teal);
  color: white;
}

.primary:hover {
  background: var(--teal-dark);
}

.secondary {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
}

.danger {
  width: fit-content;
  color: white;
  background: var(--danger);
}

.danger-panel {
  border-color: rgba(169, 67, 54, 0.3);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  font-size: 22px;
  line-height: 1;
}

.muted-text {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.status-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.status-grid article,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.status-grid article {
  padding: 16px;
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 6px;
}

.status-grid strong {
  font-size: 17px;
}

.panel {
  padding: 20px;
}

.panel-heading {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  margin-bottom: 18px;
}

.form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.toolbar {
  grid-template-columns: 170px minmax(220px, 1fr) 180px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 690;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  padding: 11px 12px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.45;
}

input:focus,
textarea:focus,
select:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(20, 125, 115, 0.14);
}

.switch {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 14px;
  font-weight: 720;
}

.switch input,
.source-row input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.switch.inline {
  min-height: auto;
  align-self: center;
}

.toggle-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toggle-row .switch {
  min-height: 38px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.settings-grid {
  grid-template-columns: 260px minmax(0, 1fr);
  align-items: start;
}

.profile-list {
  display: grid;
  gap: 8px;
}

.profile-tab {
  display: grid;
  gap: 4px;
  text-align: left;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--ink);
}

.profile-tab.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(20, 125, 115, 0.12);
}

.profile-tab span {
  color: var(--muted);
  font-size: 12px;
}

.match-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: -2px 0 16px;
}

.match-tab {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--ink);
  font-weight: 720;
}

.match-tab strong {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  color: var(--muted);
  background: white;
  font-size: 12px;
}

.match-tab.active {
  color: var(--teal-dark);
  border-color: var(--teal);
  background: rgba(20, 125, 115, 0.08);
  box-shadow: 0 0 0 3px rgba(20, 125, 115, 0.12);
}

.match-tab.active strong {
  color: white;
  background: var(--teal);
}

.profile-editor,
.profile-panel {
  display: grid;
  gap: 16px;
}

.section-heading {
  margin-bottom: 12px;
}

.keyword-editor {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfa;
}

.keyword-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.keyword-grid label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.keyword-card {
  display: grid;
  gap: 8px;
  align-content: start;
}

.keyword-card > label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 690;
}

.keyword-card > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.keyword-card.compact {
  gap: 7px;
}

.token-table {
  display: grid;
  gap: 6px;
}

.token-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 86px;
  gap: 6px;
}

.token-row input {
  min-height: 38px;
  padding: 8px 10px;
}

.token-row button {
  min-height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--danger);
  background: #f8eeee;
  font-weight: 760;
}

.token-add {
  width: fit-content;
  min-height: 34px;
  padding: 0 12px;
}

.areas {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: stretch;
}

.area-card {
  display: grid;
  grid-template-rows: auto auto auto;
  align-content: start;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 28px;
  border-radius: 999px;
  color: var(--teal-dark);
  background: rgba(20, 125, 115, 0.12);
  font-weight: 800;
}

.job-list {
  display: grid;
  gap: 10px;
}

.job-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 220px;
  gap: 18px;
  padding: 15px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.job-row.discarded {
  opacity: 0.52;
}

.job-row h3 {
  margin: 8px 0;
  font-size: 17px;
  line-height: 1.25;
}

.job-row a {
  color: var(--teal-dark);
  text-decoration: none;
}

.job-row a:hover {
  text-decoration: underline;
}

.job-row p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin-bottom: 10px;
}

.job-row aside {
  display: grid;
  gap: 6px;
  align-content: start;
  color: var(--muted);
  font-size: 13px;
}

.job-row aside strong {
  color: var(--ink);
}

.review-control {
  display: grid;
  gap: 6px;
  margin-top: 6px;
}

.review-control > span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.review-buttons {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.review-buttons button {
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
  text-align: left;
}

.review-buttons button:hover {
  border-color: rgba(20, 125, 115, 0.35);
  color: var(--teal-dark);
}

.review-buttons button.active {
  color: white;
  background: var(--teal);
  border-color: var(--teal);
}

.review-buttons button[data-status-value="discarded"].active {
  color: #9f2d24;
  background: #fff0ef;
  border-color: #f0c9c4;
}

.review-by {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.match-meta,
.reasons {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.tag {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 8px;
  background: white;
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
  font-weight: 690;
}

.tag.score {
  color: white;
  background: var(--teal);
  border-color: var(--teal);
}

.tag.warning {
  color: #9f2d24;
  background: #fdeaea;
  border-color: #efb0aa;
}

.tag.review {
  color: var(--teal-dark);
  background: rgba(20, 125, 115, 0.1);
  border-color: rgba(20, 125, 115, 0.25);
}

.sources-list {
  display: grid;
  gap: 10px;
}

.source-row {
  display: grid;
  grid-template-columns: 34px minmax(130px, 0.8fr) 110px minmax(240px, 1.5fr) 42px;
  gap: 10px;
  align-items: center;
}

.source-status {
  grid-column: 2 / -1;
  color: var(--muted);
  font-size: 12px;
}

.source-row button {
  height: 42px;
  border-radius: 8px;
  background: #f8eeee;
  color: var(--danger);
  font-weight: 800;
}

.source-row input[type="checkbox"] {
  justify-self: center;
}

.empty {
  color: var(--muted);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 360px;
  padding: 13px 15px;
  border-radius: 8px;
  background: #18211e;
  color: white;
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(24, 33, 30, 0.42);
}

.modal {
  width: min(520px, 100%);
  display: grid;
  gap: 16px;
  padding: 20px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 28px 80px rgba(24, 33, 30, 0.24);
}

.modal-heading {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
}

.modal-copy {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.modal-warning {
  display: grid;
  gap: 4px;
  padding: 12px;
  border-radius: 8px;
  color: #9f2d24;
  background: #fdeaea;
  border: 1px solid #efb0aa;
  font-size: 13px;
}

.modal-warning span {
  color: #74413d;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(460px, 100%);
  display: grid;
  gap: 18px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel .brand {
  color: var(--ink);
  margin-bottom: 12px;
}

.login-panel p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.5;
}

.login-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

@media (max-width: 1100px) {
  .toolbar,
  .settings-grid,
  .keyword-grid,
  .areas {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 860px) {
  .shell {
    grid-template-columns: 1fr;
  }

  .rail {
    position: static;
    height: auto;
  }

  .rail nav {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .status-grid,
  .job-row {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 680px) {
  main {
    padding: 18px;
  }

  .topbar,
  .panel-heading,
  .form-grid,
  .toolbar,
  .keyword-grid,
  .settings-grid,
  .status-grid,
  .areas,
  .source-row,
  .job-row {
    grid-template-columns: 1fr;
  }

  .actions {
    grid-auto-flow: row;
    justify-content: stretch;
  }
}
