:root {
  --bg: #1e1f22;
  --panel: #26282c;
  --panel-border: #34373c;
  --field: #17181b;
  --field-border: #41454c;
  --header: #2e3035;
  --row-alt: #2a2c31;
  --row-hover: #31343a;
  --row-selected: #24365e;
  --text: #e3e5e8;
  --text-label: #b4b8bf;
  --text-muted: #9aa0a8;
  --text-disabled: #6b7078;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: #6ea8fe;
  --orange: #f97316;
  --orange-hover: #ea580c;
  --warning: #f5a35c;
  --danger: #f87171;
  --good-bg: #1f3a2a; --good-fg: #9fe8be;
  --ok-bg: #3a3220; --ok-fg: #f5c26b;
  --low-bg: #2e3035; --low-fg: #9aa0a8;
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-light); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* --- Кнопки и поля --- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--header); border: 1px solid var(--field-border); border-radius: var(--radius);
  padding: 6px 12px; cursor: pointer; white-space: nowrap; color: var(--text);
  transition: background .15s, border-color .15s;
}
.btn:hover:not(:disabled) { background: #383b41; }
.btn:disabled { color: var(--text-disabled); cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn.primary:disabled, .btn.orange:disabled { background: var(--header); border-color: var(--field-border); color: var(--text-disabled); }
.btn.orange { background: var(--orange); border-color: var(--orange); color: #fff; font-weight: 600; }
.btn.orange:hover:not(:disabled) { background: var(--orange-hover); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--header); }
.btn.danger { color: var(--danger); }
.btn.active { border-color: var(--accent-light); color: var(--accent-light); }
.btn.on { background: #1d3157; border-color: var(--accent); color: #dbe7ff; }
.btn.small { padding: 3px 9px; font-size: 13px; }
.icon-btn { width: 34px; justify-content: center; padding: 6px 0; }

input[type=text], input[type=password], input[type=search], input[type=number], select, textarea {
  background: var(--field); border: 1px solid var(--field-border); border-radius: var(--radius);
  padding: 7px 10px; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent-light); }
textarea { resize: vertical; min-height: 60px; }
label.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--text-label); }
.field-label { color: var(--text-label); font-size: 13px; margin: 0 0 4px; display: block; }
.hint { color: var(--text-muted); font-size: 13px; }
.muted { color: var(--text-muted); }
kbd {
  background: var(--header); border: 1px solid var(--field-border); border-bottom-width: 2px;
  border-radius: 4px; padding: 0 5px; font: 12px var(--font);
}

/* --- Вход --- */
.auth {
  min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
}
.auth-box {
  width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 14px; padding: 28px 24px;
}
.auth-logo { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 700; margin-bottom: 18px; }
.auth-logo img { width: 40px; height: 40px; }
.tabs { display: flex; gap: 4px; background: var(--field); padding: 4px; border-radius: 10px; margin-bottom: 18px; }
.tabs button {
  flex: 1; border: 0; background: transparent; padding: 7px; border-radius: 7px; cursor: pointer; color: var(--text-muted);
}
.tabs button.current { background: var(--header); color: var(--text); }
.form-row { margin-bottom: 12px; }
.auth .btn.primary { width: 100%; justify-content: center; padding: 9px; margin-top: 6px; }
.form-error { color: var(--danger); min-height: 20px; font-size: 13px; margin-top: 8px; }

/* --- Верхняя строка --- */
.app { display: flex; flex-direction: column; height: 100%; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--panel-border); flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-right: 6px; }
.brand img { width: 26px; height: 26px; }
#vacancySelect { width: auto; min-width: 200px; max-width: 340px; }
.spacer { flex: 1; }
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; min-width: 230px;
  background: var(--header); border: 1px solid var(--field-border); border-radius: var(--radius);
  padding: 4px; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.menu.left { left: 0; right: auto; }
.menu button {
  display: block; width: 100%; text-align: left; background: transparent; border: 0; border-radius: 6px;
  padding: 7px 10px; cursor: pointer; color: var(--text);
}
.menu button:hover { background: #3a3d44; }
.menu hr { border: 0; border-top: 1px solid var(--field-border); margin: 4px 0; }
.menu .danger { color: var(--danger); }

/* --- Параметры вакансии --- */
.vacancy-bar { padding: 10px 16px 0; }
.summary { display: flex; align-items: center; gap: 10px; color: var(--text-muted); flex-wrap: wrap; }
.summary-text { overflow-wrap: anywhere; }
.params {
  margin-top: 10px; background: var(--panel); border: 1px solid var(--panel-border); border-radius: 12px;
  padding: 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px;
  animation: slide .2s ease-out;
}
@keyframes slide { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.params .wide { grid-column: 1 / -1; }
.params .row-inline { display: flex; gap: 14px; align-items: center; margin-top: 6px; flex-wrap: wrap; }
.params .actions { grid-column: 1 / -1; display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.source-toggles { display: flex; gap: 6px; flex-wrap: wrap; }

.message {
  margin: 10px 16px 0; padding: 8px 12px; border-left: 3px solid var(--orange); background: var(--panel);
  border-radius: 0 var(--radius) var(--radius) 0; display: flex; gap: 10px; align-items: flex-start;
}
.message.error { border-left-color: var(--danger); }
.message.flash { animation: flash 1.2s ease-out; }
@keyframes flash { from { background: #4a2e18; } to { background: var(--panel); } }
.message .close { margin-left: auto; }
.message-text { white-space: pre-line; }

/* --- Таблица и карточка --- */
.workspace { flex: 1; min-height: 0; display: flex; gap: 12px; padding: 10px 16px 0; }
.list-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 260px; }
.count { color: var(--text-muted); font-size: 13px; }
.table-wrap {
  flex: 1; min-height: 200px; overflow: auto; border: 1px solid var(--panel-border); border-radius: 10px;
  background: var(--panel);
}
table { width: 100%; border-collapse: collapse; }
thead th {
  position: sticky; top: 0; background: var(--header); text-align: left; font-weight: 600; font-size: 13px;
  color: var(--text-label); padding: 8px 10px; cursor: pointer; user-select: none; white-space: nowrap; z-index: 1;
}
thead th.sorted { color: var(--text); }
tbody td { padding: 7px 10px; border-top: 1px solid var(--panel-border); vertical-align: top; }
tbody tr { cursor: pointer; user-select: none; }
tbody tr:nth-child(even) { background: var(--row-alt); }
tbody tr:hover { background: var(--row-hover); }
tbody tr.selected { background: var(--row-selected); }
tbody tr.flash { animation: rowflash 1.6s ease-out; }
@keyframes rowflash { from { background: #3d4a24; } }
td.col-ai, th.col-ai { width: 52px; text-align: center; }
td.col-rel, th.col-rel { width: 96px; }
td.col-status, th.col-status { width: 130px; }
td.col-site, th.col-site { width: 90px; }
td.col-date, th.col-date { width: 92px; white-space: nowrap; }
.title-cell { overflow-wrap: anywhere; }
.st-new { color: var(--text); }
.st-viewed { color: var(--text-label); }
.st-interested { color: var(--accent-light); }
.st-ai_interested { color: #7ee2a8; }
.st-maybe { color: #f5c26b; }
.st-contacted { color: var(--warning); }
.st-rejected, .st-unfit { color: #949aa2; }
tr.struck .title-cell { text-decoration: line-through; }
.ai-pill {
  display: inline-block; min-width: 30px; padding: 1px 6px; border-radius: 10px; font-weight: 600; font-size: 13px;
}
.ai-good { background: var(--good-bg); color: var(--good-fg); }
.ai-ok { background: var(--ok-bg); color: var(--ok-fg); }
.ai-low { background: var(--low-bg); color: var(--low-fg); }
.ai-old { opacity: .55; }
.empty { padding: 40px 20px; text-align: center; color: var(--text-muted); }

.bottom-bar { display: flex; gap: 8px; align-items: center; padding: 10px 0 14px; flex-wrap: wrap; }

.card-pane {
  width: 380px; flex-shrink: 0; overflow: auto; background: var(--panel); border: 1px solid var(--panel-border);
  border-radius: 10px; padding: 14px; margin-bottom: 14px;
}
.card-title { font-size: 16px; font-weight: 600; margin: 0 0 4px; overflow-wrap: anywhere; }
.card-section { margin-top: 14px; }
.status-buttons { display: flex; flex-wrap: wrap; gap: 5px; }
.details { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; font-size: 13px; }
.details dt { color: var(--text-muted); }
.details dd { margin: 0; overflow-wrap: anywhere; }
.description { white-space: pre-line; color: #d2d5da; overflow-wrap: anywhere; }
.full-text {
  white-space: pre-line; font-size: 13px; color: #d2d5da; max-height: 320px; overflow: auto;
  background: var(--field); border-radius: var(--radius); padding: 10px; overflow-wrap: anywhere;
}
.ai-block { border-radius: 10px; padding: 10px 12px; animation: fade .4s ease-out; }
@keyframes fade { from { opacity: 0; } }
.ai-block .verdict { font-weight: 700; }
.ai-block .reason { white-space: pre-line; margin-top: 4px; }
.ai-block .meta { font-size: 12px; opacity: .75; margin-top: 4px; }
.ai-block.ai-good { background: var(--good-bg); color: var(--good-fg); }
.ai-block.ai-ok { background: var(--ok-bg); color: var(--ok-fg); }
.ai-block.ai-low { background: var(--low-bg); color: var(--text-label); }
.ai-block.ai-wait { background: var(--header); color: var(--text-label); }
.dots::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }

/* --- Фильтр --- */
.filter-panel { min-width: 260px; padding: 10px; }
.filter-panel .field-label { margin-top: 8px; }
.filter-panel .field-label:first-child { margin-top: 0; }
.filter-panel .reset { margin-top: 10px; width: 100%; justify-content: center; }

/* --- Окна --- */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center;
  justify-content: center; padding: 16px; z-index: 50; animation: fade .15s ease-out;
}
.dialog {
  width: 100%; max-width: 460px; max-height: 100%; overflow: auto; background: var(--panel);
  border: 1px solid var(--panel-border); border-radius: 14px; padding: 20px;
}
.dialog h2 { margin: 0 0 14px; font-size: 18px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.users { width: 100%; font-size: 13px; margin-top: 6px; }
.users td, .users th { padding: 4px 6px; text-align: left; border-top: 1px solid var(--panel-border); }
.users th { cursor: default; position: static; background: transparent; }

/* --- Просмотр новых --- */
.review {
  position: fixed; right: 16px; bottom: 16px; width: 440px; max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px); overflow: auto; z-index: 40; background: var(--panel);
  border: 1px solid var(--field-border); border-radius: 14px; padding: 16px;
  box-shadow: 0 16px 50px rgba(0,0,0,.55); animation: fade .2s ease-out;
}
.review-head { display: flex; align-items: center; gap: 8px; }
.review-progress { height: 4px; background: var(--field); border-radius: 2px; margin: 8px 0 12px; overflow: hidden; }
.review-progress div { height: 100%; background: var(--orange); transition: width .3s ease-out; }
.review-title { font-weight: 600; font-size: 15px; overflow-wrap: anywhere; }
.review-steps { font-size: 13px; color: var(--text-label); margin: 10px 0; padding-left: 18px; }
.review-steps li { margin-bottom: 3px; }
.decisions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-top: 12px; }
.decisions .btn { justify-content: center; }
.btn.no { color: #fca5a5; }
.btn.yes { color: #86efac; }
.review-summary { text-align: center; padding: 10px 0; }

/* --- Узкий экран --- */
@media (max-width: 900px) {
  .workspace { flex-direction: column; overflow: auto; }
  .card-pane { width: auto; overflow: visible; }
  .table-wrap { min-height: 320px; flex: none; max-height: 60vh; }
  .params { grid-template-columns: minmax(0, 1fr); }
  #vacancySelect { min-width: 0; flex: 1; }
  .brand span { display: none; }
  td.col-site, th.col-site, td.col-date, th.col-date { display: none; }
}
@media (max-width: 560px) {
  .topbar, .vacancy-bar, .workspace { padding-left: 12px; padding-right: 12px; }
  .message { margin-left: 12px; margin-right: 12px; }
  td.col-rel, th.col-rel { display: none; }
  #vacancySelect { order: 10; flex: 1 1 100%; max-width: none; }
  .toolbar input[type=search] { max-width: none; flex: 1; }
}
