:root {
  --bg: #f3f6f5;
  --card: #ffffff;
  --ink: #142826;
  --muted: #5d6f6b;
  --line: #dce6e3;
  --accent: #0f766e;
  --accent-2: #0d9488;
  --accent-soft: #e7f4f2;
  --danger: #b42318;
  --shadow: 0 12px 40px rgba(20, 40, 38, 0.08);
  --radius: 16px;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background:
    radial-gradient(1200px 500px at 10% -10%, #d7efe9 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
}
a { color: var(--accent); text-decoration: none; }
.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0,0,0,0);
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 12px; display: inline-block;
  background: linear-gradient(135deg, var(--accent), #36b3a0);
  box-shadow: 0 6px 16px rgba(15, 118, 110, 0.28);
}
.brand-mark.sm { width: 22px; height: 22px; border-radius: 8px; }
.auth {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); border: 1px solid var(--line);
}
.auth-card { width: min(100%, 420px); padding: 36px 32px; display: grid; gap: 14px; }
.brand { text-align: center; margin-bottom: 8px; }
.brand h1 { margin: 12px 0 4px; font-size: 28px; letter-spacing: -0.03em; }
.brand p, .hint, .meta, .who, .comment { color: var(--muted); }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 600; }
input, select, textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; font: inherit; color: var(--ink); background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(15, 118, 110, 0.18); border-color: var(--accent);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid transparent;
  font: inherit; font-weight: 600; cursor: pointer; background: none; color: var(--ink);
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.ghost { border-color: var(--line); background: #fff; }
.btn.text { min-height: 36px; color: var(--muted); }
.btn.sm { min-height: 40px; padding: 0 12px; font-size: 14px; }
.btn.primary.danger { background: var(--danger); color: #fff; }
.btn.primary.danger:hover { filter: brightness(0.93); }
.notice {
  background: #e7f6ee; color: #146c43; border-radius: 12px;
  padding: 10px 12px; margin: 0 0 12px;
}
.alert {
  background: #fde8e6; color: var(--danger); border-radius: 12px;
  padding: 10px 12px; margin: 0;
}
.top {
  position: sticky; top: 0; z-index: 5;
  background: rgba(243, 246, 245, 0.9); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.top-inner, .search-page, .edit-page {
  width: min(860px, calc(100% - 32px)); margin: 0 auto;
}
.top-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; padding: 12px 0;
}
.brand-inline, .top-actions { display: flex; align-items: center; gap: 10px; }
.search-page { padding: 28px 0 64px; }
.search-box { display: grid; gap: 14px; }
.search-box input[type="search"] {
  font-size: 20px; padding: 16px 18px; border-radius: 16px;
}
.chips {
  display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px;
  scrollbar-width: thin;
}
.chip {
  flex: 0 0 auto; cursor: pointer; margin: 0;
}
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span {
  display: inline-flex; align-items: center; min-height: 36px;
  padding: 0 12px; border-radius: 999px; background: #fff;
  border: 1px solid var(--line); color: var(--ink); font-weight: 600; font-size: 14px;
}
.chip input:checked + span,
.chip input:focus-visible + span {
  box-shadow: inset 0 0 0 2px var(--accent);
}
.busy { height: 20px; color: var(--accent); font-size: 14px; }
.htmx-indicator { opacity: 0; }
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { opacity: 1; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  background: var(--card); border: 1px solid var(--line); border-radius: 16px;
  padding: 14px 16px;
}
.item.status-norm, .item.status-norm-it, .visit-line.status-norm {
  background: #e6f6ea; border-color: #b4dfc2;
}
.item.status-uhody, .item.status-ushel-it, .visit-line.status-uhody {
  background: #eef1f2; border-color: #cfd6d8;
}
.item.status-dinamo, .visit-line.status-dinamo {
  background: #e8f0fb; border-color: #c3d4f3;
}
.item.status-chs, .item.status-chs-it, .visit-line.status-chs {
  background: #fdecea; border-color: #f3c2bc;
}
.item.status-uncategorized, .visit-line.status-uncategorized {
  background: #f7f3ea; border-color: #e4d7b8;
}
.visit-line.status-cancel {
  background: #f4efe4; border-color: #e0d3b4;
}
.item-main { min-width: 0; }
.phone {
  display: inline-block; font-size: 22px; font-weight: 700; letter-spacing: -0.03em;
  color: var(--ink); margin-right: 8px; cursor: default;
}
.item-actions { display: grid; gap: 8px; flex: 0 0 auto; justify-items: stretch; }
.cat-pill {
  display: inline-block; font-size: 12px; font-weight: 700; color: var(--accent);
  background: var(--accent-soft); border-radius: 999px; padding: 2px 8px; margin-bottom: 6px;
}
.cat-pill.status-norm, .cat-pill.status-norm-it,
.chip span.status-norm, .chip span.status-norm-it {
  color: #166534; background: #d8f3e0;
}
.cat-pill.status-uhody, .cat-pill.status-ushel-it,
.chip span.status-uhody, .chip span.status-ushel-it {
  color: #3f4a4c; background: #e4e8ea;
}
.cat-pill.status-dinamo, .chip span.status-dinamo {
  color: #1e40af; background: #dbe7fb;
}
.cat-pill.status-chs, .cat-pill.status-chs-it,
.chip span.status-chs, .chip span.status-chs-it {
  color: #9f1c16; background: #f8d7d3;
}
.cat-pill.status-uncategorized, .chip span.status-uncategorized {
  color: #7a5b12; background: #f3e8c8;
}
.copy {
  border: 0; background: none; color: var(--muted); cursor: pointer; font: inherit; font-size: 13px;
  min-height: 32px;
}
.copy.done { color: var(--accent); }
.name { font-weight: 650; margin-top: 4px; }
.comment { white-space: pre-wrap; overflow: hidden; max-width: 62ch; }
mark { background: #c8f2e8; color: inherit; padding: 0 2px; border-radius: 4px; }
.hint, .meta, .more { margin: 18px 0; }
.edit-page { padding: 28px 0 64px; }
.form { padding: 24px; display: grid; gap: 14px; }
.form h2 { margin: 0 0 4px; font-size: 18px; }
.form-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.dup-list { display: grid; gap: 8px; }
.dup-item {
  display: grid; grid-template-columns: auto 1fr; gap: 10px; align-items: start;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; background: #fff;
  cursor: pointer;
}
.dup-item input { width: auto; margin-top: 4px; }
.dup-item .comment { max-width: 100%; margin-top: 4px; font-weight: 400; }
.users-card { overflow: auto; }
.users { width: 100%; border-collapse: collapse; }
.users th {
  text-align: left; font-size: 12px; color: var(--muted); font-weight: 700;
  padding: 12px 16px 8px;
}
.user-row {
  display: grid; grid-template-columns: 110px 150px minmax(180px, 1fr) auto auto minmax(120px, 1fr) auto;
  gap: 8px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line);
}
.user-login { font-weight: 700; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); font-weight: 600; }
.check input { width: auto; margin: 0; }
.group-flags { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.group-pill { background: #e7eef6; color: #1e3a5f; }
.admin-page {
  width: min(1400px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 64px;
  display: grid;
  grid-template-columns: minmax(0, 340px) minmax(0, 1fr) minmax(280px, 340px);
  gap: 24px;
  align-items: start;
}
.tree-search { min-width: 0; }
.tree-panel {
  padding: 16px;
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 96px);
  overflow-x: hidden;
  overflow-y: auto;
  min-width: 0;
}
.group-create {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 12px;
}
.tree { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; min-width: 0; }
.tree.nested { padding: 4px 0 8px 8px; }
.tree-group {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 4px;
}
.tree-group > .tree-node { min-width: 0; }
.tree-del {
  margin-top: 8px;
  color: var(--danger);
  font-size: 12px;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}
.tree-del:hover { text-decoration: underline; }
.tree-node summary {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  cursor: pointer; padding: 8px 8px; border-radius: 10px; font-weight: 700;
  list-style: none;
}
.tree-node summary::-webkit-details-marker { display: none; }
.tree-node summary:hover { background: var(--accent-soft); }
.tree-count { color: var(--muted); font-size: 12px; font-weight: 650; flex: 0 0 auto; }
.tree-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.tree-children, .tree-list { min-width: 0; }
.tree-list .item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  padding: 10px 12px;
  overflow: hidden;
}
.tree-list .item-main { min-width: 0; }
.tree-list .phone {
  display: inline;
  font-size: 15px;
  margin-right: 6px;
  word-break: break-word;
}
.tree-list .copy { min-height: 28px; padding: 0; white-space: nowrap; }
.tree-list .comment { max-width: 100%; white-space: pre-wrap; }
.tree-list .btn.sm { min-height: 32px; padding: 0 10px; }
.work-page {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 64px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 24px;
  align-items: start;
}
.search-col { min-width: 0; }
.journal-panel {
  padding: 16px;
  position: sticky;
  top: 72px;
  max-height: calc(100vh - 96px);
  overflow: auto;
  min-width: 0;
}
.journal-panel h2 { margin: 0 0 12px; font-size: 16px; }
.journal-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.journal-item {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px;
  display: grid; gap: 8px; background: #fff;
}
.journal-form, .journal-cancel { display: grid; gap: 8px; margin-top: 6px; }
.journal-done summary { list-style: none; cursor: pointer; }
.journal-done summary::-webkit-details-marker { display: none; }
.journal-done summary.btn { display: inline-flex; width: 100%; }
.visit-status { flex-wrap: wrap; }
.chip span.status-norm { background: #e6f6ea; border-color: #b4dfc2; }
.chip span.status-uhody { background: #eef1f2; border-color: #cfd6d8; }
.chip span.status-chs { background: #fdecea; border-color: #f3c2bc; }
.visit-block { margin-top: 4px; grid-column: 1 / -1; min-width: 0; }
.visit-stats { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.visit-lines { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; width: 100%; max-height: 70vh; overflow: auto; }
.visit-line {
  border-radius: 10px; padding: 8px 12px; font-size: 14px;
  display: grid; gap: 2px; border: 1px solid var(--line); width: 100%;
  box-sizing: border-box;
}
.visit-date, .visit-tag { font-size: 12px; font-weight: 700; }
.visit-comment { white-space: pre-wrap; }
.user-login { font-weight: 700; }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink); font-weight: 600; }
.check input { width: auto; margin: 0; }
@media (max-width: 860px) {
  .user-row { grid-template-columns: 1fr 1fr; }
  .user-login { grid-column: 1 / -1; }
}
.danger-form { margin-top: 16px; }
.back { font-weight: 650; }
.help-page {
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 64px;
}
.help-card { padding: 28px 32px; }
.help-card h1 { margin: 0 0 8px; font-size: 26px; letter-spacing: -0.03em; }
.help-card h2 { margin: 22px 0 8px; font-size: 17px; }
.help-card ul { margin: 0; padding-left: 18px; display: grid; gap: 8px; }
.help-card li { color: var(--ink); }
@media (max-width: 900px) {
  .admin-page, .work-page { grid-template-columns: 1fr; }
  .tree-panel, .journal-panel { position: static; max-height: none; }
}
.visits-page { width: min(1100px, calc(100% - 32px)); }
.visits-card { overflow-x: auto; padding: 0; }
.visits-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.visits-table th, .visits-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.visits-table th { font-size: 12px; color: var(--muted); font-weight: 700; }
.visits-table .nowrap { white-space: nowrap; }
.visits-table .clip { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty-actions { margin-top: 12px; padding: 16px; display: grid; gap: 12px; }
.empty-actions textarea { min-height: 80px; }
.danger-box { margin-top: 16px; border-color: #f3c2bc; }
.danger, .btn.danger { color: var(--danger); }

/* HR workspace */
.hr-top .hr-mark {
  background: linear-gradient(135deg, #0f4c5c, #0f766e);
}
.hr-top-inner {
  width: min(1200px, calc(100% - 32px));
  flex-wrap: wrap;
}
.hr-nav {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
}
.hr-nav .btn.active {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.hr-page {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 64px;
  display: grid;
  gap: 18px;
}
.hr-hero { padding: 24px 28px; display: grid; gap: 12px; }
.hr-hero h1 { margin: 0; font-size: 26px; letter-spacing: -0.03em; }
.hr-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
}
.hr-stat {
  display: grid; gap: 2px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: 14px; background: #fff;
  color: inherit;
}
.hr-stat .n { font-size: 22px; font-weight: 750; letter-spacing: -0.03em; }
.hr-stat .l { font-size: 12px; color: var(--muted); font-weight: 650; }
.hr-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}
.hr-panel { padding: 18px; display: grid; gap: 12px; min-width: 0; }
.hr-panel-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.hr-panel-head h1, .hr-panel-head h2 { margin: 0; font-size: 18px; }
.hr-list, .hr-feed, .hr-chat-list {
  list-style: none; margin: 0; padding: 0; display: grid; gap: 10px;
}
.hr-list li, .hr-feed li {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  display: grid; gap: 4px; background: #fff;
}
.hr-list a { color: inherit; display: grid; gap: 4px; }
.hr-filter {
  padding: 16px; display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(180px, 0.8fr) auto;
  gap: 12px; align-items: end;
}
.hr-table-wrap { overflow: auto; padding: 0; }
.hr-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.hr-table th, .hr-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  text-align: left; vertical-align: top;
}
.hr-table th { font-size: 12px; color: var(--muted); font-weight: 700; }
.hr-badge {
  display: inline-flex; align-items: center; min-height: 24px;
  padding: 0 8px; border-radius: 999px; font-size: 12px; font-weight: 700;
  background: var(--accent-soft); color: var(--accent);
}
.hr-badge.status-rejected { background: #fde8e6; color: var(--danger); }
.hr-badge.status-qualified, .hr-badge.status-hired { background: #e6f6ea; color: #166534; }
.hr-badge.status-contacted, .hr-badge.status-in_review { background: #e8f0fb; color: #1e40af; }
.hr-detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}
.hr-dl { display: grid; gap: 8px; margin: 0; }
.hr-dl > div {
  display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 8px;
  padding: 6px 0; border-bottom: 1px solid var(--line);
}
.hr-dl dt { color: var(--muted); font-size: 12px; font-weight: 700; margin: 0; }
.hr-dl dd { margin: 0; }
.hr-status-form, .hr-chat-form { display: grid; gap: 10px; margin-top: 8px; }
.hr-chat-list { max-height: 55vh; overflow: auto; }
.hr-msg {
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px;
  display: grid; gap: 6px; background: #fff;
}
.hr-msg.dir-out { background: #eef8f6; }
.hr-msg.dir-in { background: #fff; }
.hr-msg-meta {
  display: flex; justify-content: space-between; gap: 8px;
  font-size: 12px; color: var(--muted); font-weight: 650;
}
.hr-msg-body { white-space: pre-wrap; }
.hr-feed li.unseen { box-shadow: inset 3px 0 0 var(--accent); }
.user-row-hr {
  grid-template-columns: 100px 140px repeat(auto-fit, minmax(110px, auto));
}
@media (max-width: 900px) {
  .hr-grid, .hr-detail-grid, .hr-filter { grid-template-columns: 1fr; }
}

