/* Projects index workspace. Tokens mirror tasks.css, agent_runs_index.css, and project_show.css. */
[data-pull-refresh-target="scroller"]:has(> .projects-workspace) {
  background: #101722;
}

.projects-workspace {
  --bg: #101722;
  --panel: #192331;
  --panel-2: #18222f;
  --raise: #202c3d;
  --edge: #354151;
  --rule: #2a3545;
  --text: #f3f6fc;
  --soft: #d0d8e4;
  --muted: #a9b5c6;
  --faint: #7d899b;
  --link: #a2c6ff;
  --green: #9cddbd;
  --green-wash: #203c34;
  --blue: #acd2ff;
  --blue-wash: #233e60;
  --amber: #f6d18f;
  --amber-wash: #403522;
  --yellow: #f3e08a;
  --yellow-wash: #3d3820;
  --red: #ffb6bd;
  --red-wash: #45242b;
  --violet: #d2c2f8;
  --violet-wash: #302e49;
  --mono: ui-monospace, Menlo, monospace;

  min-height: 100%;
  color: var(--text);
  color-scheme: dark;
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  overflow-wrap: anywhere;

  > [role="status"],
  > [role="alert"] {
    max-width: 1252px;
    margin: 20px auto 0;
    width: calc(100% - 2 * clamp(20px, 3vw, 44px));
  }

  :is(a, button, summary):focus-visible {
    outline: 2px solid #93c5fd;
    outline-offset: 3px;
  }
  summary { list-style: none; cursor: pointer; }
  summary::-webkit-details-marker { display: none; }

  .pi-wrap {
    max-width: 1340px;
    margin: 0 auto;
    padding: 28px clamp(20px, 3vw, 44px) 56px;
  }

  svg.i {
    width: 15px;
    height: 15px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex: none;
  }

  /* Primary & Secondary Buttons */
  .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 36px;
    padding: 7px 14px;
    border: 1px solid var(--edge);
    border-radius: 8px;
    background: var(--raise);
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    color: var(--text);
  }
  .btn:hover { filter: brightness(1.14); }
  .btn-primary {
    background: #3466cd;
    border-color: #5081e4;
    color: #fff;
  }

  /* Intro + CTA Row */
  .pi-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
  }
  .pi-head p {
    color: var(--muted);
    font-size: 13px;
  }

  /* 4-Column KPI Totals Strip */
  .pi-totals {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 22px;
    background: var(--panel);
    border: 1px solid var(--edge);
    border-radius: 12px;
    overflow: hidden;
  }
  .pi-totals a {
    display: block;
    padding: 14px 18px;
    transition: background-color 120ms ease;
  }
  .pi-totals a + a { border-left: 1px solid var(--edge); }
  .pi-totals a:hover { background: #1f2b3b; }
  .pi-totals a:focus-visible { outline-offset: -2px; }
  .pi-totals a[aria-current="page"] {
    background: #203147;
    box-shadow: inset 0 -2px 0 var(--tone, #80acff);
  }
  .pi-totals dt {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: #c4cedb;
  }
  .pi-totals dt::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--tone, #80acff);
    flex-shrink: 0;
  }
  .pi-totals dd {
    margin-top: 2px;
    font-size: 28px;
    line-height: 1.2;
    letter-spacing: -1px;
    font-weight: 620;
    font-variant-numeric: tabular-nums;
    color: var(--text);
  }
  .pi-totals dd small {
    margin-left: 6px;
    font-size: 12px;
    letter-spacing: 0;
    font-weight: 400;
    color: var(--muted);
  }

  /* Filter + Sort Bar */
  .pi-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 14px;
  }
  .pi-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  .pi-filters a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    font-size: 12px;
    color: #b9c5d4;
    background: #17202c;
    border: 1px solid #394657;
    border-radius: 7px;
    white-space: nowrap;
  }
  .pi-filters a:hover { background: #243141; }
  .pi-filters a[aria-current="page"] {
    background: #233953;
    border-color: #648dbb;
    color: #e7efff;
  }
  .pi-filters a span {
    font: 11px var(--mono);
    color: #a5b2c5;
  }
  .pi-filters a i {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--tone);
    display: inline-block;
    flex-shrink: 0;
  }

  /* Sort Dropdown */
  .menu-wrap { position: relative; }
  .pi-sort { margin-left: auto; }
  .pi-sort-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 6px 10px;
    border: 1px solid #394657;
    border-radius: 7px;
    background: #17202c;
    font-size: 12px;
    color: #d5dde8;
    white-space: nowrap;
  }
  .pi-sort-btn:hover { background: #243141; }
  .pi-sort-btn strong { font-weight: 600; color: #eff3fa; }
  .pi-sort-btn svg { width: 13px; height: 13px; color: #9daabc; }
  .pi-sort[open] .pi-sort-btn {
    border-color: #648dbb;
    background: #1f2e42;
  }
  .menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 20;
    width: 224px;
    padding: 6px;
    background: #1d2837;
    border: 1px solid #415066;
    border-radius: 10px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.58);
  }
  .menu a {
    display: flex;
    width: 100%;
    align-items: center;
    justify-content: space-between;
    gap: 9px;
    padding: 8px 10px;
    border-radius: 6px;
    font-size: 13px;
    color: #dde5f0;
    font-weight: 500;
  }
  .menu a:hover { background: #2a3749; }
  .menu a[aria-current="true"] {
    background: #233953;
    color: #fff;
  }
  .menu a svg { width: 14px; height: 14px; color: #80acff; }

  /* Semantic Pills & Badges */
  .pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.35;
    white-space: nowrap;
    background: #2c3544;
    color: var(--soft);
  }
  .pill::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex: none;
  }
  .pill.live::before {
    box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 25%, transparent);
  }
  .pill em {
    font: 10.5px var(--mono);
    font-style: normal;
    opacity: .85;
  }
  .t-green { background: var(--green-wash); color: var(--green); }
  .t-blue { background: var(--blue-wash); color: var(--blue); }
  .t-amber { background: var(--amber-wash); color: var(--amber); }
  .t-yellow { background: var(--yellow-wash); color: var(--yellow); }
  .t-red { background: var(--red-wash); color: var(--red); }
  .t-violet { background: var(--violet-wash); color: var(--violet); }
  .t-gray { background: #2c3544; color: var(--soft); }

  .featchip {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px 2px 6px;
    border-radius: 6px;
    background: #1d2b45;
    border: 1px solid #2f4b78;
    color: #bcd5ff;
    font-size: 11.5px;
    font-weight: 550;
    white-space: nowrap;
    max-width: 100%;
  }
  .featchip span { overflow: hidden; text-overflow: ellipsis; }
  .featchip svg { width: 12px; height: 12px; flex-shrink: 0; }
  .featchip em { font: 10.5px var(--mono); font-style: normal; color: #8fb0e0; }
  .featchip:hover { border-color: #4f78b8; color: #fff; }

  .pi-chip {
    padding: 1px 7px;
    border: 1px solid var(--edge);
    border-radius: 5px;
    font-size: 11px;
    line-height: 1.5;
    color: #c2ccda;
    background: #1c2737;
    white-space: nowrap;
  }
  .pi-chip-more {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 10.5px;
  }

  .pi-shared {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 1px 7px 1px 3px;
    border-radius: 20px;
    background: var(--violet-wash);
    border: 1px solid #4b4570;
    color: var(--violet);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
  }
  .pi-shared-avatar {
    display: inline-grid;
    place-items: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #463d73;
    color: #ece4ff;
    font-size: 9.5px;
    font-weight: 700;
  }

  .pi-live-btn {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 24px;
    padding: 2px 8px;
    border: 1px solid #415066;
    border-radius: 6px;
    background: var(--raise);
    color: var(--text);
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.35;
    white-space: nowrap;
    transition: background-color 110ms ease, border-color 110ms ease, color 110ms ease;
  }
  .pi-live-btn svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    color: var(--link);
    flex: none;
  }
  .pi-live-btn:hover {
    background: #27364b;
    border-color: #648dbb;
    color: #ffffff;
  }
  .pi-live-btn:hover svg {
    color: #ffffff;
  }
  .pi-live-btn:focus-visible {
    outline: 2px solid #93c5fd;
    outline-offset: 2px;
  }

  /* Projects Table / List Surface */
  .pi-list {
    overflow: hidden;
    border: 1px solid #334051;
    border-radius: 12px;
    background: var(--panel-2);
  }

  .pi-cols {
    display: grid;
    grid-template-columns: minmax(286px, 1.45fr) 186px 146px 112px 92px;
    align-items: start;
    gap: 14px;
    padding-inline: 18px;
  }

  .pi-labels {
    align-items: center;
    height: 34px;
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: .105em;
    color: #acb9ca;
    background: #202c3a;
    font-weight: 650;
  }
  .pi-labels :last-child,
  .pi-activity { text-align: right; }

  .pi-row {
    position: relative;
    padding-block: 15px;
    border-top: 1px solid #303c4b;
    transition: background-color 110ms ease;
  }
  .pi-labels + .pi-row { border-top: 0; }
  .pi-row:hover { background: #1f2b3a; }
  .pi-row.attn { box-shadow: inset 3px 0 0 #ff929c; }
  .pi-row.blocked { box-shadow: inset 3px 0 0 #f5c16b; }

  /* Col 1: Identity */
  .pi-id {
    display: flex;
    align-items: flex-start;
    gap: 13px;
    min-width: 0;
  }
  .project-icon-slot {
    --slot: 44px;
    --radius: 10px;
    display: grid;
    place-items: center;
    width: var(--slot);
    height: var(--slot);
    flex-shrink: 0;
    margin-top: 1px;
  }
  .project-icon-slot img {
    --size: min(var(--slot), calc(var(--icon-pixels, 192px) / var(--icon-density, 1)));
    width: var(--size);
    height: var(--size);
    border-radius: min(var(--radius), calc(var(--size) * 0.227));
    object-fit: contain;
    display: block;
  }
  .project-icon-slot img[src="/project-folder.svg"] {
    --size: var(--slot);
  }
  .pi-id-body {
    min-width: 0;
    flex: 1;
  }
  .pi-title-line {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px 8px;
  }
  .pi-title {
    font-size: 15px;
    font-weight: 620;
    line-height: 1.32;
    letter-spacing: -.012em;
    color: #eff3fa;
  }
  .pi-title::after {
    content: "";
    position: absolute;
    inset: 0;
  }
  .pi-title:focus-visible { outline: none; }
  .pi-title:focus-visible::after {
    outline: 2px solid #93c5fd;
    outline-offset: -2px;
  }

  .pi-meta-stack {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 4px;
    min-width: 0;
  }
  .pi-meta-line {
    display: flex;
    align-items: center;
    gap: 7px;
    font-size: 12px;
    color: var(--muted);
    min-width: 0;
  }
  .pi-path {
    font: 11.5px/1.4 var(--mono);
    color: #9daabc;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .pi-path-missing {
    font-size: 12px;
    color: var(--faint);
    font-style: italic;
  }
  .pi-loc-count {
    font: 10.5px/1.35 var(--mono);
    padding: 0 5px;
    border: 1px solid #354458;
    border-radius: 4px;
    background: #141d29;
    color: #a8c9fe;
    white-space: nowrap;
    flex-shrink: 0;
  }
  .pi-repo {
    font: 11.5px/1.4 var(--mono);
    color: #8f9eb3;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .pi-repo svg {
    width: 12px;
    height: 12px;
    color: #6f7f96;
    flex-shrink: 0;
  }
  .pi-repo em {
    font-style: normal;
    color: var(--faint);
  }

  .pi-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
    margin-top: 7px;
  }

  .pi-alt {
    display: none;
    align-items: center;
    gap: 6px;
    margin-top: 7px;
    font-size: 11.5px;
    color: var(--soft);
  }
  .pi-alt code {
    font: 10.5px var(--mono);
    color: #9daabc;
  }

  /* Col 2: Work Pipeline */
  .pi-work {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding-top: 1px;
  }
  .pi-work-pills {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 5px;
  }
  .pi-counts {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 2px 10px;
    font-size: 12px;
    color: #aebaca;
    font-variant-numeric: tabular-nums;
  }
  .pi-counts strong {
    color: #edf2fa;
    font-weight: 600;
  }
  .pi-count-sub {
    display: block;
    font-size: 11px;
    color: var(--yellow);
    margin-top: -2px;
  }

  /* Col 3: Health */
  .pi-health {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding-top: 1px;
  }
  .pi-health a {
    position: relative;
    z-index: 1;
  }
  .pi-health a:hover { filter: brightness(1.14); }
  .pi-err-link {
    position: relative;
    z-index: 1;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: 6px;
    border: 1px solid #6b3540;
    background: #2c1c22;
    color: var(--red);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
  }
  .pi-err-link svg { width: 12px; height: 12px; flex-shrink: 0; }
  .pi-err-link:hover { border-color: #964958; color: #ffd4d8; }
  .pi-none {
    font-size: 12px;
    color: var(--faint);
  }

  /* Col 4: Default Agent */
  .pi-agent {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding-top: 1px;
  }
  .pv {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 12px;
    color: var(--soft);
    white-space: nowrap;
  }
  .pv svg,
  .pv img {
    width: 14px;
    height: 14px;
    flex-shrink: 0;
    object-fit: contain;
  }
  .pi-agent code {
    display: block;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font: 10.5px/1.4 var(--mono);
    color: #9daabc;
  }
  .pi-agent-flag {
    font: 10px/1.35 var(--mono);
    padding: 1px 5px;
    border: 1px solid var(--edge);
    border-radius: 4px;
    color: var(--muted);
    background: #141d29;
    white-space: nowrap;
  }

  /* Col 5: Activity */
  .pi-activity {
    min-width: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 5px;
    padding-top: 1px;
    font-size: 12px;
    color: #c4cedb;
    font-variant-numeric: tabular-nums;
  }
  .pi-shipped {
    font-weight: 600;
    color: #edf2fa;
    white-space: nowrap;
  }
  .pi-shipped span {
    font-weight: 400;
    color: var(--muted);
    font-size: 11px;
  }
  .pi-shipped.is-zero {
    color: var(--faint);
    font-weight: 500;
  }
  .pi-spark {
    display: grid;
    grid-template-columns: repeat(7, 5px);
    gap: 2px;
    align-items: end;
    height: 14px;
  }
  .pi-spark i {
    display: block;
    min-height: 2px;
    border-radius: 1px 1px 0 0;
    background: #365f4e;
  }
  .pi-spark i.is-zero { background: #2c3849; }
  .pi-spark i.is-today { background: #78d5aa; }
  .pi-activity time {
    display: block;
    font: 10.5px/1.3 var(--mono);
    color: #9daabc;
    white-space: nowrap;
  }

  /* Footer bar */
  .pi-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    border-top: 1px solid #303c4b;
    font-size: 12px;
    color: var(--muted);
  }
  .pi-foot a {
    color: var(--link);
    font-weight: 600;
    white-space: nowrap;
  }
  .pi-foot a:hover { text-decoration: underline; }

  /* Empty State */
  .pi-empty {
    padding: 56px 20px;
    text-align: center;
    color: var(--muted);
  }
  .pi-empty-icon {
    display: inline-grid;
    place-items: center;
    width: 48px;
    height: 48px;
    margin-bottom: 14px;
    border-radius: 12px;
    background: #202c3d;
    border: 1px solid var(--edge);
    color: #8fbaff;
  }
  .pi-empty-icon svg { width: 24px; height: 24px; }
  .pi-empty h2 {
    font-size: 16px;
    font-weight: 650;
    color: var(--text);
    margin-bottom: 6px;
  }
  .pi-empty p {
    max-width: 380px;
    margin: 0 auto 18px;
    font-size: 13px;
    color: var(--muted);
  }
}

/* Narrow desktop (sidebar open, collapse Agent col inline) */
@media (max-width: 1179px) {
  .projects-workspace {
    .pi-cols {
      grid-template-columns: minmax(220px, 1.25fr) 184px 144px 92px;
    }
    .pi-cols > .pi-agent,
    .pi-labels > .l-agent { display: none; }
    .pi-alt { display: inline-flex; flex-wrap: wrap; }
  }
}

/* Compact desktop / tablet with sidebar open (<= 1023px: 2x2 KPIs + stacked card rows) */
@media (max-width: 1023px) {
  .projects-workspace {
    .pi-totals {
      grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .pi-totals a:nth-child(3) { border-left: 0; }
    .pi-totals a:nth-child(n + 3) { border-top: 1px solid var(--edge); }
    .pi-totals dd { font-size: 25px; }

    .pi-labels { display: none; }
    .pi-cols {
      grid-template-columns: minmax(0, 1fr) auto;
      gap: 10px 14px;
      padding-inline: 16px;
    }
    .pi-row:first-of-type { border-top: 0; }
    .pi-id { grid-column: 1 / -1; }
    .pi-work {
      grid-column: 1;
      grid-row: 2;
      padding-left: 57px;
    }
    .pi-activity {
      grid-column: 2;
      grid-row: 2;
      align-self: start;
    }
    .pi-health {
      grid-column: 1 / -1;
      grid-row: 3;
      flex-direction: row;
      flex-wrap: wrap;
      align-items: center;
      padding-left: 57px;
    }
  }
}

/* Mobile (< 768px: sidebar collapses to mobile header) */
@media (max-width: 767px) {
  .projects-workspace {
    .pi-wrap { padding: 18px 14px 40px; }
    .pi-head { gap: 10px; margin-bottom: 14px; }
    .pi-totals { margin-bottom: 16px; border-radius: 10px; }
    .pi-totals a { padding: 12px 13px; }
    .pi-totals dd { font-size: 22px; }
    .pi-totals dd small { display: block; margin: 2px 0 0; font-size: 11px; }
    .pi-bar { gap: 8px; }
    .pi-filters {
      flex-wrap: nowrap;
      overflow-x: auto;
      width: 100%;
      padding-bottom: 2px;
      scrollbar-width: none;
    }
    .pi-filters::-webkit-scrollbar { display: none; }
    .pi-sort { margin-left: 0; }
    .pi-sort .menu { left: 0; right: auto; }

    .pi-cols { padding-inline: 14px; gap: 9px 10px; }
    .pi-row { padding-block: 13px; }
    .project-icon-slot { --slot: 36px; --radius: 8px; }
    .pi-id { gap: 10px; }
    .pi-title { font-size: 14.5px; }
    .pi-live-btn {
      min-height: 28px;
      padding: 3px 9px;
      font-size: 12px;
    }
    .pi-work,
    .pi-health { padding-left: 46px; }
    .pi-foot { padding: 11px 14px; flex-wrap: wrap; }
  }
}

/* Minimum mobile width (320px boundary) */
@media (max-width: 374px) {
  .projects-workspace {
    .pi-head { flex-wrap: wrap; }
    .pi-work,
    .pi-health { padding-left: 0; }
    .pi-activity {
      grid-column: 1 / -1;
      grid-row: 4;
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      border-top: 1px solid #263140;
      padding-top: 8px;
    }
    .pi-totals a { padding: 10px 10px; }
    .pi-totals dt { font-size: 11px; gap: 6px; }
    .pi-totals dd { font-size: 20px; }
  }
}
