/* ─── Kanban Board Styles ─── */

/* ─── Filter Bar (GitHub Projects-style) ─── */
.kanban-container {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  gap: 0;
}

.kanban-filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px 10px;
  flex-shrink: 0;
  flex-wrap: wrap;
}

.kanban-filter-search {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-card, rgba(255, 255, 255, 0.04));
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
  padding: 6px 10px;
  flex: 1;
  min-width: 180px;
  max-width: 320px;
}

.kanban-filter-icon {
  font-size: 13px;
  opacity: 0.6;
  flex-shrink: 0;
}

.kanban-filter-input {
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  width: 100%;
  min-width: 0;
}

.kanban-filter-input::placeholder {
  color: var(--text-secondary);
  opacity: 0.5;
}

.kanban-filter-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.kanban-filter-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-full, 999px);
  background: var(--bg-card, rgba(255, 255, 255, 0.04));
  color: var(--text-secondary);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.kanban-filter-chip:hover {
  border-color: var(--border-strong, rgba(255, 255, 255, 0.15));
  color: var(--text-primary);
}

.kanban-filter-chip.active {
  background: var(--accent, #3b82f6);
  border-color: var(--accent, #3b82f6);
  color: var(--accent-text, #fff);
}

.kanban-filter-chip.clear {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
  font-size: 11px;
  opacity: 0.7;
}

.kanban-filter-chip.clear:hover {
  opacity: 1;
  color: var(--color-critical, #dc2626);
}

.kanban-filter-dropdown-wrap {
  position: relative;
}

.kanban-filter-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  z-index: 100;
  min-width: 180px;
  background: var(--bg-primary, #0f172a);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
  padding: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  max-height: 240px;
  overflow-y: auto;
}

.kanban-filter-option {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: none;
  background: transparent;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  border-radius: var(--radius-sm, 4px);
  text-align: left;
  transition: background 0.1s;
}

.kanban-filter-option:hover {
  background: var(--bg-card, rgba(255, 255, 255, 0.06));
}

.kanban-filter-option.selected {
  background: rgba(59, 130, 246, 0.12);
  color: var(--accent, #3b82f6);
  font-weight: 600;
}

.kanban-filter-option .kanban-card-priority {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ─── Board Layout ─── */

.kanban-board {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding: 8px 0;
  min-height: 0;
  flex: 1;
  /* pan-x: horizontal board scroll; pinch-zoom: allow standard gesture */
  touch-action: pan-x pinch-zoom;
  overscroll-behavior-x: contain;
  align-items: stretch;
}

body.kanban-dragging {
  user-select: none;
}

body.kanban-dragging .kanban-board {
  scroll-snap-type: none;
  overscroll-behavior-x: none;
}

body.kanban-dragging .kanban-column {
  scroll-snap-align: none;
}

body.kanban-dragging .kanban-card {
  touch-action: none;
}

.kanban-column {
  min-width: 260px;
  max-width: none;
  flex: 1 1 280px;
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  border-radius: var(--radius-lg, 12px);
  padding: 14px;
  /* Use the Telegram stable viewport height, not raw 100vh which Telegram
     overrides — prevents columns being too short or clipped on the web app */
  max-height: calc(var(--viewport-stable-height, 100vh) - 180px);
  position: relative;
  border: 1px solid var(--border);
  /* Limit layout recalculations to within the column — columns don't affect
     each other's geometry, so the browser can skip cross-column layout work. */
  contain: layout;
}

.kanban-column.drag-over {
  border: 2px dashed var(--accent);
  background: rgba(59, 130, 246, 0.06);
}

.kanban-column-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 4px;
  font-weight: 600;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-secondary);
  border-bottom: 2px solid var(--border, rgba(255, 255, 255, 0.06));
  margin-bottom: 8px;
}

.kanban-column-title {
  flex: 1;
}

.kanban-count {
  background: var(--surface-1);
  padding: 2px 8px;
  border-radius: var(--radius-full, 999px);
  font-size: 12px;
  font-weight: 500;
  border: 1px solid var(--border);
}

.kanban-add-btn {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm, 6px);
  cursor: pointer;
  font-size: 16px;
  font-weight: 600;
  line-height: 1;
  transition: background 0.15s, color 0.15s;
  padding: 0;
  font-family: inherit;
}

.kanban-add-btn:hover {
  background: var(--bg-card, rgba(255, 255, 255, 0.1));
  color: var(--text-primary);
}

.kanban-add-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.kanban-inline-create {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--accent);
  border-radius: var(--radius-md, 8px);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
}

.kanban-inline-create::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

.kanban-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  flex: 1;
  padding: 4px;
  min-height: 0;
  touch-action: pan-y;
  /* Contain scroll within the column — prevents touch scroll spilling up to
     main-content or the page when the user reaches the top/bottom of a column. */
  overscroll-behavior-y: contain;
}

.kanban-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 8px);
  padding: 14px;
  cursor: pointer;
  transition: border-color 0.15s, opacity 0.15s, transform 0.15s;
  touch-action: pan-y;
}

.kanban-card:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

.kanban-card:active {
  transform: translateY(0) scale(0.98);
}

.kanban-card.dragging {
  opacity: 0.4;
}

/* ─── Touch drag clone ─── */
.kanban-card.touch-drag-clone {
  opacity: 0.85;
  transform: rotate(2deg) scale(1.04);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35), 0 4px 12px rgba(0, 0, 0, 0.2);
  border-color: var(--accent, #3b82f6);
  pointer-events: none;
  z-index: 9999;
  transition: none;
}

.kanban-card-badge {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 2px 6px;
  border-radius: var(--radius-sm, 4px);
  color: #fff;
}

/* ─── Card Header (repo badge + issue # + priority) ─── */
.kanban-card-header {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}

.kanban-card-repo {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  background: var(--surface-1, rgba(255, 255, 255, 0.06));
  border: 1px solid var(--border);
  border-radius: var(--radius-sm, 4px);
  padding: 1px 6px;
  letter-spacing: 0.02em;
  max-width: 100px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kanban-card-issue {
  font-size: 11px;
  font-weight: 600;
  color: var(--accent, #3b82f6);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.kanban-card-assignee {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent, #3b82f6);
  color: var(--accent-text, #fff);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  flex-shrink: 0;
}

.kanban-card-title {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 4px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.kanban-card-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kanban-card-base {
  font-size: 11px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  opacity: 0.8;
}

.kanban-card-base code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 11px;
}

.kanban-card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.kanban-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.kanban-card-priority {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.kanban-card-id {
  opacity: 0.6;
  font-family: monospace;
  font-size: 11px;
}

.kanban-empty-col {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  font-size: 13px;
  padding: 24px 12px;
  opacity: 0.5;
  border: 2px dashed var(--border, rgba(255, 255, 255, 0.08));
  border-radius: var(--radius-md, 8px);
  margin: 4px;
}

@media (max-width: 640px) {
  .kanban-board {
    scroll-snap-type: x mandatory;
    scroll-padding: 12px;
  }

  .kanban-column {
    min-width: 80%;
    max-width: 85%;
    scroll-snap-align: start;
  }
}

.kanban-scroll-fade {
  height: 16px;
  flex-shrink: 0;
  background: linear-gradient(to top, var(--bg-card), transparent);
  border-radius: 0 0 var(--radius-lg, 12px) var(--radius-lg, 12px);
  pointer-events: none;
  margin: 0 -12px -12px;
}

@media (min-width: 769px) {
  .kanban-column {
    min-width: 280px;
  }
}

@media (min-width: 1400px) {
  .kanban-board {
    gap: 18px;
    padding: 12px 0 18px;
  }

  .kanban-column {
    min-width: 280px;
    max-height: none;
  }
}

@media (max-width: 768px) {
  .kanban-board {
    scroll-snap-type: x mandatory;
    scroll-padding: 12px;
    padding: 8px 12px 12px;
    overscroll-behavior-x: contain;
    -webkit-overflow-scrolling: touch;
  }

  .kanban-column {
    flex: 0 0 85%;
    min-width: 260px;
    max-width: 85%;
    scroll-snap-align: start;
    scroll-snap-stop: always;
  }
}

@media (max-width: 640px) {
  .kanban-board {
    gap: 10px;
    scroll-snap-type: x mandatory;
    scroll-padding: 16px;
    -webkit-overflow-scrolling: touch;
  }

  .kanban-column {
    min-width: 86vw;
    max-width: 86vw;
    scroll-snap-align: start;
    padding: 12px;
  }

  .kanban-cards {
    padding: 2px;
  }
}

/* View toggle */
.view-toggle {
  display: flex;
  gap: 4px;
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-md, 8px);
  padding: 3px;
}

.view-toggle-btn {
  padding: 6px 12px;
  border: none;
  background: none;
  border-radius: var(--radius-sm, 6px);
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.view-toggle-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.view-toggle-btn.active {
  background: var(--accent);
  color: var(--accent-text);
}

/* ═══════════════════════════════════════════════
 *  Desktop Premium Density Overrides
 * ═══════════════════════════════════════════════ */
@media (min-width: 1400px) {
  .kanban-board {
    gap: 12px;
    padding: 8px 0 12px;
  }

  .kanban-column {
    padding: 10px;
    border-radius: var(--radius-md);
  }

  .kanban-card {
    padding: 10px;
    border-radius: var(--radius-sm);
  }

  .kanban-card-title {
    font-size: 13px;
  }

  .kanban-card-desc,
  .kanban-card-meta {
    font-size: 11px;
  }

  .kanban-column-header {
    font-size: 12px;
    padding: 6px 4px;
    margin-bottom: 6px;
  }
}

/* ═══════════════════════════════════════════════
 *  Performance hints
 * ═══════════════════════════════════════════════ */

/* Promote the horizontal scroll container to its own compositor layer so that
   scrolling the board doesn't trigger main-thread layout. */
.kanban-board {
  will-change: scroll-position;
}

/* ═══════════════════════════════════════════════
 *  Board View: Full-height bounded layout
 *
 *  Problem: .main-content is overflow-y:auto (a block element).
 *  .kanban-container has flex:1/min-height:0 but those only work when
 *  the *parent* is a flex container.  Without this, columns grow to
 *  their natural content height and the outer page scrolls vertically
 *  instead of each column scrolling its own cards.
 *
 *  Fix: TasksTab adds "tasks-board-view" to <body> when board view is
 *  active.  CSS then converts main-content into a bounded flex column,
 *  so the kanban-container fills the remaining height and columns can
 *  scroll internally.
 * ═══════════════════════════════════════════════ */

body.tasks-board-view .main-content {
  overflow: hidden !important;
  display: flex !important;
  flex-direction: column;
  min-height: 0;
  /* Remove vertical padding — kanban-board manages its own bottom clearance */
  padding-top: 0 !important;
  padding-bottom: 0 !important;
}

/* Toolbar stays fixed-height; no longer needs position:sticky since the
   container no longer scrolls. */
body.tasks-board-view .sticky-search {
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

/* Status summary row stays fixed-height */
body.tasks-board-view .snapshot-bar {
  flex-shrink: 0;
  margin-bottom: 0;
}

/* kanban-container fills all remaining vertical space.
   It already carries flex:1 and min-height:0 — the parent flex
   context added above is what makes those take effect. */
body.tasks-board-view .kanban-container {
  flex: 1;
  min-height: 0;
}

/* On mobile, add clearance at the bottom of the board for the fixed nav bar
   so the last card row isn't hidden behind it. */
@media (max-width: 768px) {
  body.tasks-board-view .kanban-board {
    padding-bottom: calc(var(--nav-height, 56px) + var(--safe-bottom, 0px) + 12px);
  }
}

/* ─── Reduced motion: disable decorative transitions on kanban cards ─── */
@media (prefers-reduced-motion: reduce) {
  .kanban-card {
    transition: border-color 0.05s;
  }
  .kanban-card:hover {
    transform: none;
  }
  .kanban-card:active {
    transform: scale(0.99);
  }
  .kanban-card.touch-drag-clone {
    transform: none;
  }
}
