/* Доска v0.1 — design tokens */
:root {
  --bg: #0F1115;
  --bg-host: #161922;
  --bg-card: #1d2230;
  --bg-card-hover: #252b3d;
  --border: #2c3346;
  --text-primary: #e6e8ee;
  --text-muted: #8a91a3;
  --accent: #7c9cff;
  --accent-soft: #2a3460;
  --done: #6c757d;
  --danger: #ff6b6b;
  --success: #5cd6a7;

  --radius-card: 12px;
  --radius-btn: 6px;
  --header-h: 32px;
  --pad: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  overflow: hidden;
}

button {
  font: inherit;
  color: inherit;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 6px 12px;
  cursor: pointer;
  transition: background 120ms, border-color 120ms;
}
button:hover { background: var(--bg-card-hover); border-color: var(--accent); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.primary { background: var(--accent); color: #0a0d14; border-color: var(--accent); font-weight: 600; }
button.primary:hover { background: #9ab3ff; border-color: #9ab3ff; }
button.danger { color: var(--danger); }
button.danger:hover { background: rgba(255,107,107,0.1); border-color: var(--danger); }

input, textarea {
  font: inherit;
  color: var(--text-primary);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 6px 10px;
  outline: none;
  transition: border-color 120ms;
}
input:focus, textarea:focus { border-color: var(--accent); }
input[type="checkbox"] { accent-color: var(--accent); }

/* ====== Auth ====== */
.auth-shell {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100vh;
  padding: 24px;
}
.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 32px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}
.auth-card h1 {
  margin: 0 0 4px 0;
  font-size: 22px;
  font-weight: 600;
}
.auth-card p.subtitle {
  margin: 0 0 24px 0;
  color: var(--text-muted);
  font-size: 13px;
}
.auth-form { display: flex; flex-direction: column; gap: 12px; }
.auth-form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); }
.auth-form .row { display: flex; gap: 8px; align-items: center; }
.auth-form .row button { flex: 1; }
.auth-switch {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
}
.auth-switch a { color: var(--accent); cursor: pointer; text-decoration: none; }
.auth-switch a:hover { text-decoration: underline; }
.auth-error {
  margin-top: 8px;
  padding: 8px 10px;
  background: rgba(255,107,107,0.1);
  border: 1px solid var(--danger);
  border-radius: var(--radius-btn);
  color: var(--danger);
  font-size: 12px;
}

/* ====== App shell ====== */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100vh;
  background: var(--bg);
}
.app-header {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 48px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-host);
  gap: 16px;
  flex-shrink: 0;
  z-index: 10;
}
.app-header .brand { font-weight: 600; font-size: 15px; }
.app-header .grow { flex: 1; }
.app-header .user { font-size: 12px; color: var(--text-muted); }
.app-header .user strong { color: var(--text-primary); font-weight: 500; }

.dropdown {
  position: absolute;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  min-width: 200px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  z-index: 100;
  padding: 4px;
}
.dropdown__item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
}
.dropdown__item:hover { background: var(--bg-card-hover); }

.toasts {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-btn);
  padding: 10px 14px;
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4);
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn 200ms ease;
}
.toast--error { border-color: var(--danger); color: var(--danger); }
.toast--info { border-color: var(--accent); }
.toast__close { cursor: pointer; opacity: 0.6; }
.toast__close:hover { opacity: 1; }
@keyframes slideIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ====== Canvas ====== */
.app-main {
  flex: 1;
  position: relative;
  overflow: hidden;
}
.app-main--canvas { background: var(--bg); }
.canvas-host {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background-image: radial-gradient(circle, var(--border) 0.8px, transparent 0.8px);
  background-size: 24px 24px;
  background-position: 0 0;
  cursor: default;
}
.canvas-host[data-show-grid="false"] {
  background-image: none;
}
.canvas-world {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  transform-origin: 0 0;
  pointer-events: none;
  background-image: radial-gradient(circle, var(--border) 0.8px, transparent 0.8px);
  background-size: 24px 24px;
  background-position: 0 0;
  image-rendering: optimizeQuality;
}
.canvas-world * {
  text-rendering: geometricPrecision;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  /* GPU-слой на виджетах вызывал ghosting при drag фото. Отключаем. */
  /* transform: translateZ(0); */
}
.canvas-world > .widget {
  /* На самом виджете GPU-ускоряем только когда активно двигаем — иначе оставляем CPU */
  will-change: auto;
}
.canvas-world > .widget.dragging,
.canvas-world > .widget.resizing {
  will-change: transform;
  transform: translateZ(0);
}
.canvas-world[data-show-grid="false"] {
  background-image: none;
}
.canvas-world > .widget {
  pointer-events: auto;
}

.canvas-hint {
  position: absolute;
  bottom: 12px;
  left: 12px;
  font-size: 11px;
  color: var(--text-muted);
  pointer-events: none;
  opacity: 0.7;
  z-index: 5;
}

/* ====== Widgets ====== */
.widget {
  position: absolute;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  user-select: none;
  transition: box-shadow 120ms, border-color 120ms;
  /* GPU-слой убран — вызывал ghosting при drag фото. */
  /* Теперь transform: translate() для drag создаст GPU-слой естественно. */
}
.widget.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft), 0 4px 16px rgba(0,0,0,0.4); }
.widget__header {
  display: flex;
  align-items: center;
  background: var(--bg-card-hover);
  padding: 0 8px 0 var(--pad);
  height: var(--header-h);
  flex-shrink: 0;
  cursor: grab;
  border-bottom: 1px solid var(--border);
}
.widget__header:active { cursor: grabbing; }
.widget__icon { font-size: 14px; color: var(--text-muted); margin-right: 8px; }
.widget__title {
  flex: 1;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.widget__title[contenteditable="true"] {
  outline: none;
  background: var(--bg);
  border-radius: 3px;
  padding: 2px 4px;
}
.widget__delete {
  background: none;
  border: none;
  font-size: 18px;
  width: 24px;
  height: 24px;
  border-radius: 3px;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.widget__delete:hover { color: var(--danger); background: rgba(255,107,107,0.1); }

.widget__body {
  flex: 1;
  overflow: auto;
  padding: var(--pad);
}

.widget__resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  background:
    linear-gradient(135deg, transparent 50%, var(--text-muted) 50%, var(--text-muted) 60%, transparent 60%, transparent 70%, var(--text-muted) 70%, var(--text-muted) 80%, transparent 80%);
  opacity: 0.5;
}
.widget__resize:hover { opacity: 0.9; }

/* ----- Checklist / Todo items ----- */
.item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.item:last-child { border-bottom: none; }
.item__check {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  cursor: pointer;
}
.item__text {
  flex: 1;
  font-size: 13px;
  outline: none;
  border-radius: 3px;
  padding: 2px 4px;
  cursor: text;
}
.item__text:focus { background: var(--bg); }
.item--done .item__text { text-decoration: line-through; color: var(--done); }
.item__delete {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0 4px;
  cursor: pointer;
  font-size: 14px;
  opacity: 0;
  transition: opacity 120ms;
}
.item:hover .item__delete { opacity: 1; }
.item__delete:hover { color: var(--danger); }

.item-add {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.item-add input { flex: 1; }

/* ----- Todo priority ----- */
.priority {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 4px;
  flex-shrink: 0;
}
.priority-0 { background: var(--text-muted); }
.priority-1 { background: var(--accent); }
.priority-2 { background: #ffa14a; }
.priority-3 { background: var(--danger); }

.due {
  font-size: 11px;
  color: var(--text-muted);
  margin-right: 4px;
}

/* ----- Scheduler columns ----- */
.scheduler {
  display: flex;
  gap: 8px;
  height: 100%;
}
.scheduler__col {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.scheduler__col-header {
  font-size: 11px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-align: center;
  letter-spacing: 0.5px;
}
.scheduler__list {
  flex: 1;
  overflow: auto;
  min-height: 0;
}

/* ----- Counter ----- */
.counter {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  gap: 12px;
}
.counter__value {
  font-size: 48px;
  font-weight: 200;
  font-variant-numeric: tabular-nums;
}
.counter__row {
  display: flex;
  gap: 8px;
}
.counter__row button {
  width: 36px;
  height: 36px;
  font-size: 18px;
  padding: 0;
}
.counter__name {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  margin-top: 4px;
}
.counter__edit {
  font-size: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  text-decoration: underline;
}
.counter__edit:hover { color: var(--accent); }

/* ====== Misc ====== */
.modal-bg {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 20px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
}
.modal h3 { margin: 0 0 12px 0; font-size: 15px; }
.modal .form { display: flex; flex-direction: column; gap: 8px; }
.modal .form label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); }
.modal .actions { display: flex; gap: 8px; margin-top: 12px; justify-content: flex-end; }


/* === MOBILE (≤768px) — public board === */
@media (max-width: 768px) {
  .public-board .app-header {
    flex-wrap: wrap;
    padding: 6px 8px;
    gap: 4px;
  }
  .public-board .app-header button[title="Вверх"],
  .public-board .app-header button[title="Вниз"],
  .public-board .app-header button[title="Влево"],
  .public-board .app-header button[title="Вправо"] {
    display: none;
  }
  .public-board .app-header button {
    min-width: 36px;
    min-height: 32px;
    padding: 4px 6px !important;
    font-size: 14px !important;
  }
  .canvas-host {
    touch-action: pan-x pan-y;
  }
}
@media (max-width: 480px) {
  .public-board .app-header {
    padding: 4px;
  }
  .public-board .app-header button {
    min-width: 32px;
    min-height: 30px;
    font-size: 13px !important;
  }
}

/* === MOBILE (≤768px) === */
@media (max-width: 768px) {
  /* Header: показать только brand + burger + ws indicator */
  .app-header {
    flex-wrap: wrap;
    padding: 6px 8px;
    gap: 6px;
    position: relative;
  }
  .app-header .burger-btn {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 36px;
  }
  /* Скрываем desktop-only элементы */
  .app-header .add-group,
  .app-header .nav-wrap,
  .app-header .share-btn,
  .app-header .user,
  .app-header .logout-btn {
    display: none !important;
  }
  /* Ws indicator виден, но компактный */
  .app-header .ws-indicator {
    font-size: 10px;
    min-width: auto;
    margin-left: auto;
  }
  .app-header .brand {
    font-size: 16px;
    flex: 1;
  }
  /* Mobile menu — relative positioning работает через .app-header position:relative */
  .mobile-menu {
    display: none; /* toggled via JS */
  }

  /* Canvas */
  .canvas-host {
    touch-action: pan-x pan-y;
  }
  /* Виджеты */
  .widget {
    min-width: 180px;
    min-height: 120px;
  }
  .widget__resize {
    width: 32px !important;
    height: 32px !important;
    bottom: -8px;
    right: -8px;
    background: var(--accent) !important;
    opacity: 0.7;
  }
  .widget__delete {
    width: 32px !important;
    height: 32px !important;
    font-size: 18px !important;
  }
  .widget__extra-btn {
    width: 32px !important;
    height: 32px !important;
    font-size: 16px !important;
  }
  .widget__header {
    min-height: 44px; /* тач-удобный */
    padding: 6px 10px;
  }
  .widget__title {
    font-size: 14px;
  }
  .context-menu button {
    padding: 12px 16px !important;
    font-size: 14px !important;
    min-height: 44px;
  }
  .checklist-item__text, .todo-item__text {
    font-size: 14px;
    min-height: 32px;
  }
  /* Auth form */
  .auth-card {
    max-width: 95vw;
  }
}

@media (max-width: 480px) {
  .app-header button {
    padding: 5px 8px !important;
    font-size: 11px !important;
    min-height: 30px;
  }
  .app-header .brand {
    font-size: 13px;
  }
  .widget {
    min-width: 150px;
  }
}
