:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --accent: #0f172a;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

/* ---------- buttons & inputs ---------- */

.btn {
  font: inherit;
  font-size: 13.5px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 9px;
  padding: 8px 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn:hover { background: #f1f5f9; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn.primary:hover { background: #1e293b; }

.btn.select { padding: 7px 9px; }

input[type="text"], input[type="number"], textarea, .field select {
  width: 100%;
  font: inherit;
  font-size: 13.5px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 9px;
  background: #fff;
  color: var(--ink);
}

input[type="text"]:focus, input[type="number"]:focus, textarea:focus {
  outline: 2px solid #94a3b8;
  outline-offset: -1px;
}

input[type="color"] {
  width: 36px;
  height: 32px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
}

input[type="checkbox"] { accent-color: var(--accent); width: 15px; height: 15px; }

input[type="range"] { width: 100%; accent-color: var(--accent); }

/* ---------- layout ---------- */

main {
  max-width: 1180px;
  margin: 20px auto 40px;
  padding: 0 20px;
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.chart-card {
  flex: 1 1 auto;
  min-width: 0;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

canvas {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: block;
  touch-action: none;
}

.hint {
  color: var(--muted);
  font-size: 12.5px;
  margin-top: 12px;
  text-align: center;
}

.panel {
  flex: 0 0 332px;
  width: 332px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  position: sticky;
  top: 76px;
  max-height: calc(100vh - 96px);
  overflow: auto;
  padding-bottom: 4px;
}

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 12px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.card h2 {
  margin: 0 0 12px;
  font-size: 12.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.card h2 .count { color: #94a3b8; }

.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; }

.field label { font-size: 12px; color: var(--muted); }

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 10px;
}

.quad-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.quad-row .qname {
  font-size: 12px;
  color: var(--muted);
  flex: 0 0 68px;
}

.quad-row input[type="text"] { flex: 1; min-width: 0; }

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  margin: 8px 0 4px;
  cursor: pointer;
  user-select: none;
}

/* ---------- users ---------- */

.add-form {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.add-form input { flex: 1; min-width: 0; }

.bulk { margin-top: 8px; font-size: 13px; }

.bulk summary {
  cursor: pointer;
  color: var(--muted);
  user-select: none;
}

.bulk summary:hover { color: var(--ink); }

.bulk textarea {
  margin-top: 8px;
  resize: vertical;
  font-size: 13px;
}

.bulk .btn { margin-top: 8px; }

.user-list { margin-top: 10px; }

.user-list .empty {
  color: var(--muted);
  font-size: 13px;
  padding: 8px 2px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 2px;
  border-bottom: 1px solid var(--line);
}

.user-row:last-child { border-bottom: none; }

.user-row img,
.thumb-fallback {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  object-fit: cover;
  flex: 0 0 26px;
}

.thumb-fallback {
  background: #e2e8f0;
  color: #64748b;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
}

.user-name {
  flex: 1;
  min-width: 0;
  font-size: 13.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-row input[type="number"] {
  width: 58px;
  flex: 0 0 58px;
  font-size: 12.5px;
  padding: 4px 6px;
}

.user-del {
  border: none;
  background: none;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  padding: 3px 7px;
  border-radius: 6px;
}

.user-del:hover { color: #dc2626; background: #fee2e2; }

/* ---------- drag & drop из списка ---------- */

.user-row { touch-action: none; }

.chart-card {
  transition: border-color 0.15s, box-shadow 0.15s;
}

.chart-card.dropping {
  border-color: #94a3b8;
  box-shadow: 0 0 0 3px rgba(148, 163, 184, 0.25);
}

.drag-ghost {
  position: fixed;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background-size: cover;
  background-position: center;
  border: 2px solid #fff;
  box-shadow: 0 6px 16px rgba(15, 23, 42, 0.35);
  transform: translate(-50%, -115%);
  pointer-events: none;
  opacity: 0.95;
  z-index: 100;
}

body.list-dragging {
  cursor: grabbing !important;
  user-select: none;
  -webkit-user-select: none;
}

body.list-dragging * { cursor: grabbing !important; }

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 16px);
  background: var(--accent);
  color: #fff;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s, transform 0.25s;
  z-index: 20;
  max-width: 90vw;
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- boards ---------- */

.board-name {
  font: inherit;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px dashed transparent;
  border-radius: 0;
  padding: 4px 6px;
  width: 190px;
}

.board-name:hover { border-bottom-color: #cbd5e1; }

.board-name:focus {
  outline: none;
  border-bottom-color: #94a3b8;
  background: #f8fafc;
}

.icon-btn {
  border: none;
  background: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 16px;
  line-height: 1;
  padding: 5px 8px;
  border-radius: 6px;
}

.icon-btn:hover { background: #e2e8f0; color: var(--ink); }

.icon-btn.big { font-size: 22px; padding: 2px 8px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 15;
  padding: 20px;
}

.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--card);
  border-radius: 16px;
  width: 100%;
  max-width: 520px;
  max-height: min(80vh, 640px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.35);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 18px 6px;
}

.modal-head h3 { margin: 0; font-size: 16px; }

.modal-body {
  padding: 8px 18px 18px;
  overflow: auto;
  display: flex;
  flex-direction: column;
}

.btn.wide { width: 100%; margin-bottom: 12px; }

.boards-list { display: flex; flex-direction: column; }

.boards-list .empty {
  color: var(--muted);
  font-size: 13px;
  padding: 8px 2px;
}

.board-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
}

.board-item:hover { background: #f1f5f9; }

.board-item.current {
  background: #f8fafc;
  box-shadow: inset 3px 0 0 var(--accent);
}

.board-main { flex: 1; min-width: 0; }

.board-title {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.board-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  main { flex-direction: column; }
  .panel {
    width: 100%;
    flex: auto;
    position: static;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 600px) {
  .board-name { width: 130px; }
}
