/* Card detail (CARD-5): a modal on desktop, a full-screen sheet on phone. Markdown (MD-1). */

.backdrop--modal {
  place-items: start center;
  overflow-y: auto;
  padding: var(--space-7) var(--space-4);
  overscroll-behavior: contain;
}

.card-modal {
  width: min(840px, 100%);
  border-radius: var(--radius-xl);
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-modal);
  animation: rise var(--medium) var(--ease);
}

.card-modal__head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-5) var(--space-2) var(--space-6);
}

.card-modal__title {
  margin: -4px -8px;
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  font-size: var(--text-xl);
  font-weight: 750;
  letter-spacing: -0.02em;
  line-height: 1.25;
  overflow-wrap: anywhere;
  cursor: text;
}

.card-modal__title:hover {
  background: var(--paper-sunken);
}

.card-modal__where {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  color: var(--ink-muted);
  font-size: var(--text-sm);
}

.card-modal__where strong {
  color: var(--ink);
  font-weight: 650;
}

.card-modal__body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 208px;
  gap: var(--space-6);
  padding: var(--space-3) var(--space-5) var(--space-6) var(--space-6);
}

.card-section {
  margin-top: var(--space-5);
}

.card-section:first-child {
  margin-top: 0;
}

.card-section__head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 32px;
  margin-bottom: var(--space-2);
}

.card-section__head > .icon {
  color: var(--ink-subtle);
}

.card-section__head .caps {
  flex: 1;
}

.card-facts {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4) var(--space-6);
}

.fact {
  display: grid;
  gap: 6px;
  align-content: start;
}

.fact__value {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.fact__add {
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-pill);
  color: var(--ink-muted);
}

.fact__add:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 26px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
}

.description {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  background: var(--surface-raised);
  border: 1px solid var(--line);
}

.editor {
  display: grid;
  gap: var(--space-2);
}

.editor__bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
}

.editor__actions {
  display: flex;
  gap: var(--space-2);
}

/* Checklists */

.checklist + .checklist {
  margin-top: var(--space-4);
}

.checklist__head {
  display: flex;
  align-items: center;
  gap: 4px;
  min-height: 36px;
}

.checklist__toggle {
  width: 28px;
  min-width: 28px;
  min-height: 28px;
  color: var(--ink-subtle);
}

.checklist__toggle .icon {
  transition: transform var(--fast) var(--ease);
}

.checklist--collapsed .checklist__toggle .icon {
  transform: rotate(-90deg);
}

.checklist__name {
  flex: 1;
  min-width: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.checklist__count {
  color: var(--ink-subtle);
  font-size: var(--text-sm);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.checklist--complete .checklist__count {
  color: var(--ok);
}

.progress {
  display: block;
  width: 100%;
  height: 6px;
  margin: 2px 0 6px;
  border: 0;
  border-radius: var(--radius-pill);
  background: var(--paper-sunken);
  overflow: hidden;
  appearance: none;
}

.progress::-webkit-progress-bar {
  background: var(--paper-sunken);
  border-radius: var(--radius-pill);
}

.progress::-webkit-progress-value {
  background: var(--accent);
  border-radius: var(--radius-pill);
  transition: width var(--medium) var(--ease);
}

.progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: var(--radius-pill);
}

.checklist--complete .progress::-webkit-progress-value {
  background: var(--ok);
}

.checklist--complete .progress::-moz-progress-bar {
  background: var(--ok);
}

.check-items {
  margin: 0;
  padding: 0;
  list-style: none;
}

.check-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  min-height: 36px;
  padding: 8px 6px 8px 8px;
  border-radius: var(--radius-sm);
}

.check-item:hover {
  background: var(--paper-sunken);
}

.check-item > .check {
  margin-top: 1px;
}

.check-item__text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
}

.check-item--done .check-item__text {
  color: var(--ink-subtle);
  text-decoration: line-through;
  text-decoration-color: var(--line-strong);
}

.check-item__grip {
  color: var(--ink-subtle);
  opacity: 0;
  cursor: grab;
}

.check-item:hover .check-item__grip {
  opacity: 1;
}

.checklist--collapsed .check-items,
.checklist--collapsed .checklist__add {
  display: none;
}

.checklist__add {
  margin-top: 2px;
  color: var(--ink-muted);
}

@media (pointer: coarse) {
  .check-item {
    min-height: var(--touch);
    align-items: center;
  }

  .check-item > .check {
    width: 22px;
    height: 22px;
    margin-top: 0;
  }

  .check-item__grip {
    opacity: 1;
  }

  .inline-check {
    min-height: var(--touch);
  }

  .inline-check > .check {
    width: 22px;
    height: 22px;
  }
}

/* Comments */

.composer {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-3);
}

.composer .textarea {
  min-height: 72px;
}

.composer__actions {
  display: flex;
  justify-content: flex-end;
  margin-top: var(--space-2);
}

.comments {
  display: grid;
  gap: var(--space-4);
  margin: var(--space-5) 0 0;
  padding: 0;
  list-style: none;
}

.comment {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: var(--space-3);
}

.comment__head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 8px;
  font-size: var(--text-sm);
}

.comment__author {
  font-weight: 700;
}

.comment__time {
  color: var(--ink-subtle);
}

.comment__body {
  margin-top: 4px;
  padding: 10px 14px;
  border-radius: 4px var(--radius-lg) var(--radius-lg) var(--radius-lg);
  background: var(--paper-sunken);
}

.comment__actions {
  display: flex;
  gap: 2px;
  margin-top: 2px;
}

.comment__actions .btn {
  min-height: 28px;
  padding: 0 8px;
  font-size: var(--text-xs);
}

.comment--deleted-user .comment__author {
  color: var(--ink-subtle);
  font-style: italic;
}

/* Side column: actions + metadata */

.card-side {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-side .btn {
  justify-content: flex-start;
}

.card-side__meta {
  display: grid;
  gap: 4px;
  margin-top: var(--space-4);
  padding-top: var(--space-4);
  border-top: 1px solid var(--line);
  color: var(--ink-subtle);
  font-size: var(--text-xs);
}

.card-side__meta strong {
  color: var(--ink-muted);
  font-weight: 650;
}

.conflict-banner {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2) var(--space-3);
  margin-bottom: var(--space-3);
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--warn-soft);
  color: var(--warn);
  font-size: var(--text-sm);
  font-weight: 600;
}

.conflict-banner span {
  flex: 1;
  min-width: 12rem;
}

/* Phone: full-screen sheet (UI-2) */

@media (max-width: 640px) {
  .backdrop--modal {
    padding: 0;
  }

  .card-modal {
    min-height: 100%;
    border-radius: 0;
    box-shadow: none;
    animation-name: sheet;
  }

  .card-modal__head {
    position: sticky;
    top: 0;
    z-index: 2;
    padding: calc(var(--space-3) + var(--safe-top)) calc(var(--space-3) + var(--safe-right)) var(--space-3)
      calc(var(--space-4) + var(--safe-left));
    border-bottom: 1px solid var(--line);
    background: var(--surface);
  }

  .card-modal__title {
    font-size: var(--text-lg);
  }

  .card-modal__body {
    grid-template-columns: minmax(0, 1fr);
    gap: var(--space-5);
    padding: var(--space-4) calc(var(--space-4) + var(--safe-right)) calc(var(--space-6) + var(--safe-bottom))
      calc(var(--space-4) + var(--safe-left));
  }

  .card-side {
    flex-direction: row;
    flex-wrap: wrap;
    padding-top: var(--space-4);
    border-top: 1px solid var(--line);
  }

  .card-side > .caps {
    display: none;
  }

  .card-side .btn {
    flex: 1 1 auto;
  }

  .card-side__meta {
    flex-basis: 100%;
    margin-top: var(--space-2);
    padding-top: 0;
    border-top: 0;
  }
}

@keyframes sheet {
  from {
    transform: translateY(24px);
    opacity: 0;
  }
}

/* ---- Rendered markdown (MD-1) ---- */

.md {
  overflow-wrap: anywhere;
}

.md > * + * {
  margin-top: 0.7em;
}

.md h1,
.md h2,
.md h3,
.md h4 {
  margin-top: 1.2em;
  font-weight: 750;
}

.md > :first-child {
  margin-top: 0;
}

.md h1 { font-size: 1.4em; }
.md h2 { font-size: 1.2em; }
.md h3 { font-size: 1.05em; }
.md h4 { font-size: 1em; }

.md ul,
.md ol {
  padding-left: 1.4em;
}

.md li + li {
  margin-top: 0.25em;
}

.md li.task {
  list-style: none;
  margin-left: -1.4em;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.md li.task .check {
  margin-top: 3px;
  cursor: default;
}

.md code {
  padding: 0.1em 0.35em;
  border-radius: var(--radius-xs);
  background: var(--paper-sunken);
  font-family: var(--font-mono);
  font-size: 0.88em;
}

.md pre {
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: var(--paper-sunken);
  overflow-x: auto;
}

.md pre code {
  padding: 0;
  background: none;
  font-size: 0.85em;
}

.md blockquote {
  margin-left: 0;
  margin-right: 0;
  padding: 2px 0 2px var(--space-4);
  border-left: 3px solid var(--line-strong);
  color: var(--ink-muted);
}

.md hr {
  height: 1px;
  border: 0;
  background: var(--line);
}

.md table {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  border-collapse: collapse;
  font-size: 0.94em;
}

.md th,
.md td {
  padding: 6px 12px;
  border: 1px solid var(--line);
  text-align: left;
}

.md th {
  background: var(--surface-raised);
  font-weight: 700;
}

.md .wikilink {
  font-weight: 600;
  text-decoration: none;
  border-bottom: 1.5px solid var(--accent-soft);
}

.md .wikilink:hover {
  border-bottom-color: var(--accent);
}

.md .wikilink--missing {
  color: var(--danger);
  border-bottom: 1.5px dashed currentColor;
}

.md .wikilink--missing::after {
  content: " +";
  font-weight: 700;
}

/* ---- M4: editing affordances in the card detail ---- */

.card-modal__heading {
  min-width: 0;
  flex: 1;
}

.card-modal__title--editable,
.checklist__name.is-editable,
.check-item__text.is-editable {
  cursor: text;
  border-radius: var(--radius-sm);
}

.card-modal__title--editable:hover,
.checklist__name.is-editable:hover,
.check-item__text.is-editable:hover {
  background: var(--paper-sunken);
}

.card-modal__title-input {
  width: 100%;
  min-height: 40px;
  font-size: var(--text-xl);
  font-weight: 750;
  resize: none;
}

.description-empty {
  justify-content: flex-start;
  width: 100%;
  min-height: 56px;
  border: 1.5px dashed var(--line-strong);
  background: transparent;
  color: var(--ink-muted);
}

.due-editor {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin-top: var(--space-2);
}

.input--compact {
  width: auto;
  min-height: 34px;
  padding: 4px 8px;
}

.label-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
}

.label-picker__item {
  border: 0;
  cursor: pointer;
  opacity: 0.55;
}

.label-picker__item[aria-pressed="true"] {
  opacity: 1;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 3.5px currentColor;
}

.check-item__edit {
  display: flex;
  flex: 1;
  gap: 4px;
  min-width: 0;
}

.check-item__edit .input,
.check-item--new .input,
.checklist--new .input {
  flex: 1;
  min-height: 34px;
}

.check-item--new {
  padding-left: 28px;
}

.check-slot {
  list-style: none;
  border: 2px dashed var(--line-strong);
  border-radius: var(--radius-sm);
}

.dnd-lifted.check-item {
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: var(--card-shadow-drag);
}

.label-list {
  display: grid;
  gap: var(--space-2);
  margin: 0 0 var(--space-4);
  padding: 0;
  list-style: none;
}

.label-list__row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
}

.label-list__swatch {
  min-width: 72px;
  justify-content: center;
}

.label-list__row .input {
  flex: 1 1 120px;
  width: auto;
}

.label-list__row .input--select {
  flex: 0 1 auto;
}

.card-modal:focus {
  outline: none;
}
