:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #203037;
  background: #f5f7f8;
  font-synthesis: none;
  --accent: #146a62;
  --accent-hover: #10584f;
  --muted: #607078;
  --border: #dce3e6;
  --soft: #edf2f3;
  --danger: #9a403b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; line-height: 1.5; }
a { color: var(--accent); text-underline-offset: 3px; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
button:disabled, fieldset:disabled { cursor: wait; opacity: .62; }
:focus-visible { outline: 3px solid #23897c; outline-offset: 2px; }

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.nav-wrap {
  max-width: 1240px;
  min-height: 58px;
  margin: 0 auto;
  padding: 11px 28px;
  display: flex;
  align-items: center;
  gap: 28px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  flex: 0 0 auto;
  color: #203037;
  text-decoration: none;
  font-size: 18px;
  font-weight: 750;
}

.brand img { display: block; border-radius: 8px; }
nav { display: flex; align-items: center; gap: 20px; }
nav a { color: var(--muted); text-decoration: none; font-size: 13px; white-space: nowrap; }
nav a[aria-current] { color: var(--accent); font-weight: 700; }

.header-account {
  margin-left: auto;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
}

#current-user { color: #33484f; font-weight: 650; white-space: nowrap; }
#auth-status { white-space: nowrap; }

main {
  max-width: 1240px;
  margin: 0 auto;
  padding: 34px 28px 24px;
}

.intro { margin-bottom: 22px; }
.product-label { color: var(--accent); font-size: 12px; font-weight: 700; margin: 0 0 5px; }
h1 { font-size: clamp(27px, 3vw, 36px); line-height: 1.2; letter-spacing: -.035em; margin: 0 0 10px; }
h2 { font-size: 22px; line-height: 1.25; letter-spacing: -.02em; margin: 0; }
h3 { margin: 0; }
p { margin: 7px 0; }
.subtle, .field-help { color: var(--muted); font-size: 12px; }

.search-panel {
  background: #fff;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 3px 12px #152f3505;
}

fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px 18px; }
label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; font-weight: 650; }
input, select {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  padding: 8px 11px;
  color: #203037;
  background: #fff;
  border: 1px solid #cbd5da;
  border-radius: 7px;
  font-weight: 400;
}
input::placeholder { color: #7a878e; }
.field-help { font-size: 10px; font-weight: 400; line-height: 1.35; }

.form-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid #edf0f2;
}

.button {
  min-height: 38px;
  padding: 8px 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-size: 13px;
  font-weight: 650;
  line-height: 1.2;
  text-decoration: none;
  text-align: center;
  white-space: nowrap;
}
.primary { min-width: 112px; color: #fff; background: var(--accent); }
.primary:hover { background: var(--accent-hover); }
.secondary { color: var(--accent); background: #fff; border-color: var(--border); }
.secondary:hover { border-color: #aebfc3; background: #f9fbfb; }
.quiet { min-height: 34px; padding: 6px 9px; color: var(--muted); background: transparent; }
.quiet:hover { color: var(--accent); background: #f0f5f4; }
.danger { color: var(--danger); }
.danger:hover { color: #7d302c; background: #fff4f3; }

.results-toolbar {
  margin: 30px 0 14px;
  padding: 15px 16px;
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 11px;
}
.results-toolbar h2 { margin-right: auto; align-self: center; }
.results-toolbar label { flex-direction: row; align-items: center; gap: 7px; color: var(--muted); font-weight: 500; }
.results-toolbar select { min-height: 36px; width: 155px; padding: 6px 28px 6px 9px; font-size: 12px; }
.results-toolbar .sort-label select { width: 145px; }
.selection-count { padding: 0 5px; color: #40555e; font-size: 13px; white-space: nowrap; align-self: center; }

.metadata {
  margin: 0 0 12px;
  padding: 11px 14px;
  display: flex;
  align-items: center;
  gap: 8px 12px;
  flex-wrap: wrap;
  background: var(--soft);
  border-radius: 8px;
  font-size: 13px;
}
.metadata-title { color: #29444c; font-weight: 700; }
.metadata-count { color: var(--muted); }
.metadata-details { margin-left: auto; color: var(--muted); font-size: 12px; }
.metadata-details summary { cursor: pointer; }
.metadata-details dl { margin: 8px 0 0; display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; }
.metadata-details dt { color: #73838a; }
.metadata-details dd { margin: 0; overflow-wrap: anywhere; }
.metadata-details ul { margin: 8px 0 0; padding-left: 18px; }
.badge { padding: 3px 8px; border-radius: 999px; background: #f8f1df; color: #715c27; font-size: 11px; font-weight: 650; }

.notice { border-radius: 8px; padding: 12px 15px; margin: 14px 0; font-size: 13px; overflow-wrap: anywhere; }
.error { color: #84312e; background: #fff1f0; border: 1px solid #ebc9c6; }
.warning { color: #69541e; background: #fcf7e9; border: 1px solid #eadfbf; }
.partial-warning {
  min-height: 54px;
  margin: 0 0 12px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #69541e;
  background: #fcf7e9;
  border: 1px solid #eadfbf;
  border-radius: 8px;
  font-size: 13px;
}
.partial-warning div { display: flex; gap: 8px; flex-wrap: wrap; }
.partial-warning strong { font-weight: 700; }
.partial-warning span:last-child { color: #796a41; }

.loading { padding: 14px 0; display: flex; align-items: center; gap: 10px; color: var(--accent); font-size: 13px; }
.spinner { width: 17px; height: 17px; border-radius: 50%; border: 2px solid #cadfdb; border-top-color: var(--accent); animation: spin 1s linear infinite; flex-shrink: 0; }
@keyframes spin { to { transform: rotate(360deg); } }

.cards { display: grid; gap: 12px; }
.card { min-width: 0; padding: 17px 18px; background: #fff; border: 1px solid var(--border); border-radius: 11px; }
.selected-card { border-color: #9fc9c1; box-shadow: inset 3px 0 0 var(--accent); }
.card-head { display: grid; grid-template-columns: 22px 58px minmax(0, 1fr) auto; gap: 12px; align-items: start; }
.selection-label { display: flex; align-items: center; justify-content: center; padding-top: 8px; }
.selection-label input { width: 18px; height: 18px; min-height: 0; margin: 0; accent-color: var(--accent); }
.score { min-width: 58px; padding: 6px; text-align: center; background: #f1f3f4; border: 1px solid #dce2e5; border-radius: 8px; }
.score strong { display: block; font-size: 21px; line-height: 1.25; }
.score small { color: var(--muted); font-size: 9px; }
.score.high { background: #eaf4f1; border-color: #cfe3dd; }
.score.medium { background: #f5f3e9; border-color: #e5dfc7; }
.score.weak { color: #59686e; background: #f2f4f5; }
.card-heading { min-width: 0; }
.card-title { font-size: 18px; line-height: 1.3; overflow-wrap: anywhere; }
.card-company { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.status-badge { align-self: start; padding: 4px 8px; color: #496067; background: #edf1ee; border-radius: 999px; font-size: 10px; font-weight: 700; white-space: nowrap; }

.job-facts { display: flex; flex-wrap: wrap; gap: 5px 18px; margin: 12px 0; padding-left: 92px; color: #52656d; font-size: 12px; }
.card-actions { margin: 11px 0 0; padding: 10px 0 0 92px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; border-top: 1px solid #edf0f2; }
.card-actions .primary { order: -2; }
.card-actions .open-hh { order: -1; }

.match-details { margin: 10px 0 0 92px; border-top: 1px solid #edf0f2; }
.match-details summary { padding: 9px 0 2px; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; cursor: pointer; color: var(--accent); font-size: 12px; font-weight: 650; list-style-position: inside; }
.match-summary { display: inline-flex; gap: 10px; flex-wrap: wrap; color: var(--muted); font-weight: 400; }
.match-summary .penalty-count { color: #8c5b55; }
.explanations { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; padding: 10px 0 4px; }
.explanations h4 { margin: 0 0 5px; color: #52656d; font-size: 11px; }
.explanations ul { margin: 0; padding-left: 16px; font-size: 11px; overflow-wrap: anywhere; }
.explanations p { margin: 0; color: var(--muted); font-size: 11px; }

.letter-editor { margin: 10px 0 0 92px; font-size: 12px; }
.letter-editor > summary { cursor: pointer; color: var(--accent); font-weight: 650; }
.letter-editor section { margin-top: 10px; }
.letter-editor h4 { margin: 0 0 7px; }
.letter-editor textarea { display: block; width: 100%; min-height: 190px; padding: 11px; border: 1px solid #cbd5da; border-radius: 7px; resize: vertical; }
.letter-editor .card-actions { padding-left: 0; }

.results-footer { min-height: 48px; margin-top: 12px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.result-count { color: var(--muted); font-size: 13px; }
.pagination { display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 12px; }
#page-indicator { min-width: 46px; text-align: center; }

.empty-state { padding: 44px 20px; text-align: center; color: var(--muted); border: 1px dashed #cfdade; border-radius: 11px; }
.empty-state h3 { color: #40555e; font-size: 17px; }
.empty-state p { max-width: 460px; margin: 7px auto 0; font-size: 13px; }
.empty-symbol { display: block; margin-bottom: 6px; color: #849a9f; font-size: 25px; }
footer { margin-top: 30px; padding-top: 15px; display: flex; justify-content: space-between; gap: 15px; color: var(--muted); border-top: 1px solid var(--border); font-size: 12px; }

.login-panel { max-width: 460px; margin: 10vh auto; padding: 24px; }
.login-panel form { display: grid; gap: 18px; }
.visually-hidden, .skip-link { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
.skip-link:focus { width: auto; height: auto; clip-path: none; padding: 12px; background: #fff; z-index: 2; }

@media (max-width: 980px) {
  .nav-wrap { gap: 18px; }
  .header-account { gap: 8px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .results-toolbar h2 { flex-basis: calc(100% - 190px); }
  .explanations { grid-template-columns: 1fr; gap: 11px; }
}

@media (max-width: 720px) {
  .nav-wrap { flex-wrap: wrap; padding: 10px 20px; }
  .header-account { width: 100%; margin-left: 0; justify-content: flex-start; border-top: 1px solid #edf0f2; padding-top: 8px; }
  main { padding: 28px 20px 20px; }
  .results-toolbar { align-items: center; }
  .results-toolbar h2 { flex-basis: 100%; }
  .card-head { grid-template-columns: 22px 54px minmax(0, 1fr); }
  .status-badge { grid-column: 3; }
  .job-facts, .card-actions, .match-details, .letter-editor { padding-left: 0; margin-left: 0; }
}

@media (max-width: 540px) {
  .nav-wrap { padding: 10px 16px; gap: 12px; }
  .brand { font-size: 16px; }
  .brand img { width: 30px; height: 30px; }
  nav { order: 3; width: 100%; gap: 16px; }
  .header-account { order: 4; flex-wrap: wrap; }
  main { padding: 24px 16px 18px; }
  .intro { margin-bottom: 18px; }
  .intro > .subtle { display: none; }
  .search-panel { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; gap: 13px; }
  .form-footer { align-items: stretch; flex-direction: column; }
  .form-footer .primary { width: 100%; }
  .results-toolbar { margin-top: 24px; padding: 13px; }
  .results-toolbar label { flex: 1 1 145px; flex-direction: column; align-items: stretch; }
  .results-toolbar select, .results-toolbar .sort-label select { width: 100%; }
  .selection-count { width: 100%; padding: 3px 0; }
  .card { padding: 15px; }
  .card-head { grid-template-columns: 20px 50px minmax(0, 1fr); gap: 9px; }
  .score { min-width: 50px; }
  .score strong { font-size: 19px; }
  .card-title { font-size: 16px; }
  .job-facts { gap: 4px 12px; }
  .card-actions .button { flex: 1 1 auto; white-space: normal; }
  .match-details summary { align-items: flex-start; flex-direction: column; gap: 4px; }
  .results-footer { align-items: flex-start; flex-direction: column; }
  .pagination { width: 100%; justify-content: space-between; }
  footer { flex-direction: column; }
}

@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

.admin-toolbar, .admin-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-toolbar { margin: 20px 0; }
.users-table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
.users-table { width: 100%; min-width: 920px; border-collapse: collapse; font-size: 13px; }
.users-table th, .users-table td { padding: 13px 14px; vertical-align: top; border-bottom: 1px solid var(--border); text-align: left; overflow-wrap: anywhere; }
.users-table th { color: var(--muted); font-size: 12px; font-weight: 700; background: #f9fbfb; }
.users-table tbody tr:last-child td { border-bottom: 0; }
.user-actions { display: flex; flex-wrap: wrap; gap: 6px; min-width: 230px; }
.user-actions .button { font-size: 12px; white-space: normal; }
.status-active { color: var(--accent); font-weight: 700; }
.status-disabled { color: var(--danger); font-weight: 700; }
.you-badge { display: inline-block; margin-left: 7px; padding: 1px 6px; color: var(--accent); border: 1px solid #9dcec7; border-radius: 99px; font-size: 11px; font-weight: 700; }
dialog { width: min(520px, calc(100% - 32px)); max-height: calc(100% - 40px); border: 1px solid var(--border); border-radius: 14px; padding: 24px; color: inherit; box-shadow: 0 20px 80px #20303733; }
dialog::backdrop { background: #20303777; }
dialog form { display: grid; gap: 14px; }
dialog h2, dialog p { margin: 0; }
dialog h2 { font-size: 22px; }
dialog input, dialog select { width: 100%; }
.profile-checkboxes { display: grid; gap: 12px; }
.profile-checkboxes label { display: flex; align-items: flex-start; gap: 10px; overflow-wrap: anywhere; }
.profile-checkboxes input { width: auto; margin-top: 5px; flex-shrink: 0; }
.password-control { display: flex; gap: 8px; margin-top: 5px; }
.password-control input { min-width: 0; }
.password-toggle { flex: 0 0 auto; }
.active-control { display: flex; gap: 9px; align-items: center; }
.active-control input { width: auto; }
