:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d7dde7;
  --text: #18202c;
  --muted: #697386;
  --accent: #315fd8;
  --danger: #bd2d21;
  --shadow: 0 2px 7px rgba(17, 24, 39, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 12px/1.35 Inter, Segoe UI, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

button, input, select, textarea { font: inherit; }

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 5px 8px;
  cursor: pointer;
}

button:hover { border-color: var(--accent); }
button:disabled { cursor: not-allowed; opacity: .55; }
button.active, button[type="submit"] {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 7px;
  background: #fff;
  color: var(--text);
}

textarea { resize: vertical; min-height: 54px; }

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  margin-top: 7px;
}

h1, h2 { margin: 0 0 8px; font-size: 14px; }
h2 { font-size: 12px; color: #2a3444; }

.hidden { display: none !important; }
.mt { margin-top: 6px; }
.muted, .hint { color: var(--muted); }
.hint { margin: 7px 0 0; font-size: 11px; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
}

.login-card { width: 270px; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px;
  box-shadow: var(--shadow);
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-rows: 38px 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.brand { font-weight: 700; min-width: 92px; }

.main-nav {
  display: flex;
  gap: 5px;
}

.main-nav button {
  padding: 4px 9px;
}

.backlog {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.userbar {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.ghost { background: transparent; }

.workspace {
  display: grid;
  grid-template-columns: 238px 1fr;
  min-height: 0;
}

.sidebar {
  display: grid;
  align-content: start;
  gap: 8px;
  padding: 8px;
  border-right: 1px solid var(--line);
  overflow: auto;
}

.tool-grid, .inline-buttons, .two-cols {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
}

.selected-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--muted);
}

.canvas-wrap {
  position: relative;
  overflow: hidden;
  background: #eef1f5;
}

.board {
  position: absolute;
  left: 0;
  top: 0;
  width: 7000px;
  height: 4800px;
  transform-origin: 0 0;
}

.bg-grid {
  background-color: #fbfcff;
  background-image:
    linear-gradient(#e6eaf1 1px, transparent 1px),
    linear-gradient(90deg, #e6eaf1 1px, transparent 1px);
  background-size: 32px 32px;
}

.bg-dots {
  background-color: #fbfcff;
  background-image: radial-gradient(#d4dbe7 1px, transparent 1px);
  background-size: 18px 18px;
}

.bg-blank { background: #fbfcff; }
.bg-dark {
  background-color: #17211e;
  background-image: radial-gradient(#344b45 1px, transparent 1px);
  background-size: 20px 20px;
}

.board-layer {
  position: relative;
  width: 100%;
  height: 100%;
}

.item {
  position: absolute;
  min-width: 10px;
  min-height: 10px;
  user-select: none;
  touch-action: none;
}

.item.selected {
  outline: 1.5px solid var(--accent);
  outline-offset: 2px;
}

.item.locked::after {
  content: "🔒";
  position: absolute;
  right: -7px;
  top: -9px;
  font-size: 12px;
}

.item[contenteditable="true"], .table-item td[contenteditable="true"] {
  user-select: text;
  cursor: text;
}

.sticky {
  border: 1px solid rgba(0,0,0,.14);
  border-radius: var(--radius, 6px);
  padding: 8px;
  box-shadow: 0 2px 5px rgba(0,0,0,.12);
  white-space: pre-wrap;
  overflow: hidden;
}

.text-item {
  padding: 3px;
  white-space: pre-wrap;
  overflow: hidden;
}

.link-item {
  display: grid;
  align-items: center;
  border: 1px solid rgba(49, 95, 216, .35);
  border-radius: var(--radius, 6px);
  background: var(--fill);
  padding: 7px 9px;
  overflow: hidden;
}

.link-item a {
  color: inherit;
  text-decoration: underline;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.shape {
  border: 2px solid currentColor;
  border-radius: var(--radius, 4px);
  background: var(--fill);
}

.ellipse { border-radius: 999px; }

.svg-item svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.image-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.table-item {
  background: var(--fill);
  border: 1px solid var(--line);
  border-radius: var(--radius, 6px);
  overflow: hidden;
}

.table-item table {
  width: 100%;
  height: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

.table-item td {
  border: 1px solid rgba(0,0,0,.14);
  padding: 5px;
  vertical-align: top;
  min-width: 36px;
  outline: none;
}

.resize-handle {
  position: absolute;
  width: 9px;
  height: 9px;
  border: 1px solid #fff;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 1px var(--accent);
  z-index: 3;
}

.resize-handle[data-dir="nw"] { left: -7px; top: -7px; cursor: nwse-resize; }
.resize-handle[data-dir="n"] { left: calc(50% - 5px); top: -7px; cursor: ns-resize; }
.resize-handle[data-dir="ne"] { right: -7px; top: -7px; cursor: nesw-resize; }
.resize-handle[data-dir="e"] { right: -7px; top: calc(50% - 5px); cursor: ew-resize; }
.resize-handle[data-dir="se"] { right: -7px; bottom: -7px; cursor: nwse-resize; }
.resize-handle[data-dir="s"] { left: calc(50% - 5px); bottom: -7px; cursor: ns-resize; }
.resize-handle[data-dir="sw"] { left: -7px; bottom: -7px; cursor: nesw-resize; }
.resize-handle[data-dir="w"] { left: -7px; top: calc(50% - 5px); cursor: ew-resize; }

.zoom-badge, .drop-hint {
  position: absolute;
  padding: 4px 7px;
  background: rgba(255,255,255,.9);
  border: 1px solid var(--line);
  border-radius: 6px;
}

.zoom-badge { right: 10px; bottom: 10px; }
.drop-hint { left: 10px; bottom: 10px; color: var(--muted); opacity: .78; }

.remote-cursor {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  color: #fff;
  background: #111827;
  border-radius: 12px;
  padding: 2px 6px;
  transform: translate(8px, 8px);
}

.remote-cursor::before {
  content: "";
  position: absolute;
  left: -6px;
  top: -6px;
  border: 6px solid transparent;
  border-right-color: #111827;
  transform: rotate(45deg);
}

.admin-section {
  min-height: 0;
  overflow: auto;
  padding: 14px;
}

.admin-card {
  max-width: 820px;
}

.admin-form {
  display: grid;
  grid-template-columns: 1fr 190px 1.2fr 160px;
  gap: 8px;
  align-items: end;
}

.roles-box {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 0;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.roles-box legend {
  color: var(--muted);
  padding: 0 4px;
}

.roles-box label {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  color: var(--text);
}

.roles-box input {
  width: auto;
}

.users-list {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.user-row {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px;
  display: grid;
  gap: 5px;
}

.admin-users .user-row {
  grid-template-columns: 1fr 1.3fr 1fr 150px;
  align-items: center;
}

.password-pill {
  font-family: Consolas, monospace;
  background: #f3f5f8;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 5px 7px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.readonly .sidebar button:not(#undoBtn):not(#redoBtn),
.readonly .sidebar input,
.readonly .sidebar select,
.readonly .sidebar textarea {
  pointer-events: none;
  opacity: .55;
}

.error { color: var(--danger); min-height: 16px; }
.success { color: #1f7a3d; word-break: break-all; }
