/* ── Reset & Base ─────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #ebebeb;
  --card: #ffffff;
  --border: #e0e0e0;
  --text: #1a1a1a;
  --muted: #888;
  --danger: #e17055;
  --success: #00b894;
  --radius: 8px;
}

/* ── Full-screen overlay (login) ──────────────────────────── */
.full-screen-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
.full-screen-overlay.hidden {
  display: none;
}
.startup-message {
  text-align: center;
  color: var(--muted);
}
.startup-message button {
  margin-top: 16px;
}

#screen-login {
  padding: 24px 16px 48px;
  overflow-y: auto;
  align-items: flex-start;
}
.login-stack {
  width: 360px;
  max-width: 100%;
  margin: auto;
  flex-shrink: 0;
}
.login-card {
  background: var(--card);
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.1);
}
.login-brand-image {
  display: block;
  width: 440px;
  max-width: calc(100vw - 32px);
  height: auto;
  margin: -48px auto -36px;
  position: relative;
  left: 50%;
  transform: translateX(-50%);
}

.login-logo {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  margin-bottom: 28px;
  text-align: center;
}
.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 10px;
  padding: 8px 12px;
  background: #fdf0ee;
  border-radius: 6px;
}
.btn-full {
  width: 100%;
  margin-top: 4px;
}

/* ── Projects screen ──────────────────────────────────────── */
.projects-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.projects-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}
.projects-title {
  font-size: 18px;
  font-weight: 700;
}
.projects-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
}
.projects-empty {
  color: var(--muted);
  font-size: 14px;
  grid-column: 1 / -1;
}
.project-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 0;
  cursor: pointer;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  transition:
    box-shadow 0.15s,
    transform 0.15s;
  display: flex;
  flex-direction: column;
}
.project-card:hover {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  transform: translateY(-2px);
}
.project-card-thumb {
  width: 100%;
  aspect-ratio: 1/1;
  object-fit: cover;
  display: block;
  image-rendering: pixelated;
}
.project-card-thumb-empty {
  background: #e8e8e8;
}
.project-card-body {
  padding: 12px 14px 10px;
  flex: 1;
}
.project-card-name {
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 4px;
}
.project-card-meta {
  font-size: 12px;
  color: var(--muted);
}
.project-card-actions {
  display: flex;
  gap: 4px;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
  opacity: 0;
  transition: opacity 0.12s;
}
.project-card:hover .project-card-actions {
  opacity: 1;
}
.project-action-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 14px;
  padding: 3px 6px;
  border-radius: 4px;
  line-height: 1;
}
.project-action-btn:hover {
  background: #f0f0f0;
}
.project-action-danger:hover {
  background: #fdf0ee;
}
.project-delete-btn {
  display: none;
}

/* ── Admin panel ──────────────────────────────────────────── */
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
}
.admin-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: #f8f8f8;
}
.admin-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.admin-table tr:last-child td {
  border-bottom: none;
}
.role-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}
.role-admin {
  background: #e8f0ff;
  color: #3b5bdb;
}
.role-user {
  background: #e8f5e9;
  color: #2e7d32;
}
.btn-danger-sm {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}
.btn-danger-sm:hover {
  background: #fdf0ee;
}

/* ── Header additions ─────────────────────────────────────── */
.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  color: var(--text);
  font-family: inherit;
  font-weight: 500;
}
.btn-ghost:hover {
  background: #f0f0f0;
}
.user-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 50%;
  cursor: pointer;
  padding: 0;
}
.project-name-badge {
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  padding: 0 4px;
}

body {
  font-family:
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  font-size: 14px;
}

/* ── Header ───────────────────────────────────────────────── */
.app-header {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  height: 52px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  flex-shrink: 0;
  z-index: 10;
}

.app-title {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.3px;
}

.view-tabs {
  display: flex;
  gap: 2px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: auto;
}

.tab-btn {
  padding: 6px 14px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
  transition:
    background 0.12s,
    color 0.12s;
}
.tab-btn:hover {
  background: #f0f0f0;
  color: var(--text);
}
.tab-btn.active {
  background: var(--text);
  color: #fff;
}

/* ── Main layout ──────────────────────────────────────────── */
.app-main {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.view {
  height: 100%;
  overflow-y: auto;
  padding: 20px;
}

#view-board:not(.hidden) {
  overflow-x: auto;
  overflow-y: auto;
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 16px;
  padding-bottom: 20px;
}

#view-todo:not(.hidden) {
  overflow-x: auto;
  overflow-y: hidden;
  display: block;
  padding-bottom: 20px;
}

.view.hidden {
  display: none;
}

.hidden {
  display: none !important;
}

.board-view-shell {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 100%;
}

.board-filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 2px 0;
}

.board-filter-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.board-filter-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.7);
  border: 1px solid var(--border);
  cursor: pointer;
  user-select: none;
}

.board-filter-check input {
  margin: 0;
}

.board-filter-check.all {
  font-weight: 600;
}

.board-columns {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 16px;
  min-width: 100%;
}

/* ── Board view ───────────────────────────────────────────── */
.board-section {
  flex-shrink: 0;
  width: 220px;
  background: #e0e0e0;
  border-radius: var(--radius);
  padding: 10px;
  height: 90vh;
  overflow-y: scroll;
}

.board-section.dragging-section {
  opacity: 0.55;
}

.board-section.drag-over {
  box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.18);
}

.board-section-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  padding-left: 4px;
  cursor: grab;
  user-select: none;
}

.board-section-header:active {
  cursor: grabbing;
}

.board-section-drag-handle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: -1px;
  background: rgba(255, 255, 255, 0.5);
}

.board-section-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.board-section-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--muted);
}

.board-section-count {
  font-size: 11px;
  color: var(--muted);
  background: #e8e8e8;
  padding: 1px 7px;
  border-radius: 10px;
  font-weight: 600;
}

.board-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.board-card {
  background: var(--card);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  border-top: 3px solid var(--accent, #888);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
  position: relative;
  transition:
    box-shadow 0.15s,
    transform 0.15s;
  display: grid;
  grid-template-columns: 5rem auto;
  align-items: center;
}
.board-card img {
  -webkit-user-drag: none;
  user-select: none;
}
.board-card:hover {
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.12);
  transform: translateY(-2px);
}
.board-card.dragging {
  opacity: 0.4;
  transform: scale(0.97);
}
.board-cards.drag-over {
  background: rgba(0, 0, 0, 0.04);
  border-radius: var(--radius);
}

.card-thumb {
  width: 100%;
  max-height: 5rem;
  object-fit: cover;
  object-position: center center;
  display: block;
  image-rendering: pixelated;
}

.board-card-body {
  padding: 10px 12px 12px;
  align-self: end;
}

.board-card-body:only-child {
  grid-column: 1 / -1;
}

.board-card-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 5px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.board-card-meta {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
}

.badge-placeholder {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  background: #e0e0e0;
  color: #666;
}

.backlink-badge {
  font-size: 10px;
  color: var(--muted);
  margin-left: auto;
}

/* ── User avatars ──────────────────────────────────── */
.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  border: 2px solid rgba(255, 255, 255, 0.8);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.18);
  vertical-align: middle;
  overflow: hidden;
  user-select: none;
  letter-spacing: 0;
}
img.user-avatar {
  object-fit: cover;
  font-size: 0;
}
.card-editor-overlay {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  pointer-events: none;
  line-height: 0;
}

/* ── Profile modal ──────────────────────────────── */
.profile-avatar-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 24px 0 12px;
}
.profile-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.profile-avatar-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

/* ── Detail side panel ────────────────────────────────────── */
.side-panel {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  justify-content: flex-end;
}
.side-panel.hidden {
  display: none;
}

.side-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  cursor: pointer;
}

.side-content {
  position: relative;
  z-index: 1;
  background: var(--bg);
  width: min(92vw, 1100px);
  height: 100%;
  overflow-y: auto;
  padding: 20px;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ── Detail content ───────────────────────────────────────── */
.detail-header {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.detail-header-left {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.detail-title {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
}

.detail-badges {
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge-template {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #fff;
}

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

.detail-sections {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-start;
}

.detail-section {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  flex: 1;
  min-width: 150px;
  max-width: 260px;
}

.detail-section:has(.field-bullets),
.detail-section:has(.field-rich-text) {
  flex: 2;
  max-width: 400px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 4px;
}

.section-subtitle {
  font-size: 11px;
  color: var(--muted);
  text-align: center;
  margin-bottom: 12px;
}

.section-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Field rendering ──────────────────────────────────────── */
.field-row {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  font-size: 13px;
  flex-wrap: wrap;
}

.field-label {
  font-weight: 600;
  color: #555;
  flex-shrink: 0;
}
.field-value {
  color: var(--text);
}
.field-bullets {
  margin: 2px 0 0 0;
  padding-left: 18px;
  color: var(--text);
  font-size: 13px;
  line-height: 1.6;
}
.field-value-empty {
  color: #ccc;
  font-style: italic;
}

.field-rich-text {
  font-size: 13px;
  color: #333;
  line-height: 1.55;
}

.field-image {
  width: 100%;
}
.field-img {
  width: 100%;
  border-radius: 6px;
  object-fit: cover;
  display: block;
  image-rendering: pixelated;
}

.field-loot {
  font-style: italic;
  color: #555;
}

/* Reference chips */
.ref-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  background: #f5f5f5;
  border-left: 3px solid var(--accent, #888);
  border-radius: 4px;
  padding: 7px 10px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s;
}
.ref-chip:hover {
  background: #eee;
}

.ref-chip-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.ref-chip-name {
  font-weight: 600;
}
.ref-chip-rel {
  margin-left: auto;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

/* Inline reference (inside field-row) */
.ref-chip-inline {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: #f0f0f0;
  border-radius: 4px;
  padding: 2px 8px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  border-left: 3px solid var(--accent, #888);
}
.ref-chip-inline:hover {
  background: #e8e8e8;
}

/* Recipe grid */
.field-recipe {
  margin-top: 2px;
}
.recipe-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
  text-align: center;
}
.recipe-grid {
  border-collapse: collapse;
  width: 100%;
}
.recipe-grid td {
  border: 1px solid var(--border);
  padding: 5px 8px;
  font-size: 12px;
  text-align: center;
  background: #fafafa;
  min-width: 44px;
}

/* Checkbox list */
.field-checklist {
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.checklist-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
}

/* Checkbox-list editor (form) */
.checklist-editor {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 6px;
}
.checklist-edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.checklist-edit-label {
  flex: 1;
}
.checklist-add-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.checklist-add-input {
  flex: 1;
  font-size: 13px;
}

/* ── Todo view ────────────────────────────────────────────── */
/* ── Todo / Kanban board ──────────────────────────────────── */
.todo-board {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  height: 100%;
  overflow-x: auto;
  padding-bottom: 16px;
}

.todo-col {
  flex: 0 0 220px;
  background: #f0f0f3;
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 120px);
  transition:
    box-shadow 0.15s,
    transform 0.15s,
    outline-color 0.15s;
}

.todo-col.drag-over {
  outline: 2px solid rgba(0, 0, 0, 0.08);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.todo-col-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px 8px;
  border-bottom: 1px solid var(--border);
}

.todo-col-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}

.todo-col-count {
  font-size: 11px;
  font-weight: 700;
  background: #ddd;
  border-radius: 10px;
  padding: 1px 7px;
  color: #666;
}

.todo-col-cards {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.todo-card {
  background: var(--card);
  border-radius: 8px;
  padding: 10px 12px;
  border-left: 3px solid var(--accent, #ccc);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  cursor: grab;
}

.todo-card.dragging {
  opacity: 0.45;
}

.todo-card-thumb-wrap {
  width: 100%;
  max-width: 120px;
  margin: 2px auto 8px;
  border-radius: 6px;
  overflow: hidden;
  background: #f7f7f8;
}

.todo-card-thumb-wrap .card-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: contain;
  object-position: center center;
  max-height: 120px;
  aspect-ratio: 1/1;
}

.todo-card-top {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin-bottom: 8px;
}

.todo-card-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}

.todo-card-name {
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  flex: 1;
  line-height: 1.35;
}
.todo-card-name:hover {
  text-decoration: underline;
}

.todo-checklist {
  list-style: none;
  margin: 0 0 8px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.todo-section-checklist {
  list-style: none;
  margin: 0 0 8px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.todo-check-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  transition: background 0.1s;
}
.todo-check-item:hover {
  background: #f5f5f5;
}
.todo-check-item.checked .todo-check-label {
  text-decoration: line-through;
  color: var(--muted);
}

.todo-check-box {
  width: 14px;
  height: 14px;
  border: 1.5px solid #ccc;
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  flex-shrink: 0;
  color: #00897b;
}
.todo-check-item.checked .todo-check-box {
  background: #d4f5e9;
  border-color: #00897b;
}

.todo-section-item {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  padding: 2px 4px;
  border-radius: 4px;
  background: #f7f7f8;
}
.todo-section-item.checked .todo-check-label {
  text-decoration: line-through;
  color: var(--muted);
}

.todo-section-item .todo-check-box {
  border-color: #bbb;
}
.todo-section-item.checked .todo-check-box {
  background: #d4f5e9;
  border-color: #00897b;
}

.todo-progress-bar {
  height: 3px;
  background: #eee;
  border-radius: 2px;
  margin-bottom: 8px;
  overflow: hidden;
}
.todo-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.3s;
}

.todo-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin-top: 4px;
}

.todo-assignees {
  display: flex;
  gap: 3px;
  cursor: pointer;
  flex-wrap: wrap;
}

.todo-unassigned {
  font-size: 11px;
  color: var(--muted);
}

/* Assignee popup */
.assignee-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
}
.assignee-popup {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  min-width: 200px;
  max-height: 400px;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
}
.assignee-popup-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 10px;
}
.assignee-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 4px;
  cursor: pointer;
  font-size: 13px;
  border-radius: 5px;
}
.assignee-row:hover {
  background: #f5f5f5;
}

/* ── Mindmap view ─────────────────────────────────────────── */
#view-mindmap {
  padding: 0;
  position: relative;
}
.mindmap-toolbar {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 5;
}
#cy {
  width: 100%;
  height: 100%;
}
#cy canvas {
  image-rendering: pixelated;
}

/* ── Modal (create/edit form) ─────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 20px;
  overflow-y: auto;
}
.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.modal-panel {
  position: relative;
  z-index: 1;
  background: var(--card);
  border-radius: 12px;
  width: 100%;
  max-width: 580px;
  padding: 24px;
}

/* ── Forms ────────────────────────────────────────────────── */
.form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}
.form-header h2 {
  font-size: 17px;
  font-weight: 700;
}

.form-group {
  margin-bottom: 14px;
}
.form-group > label:first-child {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #555;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin-bottom: 5px;
}
.form-group input[type="text"],
.form-group input[type="password"],
.form-group input[type="url"],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #fff;
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--text);
}

.form-section {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 14px;
}
.form-section legend {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: #555;
  padding: 0 6px;
}

.req {
  color: var(--danger);
}

.multi-entry-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 6px;
}

.multi-entry-row {
  display: flex;
  gap: 6px;
  align-items: center;
}

.multi-entry-row input[type="text"] {
  flex: 1;
}

.multi-entry-row select {
  flex: 0 0 160px;
}

.btn-add-entry {
  font-size: 12px;
  padding: 4px 10px;
  background: transparent;
  border: 1px dashed var(--border);
  border-radius: 6px;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
}
.btn-add-entry:hover {
  background: #f0f0f0;
  color: var(--text);
}

.btn-remove-entry {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  padding: 2px 4px;
  border-radius: 4px;
  flex-shrink: 0;
}
.btn-remove-entry:hover {
  color: var(--danger);
  background: #fdf0ee;
}

.img-upload-label {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  cursor: pointer;
}

.img-upload-preview {
  width: 160px;
  height: 100px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: block;
  image-rendering: pixelated;
}

.img-upload-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
  color: var(--muted);
  font-size: 12px;
}

.img-upload-btn {
  font-size: 12px;
  padding: 4px 12px;
  background: #f0f0f0;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}
.img-upload-label:hover .img-upload-btn {
  background: #e4e4e4;
}

.img-upload-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  flex-wrap: wrap;
}

.img-paste-btn {
  font-size: 12px;
  padding: 4px 10px;
  white-space: nowrap;
  align-self: flex-end;
}

.checkbox-label {
  display: flex !important;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 400 !important;
  text-transform: none !important;
  letter-spacing: 0 !important;
  margin-bottom: 4px;
  color: var(--text) !important;
}
.checkbox-label input {
  width: auto !important;
}

.recipe-grid-edit td input {
  width: 70px;
  text-align: center;
  padding: 4px;
}

.recipe-cell-editor {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: stretch;
}

.recipe-cell-editor input,
.recipe-cell-editor select {
  width: 100%;
  min-width: 92px;
  padding: 4px 6px;
  font-size: 12px;
}

.recipe-grid-ref {
  max-width: 100%;
  justify-content: center;
  cursor: pointer;
}

.recipe-grid-missing {
  color: var(--muted);
  font-size: 11px;
}

.form-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn-primary {
  background: var(--text);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
}

/* ── Incomplete obtained FAB ──────────────────────────────── */
.incomplete-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #f39c12;
  color: #fff;
  border: none;
  font-size: 22px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  z-index: 90;
  transition:
    background 0.15s,
    transform 0.15s;
}
.incomplete-fab:hover {
  background: #e67e22;
  transform: scale(1.08);
}

.incomplete-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  line-height: 1;
}

.incomplete-panel {
  position: fixed;
  bottom: 84px;
  right: 24px;
  width: 300px;
  max-height: 400px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  z-index: 89;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.incomplete-panel.hidden {
  display: none;
}

.incomplete-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.incomplete-list {
  overflow-y: auto;
  flex: 1;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.incomplete-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s;
}
.incomplete-item:hover {
  background: var(--bg);
}

.incomplete-item-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.incomplete-item-name {
  flex: 1;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.incomplete-item-type {
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
}
.btn-primary:hover {
  background: #333;
}

.btn-secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
}
.btn-secondary:hover {
  background: #f5f5f5;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 7px 14px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
}
.btn-danger:hover {
  background: #fff5f3;
}

.btn-icon {
  background: transparent;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
  border-radius: 4px;
  line-height: 1;
  font-family: inherit;
}
.btn-icon:hover {
  background: #f0f0f0;
}

/* ── Field comment panel ──────────────────────────────────── */
.comment-backdrop {
  position: fixed;
  inset: 0;
  z-index: 149;
}
.comment-backdrop.hidden {
  display: none;
}

.comment-panel {
  position: fixed;
  right: 0;
  top: 0;
  bottom: 0;
  width: 360px;
  background: var(--card);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 150;
  box-shadow: -4px 0 24px rgba(0, 0, 0, 0.1);
}
.comment-panel.hidden {
  display: none;
}

.comment-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.comment-panel-title {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 280px;
}

.comment-thread {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.comment-empty {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 24px 0;
}

.comment-item {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.comment-item.resolved {
  opacity: 0.55;
}

.comment-bubble {
  background: #f5f5f5;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  line-height: 1.5;
}
.comment-bubble .comment-text {
  white-space: pre-wrap;
  word-break: break-word;
}
.comment-meta {
  display: flex;
  align-items: center;
  gap: 6px;
}
.comment-author {
  font-weight: 600;
  color: var(--text);
  font-size: 12px;
}
.comment-time {
  font-size: 11px;
  color: var(--muted);
}
.comment-actions {
  display: flex;
  gap: 6px;
  margin-top: 2px;
}
.comment-action-btn {
  background: none;
  border: none;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-family: inherit;
}
.comment-action-btn:hover {
  background: #f0f0f0;
  color: var(--text);
}
.comment-action-btn.resolve-btn {
  color: #0984e3;
}
.comment-action-btn.resolved-btn {
  color: var(--success);
}
.comment-action-btn.delete-btn {
  color: var(--danger);
}

.comment-resolved-badge {
  font-size: 10px;
  background: var(--success);
  color: #fff;
  border-radius: 4px;
  padding: 1px 5px;
  font-weight: 600;
  margin-left: 4px;
}

.comment-replies {
  margin-left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.comment-reply-bubble {
  background: #eef3fb;
  border-radius: 7px;
  padding: 8px 10px;
  font-size: 12px;
  line-height: 1.5;
}
.comment-reply-form {
  margin-left: 20px;
  display: flex;
  gap: 6px;
  margin-top: 4px;
}
.comment-reply-input {
  flex: 1;
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  font-family: inherit;
  resize: none;
}
.comment-reply-input:focus {
  outline: none;
  border-color: #888;
}

.comment-compose {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  align-items: flex-end;
}
.comment-input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
}
.comment-input:focus {
  outline: none;
  border-color: #888;
}
.comment-send-btn {
  flex-shrink: 0;
  padding: 8px 14px;
}

/* red dot on checklist items with unresolved comments */
.todo-check-item .comment-dot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e17055;
  flex-shrink: 0;
  display: inline-block;
  margin-left: 4px;
  cursor: pointer;
  vertical-align: middle;
}
/* expanded hit area via pseudo-element */
.todo-check-item .comment-dot::before {
  content: "";
  position: absolute;
  inset: -8px;
}
.todo-check-item .comment-dot:hover {
  background: #c0392b;
  transform: scale(1.3);
  transition: transform 0.1s;
}

/* comment dot in detail panel section title */
.detail-section-comment-dot {
  position: relative;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #e17055;
  display: inline-block;
  margin-left: 6px;
  vertical-align: middle;
  flex-shrink: 0;
}

/* comment dot next to a specific field in the detail panel */
.field-comment-wrap {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 6px;
}
.field-comment-wrap > *:first-child {
  flex: 1;
  min-width: 0;
}
.detail-field-comment-dot {
  position: relative;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #e17055;
  flex-shrink: 0;
  cursor: pointer;
  margin-top: 6px;
}
.detail-field-comment-dot::before {
  content: "";
  position: absolute;
  inset: -8px;
}
.detail-field-comment-dot:hover {
  background: #c0392b;
  transform: scale(1.25);
  transition: transform 0.1s;
}
/* resolved comments show as grey dot */
.comment-dot.comment-dot-resolved {
  background: #b2bec3;
}

/* right-click context menu */
.ctx-menu {
  position: fixed;
  z-index: 300;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.14);
  min-width: 160px;
  padding: 4px 0;
}
.ctx-menu.hidden {
  display: none;
}
.ctx-menu-item {
  display: block;
  width: 100%;
  background: none;
  border: none;
  text-align: left;
  padding: 8px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
}
.ctx-menu-item:hover {
  background: var(--bg);
}

/* ── Misc ─────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted);
}
.empty-state p {
  margin-bottom: 16px;
  font-size: 15px;
}

.loading {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

.error-state {
  background: #fff5f3;
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  padding: 16px 20px;
  color: var(--danger);
  margin: 20px;
}

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: #aaa;
}

/* ── Templates list ──────────────────────────────────────── */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 12px;
}
.tmpl-card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: flex;
  align-items: stretch;
  overflow: hidden;
}
.tmpl-card-color {
  width: 6px;
  background: var(--accent);
  flex-shrink: 0;
}
.tmpl-card-body {
  flex: 1;
  padding: 12px;
  min-width: 0;
}
.tmpl-card-name {
  font-weight: 600;
  font-size: 14px;
}
.tmpl-card-meta {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}
.tmpl-card-id {
  font-size: 11px;
  color: var(--muted);
  font-family: monospace;
  margin-top: 4px;
}
.tmpl-card-actions {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 8px 6px;
  gap: 4px;
}

/* ── Template editor ─────────────────────────────────────── */
.tmpl-editor {
  max-width: 820px;
  margin: 0 auto;
  padding-bottom: 48px;
}
.tmpl-editor-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}
.tmpl-editor-header h2 {
  font-size: 18px;
  font-weight: 700;
  margin: 0 0 4px;
}
.tmpl-editor-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-shrink: 0;
}
.tmpl-id-badge {
  display: inline-block;
  font-size: 12px;
  font-family: monospace;
  color: var(--muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
  border: 1px solid var(--border);
}
.tmpl-meta {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
}
.tmpl-meta-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
}
.tmpl-sections-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.tmpl-sections-header h3 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
}
.tmpl-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  background: var(--card);
}
.tmpl-section-head {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  border-radius: var(--radius) var(--radius) 0 0;
}
.tmpl-section-label {
  flex: 1;
  font-weight: 600;
  font-size: 14px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  outline: none;
  padding: 2px 6px;
  color: inherit;
  font-family: inherit;
}
.tmpl-section-label:hover {
  border-color: var(--border);
}
.tmpl-section-label:focus {
  border-color: var(--text);
  background: var(--card);
}
.tmpl-section-btns {
  display: flex;
  gap: 4px;
}
.tmpl-fields {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tmpl-field {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  background: var(--bg);
}
.tmpl-field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.tmpl-field-label {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  font-size: 13px;
  font-family: inherit;
  color: inherit;
  outline: none;
}
.tmpl-field-label:focus {
  border-color: var(--text);
}
.tmpl-field-type {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 6px;
  font-size: 13px;
  color: inherit;
  font-family: inherit;
  outline: none;
  cursor: pointer;
}
.tmpl-field-check {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}
.tmpl-field-btns {
  display: flex;
  gap: 4px;
  margin-left: auto;
}
.tmpl-field-extra {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 13px;
}
.tmpl-field-extra label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
  min-width: 160px;
}
.tmpl-field-extra input,
.tmpl-field-extra textarea {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 6px;
  font-size: 13px;
  color: inherit;
  font-family: inherit;
  outline: none;
}
.tmpl-field-extra input:focus,
.tmpl-field-extra textarea:focus {
  border-color: var(--text);
}

/* ── Shared small button helpers ─────────────────────────── */
.btn-icon-sm {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: 12px;
  cursor: pointer;
  color: var(--muted);
  line-height: 1.6;
}
.btn-icon-sm:hover {
  background: var(--bg);
  color: var(--text);
}
.btn-danger-icon {
  color: var(--danger);
}
.btn-danger-icon:hover {
  background: rgba(225, 112, 85, 0.1);
  border-color: var(--danger);
}
.btn-sm {
  font-size: 12px;
  padding: 4px 10px;
}

.header-brand-image {
  display: block;
  width: 76px;
  height: 44px;
  object-fit: cover;
}

.app-version {
  position: fixed;
  right: 12px;
  bottom: 8px;
  z-index: 10000;
  max-width: calc(100vw - 24px);
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 5px;
  background: var(--bg);
  color: var(--text);
  font: 11px/1.4 monospace;
  pointer-events: none;
}
