/*
 * kCube UI enhancements — the Projects page (see kcube_projects.js).
 * Colours come from the kcube theme variables with plain fallbacks.
 */

body.kc-projects {
  --kc-pt-line: var(--kc-menu-line, #dde2e8);
  --kc-pt-muted: #6b7480;
  --kc-pt-radius: 10px;
  --kc-pt-shadow: 0 1px 2px rgba(16, 24, 40, 0.05);
  --kc-pt-shadow-hover: 0 8px 24px rgba(16, 24, 40, 0.10);
}

body.kc-projects #content { background: #f7f8fa; }

.kc-pt-hidden { display: none !important; }

/* ---- additions to the query bar: count, legend, search, Board | List -- */

body.kc-projects #content .kc-qhead .kc-qhead-title h2 { font-size: 1.625rem; font-weight: 700; letter-spacing: -0.01em; }

.kc-pt-total {
  font-size: 0.8125rem;
  font-weight: 600;
  letter-spacing: 0;
  color: var(--kc-orange-deep, #c65a12);
  background: var(--kc-orange-tint, #fff1e6);
  border-radius: 999px;
  padding: 3px 10px;
}

body.kc-projects #content p.kc-pt-legend {
  display: flex;
  gap: 14px;
  margin: 6px 0 0;
  font-size: 0.8125rem;
  color: var(--kc-pt-muted);
}

.kc-pt-legend .icon { display: inline-flex; align-items: center; gap: 4px; padding: 0; background: none; }

.kc-pt-search {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 1 300px;
  min-inline-size: 180px;
  block-size: 34px;
  box-sizing: border-box;
  padding-inline: 12px;
  border: 1px solid var(--kc-input-border, #c9d1da);
  border-radius: 8px;
  background: #fff;
  color: var(--kc-pt-muted);
  cursor: text;
}

.kc-pt-search:focus-within { border-color: var(--kc-blue-light, #29aae1); box-shadow: 0 0 0 3px var(--kc-blue-tint, #e6f4fb); }

body.kc-projects .kc-pt-search input[type="search"] {
  flex: 1 1 auto;
  min-inline-size: 0;
  border: 0;
  block-size: auto;
  padding: 0;
  background: transparent;
  font-size: 0.9375rem;
  box-shadow: none;
}

body.kc-projects .kc-pt-search input[type="search"]:focus { outline: none; box-shadow: none; }

/* Board | List segmented control */
.kc-pt-seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: 8px;
  background: #eef1f4;
}

.kc-pt-seg button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  block-size: 28px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--kc-ink-soft, #3d434a);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.kc-pt-seg button:hover { color: var(--kc-ink, #262626); }

.kc-pt-seg button.is-active {
  background: #fff;
  color: var(--kc-orange-deep, #c65a12);
  box-shadow: 0 1px 3px rgba(16, 24, 40, 0.12);
}

/* ---- board: project cards --------------------------------------------- */

body.kc-projects #projects-index { container: kc-board / inline-size; }

body.kc-projects #projects-index ul.kc-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
  align-items: start;
  margin: 0;
  padding: 0;
  list-style: none;
  column-count: auto;
  columns: auto;
}

body.kc-projects #projects-index li.kc-card {
  display: flex;
  flex-direction: column;
  margin: 0;
  padding: 16px;
  background: #fff;
  border: 1px solid var(--kc-pt-line);
  border-radius: var(--kc-pt-radius);
  box-shadow: var(--kc-pt-shadow);
  break-inside: avoid;
  min-inline-size: 0;
  transition: box-shadow 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
  position: relative;
  overflow: hidden;
}

body.kc-projects #projects-index li.kc-card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  block-size: 3px;
  background: linear-gradient(90deg, var(--kc-orange, #f48120), var(--kc-blue-light, #29aae1) 55%, var(--kc-green, #a4cd39));
  opacity: 0;
  transition: opacity 0.18s ease;
}

body.kc-projects #projects-index li.kc-card:hover {
  border-color: #cfd6de;
  box-shadow: var(--kc-pt-shadow-hover);
  transform: translateY(-1px);
}

body.kc-projects #projects-index li.kc-card:hover::before { opacity: 1; }
body.kc-projects #projects-index li.kc-card[hidden] { display: none; }

/* head: tile · name · badges */
body.kc-projects #projects-index div.kc-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  padding: 0;
  background: none;
  border: 0;
}

.kc-card-tile {
  flex: 0 0 auto;
  inline-size: 40px;
  block-size: 40px;
  border-radius: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  font-size: 0.875rem;
  letter-spacing: 0.02em;
}

.kc-card-title { flex: 1 1 auto; min-inline-size: 0; }

body.kc-projects #projects-index .kc-card-title a.project {
  display: block;
  font-size: 1rem;
  font-weight: 700;
  line-height: 1.3;
  color: var(--kc-ink, #262626);
  padding: 0;
  background: none;
  overflow-wrap: anywhere;
}

body.kc-projects #projects-index .kc-card-title a.project:hover { color: var(--kc-blue, #0c78bd); text-decoration: none; }
/* the whole card head is clickable */
body.kc-projects #projects-index .kc-card-title a.project::after { content: ""; position: absolute; inset: 0 0 auto; block-size: 72px; }

body.kc-projects #projects-index li.kc-card.is-closed .kc-card-tile { filter: grayscale(1); opacity: 0.6; }
body.kc-projects #projects-index li.kc-card.is-closed .kc-card-title a.project { color: #868e96; }

/* Redmine's own icon classes on the link would add a raster icon: drop it */
body.kc-projects #projects-index a.project.icon { padding-inline-start: 0; background-image: none; }
body.kc-projects #projects-index a.project.icon > svg { display: none; }

.kc-card-badges { display: flex; gap: 4px; flex: 0 0 auto; }
.kc-card-badges:empty { display: none; }

body.kc-projects #projects-index .kc-card-badges .icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 26px;
  block-size: 26px;
  border-radius: 50%;
  background: #f1f3f5;
  padding: 0;
}

body.kc-projects #projects-index .kc-card-badges .icon-only.my-project { background: var(--kc-green-tint, #eef7e3); }
body.kc-projects #projects-index .kc-card-badges .icon-only.my-project svg { stroke: var(--kc-green-deep, #4f7a0c); }
body.kc-projects #projects-index .kc-card-badges .icon-only.icon-bookmarked-project { background: var(--kc-orange-tint, #fff1e6); }
body.kc-projects #projects-index .kc-card-badges .icon-only.icon-bookmarked-project svg { stroke: var(--kc-orange-deep, #c65a12); }

/* description, clamped to three lines */
body.kc-projects #projects-index .kc-card-desc {
  margin: 12px 0 0;
  color: #4a5360;
  font-size: 0.875rem;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}

body.kc-projects #projects-index .kc-card-desc p,
body.kc-projects #projects-index .kc-card-desc ul,
body.kc-projects #projects-index .kc-card-desc ol { margin: 0; padding-inline-start: 0; list-style-position: inside; }
body.kc-projects #projects-index .kc-card-desc h1,
body.kc-projects #projects-index .kc-card-desc h2,
body.kc-projects #projects-index .kc-card-desc h3 { font-size: inherit; margin: 0; border: 0; padding: 0; }
body.kc-projects #projects-index .kc-card-desc a { position: relative; z-index: 1; }

/* subprojects */
.kc-card-subs {
  margin-block-start: 14px;
  padding-block-start: 12px;
  border-block-start: 1px solid #eef1f4;
}

.kc-card-subs-head {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-block-end: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--kc-pt-muted);
}

/* the subproject tree: connector lines, one row height, names aligned */
body.kc-projects #projects-index .kc-card-subs ul.projects {
  margin: 0;
  padding: 0;
  list-style: none;
  border: 0;
}

body.kc-projects #projects-index .kc-card-subs li.kc-sub {
  --kc-row: 32px;
  --kc-line: #d9dfe6;
  position: relative;
  margin: 0;
  padding: 0 0 0 20px;
}

/* vertical line through the siblings, elbow into each row */
body.kc-projects #projects-index .kc-card-subs li.kc-sub::before,
body.kc-projects #projects-index .kc-card-subs li.kc-sub::after {
  content: "";
  position: absolute;
  inset-inline-start: 6px;
  border-color: var(--kc-line);
  border-style: solid;
  border-width: 0;
  pointer-events: none;
}

body.kc-projects #projects-index .kc-card-subs li.kc-sub::before {
  inset-block: 0;
  border-inline-start-width: 1.5px;
}

body.kc-projects #projects-index .kc-card-subs li.kc-sub::after {
  inset-block-start: 0;
  block-size: calc(var(--kc-row) / 2);
  inline-size: 10px;
  border-inline-start-width: 1.5px;
  border-block-end-width: 1.5px;
  border-end-start-radius: 6px;
}

/* the last visible sibling ends in the elbow */
body.kc-projects #projects-index .kc-card-subs li.kc-sub:last-child::before,
body.kc-projects #projects-index li.kc-card:not(.is-expanded):not(.is-searching) li.kc-sub:not(.kc-folded):not(:has(~ li.kc-sub:not(.kc-folded)))::before,
body.kc-projects #projects-index li.kc-card.is-searching li.kc-sub:not(.kc-miss):not(:has(~ li.kc-sub:not(.kc-miss)))::before { display: none; }

body.kc-projects #projects-index .kc-card-subs div.kc-sub-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  column-gap: 8px;
  min-block-size: var(--kc-row);
  margin: 0;
  padding: 0;
  background: none;
  border: 0;
}

body.kc-projects #projects-index .kc-card-subs div.kc-sub-row > a.project {
  display: flex;
  align-items: center;
  gap: 6px;
  min-inline-size: 0;
  padding: 4px 8px;
  margin: 0;
  border-radius: 6px;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--kc-blue, #0c78bd);
  background: none;
  position: relative;
  z-index: 1;
  text-decoration: none;
}

body.kc-projects #projects-index .kc-card-subs div.kc-sub-row > a.project:hover { background: var(--kc-blue-tint, #e6f4fb); color: var(--kc-blue-deep, #0a5f96); }
body.kc-projects #projects-index .kc-card-subs div.kc-sub-row > a.project:hover .kc-sub-name { text-decoration: underline; }

.kc-sub-name {
  min-inline-size: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.kc-sub-type {
  display: none;
  flex: 0 0 auto;
  min-inline-size: 30px;
  box-sizing: border-box;
  padding: 1px 5px;
  border-radius: 4px;
  background: #f1f3f5;
  color: #5c6672;
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-align: center;
  line-height: 1.5;
}

li.kc-mixed-types .kc-sub-type { display: inline-block; }

body.kc-projects #projects-index li.kc-sub.is-closed > div > a.project { color: #868e96; }

body.kc-projects #projects-index .kc-card-subs div.kc-sub-row > .kc-sub-desc { display: none; }

/* member / bookmark marks: one small column on the right */
.kc-sub-marks { display: inline-flex; gap: 4px; }
.kc-sub-marks:empty { display: none; }

body.kc-projects #projects-index .kc-sub-marks .icon-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: 22px;
  block-size: 22px;
  border-radius: 50%;
  padding: 0;
  background: #f1f3f5;
}

body.kc-projects #projects-index .kc-sub-marks .icon-only svg { inline-size: 13px; block-size: 13px; margin: 0; }
body.kc-projects #projects-index .kc-sub-marks .icon-only.my-project { background: var(--kc-green-tint, #eef7e3); }
body.kc-projects #projects-index .kc-sub-marks .icon-only.my-project svg { stroke: var(--kc-green-deep, #4f7a0c); }
body.kc-projects #projects-index .kc-sub-marks .icon-only.icon-bookmarked-project { background: var(--kc-orange-tint, #fff1e6); }
body.kc-projects #projects-index .kc-sub-marks .icon-only.icon-bookmarked-project svg { stroke: var(--kc-orange-deep, #c65a12); }

/* long lists fold */
body.kc-projects #projects-index li.kc-card:not(.is-expanded):not(.is-searching) li.kc-folded { display: none; }
body.kc-projects #projects-index li.kc-card.is-searching li.kc-miss { display: none; }
body.kc-projects #projects-index li.kc-card.is-searching .kc-card-more { display: none; }
body.kc-projects #projects-index li.kc-hit > div.kc-sub-row > a.project { background: #fff7d6; }

.kc-card-more {
  display: inline-flex;
  align-items: center;
  margin: 6px 0 0 20px;
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--kc-blue, #0c78bd);
  font: inherit;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  position: relative;
  z-index: 1;
}

.kc-card-more:hover { background: var(--kc-blue-tint, #e6f4fb); color: var(--kc-blue-deep, #0a5f96); }

/* empty search */
.kc-cards-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 48px 16px;
  color: var(--kc-pt-muted);
  text-align: center;
}

.kc-cards-empty[hidden] { display: none; }
.kc-cards-empty strong { color: var(--kc-ink, #262626); font-size: 1rem; margin-block-start: 6px; }

/* ---- list view -------------------------------------------------------- */

body.kc-projects #content table.list { background: #fff; }

/* ---- narrow screens ---------------------------------------------------- */

@media (max-width: 899px) {
  .kc-pt-search { flex: 1 1 100%; }
  body.kc-projects #projects-index ul.kc-cards { grid-template-columns: 1fr; }
}

/* ---- neutralise Redmine's masonry columns and nested-list spacing ------ */

body.kc-projects #projects-index { column-count: auto; column-width: auto; columns: auto; margin-block-end: 20px; }
body.kc-projects #projects-index ul.projects li.child { margin-block-start: 0; }
body.kc-projects #projects-index li.root ul.projects { border-inline-start: 0; padding-inline-start: 0; }
body.kc-projects #projects-index ul.projects div.root a.project { margin: 0; }
body.kc-projects #projects-index ul.projects div.root .icon-bookmarked-project svg,
body.kc-projects #projects-index ul.projects div.root .my-project svg,
body.kc-projects #projects-index ul.projects .icon-bookmarked-project svg,
body.kc-projects #projects-index ul.projects .my-project svg { margin: 0; stroke-width: 2; }
body.kc-projects #projects-index ul.projects div.description { padding-block-start: 0; }

/* rows without a type keep an empty tag slot in mixed cards, so names align */
li.kc-mixed-types .kc-sub-type.is-empty { visibility: hidden; }

/* masonry (see masonry() in kcube_projects.js): small rows, each card spans its
   own height plus the gap, so cards stack without holes. Without JS the grid
   above still works, just with even rows. */
body.kc-projects #projects-index ul.kc-cards { --kc-card-gap: 16px; }
body.kc-projects #projects-index ul.kc-cards.is-masonry {
  grid-auto-rows: 4px;
  row-gap: 0;
  column-gap: var(--kc-card-gap);
  align-items: start;
}


/* the Projects bar also holds search and Board | List: it gets its own row */
body.kc-projects .kc-qbar { order: 4; flex-basis: 100%; }
