/* ===== Кульман — двіжок ТЗ ===================================== */
/* Палітра: інк-графіт, паперова сітка кульмана, синій штамп        */
:root {
  --ink: #182430;
  --ink-soft: #45566a;
  --ink-faint: #8496a8;
  --ground: #edf0f2;
  --grid-line: rgba(24, 36, 48, 0.045);
  --surface: #ffffff;
  --line: #d8dee5;
  --stamp: #1450c8;
  --stamp-soft: #e7edfb;
  --danger: #b42318;

  --st-todo: #64748b;    --st-todo-bg: #eef1f5;
  --st-progress: #b45309; --st-progress-bg: #fdf3e3;
  --st-review: #7c3aed;  --st-review-bg: #f3edfd;
  --st-done: #15803d;    --st-done-bg: #e8f6ec;

  --font-body: 'IBM Plex Sans', system-ui, -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, 'Cascadia Mono', monospace;
  --font-brand: 'Unbounded', var(--font-body);

  --radius: 10px;
  --shadow: 0 1px 2px rgba(24,36,48,.06), 0 6px 24px rgba(24,36,48,.07);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: 14px;
  color: var(--ink);
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0 / 100% 24px,
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0 / 24px 100%,
    var(--ground);
}

.wordmark {
  font-family: var(--font-brand);
  font-weight: 500;
  letter-spacing: .14em;
  color: var(--ink);
  user-select: none;
}
.eyebrow {
  font-family: var(--font-mono);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .12em;
  color: var(--ink-faint);
}

/* ===== Кнопки ================================================= */
.btn {
  font-family: var(--font-body);
  font-size: 13px; font-weight: 600;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 14px;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.btn-primary { background: var(--stamp); color: #fff; }
.btn-primary:hover { background: #0f3e9c; }
.btn-ghost { background: transparent; color: var(--ink-soft); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--ink-faint); color: var(--ink); }
.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-danger-link {
  background: none; border: none; color: var(--danger);
  font-size: 12px; cursor: pointer; padding: 4px;
}
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--stamp);
  outline-offset: 1px;
}

/* ===== Вхід ==================================================== */
.login-wrap {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 24px;
}
.login-card {
  width: 360px; max-width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 36px 32px;
}
.login-card .wordmark { font-size: 22px; margin-bottom: 8px; }
.login-sub { color: var(--ink-soft); margin: 0 0 24px; line-height: 1.5; }
.login-card label { display: block; font-weight: 600; font-size: 12px; margin-bottom: 14px; color: var(--ink-soft); }
.login-card input {
  display: block; width: 100%;
  margin-top: 5px; padding: 9px 12px;
  font: inherit;
  border: 1px solid var(--line); border-radius: 8px;
}
.login-error { color: var(--danger); font-size: 13px; margin-bottom: 12px; }

/* ===== Каркас ================================================= */
.app { display: flex; flex-direction: column; height: 100vh; }

.topbar {
  display: flex; align-items: center; gap: 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 16px;
  height: 52px;
  flex-shrink: 0;
}
.wordmark-sm { font-size: 13px; }
.menu-btn {
  display: none;
  background: none; border: 1px solid var(--line); border-radius: 8px;
  font-size: 15px; color: var(--ink-soft);
  padding: 4px 9px; cursor: pointer;
}
.doc-title-wrap { flex: 1; min-width: 0; }
.doc-title {
  width: 100%;
  font: 600 16px var(--font-body);
  color: var(--ink);
  border: 1px solid transparent; border-radius: 8px;
  padding: 6px 10px;
  background: transparent;
}
.doc-title:hover { border-color: var(--line); }
.doc-title:focus { border-color: var(--stamp); background: var(--surface); }
.doc-title:disabled { color: var(--ink); -webkit-text-fill-color: var(--ink); opacity: 1; }

.view-switch {
  display: flex; gap: 2px;
  background: var(--ground);
  border: 1px solid var(--line);
  border-radius: 9px; padding: 2px;
}
.view-switch button {
  font: 600 12px var(--font-body);
  border: none; border-radius: 7px;
  background: transparent; color: var(--ink-soft);
  padding: 5px 12px; cursor: pointer;
}
.view-switch button.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 2px rgba(24,36,48,.12); }

.topbar-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }

/* Аватари-штампи */
.avatars { display: flex; }
.avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  border: 2px solid var(--surface);
  display: inline-grid; place-items: center;
  font: 600 11px var(--font-body);
  color: #fff;
  cursor: default;
  flex-shrink: 0;
}
.avatars .avatar { margin-left: -7px; }
.avatars .avatar:first-child { margin-left: 0; }
.avatar.self { cursor: pointer; border-color: var(--stamp); }

.user-menu { position: relative; }
.dropdown {
  position: absolute; right: 0; top: 38px; z-index: 40;
  background: var(--surface);
  border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow);
  min-width: 190px; padding: 6px;
}
.dropdown-head { font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.dropdown button {
  display: block; width: 100%; text-align: left;
  background: none; border: none; border-radius: 6px;
  font: 500 13px var(--font-body); color: var(--ink-soft);
  padding: 8px 10px; cursor: pointer;
}
.dropdown button:hover { background: var(--ground); color: var(--ink); }

.layout { display: flex; flex: 1; min-height: 0; }

/* ===== Сайдбар ================================================= */
.sidebar {
  width: 250px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 8px;
}
.doc-list { overflow-y: auto; padding: 4px 8px 16px; }
.doc-item {
  display: block; width: 100%; text-align: left;
  background: none; border: 1px solid transparent; border-radius: 8px;
  padding: 9px 10px; margin-bottom: 2px;
  cursor: pointer; font: inherit; color: var(--ink);
}
.doc-item:hover { background: var(--ground); }
.doc-item.active { background: var(--stamp-soft); border-color: rgba(20,80,200,.25); }
.doc-item .di-title { font-weight: 600; font-size: 13px; display: block; margin-bottom: 3px; }
.doc-item .di-meta { font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-faint); }
.doc-progress {
  height: 3px; border-radius: 2px; background: var(--line);
  margin-top: 6px; overflow: hidden;
}
.doc-progress i { display: block; height: 100%; background: var(--st-done); }

/* ===== Основна зона =========================================== */
.main {
  flex: 1; min-width: 0;
  overflow-y: auto;
  position: relative;
  padding: 24px;
}
.placeholder {
  height: 100%;
  display: grid; place-content: center; text-align: center;
  color: var(--ink-faint);
}
.placeholder-art { font-size: 44px; margin-bottom: 8px; }

/* --- Режим «Документ» --- */
.doc-view { max-width: 820px; margin: 0 auto; padding-bottom: 90px; }
.item-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(24,36,48,.05);
  margin-bottom: 14px;
  position: relative;
  transition: box-shadow .15s;
}
.item-card:focus-within { box-shadow: var(--shadow); border-color: rgba(20,80,200,.35); }
.item-head {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 14px 0;
}
.item-num {
  font-family: var(--font-mono); font-size: 11px;
  color: var(--ink-faint); flex-shrink: 0;
  min-width: 26px;
}
.item-title {
  flex: 1; min-width: 0;
  font: 600 15px var(--font-body); color: var(--ink);
  border: none; background: transparent; padding: 4px 6px;
  border-radius: 6px;
}
.item-title:hover { background: var(--ground); }
.item-title:focus { background: var(--ground); }
.item-content {
  display: block; width: calc(100% - 28px);
  margin: 6px 14px 10px;
  font: 400 14px/1.6 var(--font-body); color: var(--ink);
  border: none; background: transparent;
  border-radius: 6px; padding: 6px;
  resize: none; overflow: hidden;
  min-height: 40px;
}
.item-content:hover { background: var(--ground); }
.item-content:focus { background: var(--ground); }
.item-foot {
  display: flex; align-items: center; gap: 10px;
  border-top: 1px dashed var(--line);
  padding: 8px 14px;
}
.item-foot .spacer { flex: 1; }
.item-move { display: flex; gap: 2px; }
.item-move button, .item-del {
  background: none; border: none; color: var(--ink-faint);
  cursor: pointer; font-size: 14px; padding: 2px 6px; border-radius: 5px;
}
.item-move button:hover { background: var(--ground); color: var(--ink); }
.item-del:hover { background: #fdecec; color: var(--danger); }

select.item-status, select.item-assignee {
  font: 500 12px var(--font-body);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 4px 8px; cursor: pointer; background: var(--surface);
  color: var(--ink-soft);
  max-width: 170px;
}
select.item-status[data-st="todo"]        { background: var(--st-todo-bg); color: var(--st-todo); border-color: transparent; }
select.item-status[data-st="in_progress"] { background: var(--st-progress-bg); color: var(--st-progress); border-color: transparent; }
select.item-status[data-st="review"]      { background: var(--st-review-bg); color: var(--st-review); border-color: transparent; }
select.item-status[data-st="done"]        { background: var(--st-done-bg); color: var(--st-done); border-color: transparent; }

/* Індикатор "хто редагує" — як позначка олівцем */
.editing-badge {
  position: absolute; top: -9px; right: 12px;
  font: 500 10.5px var(--font-mono);
  background: var(--ink); color: #fff;
  border-radius: 5px; padding: 2px 8px;
  animation: pulse 1.6s ease-in-out infinite;
  pointer-events: none;
  z-index: 5;
}
@keyframes pulse { 50% { opacity: .55; } }

.item-updated {
  font-family: var(--font-mono); font-size: 10.5px; color: var(--ink-faint);
}

/* --- Режим «Дошка» --- */
.board-view {
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 14px;
  align-items: start;
  min-height: calc(100% - 10px);
}
.board-col {
  background: rgba(255,255,255,.55);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  min-height: 200px;
}
.board-col h3 {
  font: 600 12px var(--font-body);
  text-transform: uppercase; letter-spacing: .08em;
  margin: 2px 4px 10px;
  color: var(--ink-soft);
}
.board-col[data-status="todo"] h3        { color: var(--st-todo); }
.board-col[data-status="in_progress"] h3 { color: var(--st-progress); }
.board-col[data-status="review"] h3      { color: var(--st-review); }
.board-col[data-status="done"] h3        { color: var(--st-done); }
.board-col.drag-over { border-color: var(--stamp); background: var(--stamp-soft); }

.col-cards { display: flex; flex-direction: column; gap: 8px; min-height: 40px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  cursor: grab;
  box-shadow: 0 1px 2px rgba(24,36,48,.06);
  position: relative;
}
.card:hover { border-color: var(--ink-faint); }
.card.dragging { opacity: .45; }
.card-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.card-meta { display: flex; align-items: center; gap: 6px; }
.card-meta .avatar { width: 22px; height: 22px; font-size: 9px; border-width: 1px; }
.card-num { font-family: var(--font-mono); font-size: 10px; color: var(--ink-faint); margin-left: auto; }

.fab {
  position: sticky; bottom: 20px; left: 100%;
  transform: translateX(-8px);
  background: var(--stamp); color: #fff;
  border: none; border-radius: 999px;
  font: 600 13px var(--font-body);
  padding: 12px 20px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(20,80,200,.35);
}
.fab:hover { background: #0f3e9c; }

/* ===== Журнал змін ============================================ */
.journal {
  width: 320px; flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column;
}
.journal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 14px 8px;
}
.journal-close {
  background: none; border: none; font-size: 18px;
  color: var(--ink-faint); cursor: pointer; line-height: 1;
}
.journal-feed { overflow-y: auto; padding: 4px 14px 20px; flex: 1; }
.j-entry {
  border-left: 2px solid var(--line);
  padding: 2px 0 10px 12px;
  margin-left: 4px;
  position: relative;
}
.j-entry::before {
  content: '';
  position: absolute; left: -5px; top: 6px;
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--ink-faint);
}
.j-entry[data-act="item_create"]::before { border-color: var(--st-done); }
.j-entry[data-act="item_delete"]::before { border-color: var(--danger); }
.j-entry[data-act="item_update"]::before { border-color: var(--stamp); }
.j-time { font-family: var(--font-mono); font-size: 10px; color: var(--ink-faint); }
.j-line { font-size: 12.5px; line-height: 1.45; color: var(--ink-soft); margin-top: 1px; }
.j-line b { color: var(--ink); font-weight: 600; }
.j-diff {
  font-family: var(--font-mono); font-size: 11px;
  margin-top: 4px;
  background: var(--ground); border-radius: 6px;
  padding: 5px 8px;
  overflow-wrap: anywhere;
}
.j-diff .old { color: var(--danger); text-decoration: line-through; }
.j-diff .new { color: var(--st-done); }
.j-field {
  display: inline-block;
  font-family: var(--font-mono); font-size: 10px;
  background: var(--stamp-soft); color: var(--stamp);
  border-radius: 4px; padding: 0 5px;
}

/* ===== Модалки ================================================ */
.modal { border: none; border-radius: 14px; box-shadow: var(--shadow); padding: 0; width: 400px; max-width: 92vw; }
.modal-wide { width: 620px; }
.modal::backdrop { background: rgba(24,36,48,.4); }
.modal-body { padding: 24px; }
.modal-body h3 { margin: 0 0 16px; font-size: 16px; }
.modal-body h4 { margin: 20px 0 10px; font-size: 13px; color: var(--ink-soft); }
.modal-body label { display: block; font-weight: 600; font-size: 12px; color: var(--ink-soft); margin-bottom: 12px; }
.modal-body input, .modal-body select, .modal-body textarea {
  display: block; width: 100%;
  margin-top: 5px; padding: 8px 11px;
  font: inherit;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--ink);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.modal-error { color: var(--danger); font-size: 13px; margin-top: 10px; }

.users-table { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.users-row {
  display: grid; grid-template-columns: 1fr 110px 130px 90px;
  gap: 8px; align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.users-row:last-child { border-bottom: none; }
.users-row .u-login { font-family: var(--font-mono); font-size: 11px; color: var(--ink-faint); }
.users-row select { font: 500 12px var(--font-body); padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; }
.user-add { display: grid; grid-template-columns: 1fr 1fr 1fr 130px auto; gap: 8px; }
.user-add input, .user-add select { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; min-width: 0; }

/* ===== Адмін-панель =========================================== */
.admin-badge {
  font-family: var(--font-mono); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .1em;
  background: var(--stamp-soft); color: var(--stamp);
  border-radius: 999px; padding: 3px 10px;
}
.admin-main {
  flex: 1; overflow-y: auto;
  padding: 24px;
  max-width: 1060px; margin: 0 auto; width: 100%;
}
.admin-panel {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 1px 2px rgba(24,36,48,.05);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.admin-panel .eyebrow { display: block; margin-bottom: 12px; }
.admin-cols { display: grid; grid-template-columns: 1fr 1.2fr; gap: 16px; }
.muted { color: var(--ink-faint); font-size: 13px; }

/* Стат-плитки */
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 16px;
}
.tile {
  background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px;
  display: flex; flex-direction: column; gap: 2px;
}
.tile-label {
  font-family: var(--font-mono); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .1em;
  color: var(--ink-faint);
}
.tile-value { font-size: 26px; font-weight: 700; color: var(--ink); }
.tile-sub { font-size: 12px; color: var(--ink-soft); }

/* Смуга статусів */
.status-bar {
  display: flex; gap: 2px;
  height: 14px; border-radius: 7px; overflow: hidden;
  background: var(--ground);
}
.status-bar i { display: block; height: 100%; min-width: 6px; }
.status-empty { font-size: 12px; color: var(--ink-faint); padding: 0 6px; }
.status-legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12.5px; color: var(--ink-soft); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.legend-item b { color: var(--ink); }

/* Топ користувачів */
.top-row { display: grid; grid-template-columns: 130px 1fr 40px; gap: 10px; align-items: center; margin-bottom: 8px; }
.top-name { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top-track { height: 8px; background: var(--ground); border-radius: 4px; overflow: hidden; }
.top-track i { display: block; height: 100%; background: var(--stamp); border-radius: 4px; }
.top-count { font-family: var(--font-mono); font-size: 12px; color: var(--ink-soft); text-align: right; }

/* Таблиці */
.admin-table { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.admin-row {
  display: grid;
  grid-template-columns: 1fr 130px 120px 90px 100px;
  gap: 10px; align-items: center;
  padding: 9px 14px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.admin-row:last-child { border-bottom: none; }
.admin-row-head {
  background: var(--ground);
  font-family: var(--font-mono); font-size: 10.5px;
  text-transform: uppercase; letter-spacing: .08em;
  color: var(--ink-faint);
}
.admin-row.inactive > span:first-child { color: var(--ink-faint); }
.admin-row select { font: 500 12px var(--font-body); padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.docs-grid { grid-template-columns: 1fr 120px 70px 60px 130px 110px; }
.u-self { color: var(--ink-faint); font-size: 11px; }
.mono-cell { font-family: var(--font-mono); font-size: 11.5px; color: var(--ink-soft); }
.row-actions { text-align: right; }
.j-doc { color: var(--ink-faint); }

.journal-filters {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 12px; flex-wrap: wrap;
}
.journal-filters select {
  font: 500 12px var(--font-body);
  border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; background: var(--surface);
  max-width: 220px;
}
.journal-filters .eyebrow { flex: 1; }
.admin-journal { max-height: 60vh; overflow-y: auto; margin-bottom: 10px; }

@media (max-width: 900px) {
  .admin-cols { grid-template-columns: 1fr; }
  .admin-row, .docs-grid { grid-template-columns: 1fr; gap: 6px; }
  .admin-row-head { display: none; }
  .row-actions { text-align: left; }
}

/* ===== Тости ================================================== */
.toast {
  position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff;
  border-radius: 9px; padding: 10px 18px;
  font-size: 13px;
  z-index: 100;
  animation: toast-in .2s ease-out;
}
.toast.error { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }

/* ===== Адаптив ================================================ */
@media (max-width: 1100px) {
  .journal { position: fixed; right: 0; top: 52px; bottom: 0; z-index: 30; box-shadow: var(--shadow); }
  .board-view { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
  .menu-btn { display: block; }
  .sidebar { position: fixed; left: 0; top: 52px; bottom: 0; z-index: 30; box-shadow: var(--shadow); transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; }
  .board-view { grid-template-columns: 1fr; }
  .view-switch button { padding: 5px 8px; }
  .topbar { gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
