* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: #222;
  background: #fafafa;
}

button {
  font: inherit;
  cursor: pointer;
}

/* ============================================================
   LOGIN
   ============================================================ */

body.login-page {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #f5f7fa 0%, #e4e8ed 100%);
}

.login-card {
  background: white;
  padding: 32px;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-card h1 {
  font-size: 20px;
  margin-bottom: 6px;
  text-align: center;
}

.login-card input {
  padding: 10px 12px;
  font-size: 15px;
  border: 1px solid #ddd;
  border-radius: 6px;
  outline: none;
}

.login-card input:focus { border-color: #4a90e2; }

.login-card button {
  padding: 10px;
  font-size: 15px;
  background: #4a90e2;
  color: white;
  border: none;
  border-radius: 6px;
}

.login-card button:hover { background: #3a7fd1; }

.login-error {
  color: #d33;
  font-size: 13px;
  text-align: center;
  min-height: 18px;
}

/* ============================================================
   BOARDS LIST
   ============================================================ */

body.boards-page {
  height: 100vh;
  overflow: auto;
}

.boards-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 32px;
  border-bottom: 1px solid #eaeaea;
  background: white;
  position: sticky;
  top: 0;
  z-index: 10;
}

.boards-header h1 {
  font-size: 22px;
  font-weight: 600;
}

.boards-actions {
  display: flex;
  gap: 8px;
}

.boards-actions button {
  padding: 8px 14px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: white;
  font-size: 14px;
}

.boards-actions button:hover { background: #f5f5f5; }

.boards-actions button.primary {
  background: #4a90e2;
  color: white;
  border-color: #4a90e2;
}

.boards-actions button.primary:hover { background: #3a7fd1; }

.boards-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
  padding: 24px 32px;
}

.empty {
  grid-column: 1 / -1;
  text-align: center;
  color: #999;
  padding: 60px 0;
  font-size: 15px;
}

.board-tile {
  background: white;
  border: 1px solid #e5e5e5;
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  transition: box-shadow 0.15s, transform 0.15s;
}

.board-tile:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.board-tile-link {
  display: block;
  padding: 18px 16px 16px;
  text-decoration: none;
  color: inherit;
  min-height: 100px;
}

.board-tile-name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 6px;
  word-break: break-word;
}

.board-tile-date {
  color: #888;
  font-size: 12px;
}

.board-tile-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 4px;
  opacity: 0;
  transition: opacity 0.15s;
}

.board-tile:hover .board-tile-actions { opacity: 1; }

.board-tile-actions button {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.95);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-tile-actions button:hover { background: #f0f0f0; }
.board-tile-actions .delete:hover { background: #ffe5e5; color: #c33; }

/* ============================================================
   BOARD (canvas)
   ============================================================ */

body.board-page {
  overflow: hidden;
  height: 100vh;
  --board-bg: #fafafa;
  --board-dot: #d6d6d6;
  --board-dot-size: 24px;
}

/* Toolbar */

.toolbar {
  position: fixed;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 100;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(6px);
  padding: 8px 12px;
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.toolbar-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 6px;
  text-decoration: none;
  color: #555;
  font-size: 18px;
}

.toolbar-link:hover { background: #f0f0f0; }

.toolbar-sep {
  width: 1px;
  height: 22px;
  background: #e5e5e5;
  margin: 0 4px;
}

.board-title {
  font-weight: 600;
  font-size: 14px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 0 6px;
}

.toolbar button {
  padding: 6px 10px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: white;
  font-size: 13px;
  transition: background 0.15s;
}

.toolbar button:hover { background: #f5f5f5; }

.hint {
  color: #999;
  font-size: 11px;
  margin-left: 8px;
  border-left: 1px solid #eee;
  padding-left: 8px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.save-state {
  color: #888;
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
  background: #f5f5f5;
}

.save-state[data-state="ok"]      { color: #2a8; background: #e8f5ee; }
.save-state[data-state="pending"] { color: #c80; background: #fff4d6; }

/* Inspector — floating bar for selection */

.inspector {
  position: fixed;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 99;
  background: white;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  padding: 6px;
  display: flex;
  gap: 4px;
  align-items: center;
}

.inspector[hidden] { display: none; }

.ibtn {
  height: 30px;
  min-width: 30px;
  padding: 0 8px;
  border: none;
  background: transparent;
  border-radius: 5px;
  font-size: 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  position: relative;
}

.ibtn:hover { background: #f2f2f2; }
.ibtn.active { background: #e6f0fb; color: #1e6cb4; }

.ibtn-sep {
  width: 1px;
  height: 20px;
  background: #e5e5e5;
  margin: 0 2px;
}

.ibtn-num {
  min-width: 30px;
  text-align: center;
  font-size: 13px;
  color: #555;
  user-select: none;
}

.ibtn-step { font-size: 16px; padding: 0 6px; }

.ibtn .swatch {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(0,0,0,0.1);
  background: #fff2a8;
}

.ibtn-fontcolor { position: relative; }
.ibtn-fontcolor .under {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  width: 14px;
  height: 3px;
  border-radius: 2px;
  background: #222;
}

.ins-text-only { display: flex; gap: 4px; align-items: center; }

/* Popover (palettes, font picker, emoji picker) */

.popover {
  position: fixed;
  z-index: 200;
  background: white;
  border: 1px solid #e5e5e5;
  border-radius: 8px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.16);
  padding: 10px;
  min-width: 180px;
  max-width: 380px;
}

.popover[hidden] { display: none; }

.popover h4 {
  font-size: 12px;
  font-weight: 600;
  color: #666;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}

.color-cell {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.1);
  cursor: pointer;
  transition: transform 0.1s;
  position: relative;
}

.color-cell:hover { transform: scale(1.1); }
.color-cell.selected { box-shadow: 0 0 0 2px #4a90e2; }
.color-cell.transparent {
  background: white;
  background-image:
    linear-gradient(45deg, #ddd 25%, transparent 25%),
    linear-gradient(-45deg, #ddd 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #ddd 75%),
    linear-gradient(-45deg, transparent 75%, #ddd 75%);
  background-size: 8px 8px;
  background-position: 0 0, 0 4px, 4px -4px, -4px 0;
}

.font-list { display: flex; flex-direction: column; gap: 2px; }

.font-item {
  padding: 8px 10px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.1s;
}

.font-item:hover { background: #f3f3f3; }
.font-item.selected { background: #e6f0fb; }

.popover.bg-picker { width: 340px; max-width: 92vw; }

.bg-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 4px;
}

.bg-cell {
  height: 50px;
  border-radius: 8px;
  border: 1px solid rgba(0,0,0,0.08);
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: transform 0.1s, box-shadow 0.15s;
  padding: 0;
}

.bg-cell:hover { transform: scale(1.04); box-shadow: 0 2px 6px rgba(0,0,0,0.1); }
.bg-cell.selected { box-shadow: 0 0 0 2px #4a90e2; }

.bg-custom-sep {
  height: 1px;
  background: #eee;
  margin: 10px 0 8px;
}

.bg-custom {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bg-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}

.bg-row-label {
  flex: 0 0 100px;
  color: #555;
}

.bg-seg {
  display: inline-flex;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  overflow: hidden;
}

.bg-seg button {
  padding: 4px 10px;
  border: none;
  background: white;
  font-size: 12px;
  cursor: pointer;
  border-right: 1px solid #e0e0e0;
  color: #444;
}

.bg-seg button:last-child { border-right: none; }
.bg-seg button:hover     { background: #f4f4f4; }
.bg-seg button.active    { background: #e6f0fb; color: #1e6cb4; }

.bg-color-input {
  width: 40px;
  height: 26px;
  padding: 0;
  border: 1px solid #ddd;
  border-radius: 5px;
  cursor: pointer;
  background: none;
}
.bg-color-input::-webkit-color-swatch-wrapper { padding: 2px; }
.bg-color-input::-webkit-color-swatch         { border: none; border-radius: 3px; }

.bg-alpha {
  flex: 1;
  height: 4px;
  cursor: pointer;
}

.bg-alpha-val {
  flex: 0 0 36px;
  text-align: right;
  font-size: 12px;
  color: #777;
  font-variant-numeric: tabular-nums;
}

.bg-img-btn,
.bg-img-clear {
  padding: 4px 10px;
  border: 1px solid #e0e0e0;
  border-radius: 6px;
  background: white;
  font-size: 12px;
  color: #444;
  cursor: pointer;
}

.bg-img-btn:hover { background: #f4f4f4; }
.bg-img-clear:hover { background: #ffe5e5; color: #c33; }

/* Emoji picker */

.emoji-picker { max-height: 320px; overflow-y: auto; min-width: 260px; max-width: 320px; }

.emoji-cat { margin-bottom: 4px; }
.emoji-cat-title {
  font-size: 11px;
  font-weight: 600;
  color: #888;
  text-transform: uppercase;
  margin: 6px 4px 4px;
  letter-spacing: 0.05em;
}

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}

.emoji-cell {
  width: 32px;
  height: 32px;
  border-radius: 5px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.emoji-cell:hover { background: #f0f0f0; }

/* Status toast */

.status {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.78);
  color: white;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  z-index: 200;
  transition: opacity 0.3s;
}

.status.hidden { opacity: 0; pointer-events: none; }

/* Board surface */

.board {
  width: 100vw;
  height: 100vh;
  overflow: hidden;
  cursor: grab;
  position: relative;
  background-color: #fafafa;
  /* Конкретный фон ставится из JS через inline-style. */
}

.board.panning { cursor: grabbing; }

.viewport {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
  width: 0;
  height: 0;
  will-change: transform;
}

/* Cards */

.card {
  position: absolute;
  border-radius: 8px;
  cursor: move;
  user-select: none;
  transition: box-shadow 0.15s;
}

.card.locked { cursor: default; }
.card.locked .resize-handle { display: none !important; }

.card.locked::after {
  content: "🔒";
  position: absolute;
  top: 4px;
  left: 4px;
  font-size: 10px;
  opacity: 0.55;
  pointer-events: none;
}

.card.image-card {
  background: white;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
  overflow: hidden;
}

.card.image-card img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  border-radius: 8px;
}

.card.text-card {
  background: #fff2a8;
  padding: 14px 16px;
  min-width: 120px;
  min-height: 60px;
  font-size: 14px;
  line-height: 1.4;
  color: #222;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12), 0 1px 0 rgba(0, 0, 0, 0.04);
  white-space: pre-wrap;
  word-wrap: break-word;
  overflow: hidden;
}

.card.emoji-card {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  box-shadow: none;
  overflow: hidden;
  line-height: 1;
  text-align: center;
  user-select: none;
}

.card.selected {
  box-shadow: 0 0 0 2px #4a90e2, 0 4px 14px rgba(0, 0, 0, 0.18);
}
.card.emoji-card.selected { box-shadow: 0 0 0 2px #4a90e2; }

.card[contenteditable="true"] {
  cursor: text;
  user-select: text;
  outline: 2px solid #4a90e2;
  outline-offset: -2px;
}

.card .resize-handle {
  position: absolute;
  bottom: -4px;
  right: -4px;
  width: 14px;
  height: 14px;
  background: #4a90e2;
  border: 2px solid white;
  border-radius: 3px;
  cursor: nwse-resize;
  display: none;
}

.card.selected .resize-handle { display: block; }
