/* Задачи юрдепартамента — стили интерфейса */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #1d2329;
  --muted: #5d6670;
  --line: #d8dce2;
  --line-soft: #eceef2;
  --accent: #2b6cd4;
  --accent-dark: #1d4f9e;
  --accent-weak: #e7effb;
  --red: #c23b3b;
  --red-weak: #fbe8e8;
  --amber: #a86d12;
  --amber-line: #e3b45c;
  --amber-weak: #fdf3dd;
  --green: #1e8e5a;
  --green-weak: #e2f4ea;
  --radius: 8px;
  --shadow: 0 10px 30px rgba(20, 28, 40, .18);
  --focus: 0 0 0 3px rgba(43, 108, 212, .28);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body.modal-open { overflow: hidden; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0 0 8px; }
.boot { padding: 60px; text-align: center; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.hidden, [hidden] { display: none !important; }

/* ---------- кнопки и поля ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--line);
  background: var(--surface); color: var(--text); font: inherit; font-weight: 500;
  cursor: pointer; white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover { background: #f1f3f6; }
.btn:focus-visible, .input:focus, .icon-btn:focus-visible, .tab:focus-visible { outline: none; box-shadow: var(--focus); }
.btn.primary { background: var(--accent-weak); border-color: var(--accent); color: #123a75; font-weight: 600; }
.btn.primary:hover { background: #d9e6fa; }
.btn.solid { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.solid:hover { background: var(--accent-dark); }
.btn.danger { color: var(--red); border-color: #efc4c4; }
.btn.danger:hover { background: var(--red-weak); }
.btn.small { height: 28px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.link-btn { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--red); }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px;
  border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: #eef0f3; color: var(--text); }
.input {
  height: 34px; padding: 0 10px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--surface); color: var(--text); font: inherit; min-width: 0;
}
textarea.input { height: auto; padding: 8px 10px; resize: vertical; line-height: 1.45; }
select.input { padding-right: 6px; }
.input:disabled { background: #f3f4f6; color: var(--muted); }
.input.invalid { border-color: var(--red); box-shadow: 0 0 0 3px rgba(194, 59, 59, .15); }
.check { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; white-space: nowrap; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }

/* ---------- верхняя панель ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50; display: flex; align-items: center; gap: 28px;
  height: 56px; padding: 0 24px; background: var(--surface); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 15px; white-space: nowrap; display: flex; align-items: center; gap: 8px; }
.brand img { width: 22px; height: 22px; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tab {
  display: flex; align-items: center; padding: 0 12px; color: var(--muted); font-weight: 500;
  border-bottom: 2px solid transparent; text-decoration: none !important; font-size: 14.5px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); font-weight: 650; border-bottom-color: var(--accent); }
.topbar .spacer { flex: 1; }
.top-actions { display: flex; align-items: center; gap: 6px; position: relative; }
.bell { position: relative; }
.bell svg { width: 20px; height: 20px; }
.bell .count {
  position: absolute; top: 0; right: -2px; min-width: 17px; height: 17px; padding: 0 4px; border-radius: 9px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: 700; line-height: 17px; text-align: center;
}
.user-btn { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 8px; border: 0; border-radius: 6px; background: none; font: inherit; color: var(--text); cursor: pointer; }
.user-btn:hover { background: #eef0f3; }
.user-btn .role { color: var(--muted); font-size: 12.5px; }
.dropdown {
  position: absolute; top: 44px; right: 0; z-index: 60; width: 360px; max-height: 70vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.dropdown.menu { width: 220px; padding: 6px 0; }
.dropdown .menu-item { display: block; width: 100%; padding: 9px 14px; border: 0; background: none; text-align: left; font: inherit; color: var(--text); cursor: pointer; }
.dropdown .menu-item:hover { background: #f2f4f7; }
.dd-head { display: flex; justify-content: space-between; align-items: center; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); font-weight: 600; }
.notif { display: block; padding: 10px 14px; border-bottom: 1px solid var(--line-soft); color: var(--text); text-decoration: none !important; cursor: pointer; }
.notif:hover { background: #f5f7fa; }
.notif.unread { background: #f4f8ff; }
.notif.unread .n-text { font-weight: 600; }
.notif .n-time { color: var(--muted); font-size: 12px; margin-top: 2px; }
.dd-empty { padding: 24px 14px; color: var(--muted); text-align: center; }

/* ---------- основная область ---------- */
main { max-width: 1440px; margin: 0 auto; padding: 20px 24px 60px; }
.page-title { font-size: 20px; font-weight: 700; margin-bottom: 16px; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.toolbar .search { width: 280px; }
.toolbar select.input { max-width: 220px; }
.list-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin: 0 0 8px; color: var(--muted); font-size: 13px; }
.legend { display: inline-flex; align-items: center; gap: 6px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid; }
.legend i.red { background: var(--red-weak); border-color: var(--red); }
.legend i.yellow { background: var(--amber-weak); border-color: var(--amber-line); }

/* ---------- таблицы ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; }
table.grid th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 13px; padding: 10px 12px;
  border-bottom: 1px solid var(--line); background: #fafbfc; white-space: nowrap; user-select: none;
}
table.grid.resizable { table-layout: fixed; }
table.grid.resizable th { position: relative; padding-right: 17px; }
table.grid.resizable td { overflow-wrap: anywhere; }
.col-resizer { position: absolute; top: 0; right: 0; bottom: 0; width: 9px; cursor: col-resize; touch-action: none; }
.col-resizer:hover, .col-resizer:focus-visible { background: rgba(46, 106, 179, .2); outline: none; }
body.resizing-column { cursor: col-resize; user-select: none; }
table.grid th.sortable { cursor: pointer; }
table.grid th.sortable:hover { color: var(--text); }
table.grid th .arrow { margin-left: 4px; color: var(--accent); }
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.grid tr:last-child td { border-bottom: 0; }
table.grid.clickable tbody tr { cursor: pointer; }
table.grid.clickable tbody tr:hover td { box-shadow: inset 0 0 0 9999px rgba(20, 40, 80, .035); }
table.grid tbody tr:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
tr.row-red td { background: var(--red-weak); }
tr.row-yellow td { background: var(--amber-weak); }
td.num { color: var(--muted); font-variant-numeric: tabular-nums; width: 64px; }
td.strong { font-weight: 700; }
td.c-title { min-width: 220px; }
td.c-title .title-text { margin-right: 6px; }
td.c-preview { font-size: 13px; line-height: 1.35; }
.cell-preview { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; white-space: pre-wrap; }
.cell-preview.expanded { display: block; }
.cell-expand { border: 0; background: transparent; padding: 2px 0 0; color: var(--accent);
  cursor: pointer; font-size: 11px; text-decoration: underline; }
.cell-detail { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }
.empty-state { padding: 48px 20px; text-align: center; color: var(--muted); }
.more-row { text-align: center; padding: 14px; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--line); font-size: 12.5px; white-space: nowrap; background: var(--surface); }
.pill.new { border-color: #b9cdee; color: #1d4f9e; }
.pill.in_work { border-color: #c9ced6; }
.pill.done { border-color: #a9d9bf; color: #17734a; background: var(--green-weak); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 10px; font-size: 12px; line-height: 18px; vertical-align: middle; white-space: nowrap; }
.badge.dup { border: 1px solid #5fb88d; background: var(--green-weak); color: #145c3b; cursor: help; }
.tag { display: inline-block; margin-left: 8px; font-weight: 700; }
.tag.red { color: var(--red); }
.tag.yellow { color: var(--amber); }
.tag.green { color: var(--green); }

/* ---------- всплывающие окна ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100; display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow: auto; background: rgba(20, 25, 35, .38);
}
.modal { width: min(560px, 100%); background: var(--surface); border-radius: 10px; box-shadow: var(--shadow); }
.modal.wide { width: min(1120px, 100%); }
.modal.mid { width: min(720px, 100%); }
.modal-head { display: flex; align-items: flex-start; gap: 12px; padding: 16px 20px 12px; border-bottom: 1px solid var(--line-soft); }
.modal-title { flex: 1; font-size: 17px; font-weight: 700; line-height: 1.35; }
.modal-body { padding: 16px 20px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding-top: 16px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.popover {
  position: absolute; z-index: 300; max-width: 380px; padding: 10px 12px; background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); font-size: 13px;
}
.popover .pop-title { font-weight: 600; margin-bottom: 6px; }
.popover .pop-item { display: block; padding: 3px 0; }
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 400; display: flex; flex-direction: column; gap: 8px; max-width: 420px; }
.toast { padding: 11px 14px; border-radius: 7px; background: #1f2731; color: #fff; box-shadow: var(--shadow); transition: opacity .3s; }
.toast.error { background: #a83232; }
.toast.ok { background: #1c6e48; }
.toast.hide { opacity: 0; }

/* ---------- формы ---------- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > label, .field > .label { font-size: 13px; font-weight: 600; color: #39424c; }
.field .req { color: var(--red); margin-left: 2px; }
.field .hint { font-size: 12px; color: var(--muted); }
.company-picker { height: auto; min-height: 34px; max-height: 154px; overflow-y: auto; padding: 7px 9px; display: grid; gap: 6px; }
.company-picker.invalid { border-color: var(--red); box-shadow: 0 0 0 3px rgba(194, 59, 59, .15); }
.form-error { margin-top: 12px; padding: 9px 12px; border-radius: 6px; background: var(--red-weak); color: #8f2626; }
.dup-hint { grid-column: 1 / -1; padding: 9px 12px; border-radius: 6px; background: var(--green-weak); border: 1px solid #a9d9bf; font-size: 13px; }
.dup-hint a { margin-right: 8px; }
.create-sections { display: grid; gap: 14px; margin-top: 18px; }
.create-section { border-top: 1px solid var(--line-soft); padding-top: 14px; }
.create-section h3 { margin: 0 0 10px; font-size: 15px; }
.create-section .field { max-width: 100%; }
.create-section input[type=number] { max-width: 200px; }
.dup-summary { margin-top: 4px; font-size: 12px; line-height: 1.4; color: #246142; overflow-wrap: anywhere; }
.dup-summary a { color: #135b38; text-decoration: underline; text-underline-offset: 2px; }

/* ---------- карточка задачи ---------- */
.card-title { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.card-title .num { color: var(--muted); font-weight: 600; }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.card-meta { color: #39424c; margin-bottom: 4px; }
.card-dates { margin: 6px 0 4px; }
.card-desc { margin: 12px 0 4px; padding: 10px 12px; border-radius: 6px; background: #f7f8fa; white-space: pre-wrap; overflow-wrap: anywhere; }
.card-dups { margin: 10px 0 0; padding: 9px 12px; border-radius: 6px; background: var(--green-weak); border: 1px solid #a9d9bf; font-size: 13px; }
.card-dups a { margin: 0 6px; }
.stale { margin: 10px 0 0; padding: 9px 12px; border-radius: 6px; background: var(--amber-weak); border: 1px solid var(--amber-line); }
.card-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 28px; margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--line-soft); }
.card-grid .col + .col { padding-left: 28px; border-left: 1px solid var(--line-soft); }
.sec { margin-bottom: 22px; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.sec-head h3 { font-size: 15px; font-weight: 700; }
.steps { list-style: none; margin: 0; padding: 0; }
.step { display: flex; align-items: center; gap: 8px; padding: 5px 0; min-height: 34px; }
.step .step-main { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; cursor: pointer; }
.step input[type=checkbox] { width: 17px; height: 17px; margin: 0; flex: none; accent-color: var(--accent); }
.step .step-text { overflow-wrap: anywhere; }
.step .step-text.done { color: var(--muted); text-decoration: line-through; text-decoration-color: #aab1ba; }
.step .step-date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.step .step-date.late { color: var(--red); font-weight: 600; }
.row-actions { display: flex; gap: 2px; opacity: 0; transition: opacity .12s; }
.step:hover .row-actions, .step:focus-within .row-actions, .comment:hover .row-actions, .comment:focus-within .row-actions { opacity: 1; }
.row-actions .icon-btn { width: 26px; height: 26px; font-size: 15px; }
.inline-form { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.inline-form .input { height: 32px; }
.inline-form .grow { flex: 1; min-width: 160px; }
.empty-line { color: var(--muted); padding: 4px 0; }
.time-line { margin: 4px 0; }
.time-entries { margin: 6px 0 0; padding: 0; list-style: none; font-size: 13px; color: #39424c; }
.time-entries li { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.comments { display: flex; flex-direction: column; }
.comment { padding: 8px 0; border-bottom: 1px solid var(--line-soft); }
.comment:last-child { border-bottom: 0; }
.comment .c-head { display: flex; align-items: center; gap: 10px; margin-bottom: 3px; }
.comment .c-head .muted { font-size: 12.5px; }
.comment .c-text { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.comment .row-actions { margin-left: auto; }
.mention { color: var(--accent-dark); font-weight: 600; background: var(--accent-weak); border-radius: 4px; padding: 0 3px; }
.comment-form { position: relative; margin-top: 10px; }
.comment-form textarea { width: 100%; }
.comment-form .cf-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 6px; }
.mention-box { position: absolute; z-index: 20; left: 0; min-width: 220px; background: var(--surface); border: 1px solid var(--line); border-radius: 6px; box-shadow: var(--shadow); padding: 4px 0; }
.mention-box div { padding: 6px 12px; cursor: pointer; }
.mention-box div.active, .mention-box div:hover { background: var(--accent-weak); }
details.history summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 4px 0; }
details.history ul { list-style: none; margin: 6px 0 0; padding: 0; font-size: 13px; }
details.history li { padding: 4px 0; border-bottom: 1px solid var(--line-soft); }
details.history li .muted { font-size: 12px; }

/* ---------- вход ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: min(380px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 28px 28px 24px; box-shadow: 0 6px 24px rgba(20, 28, 40, .06); }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }
.login-card .sub { color: var(--muted); margin-bottom: 18px; }
.login-card .field { margin-bottom: 12px; }
.login-card .btn { width: 100%; height: 38px; margin-top: 6px; }
.login-note { margin-top: 12px; padding: 9px 12px; border-radius: 6px; background: var(--amber-weak); color: #7a5410; }

/* ---------- отчеты и настройки ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 16px; }
.panel h2 { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.panel .note { color: var(--muted); margin-bottom: 12px; font-size: 13px; }
.panel .filters { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; }
.panel .filters .field { min-width: 150px; }
.panel .preview { margin-top: 14px; }
.panel .preview .table-wrap { max-height: 420px; overflow: auto; }
.panel table.grid td, .panel table.grid th { padding: 8px 10px; font-size: 13px; }
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; align-items: start; }
.settings-grid .panel { margin-bottom: 0; }
.panel.wide { grid-column: 1 / -1; }
.radio-row { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.company-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.company-row .name { flex: 1; }
.kv { display: grid; grid-template-columns: 180px 1fr; gap: 6px 12px; font-size: 13px; }
.kv .k { color: var(--muted); }
.status-off { color: var(--muted); }

@media (max-width: 900px) {
  .card-grid { grid-template-columns: 1fr; }
  .card-grid .col + .col { padding-left: 0; border-left: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .topbar { gap: 12px; padding: 0 12px; }
  .brand span { display: none; }
  main { padding: 16px 12px 40px; }
  .toolbar .search { width: 100%; }
  .settings-grid { grid-template-columns: 1fr; }
}

/* ---------- узкие экраны (телефон) ---------- */
.mobile-only { display: none; }
@media (max-width: 700px) and (pointer: coarse) {
  .topbar { gap: 8px; padding: 0 8px; min-width: 0; }
  .tabs { min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .tab { padding: 0 9px; white-space: nowrap; }
  .user-btn { min-width: 0; padding: 0 4px; }
  .user-btn .role { display: none; }
  .user-btn .name { max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .dropdown { max-width: calc(100vw - 16px); }
  .mobile-only { display: block; margin-top: 2px; }
  .mobile-task-extra { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; line-clamp: 2;
    overflow: hidden; color: #39424c; font-size: 12px; line-height: 1.35; overflow-wrap: anywhere; }
  /* в списке остаются главные столбцы: задача, исполнитель, срок, статус */
  table.list-tasks th:nth-child(2), table.list-tasks td:nth-child(2),
  table.list-tasks th:nth-child(4), table.list-tasks td:nth-child(4),
  table.list-archive th:nth-child(4), table.list-archive td:nth-child(4),
  table.list-tasks th:nth-child(5), table.list-tasks td:nth-child(5),
  table.list-tasks th:nth-child(6), table.list-tasks td:nth-child(6),
  table.list-tasks th:nth-child(7), table.list-tasks td:nth-child(7),
  table.list-tasks th:nth-child(8), table.list-tasks td:nth-child(8),
  table.list-tasks th:nth-child(9), table.list-tasks td:nth-child(9),
  table.list-archive th:nth-child(2), table.list-archive td:nth-child(2),
  table.list-archive th:nth-child(5), table.list-archive td:nth-child(5),
  table.list-archive th:nth-child(7), table.list-archive td:nth-child(7),
  table.list-archive th:nth-child(8), table.list-archive td:nth-child(8) { display: none; }
  table.grid th, table.grid td { padding-left: 6px; padding-right: 6px; }
  table.grid.resizable { width: 100% !important; table-layout: auto; }
  .col-resizer { display: none; }
}

.check.wrap { white-space: normal; align-items: flex-start; }
.check.wrap input { margin-top: 2px; flex: none; }

.dropdown a.menu-item { text-decoration: none; color: var(--text); }
